6 #include "GaudiAlg/Sequencer.h"
8 #include "GaudiKernel/IAlgManager.h"
9 #include "GaudiKernel/ISvcLocator.h"
10 #include "GaudiKernel/MsgStream.h"
11 #include "GaudiKernel/Chrono.h"
12 #include "GaudiKernel/Stat.h"
13 #include "GaudiKernel/GaudiException.h"
15 #define ON_DEBUG if (UNLIKELY(outputLevel() <= MSG::DEBUG))
16 #define ON_VERBOSE if (UNLIKELY(outputLevel() <= MSG::VERBOSE))
44 log <<
MSG::ERROR <<
"Unable to configure one or more sequencer members " <<
endmsg;
49 log <<
MSG::ERROR <<
"Unable to configure one or more branch members " <<
endmsg;
55 result = alg->sysInitialize( );
57 log <<
MSG::ERROR <<
"Unable to initialize Algorithm " << alg->name() <<
endmsg;
64 result = alg->sysInitialize( );
66 log <<
MSG::ERROR <<
"Unable to initialize Algorithm " << alg->name() <<
endmsg;
83 if ( alg->isEnabled( ) ) alg->reinitialize( ).
ignore();
88 if ( alg->isEnabled( ) ) {
89 alg->reinitialize( ).ignore();
119 if ( !theAlgs.empty( ) ) {
121 if ( lastAlgorithm == branchAlgorithm ) {
153 if (alg->sysFinalize( ).isFailure()) {
155 log <<
MSG::ERROR <<
"Unable to finalize Algorithm "
171 result = alg->sysStart( );
180 result = alg->sysStart( );
197 if (alg->sysStop( ).isFailure()) {
199 log <<
MSG::ERROR <<
"Unable to stop Algorithm "
205 if (alg->sysStop( ).isFailure()) {
207 log <<
MSG::ERROR <<
"Unable to stop Algorithm "
228 result = alg->sysInitialize( );
230 log <<
MSG::ERROR <<
"Unable to initialize Algorithm " << alg->name() <<
endmsg;
233 result = alg->sysStart( );
243 if ( ! alg->isEnabled( ) ) {
244 alg->beginRun( ).ignore();
253 result = alg->sysInitialize( );
255 log <<
MSG::ERROR <<
"Unable to initialize Algorithm " << alg->name() <<
endmsg;
258 result = alg->sysStart( );
268 if ( ! alg->isEnabled( ) ) {
269 alg->beginRun( ).ignore();
285 if ( ! alg->isEnabled( ) ) alg->endRun( ).
ignore();
290 if ( ! alg->isEnabled( ) ) alg->endRun( ).ignore();
346 const std::string&
name,
354 const std::string&
name,
363 return remove( pAlgorithm->
name( ) );
384 const std::vector<Algorithm*>&
389 std::vector<Algorithm*>&
430 std::vector<Algorithm*>& theAlgs )
436 theAlgs.push_back( pAlgorithm );
443 const std::string& algName,
445 std::vector<Algorithm*>& theAlgs )
452 StatusCode result = theAlgMgr->createAlgorithm( type, algName, tmp );
455 pAlgorithm =
dynamic_cast<Algorithm*
>(tmp);
456 theAlgs.push_back( pAlgorithm );
468 std::vector<Algorithm*>& theAlgs,
469 std::vector<bool>& theLogic )
480 for (
const auto&
n : theNames.
value() ) {
489 std::string theName = typeName.
name();
490 std::string theType = typeName.
type();
498 bool isInverted =
false;
499 std::string::size_type invert = theName.find_first_of(
":" );
501 while ( std::string::npos != invert
502 && invert < (theName.size() - 1) && theName[invert+1] ==
':' )
503 invert = theName.find_first_of(
":", invert+2 );
504 if ( std::string::npos != invert ) {
505 if ( theName == theType ) {
508 theType = theType.substr( 0, invert );
510 theName = theName.substr( 0, invert );
522 log <<
MSG::WARNING << theName <<
" is not an Algorithm - Failed dynamic cast" <<
endmsg;
523 theAlgorithm =
nullptr;
526 if ( theAlgorithm ) {
529 status =
append( theAlgorithm, theAlgs );
548 if ( status.
isSuccess( ) ) theLogic.push_back( isInverted );
553 if ( result.
isSuccess() && theAlgs.size() != 0 ) {
555 auto ai = theAlgs.begin();
556 auto li = theLogic.begin();
557 for ( ; ai != theAlgs.end(); ++ai, ++li ) {
559 if ( ai != theAlgs.begin() ) log <<
", ";
566 if (*li) log <<
":invert";
575 std::vector<bool>& theLogic,
585 unsigned int size = theAlgs.size( );
586 for (
unsigned int i = first;
i < size;
i++) {
587 lastAlgorithm = theAlgs[
i];
594 bool isInverted = theLogic[
i];
595 if ( isInverted ) passed = ! passed;
602 if ( ! passed )
break;
634 for (
auto& alg : theAlgs ) {
635 if ( alg->name( ) == algname ) {
639 log <<
MSG::INFO <<
"Sequencer::remove( ) isn't implemented yet!!!!!" <<
endmsg;
std::vector< bool > m_isBranchInverted
void resetExecuted() override
Reset the executed state of the Algorithm for the duration of the current event.
virtual bool isStopOverride() const
Has the StopOverride mode been set?
StatusCode append(Algorithm *pAlgorithm)
Append an algorithm to the sequencer.
Definition of the MsgStream class used to transmit messages.
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
StatusCode remove(Algorithm *pAlgorithm)
Remove the specified algorithm from the sequencer.
SmartIF< ISvcLocator > & serviceLocator() const
The standard service locator.
StatusCode removeFromBranch(Algorithm *pAlgorithm)
virtual Property & declareUpdateHandler(std::function< void(Property &)> fun)
set new callback for update
bool isSuccess() const
Test for a status code of SUCCESS.
auto begin(reverse_wrapper< T > &w)
Sequencer(const std::string &name, ISvcLocator *svcloc)
Constructor(s)
GAUDI_API const std::string typeinfoName(const std::type_info &)
Get platform independent information about the class type.
The IAlgManager is the interface implemented by the Algorithm Factory in the Application Manager to s...
virtual bool branchFilterPassed() const
additional interface methods
Property * declareProperty(const std::string &name, T &property, const std::string &doc="none") const
Declare the named property.
StatusCode stop() override
Sequencer finalization.
void branchMembershipHandler(Property &theProp)
"BranchMembers" property handler
bool filterPassed() const override
Did this algorithm pass or fail its filter criterion for the last event?
bool m_branchFilterPassed
BooleanProperty m_stopOverride
StatusCode reinitialize() override
Sequencer Reinitialization.
StatusCode beginRun() override
Sequencer beginRun.
const std::vector< Algorithm * > & branchAlgorithms() const
List of branch algorithms.
StatusCode executeMember(Algorithm *theAlgorithm)
Execute member algorithm.
bool isFailure() const
Test for a status code of FAILURE.
StringArrayProperty m_branchNames
StatusCode decodeBranchMemberNames()
Decode branch member name list.
const std::string & name() const override
The identifying name of the algorithm object.
TYPE * get() const
Get interface pointer.
virtual StatusCode setBranchFilterPassed(bool state)
Set the branch filter passed flag for the last event.
StatusCode service(const Gaudi::Utils::TypeNameString &name, T *&svc, bool createIf=true)
Templated method to access a service by name.
StatusCode decodeNames(StringArrayProperty &theNames, std::vector< Algorithm * > &theAlgs, std::vector< bool > &theLogic)
Decode algorithm names, creating or appending algorithms as appropriate.
Helper class to parse a string of format "type/name".
void setExecuted(bool state) override
Set the executed flag to the specified state.
StatusCode execute() override
The actions to be performed by the sequencer on an event.
StatusCode decodeMemberNames()
Decode Member Name list.
StatusCode createAndAppendToBranch(const std::string &type, const std::string &name, Algorithm *&pAlgorithm)
Create a algorithm and append it to the sequencer branch.
unsigned long addRef() override
Reference Interface instance.
auto end(reverse_wrapper< T > &w)
This class is used for returning status codes from appropriate routines.
StatusCode sysExecute() override
The actions to be performed by the algorithm on an event.
bool isExecuted() const override
Has this algorithm been executed since the last reset?
The IAlgorithm is the interface implemented by the Algorithm base class.
const TYPE & value() const
explicit conversion
const std::vector< Algorithm * > * subAlgorithms() const
List of sub-algorithms. Returns a pointer to a vector of (sub) Algorithms.
Base class from which all concrete algorithm classes should be derived.
Property base class allowing Property* collections to be "homogeneous".
void membershipHandler(Property &theProp)
"Members" property handler
StatusCode endRun() override
Sequencer endRun.
bool isInitialized() const override
Has the Algorithm already been initialized?
std::vector< bool > m_isInverted
StatusCode createAndAppend(const std::string &type, const std::string &name, Algorithm *&pAlgorithm)
Create a algorithm and append it to the sequencer.
bool isEnabled() const override
Is this algorithm enabled or disabled?
const std::string & type() const
StatusCode appendToBranch(Algorithm *pAlgorithm)
Append an algorithm to the sequencer branch.
StringArrayProperty m_names
StatusCode finalize() override
Sequencer finalization.
StatusCode initialize() override
Initialization of a sequencer.
std::vector< Algorithm * > m_branchAlgs
const std::string & name() const
std::string typeName(const std::type_info &typ)
SmartIF< IMessageSvc > & msgSvc() const
The standard message service.
void setFilterPassed(bool state) override
Set the filter passed flag to the specified state.
void resetExecuted() override
Reset the Sequencer executed state for the current event.
StatusCode start() override
Sequencer finalization.