The Gaudi Framework  v33r1 (b1225454)
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 81 of file __init__.py.

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__()

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

Definition at line 82 of file __init__.py.

82  def __init__(self, opts, appType="Gaudi::Application"):
83  global _GaudiKernelLib
84  if _GaudiKernelLib is None:
85  # FIXME: note that we need PyDLL instead of CDLL if the calls to
86  # Python functions are not protected with the GIL.
87  gkl = _GaudiKernelLib = ctypes.PyDLL(
88  'libGaudiKernel' +
89  ('.dylib' if sys.platform == 'darwin' else '.so'),
90  mode=ctypes.RTLD_GLOBAL)
91  gkl._py_Gaudi__Application__create.restype = ctypes.c_void_p
92  gkl._py_Gaudi__Application__run.argtypes = [ctypes.c_void_p]
93  gkl._py_Gaudi__Application__run.restype = ctypes.c_int
94  gkl._py_Gaudi__Application__delete.argtypes = [ctypes.c_void_p]
95 
96  c_opts = (c_opt_t * len(opts))()
97  for idx, item in enumerate(opts.items()):
98  c_opts[idx].key = item[0].encode('ascii')
99  c_opts[idx].value = item[1].encode('ascii')
100 
101  self._impl = _GaudiKernelLib._py_Gaudi__Application__create(
102  appType.encode('ascii'), c_opts, ctypes.c_long(len(c_opts)))
103 

◆ __del__()

def Gaudi.Application.__del__ (   self)

Definition at line 111 of file __init__.py.

111  def __del__(self):
112  _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 51 of file Application.cpp.

51  {
52  // # Prepare the application
53  // - instantiate
55  GAUDI_ASSERT_THROW_NAME( app, "failure instantiating ApplicationMgr", "Gaudi::Application" );
56 
57  // - main configuration
58  consumeOptions( app.as<IProperty>(), options );
59  // - start minimal services
60  GAUDI_ASSERT_THROW_NAME( app->configure(), "failure creating basic services", "Gaudi::Application" );
61 
62  consumeOptions( SmartIF<IMessageSvc>{app}.as<IProperty>(), options );
63 
64  // - prepare job configuration
65  {
66  auto sloc = app.as<ISvcLocator>();
67  auto jos = sloc->service<IJobOptionsSvc>( "JobOptionsSvc" );
68  std::for_each( begin( options ), end( options ), [&jos]( const auto& item ) {
69  std::string_view name = item.first;
70  const auto sep_pos = name.find_last_of( '.' );
71  std::string_view client = name.substr( 0, sep_pos );
72  name.remove_prefix( sep_pos + 1 );
73  jos->addPropertyToCatalogue( std::string{client}, Gaudi::Property<std::string>{std::string{name}, item.second} )
74  .ignore( /* AUTOMATICALLY ADDED FOR gaudi/Gaudi!763 */ );
75  } );
76  }
77 }
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:35
Implementation of property with value of concrete type.
Definition: Property.h:370
#define GAUDI_ASSERT_THROW_NAME(cond, msg, name)
Definition: Application.cpp:24
SmartIF< IFace > as() const
return a new SmartIF instance to another interface
Definition: SmartIF.h:117
STL class.
SmartIF< IStateful > app
Handle to the ApplicationMgr instance.
Definition: Application.h:50
StatusCode service(const Gaudi::Utils::TypeNameString &name, T *&svc, bool createIf=true)
Templated method to access a service by name.
Definition: ISvcLocator.h:86
Main interface for the JobOptions service.
def end
Definition: IOTest.py:123
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:30
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 79 of file Application.cpp.

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

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 46 of file Application.cpp.

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

◆ create() [2/2]

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

Definition at line 105 of file __init__.py.

105  def create(cls, appType, opts):
106  return cls(opts, appType=appType)
107 

◆ 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 81 of file Application.cpp.

81  {
82  auto prop = app.as<IProperty>();
83  auto processor = app.as<IEventProcessor>();
84 
86  evtMax.assign( prop->getProperty( "EvtMax" ) );
87 
88  // - get ready to process events
89  if ( app->initialize() ) {
90  if ( app->start() ) {
91  // - main processing loop
92  if ( !processor->executeRun( evtMax ) ) setAppReturnCode( prop, Gaudi::ReturnCode::GenericFailure ).ignore();
93 
94  app->stop().ignore();
95  } else
97  app->finalize().ignore();
98  } else
100  return getAppReturnCode( prop );
101 }
int getAppReturnCode(const SmartIF< IProperty > &appmgr)
Get the application (current) return code.
Definition: AppReturnCode.h:79
Implementation of property with value of concrete type.
Definition: Property.h:370
SmartIF< IFace > as() const
return a new SmartIF instance to another interface
Definition: SmartIF.h:117
constexpr int GenericFailure
Definition: AppReturnCode.h:28
virtual StatusCode start()=0
Start (from INITIALIZED to RUNNING).
SmartIF< IStateful > app
Handle to the ApplicationMgr instance.
Definition: Application.h:50
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:59
const StatusCode & ignore() const
Ignore/check StatusCode.
Definition: StatusCode.h:168
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:30

◆ 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 46 of file Application.h.

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

◆ run() [3/3]

def Gaudi.Application.run (   self)

Definition at line 108 of file __init__.py.

108  def run(self):
109  return _GaudiKernelLib._py_Gaudi__Application__run(self._impl)
110 

Member Data Documentation

◆ _impl

Gaudi.Application._impl
private

Definition at line 101 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: