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