Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  master (f31105fd)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
Sequence.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/Sequence.h>
13 
14 #include <numeric>
15 #include <string>
16 #include <vector>
17 
18 using Gaudi::Sequence;
19 
20 namespace {
21  template <StatusCode ( Gaudi::Algorithm::*f )(), typename C>
22  bool for_algorithms( C& c ) {
23  return std::accumulate( std::begin( c ), std::end( c ), true,
24  []( bool b, Gaudi::Algorithm* a ) { return ( a->*f )().isSuccess() && b; } );
25  }
26 } // namespace
27 
28 StatusCode Sequence::initialize() {
30 
31  // initialize sub-algorithms
32  if ( !for_algorithms<&Algorithm::sysInitialize>( m_subAlgms ) ) {
33  error() << "error initializing one or several sub-algorithms of Sequence " << name() << endmsg;
34  return StatusCode::FAILURE;
35  }
36 
37  return StatusCode::SUCCESS;
38 }
39 
41  // Bypass the finalialization if the algorithm hasn't been initilized.
42  // Note: this check is also in Gaudi::Algorithm::sysFinalize
44 
45  // finalize sub-algorithms
46  if ( !for_algorithms<&Algorithm::sysFinalize>( m_subAlgms ) ) {
47  error() << "error finalizing one or several sub-algorithms of Sequence " << name() << endmsg;
48  return StatusCode::FAILURE;
49  }
50 
51  // Release all sub-algorithms
52  for ( auto& it : m_subAlgms ) it->release();
53  m_subAlgms.clear();
54 
55  return Algorithm::finalize();
56 }
57 
59  if ( !Algorithm::start() ) return StatusCode::FAILURE;
60 
61  // start sub-algorithms
62  if ( !for_algorithms<&Algorithm::sysStart>( m_subAlgms ) ) {
63  error() << "error starting one or several sub-algorithms of Sequence " << name() << endmsg;
64  return StatusCode::FAILURE;
65  }
66 
67  return StatusCode::SUCCESS;
68 }
69 
71  // stop sub-algorithms
72  if ( !for_algorithms<&Algorithm::sysStop>( m_subAlgms ) ) {
73  error() << "error stopping one or several sub-algorithms of Sequence " << name() << endmsg;
74  return StatusCode::FAILURE;
75  }
76 
77  return Algorithm::stop();
78 }
79 
81  // re-initialize sub-algorithms
82  if ( !for_algorithms<&Algorithm::sysReinitialize>( m_subAlgms ) ) {
83  error() << "error re-initializing one or several sub-algorithms of Sequence " << name() << endmsg;
84  return StatusCode::FAILURE;
85  }
86 
87  return Algorithm::reinitialize();
88 }
89 
91  // re-start sub-algorithms
92  if ( !for_algorithms<&Algorithm::sysRestart>( m_subAlgms ) ) {
93  error() << "error re-restarting one or several sub-algorithms of Sequence " << name() << endmsg;
94  return StatusCode::FAILURE;
95  }
96 
97  return Algorithm::restart();
98 }
99 
102 
103  // loop through sub-algs
104  for ( auto alg : *subAlgorithms() ) vis->visit( alg );
105 }
106 
108 
110 
113  if ( !am ) return StatusCode::FAILURE;
114 
115  // Maybe modify the AppMgr interface to return Algorithm* ??
116  IAlgorithm* tmp;
117  StatusCode sc = am->createAlgorithm( type, name, tmp );
118  if ( sc.isFailure() ) return StatusCode::FAILURE;
119 
120  try {
121  pSubAlgorithm = dynamic_cast<Algorithm*>( tmp );
122  m_subAlgms.push_back( pSubAlgorithm );
123  } catch ( ... ) { sc = StatusCode::FAILURE; }
124  return sc;
125 }
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:111
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:40
gaudirun.c
c
Definition: gaudirun.py:525
Gaudi::Sequence::stop
StatusCode stop() override
System stop.
Definition: Sequence.cpp:70
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:58
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:100
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:130
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:107
Gaudi::Sequence::restart
StatusCode restart() override
Restart method invoked by the framework.
Definition: Sequence.cpp:90
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:80