The Gaudi Framework  master (ff829712)
Loading...
Searching...
No Matches
Gaudi::Application Class Reference

Gaudi application entry point. More...

#include </builds/gaudi/Gaudi/GaudiKernel/include/Gaudi/Application.h>

Inheritance diagram for Gaudi::Application:
Collaboration diagram for Gaudi::Application:

Public Types

using Options = std::map<std::string, std::string>
 
using Factory = Gaudi::PluginService::Factory<Application( Options )>
 

Public Member Functions

 __init__ (self, opts, appType="Gaudi::Application")
 
 create (cls, appType, opts)
 
 run (self)
 
 __del__ (self)
 
 Application (Options opts)
 Construct and configure the application from the provided options.
 
virtual ~Application ()
 
virtual int run ()
 Implement the application main logic:
 
int run (std::function< int(SmartIF< IStateful > &)> action)
 Run a user provided implementation of the application main logic.
 

Static Public Member Functions

static Factory::ReturnType create (std::string_view type, Options opts)
 Factory function to instantiate a derived class via GaudiPluginService.
 

Protected Attributes

 _impl
 
SmartIF< IStatefulapp
 Handle to the ApplicationMgr instance.
 

Detailed Description

Gaudi application entry point.

Gaudi::Application can be used to bootstrap a standard Gaudi application or to implement custom applications, either via a specialization that overrides the method run (which can be instantiated either directly or via the GaudiPluginService, with the helper create) or by passing a callable object to the dedicated run method.

Definition at line 27 of file Application.h.

Member Typedef Documentation

◆ Factory

using Gaudi::Application::Factory = Gaudi::PluginService::Factory<Application( Options )>

Definition at line 30 of file Application.h.

◆ Options

using Gaudi::Application::Options = std::map<std::string, std::string>

Definition at line 29 of file Application.h.

Constructor & Destructor Documentation

◆ __init__()

Gaudi.Application.__init__ ( self,
opts,
appType = "Gaudi::Application" )

Definition at line 90 of file __init__.py.

90 def __init__(self, opts, appType="Gaudi::Application"):
91 global _GaudiKernelLib
92 if _GaudiKernelLib is None:
93 # Note: using CDLL instead of PyDLL means that every call to the Python C
94 # API must be protected acquiring the GIL
95 #
96 if sys.platform == "darwin":
97 # LD_LIBRARY_PATH cannot be used for dlopen on macos;
98 # use custom variable GAUDI_PLUGIN_PATH instead
99 _libpaths = os.environ.get("GAUDI_PLUGIN_PATH")
100 if not _libpaths:
101 print("WARNING: GAUDI_PLUGIN_PATH is empty!")
102 for _path in _libpaths.split(":"):
103 _lib = os.path.join(_path, "libGaudiKernel.dylib")
104 if os.path.isfile(_lib):
105 gkl = _GaudiKernelLib = ctypes.CDLL(
106 _lib,
107 mode=ctypes.RTLD_GLOBAL,
108 )
109 else:
110 gkl = _GaudiKernelLib = ctypes.CDLL(
111 "libGaudiKernel.so",
112 mode=ctypes.RTLD_GLOBAL,
113 )
114 gkl._py_Gaudi__Application__create.restype = ctypes.c_void_p
115 gkl._py_Gaudi__Application__run.argtypes = [ctypes.c_void_p]
116 gkl._py_Gaudi__Application__run.restype = ctypes.c_int
117 gkl._py_Gaudi__Application__delete.argtypes = [ctypes.c_void_p]
118
119 c_opts = (c_opt_t * len(opts))()
120 for idx, item in enumerate(opts.items()):
121 c_opts[idx].key = item[0].encode("ascii")
122 c_opts[idx].value = item[1].encode("ascii")
123
124 self._impl = _GaudiKernelLib._py_Gaudi__Application__create(
125 appType.encode("ascii"), c_opts, ctypes.c_ulong(len(c_opts))
126 )
127

◆ __del__()

Gaudi.Application.__del__ ( self)

Definition at line 135 of file __init__.py.

135 def __del__(self):
136 _GaudiKernelLib._py_Gaudi__Application__delete(self._impl)

◆ Application()

Gaudi::Application::Application ( Options opts)

Construct and configure the application from the provided options.

Definition at line 52 of file Application.cpp.

53 : // instantiate
55
56 GAUDI_ASSERT_THROW_NAME( app, "failure instantiating ApplicationMgr", "Gaudi::Application" );
57
58 // - main configuration
59 consumeOptions( app.as<IProperty>(), options );
60 // - start minimal services
61 GAUDI_ASSERT_THROW_NAME( app->configure(), "failure creating basic services", "Gaudi::Application" );
62
63 consumeOptions( SmartIF<IMessageSvc>{ app }.as<IProperty>(), options );
64
65 // - prepare job configuration
66 {
67 auto sloc = app.as<ISvcLocator>();
68 auto& jos = sloc->getOptsSvc();
69 for ( const auto& [name, value] : options ) jos.set( name, value );
70 }
71}
#define GAUDI_ASSERT_THROW_NAME(cond, msg, name)
SmartIF< IStateful > app
Handle to the ApplicationMgr instance.
Definition Application.h:50
GAUDI_API IAppMgrUI * createApplicationMgr()

◆ ~Application()

Gaudi::Application::~Application ( )
virtual

Definition at line 73 of file Application.cpp.

73{ app->terminate().ignore(); }

Member Function Documentation

◆ create() [1/2]

Gaudi.Application.create ( cls,
appType,
opts )

Definition at line 129 of file __init__.py.

129 def create(cls, appType, opts):
130 return cls(opts, appType=appType)
131

◆ create() [2/2]

Gaudi::Application::Factory::ReturnType Gaudi::Application::create ( std::string_view type,
Options opts )
static

Factory function to instantiate a derived class via GaudiPluginService.

Definition at line 47 of file Application.cpp.

47 {
48 if ( type == "Gaudi::Application" ) { return std::make_unique<Application>( std::move( opts ) ); }
49 return Factory::create( type, std::move( opts ) );
50}

◆ run() [1/3]

Gaudi.Application.run ( self)

Reimplemented in Gaudi::TestSuite::QueueingApplication.

Definition at line 132 of file __init__.py.

132 def run(self):
133 return _GaudiKernelLib._py_Gaudi__Application__run(self._impl)
134

◆ run() [2/3]

int Gaudi::Application::run ( )
virtual

Implement the application main logic:

  • prepare for processing (initialize + start)
  • loop over events
  • terminate (stop + finalize)

Reimplemented in Gaudi::TestSuite::QueueingApplication.

Definition at line 75 of file Application.cpp.

75 {
76 auto prop = app.as<IProperty>();
77 auto processor = app.as<IEventProcessor>();
78
79 Gaudi::Property<int> evtMax;
80 evtMax.assign( prop->getProperty( "EvtMax" ) );
81
82 // - get ready to process events
83 if ( app->initialize() ) {
84 if ( app->start() ) {
85 // - main processing loop
86 if ( !processor->executeRun( evtMax ) ) setAppReturnCode( prop, Gaudi::ReturnCode::GenericFailure ).ignore();
87
88 app->stop().ignore();
89 } else
91 app->finalize().ignore();
92 } else
94 return getAppReturnCode( prop );
95}
const StatusCode & ignore() const
Allow discarding a StatusCode without warning.
Definition StatusCode.h:139
constexpr int GenericFailure
int getAppReturnCode(const SmartIF< IProperty > &appmgr)
Get the application (current) return code.
StatusCode setAppReturnCode(SmartIF< IProperty > &appmgr, int value, bool force=false)
Set the application return code.

◆ run() [3/3]

int Gaudi::Application::run ( std::function< int(SmartIF< IStateful > &)> action)
inline

Run a user provided implementation of the application main logic.

Definition at line 46 of file Application.h.

46{ return action( app ); }

Member Data Documentation

◆ _impl

Gaudi.Application._impl
protected
Initial value:
= _GaudiKernelLib._py_Gaudi__Application__create(
appType.encode("ascii"), c_opts, ctypes.c_ulong(len(c_opts))
)

Definition at line 124 of file __init__.py.

◆ app

SmartIF<IStateful> Gaudi::Application::app
protected

Handle to the ApplicationMgr instance.

Definition at line 50 of file Application.h.


The documentation for this class was generated from the following files: