The Gaudi Framework  v32r2 (46d42edc)
Gaudi.Application Class Reference

Gaudi application entry point. More...

#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

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

Static Public Member Functions

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

Protected Attributes

SmartIF< IStatefulapp
 Handle to the ApplicationMgr instance. More...
 

Private Attributes

 _impl
 

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 62 of file __init__.py.

Member Typedef Documentation

◆ Factory

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

Definition at line 20 of file Application.h.

◆ Options

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

Definition at line 19 of file Application.h.

Constructor & Destructor Documentation

◆ __init__()

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

Definition at line 63 of file __init__.py.

63  def __init__(self, opts, appType="Gaudi::Application"):
64  global _GaudiKernelLib
65  if _GaudiKernelLib is None:
66  # FIXME: note that we need PyDLL instead of CDLL if the calls to
67  # Python functions are not protected with the GIL.
68  gkl = _GaudiKernelLib = ctypes.PyDLL(
69  'libGaudiKernel' +
70  ('.dylib' if sys.platform == 'darwin' else '.so'),
71  mode=ctypes.RTLD_GLOBAL)
72  gkl._py_Gaudi__Application__create.restype = ctypes.c_void_p
73  gkl._py_Gaudi__Application__run.argtypes = [ctypes.c_void_p]
74  gkl._py_Gaudi__Application__run.restype = ctypes.c_int
75  gkl._py_Gaudi__Application__delete.argtypes = [ctypes.c_void_p]
76 
77  c_opts = (c_opt_t * len(opts))()
78  for idx, item in enumerate(opts.items()):
79  c_opts[idx].key = item[0].encode('ascii')
80  c_opts[idx].value = item[1].encode('ascii')
81 
82  self._impl = _GaudiKernelLib._py_Gaudi__Application__create(
83  appType.encode('ascii'), c_opts, ctypes.c_long(len(c_opts)))
84 

◆ __del__()

def Gaudi.Application.__del__ (   self)

Definition at line 92 of file __init__.py.

92  def __del__(self):
93  _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 41 of file Application.cpp.

41  {
42  // # Prepare the application
43  // - instantiate
45  GAUDI_ASSERT_THROW_NAME( app, "failure instantiating ApplicationMgr", "Gaudi::Application" );
46 
47  // - main configuration
48  consumeOptions( app.as<IProperty>(), options );
49  // - start minimal services
50  GAUDI_ASSERT_THROW_NAME( app->configure(), "failure creating basic services", "Gaudi::Application" );
51 
52  consumeOptions( SmartIF<IMessageSvc>{app}.as<IProperty>(), options );
53 
54  // - prepare job configuration
55  {
56  auto sloc = app.as<ISvcLocator>();
57  auto jos = sloc->service<IJobOptionsSvc>( "JobOptionsSvc" );
58  std::for_each( begin( options ), end( options ), [&jos]( const auto& item ) {
59  std::string_view name = item.first;
60  const auto sep_pos = name.find_last_of( '.' );
61  std::string_view client = name.substr( 0, sep_pos );
62  name.remove_prefix( sep_pos + 1 );
63  jos->addPropertyToCatalogue( std::string{client}, Gaudi::Property<std::string>{std::string{name}, item.second} );
64  } );
65  }
66 }
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:25
Implementation of property with value of concrete type.
Definition: Property.h:352
#define GAUDI_ASSERT_THROW_NAME(cond, msg, name)
Definition: Application.cpp:14
SmartIF< IFace > as() const
return a new SmartIF instance to another interface
Definition: SmartIF.h:107
STL class.
SmartIF< IStateful > app
Handle to the ApplicationMgr instance.
Definition: Application.h:40
StatusCode service(const Gaudi::Utils::TypeNameString &name, T *&svc, bool createIf=true)
Templated method to access a service by name.
Definition: ISvcLocator.h:76
Main interface for the JobOptions service.
def end
Definition: IOTest.py:113
AttribStringParser::Iterator begin(const AttribStringParser &parser)
The IProperty is the basic interface for all components which have properties that can be set or get.
Definition: IProperty.h:20
T for_each(T... args)
virtual StatusCode configure()=0
Configuration (from OFFLINE to CONFIGURED).
GAUDI_API IAppMgrUI * createApplicationMgr(const std::string &dllname, const std::string &factname)

◆ ~Application()

Gaudi.Application::~Application ( )
virtual

Definition at line 68 of file Application.cpp.

68 { app->terminate().ignore(); }
virtual StatusCode terminate()=0
Initialization (from CONFIGURED to OFFLINE).
SmartIF< IStateful > app
Handle to the ApplicationMgr instance.
Definition: Application.h:40
const StatusCode & ignore() const
Ignore/check StatusCode.
Definition: StatusCode.h:153

Member Function Documentation

◆ create() [1/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 36 of file Application.cpp.

36  {
37  if ( type == "Gaudi::Application" ) { return std::make_unique<Application>( std::move( opts ) ); }
38  return Factory::create( type, std::move( opts ) );
39 }
T move(T... args)

◆ create() [2/2]

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

Definition at line 86 of file __init__.py.

86  def create(cls, appType, opts):
87  return cls(opts, appType=appType)
88 

◆ run() [1/3]

int Gaudi.Application::run ( )
virtual

Implement the application main logic:

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

Definition at line 70 of file Application.cpp.

70  {
71  auto prop = app.as<IProperty>();
72  auto processor = app.as<IEventProcessor>();
73 
75  evtMax.assign( prop->getProperty( "EvtMax" ) );
76 
77  // - get ready to process events
78  if ( app->initialize() ) {
79  if ( app->start() ) {
80  // - main processing loop
81  if ( !processor->executeRun( evtMax ) ) setAppReturnCode( prop, Gaudi::ReturnCode::GenericFailure );
82 
83  app->stop().ignore();
84  } else
86  app->finalize().ignore();
87  } else
89  return getAppReturnCode( prop );
90 }
int getAppReturnCode(const SmartIF< IProperty > &appmgr)
Get the application (current) return code.
Definition: AppReturnCode.h:69
Implementation of property with value of concrete type.
Definition: Property.h:352
SmartIF< IFace > as() const
return a new SmartIF instance to another interface
Definition: SmartIF.h:107
constexpr int GenericFailure
Definition: AppReturnCode.h:18
virtual StatusCode start()=0
Start (from INITIALIZED to RUNNING).
SmartIF< IStateful > app
Handle to the ApplicationMgr instance.
Definition: Application.h:40
virtual StatusCode stop()=0
Stop (from RUNNING to INITIALIZED).
virtual StatusCode initialize()=0
Initialization (from CONFIGURED to INITIALIZED).
StatusCode setAppReturnCode(SmartIF< IProperty > &appmgr, int value, bool force=false)
Set the application return code.
Definition: AppReturnCode.h:49
const StatusCode & ignore() const
Ignore/check StatusCode.
Definition: StatusCode.h:153
virtual StatusCode finalize()=0
Finalize (from INITIALIZED to CONFIGURED).
The IEventProcessor is the interface to process events.
The IProperty is the basic interface for all components which have properties that can be set or get.
Definition: IProperty.h:20

◆ run() [2/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 36 of file Application.h.

36 { return action( app ); }
SmartIF< IStateful > app
Handle to the ApplicationMgr instance.
Definition: Application.h:40

◆ run() [3/3]

def Gaudi.Application.run (   self)

Definition at line 89 of file __init__.py.

89  def run(self):
90  return _GaudiKernelLib._py_Gaudi__Application__run(self._impl)
91 

Member Data Documentation

◆ _impl

Gaudi.Application._impl
private

Definition at line 82 of file __init__.py.

◆ app

SmartIF<IStateful> Gaudi.Application::app
protected

Handle to the ApplicationMgr instance.

Definition at line 40 of file Application.h.


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