| The Gaudi Framework v27r1

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

HiveSlimEventLoopMgr.cpp
Go to the documentation of this file.
1 // FW includes
2 #include "GaudiKernel/SmartIF.h"
3 #include "GaudiKernel/Incident.h"
4 #include "GaudiKernel/MsgStream.h"
5 #include "GaudiKernel/SvcFactory.h"
6 #include "GaudiKernel/DataObject.h"
7 #include "GaudiKernel/IAlgManager.h"
8 #include "GaudiKernel/IIncidentSvc.h"
9 #include "GaudiKernel/IEvtSelector.h"
10 #include "GaudiKernel/IDataManagerSvc.h"
11 #include "GaudiKernel/IDataProviderSvc.h"
12 #include "GaudiKernel/IConversionSvc.h"
13 #include "GaudiKernel/AppReturnCode.h"
14 #include "GaudiKernel/DataSvc.h"
15 #include "GaudiKernel/IChronoStatSvc.h"
16 #include "GaudiKernel/IIncidentListener.h"
17
18 #include "HistogramAgent.h"
19
20
21 #include "GaudiHive/HiveSlimEventLoopMgr.h"
22
23 #include "GaudiKernel/EventContext.h"
24 #include "GaudiKernel/Algorithm.h"
25
26 #include <GaudiKernel/GaudiException.h>
27
28 #include <GaudiKernel/IScheduler.h>
29
30 // External libraries
31 #include <chrono>
32
33
34 // Instantiation of a static factory class used by clients to create instances of this service
35 DECLARE_SERVICE_FACTORY(HiveSlimEventLoopMgr)
36
37
38 #define ON_DEBUG if (UNLIKELY(outputLevel() <= MSG::DEBUG))
39 #define ON_VERBOSE if (UNLIKELY(outputLevel() <= MSG::VERBOSE))
40
41 #define DEBMSG ON_DEBUG debug()
42 #define VERMSG ON_VERBOSE verbose()
43
44 //--------------------------------------------------------------------------------------------
45 // Standard Constructor
46 //--------------------------------------------------------------------------------------------
47 HiveSlimEventLoopMgr::HiveSlimEventLoopMgr(const std::string& name, ISvcLocator* svcLoc)
48 : base_class(name, svcLoc), m_appMgrUI(svcLoc)
49 {
50 m_histoDataMgrSvc = 0;
51 m_histoPersSvc = 0;
52 m_evtDataMgrSvc = 0;
53 m_whiteboard = 0;
54 m_evtSelector = 0;
55 m_evtContext = 0;
56 m_blackListBS = nullptr;
57
58 // Declare properties
59 declareProperty("HistogramPersistency", m_histPersName = "");
60 declareProperty("EvtSel", m_evtsel );
61 declareProperty("Warnings",m_warnings=true,
62 "Set this property to false to suppress warning messages");
63 declareProperty("SchedulerName", m_schedulerName="ForwardSchedulerSvc",
64 "Name of the scheduler to be used");
65 declareProperty("EventNumberBlackList", m_eventNumberBlacklist);
66
67 m_scheduledStop = false;
68
69 }
70
71 //--------------------------------------------------------------------------------------------
72 // Standard Destructor
73 //--------------------------------------------------------------------------------------------
74 HiveSlimEventLoopMgr::~HiveSlimEventLoopMgr() {
75 if( m_histoDataMgrSvc ) m_histoDataMgrSvc->release();
76 if( m_histoPersSvc ) m_histoPersSvc->release();
77 if( m_evtDataMgrSvc ) m_evtDataMgrSvc->release();
78 if( m_whiteboard ) m_whiteboard->release();
79 if( m_evtSelector ) m_evtSelector->release();
80 if( m_evtContext ) delete m_evtContext;
81 }
82
83 //--------------------------------------------------------------------------------------------
84 // implementation of IAppMgrUI::initialize
85 //--------------------------------------------------------------------------------------------
86 StatusCode HiveSlimEventLoopMgr::initialize() {
87
88 if ( !m_appMgrUI.isValid() ) {
89 return StatusCode::FAILURE;
90 }
91
92 StatusCode sc = Service::initialize();
93 if ( !sc.isSuccess() ) {
94 error() << "Failed to initialize Service Base class." << endmsg;
95 return StatusCode::FAILURE;
96 }
97
98 // Get the references to the services that are needed by the ApplicationMgr itself
99 m_incidentSvc = serviceLocator()->service("IncidentSvc");
100 if( !m_incidentSvc.isValid() ) {
101 fatal() << "Error retrieving IncidentSvc." << endmsg;
102 return StatusCode::FAILURE;
103 }
104
105 // Setup access to event data services
106 m_evtDataMgrSvc = serviceLocator()->service("EventDataSvc");
107 if( !m_evtDataMgrSvc.isValid() ) {
108 fatal() << "Error retrieving EventDataSvc interface IDataManagerSvc." << endmsg;
109 return StatusCode::FAILURE;
110 }
111 m_whiteboard = serviceLocator()->service("EventDataSvc");
112 if( !m_whiteboard.isValid() ) {
113 fatal() << "Error retrieving EventDataSvc interface IHiveWhiteBoard." << endmsg;
114 return StatusCode::FAILURE;
115 }
116 m_schedulerSvc = serviceLocator()->service(m_schedulerName);
117 if ( !m_schedulerSvc.isValid()){
118 fatal() << "Error retrieving SchedulerSvc interface ISchedulerSvc." << endmsg;
119 return StatusCode::FAILURE;
120 }
121 // Obtain the IProperty of the ApplicationMgr
122 m_appMgrProperty = serviceLocator();
123 if ( ! m_appMgrProperty.isValid() ) {
124 fatal() << "IProperty interface not found in ApplicationMgr." << endmsg;
125 return StatusCode::FAILURE;
126 }
127
128 // We do not expect a Event Selector necessarily being declared
129 setProperty(m_appMgrProperty->getProperty("EvtSel")).ignore();
130
131 if( m_evtsel != "NONE" || m_evtsel.length() == 0) {
132 m_evtSelector = serviceLocator()->service("EventSelector");
133 if( m_evtSelector.isValid() ) {
134 // Setup Event Selector
135 sc=m_evtSelector->createContext(m_evtContext);
136 if( !sc.isSuccess() ) {
137 fatal() << "Can not create the event selector Context." << endmsg;
138 return sc;
139 }
140 }
141 else {
142 fatal() << "EventSelector not found." << endmsg;
143 return sc;
144 }
145 }
146 else {
147 m_evtSelector = 0;
148 m_evtContext = 0;
149 if ( m_warnings ) {
150 warning() << "Unable to locate service \"EventSelector\" " << endmsg;
151 warning() << "No events will be processed from external input." << endmsg;
152 }
153 }
154
155 // Setup access to histogramming services
156 m_histoDataMgrSvc = serviceLocator()->service("HistogramDataSvc");
157 if( !m_histoDataMgrSvc.isValid() ) {
158 fatal() << "Error retrieving HistogramDataSvc." << endmsg;
159 return sc;
160 }
161 // Setup histogram persistency
162 m_histoPersSvc = serviceLocator()->service("HistogramPersistencySvc");
163 if( !m_histoPersSvc.isValid() ) {
164 warning() << "Histograms cannot not be saved - though required." << endmsg;
165 return sc;
166 }
167
168 // Setup algorithm resource pool
169 m_algResourcePool = serviceLocator()->service("AlgResourcePool");
170 if( !m_algResourcePool.isValid() ) {
171 fatal() << "Error retrieving AlgResourcePool" << endmsg;
172 return StatusCode::FAILURE;
173 }
174
175 std::sort(m_eventNumberBlacklist.begin(), m_eventNumberBlacklist.end());
176 info() << "Found " << m_eventNumberBlacklist.size() << " events in black list" << endmsg;
177
178 return StatusCode::SUCCESS;
179 }
180 //--------------------------------------------------------------------------------------------
181 // implementation of IService::reinitialize
182 //--------------------------------------------------------------------------------------------
183 StatusCode HiveSlimEventLoopMgr::reinitialize() {
184
185
186 // Check to see whether a new Event Selector has been specified
187 setProperty(m_appMgrProperty->getProperty("EvtSel"));
188 if( m_evtsel != "NONE" || m_evtsel.length() == 0) {
189 SmartIF<IService> theSvc(serviceLocator()->service("EventSelector"));
190 SmartIF<IEvtSelector> theEvtSel(theSvc);
191 StatusCode sc;
192 if( theEvtSel.isValid() && ( theEvtSel.get() != m_evtSelector.get() ) ) {
193 // Setup Event Selector
194 if ( m_evtSelector.get() && m_evtContext ) {
195 // Need to release context before switching to new event selector
196 m_evtSelector->releaseContext(m_evtContext);
197 m_evtContext = 0;
198 }
199 m_evtSelector = theEvtSel;
200 if (theSvc->FSMState() == Gaudi::StateMachine::INITIALIZED) {
201 sc = theSvc->reinitialize();
202 if( !sc.isSuccess() ) {
203 error() << "Failure Reinitializing EventSelector "
204 << theSvc->name( ) << endmsg;
205 return sc;
206 }
207 }
208 else {
209 sc = theSvc->sysInitialize();
210 if( !sc.isSuccess() ) {
211 error() << "Failure Initializing EventSelector "
212 << theSvc->name( ) << endmsg;
213 return sc;
214 }
215 }
216 sc = m_evtSelector->createContext(m_evtContext);
217 if( !sc.isSuccess() ) {
218 error() << "Can not create Context " << theSvc->name( ) << endmsg;
219 return sc;
220 }
221
222 }
223 else if ( m_evtSelector.isValid() ) {
224 if ( m_evtContext ) {
225 m_evtSelector->releaseContext(m_evtContext);
226 m_evtContext = 0;
227 }
228 sc = m_evtSelector->createContext(m_evtContext);
229 if( !sc.isSuccess() ) {
230 error() << "Can not create Context " << theSvc->name( ) << endmsg;
231 return sc;
232 }
233 }
234 }
235 else if ( m_evtSelector.isValid() && m_evtContext ) {
236 m_evtSelector->releaseContext(m_evtContext);
237 m_evtSelector = 0;
238 m_evtContext = 0;
239 }
240 return StatusCode::SUCCESS;
241 }
242
243 //--------------------------------------------------------------------------------------------
244 // implementation of IService::stop
245 //--------------------------------------------------------------------------------------------
246 // Removed call to MinimalEventLoopMgr!
247 StatusCode HiveSlimEventLoopMgr::stop() {
248 if ( ! m_endEventFired ) {
249 // Fire pending EndEvent incident
250 m_incidentSvc->fireIncident(Incident(name(),IncidentType::EndEvent));
251 m_endEventFired = true;
252 }
253 return StatusCode::SUCCESS;
254 }
255
256 //--------------------------------------------------------------------------------------------
257 // implementation of IAppMgrUI::finalize
258 //--------------------------------------------------------------------------------------------
259 // Removed call to MinimalEventLoopMgr!
260 StatusCode HiveSlimEventLoopMgr::finalize() {
261
262 StatusCode scRet;
263 StatusCode sc = Service::finalize();
264
265 if (sc.isFailure()) {
266 scRet = StatusCode::FAILURE;
267 error() << "Problems finalizing Service base class" << endmsg;
268 }
269
270 // Save Histograms Now
271 if ( m_histoPersSvc != 0 ) {
272 HistogramAgent agent;
273 sc = m_histoDataMgrSvc->traverseTree( &agent );
274 if( sc.isSuccess() ) {
275 IDataSelector* objects = agent.selectedObjects();
276 // skip /stat entry!
277 if ( objects->size() > 0 ) {
278 IDataSelector::iterator i;
279 for ( i = objects->begin(); i != objects->end(); i++ ) {
280 IOpaqueAddress* pAddr = 0;
281 StatusCode iret = m_histoPersSvc->createRep(*i, pAddr);
282 if ( iret.isSuccess() ) {
283 (*i)->registry()->setAddress(pAddr);
284 }
285 else {
286 sc = iret;
287 }
288 }
289 for ( i = objects->begin(); i != objects->end(); i++ ) {
290 IRegistry* reg = (*i)->registry();
291 StatusCode iret = m_histoPersSvc->fillRepRefs(reg->address(), *i);
292 if ( !iret.isSuccess() ) {
293 sc = iret;
294 }
295 }
296 }
297 if ( sc.isSuccess() ) {
298 info() << "Histograms converted successfully according to request." << endmsg;
299 }
300 else {
301 error() << "Error while saving Histograms." << endmsg;
302 }
303 }
304 else {
305 error() << "Error while traversing Histogram data store" << endmsg;
306 }
307 }
308
309 scRet=sc;
310
311 // Release event selector context
312 if ( m_evtSelector && m_evtContext ) {
313 m_evtSelector->releaseContext(m_evtContext).ignore();
314 m_evtContext = 0;
315 }
316
317 m_incidentSvc = 0; // release
318 m_appMgrUI = 0; // release
319
320 // Release all interfaces...
321 m_histoDataMgrSvc = 0;
322 m_histoPersSvc = 0;
323
324 m_evtSelector = 0;
325 m_whiteboard = 0;
326 m_evtDataMgrSvc = 0;
327
328 return scRet;
329 }
330
331 //--------------------------------------------------------------------------------------------
332 // implementation of executeEvent(void* par)
333 //--------------------------------------------------------------------------------------------
334 StatusCode HiveSlimEventLoopMgr::executeEvent(void* createdEvts_IntPtr) {
335
336 // Leave the interface intact and swallow this C trick.
337 int& createdEvts = *((int*)createdEvts_IntPtr);
338
339 EventContext* evtContext(nullptr);
340
341 // Check if event number is in blacklist
342 if(LIKELY(m_blackListBS != nullptr)){ //we are processing a finite number of events, use bitset blacklist
343 if(m_blackListBS->test(createdEvts)){
344 verbose() << "Event " << createdEvts << " on black list" << endmsg;
345 return StatusCode::RECOVERABLE;
346 }
347 } else if(std::binary_search(m_eventNumberBlacklist.begin(),m_eventNumberBlacklist.end(),createdEvts)){
348
349 verbose() << "Event " << createdEvts << " on black list" << endmsg;
350 return StatusCode::RECOVERABLE;
351 }
352
353 if ( createEventContext(evtContext,createdEvts).isFailure() ){
354 fatal() << "Impossible to create event context" << endmsg;
355 return StatusCode::FAILURE;
356 }
357
358 verbose() << "Beginning to process event " << createdEvts << endmsg;
359
360 // An incident may schedule a stop, in which case is better to exit before the actual execution.
361 // DP have to find out who shoots this
362 /* if ( m_scheduledStop ) {
363 always() << "Terminating event processing loop due to a stop scheduled by an incident listener" << endmsg;
364 return StatusCode::SUCCESS;
365 }*/
366
367
368 StatusCode declEvtRootSc = declareEventRootAddress();
369 if (declEvtRootSc.isFailure()) { // We ran out of events!
370 createdEvts = -1; // Set created event to a negative value: we finished!
371 return StatusCode::SUCCESS;
372 }
373
374 // Fire BeginEvent "Incident"
375 m_incidentSvc->fireIncident(Incident(name(),IncidentType::BeginEvent));
376
377 // Now add event to the scheduler
378 verbose() << "Adding event " << evtContext->evt()
379 << ", slot " << evtContext->slot()
380 << " to the scheduler" << endmsg;
381
382 m_incidentSvc->fireIncident(Incident(name(), IncidentType::BeginProcessing));
383
384 StatusCode addEventStatus = m_schedulerSvc->pushNewEvent(evtContext);
385
386 // If this fails, we need to wait for something to complete
387 if (!addEventStatus.isSuccess()){
388 fatal() << "An event processing slot should be now free in the scheduler, but it appears not to be the case." << endmsg;
389 }
390
391 createdEvts++;
392 return StatusCode::SUCCESS;
393
394 }
395
396 //--------------------------------------------------------------------------------------------
397 // implementation of IEventProcessing::executeRun
398 //--------------------------------------------------------------------------------------------
399 StatusCode HiveSlimEventLoopMgr::executeRun( int maxevt ) {
400 StatusCode sc;
401 bool eventfailed = false;
402
403 if(maxevt > 0){ //finite number of events to process
404 const unsigned int umaxevt = static_cast<unsigned int>(maxevt);
405 m_blackListBS = new boost::dynamic_bitset<>(maxevt); //all initialized to zero
406 for(unsigned int i = 0; i < m_eventNumberBlacklist.size() && m_eventNumberBlacklist[i] <= umaxevt; ++i ){ //black list is sorted in init
407 m_blackListBS->set(m_eventNumberBlacklist[i], true);
408 }
409 }
410
411 sc = m_algResourcePool->beginRun();
412 if (sc.isFailure())
413 eventfailed=true;
414
415 // Call now the nextEvent(...)
416 sc = nextEvent(maxevt);
417 if (!sc.isSuccess())
418 eventfailed = true;
419
420 sc = m_algResourcePool->endRun();
421 if (sc.isFailure())
422 eventfailed=true;
423
424 if(m_blackListBS != nullptr)
425 delete m_blackListBS;
426
427 if (eventfailed)
428 return StatusCode::FAILURE;
429 else
430 return StatusCode::SUCCESS;
431 }
432
433 //--------------------------------------------------------------------------------------------
434 // Implementation of IEventProcessor::stopRun()
435 //--------------------------------------------------------------------------------------------
436 StatusCode HiveSlimEventLoopMgr::stopRun() {
437 // Set the application return code
438 SmartIF<IProperty> appmgr(serviceLocator());
439 if(Gaudi::setAppReturnCode(appmgr, Gaudi::ReturnCode::ScheduledStop).isFailure()) {
440 error() << "Could not set return code of the application ("
441 << Gaudi::ReturnCode::ScheduledStop << ")" << endmsg;
442 }
443 m_scheduledStop = true;
444 return StatusCode::SUCCESS;
445 }
446
447 //--------------------------------------------------------------------------------------------
448 // implementation of IAppMgrUI::nextEvent
449 //--------------------------------------------------------------------------------------------
450 // Here the loop on the events takes place.
451 // This is also the natural place to put the preparation of the algorithms
452 // contexts, which contain the event specific data.
453 #include "GaudiKernel/Memory.h"
454 StatusCode HiveSlimEventLoopMgr::nextEvent(int maxevt) {
455
456 // Calculate runtime
457 typedef std::chrono::high_resolution_clock Clock;
458 typedef Clock::time_point time_point;
459
460 // Reset the application return code.
461 Gaudi::setAppReturnCode(m_appMgrProperty, Gaudi::ReturnCode::Success, true).ignore();
462
463 int finishedEvts =0;
464 int createdEvts =0;
465 int skippedEvts = 0;
466 info() << "Starting loop on events" << endmsg;
467 // Loop until the finished events did not reach the maxevt number
468 bool loop_ended = false;
469 // Run the first event before spilling more than one
470 bool newEvtAllowed = false ;
471
472 constexpr double oneOver1204 = 1./1024.;
473
474 uint iteration = 0;
475 time_point start_time = Clock::now();
476 while ( !loop_ended and (maxevt < 0 or (finishedEvts+skippedEvts) < maxevt)){
477 debug() << "work loop iteration " << iteration++ << endmsg;
478 // if the created events did not reach maxevt, create an event
479 if ((newEvtAllowed or createdEvts == 0 ) && // Launch the first event alone
480 createdEvts >= 0 && // The events are not finished with an unlimited number of events
481 (createdEvts < maxevt or maxevt<0) && // The events are not finished with a limited number of events
482 m_schedulerSvc->freeSlots()>0){ // There are still free slots in the scheduler
483
484 if (1==createdEvts) // reset counter to count from event 1
485 start_time = Clock::now();
486
487 debug() << "createdEvts: " << createdEvts << ", freeslots: " << m_schedulerSvc->freeSlots() << endmsg;
488 // DP remove to remove the syscalls...
489 // if (0!=createdEvts){
490 // info() << "Event Number = " << createdEvts
491 // << " WSS (MB) = " << System::mappedMemory(System::MemoryUnit::kByte)*oneOver1204
492 // << " Time (s) = " << secsFromStart(start_time) << endmsg;
493 // }
494
495 //TODO can we adapt the interface of executeEvent for a nicer solution?
496 StatusCode sc = StatusCode::RECOVERABLE;
497 while(!sc.isSuccess() //we haven't created an event yet
498 && (createdEvts < maxevt or maxevt<0)){ //redunant check for maxEvts, can we do better?
499 sc = executeEvent(&createdEvts);
500
501 if (sc.isRecoverable()){ //we skipped an event
502
503 //this is all to skip the event
504 size_t slot = m_whiteboard->allocateStore(createdEvts); //we need a new store, not to change the previous event
505 m_whiteboard->selectStore(slot);
506 declareEventRootAddress(); //actually skip over the event
507 m_whiteboard->freeStore(slot); // delete the store
508
509 ++createdEvts;
510 ++skippedEvts;
511 } else if (sc.isRecoverable()){ //exit immediatly
512 return StatusCode::FAILURE;
513 } // else we have an success --> exit loop
514 }
515
516 } // end if condition createdEvts < maxevt
517 else{
518 // all the events were created but not all finished or the slots were
519 // all busy: the scheduler should finish its job
520
521 debug() << "Draining the scheduler" << endmsg;
522
523 // Pull out of the scheduler the finished events
524 if (drainScheduler(finishedEvts).isFailure()){
525 loop_ended = true;
526 }
527 newEvtAllowed = true;
528 }
529 } // end main loop on finished events
530 time_point end_time = Clock::now();
531
532 info() << "---> Loop Finished (skipping 1st evt) - "
533 << " WSS " << System::mappedMemory(System::MemoryUnit::kByte)*oneOver1204
534 << " total time " << std::chrono::duration_cast < std::chrono::nanoseconds > (end_time - start_time).count() <<endmsg;
535 info() << skippedEvts << " events were SKIPed" << endmsg;
536
537 return StatusCode::SUCCESS;
538
539 }
540
541 //---------------------------------------------------------------------------
542
544 StatusCode HiveSlimEventLoopMgr::getEventRoot(IOpaqueAddress*& refpAddr) {
545 refpAddr = 0;
546 StatusCode sc = m_evtSelector->next(*m_evtContext);
547 if ( !sc.isSuccess() ) {
548 return sc;
549 }
550 // Create root address and assign address to data service
551 sc = m_evtSelector->createAddress(*m_evtContext,refpAddr);
552 if( !sc.isSuccess() ) {
553 sc = m_evtSelector->next(*m_evtContext);
554 if ( sc.isSuccess() ) {
555 sc = m_evtSelector->createAddress(*m_evtContext,refpAddr);
556 if ( !sc.isSuccess() ) {
557 warning() << "Error creating IOpaqueAddress." << endmsg;
558 }
559 }
560 }
561 return sc;
562 }
563
564 //---------------------------------------------------------------------------
565
566 StatusCode HiveSlimEventLoopMgr::declareEventRootAddress(){
567
568 StatusCode sc;
569 if( m_evtContext ) {
570 //---This is the "event iterator" context from EventSelector
571 IOpaqueAddress* pAddr = 0;
572 sc = getEventRoot(pAddr);
573 if( !sc.isSuccess() ) {
574 info() << "No more events in event selection " << endmsg;
575 return StatusCode::FAILURE;
576 }
577 sc = m_evtDataMgrSvc->setRoot ("/Event", pAddr);
578 if( !sc.isSuccess() ) {
579 warning() << "Error declaring event root address." << endmsg;
580 }
581 }
582 else {
583 //---In case of no event selector----------------
584 sc = m_evtDataMgrSvc->setRoot ("/Event", new DataObject());
585 if( !sc.isSuccess() ) {
586 warning() << "Error declaring event root DataObject" << endmsg;
587 }
588 }
589 return StatusCode::SUCCESS;
590 }
591
592 //---------------------------------------------------------------------------
593
594 StatusCode HiveSlimEventLoopMgr::createEventContext(EventContext*& evtContext, int createdEvts){
595 evtContext = new EventContext;
596
597 evtContext->set(createdEvts, m_whiteboard->allocateStore(createdEvts));
598
599 StatusCode sc = m_whiteboard->selectStore(evtContext->slot());
600 if (sc.isFailure()){
601 warning() << "Slot " << evtContext->slot()
602 << " could not be selected for the WhiteBoard" << endmsg;
603 }
604 return sc;
605 }
606
607 //---------------------------------------------------------------------------
608
609 StatusCode HiveSlimEventLoopMgr::drainScheduler(int& finishedEvts){
610
611 StatusCode sc(StatusCode::SUCCESS);
612
613 // maybe we can do better
614 std::vector<EventContext*> finishedEvtContexts;
615
616 EventContext* finishedEvtContext(nullptr);
617
618 // Here we wait not to loose cpu resources
619 debug() << "Waiting for a context" << endmsg;
620 sc = m_schedulerSvc->popFinishedEvent(finishedEvtContext);
621
622 // We got past it: cache the pointer
623 if (sc.isSuccess()){
624 debug() << "Context obtained" << endmsg;
625 } else{
626 // A problem occurred.
627 debug() << "Context not obtained: a problem in the scheduling?" << endmsg;
628 // return StatusCode::FAILURE;
629 }
630 finishedEvtContexts.push_back(finishedEvtContext);
631
632 // Let's see if we can pop other event contexts
633 while (m_schedulerSvc->tryPopFinishedEvent(finishedEvtContext).isSuccess()){
634 finishedEvtContexts.push_back(finishedEvtContext);
635 }
636
637 // Now we flush them
638 StatusCode finalSC;
639 for (auto& thisFinishedEvtContext : finishedEvtContexts){
640 if (nullptr == thisFinishedEvtContext){
641 error() << "Detected nullptr ctxt before clearing WB!"<< endmsg;
642 finalSC = StatusCode::FAILURE;
643 continue;
644 }
645 if (thisFinishedEvtContext->evtFail()){
646 fatal() << "Failed event detected"<< endmsg;
647 finalSC = StatusCode::FAILURE;
648 }
649
650 m_incidentSvc->fireIncident(Incident(name(), IncidentType::EndProcessing));
651 m_incidentSvc->fireIncident(Incident(name(),IncidentType::EndEvent));
652
653 debug() << "Clearing slot " << thisFinishedEvtContext->slot()
654 << " (event " << thisFinishedEvtContext->evt()
655 << ") of the whiteboard" << endmsg;
656
657 StatusCode sc = clearWBSlot(thisFinishedEvtContext->slot());
658 if (!sc.isSuccess())
659 error() << "Whiteboard slot " << thisFinishedEvtContext->slot()
660 << " could not be properly cleared";
661
662
663 delete thisFinishedEvtContext;
664
665 finishedEvts++;
666
667 }
668 return finalSC;
669 }
670
671 //---------------------------------------------------------------------------
672
673 StatusCode HiveSlimEventLoopMgr::clearWBSlot(int evtSlot) {
674 StatusCode sc = m_whiteboard->clearStore(evtSlot);
675 if( !sc.isSuccess() ) {
676 warning() << "Clear of Event data store failed" << endmsg;
677 }
678 return m_whiteboard->freeStore(evtSlot);
679 }
680 //---------------------------------------------------------------------------
681
682
683
684
685
686
687
688
689
690
HiveSlimEventLoopMgr::finalize
virtual StatusCode finalize()
implementation of IService::finalize
Definition: HiveSlimEventLoopMgr.cpp:260
HiveSlimEventLoopMgr::clearWBSlot
StatusCode clearWBSlot(int evtSlot)
Clear a slot in the WB.
Definition: HiveSlimEventLoopMgr.cpp:673
Service::initialize
StatusCode initialize() override
Definition: Service.cpp:68
std::chrono::nanoseconds
Gaudi::StateMachine::INITIALIZED
Definition: StateMachine.h:15
HiveSlimEventLoopMgr::m_incidentSvc
SmartIF< IIncidentSvc > m_incidentSvc
Reference to the incident service.
Definition: HiveSlimEventLoopMgr.h:73
Algorithm.h
SmartIF< IService >
Service::serviceLocator
SmartIF< ISvcLocator > & serviceLocator() const override
Retrieve pointer to service locator.
Definition: Service.cpp:324
HiveSlimEventLoopMgr::m_evtDataMgrSvc
SmartIF< IDataManagerSvc > m_evtDataMgrSvc
Reference to the Event Data Service's IDataManagerSvc interface.
Definition: HiveSlimEventLoopMgr.h:30
HiveSlimEventLoopMgr::executeEvent
virtual StatusCode executeEvent(void *par)
implementation of IEventProcessor::executeEvent(void* par)
Definition: HiveSlimEventLoopMgr.cpp:334
ISvcLocator
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:25
HiveSlimEventLoopMgr::declareEventRootAddress
StatusCode declareEventRootAddress()
Declare the root address of the event.
Definition: HiveSlimEventLoopMgr.cpp:566
IProperty::getProperty
virtual StatusCode getProperty(Property *p) const =0
Get the property by property.
HiveSlimEventLoopMgr::stopRun
virtual StatusCode stopRun()
implementation of IEventProcessor::stopRun()
Definition: HiveSlimEventLoopMgr.cpp:436
gaudiComponentHelp.name
name
Definition: gaudiComponentHelp.py:28
Service::finalize
StatusCode finalize() override
Definition: Service.cpp:193
EventContext::slot
ContextID_t slot() const
Definition: EventContext.h:41
MsgStream.h
HiveSlimEventLoopMgr::m_appMgrUI
SmartIF< IAppMgrUI > m_appMgrUI
Reference to the IAppMgrUI interface of the application manager.
Definition: HiveSlimEventLoopMgr.h:71
CommonMessagingBase::info
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
Definition: CommonMessaging.h:124
HiveSlimEventLoopMgr::HiveSlimEventLoopMgr
HiveSlimEventLoopMgr(const std::string &nam, ISvcLocator *svcLoc)
Standard Constructor.
Definition: HiveSlimEventLoopMgr.cpp:47
HiveSlimEventLoopMgr::drainScheduler
StatusCode drainScheduler(int &finishedEvents)
Drain the scheduler from all actions that may be queued.
Definition: HiveSlimEventLoopMgr.cpp:609
StatusCode::isSuccess
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:76
HistogramAgent
HistogramAgent base in charge of collecting all the refereces to DataObjects in a transient store tha...
Definition: HistogramAgent.h:17
HiveSlimEventLoopMgr::m_whiteboard
SmartIF< IHiveWhiteBoard > m_whiteboard
Reference to the Whiteboard.
Definition: HiveSlimEventLoopMgr.h:42
HiveSlimEventLoopMgr::m_schedulerSvc
SmartIF< IScheduler > m_schedulerSvc
A shortcut for the scheduler.
Definition: HiveSlimEventLoopMgr.h:55
CommonMessagingBase::verbose
MsgStream & verbose() const
shortcut for the method msgStream(MSG::VERBOSE)
Definition: CommonMessaging.h:130
HiveSlimEventLoopMgr::m_scheduledStop
bool m_scheduledStop
Scheduled stop of event processing.
Definition: HiveSlimEventLoopMgr.h:69
std::binary_search
T binary_search(T...args)
Service::setProperty
StatusCode setProperty(const Property &p) override
Definition: Service.cpp:330
EventContext.h
HiveSlimEventLoopMgr
Definition: HiveSlimEventLoopMgr.h:25
std::chrono::duration_cast
T duration_cast(T...args)
std::vector::end
T end(T...args)
IConverter::createRep
virtual StatusCode createRep(DataObject *pObject, IOpaqueAddress *&refpAddress)=0
Convert the transient object to the requested representation.
IScheduler.h
merge_files.sc
int sc
Definition: merge_files.py:167
EventContext
This class represents an entry point to all the event specific data.
Definition: EventContext.h:25
HiveSlimEventLoopMgr::m_histPersName
std::string m_histPersName
Name of the Hist Pers type.
Definition: HiveSlimEventLoopMgr.h:46
StatusCode::RECOVERABLE
Definition: StatusCode.h:31
HiveSlimEventLoopMgr::m_appMgrProperty
SmartIF< IProperty > m_appMgrProperty
Property interface of ApplicationMgr.
Definition: HiveSlimEventLoopMgr.h:48
StatusCode::isFailure
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:86
HiveSlimEventLoopMgr::m_eventNumberBlacklist
std::vector< unsigned int > m_eventNumberBlacklist
List of events to be skipped. The number is the number in the job.
Definition: HiveSlimEventLoopMgr.h:76
Gaudi::ReturnCode::ScheduledStop
constexpr int ScheduledStop
Definition: AppReturnCode.h:25
System::kByte
Definition: Memory.h:56
EventContext::evt
ContextEvt_t evt() const
Definition: EventContext.h:40
std::string
STL class.
Incident.h
SmartIF::get
TYPE * get() const
Get interface pointer.
Definition: SmartIF.h:76
IService::sysInitialize
virtual StatusCode sysInitialize()=0
Initialize Service.
DataSvc.h
ISvcLocator::service
StatusCode service(const Gaudi::Utils::TypeNameString &name, T *&svc, bool createIf=true)
Templated method to access a service by name.
Definition: ISvcLocator.h:78
HiveSlimEventLoopMgr::m_evtsel
std::string m_evtsel
Event selector.
Definition: HiveSlimEventLoopMgr.h:36
Service::name
const std::string & name() const override
Retrieve name of the service.
Definition: Service.cpp:319
std::vector::push_back
T push_back(T...args)
CommonMessagingBase::error
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
Definition: CommonMessaging.h:118
SvcFactory.h
IHiveWhiteBoard::selectStore
virtual StatusCode selectStore(size_t partitionIndex)=0
Activate an given 'slot' for all subsequent calls within the same thread id.
IIncidentSvc::fireIncident
virtual void fireIncident(const Incident &incident)=0
Fire an Incident.
IDataManagerSvc.h
IDataProviderSvc.h
std::chrono::high_resolution_clock
CommonMessagingBase::warning
MsgStream & warning() const
shortcut for the method msgStream(MSG::WARNING)
Definition: CommonMessaging.h:121
IHiveWhiteBoard::clearStore
virtual StatusCode clearStore(size_t partitionIndex)=0
Clear an given 'slot'.
HiveSlimEventLoopMgr::executeRun
virtual StatusCode executeRun(int maxevt)
implementation of IEventProcessor::executeRun()
Definition: HiveSlimEventLoopMgr.cpp:399
HiveSlimEventLoopMgr.h
StatusCode::FAILURE
Definition: StatusCode.h:29
IDataManagerSvc::traverseTree
virtual StatusCode traverseTree(IDataStoreAgent *pAgent)=0
Analyse by traversing all data objects in the data store.
IAlgResourcePool::endRun
virtual StatusCode endRun()=0
End Run.
IIncidentSvc.h
StatusCode::SUCCESS
Definition: StatusCode.h:30
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
GaudiException.h
IEvtSelector::next
virtual StatusCode next(Context &c) const =0
Fetch the next event or the first event if it will be use soon after the creation of the context...
SmartIF.h
IEvtSelector::createContext
virtual StatusCode createContext(Context *&c) const =0
Create and return a context object that will keep track of the state of selection.
HiveSlimEventLoopMgr::createEventContext
StatusCode createEventContext(EventContext *&eventContext, int createdEvents)
Create event context.
Definition: HiveSlimEventLoopMgr.cpp:594
IEvtSelector::releaseContext
virtual StatusCode releaseContext(Context *&) const =0
Release the Context object.
IRegistry
The IRegistry represents the entry door to the environment any data object residing in a transient da...
Definition: IRegistry.h:22
IScheduler::pushNewEvent
virtual StatusCode pushNewEvent(EventContext *eventContext)=0
Make an event available to the scheduler.
DECLARE_SERVICE_FACTORY
#define DECLARE_SERVICE_FACTORY(x)
Definition: Service.h:361
HiveSlimEventLoopMgr::~HiveSlimEventLoopMgr
virtual ~HiveSlimEventLoopMgr()
Standard Destructor.
Definition: HiveSlimEventLoopMgr.cpp:74
HiveSlimEventLoopMgr::getEventRoot
StatusCode getEventRoot(IOpaqueAddress *&refpAddr)
Create event address using event selector.
Definition: HiveSlimEventLoopMgr.cpp:544
StatusCode::isRecoverable
bool isRecoverable() const
Definition: StatusCode.h:87
Clock
std::chrono::high_resolution_clock Clock
Definition: ITimelineSvc.h:11
HistogramAgent::selectedObjects
IDataSelector * selectedObjects()
Return the set of selected DataObjects.
Definition: HistogramAgent.h:28
HiveSlimEventLoopMgr::initialize
virtual StatusCode initialize()
implementation of IService::initialize
Definition: HiveSlimEventLoopMgr.cpp:86
HiveSlimEventLoopMgr::reinitialize
virtual StatusCode reinitialize()
implementation of IService::reinitialize
Definition: HiveSlimEventLoopMgr.cpp:183
Gaudi::setAppReturnCode
StatusCode setAppReturnCode(SmartIF< IProperty > &appmgr, int value, bool force=false)
Set the application return code.
Definition: AppReturnCode.h:50
IRegistry::address
virtual IOpaqueAddress * address() const =0
Retrieve opaque storage address.
IDataManagerSvc::setRoot
virtual StatusCode setRoot(std::string root_name, DataObject *pObject)=0
Initialize data store for new event by giving new event path.
LIKELY
#define LIKELY(x)
Definition: Kernel.h:125
HiveSlimEventLoopMgr::nextEvent
virtual StatusCode nextEvent(int maxevt)
implementation of IService::nextEvent
Definition: HiveSlimEventLoopMgr.cpp:454
HiveSlimEventLoopMgr::stop
virtual StatusCode stop()
implementation of IService::stop
Definition: HiveSlimEventLoopMgr.cpp:247
AppReturnCode.h
HiveSlimEventLoopMgr::m_warnings
bool m_warnings
Flag to disable warning messages when using external input.
Definition: HiveSlimEventLoopMgr.h:53
GaudiPython.Bindings.DataObject
DataObject
Definition: Bindings.py:50
System::mappedMemory
GAUDI_API long mappedMemory(MemoryUnit unit=kByte, InfoType fetch=Memory, long pid=-1)
Basic Process Information: priority boost.
Definition: Memory.cpp:180
std::string::length
T length(T...args)
std::vector< DataObject * >
Memory.h
IAlgResourcePool::beginRun
virtual StatusCode beginRun()=0
Begin Run.
IInterface::release
virtual unsigned long release()=0
Release Interface instance.
CommonMessagingBase::debug
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
Definition: CommonMessaging.h:127
IConversionSvc.h
HiveSlimEventLoopMgr::m_histoPersSvc
SmartIF< IConversionSvc > m_histoPersSvc
Reference to the Histogram Persistency Service.
Definition: HiveSlimEventLoopMgr.h:40
IHiveWhiteBoard::allocateStore
virtual size_t allocateStore(int evtnumber)=0
Allocate a store partition for new event.
SmartIF::isValid
bool isValid() const
Allow for check if smart pointer is valid.
Definition: SmartIF.h:62
std::vector::begin
T begin(T...args)
time_point
Clock::time_point time_point
Definition: ITimelineSvc.h:12
std::chrono::high_resolution_clock::now
T now(T...args)
IScheduler::tryPopFinishedEvent
virtual StatusCode tryPopFinishedEvent(EventContext *&eventContext)=0
Try to retrieve a finished event from the scheduler.
Incident
Base class for all Incidents (computing events).
Definition: Incident.h:17
HiveSlimEventLoopMgr::m_histoDataMgrSvc
SmartIF< IDataManagerSvc > m_histoDataMgrSvc
Reference to the Histogram Data Service.
Definition: HiveSlimEventLoopMgr.h:38
HiveSlimEventLoopMgr::m_evtSelector
SmartIF< IEvtSelector > m_evtSelector
Reference to the Event Selector.
Definition: HiveSlimEventLoopMgr.h:32
IHiveWhiteBoard::freeStore
virtual StatusCode freeStore(size_t partitionIndex)=0
Free a store partition.
CommonMessaging
Definition: CommonMessaging.h:58
IAlgManager.h
IEvtSelector.h
IIncidentListener.h
Service::service
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.
Definition: Service.h:144
IChronoStatSvc.h
std::sort
T sort(T...args)
HistogramAgent.h
HiveSlimEventLoopMgr::m_schedulerName
std::string m_schedulerName
Name of the scheduler to be used.
Definition: HiveSlimEventLoopMgr.h:67
EventContext::set
void set(const ContextEvt_t &e=0, const ContextID_t &s=INVALID_CONTEXT_ID, const bool f=false)
Definition: EventContext.h:47
IOpaqueAddress
Opaque address interface definition.
Definition: IOpaqueAddress.h:23
StatusCode::ignore
void ignore() const
Definition: StatusCode.h:108
CommonMessagingBase::fatal
MsgStream & fatal() const
shortcut for the method msgStream(MSG::FATAL)
Definition: CommonMessaging.h:112
Service::declareProperty
Property * declareProperty(const std::string &name, T &property, const std::string &doc="none") const
Declare the named property.
Definition: Service.h:215
Gaudi::ReturnCode::Success
constexpr int Success
Definition: AppReturnCode.h:16
HiveSlimEventLoopMgr::m_algResourcePool
SmartIF< IAlgResourcePool > m_algResourcePool
Reference to the Algorithm resource pool.
Definition: HiveSlimEventLoopMgr.h:44
IEvtSelector::createAddress
virtual StatusCode createAddress(const Context &c, IOpaqueAddress *&iop) const =0
Create an IOpaqueAddress object from the event fetched.
ana.i
list i
Definition: ana.py:128
IConverter::fillRepRefs
virtual StatusCode fillRepRefs(IOpaqueAddress *pAddress, DataObject *pObject)=0
Resolve the references of the converted object.
IScheduler::freeSlots
virtual unsigned int freeSlots()=0
Get the free event processing slots.
IScheduler::popFinishedEvent
virtual StatusCode popFinishedEvent(EventContext *&eventContext)=0
Retrieve a finished event from the scheduler.
HiveSlimEventLoopMgr::m_endEventFired
bool m_endEventFired
Flag to avoid to fire the EnvEvent incident twice in a row (and also not before the first event) ...
Definition: HiveSlimEventLoopMgr.h:51
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
HiveSlimEventLoopMgr::m_blackListBS
boost::dynamic_bitset * m_blackListBS
Definition: HiveSlimEventLoopMgr.h:79
DataObject.h
HiveSlimEventLoopMgr::m_evtContext
IEvtSelector::Context * m_evtContext
Event Iterator.
Definition: HiveSlimEventLoopMgr.h:34