The Gaudi Framework  master (82fdf313)
Loading...
Searching...
No Matches
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
18using Gaudi::Sequence;
19
20namespace {
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
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;
35 }
36
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;
49 }
50
51 m_subAlgms.clear();
52
53 return Algorithm::finalize();
54}
55
58
59 // start sub-algorithms
60 if ( !for_algorithms<&Algorithm::sysStart>( m_subAlgms ) ) {
61 error() << "error starting one or several sub-algorithms of Sequence " << name() << endmsg;
63 }
64
66}
67
69 // stop sub-algorithms
70 if ( !for_algorithms<&Algorithm::sysStop>( m_subAlgms ) ) {
71 error() << "error stopping one or several sub-algorithms of Sequence " << name() << endmsg;
73 }
74
75 return Algorithm::stop();
76}
77
79 // re-initialize sub-algorithms
80 if ( !for_algorithms<&Algorithm::sysReinitialize>( m_subAlgms ) ) {
81 error() << "error re-initializing one or several sub-algorithms of Sequence " << name() << endmsg;
83 }
84
86}
87
89 // re-start sub-algorithms
90 if ( !for_algorithms<&Algorithm::sysRestart>( m_subAlgms ) ) {
91 error() << "error re-restarting one or several sub-algorithms of Sequence " << name() << endmsg;
93 }
94
95 return Algorithm::restart();
96}
97
100
101 // loop through sub-algs
102 for ( auto alg : *subAlgorithms() ) vis->visit( alg );
103}
104
105const std::vector<Gaudi::Algorithm*>* Sequence::subAlgorithms() const { return &m_subAlgms; }
106
107std::vector<Gaudi::Algorithm*>* Sequence::subAlgorithms() { return &m_subAlgms; }
108
109StatusCode Sequence::createSubAlgorithm( const std::string& type, const std::string& name, Algorithm*& pSubAlgorithm ) {
111 if ( !am ) return StatusCode::FAILURE;
112
113 // Maybe modify the AppMgr interface to return Algorithm* ??
114 IAlgorithm* tmp;
115 StatusCode sc = am->createAlgorithm( type, name, tmp );
116 if ( sc.isFailure() ) return StatusCode::FAILURE;
117
118 try {
119 pSubAlgorithm = dynamic_cast<Algorithm*>( tmp );
120 m_subAlgms.push_back( pSubAlgorithm );
121 } catch ( ... ) { sc = StatusCode::FAILURE; }
122 return sc;
123}
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition MsgStream.h:198
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
Base class from which all concrete algorithm classes should be derived.
Definition Algorithm.h:87
StatusCode restart() override
the default (empty) implementation of IStateful::restart() method
void acceptDHVisitor(IDataHandleVisitor *) const override
Gaudi::StateMachine::State FSMState() const override
returns the current state of the algorithm
Definition Algorithm.h:187
StatusCode initialize() override
the default (empty) implementation of IStateful::initialize() method
Definition Algorithm.h:175
StatusCode finalize() override
the default (empty) implementation of IStateful::finalize() method
Definition Algorithm.h:181
SmartIF< ISvcLocator > & serviceLocator() const override
The standard service locator.
StatusCode stop() override
the default (empty) implementation of IStateful::stop() method
Definition Algorithm.h:179
const std::string & name() const override
The identifying name of the algorithm object.
StatusCode reinitialize() override
the default (empty) implementation of IStateful::reinitialize() method
const std::string & type() const override
The type of the algorithm object.
Definition Algorithm.h:162
bool isEnabled() const override
Is this algorithm enabled or disabled?
StatusCode start() override
the default (empty) implementation of IStateful::start() method
Definition Algorithm.h:177
StatusCode finalize() override
System finalization.
Definition Sequence.cpp:40
StatusCode start() override
System start.
Definition Sequence.cpp:56
StatusCode reinitialize() override
Reinitialization method invoked by the framework.
Definition Sequence.cpp:78
Algorithm(std::string name, ISvcLocator *svcloc, std::string version=PACKAGE_VERSION)
Constructor.
Definition Algorithm.h:98
StatusCode createSubAlgorithm(const std::string &type, const std::string &name, Algorithm *&pSubAlg)
Create a sub algorithm.
Definition Sequence.cpp:109
StatusCode restart() override
Restart method invoked by the framework.
Definition Sequence.cpp:88
const std::vector< Algorithm * > * subAlgorithms() const
List of sub-algorithms. Returns a pointer to a vector of (sub) Algorithms.
Definition Sequence.cpp:105
void acceptDHVisitor(IDataHandleVisitor *) const override
Definition Sequence.cpp:98
StatusCode stop() override
System stop.
Definition Sequence.cpp:68
std::vector< Algorithm * > m_subAlgms
Sub algorithms.
Definition Sequence.h:84
The IAlgorithm is the interface implemented by the Algorithm base class.
Definition IAlgorithm.h:36
virtual void visit(const IDataHandleHolder *)=0
StatusCode initialize() override
Initialization method invoked by the framework.
Definition Sequence.cpp:28
Small smart pointer class with automatic reference counting for IInterface.
Definition SmartIF.h:28
This class is used for returning status codes from appropriate routines.
Definition StatusCode.h:64
bool isFailure() const
Definition StatusCode.h:129
constexpr static const auto SUCCESS
Definition StatusCode.h:99
constexpr static const auto FAILURE
Definition StatusCode.h:100