BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
EFEventLoopMgr.cxx
Go to the documentation of this file.
1//===================================================================
2//
3// EFEventLoopMgr.cpp
4//--------------------------------------------------------------------
5//
6// Package : EFEventLoopMgr
7//
8// Description: implementation of the Application's batch mode handler
9//
10// Author : TangRui tangr@mail.ihep.ac.cn
11//
12//====================================================================
13#define GAUDISVC_EFEVENTLOOPMGR_CPP
14#include <stdlib.h>
15
16#include "GaudiKernel/DataObject.h"
17#include "GaudiKernel/DataSelectionAgent.h"
18#include "GaudiKernel/IAlgManager.h"
19#include "GaudiKernel/IAlgorithm.h"
20#include "GaudiKernel/IConversionSvc.h"
21#include "GaudiKernel/IDataManagerSvc.h"
22#include "GaudiKernel/IDataProviderSvc.h"
23#include "GaudiKernel/IEvtSelector.h"
24#include "GaudiKernel/IIncidentSvc.h"
25#include "GaudiKernel/Incident.h"
26#include "GaudiKernel/MsgStream.h"
27#include "GaudiKernel/SmartDataPtr.h"
28#include "GaudiKernel/SmartIF.h"
29#include "GaudiKernel/ThreadGaudi.h"
30
36// #include "HltDataTypes/EFBesTimer.h"
37
38#include "EventModel/Event.h"
39#include "EventModel/EventHeader.h"
40#include "EventModel/EventModel.h"
41
43
44#include "eformat/eformat.h"
45// #include "eformat/write/eformat.h"
46
47#include "RawDataCnv/EventManagement/RAWEVENT.h"
48#include "RawDataCnv/RawDataAddress.h"
49
50extern const CLID& CLID_Event;
51//=========================================================================
52// Standard Constructor
53//=========================================================================
54EFEventLoopMgr::EFEventLoopMgr( const std::string& nam, ISvcLocator* svcLoc )
55 : MinimalEventLoopMgr( nam, svcLoc ) {
56 declareProperty( "EvtSel", m_evtsel );
57 declareProperty( "HistogramPersistency", m_histPersName = "" );
58 declareProperty( "DisableEFResult", m_disableEFResult = true );
59 declareProperty( "OkexecuteEvent", m_okexecuteEvent = true );
60 declareProperty( "OutputLevel", m_outputLevel = MSG::ALWAYS );
61 declareProperty( "TimeTest", m_timeTest = 0 );
64 m_total_nevt = 0;
65 m_currentRun = 0;
67 m_evtDataSvc = 0;
68 m_evtSelector = 0;
69 m_evtContext = 0;
70 m_firstRun = true;
71 m_incidentSvc = 0;
72 m_trgType = 0;
73 m_firstEvent = true;
74}
75
76//=========================================================================
77// Standard Destructor
78//=========================================================================
80 if ( m_histoDataMgrSvc ) m_histoDataMgrSvc->release();
81 if ( m_histoPersSvc ) m_histoPersSvc->release();
82 if ( m_incidentSvc ) m_incidentSvc->release();
83 if ( m_evtDataMgrSvc ) m_evtDataMgrSvc->release();
84 if ( m_evtDataSvc ) m_evtDataSvc->release();
85 if ( m_evtSelector ) m_evtSelector->release();
86 if ( m_evtContext ) delete m_evtContext;
87}
88
89//=========================================================================
90// implementation of IAppMgrUI::initalize
91//=========================================================================
93 MsgStream log( msgSvc(), name() );
94 // initialize the base class
95 cout << "EFEventLoopMgr::initialize() there are " << m_topAlgList.size() << " topAlg now"
96 << endl;
97 StatusCode sc = MinimalEventLoopMgr::initialize();
98 // leave this after initialization of base class, otherwise msgSvc is not correctly set up
99 // -----
100 log << MSG::INFO << "EFEventLoopMgr:initalize(): ---> EventLoopMgr = " << name()
101 << " initializing " << endmsg;
102 if ( !sc.isSuccess() )
103 {
104 log << MSG::ERROR
105 << "EFEventLoopMgr:initalize():Failed to initialize base class MinimalEventLoopMgr"
106 << endmsg;
107 return sc;
108 }
109 // Setup access to event data services
110 sc = serviceLocator()->service( "EventDataSvc", m_evtDataMgrSvc, true );
111 if ( !sc.isSuccess() )
112 {
113 log << MSG::FATAL << "Error retrieving EventDataSvc interface IDataManagerSvc." << endmsg;
114 return sc;
115 }
116 sc = serviceLocator()->service( "EventDataSvc", m_evtDataSvc, true );
117 if ( !sc.isSuccess() )
118 {
119 log << MSG::FATAL << "Error retrieving EventDataSvc interface IDataProviderSvc." << endmsg;
120 return sc;
121 }
122 //-------------------------------------------------------------------------------
123 // Get the references to the services that are needed by the ApplicationMgr itself
124 //--------------------------------------------------------------------------------
125 sc = serviceLocator()->service( "IncidentSvc", m_incidentSvc, true );
126
127 if ( !sc.isSuccess() )
128 {
129 log << MSG::FATAL << "EFEventLoopMgr:initalize():Error retrieving IncidentSvc" << endmsg;
130 return sc;
131 }
132
133 //-------------------------------------------------------------------------------
134 // Get the references to the services that are needed by the ApplicationMgr itself
135 //--------------------------------------------------------------------------------
136 sc = serviceLocator()->service( "HltStoreSvc", m_HltStoreSvc, true );
137 if ( !sc.isSuccess() )
138 {
139 log << MSG::FATAL << "EFEventLoopMgr:initalize():Error retrieving HltStoreSvc" << endmsg;
140 return sc;
141 }
142
143 //--------------------------------------------------------------------------
144 // Access Property Manager interface:
145 //--------------------------------------------------------------------------
146 SmartIF<IProperty> prpMgr( serviceLocator() );
147 if ( !prpMgr.isValid() )
148 {
149 log << MSG::FATAL
150 << "EFEventLoopMgr:initalize():IProperty interface not found in ApplicationMgr."
151 << endmsg;
152 return StatusCode::FAILURE;
153 }
154
155 //-------------------------------------------------------------------------
156 // Setup Event Setector
157 //-------------------------------------------------------------------------
158 // We do not expect a Event Selector necessarily being declared
159 setProperty( prpMgr->getProperty( "EvtSel" ) );
160
161 if ( m_evtsel != "NONE" || m_evtsel.length() == 0 )
162 {
163
164 sc = serviceLocator()->service( "EventSelector", m_evtSelector, true );
165 if ( sc.isSuccess() )
166 { // Setup Event Selector
167 sc = m_evtSelector->createContext( m_evtContext );
168 if ( !sc.isSuccess() )
169 {
170 log << MSG::FATAL << "Can not create the event selector Context." << endmsg;
171 return sc;
172 }
173 }
174 else
175 {
176 log << MSG::FATAL << "EFEventLoopMgr:initalize():EventSelector not found." << endmsg;
177 return StatusCode::FAILURE;
178 }
179 }
180 else
181 {
182 m_evtSelector = 0;
183 m_evtContext = 0;
184 log << MSG::WARNING
185 << "EFEventLoopMgr:initalize():No service \"EventSelector\" provided : assume "
186 "\"online\" running "
187 << endmsg;
188 }
189 //--------------------------------------------------------------------
190 // Get the RawDataInputSvc
191 //--------------------------------------------------------------------
192 IService* svc;
193 sc = serviceLocator()->getService( "RawDataInputSvc", svc );
194 if ( sc != StatusCode::SUCCESS )
195 {
196 log << MSG::WARNING << " Cant get RawDataInputSvc " << endmsg;
197 return sc;
198 }
199
200 m_inputSvc = dynamic_cast<IRawDataInputSvc*>( svc );
201 if ( m_inputSvc == 0 )
202 {
203 log << MSG::WARNING << " Cant cast to RawDataInputSvc " << endmsg;
204 return StatusCode::FAILURE;
205 }
206
207 sc = m_HltStoreSvc->get( "EventType", m_evtType );
208 if ( sc.isFailure() )
209 {
210 log << MSG::ERROR << "Could not find EventType" << endmsg;
211 return StatusCode::FAILURE;
212 }
213 sc = m_HltStoreSvc->get( "EFResult", m_efResult );
214 if ( sc.isFailure() )
215 {
216 log << MSG::ERROR << "Could not find EFResult" << endmsg;
217 return StatusCode::FAILURE;
218 }
219 // cout <<"000000000000000000000000000000 "<<m_timeTest<<endl;
220 if ( m_timeTest )
221 {
222 // cout <<"111111111111111111111111111111111111"<<endl;
223 // IBesTimerSvc* timerSvc;
224 // sc = service( "BesTimerSvc", timerSvc);
225 // if( sc.isFailure() ) {
226 // log << MSG::WARNING << ": Unable to locate BesTimer Service" << endmsg;
227 // }
228 // else{
229 // cout <<"222222222222222222222222222222222222222"<<endl;
230 // pBesTimer=timerSvc->addItem("EventFilterHandler");
231 // if(pBesTimer)pBesTimer->propName("nEventFilterHandler");
232 //}
233 }
234 return StatusCode::SUCCESS;
235}
236
237//=========================================================================
238// implementation of IAppMgrUI::finalize
239//=========================================================================
241 MsgStream log( msgSvc(), name() );
242 log << MSG::INFO
243 << " EFEventLoopMgr:finalize():Number of events processed : " << m_total_nevt << endmsg;
244
246 {
247 m_evtSelector->releaseContext( m_evtContext );
248 m_evtContext = 0;
249 }
250
251 m_histoPersSvc = releaseInterface( m_histoPersSvc );
252
253 m_evtSelector = releaseInterface( m_evtSelector );
254 m_incidentSvc = releaseInterface( m_incidentSvc );
255 m_evtDataSvc = releaseInterface( m_evtDataSvc );
256 m_evtDataMgrSvc = releaseInterface( m_evtDataMgrSvc );
257 StatusCode sc = MinimalEventLoopMgr::finalize();
258
259 return sc;
260}
261
262//=========================================================================
263// executeEvent(void* par) ---> for "online" running
264//=========================================================================
265// the parameter par is an EventFormat::RawMemory::FullEventFragment
266// and it will be feed into Psc::process method
267StatusCode EFEventLoopMgr::executeEvent( void* par ) {
268
269 StatusCode sc;
270 DataObject* pObject = 0;
271 MsgStream log( msgSvc(), name() );
272 // return StatusCode::SUCCESS;
273 // log << MSG::DEBUG << "EFEventLoopMgr:executeEvent(void* par):Declaring Fragment" <<
274 // endmsg; if(pBesTimer&&m_timeTest==1){
275 // pBesTimer->start();
276 // pStart=true;
277 // cout<<"time test: start!!!!!!!!!!!!!!!!!!!"<<endl;
278 //}
279 if ( m_firstEvent )
280 {
281 m_re = new RAWEVENT;
282 m_firstEvent = false;
283 }
284 else { m_re->reset(); }
285
286 eformat::FullEventFragment<uint32_t*> pre( (uint32_t*)par );
287 try
288 { pre.check_tree(); } catch ( eformat::Issue& ex )
289 {
290 std::cerr << std::endl << "Uncaught eformat issue: " << ex.what() << std::endl;
291 return StatusCode::FAILURE;
292 } catch ( ers::Issue& ex )
293 {
294 std::cerr << std::endl << "Uncaught ERS issue: " << ex.what() << std::endl;
295 return StatusCode::FAILURE;
296 } catch ( std::exception& ex )
297 {
298 std::cerr << std::endl << "Uncaught std exception: " << ex.what() << std::endl;
299 return StatusCode::FAILURE;
300 } catch ( ... )
301 {
302 std::cerr << std::endl << "Uncaught unknown exception" << std::endl;
303 return StatusCode::FAILURE;
304 }
305
306 log << MSG::DEBUG << "[Event No. #" << pre.global_id() << "] " << pre.fragment_size_word()
307 << " words in " << pre.nchildren() << " subdetectors " << endmsg;
308
309 m_re->setRunNo( pre.run_no() );
310 m_re->setEventNo( pre.global_id() );
311 m_re->setTime( pre.time() );
312
313 uint32_t* robs[100];
314 int nrobs = eformat::get_robs( (uint32_t*)par, (const uint32_t**)robs, 100 );
315 if ( nrobs > 100 ) log << MSG::ERROR << "ROBFragments' number exceeds than 100!" << endmsg;
316
317 for ( int robi = 0; robi < nrobs; robi++ )
318 {
319 eformat::ROBFragment<uint32_t*> rob( robs[robi] );
320 uint32_t status = rob.rod_detev_type();
321 uint32_t sourceid = rob.rod_source_id();
322 if ( ( status & 0x2 ) && ( sourceid != 0xa50000 ) )
323 {
324 std::string answer = "Error";
325 m_efResult->reset();
326 m_evtType->reset();
327 m_evtType->setAnswer( answer );
328 log << MSG::DEBUG << "detector status is " << status << endmsg;
329 // delete m_re;
330 return StatusCode::SUCCESS;
331 }
332 }
333
334 bool trg = false;
335 for ( int robi = 0; robi < nrobs; robi++ )
336 {
337 eformat::ROBFragment<uint32_t*> rob( robs[robi] );
338 uint32_t* dataptr = NULL;
339 rob.rod_data( dataptr );
340 vector<uint32_t> DetElements( dataptr, ( dataptr + rob.rod_ndata() ) );
341
342 uint32_t source_id_number = rob.rod_source_id();
343 // std::cout<<"#####source_id_number#####"<<source_id_number<<std::endl;
344 source_id_number <<= 8;
345 source_id_number >>= 24;
346 // std::cout<<"#####(source_id_number<<24)>>29#####"<<source_id_number<<std::endl;
347 // be careful here!!!
348 log << MSG::DEBUG << source_id_number << " Digi size=" << DetElements.size() << endmsg;
349 switch ( source_id_number )
350 {
351 case 161:
352 m_re->addReMdcDigi( dataptr, DetElements.size() );
353 // if(DetElements.size()>0)std::cout<<hex<<DetElements[0]<<std::endl;
354 break;
355 case 163: m_re->addReEmcDigi( dataptr, DetElements.size() ); break;
356 case 162:
357 // std::cout<<"EFEventLoopMgr::TOFDigi size="<<DetElements.size()<<std::endl;
358 m_re->addReTofDigi( dataptr, DetElements.size() );
359 break;
360 case 164:
361 // std::cout<<"EFEventLoopMgr::MUCDigi size="<<DetElements.size()<<std::endl;
362 m_re->addReMucDigi( dataptr, DetElements.size() );
363 break;
364 case 165: trg = getTrigChn( dataptr, rob.rod_ndata() ); break;
365 default:
366 // std::cerr << "no such subdetector type!" << std::endl;
367 break;
368 }
369 if ( trg )
370 {
371 std::string answer = "RandomTrg";
372 m_efResult->reset();
373 m_evtType->reset();
374 m_evtType->setAnswer( answer );
375 log << MSG::DEBUG << "a random trigger event is taken" << endmsg;
376 m_re->reset();
377 return StatusCode::SUCCESS;
378 }
379 }
380 // if(pBesTimer&&m_timeTest==2){
381 // pBesTimer->start();
382 // pStart=true;
383 // cout<<"time test: start!!!!!!!!!!!!!!!!!!!"<<endl;
384 //}
385 if ( !( m_inputSvc->setCurrentEvent( m_re ) ) )
386 {
387 log << MSG::FATAL << "m_inputSvc->setCurrentEvent(m_re) Failed!" << endmsg;
388 exit( 1 );
389 }
390
391 if ( 0 != m_total_nevt )
392 {
393 sc = m_evtDataMgrSvc->clearStore();
394 if ( !sc.isSuccess() )
395 { log << MSG::DEBUG << "Clear of Event data store failed" << endmsg; }
396 }
397 /*
398 if( m_evtContext ) {
399 IOpaqueAddress* addr = 0;
400 sc = getEventRoot(addr);
401 if( !sc.isSuccess() ) {
402 log << MSG::INFO << "No more events in event selection " << endmsg;
403 return StatusCode::FAILURE;
404 }
405 sc = m_evtDataMgrSvc->setRoot ("/Event", addr);
406 if( !sc.isSuccess() ) {
407 log << MSG::WARNING << "Error declaring event root address." << endmsg;
408 return StatusCode::FAILURE;
409 }
410 SmartDataPtr<Event::EventHeader> evt(m_evtDataSvc,"/Event/EventHeader");
411 if(!evt) {
412 sc = m_evtDataMgrSvc->registerAddress ("/Event/EventHeader", addr);
413 if( !sc.isSuccess() ) {
414 log << MSG::WARNING << "Error register EventHeader address." << endmsg;
415 }
416 }
417 sc = m_evtDataSvc->retrieveObject("/Event", pObject);
418 if( !sc.isSuccess() ) {
419 log << MSG::WARNING << "Unable to retrieve Event root object" << endmsg;
420 return StatusCode::FAILURE;
421 }
422 }
423 else {
424 sc = m_evtDataMgrSvc->setRoot ("/Event", new DataObject());
425 if( !sc.isSuccess() ) {
426 log << MSG::WARNING << "Error declaring event root DataObject" << endmsg;
427 }
428 }
429 */
430
431 // Create event address in the event store
432 // IOpaqueAddress* addr = new RawDataAddress(CLID_Event, "EventHeader", "EventHeader");
433 IOpaqueAddress* addr = 0;
434 sc = m_evtSelector->createAddress( *m_evtContext, addr );
435 if ( !sc.isSuccess() )
436 {
437 log << MSG::WARNING << "Error creating IOpaqueAddress." << endmsg;
438 return sc;
439 }
440 // Set root clears the event data store first
441 sc = m_evtDataMgrSvc->setRoot( "/Event", addr );
442 if ( !sc.isSuccess() )
443 {
444 log << MSG::WARNING << "Error declaring event root address." << endmsg;
445 return sc;
446 }
447 sc = m_evtDataSvc->retrieveObject( "/Event", pObject );
448 if ( !sc.isSuccess() )
449 {
450 log << MSG::WARNING << "Unable to retrieve Event root object" << endmsg;
451 return sc;
452 }
453
454 m_total_nevt++;
455 // Fire BeginEvent "Incident"
456 m_incidentSvc->fireIncident( Incident( name(), "BeginEvent" ) );
457 // Execute Algorithms
458 sc = MinimalEventLoopMgr::executeEvent( NULL );
459 // Fire EndEvent "Incident"
460 m_incidentSvc->fireIncident( Incident( name(), "EndEvent" ) );
461
462 // if(pBesTimer){
463 // pBesTimer->stop();
464 // double time=pBesTimer->elapsed();
465 // std::cout<<"Run time="<<time<<std::endl;
466 // }
467 // delete addr;
468 // delete m_re;
469 return sc;
470}
471
472/// Create event address using event selector
473StatusCode EFEventLoopMgr::getEventRoot( IOpaqueAddress*& refpAddr ) {
474 refpAddr = 0;
475 StatusCode sc = m_evtSelector->next( *m_evtContext );
476 if ( !sc.isSuccess() ) { return sc; }
477 // Create root address and assign address to data service
478 sc = m_evtSelector->createAddress( *m_evtContext, refpAddr );
479 if ( !sc.isSuccess() )
480 {
481 sc = m_evtSelector->next( *m_evtContext );
482 if ( sc.isSuccess() )
483 {
484 sc = m_evtSelector->createAddress( *m_evtContext, refpAddr );
485 if ( !sc.isSuccess() )
486 {
487 MsgStream log( msgSvc(), name() );
488 log << MSG::WARNING << "Error creating IOpaqueAddress." << endmsg;
489 }
490 }
491 }
492 return sc;
493}
494
495//----------------------------------------------------------------------------------
496// implementation of IInterface: queryInterface
497//----------------------------------------------------------------------------------
498StatusCode EFEventLoopMgr::queryInterface( const InterfaceID& riid, void** ppvInterface ) {
499 if ( IEFEventLoopMgr::interfaceID().versionMatch( riid ) )
500 { *ppvInterface = (IEFEventLoopMgr*)this; }
501 else { return MinimalEventLoopMgr::queryInterface( riid, ppvInterface ); }
502 addRef();
503 return StatusCode::SUCCESS;
504}
505
506//=========================================================================
507// EF: prepare for run step ---> for "online" running
508//=========================================================================
509StatusCode EFEventLoopMgr::prepareForRun( int ef_run_number ) {
510 MsgStream log( msgSvc(), name() );
511 StatusCode sc;
512 int run_num = ef_run_number;
513 log << MSG::DEBUG << " ---> EFprepareForRun::Received run number from PT = " << run_num
514 << endmsg;
515
516 log << MSG::DEBUG << " ---> EFprepareForRun::Setup IOVSvc for run number = " << run_num
517 << endmsg;
518 const EventInfo* pEvent = new EventInfo( new EventID( run_num, 0 ), new EventType() );
519
520 if ( m_currentRun != run_num )
521 {
522 m_incidentSvc->fireIncident( Incident( name(), "NewRun" ) );
523 m_currentRun = run_num;
524 }
525 m_incidentSvc->fireIncident( Incident( name(), "BeginRun" ) );
526 ListAlg::iterator ita;
527 bool failed = false;
528 for ( ita = m_topAlgList.begin(); ita != m_topAlgList.end(); ita++ )
529 {
530 sc = ( *ita )->sysBeginRun();
531 if ( !sc.isSuccess() )
532 {
533 log << MSG::WARNING << "beginRun() of algorithm " << ( *ita )->name() << " failed"
534 << endmsg;
535 failed = true;
536 }
537 }
538 // hxt sc = m_StoreGateSvc->record(pEvent,"");
539 if ( failed ) return StatusCode::FAILURE;
540 else return StatusCode::SUCCESS;
541}
542
543//=========================================================================
544// EFResult() ---> for "online" running
545//=========================================================================
546// 3 possible EFDecisions exist: "Accepted", "Rejected", "Error"
548 MsgStream log( msgSvc(), name() );
549 if ( m_disableEFResult )
550 {
551 std::string defaultEFDecision = "Other";
552 log << MSG::WARNING
553 << "EFEventLoopMgr:EF_Decision():---> EFResult handling is disabled. Default "
554 "EFDecision = "
555 << defaultEFDecision << endmsg;
556 if ( m_okexecuteEvent != 1 )
557 {
558 std::string defaultEFDecision = "Error";
559 log << MSG::WARNING
560 << "EFEventLoopMgr:EF_Decision():---> Error in executeEvent, setting EFDecision to: "
561 << defaultEFDecision << endmsg;
562 return defaultEFDecision;
563 }
564 return defaultEFDecision;
565 }
566 else
567 {
568 // log << MSG::DEBUG << "Try to get the EFDecision" << endmsg;
569
570 // StatusCode sc = m_HltStoreSvc->get("EFResult", m_efResult);
571 // enrich the result returned to online
572 // by Fu Chengdong
573 if ( m_evtType->getAnswerIndex() == -1 )
574 {
575 log << MSG::DEBUG << "EF_Decision(): Unvalid EFResult(AnswerIndex=-1)" << endmsg;
576 return "Error";
577 }
578 std::string answer = m_evtType->getAnswer();
579 log << MSG::INFO << "The answer is " << answer << endmsg;
580 return answer;
581 }
582}
583
585 MsgStream log( msgSvc(), name() );
586 uint32_t x = 1;
587 uint32_t y = 0;
588 uint32_t z = 0;
589 uint32_t version = ( x << 16 ) + ( y << 8 ) + z;
590 log << MSG::INFO << "The version is " << version << endmsg;
591 return version;
592}
594 MsgStream log( msgSvc(), name() );
595 uint32_t alg = m_efResult->getEFVec( 0 );
596 // log << MSG::INFO << "The algorithm tag is " << alg<<endmsg;
597 int itype = m_evtType->getMidAnswerIndex();
598 // cout <<itype<<endl;
599 if ( itype != -1 ) alg += ( 1 << itype );
600 uint32_t alg16 = alg >> 16;
601 log << MSG::DEBUG << "The algorithm tag is " << alg << ":" << ( alg & 1 )
602 << ( ( alg >> 1 ) & 1 ) << ( ( alg >> 2 ) & 1 ) << ( ( alg >> 3 ) & 1 )
603 << ( ( alg >> 4 ) & 1 ) << ( ( alg >> 5 ) & 1 ) << ( ( alg >> 6 ) & 1 )
604 << ( ( alg >> 7 ) & 1 ) << ":%# " << alg16 << endmsg;
605 return alg;
606}
607
609 MsgStream log( msgSvc(), name() );
610 uint32_t etot = m_efResult->getEFVec( 31 );
611 log << MSG::INFO << "The total energy is " << *( (float*)&etot ) << "GeV" << endmsg;
612 return etot;
613}
614// This method should return a pointer to the local memory containing the EF
615// SubDetectorFragment
617 // std::cout << "jak:"<<__FILE__<<std::endl;
618 MsgStream log( msgSvc(), name() );
619
620 if ( m_disableEFResult )
621 {
622 log << MSG::WARNING
623 << "EFEventLoopMgr:EF_Fragment_Address():---> EFResult handling is disabled!!!! No "
624 "pointer to EF Fragment will be given."
625 << endmsg;
626 return NULL;
627 }
628 else
629 {
630
631 // log << MSG::DEBUG << "EFEventLoopMgr:EF_Fragment_Address():---> Going to retrieve
632 // EFResult, for the Fragment Address"<<endmsg;
633 uint32_t alg = m_efResult->getEFVec( 0 );
634 log << MSG::DEBUG << "alg=" << alg << endmsg;
635 uint32_t num = m_efResult->getEFVec( 1 );
636 int nmdc = num & 0xFF;
637 int ntof = ( num >> 8 ) & 0xFF;
638 int nemc = ( num >> 16 ) & 0xFF;
639 int nmuc = ( num >> 24 ) & 0xFF;
640 int ndata = 1;
641 uint32_t ndatap = nmdc + ntof + nemc + nmuc;
642 ndata += ndatap;
643 int ndec = m_efResult->getDecNum();
644 if ( ndec > 0 ) ndata += ( ndec + 1 );
645 if ( ( alg & 4 ) && ( !( alg & 2 ) ) )
646 log << MSG::WARNING << "sub-algorithms error!" << endmsg;
647 if ( ( ONLINE_DATA_HEAD + ONLINE_DATA_TAIL ) != 40 )
648 {
649 log << MSG::FATAL << "data length error!" << endmsg;
650 return NULL;
651 }
652 log << MSG::INFO << "sent data lenth=" << ndata + 40 << endmsg; // byjak
653 // uint32_t* efAddress=malloc((ndata+ONLINE_DATA_HEAD+ONLINE_DATA_TAIL)*sizeof(uint32_t));
654 uint32_t* efAddress = new uint32_t[ndata + ONLINE_DATA_HEAD + ONLINE_DATA_TAIL];
655 // std::cout << "fucd-->Address" << efAddress << "; ndata="<<ndata<<std::endl;
656 if ( efAddress == NULL ) return NULL;
657 efAddress[0] = 0xbb1234bb;
658 efAddress[1] = ndata + ONLINE_DATA_HEAD + ONLINE_DATA_TAIL;
659 efAddress[2] = 8;
660 efAddress[3] = 0x3000000;
661 efAddress[4] = 0x7c0000;
662 efAddress[5] = 1;
663 efAddress[6] = 0;
664 efAddress[7] = 0;
665 efAddress[8] = 0xcc1234cc;
666 efAddress[9] = efAddress[1] - efAddress[2];
667 efAddress[10] = 0xb;
668 efAddress[11] = 0x3000000;
669 efAddress[12] = 0x7c0000;
670 efAddress[13] = 1;
671 efAddress[14] = 0;
672 efAddress[15] = 3;
673 efAddress[16] = 0;
674 efAddress[17] = 0;
675 efAddress[18] = 0;
676 efAddress[19] = 0xdd1234dd;
677 efAddress[20] = efAddress[9] - efAddress[10];
678 efAddress[21] = 8;
679 efAddress[22] = 0x3000000;
680 efAddress[23] = 0x7c0000;
681 efAddress[24] = 1;
682 efAddress[25] = 0;
683 efAddress[26] = 0;
684 efAddress[27] = 0xee1234ee;
685 efAddress[28] = 9;
686 efAddress[29] = 0x3000000;
687 efAddress[30] = 0x7c0000;
688 efAddress[31] = 0;
689 efAddress[32] = 0;
690 efAddress[33] = 0;
691 efAddress[34] = 0;
692 efAddress[35] = 0;
693 // efAddress[36]=0;
694 efAddress[36 + ndata] = 0;
695 efAddress[37 + ndata] = 1;
696 efAddress[38 + ndata] = ndata;
697 efAddress[39 + ndata] = 1;
698 efAddress[ONLINE_DATA_HEAD] = m_efResult->getEFVec( 1 );
699 if ( ndata == 1 ) { return efAddress; }
700 else
701 {
702 unsigned int i = 1;
703 for ( int j = 5; j < 5 + nmdc; j++ )
704 {
705 efAddress[ONLINE_DATA_HEAD + i] = m_efResult->getEFVec( j );
706 ++i;
707 }
708 for ( int j = 25; j < 25 + ntof; j++ )
709 {
710 efAddress[ONLINE_DATA_HEAD + i] = m_efResult->getEFVec( j );
711 ++i;
712 }
713 for ( int j = 30; j < 30 + nemc; j++ )
714 {
715 efAddress[ONLINE_DATA_HEAD + i] = m_efResult->getEFVec( j );
716 ++i;
717 }
718 for ( int j = 52; j < 52 + nmuc; j++ )
719 {
720 efAddress[ONLINE_DATA_HEAD + i] = m_efResult->getEFVec( j );
721 ++i;
722 }
723 if ( ndec > 0 )
724 {
725 efAddress[ONLINE_DATA_HEAD + i] = ndec;
726 ++i;
727 for ( int j = 54; j < 54 + ndec; ++j )
728 {
729 efAddress[ONLINE_DATA_HEAD + i] = m_efResult->getEFVec( j );
730 ++i;
731 }
732 }
733 log << MSG::DEBUG << "0th eff data is "
734 << ( ( efAddress[ONLINE_DATA_HEAD] >> 24 ) & 0xFF )
735 << ( ( efAddress[ONLINE_DATA_HEAD] >> 16 ) & 0xFF )
736 << ( ( efAddress[ONLINE_DATA_HEAD] >> 8 ) & 0xFF )
737 << ( ( efAddress[ONLINE_DATA_HEAD] >> 0 ) & 0xFF ) << endmsg;
738 for ( int i = 1; i < ndatap + 1; i++ )
739 {
740 log << MSG::DEBUG << i << "th eff data is "
741 << *( (float*)&( efAddress[ONLINE_DATA_HEAD + i] ) ) << endmsg;
742 }
743 for ( int i = ndatap + 1; i < ndata; i++ )
744 {
745 log << MSG::DEBUG << i << "th eff data is " << efAddress[ONLINE_DATA_HEAD + i]
746 << endmsg;
747 }
748 return efAddress;
749 }
750
751 return NULL;
752
753 // FullEventAssembler<EFSrcIdMap> fea ;
754
755 /** EF ROD */
756 // FullEventAssembler<EFSrcIdMap>::RODDATA* EFROD ;
757 // EventFormat::SourceID helpEFID(EventFormat::TDAQ_EVENT_FILTER,EventFormat::ROD_TYPE,0);
758 // uint32_t rodIdEF = helpEFID.source_id();
759
760 /* Create the ROD data container to be filled later */
761 // EFROD = fea.getRodData( rodIdEF );
762
763 // std::vector<uint32_t> efVec(m_efResult->getEFVec());
764
765 // for (std::vector<uint32_t>::iterator i=efVec.begin();
766 // i!=efVec.end();++i)
767 //{
768 // EFROD->push_back(*i);
769 // }
770
771 /** Create an emply RawEvent and fill the RODs into the RawEvent (FullEventFragment) re */
772
773 // Get ByteStreamCnvSvc
774
775 // StatusCode sc;
776
777 // Get ByteStreamCnvSvc
778 // hxt if(StatusCode::SUCCESS != service("ByteStreamCnvSvc",m_ByteStreamEventAccess)){
779 // hxt log << MSG::ERROR << " EFEventLoopMgr:EF_Fragment_Address():Can't get
780 // ByteStreamEventAccess interface " << endmsg; hxt return NULL; hxt }
781
782 // Obtain the RawEvent
783 /*
784 log <<MSG::INFO<< "EFEventLoopMgr:EF_Fragment_Address(): Abans del get RawEvent" << endmsg;
785
786 RawEvent* re = m_ByteStreamEventAccess->getRawEvent();
787
788 log << MSG::INFO <<"EFEventLoopMgr:EF_Fragment_Address(): Despres del get RawEvent" <<
789 endmsg;
790 */
791
792 // fea.fill(re,log);
793
794 // To serialize RawEvent and obtain a pointer to the memory address
795 // where the EF SubdetectorFragment is
796
797 // Now get SubdetectorFragment from Raw Event
798 /*
799 const VDETF& vdetf=re->compounds();
800
801 log << MSG::DEBUG<< " EFEventLoopMgr:EF_Fragment_Address(): Full Event:" << hex << "Full
802 source ID: " << re->header().source_id() <<endmsg; log << MSG::DEBUG<< "
803 EFEventLoopMgr:EF_Fragment_Address(): Fragment size in words:" <<
804 re->header().fragment_size_word()<<endmsg; log << MSG::DEBUG<< "
805 EFEventLoopMgr:EF_Fragment_Address(): # of subdetectors:" <<vdetf.size()<<endmsg;
806
807
808 VDETF::const_iterator it_detf = vdetf.begin();
809 VDETF::const_iterator it_detf_end = vdetf.end();
810
811
812 //Loop over all Subdetectors
813
814 for(; it_detf!=it_detf_end; ++it_detf){
815
816
817
818 if(!((*it_detf)->is_valid())){
819
820 log<< MSG::ERROR << "EFEventLoopMgr:EF_Fragment_Address():Got invalid subdetector
821 fragment!. A null pointer will be returned" << endmsg; return NULL;
822 }
823
824 // Get the size of the SubDet fragment in WORDS
825 int fragSize = (*it_detf)->size_word();
826
827 //Now like in ptdummy::Steering
828
829
830 // Create a NEW memory storage (it mallocs a new region in "local" memory)
831 EventFormat::RawMemoryStorage store(fragSize*4);
832
833 // Serialize the subDetector fragment on the store (on the "local" buffer)
834 (*it_detf)->serialise(store);
835
836 log << MSG::DEBUG<< " EFEventLoopMgr:EF_Fragment_Address():SubDetectorFragment serialized
837 on 'local memory.'" <<endmsg;
838
839
840
841 // Return to pt::Worker the address (p) of the "local" memory region
842 // containing the serialized EF fragment
843
844 m_serializedEFAddress=(char*)store.address();
845
846 // Release the ownership of the 'local' memory region containing the
847 // serialized Fragment (i.e.: exiting from process() the storage distructor
848 // will not delete this memory region)
849 // The memory region MUST be deleted by pt::worker !!!
850
851 store.release_memory();
852 }
853 return m_serializedEFAddress;
854 */
855 }
856
857 return NULL;
858}
859
860bool EFEventLoopMgr::getTrigChn( uint32_t* data, uint32_t ndata ) {
861 MsgStream log( msgSvc(), name() );
862 log << MSG::DEBUG << ndata << ":" << ( *data ) << "," << endmsg;
863 uint32_t index = 0;
864
865 while ( ndata - index > 1 )
866 {
867 uint32_t header = *( data + index );
868 uint32_t blockSize = ( ( header >> 14 ) & 0x3FF );
869 uint32_t id = ( header >> 24 );
870 // std::cout << "TriggerChannel:" << hex<<header << "==>" << blockSize<<","<<id
871 // << ","<<((header >> 8) & 0x3F) << dec<<std::endl;
872 if ( blockSize == 0 || ( index + blockSize ) > ndata ) break;
873 if ( id == 0xD3 )
874 {
875 uint32_t window = ( ( header >> 8 ) & 0x3F ); // Time window, bit8 to bit13, total: 0--31
876 uint32_t size = blockSize - 1;
877 if ( window == 0 )
878 {
879 log << MSG::FATAL << "window=0" << endmsg;
880 // return false;
881 }
882 else if ( size % window != 0 )
883 {
884 log << MSG::FATAL << "GTL data is NOT completed" << endmsg;
885 // return false;
886 }
887 // vector<uint32_t> trigData(data+index+1, data+index+size);
888 for ( uint32_t j = 0; j < size; j++ )
889 {
890 uint32_t trgdata = *( data + index + 1 + j );
891 uint32_t dataId = ( ( trgdata >> 24 ) & 0x7 );
892 // std::cout <<hex<< trgdata << "==>"<< dataId <<"," <<
893 // (trgdata&0xFFFFFF)<<dec<<std::endl;
894 if ( dataId != 5 ) continue;
895 // std::cout <<hex<< trgdata <<dec<<std::endl;
896 m_trgType = m_trgType | ( trgdata & 0xFFFF );
897 if ( trgdata & ( 1 << 9 ) ) return true;
898 // if(trgdata&(1<<8)) return true;
899 // if(trgdata&(1<<10)) return true;
900 }
901 }
902 index += blockSize;
903 }
904 // cout<<m_trgType<<endl;
905
906 return false;
907}
TTree * data
Double_t etot
#define ONLINE_DATA_TAIL
#define ONLINE_DATA_HEAD
Defines the EFResult RDO structure.
const CLID & CLID_Event
IMessageSvc * msgSvc()
virtual bool getTrigChn(uint32_t *data, uint32_t ndata)
whether it is a RrandomTrg
std::string m_evtsel
Event selector.
virtual StatusCode executeEvent(void *par)
implementation of IEventProcessor::executeEvent(void* par)
IConversionSvc * m_histoPersSvc
Reference to the Histogram Persistency Service.
virtual ~EFEventLoopMgr()
Standard Destructor.
std::string m_histPersName
Name of the Hist Pers type.
virtual StatusCode initialize()
implementation of IAppMgrUI::initalize
virtual std::string EF_Decision()
return data from EF decision
virtual StatusCode finalize()
implementation of IAppMgrUI::finalize
StatusCode getEventRoot(IOpaqueAddress *&refpAddr)
Create event address using event selector.
EventID::number_type m_currentRun
current run number
virtual uint32_t EF_Version()
return version number
EFEventLoopMgr(const std::string &nam, ISvcLocator *svcLoc)
Standard Constructor.
virtual uint32_t EF_Total_Energy()
return total energy
IIncidentSvc * m_incidentSvc
Reference to the indicent service.
virtual uint32_t * EF_Fragment_Address()
Return a pointer to the local memory containing the EF subdetector fragment.
virtual StatusCode prepareForRun(int ef_run_number)
prepare for run step
IDataManagerSvc * m_evtDataMgrSvc
Reference to the Event Data Service's IDataManagerSvc interface.
virtual StatusCode queryInterface(const InterfaceID &riid, void **ppvInterface)
implementation of IInterface: queryInterface
IEvtSelector::Context * m_evtContext
Event Context.
IDataProviderSvc * m_evtDataSvc
Reference to the Event Data Service's IDataProviderSvc interface.
virtual uint32_t EF_Algorithm_Tag()
return algorithm tag
IDataManagerSvc * m_histoDataMgrSvc
Reference to the Histogram Data Service.
HltStoreSvc * m_HltStoreSvc
Reference to HltStoreSvc;.
IEvtSelector * m_evtSelector
Reference to the Event Selector.
This class provides general information about an event. It extends EventInfo with a list of sub-evts ...
Definition EventInfo.h:33
static const InterfaceID & interfaceID()
Retrieve interface ID.
Root Issue class.
const char * what() const
Human description message.
size_t get_robs(const uint32_t *fragment, const uint32_t **rob, size_t max_count)
Definition util.cxx:104