The Gaudi Framework  master (37c0b60a)
Sequence.cpp
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2024 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/Sequence.h>
13 
14 using Gaudi::Sequence;
15 
16 namespace {
17  template <StatusCode ( Gaudi::Algorithm::*f )(), typename C>
18  bool for_algorithms( C& c ) {
19  return std::accumulate( std::begin( c ), std::end( c ), true,
20  []( bool b, Gaudi::Algorithm* a ) { return ( a->*f )().isSuccess() && b; } );
21  }
22 } // namespace
23 
24 StatusCode Sequence::initialize() {
26 
27  // initialize sub-algorithms
28  if ( !for_algorithms<&Algorithm::sysInitialize>( m_subAlgms ) ) {
29  error() << "error initializing one or several sub-algorithms of Sequence " << name() << endmsg;
30  return StatusCode::FAILURE;
31  }
32 
33  return StatusCode::SUCCESS;
34 }
35 
37  // Bypass the finalialization if the algorithm hasn't been initilized.
38  // Note: this check is also in Gaudi::Algorithm::sysFinalize
40 
41  // finalize sub-algorithms
42  if ( !for_algorithms<&Algorithm::sysFinalize>( m_subAlgms ) ) {
43  error() << "error finalizing one or several sub-algorithms of Sequence " << name() << endmsg;
44  return StatusCode::FAILURE;
45  }
46 
47  // Release all sub-algorithms
48  for ( auto& it : m_subAlgms ) it->release();
49  m_subAlgms.clear();
50 
51  return Algorithm::finalize();
52 }
53 
55  if ( !Algorithm::start() ) return StatusCode::FAILURE;
56 
57  // start sub-algorithms
58  if ( !for_algorithms<&Algorithm::sysStart>( m_subAlgms ) ) {
59  error() << "error starting one or several sub-algorithms of Sequence " << name() << endmsg;
60  return StatusCode::FAILURE;
61  }
62 
63  return StatusCode::SUCCESS;
64 }
65 
67  // stop sub-algorithms
68  if ( !for_algorithms<&Algorithm::sysStop>( m_subAlgms ) ) {
69  error() << "error stopping one or several sub-algorithms of Sequence " << name() << endmsg;
70  return StatusCode::FAILURE;
71  }
72 
73  return Algorithm::stop();
74 }
75 
77  // re-initialize sub-algorithms
78  if ( !for_algorithms<&Algorithm::sysReinitialize>( m_subAlgms ) ) {
79  error() << "error re-initializing one or several sub-algorithms of Sequence " << name() << endmsg;
80  return StatusCode::FAILURE;
81  }
82 
83  return Algorithm::reinitialize();
84 }
85 
87  // re-start sub-algorithms
88  if ( !for_algorithms<&Algorithm::sysRestart>( m_subAlgms ) ) {
89  error() << "error re-restarting one or several sub-algorithms of Sequence " << name() << endmsg;
90  return StatusCode::FAILURE;
91  }
92 
93  return Algorithm::restart();
94 }
95 
98 
99  // loop through sub-algs
100  for ( auto alg : *subAlgorithms() ) vis->visit( alg );
101 }
102 
104 
106 
109  if ( !am ) return StatusCode::FAILURE;
110 
111  // Maybe modify the AppMgr interface to return Algorithm* ??
112  IAlgorithm* tmp;
113  StatusCode sc = am->createAlgorithm( type, name, tmp );
114  if ( sc.isFailure() ) return StatusCode::FAILURE;
115 
116  try {
117  pSubAlgorithm = dynamic_cast<Algorithm*>( tmp );
118  m_subAlgms.push_back( pSubAlgorithm );
119  } catch ( ... ) { sc = StatusCode::FAILURE; }
120  return sc;
121 }
IAlgManager.h
std::string
STL class.
Gaudi::Algorithm::acceptDHVisitor
void acceptDHVisitor(IDataHandleVisitor *) const override
Definition: Algorithm.cpp:186
Gaudi::Algorithm::name
const std::string & name() const override
The identifying name of the algorithm object.
Definition: Algorithm.cpp:526
Gaudi::Sequence::createSubAlgorithm
StatusCode createSubAlgorithm(const std::string &type, const std::string &name, Algorithm *&pSubAlg)
Create a sub algorithm.
Definition: Sequence.cpp:107
Gaudi::Algorithm::type
const std::string & type() const override
The type of the algorithm object.
Definition: Algorithm.h:165
std::vector< Gaudi::Algorithm * >
Gaudi::Algorithm::initialize
StatusCode initialize() override
the default (empty) implementation of IStateful::initialize() method
Definition: Algorithm.h:178
Gaudi::Algorithm::serviceLocator
SmartIF< ISvcLocator > & serviceLocator() const override
The standard service locator.
Definition: Algorithm.cpp:570
Gaudi::Sequence::finalize
StatusCode finalize() override
System finalization.
Definition: Sequence.cpp:36
gaudirun.c
c
Definition: gaudirun.py:525
Gaudi::Sequence::stop
StatusCode stop() override
System stop.
Definition: Sequence.cpp:66
Gaudi::Algorithm::start
StatusCode start() override
the default (empty) implementation of IStateful::start() method
Definition: Algorithm.h:180
Gaudi::Sequence::start
StatusCode start() override
System start.
Definition: Sequence.cpp:54
ManySmallAlgs.alg
alg
Definition: ManySmallAlgs.py:81
Gaudi::Sequence::m_subAlgms
std::vector< Algorithm * > m_subAlgms
Sub algorithms.
Definition: Sequence.h:84
Gaudi::Algorithm::isEnabled
bool isEnabled() const override
Is this algorithm enabled or disabled?
Definition: Algorithm.cpp:536
Gaudi::StateMachine::CONFIGURED
@ CONFIGURED
Definition: StateMachine.h:24
StatusCode
Definition: StatusCode.h:65
IAlgorithm
Definition: IAlgorithm.h:38
Gaudi::Algorithm::FSMState
Gaudi::StateMachine::State FSMState() const override
returns the current state of the algorithm
Definition: Algorithm.h:190
Gaudi::Algorithm
Base class from which all concrete algorithm classes should be derived.
Definition: Algorithm.h:90
Gaudi::Sequence::acceptDHVisitor
void acceptDHVisitor(IDataHandleVisitor *) const override
Definition: Sequence.cpp:96
std::accumulate
T accumulate(T... args)
SmartIF< IAlgManager >
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:202
IDataHandleVisitor
Definition: IDataHandleHolder.h:46
StatusCode::isFailure
bool isFailure() const
Definition: StatusCode.h:129
gaudirun.type
type
Definition: gaudirun.py:160
Gaudi::Algorithm::finalize
StatusCode finalize() override
the default (empty) implementation of IStateful::finalize() method
Definition: Algorithm.h:184
ConditionsStallTest.name
name
Definition: ConditionsStallTest.py:77
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:100
std::begin
T begin(T... args)
Gaudi::Algorithm::restart
StatusCode restart() override
the default (empty) implementation of IStateful::restart() method
Definition: Algorithm.cpp:511
Sequence.h
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:103
Gaudi::Sequence::restart
StatusCode restart() override
Restart method invoked by the framework.
Definition: Sequence.cpp:86
std::end
T end(T... args)
Gaudi::Algorithm::reinitialize
StatusCode reinitialize() override
the default (empty) implementation of IStateful::reinitialize() method
Definition: Algorithm.cpp:491
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition: StatusCode.h:101
Gaudi::Sequence
Definition: Sequence.h:18
Gaudi::Algorithm::stop
StatusCode stop() override
the default (empty) implementation of IStateful::stop() method
Definition: Algorithm.h:182
IDataHandleVisitor::visit
virtual void visit(const IDataHandleHolder *)=0
Gaudi::Sequence::reinitialize
StatusCode reinitialize() override
Reinitialization method invoked by the framework.
Definition: Sequence.cpp:76