Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  v31r0 (aeb156f0)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
AlgContextSvc.cpp
Go to the documentation of this file.
1 // ============================================================================
2 // Include files
3 // ============================================================================
4 // Local
5 // ============================================================================
6 #include "AlgContextSvc.h"
7 // ============================================================================
8 // GaudiKernel
9 // ============================================================================
13 #include "GaudiKernel/MsgStream.h"
14 
15 // ============================================================================
23 // ============================================================================
28 // ============================================================================
29 // standard initialization of the service
30 // ============================================================================
31 StatusCode AlgContextSvc::initialize() {
32  // Initialize the base class
34  if ( sc.isFailure() ) { return sc; }
35  // Incident Service
36  if ( m_inc ) {
37  m_inc->removeListener( this );
38  m_inc.reset();
39  }
40  // perform more checks?
42  numSlots = ( 1 > numSlots ) ? 1 : numSlots;
43  if ( numSlots > 1000 ) {
44  warning() << "Num Slots are greater than 1000. Is this correct? numSlots=" << numSlots << endmsg;
45  numSlots = 1000;
46  warning() << "Setting numSlots to " << numSlots << endmsg;
47  }
48  m_inEvtLoop.resize( numSlots, 0 );
49 
50  if ( m_check ) {
51  m_inc = Service::service( "IncidentSvc", true );
52  if ( !m_inc ) {
53  error() << "Could not locate 'IncidentSvc'" << endmsg;
54  return StatusCode::FAILURE;
55  }
56  m_inc->addListener( this, IncidentType::BeginEvent );
57  m_inc->addListener( this, IncidentType::EndEvent );
58  }
59  if ( m_algorithms.get() && !m_algorithms->empty() ) {
60  warning() << "Non-empty stack of algorithms #" << m_algorithms->size() << endmsg;
61  }
62  return StatusCode::SUCCESS;
63 }
64 
65 // implementation of start
66 // needs to be removed once we have a proper service
67 // for getting configuration information at initialization time
68 // S. Kama
70  auto sc = Service::start();
72  numSlots = ( 1 > numSlots ) ? 1 : numSlots;
73  if ( numSlots > 1000 ) {
74  warning() << "Num Slots are greater than 1000. Is this correct? numSlots=" << numSlots << endmsg;
75  numSlots = 1000;
76  }
77  m_inEvtLoop.resize( numSlots, 0 );
78 
79  return sc;
80 }
81 
82 // ============================================================================
83 // standard finalization of the service @see IService
84 // ============================================================================
86  if ( m_algorithms.get() && !m_algorithms->empty() ) {
87  warning() << "Non-empty stack of algorithms #" << m_algorithms->size() << endmsg;
88  }
89  // Incident Service
90  if ( m_inc ) {
91  m_inc->removeListener( this );
92  m_inc.reset();
93  }
94  // finalize the base class
95  return Service::finalize();
96 }
97 // ============================================================================
98 // set the currently executing algorithm ("push_back") @see IAlgContextSvc
99 // ============================================================================
101  if ( !a ) {
102  warning() << "IAlgorithm* points to NULL" << endmsg;
104  }
105  if ( !m_bypassInc ) {
106  if ( !m_inEvtLoop[context.valid() ? context.slot() : 0] ) return StatusCode::SUCCESS;
107  }
108  // check whether thread-local algorithm list already exists
109  // if not, create it
110  if ( !m_algorithms.get() ) { m_algorithms.reset( new IAlgContextSvc::Algorithms() ); }
111  if ( a->type() != "IncidentProcAlg" ) m_algorithms->push_back( a );
112 
113  return StatusCode::SUCCESS;
114 }
115 // ============================================================================
116 // remove the algorithm ("pop_back") @see IAlgContextSvc
117 // ============================================================================
119  // check whether thread-local algorithm list already exists
120  // if not, create it
121  if ( !m_algorithms.get() ) { m_algorithms.reset( new IAlgContextSvc::Algorithms() ); }
122 
123  if ( !a ) {
124  warning() << "IAlgorithm* points to NULL" << endmsg;
126  }
127 
128  if ( !m_bypassInc ) {
129  if ( !m_inEvtLoop[context.valid() ? context.slot() : 0] ) return StatusCode::SUCCESS;
130  }
131 
132  if ( a->type() != "IncidentProcAlg" ) {
133  // if ( m_algorithms->empty() || m_algorithms->back() != a ){
134  // error() << "Algorithm stack is invalid" << endmsg ;
135  // return StatusCode::FAILURE ;
136  // }
137  if ( !m_algorithms->empty() ) {
138  if ( m_algorithms->back() == a ) { m_algorithms->pop_back(); }
139  }
140  }
141  return StatusCode::SUCCESS;
142 }
143 // ============================================================================
145 // ============================================================================
147  return ( m_algorithms.get() && !m_algorithms->empty() ) ? m_algorithms->back() : nullptr;
148 }
149 // ============================================================================
150 // handle incident @see IIncidentListener
151 // ============================================================================
152 void AlgContextSvc::handle( const Incident& inc ) {
153  // some false sharing is possible but it should be negligable
154  auto currSlot = inc.context().slot();
155  if ( currSlot == EventContext::INVALID_CONTEXT_ID ) { currSlot = 0; }
156  if ( inc.type() == "BeginEvent" ) {
157  m_inEvtLoop[currSlot] = 1;
158  } else if ( inc.type() == "EndEvent" ) {
159  m_inEvtLoop[currSlot] = 0;
160  }
161 
162  // This check is invalidated with RTTI AlgContext object.
163  // Whole service needs to be rewritten. Commenting the error until then
164  // to prevent test failures.
165  // if ( m_algorithms.get() && !m_algorithms->empty() ) {
166  // //skip incident processing algorithm endevent incident
167  // if((m_algorithms->size()!=1) ||
168  // (m_algorithms->back()->type()!="IncidentProcAlg")){
169  // error() << "Non-empty stack of algorithms #"
170  // << m_algorithms->size() << endmsg ;
171  // }
172  // }
173 }
174 // ============================================================================
175 // ============================================================================
177 // ============================================================================
StatusCode initialize() override
Definition: Service.cpp:60
std::vector< int > m_inEvtLoop
Definition: AlgContextSvc.h:73
const std::string & type() const
Access to the incident type.
Definition: Incident.h:38
StatusCode finalize() override
Definition: Service.cpp:164
ContextID_t slot() const
Definition: EventContext.h:48
StatusCode start() override
Definition: Service.cpp:129
Gaudi::Property< bool > m_bypassInc
Definition: AlgContextSvc.h:71
void handle(const Incident &) override
handle incident
StatusCode start() override
constexpr static const auto RECOVERABLE
Definition: StatusCode.h:87
constexpr static const auto SUCCESS
Definition: StatusCode.h:85
SmartIF< IIncidentSvc > m_inc
pointer to Incident Service
Definition: AlgContextSvc.h:68
StatusCode setCurrentAlg(IAlgorithm *a, const EventContext &context) override
set the currently executing algorithm ("push_back")
This class represents an entry point to all the event specific data.
Definition: EventContext.h:31
bool isFailure() const
Definition: StatusCode.h:130
boost::thread_specific_ptr< IAlgContextSvc::Algorithms > m_algorithms
the stack of current algorithms
Definition: AlgContextSvc.h:66
T resize(T...args)
virtual const std::string & type() const =0
The type of the algorithm.
#define DECLARE_COMPONENT(type)
MsgStream & warning() const
shortcut for the method msgStream(MSG::WARNING)
IAlgorithm * currentAlg() const override
accessor to current algorithm:
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:50
static constexpr ContextID_t INVALID_CONTEXT_ID
Definition: EventContext.h:36
The IAlgorithm is the interface implemented by the Algorithm base class.
Definition: IAlgorithm.h:28
StatusCode unSetCurrentAlg(IAlgorithm *a, const EventContext &context) override
remove the algorithm ("pop_back")
Base class for all Incidents (computing events).
Definition: Incident.h:17
constexpr static const auto FAILURE
Definition: StatusCode.h:86
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:83
StatusCode finalize() override
standard finalization of the service
void reset(TYPE *ptr=nullptr)
Set the internal pointer to the passed one disposing of the old one.
Definition: SmartIF.h:86
virtual void removeListener(IIncidentListener *lis, const std::string &type="")=0
Remove listener.
EventContext context() const
Access to the EventContext of the source of the incident.
Definition: Incident.h:50
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:192
static GAUDI_API std::size_t numConcurrentEvents()
number of Concurrent Events (for MT)
bool valid() const
Definition: EventContext.h:51