Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  v31r0 (aeb156f0)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 
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() {
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 
30  // Bypass the finalialization if the algorithm hasn't been initilized.
31  // Note: this check is also in Gaudi::Algorithm::sysFinalize
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 
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 
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 
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 
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 
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 
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 
113 
114  // loop through sub-algs
115  for ( auto alg : *subAlgorithms() ) vis->visit( alg );
116 }
117 
119 
121 
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 }
bool isEnabled() const override
Is this algorithm enabled or disabled?
Definition: Algorithm.cpp:645
StatusCode restart() override
the default (empty) implementation of IStateful::restart() method
Definition: Algorithm.cpp:620
StatusCode start() override
the default (empty) implementation of IStateful::start() method
Definition: Algorithm.h:182
const std::string & name() const override
The identifying name of the algorithm object.
Definition: Algorithm.cpp:635
void acceptDHVisitor(IDataHandleVisitor *) const override
Definition: Algorithm.cpp:194
StatusCode endRun() override
endRun method invoked by the framework.
Definition: Sequence.cpp:101
constexpr static const auto SUCCESS
Definition: StatusCode.h:85
T end(T...args)
StatusCode stop() override
System stop.
Definition: Sequence.cpp:59
bool isFailure() const
Definition: StatusCode.h:130
STL class.
StatusCode reinitialize() override
Reinitialization method invoked by the framework.
Definition: Sequence.cpp:69
virtual void visit(const IDataHandleHolder *)=0
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
StatusCode initialize() override
the default (empty) implementation of IStateful::initialize() method
Definition: Algorithm.h:180
StatusCode createSubAlgorithm(const std::string &type, const std::string &name, Algorithm *&pSubAlg)
Create a sub algorithm.
Definition: Sequence.cpp:122
std::vector< Algorithm * > m_subAlgms
Sub algorithms.
Definition: Sequence.h:88
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:50
const std::vector< Algorithm * > * subAlgorithms() const
List of sub-algorithms. Returns a pointer to a vector of (sub) Algorithms.
Definition: Sequence.cpp:118
Gaudi::StateMachine::State FSMState() const override
returns the current state of the algorithm
Definition: Algorithm.h:192
StatusCode finalize() override
the default (empty) implementation of IStateful::finalize() method
Definition: Algorithm.h:186
StatusCode finalize() override
System finalization.
Definition: Sequence.cpp:29
The IAlgorithm is the interface implemented by the Algorithm base class.
Definition: IAlgorithm.h:28
StatusCode beginRun() override
Algorithm begin run.
Definition: Algorithm.cpp:380
const std::string & type() const override
The type of the algorithm object.
Definition: Algorithm.h:167
StatusCode reinitialize() override
the default (empty) implementation of IStateful::reinitialize() method
Definition: Algorithm.cpp:600
T begin(T...args)
StatusCode start() override
System start.
Definition: Sequence.cpp:47
StatusCode restart() override
Restart method invoked by the framework.
Definition: Sequence.cpp:79
Base class from which all concrete algorithm classes should be derived.
Definition: Algorithm.h:79
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...
constexpr static const auto FAILURE
Definition: StatusCode.h:86
SmartIF< ISvcLocator > & serviceLocator() const override
The standard service locator.
Definition: Algorithm.cpp:679
T accumulate(T...args)
StatusCode endRun() override
Algorithm end run. This method is called at the end of the event loop.
Definition: Algorithm.cpp:432
StatusCode stop() override
the default (empty) implementation of IStateful::stop() method
Definition: Algorithm.h:184
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:192
StatusCode beginRun() override
beginRun method invoked by the framework.
Definition: Sequence.cpp:89
void acceptDHVisitor(IDataHandleVisitor *) const override
Definition: Sequence.cpp:111