The Gaudi Framework  v36r9p1 (5c15b2bb)
Sequencer Class Reference

ClassName: Sequencer. More...

#include </builds/gaudi/Gaudi/GaudiAlg/include/GaudiAlg/Sequencer.h>

Inheritance diagram for Sequencer:
Collaboration diagram for Sequencer:

Public Member Functions

StatusCode initialize () override
 Initialization of a sequencer. More...
 
StatusCode reinitialize () override
 Sequencer Reinitialization. More...
 
StatusCode start () override
 Sequencer finalization. More...
 
StatusCode execute (const EventContext &ctx) const override
 The actions to be performed by the sequencer on an event. More...
 
StatusCode stop () override
 Sequencer finalization. More...
 
StatusCode finalize () override
 Sequencer finalization. More...
 
bool branchFilterPassed (const EventContext &ctx) const
 additional interface methods More...
 
void setBranchFilterPassed (const EventContext &ctx, bool state) const
 Set the branch filter passed flag for the last event. More...
 
virtual bool isStopOverride () const
 Has the StopOverride mode been set? More...
 
StatusCode append (Gaudi::Algorithm *pAlgorithm)
 Append an algorithm to the sequencer. More...
 
StatusCode appendToBranch (Gaudi::Algorithm *pAlgorithm)
 Append an algorithm to the sequencer branch. More...
 
StatusCode createAndAppend (const std::string &type, const std::string &name, Gaudi::Algorithm *&pAlgorithm)
 Create a algorithm and append it to the sequencer. More...
 
StatusCode createAndAppendToBranch (const std::string &type, const std::string &name, Gaudi::Algorithm *&pAlgorithm)
 Create a algorithm and append it to the sequencer branch. More...
 
StatusCode remove (Gaudi::Algorithm *pAlgorithm)
 Remove the specified algorithm from the sequencer. More...
 
StatusCode remove (const std::string &name)
 
StatusCode removeFromBranch (Gaudi::Algorithm *pAlgorithm)
 
StatusCode removeFromBranch (const std::string &name)
 
const std::vector< Gaudi::Algorithm * > & branchAlgorithms () const
 List of branch algorithms. More...
 
std::vector< Gaudi::Algorithm * > & branchAlgorithms ()
 
StatusCode decodeMemberNames ()
 Decode Member Name list. More...
 
StatusCode decodeBranchMemberNames ()
 Decode branch member name list. More...
 
std::ostreamtoControlFlowExpression (std::ostream &os) const override
 Produce string represention of the control flow expression. More...
 
- Public Member Functions inherited from Gaudi::Sequence
bool isSequence () const override final
 Are we a Sequence? More...
 
StatusCode createSubAlgorithm (const std::string &type, const std::string &name, Algorithm *&pSubAlg)
 Create a sub algorithm. More...
 
const std::vector< Algorithm * > * subAlgorithms () const
 List of sub-algorithms. Returns a pointer to a vector of (sub) Algorithms. More...
 
std::vector< Algorithm * > * subAlgorithms ()
 List of sub-algorithms. Returns a pointer to a vector of (sub) Algorithms. More...
 
StatusCode start () override
 System start. More...
 
StatusCode initialize () override
 Initialization method invoked by the framework. More...
 
StatusCode reinitialize () override
 Reinitialization method invoked by the framework. More...
 
StatusCode restart () override
 Restart method invoked by the framework. More...
 
StatusCode stop () override
 System stop. More...
 
StatusCode finalize () override
 System finalization. More...
 
void acceptDHVisitor (IDataHandleVisitor *) const override
 
 Algorithm (std::string name, ISvcLocator *svcloc, std::string version=PACKAGE_VERSION)
 Constructor. More...
 
- Public Member Functions inherited from Gaudi::Algorithm
 Algorithm (std::string name, ISvcLocator *svcloc, std::string version=PACKAGE_VERSION)
 Constructor. More...
 
StatusCode sysStart () override
 Reinitialization method invoked by the framework. More...
 
StatusCode sysInitialize () override
 Initialization method invoked by the framework. More...
 
StatusCode sysReinitialize () override
 Reinitialization method invoked by the framework. More...
 
StatusCode sysRestart () override
 Restart method invoked by the framework. More...
 
StatusCode sysExecute (const EventContext &ctx) override
 The actions to be performed by the algorithm on an event. More...
 
StatusCode sysStop () override
 System stop. More...
 
StatusCode sysFinalize () override
 System finalization. More...
 
const std::stringname () const override
 The identifying name of the algorithm object. More...
 
const Gaudi::StringKeynameKey () const override
 
const std::stringtype () const override
 The type of the algorithm object. More...
 
void setType (std::string type) override
 
const std::stringversion () const override
 
unsigned int index () const override
 
StatusCode configure () override
 Dummy implementation of IStateful::configure() method. More...
 
StatusCode terminate () override
 Dummy implementation of IStateful::terminate() method. More...
 
StatusCode initialize () override
 the default (empty) implementation of IStateful::initialize() method More...
 
StatusCode start () override
 the default (empty) implementation of IStateful::start() method More...
 
StatusCode stop () override
 the default (empty) implementation of IStateful::stop() method More...
 
StatusCode finalize () override
 the default (empty) implementation of IStateful::finalize() method More...
 
StatusCode reinitialize () override
 the default (empty) implementation of IStateful::reinitialize() method More...
 
StatusCode restart () override
 the default (empty) implementation of IStateful::restart() method More...
 
Gaudi::StateMachine::State FSMState () const override
 returns the current state of the algorithm More...
 
Gaudi::StateMachine::State targetFSMState () const override
 returns the state the algorithm will be in after the ongoing transition More...
 
bool isEnabled () const override
 Is this algorithm enabled or disabled? More...
 
bool isSequence () const override
 Are we a Sequence? More...
 
unsigned int errorCount () const
 Get the number of failures of the algorithm. More...
 
template<class T >
StatusCode service (std::string_view name, T *&psvc, bool createIf=true) const
 Access a service by name, creating it if it doesn't already exist. More...
 
template<class T >
StatusCode service (std::string_view svcType, std::string_view svcName, T *&psvc) const
 Access a service by name and type, creating it if it doesn't already exist. More...
 
SmartIF< IServiceservice (std::string_view name, const bool createIf=true, const bool quiet=false) const
 Return a pointer to the service identified by name (or "type/name") More...
 
template<class T >
SmartIF< T > service (std::string_view name, bool createIf=true, bool quiet=false) const
 
SmartIF< IAuditorSvc > & auditorSvc () const
 The standard auditor service.May not be invoked before sysInitialize() has been invoked. More...
 
SmartIF< IChronoStatSvc > & chronoSvc () const
 The standard Chrono & Stat service, Return a pointer to the service if present. More...
 
SmartIF< IDataProviderSvc > & detSvc () const
 The standard detector data service. More...
 
SmartIF< IConversionSvc > & detCnvSvc () const
 The standard detector data persistency conversion service. More...
 
SmartIF< IDataProviderSvc > & eventSvc () const
 The standard event data service. More...
 
SmartIF< IDataProviderSvc > & evtSvc () const
 shortcut for method eventSvc More...
 
SmartIF< IConversionSvc > & eventCnvSvc () const
 The standard event data persistency conversion service. More...
 
SmartIF< IHistogramSvc > & histoSvc () const
 The standard histogram service. More...
 
SmartIF< INTupleSvc > & ntupleSvc () const
 The standard N tuple service. More...
 
SmartIF< IRndmGenSvc > & randSvc () const
 The standard RandomGen service, Return a pointer to the service if present. More...
 
SmartIF< IToolSvc > & toolSvc () const
 The standard ToolSvc service, Return a pointer to the service if present. More...
 
SmartIF< IExceptionSvc > & exceptionSvc () const
 Get the exception Service. More...
 
SmartIF< IAlgContextSvc > & contextSvc () const
 get Algorithm Context Service More...
 
SmartIF< ITimelineSvc > & timelineSvc () const
 
SmartIF< ISvcLocator > & serviceLocator () const override
 The standard service locator. More...
 
SmartIF< ISvcLocator > & svcLoc () const
 shortcut for method serviceLocator More...
 
SmartIF< IHiveWhiteBoard > & whiteboard () const
 
SmartIF< IAlgExecStateSvc > & algExecStateSvc () const
 
bool registerContext () const
 register for Algorithm Context Service? More...
 
template<class T >
Gaudi::Details::PropertyBasedeclareProperty (const std::string &name, ToolHandle< T > &hndl, const std::string &doc="none")
 
template<class T >
Gaudi::Details::PropertyBasedeclareProperty (const std::string &name, ToolHandleArray< T > &hndlArr, const std::string &doc="none")
 
SmartIF< IMonitorSvc > & monitorSvc () const
 Access the monitor service. More...
 
template<class T >
void declareInfo (const std::string &name, const T &var, const std::string &desc) const
 Declare monitoring information. More...
 
void declareInfo (const std::string &name, const std::string &format, const void *var, int size, const std::string &desc) const
 Declare monitoring information (special case) More...
 
void acceptDHVisitor (IDataHandleVisitor *) const override
 
void registerTool (IAlgTool *tool) const
 
void deregisterTool (IAlgTool *tool) const
 
template<class T >
StatusCode declareTool (ToolHandle< T > &handle, bool createIf=true)
 
template<class T >
StatusCode declareTool (ToolHandle< T > &handle, std::string toolTypeAndName, bool createIf=true)
 
template<class T >
void addToolsArray (ToolHandleArray< T > &hndlArr)
 
const std::vector< IAlgTool * > & tools () const
 
bool isBlocking () const
 
void setBlocking (bool value)
 
unsigned int cardinality () const override
 Return the cardinality. More...
 
const std::vector< std::string > & neededResources () const override
 
AlgExecStateexecState (const EventContext &ctx) const override
 reference to AlgExecState of Alg More...
 
std::ostreamtoControlFlowExpression (std::ostream &os) const override
 Produce string represention of the control flow expression. More...
 
- Public Member Functions inherited from DataHandleHolderBase< PropertyHolder< CommonMessaging< implements< IAlgorithm, IDataHandleHolder, IProperty, IStateful > > > >
std::vector< Gaudi::DataHandle * > inputHandles () const override
 
std::vector< Gaudi::DataHandle * > outputHandles () const override
 
virtual const DataObjIDCollextraInputDeps () const override
 
virtual const DataObjIDCollextraOutputDeps () const override
 
void declare (Gaudi::DataHandle &handle) override
 
void renounce (Gaudi::DataHandle &handle) override
 
bool renounceInput (const DataObjID &id) override
 
const DataObjIDCollinputDataObjs () const override
 
const DataObjIDColloutputDataObjs () const override
 
void addDependency (const DataObjID &id, const Gaudi::DataHandle::Mode &mode) override
 
- Public Member Functions inherited from extends< PropertyHolder< CommonMessaging< implements< IAlgorithm, IDataHandleHolder, IProperty, IStateful > > >, IDataHandleHolder >
void * i_cast (const InterfaceID &tid) const override
 Implementation of IInterface::i_cast. More...
 
StatusCode queryInterface (const InterfaceID &ti, void **pp) override
 Implementation of IInterface::queryInterface. More...
 
std::vector< std::stringgetInterfaceNames () const override
 Implementation of IInterface::getInterfaceNames. More...
 
- Public Member Functions inherited from PropertyHolder< CommonMessaging< implements< IAlgorithm, IDataHandleHolder, IProperty, IStateful > > >
 PropertyHolder ()=default
 
Gaudi::Details::PropertyBasedeclareProperty (Gaudi::Details::PropertyBase &prop)
 Declare a property. More...
 
Gaudi::Details::PropertyBasedeclareProperty (const std::string &name, TYPE &value, const std::string &doc="none")
 Helper to wrap a regular data member and use it as a regular property. More...
 
Gaudi::Details::PropertyBasedeclareProperty (const std::string &name, Gaudi::Property< TYPE, VERIFIER, HANDLERS > &prop, const std::string &doc="none")
 Declare a PropertyBase instance setting name and documentation. More...
 
Gaudi::Details::PropertyBasedeclareRemoteProperty (const std::string &name, IProperty *rsvc, const std::string &rname="")
 Declare a remote property. More...
 
StatusCode setProperty (const std::string &name, const Gaudi::Details::PropertyBase &p) override
 set the property from another property with a different name More...
 
StatusCode setProperty (const std::string &s) override
 set the property from the formatted string More...
 
StatusCode setProperty (const Gaudi::Details::PropertyBase &p)
 Set the property from a property. More...
 
virtual StatusCode setProperty (const std::string &name, const Gaudi::Details::PropertyBase &p)=0
 Set the property from a property with a different name. More...
 
virtual StatusCode setProperty (const std::string &s)=0
 Set the property by string. More...
 
StatusCode setProperty (const std::string &name, const char *v)
 Special case for string literals. More...
 
StatusCode setProperty (const std::string &name, const std::string &v)
 Special case for std::string. More...
 
StatusCode setProperty (const std::string &name, const TYPE &value)
 set the property form the value More...
 
StatusCode setPropertyRepr (const std::string &n, const std::string &r) override
 set the property from name and value string representation More...
 
StatusCode getProperty (Gaudi::Details::PropertyBase *p) const override
 get the property More...
 
const Gaudi::Details::PropertyBasegetProperty (std::string_view name) const override
 get the property by name More...
 
StatusCode getProperty (std::string_view n, std::string &v) const override
 convert the property to the string More...
 
const std::vector< Gaudi::Details::PropertyBase * > & getProperties () const override
 get all properties More...
 
bool hasProperty (std::string_view name) const override
 Return true if we have a property with the given name. More...
 
Gaudi::Details::PropertyBaseproperty (std::string_view name) const
 \fixme property and bindPropertiesTo should be protected More...
 
void bindPropertiesTo (Gaudi::Interfaces::IOptionsSvc &optsSvc)
 
 PropertyHolder (const PropertyHolder &)=delete
 
PropertyHolderoperator= (const PropertyHolder &)=delete
 
- Public Member Functions inherited from CommonMessaging< implements< IAlgorithm, IDataHandleHolder, IProperty, IStateful > >
MSG::Level msgLevel () const
 get the cached level (originally extracted from the embedded MsgStream) More...
 
bool msgLevel (MSG::Level lvl) const
 get the output level from the embedded MsgStream More...
 

Protected Member Functions

StatusCode append (Gaudi::Algorithm *pAlgorithm, std::vector< Gaudi::Algorithm * > &theAlgs)
 Append an algorithm to the sequencer. More...
 
StatusCode createAndAppend (const std::string &type, const std::string &name, Gaudi::Algorithm *&pAlgorithm, std::vector< Gaudi::Algorithm * > &theAlgs)
 Create a algorithm and append it to the sequencer. More...
 
StatusCode decodeNames (Gaudi::Property< std::vector< std::string >> &theNames, std::vector< Gaudi::Algorithm * > &theAlgs, std::vector< bool > &theLogic)
 Decode algorithm names, creating or appending algorithms as appropriate. More...
 
StatusCode execute (const EventContext &ctx, const std::vector< Gaudi::Algorithm * > &theAlgs, const std::vector< bool > &theLogic, Gaudi::Algorithm *&lastAlgorithm, std::size_t first=0) const
 Execute the members in the specified list. More...
 
StatusCode executeMember (Gaudi::Algorithm *theAlgorithm, const EventContext &context) const
 Execute member algorithm. More...
 
StatusCode remove (const std::string &algname, std::vector< Gaudi::Algorithm * > &theAlgs)
 Remove the specified algorithm from the sequencer. More...
 
 Sequencer (const Sequencer &a)=delete
 
Sequenceroperator= (const Sequencer &rhs)=delete
 
- Protected Member Functions inherited from Gaudi::Algorithm
std::vector< IAlgTool * > & tools ()
 
bool isInitialized () const override
 Has the Algorithm already been initialized? More...
 
bool isFinalized () const override
 Has the Algorithm already been finalized? More...
 
void setIndex (const unsigned int &idx) override
 set instantiation index of Alg More...
 
bool isReEntrant () const override
 
- Protected Member Functions inherited from DataHandleHolderBase< PropertyHolder< CommonMessaging< implements< IAlgorithm, IDataHandleHolder, IProperty, IStateful > > > >
void initDataHandleHolder ()
 initializes all handles - called by the sysInitialize method of any descendant of this More...
 
- Protected Member Functions inherited from CommonMessaging< implements< IAlgorithm, IDataHandleHolder, IProperty, IStateful > >
MSG::Level setUpMessaging () const
 Set up local caches. More...
 
MSG::Level resetMessaging ()
 Reinitialize internal states. More...
 
void updateMsgStreamOutputLevel (int level)
 Update the output level of the cached MsgStream. More...
 

Private Attributes

Gaudi::Property< std::vector< std::string > > m_names
 
Gaudi::Property< std::vector< std::string > > m_branchNames
 
Gaudi::Property< bool > m_stopOverride { this, "StopOverride", false, "stop on filter failure override" }
 
std::vector< bool > m_isInverted
 
std::vector< Gaudi::Algorithm * > m_branchAlgs
 
std::vector< bool > m_isBranchInverted
 
std::mutex m_branchFilterMutex
 
std::map< EventContext::ContextID_t, bool > m_branchFilterPassed
 

Additional Inherited Members

- Public Types inherited from Gaudi::Algorithm
typedef Gaudi::PluginService::Factory< IAlgorithm *(const std::string &, ISvcLocator *)> Factory
 
- Public Types inherited from extends< PropertyHolder< CommonMessaging< implements< IAlgorithm, IDataHandleHolder, IProperty, IStateful > > >, IDataHandleHolder >
using base_class = extends
 Typedef to this class. More...
 
using extend_interfaces_base = extend_interfaces< Interfaces... >
 Typedef to the base of this class. More...
 
- Public Types inherited from PropertyHolder< CommonMessaging< implements< IAlgorithm, IDataHandleHolder, IProperty, IStateful > > >
using PropertyHolderImpl = PropertyHolder< CommonMessaging< implements< IAlgorithm, IDataHandleHolder, IProperty, IStateful > > >
 Typedef used to refer to this class from derived classes, as in. More...
 
- Public Types inherited from CommonMessaging< implements< IAlgorithm, IDataHandleHolder, IProperty, IStateful > >
using base_class = CommonMessaging
 
- Public Types inherited from extend_interfaces< Interfaces... >
using ext_iids = typename Gaudi::interface_list_cat< typename Interfaces::ext_iids... >::type
 take union of the ext_iids of all Interfaces... More...
 
- Public Attributes inherited from Gaudi::Algorithm
friend AlgorithmManager
 
- Protected Attributes inherited from Gaudi::Algorithm
std::unique_ptr< IDataHandleVisitorm_updateDataHandles
 Hook for for derived classes to provide a custom visitor for data handles. More...
 
- Protected Attributes inherited from DataHandleHolderBase< PropertyHolder< CommonMessaging< implements< IAlgorithm, IDataHandleHolder, IProperty, IStateful > > > >
DataObjIDColl m_inputDataObjs
 
DataObjIDColl m_outputDataObjs
 

Detailed Description

ClassName: Sequencer.

Description: A Sequencer is essentially a list of Algorithms and is responsible for their management. Note that Sequences may themselves contain other Sequences. The default execute() implementation loops over the members of the sequence, calling their execute() methods. However, this can be modified if a member is disabled, has already been executed, or a member indicates that it's filter fails. The the former two cases the execution of the member is bypassed. In the latter case, the loop is terminated and the Sequencer assumes the same filtered state as the last member.

Definition at line 35 of file Sequencer.h.

Constructor & Destructor Documentation

◆ Sequencer()

Sequencer::Sequencer ( const Sequencer a)
protecteddelete

Member Function Documentation

◆ append() [1/2]

StatusCode Sequencer::append ( Gaudi::Algorithm pAlgorithm)

Append an algorithm to the sequencer.

Definition at line 162 of file Sequencer.cpp.

162 { return append( pAlgorithm, *subAlgorithms() ); }

◆ append() [2/2]

StatusCode Sequencer::append ( Gaudi::Algorithm pAlgorithm,
std::vector< Gaudi::Algorithm * > &  theAlgs 
)
protected

Append an algorithm to the sequencer.

Protected Member Functions.

Definition at line 206 of file Sequencer.cpp.

206  {
207  // Check that the specified algorithm doesn't already exist in the membership list
208  if ( std::find( std::begin( theAlgs ), std::end( theAlgs ), pAlgorithm ) != std::end( theAlgs ) ) {
209  return StatusCode::FAILURE;
210  }
211  theAlgs.push_back( pAlgorithm );
212  pAlgorithm->addRef();
213  return StatusCode::SUCCESS;
214 }

◆ appendToBranch()

StatusCode Sequencer::appendToBranch ( Gaudi::Algorithm pAlgorithm)

Append an algorithm to the sequencer branch.

Definition at line 164 of file Sequencer.cpp.

164  {
165  return append( pAlgorithm, branchAlgorithms() );
166 }

◆ branchAlgorithms() [1/2]

std::vector< Gaudi::Algorithm * > & Sequencer::branchAlgorithms ( )

Definition at line 190 of file Sequencer.cpp.

190 { return m_branchAlgs; }

◆ branchAlgorithms() [2/2]

const std::vector< Gaudi::Algorithm * > & Sequencer::branchAlgorithms ( ) const

List of branch algorithms.

These are the algorithms that would get executed if a filter algorithm indicated a failure. The branch is located within the main sequence by the first element, which is the filter algorithm.

Definition at line 188 of file Sequencer.cpp.

188 { return m_branchAlgs; }

◆ branchFilterPassed()

bool Sequencer::branchFilterPassed ( const EventContext ctx) const

additional interface methods

Was the branch filter passed for the last event?

Definition at line 150 of file Sequencer.cpp.

150  {
151  auto lock = std::scoped_lock{ m_branchFilterMutex };
152  return m_branchFilterPassed[ctx.slot()];
153 }

◆ createAndAppend() [1/2]

StatusCode Sequencer::createAndAppend ( const std::string type,
const std::string name,
Gaudi::Algorithm *&  pAlgorithm 
)

Create a algorithm and append it to the sequencer.

A call to this method creates a child algorithm object. Note that the returned pointer is to Algorithm (as opposed to IAlgorithm), and thus the methods of IProperty are also available for the direct setting of the algorithm's properties. Using this mechanism instead of creating algorithms directly via the new operator is preferred since then the framework may take care of all of the necessary book-keeping.

Definition at line 168 of file Sequencer.cpp.

169  {
170  return createAndAppend( type, name, pAlgorithm, *subAlgorithms() );
171 }

◆ createAndAppend() [2/2]

StatusCode Sequencer::createAndAppend ( const std::string type,
const std::string name,
Gaudi::Algorithm *&  pAlgorithm,
std::vector< Gaudi::Algorithm * > &  theAlgs 
)
protected

Create a algorithm and append it to the sequencer.

A call to this method creates a child algorithm object. Note that the returned pointer is to Algorithm (as opposed to IAlgorithm), and thus the methods of IProperty are also available for the direct setting of the algorithm's properties. Using this mechanism instead of creating algorithms directly via the new operator is preferred since then the framework may take care of all of the necessary book-keeping.

Definition at line 216 of file Sequencer.cpp.

217  {
218  auto theAlgMgr = serviceLocator()->service<IAlgManager>( "ApplicationMgr" );
219  if ( !theAlgMgr ) return StatusCode::FAILURE;
220 
221  IAlgorithm* tmp;
222  StatusCode result = theAlgMgr->createAlgorithm( type, algName, tmp );
223  if ( result.isSuccess() ) {
224  try {
225  pAlgorithm = dynamic_cast<Gaudi::Algorithm*>( tmp );
226  theAlgs.push_back( pAlgorithm );
227  } catch ( ... ) {
228  error() << "Unable to create Algorithm " << algName << endmsg;
229  result = StatusCode::FAILURE;
230  }
231  }
232 
233  return result;
234 }

◆ createAndAppendToBranch()

StatusCode Sequencer::createAndAppendToBranch ( const std::string type,
const std::string name,
Gaudi::Algorithm *&  pAlgorithm 
)

Create a algorithm and append it to the sequencer branch.

A call to this method creates a child algorithm object. Note that the returned pointer is to Algorithm (as opposed to IAlgorithm), and thus the methods of IProperty are also available for the direct setting of the algorithm's properties. Using this mechanism instead of creating algorithms directly via the new operator is preferred since then the framework may take care of all of the necessary book-keeping.

Definition at line 173 of file Sequencer.cpp.

174  {
175  return createAndAppend( type, name, pAlgorithm, branchAlgorithms() );
176 }

◆ decodeBranchMemberNames()

StatusCode Sequencer::decodeBranchMemberNames ( )

Decode branch member name list.

Definition at line 197 of file Sequencer.cpp.

197  {
198  // Decode the branch membership list
200 }

◆ decodeMemberNames()

StatusCode Sequencer::decodeMemberNames ( )

Decode Member Name list.

Definition at line 192 of file Sequencer.cpp.

192  {
193  // Decode the membership list
195 }

◆ decodeNames()

StatusCode Sequencer::decodeNames ( Gaudi::Property< std::vector< std::string >> &  theNames,
std::vector< Gaudi::Algorithm * > &  theAlgs,
std::vector< bool > &  theLogic 
)
protected

Decode algorithm names, creating or appending algorithms as appropriate.

Definition at line 236 of file Sequencer.cpp.

237  {
238  StatusCode result;
239  auto theAlgMgr = serviceLocator()->service<IAlgManager>( "ApplicationMgr" );
240  if ( theAlgMgr ) {
241  // Clear the existing list of algorithms
242  theAlgs.clear();
243 
244  // Build the list of member algorithms from the contents of the
245  // theNames list.
246  for ( const auto& n : theNames.value() ) {
247 
248  // Parse the name for a syntax of the form:
249  //
250  // <type>/<name>
251  //
252  // Where <name> is the algorithm instance name, and <type> is the
253  // algorithm class type (being a subclass of Algorithm).
255  std::string theName = typeName.name();
256  std::string theType = typeName.type();
257 
258  // Parse the name for a syntax of the form:
259  //
260  // <name>:invert
261  //
262  // Where <name> is the algorithm instance name and ":invert"
263  // indicates that the filter passed logic is inverted.
264  bool isInverted = false;
265  std::string::size_type invert = theName.find_first_of( ":" );
266  // Skip all occurrences of "::" (allow namespaces)
267  while ( std::string::npos != invert && invert < ( theName.size() - 1 ) && theName[invert + 1] == ':' )
268  invert = theName.find_first_of( ":", invert + 2 );
269  if ( std::string::npos != invert ) {
270  if ( theName == theType ) {
271  // This means that we got something like "Type:invert",
272  // so we have to strip the ":invert" from the type too.
273  theType = theType.substr( 0, invert );
274  }
275  theName = theName.substr( 0, invert );
276  isInverted = true;
277  }
278  // Check whether the supplied name corresponds to an existing
279  // Algorithm object.
280  SmartIF<IAlgorithm>& theIAlg = theAlgMgr->algorithm( theName, false );
281  Gaudi::Algorithm* theAlgorithm = nullptr;
283  if ( theIAlg ) {
284  try {
285  theAlgorithm = dynamic_cast<Gaudi::Algorithm*>( theIAlg.get() );
286  } catch ( ... ) {
287  warning() << theName << " is not an Algorithm - Failed dynamic cast" << endmsg;
288  theAlgorithm = nullptr; // release
289  }
290  }
291  if ( theAlgorithm ) {
292 
293  // The specified Algorithm already exists - just append it to the membership list.
294  status = append( theAlgorithm, theAlgs );
295  if ( status.isSuccess() ) {
296  ON_DEBUG debug() << theName << " already exists - appended to member list" << endmsg;
297  } else {
298  warning() << theName << " already exists - append failed!!!" << endmsg;
299  result = StatusCode::FAILURE;
300  }
301  } else {
302 
303  // The specified name doesn't exist - create a new object of the specified type
304  // and append it to the membership list.
305  status = createAndAppend( theType, theName, theAlgorithm, theAlgs );
306  if ( status.isSuccess() ) {
307  ON_DEBUG debug() << theName << " doesn't exist - created and appended to member list" << endmsg;
308  } else {
309  warning() << theName << " doesn't exist - creation failed!!!" << endmsg;
310  result = StatusCode::FAILURE;
311  }
312  }
313  if ( status.isSuccess() ) theLogic.push_back( isInverted );
314  }
315  }
316  // Print membership list
317  if ( result.isSuccess() && theAlgs.size() != 0 ) {
318  info() << "Member list: ";
319  auto ai = theAlgs.begin();
320  auto li = theLogic.begin();
321  for ( ; ai != theAlgs.end(); ++ai, ++li ) {
322 
323  if ( ai != theAlgs.begin() ) info() << ", ";
324  auto alg = *ai;
325  if ( alg->name() == System::typeinfoName( typeid( *alg ) ) )
326  info() << alg->name();
327  else
328  info() << System::typeinfoName( typeid( *alg ) ) << "/" << alg->name();
329 
330  if ( *li ) info() << ":invert";
331  }
332  info() << endmsg;
333  }
334  return result;
335 }

◆ execute() [1/2]

StatusCode Sequencer::execute ( const EventContext ctx) const
override

The actions to be performed by the sequencer on an event.

This method is invoked once per event.

Definition at line 70 of file Sequencer.cpp.

70  {
72  ON_DEBUG debug() << name() << " Sequencer::execute()" << endmsg;
73 
74  auto& state = execState( ctx );
75 
76  // Bypass the loop if this sequencer is disabled or has already been executed
77  if ( isEnabled() && !( execState( ctx ).state() == AlgExecState::State::Done ) ) {
78  Gaudi::Algorithm* lastAlgorithm;
79  result = execute( ctx, *subAlgorithms(), m_isInverted, lastAlgorithm );
80  if ( result.isSuccess() ) {
81  const bool passed = state.filterPassed();
82  if ( !passed && !isStopOverride() ) {
83 
84  // Filter failed and stop override not set. Execute the
85  // branch if there is one associated with the filter
86  // algorithm that failed. Note that the first member on
87  // the branch is the failing algorithm and so should
88  // be skipped.
89  const auto& theAlgs = branchAlgorithms();
90  if ( !theAlgs.empty() ) {
91  Gaudi::Algorithm* branchAlgorithm = theAlgs[0];
92  if ( lastAlgorithm == branchAlgorithm ) {
93 
94  // Branch specified - Loop over branch members
95  result = execute( ctx, branchAlgorithms(), m_isBranchInverted, lastAlgorithm, 1 );
96  if ( result.isSuccess() ) {
97 
98  // The final filter passed state will be set true if either
99  // of the main or branches passed, otherwise false.
100 
101  // Save the branch filter passed state.
102  setBranchFilterPassed( ctx, state.filterPassed() );
103  }
104  }
105  }
106  }
107  }
108 
109  // Prevent multiple executions of this sequencer for the current event
110  state.setState( AlgExecState::State::Done );
111  }
112  return result;
113 }

◆ execute() [2/2]

StatusCode Sequencer::execute ( const EventContext ctx,
const std::vector< Gaudi::Algorithm * > &  theAlgs,
const std::vector< bool > &  theLogic,
Gaudi::Algorithm *&  lastAlgorithm,
std::size_t  first = 0 
) const
protected

Execute the members in the specified list.

Definition at line 337 of file Sequencer.cpp.

339  {
341 
342  auto& state = execState( ctx );
343 
344  // Reset the branch filter passed flag
345  setBranchFilterPassed( ctx, false );
346 
347  // Loop over all algorithms calling their execute functions if they
348  // are (a) not disabled, and (b) aren't already executed. Note that
349  // in the latter case the filter state is still examined. Terminate
350  // the loop if an algorithm indicates that it's filter didn't pass.
351  auto size = theAlgs.size();
352  for ( auto i = first; i < size; i++ ) {
353  lastAlgorithm = theAlgs[i];
354  result = executeMember( lastAlgorithm, ctx );
355  if ( result.isSuccess() ) {
356 
357  // Take the filter passed status of this algorithm as my own status.
358  // Note that we take into account inverted logic.
359  bool passed = lastAlgorithm->execState( ctx ).filterPassed();
360  bool isInverted = theLogic[i];
361  if ( isInverted ) passed = !passed;
362  state.setFilterPassed( passed );
363 
364  // The behaviour when the filter fails depends on the StopOverride property.
365  // The default action is to stop processing, but this default can be
366  // overridden by setting the "StopOverride" property to true.
367  if ( !isStopOverride() ) {
368  if ( !passed ) break;
369  }
370  } else {
371  break;
372  }
373  }
374  return result;
375 }

◆ executeMember()

StatusCode Sequencer::executeMember ( Gaudi::Algorithm theAlgorithm,
const EventContext context 
) const
protected

Execute member algorithm.

Definition at line 377 of file Sequencer.cpp.

377  {
379  if ( theAlgorithm->isEnabled() ) {
380  if ( theAlgorithm->execState( context ).state() != AlgExecState::State::Done ) {
381  result = theAlgorithm->sysExecute( context );
382  }
383  }
384  return result;
385 }

◆ finalize()

StatusCode Sequencer::finalize ( )
override

Sequencer finalization.

Definition at line 115 of file Sequencer.cpp.

115  {
116  // Loop over all branch members calling their finalize functions
117  // if they are not disabled. Note that the Sequence::finalize
118  // function already does this for the main members.
119  for ( auto& alg : branchAlgorithms() ) {
120  if ( alg->sysFinalize().isFailure() ) { error() << "Unable to finalize Algorithm " << alg->name() << endmsg; }
121  }
122  return Sequence::finalize();
123 }

◆ initialize()

StatusCode Sequencer::initialize ( )
override

Initialization of a sequencer.

Typically things like histogram creation, setting up of data structures etc, should be done here. If a sequence has properties specified in the job options file, they will be set to the requested values BEFORE the initialize() method is invoked.

Definition at line 27 of file Sequencer.cpp.

27  {
28  auto is_good = decodeMemberNames();
29  if ( !is_good ) {
30  error() << "Unable to configure one or more sequencer members " << endmsg;
31  return is_good;
32  }
33 
34  is_good = decodeBranchMemberNames();
35  if ( !is_good ) {
36  error() << "Unable to configure one or more branch members " << endmsg;
37  return is_good;
38  }
39 
40  // We have to "decode" members before calling base class initialize
41  is_good = Sequence::initialize();
42  if ( !is_good ) return is_good;
43 
44  // Loop over all branches
45  // (Sequence does not know about branches)
46  for ( auto& alg : branchAlgorithms() ) {
47  is_good = alg->sysInitialize();
48  if ( is_good.isFailure() ) {
49  error() << "Unable to initialize Algorithm " << alg->name() << endmsg;
50  return is_good;
51  }
52  }
53 
54  return is_good;
55 }

◆ isStopOverride()

bool Sequencer::isStopOverride ( ) const
virtual

Has the StopOverride mode been set?

Definition at line 160 of file Sequencer.cpp.

160 { return m_stopOverride.value(); }

◆ operator=()

Sequencer& Sequencer::operator= ( const Sequencer rhs)
protecteddelete

◆ reinitialize()

StatusCode Sequencer::reinitialize ( )
override

Sequencer Reinitialization.

Definition at line 57 of file Sequencer.cpp.

57  {
58  // Bypass the loop if this sequencer is disabled
59  if ( isEnabled() ) {
60  // Loop over all branch members calling their reinitialize functions
61  // if they are not disabled.
62  for ( auto& alg : branchAlgorithms() ) {
63  if ( alg->isEnabled() ) { alg->reinitialize().ignore(); }
64  }
65  return Sequence::reinitialize();
66  }
67  return StatusCode::SUCCESS;
68 }

◆ remove() [1/3]

StatusCode Sequencer::remove ( const std::string algname,
std::vector< Gaudi::Algorithm * > &  theAlgs 
)
protected

Remove the specified algorithm from the sequencer.

Definition at line 387 of file Sequencer.cpp.

387  {
389 
390  // Test that the algorithm exists in the member list
391  for ( auto& alg : theAlgs ) {
392  if ( alg->name() == algname ) {
393 
394  // Algorithm with specified name exists in the algorithm list - remove it
395  // THIS ISN'T IMPLEMENTED YET!!!!
396  info() << "Sequencer::remove( ) isn't implemented yet!!!!!" << endmsg;
397  result = StatusCode::SUCCESS;
398  break;
399  }
400  }
401  return result;
402 }

◆ remove() [2/3]

StatusCode Sequencer::remove ( const std::string name)

Definition at line 180 of file Sequencer.cpp.

180 { return remove( algname, *subAlgorithms() ); }

◆ remove() [3/3]

StatusCode Sequencer::remove ( Gaudi::Algorithm pAlgorithm)

Remove the specified algorithm from the sequencer.

Definition at line 178 of file Sequencer.cpp.

178 { return remove( pAlgorithm->name() ); }

◆ removeFromBranch() [1/2]

StatusCode Sequencer::removeFromBranch ( const std::string name)

Definition at line 186 of file Sequencer.cpp.

186 { return remove( algname, branchAlgorithms() ); }

◆ removeFromBranch() [2/2]

StatusCode Sequencer::removeFromBranch ( Gaudi::Algorithm pAlgorithm)

Definition at line 182 of file Sequencer.cpp.

182  {
183  return removeFromBranch( pAlgorithm->name() );
184 }

◆ setBranchFilterPassed()

void Sequencer::setBranchFilterPassed ( const EventContext ctx,
bool  state 
) const

Set the branch filter passed flag for the last event.

Definition at line 155 of file Sequencer.cpp.

155  {
156  auto lock = std::scoped_lock{ m_branchFilterMutex };
157  m_branchFilterPassed[ctx.slot()] = state;
158 }

◆ start()

StatusCode Sequencer::start ( )
override

Sequencer finalization.

Definition at line 125 of file Sequencer.cpp.

125  {
126  auto is_good = Sequence::start();
127  if ( !is_good ) return is_good;
128 
129  // Loop over all branches
130  for ( auto& alg : branchAlgorithms() ) {
131  is_good = alg->sysStart();
132  if ( !is_good ) {
133  error() << "Unable to start Algorithm " << alg->name() << endmsg;
134  return is_good;
135  }
136  }
137 
138  return is_good;
139 }

◆ stop()

StatusCode Sequencer::stop ( )
override

Sequencer finalization.

Definition at line 141 of file Sequencer.cpp.

141  {
142  // Loop over all branch members calling their finalize functions
143  // if they are not disabled.
144  for ( auto& alg : branchAlgorithms() ) {
145  if ( alg->sysStop().isFailure() ) { error() << "Unable to stop Algorithm " << alg->name() << endmsg; }
146  }
147  return Sequence::stop();
148 }

◆ toControlFlowExpression()

std::ostream & Sequencer::toControlFlowExpression ( std::ostream os) const
override

Produce string represention of the control flow expression.

Definition at line 404 of file Sequencer.cpp.

404  {
405  auto& theAlgs = *subAlgorithms();
406  if ( theAlgs.empty() ) return os << "CFTrue";
407 
408  os << "seq(";
409  const auto algs_count = theAlgs.size();
410  const auto op = isStopOverride() ? " >> " : " & ";
411  size_t i = 0;
412  while ( i < algs_count ) {
413  if ( i ) os << op;
414  if ( m_isInverted[i] ) os << "~";
415  theAlgs[i]->toControlFlowExpression( os );
416  ++i;
417  }
418  return os << ")";
419 }

Member Data Documentation

◆ m_branchAlgs

std::vector<Gaudi::Algorithm*> Sequencer::m_branchAlgs
private

Definition at line 235 of file Sequencer.h.

◆ m_branchFilterMutex

std::mutex Sequencer::m_branchFilterMutex
mutableprivate

Definition at line 238 of file Sequencer.h.

◆ m_branchFilterPassed

std::map<EventContext::ContextID_t, bool> Sequencer::m_branchFilterPassed
mutableprivate

Definition at line 239 of file Sequencer.h.

◆ m_branchNames

Gaudi::Property<std::vector<std::string> > Sequencer::m_branchNames
private
Initial value:
{ this,
"BranchMembers",
{},
[this]( auto& ) {
if ( this->isInitialized() )
},
"branch member names" }

Definition at line 224 of file Sequencer.h.

◆ m_isBranchInverted

std::vector<bool> Sequencer::m_isBranchInverted
private

Definition at line 236 of file Sequencer.h.

◆ m_isInverted

std::vector<bool> Sequencer::m_isInverted
private

Definition at line 234 of file Sequencer.h.

◆ m_names

Gaudi::Property<std::vector<std::string> > Sequencer::m_names
private
Initial value:
{ this,
"Members",
{},
[this]( auto& ) {
if ( this->isInitialized() ) this->decodeMemberNames().ignore();
},
"member names" }

Definition at line 217 of file Sequencer.h.

◆ m_stopOverride

Gaudi::Property<bool> Sequencer::m_stopOverride { this, "StopOverride", false, "stop on filter failure override" }
private

Definition at line 232 of file Sequencer.h.


The documentation for this class was generated from the following files:
Sequencer::removeFromBranch
StatusCode removeFromBranch(Gaudi::Algorithm *pAlgorithm)
Definition: Sequencer.cpp:182
Sequencer::executeMember
StatusCode executeMember(Gaudi::Algorithm *theAlgorithm, const EventContext &context) const
Execute member algorithm.
Definition: Sequencer.cpp:377
std::lock
T lock(T... args)
Gaudi::Algorithm::sysExecute
StatusCode sysExecute(const EventContext &ctx) override
The actions to be performed by the algorithm on an event.
Definition: Algorithm.cpp:341
std::string
STL class.
details::size
constexpr auto size(const T &, Args &&...) noexcept
Definition: AnyDataWrapper.h:22
AlgExecState::state
State state() const
Definition: IAlgExecStateSvc.h:42
Gaudi::Algorithm::name
const std::string & name() const override
The identifying name of the algorithm object.
Definition: Algorithm.cpp:542
StatusCode::isSuccess
bool isSuccess() const
Definition: StatusCode.h:314
Gaudi::Algorithm::isInitialized
bool isInitialized() const override
Has the Algorithm already been initialized?
Definition: Algorithm.h:419
Gaudi::Algorithm::type
const std::string & type() const override
The type of the algorithm object.
Definition: Algorithm.h:165
std::find
T find(T... args)
std::string::size
T size(T... args)
Sequencer::m_branchAlgs
std::vector< Gaudi::Algorithm * > m_branchAlgs
Definition: Sequencer.h:235
Gaudi::Algorithm::serviceLocator
SmartIF< ISvcLocator > & serviceLocator() const override
The standard service locator.
Definition: Algorithm.cpp:586
ON_DEBUG
#define ON_DEBUG
Definition: Sequencer.cpp:24
Sequencer::append
StatusCode append(Gaudi::Algorithm *pAlgorithm)
Append an algorithm to the sequencer.
Definition: Sequencer.cpp:162
Sequencer::m_branchFilterMutex
std::mutex m_branchFilterMutex
Definition: Sequencer.h:238
System::typeinfoName
GAUDI_API const std::string typeinfoName(const std::type_info &)
Get platform independent information about the class type.
Definition: System.cpp:310
std::vector::clear
T clear(T... args)
Sequencer::m_branchNames
Gaudi::Property< std::vector< std::string > > m_branchNames
Definition: Sequencer.h:224
Sequencer::m_isInverted
std::vector< bool > m_isInverted
Definition: Sequencer.h:234
basic.alg
alg
Definition: basic.py:15
std::vector::push_back
T push_back(T... args)
IAlgManager
Definition: IAlgManager.h:37
Gaudi::Algorithm::isEnabled
bool isEnabled() const override
Is this algorithm enabled or disabled?
Definition: Algorithm.cpp:552
Gaudi::Utils::TypeNameString
Helper class to parse a string of format "type/name".
Definition: TypeNameString.h:20
Sequencer::execute
StatusCode execute(const EventContext &ctx) const override
The actions to be performed by the sequencer on an event.
Definition: Sequencer.cpp:70
GaudiPython.Pythonizations.ctx
ctx
Definition: Pythonizations.py:588
StatusCode
Definition: StatusCode.h:65
IAlgorithm
Definition: IAlgorithm.h:38
Gaudi::Algorithm::execState
AlgExecState & execState(const EventContext &ctx) const override
reference to AlgExecState of Alg
Definition: Algorithm.cpp:554
Gaudi::Algorithm
Base class from which all concrete algorithm classes should be derived.
Definition: Algorithm.h:90
Gaudi::Property::value
const ValueType & value() const
Backward compatibility (.
Definition: Property.h:240
Sequencer::remove
StatusCode remove(Gaudi::Algorithm *pAlgorithm)
Remove the specified algorithm from the sequencer.
Definition: Sequencer.cpp:178
SmartIF< IAlgorithm >
Sequencer::m_names
Gaudi::Property< std::vector< std::string > > m_names
Definition: Sequencer.h:217
Sequencer::m_branchFilterPassed
std::map< EventContext::ContextID_t, bool > m_branchFilterPassed
Definition: Sequencer.h:239
Sequencer::createAndAppend
StatusCode createAndAppend(const std::string &type, const std::string &name, Gaudi::Algorithm *&pAlgorithm)
Create a algorithm and append it to the sequencer.
Definition: Sequencer.cpp:168
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:203
GaudiPluginService.cpluginsvc.n
n
Definition: cpluginsvc.py:235
Sequencer::m_stopOverride
Gaudi::Property< bool > m_stopOverride
Definition: Sequencer.h:232
StatusCode::ignore
const StatusCode & ignore() const
Allow discarding a StatusCode without warning.
Definition: StatusCode.h:139
std::string::substr
T substr(T... args)
Sequencer::isStopOverride
virtual bool isStopOverride() const
Has the StopOverride mode been set?
Definition: Sequencer.cpp:160
Sequencer::decodeMemberNames
StatusCode decodeMemberNames()
Decode Member Name list.
Definition: Sequencer.cpp:192
Sequencer::decodeNames
StatusCode decodeNames(Gaudi::Property< std::vector< std::string >> &theNames, std::vector< Gaudi::Algorithm * > &theAlgs, std::vector< bool > &theLogic)
Decode algorithm names, creating or appending algorithms as appropriate.
Definition: Sequencer.cpp:236
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:100
SmartIF::get
TYPE * get() const
Get interface pointer.
Definition: SmartIF.h:86
GaudiDict::typeName
std::string typeName(const std::type_info &typ)
Definition: Dictionary.cpp:31
Sequencer::decodeBranchMemberNames
StatusCode decodeBranchMemberNames()
Decode branch member name list.
Definition: Sequencer.cpp:197
compareRootHistos.state
def state
Definition: compareRootHistos.py:500
std::begin
T begin(T... args)
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
AlgExecState::filterPassed
bool filterPassed() const
Definition: IAlgExecStateSvc.h:41
Sequencer::setBranchFilterPassed
void setBranchFilterPassed(const EventContext &ctx, bool state) const
Set the branch filter passed flag for the last event.
Definition: Sequencer.cpp:155
Sequencer::branchAlgorithms
const std::vector< Gaudi::Algorithm * > & branchAlgorithms() const
List of branch algorithms.
Definition: Sequencer.cpp:188
std::string::find_first_of
T find_first_of(T... args)
std::end
T end(T... args)
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition: StatusCode.h:101
Sequencer::m_isBranchInverted
std::vector< bool > m_isBranchInverted
Definition: Sequencer.h:236
IOTest.start
def start
Definition: IOTest.py:113