The Gaudi Framework  v29r0 (ff2e7097)
AlgContextSvc Class Reference

#include <src/AlgContextSvc.h>

Inheritance diagram for AlgContextSvc:
Collaboration diagram for AlgContextSvc:

Public Member Functions

StatusCode setCurrentAlg (IAlgorithm *a) override
 set the currently executing algorithm ("push_back") More...
 
StatusCode unSetCurrentAlg (IAlgorithm *a) override
 remove the algorithm ("pop_back") More...
 
IAlgorithmcurrentAlg () const override
 accessor to current algorithm: More...
 
const IAlgContextSvc::Algorithmsalgorithms () const override
 get the stack of executed algorithms More...
 
void handle (const Incident &) override
 handle incident More...
 
StatusCode initialize () override
 standard initialization of the service More...
 
StatusCode start () override
 
StatusCode finalize () override
 standard finalization of the service More...
 
 ~AlgContextSvc () override=default
 Standard Destructor. More...
 
- Public Member Functions inherited from extends< Service, IAlgContextSvc, IIncidentListener >
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...
 
 ~extends () override=default
 Virtual destructor. More...
 
- Public Member Functions inherited from Service
const std::stringname () const override
 Retrieve name of the service. More...
 
StatusCode configure () override
 
StatusCode initialize () override
 
StatusCode start () override
 
StatusCode stop () override
 
StatusCode finalize () override
 
StatusCode terminate () override
 
Gaudi::StateMachine::State FSMState () const override
 
Gaudi::StateMachine::State targetFSMState () const override
 
StatusCode reinitialize () override
 
StatusCode restart () override
 
StatusCode sysInitialize () override
 Initialize Service. More...
 
StatusCode sysStart () override
 Initialize Service. More...
 
StatusCode sysStop () override
 Initialize Service. More...
 
StatusCode sysFinalize () override
 Finalize Service. More...
 
StatusCode sysReinitialize () override
 Re-initialize the Service. More...
 
StatusCode sysRestart () override
 Re-initialize the Service. More...
 
 Service (std::string name, ISvcLocator *svcloc)
 Standard Constructor. More...
 
SmartIF< ISvcLocator > & serviceLocator () const override
 Retrieve pointer to service locator. More...
 
StatusCode setProperties ()
 Method for setting declared properties to the values specified for the job. More...
 
template<class T >
StatusCode service (const std::string &name, const 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 (const std::string &name, T *&psvc, bool createIf=true) const
 
template<typename IFace = IService>
SmartIF< IFace > service (const std::string &name, bool createIf=true) const
 
template<class T >
StatusCode service (const std::string &svcType, const std::string &svcName, T *&psvc) const
 Access a service by name and type, creating it if it doesn't already exist. More...
 
template<class T >
StatusCode declareTool (ToolHandle< T > &handle, std::string toolTypeAndName, bool createIf=true)
 Declare used tool. More...
 
SmartIF< IAuditorSvc > & auditorSvc () const
 The standard auditor service.May not be invoked before sysInitialize() has been invoked. More...
 
- Public Member Functions inherited from PropertyHolder< CommonMessaging< implements< IService, IProperty, IStateful > > >
 PropertyHolder ()=default
 
 ~PropertyHolder () override=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, TYPE &value, const std::string &doc="none") const
 
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 Gaudi::Details::PropertyBase &p) override
 set the property form another property More...
 
StatusCode setProperty (const std::string &s) override
 set the property from the formatted string More...
 
StatusCode setProperty (const std::string &n, const std::string &v) override
 set the property from name and the value More...
 
StatusCode setProperty (const std::string &name, const TYPE &value)
 set the property form the value More...
 
StatusCode getProperty (Gaudi::Details::PropertyBase *p) const override
 get the property More...
 
const Gaudi::Details::PropertyBasegetProperty (const std::string &name) const override
 get the property by name More...
 
StatusCode getProperty (const std::string &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 (const std::string &name) const override
 Return true if we have a property with the given name. More...
 
 PropertyHolder (const PropertyHolder &)=delete
 
PropertyHolderoperator= (const PropertyHolder &)=delete
 
Gaudi::Details::PropertyBasedeclareProperty (const std::string &name, GaudiHandleBase &ref, const std::string &doc="none")
 Specializations for various GaudiHandles. More...
 
Gaudi::Details::PropertyBasedeclareProperty (const std::string &name, GaudiHandleArrayBase &ref, const std::string &doc="none")
 
Gaudi::Details::PropertyBasedeclareProperty (const std::string &name, DataObjectHandleBase &ref, const std::string &doc="none")
 
- Public Member Functions inherited from CommonMessagingBase
virtual ~CommonMessagingBase ()=default
 Virtual destructor. More...
 
SmartIF< IMessageSvc > & msgSvc () const
 The standard message service. More...
 
MsgStreammsgStream () const
 Return an uninitialized MsgStream. More...
 
MsgStreammsgStream (const MSG::Level level) const
 Predefined configurable message stream for the efficient printouts. More...
 
MsgStreamalways () const
 shortcut for the method msgStream(MSG::ALWAYS) More...
 
MsgStreamfatal () const
 shortcut for the method msgStream(MSG::FATAL) More...
 
MsgStreamerr () const
 shortcut for the method msgStream(MSG::ERROR) More...
 
MsgStreamerror () const
 shortcut for the method msgStream(MSG::ERROR) More...
 
MsgStreamwarning () const
 shortcut for the method msgStream(MSG::WARNING) More...
 
MsgStreaminfo () const
 shortcut for the method msgStream(MSG::INFO) More...
 
MsgStreamdebug () const
 shortcut for the method msgStream(MSG::DEBUG) More...
 
MsgStreamverbose () const
 shortcut for the method msgStream(MSG::VERBOSE) More...
 
MsgStreammsg () const
 shortcut for the method msgStream(MSG::INFO) More...
 
MSG::Level msgLevel () const
 get the output level from the embedded MsgStream More...
 
MSG::Level outputLevel () const __attribute__((deprecated))
 Backward compatibility function for getting the output level. More...
 
bool msgLevel (MSG::Level lvl) const
 get the output level from the embedded MsgStream More...
 
- Public Member Functions inherited from extend_interfaces< Interfaces... >
 ~extend_interfaces () override=default
 Virtual destructor. More...
 

Private Member Functions

 AlgContextSvc ()=delete
 
 AlgContextSvc (const AlgContextSvc &)=delete
 
AlgContextSvcoperator= (const AlgContextSvc &)=delete
 

Private Attributes

boost::thread_specific_ptr< IAlgContextSvc::Algorithmsm_algorithms
 the stack of current algorithms More...
 
SmartIF< IIncidentSvcm_inc = nullptr
 pointer to Incident Service More...
 
Gaudi::Property< bool > m_check {this, "Check", true, "Flag to perform more checks"}
 
Gaudi::Property< bool > m_bypassInc
 
std::vector< int > m_inEvtLoop
 

Additional Inherited Members

- Public Types inherited from extends< Service, IAlgContextSvc, IIncidentListener >
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 Service
typedef Gaudi::PluginService::Factory< IService *, const std::string &, ISvcLocator * > Factory
 
- Public Types inherited from PropertyHolder< CommonMessaging< implements< IService, IProperty, IStateful > > >
using PropertyHolderImpl = PropertyHolder< CommonMessaging< implements< IService, IProperty, IStateful > > >
 Typedef used to refer to this class from derived classes, as in. More...
 
- Public Types inherited from CommonMessaging< implements< IService, 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...
 
- Protected Member Functions inherited from Service
 ~Service () override
 Standard Destructor. More...
 
int outputLevel () const
 get the Service's output level More...
 
- Protected Member Functions inherited from PropertyHolder< CommonMessaging< implements< IService, IProperty, IStateful > > >
Gaudi::Details::PropertyBaseproperty (const std::string &name) const
 
- Protected Member Functions inherited from CommonMessaging< implements< IService, IProperty, IStateful > >
void updateMsgStreamOutputLevel (int level)
 Update the output level of the cached MsgStream. More...
 
- Protected Attributes inherited from Service
Gaudi::StateMachine::State m_state = Gaudi::StateMachine::OFFLINE
 Service state. More...
 
Gaudi::StateMachine::State m_targetState = Gaudi::StateMachine::OFFLINE
 Service state. More...
 
Gaudi::Property< int > m_outputLevel {this, "OutputLevel", MSG::NIL, "output level"}
 
Gaudi::Property< bool > m_auditInit {this, "AuditServices", false, "[[deprecated]] unused"}
 
Gaudi::Property< bool > m_auditorInitialize {this, "AuditInitialize", false, "trigger auditor on initialize()"}
 
Gaudi::Property< bool > m_auditorStart {this, "AuditStart", false, "trigger auditor on start()"}
 
Gaudi::Property< bool > m_auditorStop {this, "AuditStop", false, "trigger auditor on stop()"}
 
Gaudi::Property< bool > m_auditorFinalize {this, "AuditFinalize", false, "trigger auditor on finalize()"}
 
Gaudi::Property< bool > m_auditorReinitialize {this, "AuditReinitialize", false, "trigger auditor on reinitialize()"}
 
Gaudi::Property< bool > m_auditorRestart {this, "AuditRestart", false, "trigger auditor on restart()"}
 
SmartIF< IAuditorSvcm_pAuditorSvc
 Auditor Service. More...
 

Detailed Description

Definition at line 33 of file AlgContextSvc.h.

Constructor & Destructor Documentation

AlgContextSvc::~AlgContextSvc ( )
overridedefault

Standard Destructor.

AlgContextSvc::AlgContextSvc ( )
privatedelete
AlgContextSvc::AlgContextSvc ( const AlgContextSvc )
privatedelete

Member Function Documentation

const IAlgContextSvc::Algorithms& AlgContextSvc::algorithms ( ) const
inlineoverride

get the stack of executed algorithms

See also
IAlgContextSvc

Definition at line 43 of file AlgContextSvc.h.

43 { return *m_algorithms; }
boost::thread_specific_ptr< IAlgContextSvc::Algorithms > m_algorithms
the stack of current algorithms
Definition: AlgContextSvc.h:69
IAlgorithm * AlgContextSvc::currentAlg ( ) const
override

accessor to current algorithm:

See also
IAlgContextSvc

Definition at line 163 of file AlgContextSvc.cpp.

164 {
165  return ( m_algorithms.get() && !m_algorithms->empty() ) ? m_algorithms->back() : nullptr;
166 }
boost::thread_specific_ptr< IAlgContextSvc::Algorithms > m_algorithms
the stack of current algorithms
Definition: AlgContextSvc.h:69
StatusCode AlgContextSvc::finalize ( )
override

standard finalization of the service

See also
IService

Definition at line 89 of file AlgContextSvc.cpp.

90 {
91  if ( m_algorithms.get() && !m_algorithms->empty() ) {
92  warning() << "Non-empty stack of algorithms #" << m_algorithms->size() << endmsg;
93  }
94  // Incident Service
95  if ( m_inc ) {
96  m_inc->removeListener( this );
97  m_inc.reset();
98  }
99  // finalize the base class
100  return Service::finalize();
101 }
StatusCode finalize() override
Definition: Service.cpp:174
SmartIF< IIncidentSvc > m_inc
pointer to Incident Service
Definition: AlgContextSvc.h:71
boost::thread_specific_ptr< IAlgContextSvc::Algorithms > m_algorithms
the stack of current algorithms
Definition: AlgContextSvc.h:69
MsgStream & warning() const
shortcut for the method msgStream(MSG::WARNING)
void reset(TYPE *ptr=nullptr)
Set the internal pointer to the passed one disposing of the old one.
Definition: SmartIF.h:92
virtual void removeListener(IIncidentListener *lis, const std::string &type="")=0
Remove listener.
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209
void AlgContextSvc::handle ( const Incident inc)
override

handle incident

See also
IIncidentListener

Definition at line 170 of file AlgContextSvc.cpp.

171 {
172  // some false sharing is possible but it should be negligable
173  auto currSlot = inc.context().slot();
174  if ( currSlot == EventContext::INVALID_CONTEXT_ID ) {
175  currSlot = 0;
176  }
177  if ( inc.type() == "BeginEvent" ) {
178  m_inEvtLoop[currSlot] = 1;
179  } else if ( inc.type() == "EndEvent" ) {
180  m_inEvtLoop[currSlot] = 0;
181  }
182 
183  // This check is invalidated with RTTI AlgContext object.
184  // Whole service needs to be rewritten. Commenting the error until then
185  // to prevent test failures.
186  // if ( m_algorithms.get() && !m_algorithms->empty() ) {
187  // //skip incident processing algorithm endevent incident
188  // if((m_algorithms->size()!=1) ||
189  // (m_algorithms->back()->type()!="IncidentProcAlg")){
190  // error() << "Non-empty stack of algorithms #"
191  // << m_algorithms->size() << endmsg ;
192  // }
193  // }
194 }
std::vector< int > m_inEvtLoop
Definition: AlgContextSvc.h:76
const std::string & type() const
Access to the incident type.
Definition: Incident.h:41
ContextID_t slot() const
Definition: EventContext.h:40
static const ContextID_t INVALID_CONTEXT_ID
Definition: EventContext.h:30
EventContext context() const
Access to the EventContext of the source of the incident.
Definition: Incident.h:53
StatusCode AlgContextSvc::initialize ( )
override

standard initialization of the service

Instantiation of a static factory class used by clients to create instances of this service.

See also
IService

Definition at line 31 of file AlgContextSvc.cpp.

32 {
33  // Initialize the base class
35  if ( sc.isFailure() ) {
36  return sc;
37  }
38  // Incident Service
39  if ( m_inc ) {
40  m_inc->removeListener( this );
41  m_inc.reset();
42  }
43  // perform more checks?
45  numSlots = ( 1 > numSlots ) ? 1 : numSlots;
46  if ( numSlots > 1000 ) {
47  warning() << "Num Slots are greater than 1000. Is this correct? numSlots=" << numSlots << endmsg;
48  numSlots = 1000;
49  warning() << "Setting numSlots to " << numSlots << endmsg;
50  }
51  m_inEvtLoop.resize( numSlots, 0 );
52 
53  if ( m_check ) {
54  m_inc = Service::service( "IncidentSvc", true );
55  if ( !m_inc ) {
56  error() << "Could not locate 'IncidentSvc'" << endmsg;
57  return StatusCode::FAILURE;
58  }
59  m_inc->addListener( this, IncidentType::BeginEvent );
60  m_inc->addListener( this, IncidentType::EndEvent );
61  }
62  if ( m_algorithms.get() && !m_algorithms->empty() ) {
63  warning() << "Non-empty stack of algorithms #" << m_algorithms->size() << endmsg;
64  }
65  return StatusCode::SUCCESS;
66 }
StatusCode initialize() override
Definition: Service.cpp:64
std::vector< int > m_inEvtLoop
Definition: AlgContextSvc.h:76
SmartIF< IIncidentSvc > m_inc
pointer to Incident Service
Definition: AlgContextSvc.h:71
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:86
boost::thread_specific_ptr< IAlgContextSvc::Algorithms > m_algorithms
the stack of current algorithms
Definition: AlgContextSvc.h:69
T resize(T...args)
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
MsgStream & warning() const
shortcut for the method msgStream(MSG::WARNING)
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:28
virtual void addListener(IIncidentListener *lis, const std::string &type="", long priority=0, bool rethrow=false, bool singleShot=false)=0
Add listener.
StatusCode service(const std::string &name, const T *&psvc, bool createIf=true) const
Access a service by name, creating it if it doesn&#39;t already exist.
Definition: Service.h:85
void reset(TYPE *ptr=nullptr)
Set the internal pointer to the passed one disposing of the old one.
Definition: SmartIF.h:92
virtual void removeListener(IIncidentListener *lis, const std::string &type="")=0
Remove listener.
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209
static GAUDI_API std::size_t numConcurrentEvents()
number of Concurrent Events (for MT)
Gaudi::Property< bool > m_check
Definition: AlgContextSvc.h:73
AlgContextSvc& AlgContextSvc::operator= ( const AlgContextSvc )
privatedelete
StatusCode AlgContextSvc::setCurrentAlg ( IAlgorithm a)
override

set the currently executing algorithm ("push_back")

See also
IAlgContextSvc

Definition at line 105 of file AlgContextSvc.cpp.

106 {
107  if ( !a ) {
108  warning() << "IAlgorithm* points to NULL" << endmsg;
110  }
111  if ( !m_bypassInc ) {
112  auto currSlot = a->getContext().slot();
113  if ( currSlot == EventContext::INVALID_CONTEXT_ID ) currSlot = 0;
114  if ( !m_inEvtLoop[currSlot] ) return StatusCode::SUCCESS;
115  }
116  // check whether thread-local algorithm list already exists
117  // if not, create it
118  if ( !m_algorithms.get() ) {
120  }
121  if ( a->type() != "IncidentProcAlg" ) m_algorithms->push_back( a );
122 
123  return StatusCode::SUCCESS;
124 }
std::vector< int > m_inEvtLoop
Definition: AlgContextSvc.h:76
ContextID_t slot() const
Definition: EventContext.h:40
Gaudi::Property< bool > m_bypassInc
Definition: AlgContextSvc.h:74
boost::thread_specific_ptr< IAlgContextSvc::Algorithms > m_algorithms
the stack of current algorithms
Definition: AlgContextSvc.h:69
virtual const std::string & type() const =0
The type of the algorithm.
MsgStream & warning() const
shortcut for the method msgStream(MSG::WARNING)
static const ContextID_t INVALID_CONTEXT_ID
Definition: EventContext.h:30
virtual const EventContext & getContext() const =0
For concurrency: get the EventContext.
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209
StatusCode AlgContextSvc::start ( )
override

Definition at line 72 of file AlgContextSvc.cpp.

73 {
74  auto sc = Service::start();
76  numSlots = ( 1 > numSlots ) ? 1 : numSlots;
77  if ( numSlots > 1000 ) {
78  warning() << "Num Slots are greater than 1000. Is this correct? numSlots=" << numSlots << endmsg;
79  numSlots = 1000;
80  }
81  m_inEvtLoop.resize( numSlots, 0 );
82 
83  return sc;
84 }
std::vector< int > m_inEvtLoop
Definition: AlgContextSvc.h:76
StatusCode start() override
Definition: Service.cpp:137
T resize(T...args)
MsgStream & warning() const
shortcut for the method msgStream(MSG::WARNING)
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209
static GAUDI_API std::size_t numConcurrentEvents()
number of Concurrent Events (for MT)
StatusCode AlgContextSvc::unSetCurrentAlg ( IAlgorithm a)
override

remove the algorithm ("pop_back")

See also
IAlgContextSvc

Definition at line 128 of file AlgContextSvc.cpp.

129 {
130  // check whether thread-local algorithm list already exists
131  // if not, create it
132  if ( !m_algorithms.get() ) {
134  }
135 
136  if ( !a ) {
137  warning() << "IAlgorithm* points to NULL" << endmsg;
139  }
140 
141  if ( !m_bypassInc ) {
142  auto currSlot = a->getContext().slot();
143  if ( currSlot == EventContext::INVALID_CONTEXT_ID ) currSlot = 0;
144  if ( !m_inEvtLoop[currSlot] ) return StatusCode::SUCCESS;
145  }
146 
147  if ( a->type() != "IncidentProcAlg" ) {
148  // if ( m_algorithms->empty() || m_algorithms->back() != a ){
149  // error() << "Algorithm stack is invalid" << endmsg ;
150  // return StatusCode::FAILURE ;
151  // }
152  if ( !m_algorithms->empty() ) {
153  if ( m_algorithms->back() == a ) {
154  m_algorithms->pop_back();
155  }
156  }
157  }
158  return StatusCode::SUCCESS;
159 }
std::vector< int > m_inEvtLoop
Definition: AlgContextSvc.h:76
ContextID_t slot() const
Definition: EventContext.h:40
Gaudi::Property< bool > m_bypassInc
Definition: AlgContextSvc.h:74
boost::thread_specific_ptr< IAlgContextSvc::Algorithms > m_algorithms
the stack of current algorithms
Definition: AlgContextSvc.h:69
virtual const std::string & type() const =0
The type of the algorithm.
MsgStream & warning() const
shortcut for the method msgStream(MSG::WARNING)
static const ContextID_t INVALID_CONTEXT_ID
Definition: EventContext.h:30
virtual const EventContext & getContext() const =0
For concurrency: get the EventContext.
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209

Member Data Documentation

boost::thread_specific_ptr<IAlgContextSvc::Algorithms> AlgContextSvc::m_algorithms
private

the stack of current algorithms

Definition at line 69 of file AlgContextSvc.h.

Gaudi::Property<bool> AlgContextSvc::m_bypassInc
private
Initial value:
{this, "BypassIncidents", false,
"Flag to bypass begin/endevent incident requirement"}

Definition at line 74 of file AlgContextSvc.h.

Gaudi::Property<bool> AlgContextSvc::m_check {this, "Check", true, "Flag to perform more checks"}
private

Definition at line 73 of file AlgContextSvc.h.

SmartIF<IIncidentSvc> AlgContextSvc::m_inc = nullptr
private

pointer to Incident Service

Definition at line 71 of file AlgContextSvc.h.

std::vector<int> AlgContextSvc::m_inEvtLoop
private

Definition at line 76 of file AlgContextSvc.h.


The documentation for this class was generated from the following files: