| The Gaudi Framework v32r1 (f65d50dc)

Sequence.cpp
Go to the documentation of this file.
1 // This is allow implementation of deprecated methods beginRun and endRun
2 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
3
4 #include "GaudiKernel/IAlgManager.h"
5 #include <Gaudi/Sequence.h>
6
7 using Gaudi::Sequence;
8
9 namespace {
10 template <StatusCode ( Gaudi::Algorithm::*f )(), typename C>
11 bool for_algorithms( C& c ) {
12 return std::accumulate( std::begin( c ), std::end( c ), true,
13 []( bool b, Gaudi::Algorithm* a ) { return ( a->*f )().isSuccess() && b; } );
14 }
15 } // namespace
16
17 StatusCode Sequence::initialize() {
18 if ( !Algorithm::initialize() ) return StatusCode::FAILURE;
19
20 // initialize sub-algorithms
21 if ( !for_algorithms<&Algorithm::sysInitialize>( m_subAlgms ) ) {
22 error() << "error initializing one or several sub-algorithms of Sequence " << name() << endmsg;
23 return StatusCode::FAILURE;
24 }
25
26 return StatusCode::SUCCESS;
27 }
28
29 StatusCode Sequence::finalize() {
30 // Bypass the finalialization if the algorithm hasn't been initilized.
31 // Note: this check is also in Gaudi::Algorithm::sysFinalize
32 if ( Gaudi::StateMachine::CONFIGURED == FSMState() || !isEnabled() ) return StatusCode::SUCCESS;
33
34 // finalize sub-algorithms
35 if ( !for_algorithms<&Algorithm::sysFinalize>( m_subAlgms ) ) {
36 error() << "error finalizing one or several sub-algorithms of Sequence " << name() << endmsg;
37 return StatusCode::FAILURE;
38 }
39
40 // Release all sub-algorithms
41 for ( auto& it : m_subAlgms ) it->release();
42 m_subAlgms.clear();
43
44 return Algorithm::finalize();
45 }
46
47 StatusCode Sequence::start() {
48 if ( !Algorithm::start() ) return StatusCode::FAILURE;
49
50 // start sub-algorithms
51 if ( !for_algorithms<&Algorithm::sysStart>( m_subAlgms ) ) {
52 error() << "error starting one or several sub-algorithms of Sequence " << name() << endmsg;
53 return StatusCode::FAILURE;
54 }
55
56 return StatusCode::SUCCESS;
57 }
58
59 StatusCode Sequence::stop() {
60 // stop sub-algorithms
61 if ( !for_algorithms<&Algorithm::sysStop>( m_subAlgms ) ) {
62 error() << "error stopping one or several sub-algorithms of Sequence " << name() << endmsg;
63 return StatusCode::FAILURE;
64 }
65
66 return Algorithm::stop();
67 }
68
69 StatusCode Sequence::reinitialize() {
70 // re-initialize sub-algorithms
71 if ( !for_algorithms<&Algorithm::sysReinitialize>( m_subAlgms ) ) {
72 error() << "error re-initializing one or several sub-algorithms of Sequence " << name() << endmsg;
73 return StatusCode::FAILURE;
74 }
75
76 return Algorithm::reinitialize();
77 }
78
79 StatusCode Sequence::restart() {
80 // re-start sub-algorithms
81 if ( !for_algorithms<&Algorithm::sysRestart>( m_subAlgms ) ) {
82 error() << "error re-restarting one or several sub-algorithms of Sequence " << name() << endmsg;
83 return StatusCode::FAILURE;
84 }
85
86 return Algorithm::restart();
87 }
88
89 StatusCode Sequence::beginRun() {
90 if ( !Algorithm::beginRun() ) return StatusCode::FAILURE;
91
92 // call beginRun for sub-algorithms
93 if ( !for_algorithms<&Algorithm::sysBeginRun>( m_subAlgms ) ) {
94 error() << "error calling beginRun for one or several sub-algorithms of Sequence " << name() << endmsg;
95 return StatusCode::FAILURE;
96 }
97
98 return StatusCode::SUCCESS;
99 }
100
101 StatusCode Sequence::endRun() {
102 // call endRun for sub-algorithms
103 if ( !for_algorithms<&Algorithm::sysEndRun>( m_subAlgms ) ) {
104 error() << "error calling endRun for one or several sub-algorithms of Sequence " << name() << endmsg;
105 return StatusCode::FAILURE;
106 }
107
108 return Algorithm::endRun();
109 }
110
111 void Sequence::acceptDHVisitor( IDataHandleVisitor* vis ) const {
112 Algorithm::acceptDHVisitor( vis );
113
114 // loop through sub-algs
115 for ( auto alg : *subAlgorithms() ) vis->visit( alg );
116 }
117
118 const std::vector<Gaudi::Algorithm*>* Sequence::subAlgorithms() const { return &m_subAlgms; }
119
120 std::vector<Gaudi::Algorithm*>* Sequence::subAlgorithms() { return &m_subAlgms; }
121
122 StatusCode Sequence::createSubAlgorithm( const std::string& type, const std::string& name, Algorithm*& pSubAlgorithm ) {
123 SmartIF<IAlgManager> am( serviceLocator() );
124 if ( !am ) return StatusCode::FAILURE;
125
126 // Maybe modify the AppMgr interface to return Algorithm* ??
127 IAlgorithm* tmp;
128 StatusCode sc = am->createAlgorithm( type, name, tmp );
129 if ( sc.isFailure() ) return StatusCode::FAILURE;
130
131 try {
132 pSubAlgorithm = dynamic_cast<Algorithm*>( tmp );
133 m_subAlgms.push_back( pSubAlgorithm );
134 } catch ( ... ) { sc = StatusCode::FAILURE; }
135 return sc;
136 }
SmartIF< IAlgManager >
Gaudi::Algorithm::restart
StatusCode restart() override
the default (empty) implementation of IStateful::restart() method
Definition: Algorithm.cpp:630
ManySmallAlgs.alg
alg
Definition: ManySmallAlgs.py:69
gaudirun.c
c
Definition: gaudirun.py:487
Gaudi::StateMachine::CONFIGURED
Definition: StateMachine.h:14
gaudiComponentHelp.name
name
Definition: gaudiComponentHelp.py:41
Gaudi::Algorithm::start
StatusCode start() override
the default (empty) implementation of IStateful::start() method
Definition: Algorithm.h:182
Gaudi::Sequence::endRun
StatusCode endRun() override
endRun method invoked by the framework.
Definition: Sequence.cpp:101
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:85
Sequence.h
IAlgManager::createAlgorithm
virtual StatusCode createAlgorithm(const std::string &algtype, const std::string &algname, IAlgorithm *&alg, bool managed=false, bool checkIfExists=true)=0
Create an instance of a algorithm type that has been declared beforehand and assigns to it a name.
std::end
T end(T... args)
Gaudi::Algorithm::serviceLocator
SmartIF< ISvcLocator > & serviceLocator() const override
The standard service locator.
Definition: Algorithm.cpp:689
Gaudi::Sequence::stop
StatusCode stop() override
System stop.
Definition: Sequence.cpp:59
std::string
STL class.
Gaudi::Sequence::reinitialize
StatusCode reinitialize() override
Reinitialization method invoked by the framework.
Definition: Sequence.cpp:69
IDataHandleVisitor::visit
virtual void visit(const IDataHandleHolder *)=0
Gaudi::Algorithm::initialize
StatusCode initialize() override
the default (empty) implementation of IStateful::initialize() method
Definition: Algorithm.h:180
CommonMessagingBase::error
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
Definition: CommonMessaging.h:98
Gaudi::Sequence::createSubAlgorithm
StatusCode createSubAlgorithm(const std::string &type, const std::string &name, Algorithm *&pSubAlg)
Create a sub algorithm.
Definition: Sequence.cpp:122
Gaudi::Sequence::m_subAlgms
std::vector< Algorithm * > m_subAlgms
Sub algorithms.
Definition: Sequence.h:88
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:50
Gaudi::Algorithm::type
const std::string & type() const override
The type of the algorithm object.
Definition: Algorithm.h:167
gaudirun.type
type
Definition: gaudirun.py:142
Gaudi::Algorithm::finalize
StatusCode finalize() override
the default (empty) implementation of IStateful::finalize() method
Definition: Algorithm.h:186
Gaudi::Sequence::finalize
StatusCode finalize() override
System finalization.
Definition: Sequence.cpp:29
IAlgorithm
The IAlgorithm is the interface implemented by the Algorithm base class.
Definition: IAlgorithm.h:28
Gaudi::Algorithm::beginRun
StatusCode beginRun() override
Algorithm begin run.
Definition: Algorithm.cpp:380
IDataHandleVisitor
Definition: IDataHandleHolder.h:35
Gaudi::Algorithm::reinitialize
StatusCode reinitialize() override
the default (empty) implementation of IStateful::reinitialize() method
Definition: Algorithm.cpp:610
std::vector< Gaudi::Algorithm * >
Gaudi::Sequence::acceptDHVisitor
void acceptDHVisitor(IDataHandleVisitor *) const override
Definition: Sequence.cpp:111
Gaudi::Algorithm::acceptDHVisitor
void acceptDHVisitor(IDataHandleVisitor *) const override
Definition: Algorithm.cpp:194
std::begin
T begin(T... args)
Gaudi::Sequence::subAlgorithms
const std::vector< Algorithm * > * subAlgorithms() const
List of sub-algorithms. Returns a pointer to a vector of (sub) Algorithms.
Definition: Sequence.cpp:118
Gaudi::Sequence::start
StatusCode start() override
System start.
Definition: Sequence.cpp:47
Gaudi::Sequence::restart
StatusCode restart() override
Restart method invoked by the framework.
Definition: Sequence.cpp:79
Gaudi::Algorithm
Base class from which all concrete algorithm classes should be derived.
Definition: Algorithm.h:79
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition: StatusCode.h:86
Gaudi::Algorithm::FSMState
Gaudi::StateMachine::State FSMState() const override
returns the current state of the algorithm
Definition: Algorithm.h:192
IAlgManager.h
StatusCode::isFailure
bool isFailure() const
Definition: StatusCode.h:130
std::accumulate
T accumulate(T... args)
Gaudi::Algorithm::isEnabled
bool isEnabled() const override
Is this algorithm enabled or disabled?
Definition: Algorithm.cpp:655
Gaudi::Algorithm::endRun
StatusCode endRun() override
Algorithm end run. This method is called at the end of the event loop.
Definition: Algorithm.cpp:432
Gaudi::Algorithm::stop
StatusCode stop() override
the default (empty) implementation of IStateful::stop() method
Definition: Algorithm.h:184
Gaudi::Sequence
Definition: Sequence.h:8
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:192
Gaudi::Sequence::beginRun
StatusCode beginRun() override
beginRun method invoked by the framework.
Definition: Sequence.cpp:89
Gaudi::Algorithm::name
const std::string & name() const override
The identifying name of the algorithm object.
Definition: Algorithm.cpp:645