The Gaudi Framework
master (9f3f8895)
Toggle main menu visibility
Loading...
Searching...
No Matches
Application.cpp
Go to the documentation of this file.
1
/***********************************************************************************\
2
* (c) Copyright 1998-2025 CERN for the benefit of the LHCb and ATLAS collaborations *
3
* *
4
* This software is distributed under the terms of the Apache version 2 licence, *
5
* copied verbatim in the file "LICENSE". *
6
* *
7
* In applying this licence, CERN does not waive the privileges and immunities *
8
* granted to it by virtue of its status as an Intergovernmental Organization *
9
* or submit itself to any jurisdiction. *
10
\***********************************************************************************/
11
#include <
Gaudi/Application.h
>
12
#include <
Gaudi/Interfaces/IOptionsSvc.h
>
13
#include <
Gaudi/Property.h
>
14
#include <
GaudiKernel/AppReturnCode.h
>
15
#include <
GaudiKernel/Bootstrap.h
>
16
#include <
GaudiKernel/IAppMgrUI.h
>
17
#include <
GaudiKernel/IEventProcessor.h
>
18
#include <
GaudiKernel/IMessageSvc.h
>
19
#include <
GaudiKernel/INamedInterface.h
>
20
#include <
GaudiKernel/IProperty.h
>
21
#include <
GaudiKernel/ISvcLocator.h
>
22
#include <gsl/span>
23
#include <type_traits>
24
25
#define GAUDI_ASSERT_THROW_NAME( cond, msg, name ) \
26
if ( !cond ) throw GaudiException{ msg, name, StatusCode::FAILURE };
27
28
#define GAUDI_ASSERT_THROW( cond, msg ) \
29
if ( !cond ) throw GaudiException{ msg, this->name(), StatusCode::FAILURE };
30
31
namespace
{
32
void
consumeOptions(
SmartIF<IProperty>
prop,
Gaudi::Application::Options
& options ) {
33
GAUDI_ASSERT_THROW_NAME
( prop,
"invalid IProperty"
,
"Gaudi::Application"
);
34
std::string prefix =
SmartIF<INamedInterface>
( prop )->name() +
'.'
;
35
const
auto
prefix_size = prefix.size();
36
37
auto
opt = options.upper_bound( prefix );
38
while
( opt != end( options ) && std::string_view( opt->first ).substr( 0, prefix_size ) == prefix ) {
39
GAUDI_ASSERT_THROW_NAME
( prop->setPropertyRepr( opt->first.substr( prefix_size ), opt->second ),
40
"failure setting "
+ opt->first +
" to "
+ opt->second,
"Gaudi::Application"
);
41
// drop processed option and increase iterator
42
opt = options.erase( opt );
43
}
44
}
45
}
// namespace
46
47
Gaudi::Application::Factory::ReturnType
Gaudi::Application::create
( std::string_view type,
Options
opts ) {
48
if
( type ==
"Gaudi::Application"
) {
return
std::make_unique<Application>( std::move( opts ) ); }
49
return
Factory::create( type, std::move( opts ) );
50
}
51
52
Gaudi::Application::Application
(
Gaudi::Application::Options
options )
53
:
// instantiate
54
app
(
Gaudi
::
createApplicationMgr
() ) {
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
}
72
73
Gaudi::Application::~Application
() {
app
->terminate().ignore(); }
74
75
int
Gaudi::Application::run
() {
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
90
setAppReturnCode
( prop,
Gaudi::ReturnCode::GenericFailure
).
ignore
();
91
app
->finalize().ignore();
92
}
else
93
setAppReturnCode
( prop,
Gaudi::ReturnCode::GenericFailure
).
ignore
();
94
return
getAppReturnCode
( prop );
95
}
96
97
namespace
{
98
struct
c_opt_t
{
99
char
* key;
100
char
* value;
101
};
102
}
// namespace
103
104
#ifdef GAUDI_HASCLASSVISIBILITY
105
# pragma GCC visibility push( default )
106
#endif
107
108
extern
"C"
{
109
// helper to invoke the factory from Python
110
Gaudi::Application
*
_py_Gaudi__Application__create
(
const
char
* name,
const
c_opt_t* options,
unsigned
long
n ) {
111
Gaudi::Application::Options
opts;
112
gsl::span py_opts{ options,
static_cast<
std::remove_cv_t<decltype( gsl::dynamic_extent )
>
>( n ) };
113
for
(
auto
& opt : py_opts ) { opts[opt.key] = opt.value; }
114
return
Gaudi::Application::create
( name, std::move( opts ) ).release();
115
}
116
int
_py_Gaudi__Application__run
(
Gaudi::Application
* self ) {
return
self->run(); }
117
void
_py_Gaudi__Application__delete
(
Gaudi::Application
* self ) {
delete
self; }
118
}
119
120
#ifdef GAUDI_HASCLASSVISIBILITY
121
# pragma GCC visibility pop
122
#endif
AppReturnCode.h
_py_Gaudi__Application__delete
void _py_Gaudi__Application__delete(Gaudi::Application *self)
Definition
Application.cpp:117
_py_Gaudi__Application__create
Gaudi::Application * _py_Gaudi__Application__create(const char *name, const c_opt_t *options, unsigned long n)
Definition
Application.cpp:110
_py_Gaudi__Application__run
int _py_Gaudi__Application__run(Gaudi::Application *self)
Definition
Application.cpp:116
GAUDI_ASSERT_THROW_NAME
#define GAUDI_ASSERT_THROW_NAME(cond, msg, name)
Definition
Application.cpp:25
Application.h
Bootstrap.h
Property.h
IAppMgrUI.h
IEventProcessor.h
IMessageSvc.h
INamedInterface.h
IOptionsSvc.h
IProperty.h
ISvcLocator.h
Gaudi.Application
Gaudi application entry point.
Definition
__init__.py:88
Gaudi.Application.create
create(cls, appType, opts)
Definition
__init__.py:127
Gaudi.Application::app
SmartIF< IStateful > app
Handle to the ApplicationMgr instance.
Definition
Application.h:50
Gaudi.Application::~Application
virtual ~Application()
Definition
Application.cpp:73
Gaudi.Application::Options
std::map< std::string, std::string > Options
Definition
Application.h:29
Gaudi.Application::run
virtual int run()
Implement the application main logic:
Definition
Application.cpp:75
Gaudi.Application::Application
Application(Options opts)
Construct and configure the application from the provided options.
Definition
Application.cpp:52
Gaudi::Property
Implementation of property with value of concrete type.
Definition
Property.h:35
Gaudi.c_opt_t
Definition
__init__.py:84
IEventProcessor
The IEventProcessor is the interface to process events.
Definition
IEventProcessor.h:22
IProperty
The IProperty is the basic interface for all components which have properties that can be set or get.
Definition
IProperty.h:32
ISvcLocator
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition
ISvcLocator.h:42
ISvcLocator::getOptsSvc
Gaudi::Interfaces::IOptionsSvc & getOptsSvc()
Direct access to Gaudi::Interfaces::IOptionsSvc implementation.
Definition
ISvcLocator.cpp:17
SmartIF
Small smart pointer class with automatic reference counting for IInterface.
Definition
SmartIF.h:28
SmartIF::as
SmartIF< IFace > as() const
return a new SmartIF instance to another interface
Definition
SmartIF.h:110
StatusCode::ignore
void ignore() const
Allow discarding a StatusCode without warning.
Definition
StatusCode.h:128
Gaudi::ReturnCode::GenericFailure
constexpr int GenericFailure
Definition
AppReturnCode.h:27
Gaudi
This file provides a Grammar for the type Gaudi::Accumulators::Axis It allows to use that type from p...
Definition
__init__.py:1
Gaudi::getAppReturnCode
int getAppReturnCode(const SmartIF< IProperty > &appmgr)
Get the application (current) return code.
Definition
AppReturnCode.h:78
Gaudi::createApplicationMgr
GAUDI_API IAppMgrUI * createApplicationMgr(const std::string &dllname, const std::string &factname)
Gaudi::setAppReturnCode
StatusCode setAppReturnCode(SmartIF< IProperty > &appmgr, int value, bool force=false)
Set the application return code.
Definition
AppReturnCode.h:58
GaudiKernel
src
Lib
Application.cpp
Generated on
for The Gaudi Framework by
1.17.0