The Gaudi Framework  master (594c33fa)
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

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 87 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

Constructor & Destructor Documentation

◆ __init__()

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

Definition at line 88 of file __init__.py.

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

◆ __del__()

def Gaudi.Application.__del__ (   self)

Definition at line 133 of file __init__.py.

133  def __del__(self):
134  _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.

52  {
53  // # Prepare the application
54  // - instantiate
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 }

◆ ~Application()

Gaudi.Application::~Application ( )
virtual

Definition at line 73 of file Application.cpp.

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

Member Function Documentation

◆ create() [1/2]

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

Definition at line 127 of file __init__.py.

127  def create(cls, appType, opts):
128  return cls(opts, appType=appType)
129 

◆ 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]

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 
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 }

◆ run() [2/3]

def Gaudi.Application.run (   self)

Definition at line 130 of file __init__.py.

130  def run(self):
131  return _GaudiKernelLib._py_Gaudi__Application__run(self._impl)
132 

◆ 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
private

Definition at line 122 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:
IEventProcessor
Definition: IEventProcessor.h:24
Gaudi::createApplicationMgr
GAUDI_API IAppMgrUI * createApplicationMgr(const std::string &dllname, const std::string &factname)
std::move
T move(T... args)
AtlasMCRecoFullPrecedenceDump.evtMax
evtMax
Definition: AtlasMCRecoFullPrecedenceDump.py:28
ISvcLocator
Definition: ISvcLocator.h:46
Gaudi::getAppReturnCode
int getAppReturnCode(const SmartIF< IProperty > &appmgr)
Get the application (current) return code.
Definition: AppReturnCode.h:79
GAUDI_ASSERT_THROW_NAME
#define GAUDI_ASSERT_THROW_NAME(cond, msg, name)
Definition: Application.cpp:25
ISvcLocator::getOptsSvc
Gaudi::Interfaces::IOptionsSvc & getOptsSvc()
Direct access to Gaudi::Interfaces::IOptionsSvc implementation.
Definition: ISvcLocator.cpp:19
IProperty
Definition: IProperty.h:33
gaudirun.opts
opts
Definition: gaudirun.py:336
Gaudi::setAppReturnCode
StatusCode setAppReturnCode(SmartIF< IProperty > &appmgr, int value, bool force=false)
Set the application return code.
Definition: AppReturnCode.h:59
SmartIF< IMessageSvc >
StatusCode::ignore
const StatusCode & ignore() const
Allow discarding a StatusCode without warning.
Definition: StatusCode.h:139
SmartIF::as
SmartIF< IFace > as() const
return a new SmartIF instance to another interface
Definition: SmartIF.h:117
gaudirun.type
type
Definition: gaudirun.py:160
ConditionsStallTest.name
name
Definition: ConditionsStallTest.py:77
Gaudi.CommonGaudiConfigurables.cls
cls
Definition: CommonGaudiConfigurables.py:44
Gaudi.Application::app
SmartIF< IStateful > app
Handle to the ApplicationMgr instance.
Definition: Application.h:50
gaudirun.action
action
Definition: gaudirun.py:153
gaudirun.options
options
Definition: gaudirun.py:313
Gaudi::ReturnCode::GenericFailure
constexpr int GenericFailure
Definition: AppReturnCode.h:28
Gaudi::Property< int >