CGEM BOSS 6.6.5.i
BESIII Offline Software System
Loading...
Searching...
No Matches
MixerAlg Class Reference

#include <MixerAlg.h>

+ Inheritance diagram for MixerAlg:

Public Member Functions

 MixerAlg (const std::string &name, ISvcLocator *pSvcLocator)
 
StatusCode initialize ()
 
StatusCode execute ()
 
StatusCode finalize ()
 
 ~MixerAlg ()
 

Protected Member Functions

bool nextEvent (int nskip=0, int evtbyte=0, int eventsToEnd=0)
 
void mixDigi (SmartDataPtr< MdcDigiCol > &mdcMcDigits, SmartDataPtr< EmcDigiCol > &emcMcDigits, SmartDataPtr< MucDigiCol > &mucMcDigits, SmartDataPtr< TofDigiCol > &tofMcDigits)
 
void decodeMdc (MdcDigiCol *digiCol)
 
void decodeMuc (MucDigiCol *digiCol)
 
void decodeEmc (EmcDigiCol *digiCol)
 
void decodeTof (TofDigiCol *digiCol)
 
int getTiming ()
 
std::string eventType ()
 
std::string prepareDbQuery ()
 
bool file_sort (std::vector< std::string > &files, std::vector< int > &ranEvtNums)
 

Detailed Description

Definition at line 46 of file MixerAlg.h.

Constructor & Destructor Documentation

◆ MixerAlg()

MixerAlg::MixerAlg ( const std::string & name,
ISvcLocator * pSvcLocator )

Definition at line 37 of file MixerAlg.cxx.

37 : Algorithm(name, pSvcLocator){
38 declareProperty("MixMdcDigi", b_mdc=true);
39 declareProperty("MixEmcDigi", b_emc=true);
40 declareProperty("MixMucDigi", b_muc=true);
41 declareProperty("MixTofDigi", b_tof=true);
42
43 declareProperty("DBUserRequest", m_dbUserRequest=false);
44 declareProperty("RandomTrgRun", m_run);
45 declareProperty("RandomTrgRunRange", m_runs);
46 declareProperty("RandomTrgTimeRange", m_dates);
47
48 declareProperty("BackgroundDataFiles", m_bgfiles);
49 declareProperty("NumRanTrgEvents", m_ranTrgEvents);
50 declareProperty("NBgEventsToSignal", m_nevent=1);
51 // declareProperty("LoopBgData", b_loop=true);
52 declareProperty("ReplaceDataPath", m_pattern);
53 declareProperty("UseNewDataDir", m_newdatadir);
54 declareProperty("IfSkip", m_skip=true);
55 declareProperty("NSkip", m_NSkip=150);
56 declareProperty("OutPut", m_ifOutPut=false);
57 declareProperty("MixingMethod", m_mixingMethod=1);
58 declareProperty("MaxLoop", m_maxLoop=10);
59 declareProperty("SmearT0", m_ifSmearT0=true);
60 declareProperty("ReadBGMethod", m_readBGMethod=1);
61
62 declareProperty("ExWireFromRun", m_exRunFrom = 0 );
63 declareProperty("ExWireToRun", m_exRunTo = 999999);
64
65 declareProperty("UsingFilter", m_usingFilter = true);
66
67 m_raw_event = 0;
68 m_fr = 0;
69 m_runNo = 0;
70 m_skipCount = 0;
71 currentBGFile = "";
72 currentMCFile = "";
73 m_totalEvent = 0;
74 m_totEvtNumInCurFile = 0;
75 m_nEventsToEnd = 0;
76 m_ranStepLenInCurrentFile.clear();
77
78 m_mdcCnv = MdcConverter::instance();
79 m_mucCnv = MucConverter::instance();
80 m_tofCnv = TofConverter::instance();
81 m_emcCnv = EmcConverter::instance();
82}
static EmcConverter * instance(int runMode=2)
static MdcConverter * instance(int runMode=2)
static MucConverter * instance()
static TofConverter * instance()

◆ ~MixerAlg()

MixerAlg::~MixerAlg ( )
inline

Definition at line 52 of file MixerAlg.h.

52{}

Member Function Documentation

◆ decodeEmc()

void MixerAlg::decodeEmc ( EmcDigiCol * digiCol)
protected

Definition at line 1078 of file MixerAlg.cxx.

1079{
1080 const BufferHolder& emcBuf = m_raw_event->getEmcBuf();
1081 m_emcCnv->convert(emcBuf, digiCol);
1082}
StatusCode convert(const BufferHolder &src, EmcDigiCol *des)
const BufferHolder & getEmcBuf() const
Definition RAWEVENT.h:91

Referenced by mixDigi().

◆ decodeMdc()

void MixerAlg::decodeMdc ( MdcDigiCol * digiCol)
protected

Definition at line 1066 of file MixerAlg.cxx.

1067{
1068 const BufferHolder& mdcBuf = m_raw_event->getMdcBuf();
1069 m_mdcCnv->convert(mdcBuf, digiCol);
1070}
StatusCode convert(const BufferHolder &src, MdcDigiCol *des)
const BufferHolder & getMdcBuf() const
Definition RAWEVENT.h:89

Referenced by mixDigi().

◆ decodeMuc()

void MixerAlg::decodeMuc ( MucDigiCol * digiCol)
protected

Definition at line 1072 of file MixerAlg.cxx.

1073{
1074 const BufferHolder& mucBuf = m_raw_event->getMucBuf();
1075 m_mucCnv->convert(mucBuf, digiCol);
1076}
StatusCode convert(const BufferHolder &src, MucDigiCol *des)
const BufferHolder & getMucBuf() const
Definition RAWEVENT.h:92

Referenced by mixDigi().

◆ decodeTof()

void MixerAlg::decodeTof ( TofDigiCol * digiCol)
protected

Definition at line 1084 of file MixerAlg.cxx.

1085{
1086 const BufferHolder& tofBuf = m_raw_event->getTofBuf();
1087 m_tofCnv->convert(tofBuf, digiCol);
1088}
const BufferHolder & getTofBuf() const
Definition RAWEVENT.h:90
StatusCode convert(const BufferHolder &src, TofDigiCol *des, LumiDigiCol *des2=0)

Referenced by mixDigi().

◆ eventType()

std::string MixerAlg::eventType ( )
protected

Definition at line 1090 of file MixerAlg.cxx.

1091{
1092 const BufferHolder& hltBuf = m_raw_event->getHltBuf();
1093 DstHltInf* hlt = new DstHltInf();
1094 hlt->setEventType(hltBuf(0)[0]);
1095
1096 std::string evtType = hlt->getEventName();
1097
1098 if(hlt) delete hlt;
1099
1100 return evtType;
1101}
void setEventType(const unsigned int i)
Definition DstHltInf.h:30
const string & getEventName() const
Definition DstHltInf.cxx:61
const BufferHolder & getHltBuf() const
Definition RAWEVENT.h:95

Referenced by nextEvent().

◆ execute()

StatusCode MixerAlg::execute ( )

Definition at line 266 of file MixerAlg.cxx.

267{
268 //calculate time
269 if(m_ifOutPut) {
270 m_timer->start();
271 }
272
273 //caogf add
274 SmartDataPtr<Event::EventHeader> evt(eventSvc(),"/Event/EventHeader");
275 if( !evt ){
276 return StatusCode::FAILURE;
277 }
278
279 if(m_RealizationSvc->UseDBFlag() == true && m_RealizationSvc->ifReadRandTrg() == true && m_dbUserRequest == false) {
280 int runNo = evt -> runNumber();
281 if((runNo != m_runNo) || (RootInterface::Instance(*log)->getCurrentFileName() != currentMCFile)) {
282 m_runNo = runNo;
283 currentMCFile = RootInterface::Instance(*log)->getCurrentFileName();
284 m_mdcCnv->setRunId(runNo);
285 std::vector<std::string> bgfiles = m_RealizationSvc->getBgFileName();
286 if(bgfiles.size() == 0) {
287 (*log) << MSG::ERROR << "No random trigger files are found in the run " << m_runNo << std::endl;
288 exit(-1);
289 }
290 //m_ranTrgEvents = m_RealizationSvc->getRanTrgEvtNum();
291 if(! m_pattern.empty())
292 {
293 for(unsigned int k = 0; k < bgfiles.size(); k++) {
294 size_t pos_round = bgfiles[k].rfind("round");
295 (*log) << MSG::INFO<<"bgfiles: "<<bgfiles[k]<<endreq;
296 if(pos_round!=string::npos){
297 bgfiles[k].replace(bgfiles[k].begin(), bgfiles[k].begin()+pos_round, m_pattern);
298 (*log) << MSG::INFO<<"new random trigger data path: "<<bgfiles[k]<<endreq;
299 }
300 else{
301 (*log) << MSG::ERROR<<"string 'round' not found in random trigger path!"<<endreq;
302 exit(-1);
303 }
304 }
305 }
306 if (! m_newdatadir.empty())
307 {
308 for(unsigned int k = 0; k < bgfiles.size(); k++) {
309 char tmp[255];
310 std::strcpy (tmp, bgfiles[k].c_str());
311 string fname = basename(tmp);
312 bgfiles[k].replace(bgfiles[k].begin(), bgfiles[k].end(), m_newdatadir+'/'+fname);
313 (*log) << MSG::INFO<<"new random trigger data path: "<<bgfiles[k]<<endreq;
314 }
315 }
316
317 // achieve bg index files
318 std::vector<std::string> bgfilesIndex;
319 bgfilesIndex.clear();
320 for(unsigned int bg_index = 0; bg_index < bgfiles.size(); bg_index++) {
321 bgfilesIndex.push_back(bgfiles[bg_index] + ".idx");
322 }
323
324 // get event number of each bg file
325 if(m_fr) delete m_fr;
326 m_fr = new RawFileReader(bgfiles);
327 std::vector<int> ranTrgEvents = m_fr->getEventNumber(bgfilesIndex);
328
329 // remove bg files with 0 event
330 m_bgfiles.clear();
331 m_bgfilesIndex.clear();
332 m_ranTrgEvents.clear();
333 for(unsigned int bg_index = 0; bg_index < bgfiles.size(); bg_index++) {
334 if(ranTrgEvents[bg_index] > 0) {
335 m_bgfiles.push_back(bgfiles[bg_index]);
336 m_bgfilesIndex.push_back(bgfilesIndex[bg_index]);
337 m_ranTrgEvents.push_back(ranTrgEvents[bg_index]);
338 }
339 }
340
341 // get event number of each bg file
342 if(m_fr) delete m_fr;
343 m_fr = new RawFileReader(m_bgfiles);
344
345 // clear temp vector
346 bgfiles.clear();
347 bgfilesIndex.clear();
348 ranTrgEvents.clear();
349
350 // bg files exist?
351 if(m_bgfiles.empty() || m_ranTrgEvents.empty()) {
352 (*log) << MSG::WARNING << "No background datafiles found!!!" << endreq;
353 return StatusCode::SUCCESS;
354 }
355
356 if(m_skip == true) {
357 if(m_mixingMethod == 1) {
358 // Initialize
359 m_ranStepLenInCurrentFile.clear();
360 currentBGFile = "";
361 m_skipCount = 0;
362 m_totalEvent = 0;
363
364 // sort random trigger files by time increasing
365 bool ifsucc = file_sort(m_bgfiles,m_ranTrgEvents);
366 if( !ifsucc ) return StatusCode::FAILURE;
367
368 // achieve bg index files
369 m_bgfilesIndex.clear();
370 for(unsigned int bg_index = 0; bg_index < m_bgfiles.size(); bg_index++) {
371 m_bgfilesIndex.push_back(m_bgfiles[bg_index] + ".idx");
372 }
373
374 //count number of sets, total bg events in each set and total bg events in this run
375 m_vRanEvtNumInSubSet.clear();
376 m_vStreamNumInSubSet.clear();
377 m_totRanEvtNum = 0;
378 int set_no = -1;
379 int ranEvtNumInSubSet = 0;
380 int nstream = 0;
381 for(unsigned int i = 0; i < m_ranTrgEvents.size(); i++) {
382 if(i == 0) set_no = m_numSets[i];
383 if((i != 0) && (set_no != m_numSets[i])) {
384 m_vRanEvtNumInSubSet.push_back(ranEvtNumInSubSet);
385 m_vStreamNumInSubSet.push_back(nstream);
386 ranEvtNumInSubSet = 0;
387 nstream = 0;
388 set_no = m_numSets[i];
389 }
390
391 m_totRanEvtNum += m_ranTrgEvents[i];
392 ranEvtNumInSubSet += m_ranTrgEvents[i];
393 nstream++;
394 if(i == m_ranTrgEvents.size() - 1) {
395 m_vRanEvtNumInSubSet.push_back(ranEvtNumInSubSet);
396 m_vStreamNumInSubSet.push_back(nstream);
397 }
398 }
399
400 //get total event number in this run
401 int evtNumInRun = -1;
402 std::vector<int> vtotEvtNo = m_jobInfoSvc->getTotEvtNo();
403 for(unsigned int ii = 0; ii < vtotEvtNo.size(); ii+=2) {
404 if(std::abs(runNo) == std::abs(vtotEvtNo[ii]))
405 evtNumInRun = vtotEvtNo[ii+1];
406 }
407
408 //generate step length(event number) for each MC event to select background event
409 double tau = m_RealizationSvc->getTauValue();
410 double totalTime = m_RealizationSvc->getRunTotalTime();
411 if(m_RealizationSvc->getTauValue() == 0. || m_RealizationSvc->getRunTotalTime() == 0.) {
412 std::cout << "ERROR: In MixerAlg::execute() ---> The tau value or total run time is 0, please check it. Exit! " << std::endl;
413 exit(1);
414 }
415
416 bool using_exp = true;
417 if(totalTime*100 < tau) using_exp = false;
418 m_vStepLength.clear();
419 while(1) {
420 double ranNum;
421 if(using_exp == true) ranNum = RandExponential::shoot(tau);
422 else ranNum = RandFlat::shoot(0., totalTime);
423 if(ranNum > totalTime) continue;
424 ranNum = ranNum*m_totRanEvtNum/totalTime;
425 m_vStepLength.push_back((int)ranNum);
426 if(m_vStepLength.size() == evtNumInRun) break;
427 }
428
429 sort(m_vStepLength.begin(), m_vStepLength.end());
430
431 //
432 //Add a protect here
433 //
434 if(evtNumInRun <= 0 || m_totRanEvtNum <= 0) {
435 (*log) << MSG::ERROR << "The event number (or random trigger event number) in run " << evt->runNumber() << " is zero" << endreq;
436 return StatusCode::FAILURE;
437 }
438
439 //
440 //assigned step length and the number of selected bg events for each bg file
441 //
442 //1. define a map to store step length selected from each bg file
443 map_stepLength.clear();
444 for(unsigned int i = 0; i < m_ranTrgEvents.size(); i++) {
445 std::vector<int> vstepLength;
446 typedef pair<int, std::vector<int> > vpair;
447 map_stepLength.insert(vpair(i,vstepLength));
448 }
449 //2. assign step length for each bg file
450 for(unsigned int i = 0; i < m_ranTrgEvents.size(); ) {
451 //2.1 calculate total bg event number in this set and previous sets
452 int pre_ranEvtNumSubSet = 0;
453 int cur_ranEvtNumSubSet = 0;
454 set_no = m_numSets[i];
455 for(int j = 0; j < set_no; j++) {
456 if(j != (set_no - 1)) pre_ranEvtNumSubSet += m_vRanEvtNumInSubSet[j];
457 cur_ranEvtNumSubSet += m_vRanEvtNumInSubSet[j];
458 }
459 //2.2 assign step length
460 for(unsigned j = 0; j < m_vStepLength.size(); j++) {
461 //if current step length is in current set
462 if((m_vStepLength[j] >= pre_ranEvtNumSubSet) && (m_vStepLength[j] < cur_ranEvtNumSubSet)) {
463 int sub_stepLength = int((m_vStepLength[j]-pre_ranEvtNumSubSet)/m_vStreamNumInSubSet[set_no - 1]);
464 int file_id = 0;
465 int begin_fileId = -1, end_fileId = -1;
466 for(std::map<int,std::vector<int> >::iterator iter = map_stepLength.begin(); iter != map_stepLength.end(); iter++) {
467 //check current set number
468 if(set_no == m_numSets[iter->first]) {
469 if(begin_fileId == -1) begin_fileId = iter->first;
470 file_id++;
471 }
472 }
473 end_fileId = begin_fileId + file_id;
474 bool add_succ = false;
475 long loop_count = 0;
476
477 while(1) {
478 int random_file = int(RandFlat::shootInt(long(begin_fileId), long(end_fileId))); //exclude end_fileId
479 if(sub_stepLength < m_ranTrgEvents[random_file]) {
480 map_stepLength[random_file].push_back(sub_stepLength);
481 add_succ = true;
482 loop_count = 0;
483 }
484 if(add_succ) break;
485 loop_count++;
486 if(loop_count >= MAX_LOOP_TIMES) {
487 (*log) << MSG::ALWAYS << "Loop time is larger than MAX_LOOP_TIMES(" << MAX_LOOP_TIMES << ") in MixAlg, when assigning step length for each bg file." << endreq;
488 exit(1);
489 }
490 }
491 } //endif current step length is in current set
492 } //end assign step length
493 i += m_vStreamNumInSubSet[set_no - 1];
494 }
495
496 // check selected bg events number, equal to MC events?
497 unsigned int ranSelectedNum = 0;
498 for(std::map<int,std::vector<int> >::iterator iter = map_stepLength.begin(); iter != map_stepLength.end(); iter++) {
499 ranSelectedNum += (iter->second).size();
500 //std::cout << "file_id: " << iter->first << " ranEvtNumSelected: " << (iter->second).size() << std::endl;
501 }
502 if(ranSelectedNum != m_vStepLength.size()) {
503 (*log) << MSG::ERROR << "In MixerAlg::excute()--> selected bg events number not equal to MC events" << endreq;
504 return StatusCode::FAILURE;
505 }
506 }
507 }
508
509 if(m_mixingMethod == 2) {
510 // open background stream
511 if (m_fr) delete m_fr;
512 m_fr = NULL;
513 try {
514 m_bgfilesIndex.clear();
515 for(unsigned int bg_index = 0; bg_index < m_bgfiles.size(); bg_index++) {
516 m_bgfilesIndex.push_back(m_bgfiles[bg_index] + ".idx");
517 }
518 if(m_skip == true && m_readBGMethod == 1) m_fr = new RawFileReader(m_bgfiles, m_bgfilesIndex) ;
519 else m_fr = new RawFileReader(m_bgfiles) ;
520 }
521 catch (RawFileException& ex) {
522 ex.print();
523 return StatusCode::FAILURE;
524 }
525 }
526
527 m_raw_event->reset();
528 }
529 }
530 if(m_ifOutPut) {
531 m_timer->stop();
532 m_time1 = m_timer->elapsed();
533 m_timer->start();
534 }
535 //end caogf add
536 SmartDataPtr<MdcDigiCol> mdcMcDigits(eventSvc(),"/Event/Digi/MdcDigiCol");
537 if( ! mdcMcDigits )
538 (*log) << MSG::ERROR << "Unable to retrieve MdcDigiCol" << endreq;
539 else
540 (*log) << MSG::INFO << "MdcDigiCol retrieved of size "<< mdcMcDigits->size() << endreq;
541
542 SmartDataPtr<EmcDigiCol> emcMcDigits(eventSvc(),"/Event/Digi/EmcDigiCol");
543 if( ! emcMcDigits )
544 (*log) << MSG::ERROR << "Unable to retrieve EmcDigiCol" << endreq;
545 else
546 (*log) << MSG::INFO << "EmcDigiCol retrieved of size "<< emcMcDigits->size() << endreq;
547
548 SmartDataPtr<MucDigiCol> mucMcDigits(eventSvc(),"/Event/Digi/MucDigiCol");
549 if( ! mucMcDigits )
550 (*log) << MSG::ERROR << "Unable to retrieve MucDigiCol" << endreq;
551 else
552 (*log) << MSG::INFO << "MucDigiCol retrieved of size "<< mucMcDigits->size() << endreq;
553
554 SmartDataPtr<TofDigiCol> tofMcDigits(eventSvc(),"/Event/Digi/TofDigiCol");
555 if( ! tofMcDigits )
556 (*log) << MSG::ERROR << "Unable to retrieve TofDigiCol" << endreq;
557 else
558 (*log) << MSG::INFO << "TofDigiCol retrieved of size "<< tofMcDigits->size() << endreq;
559
560 for(int ievent = 0; ievent<m_nevent; ievent++)
561 {
562 (*log) << MSG::INFO << "Mixing BG Event " << ievent << endreq;
563 //if(m_skip == true) {
564 // nskipped = 0;
565 // m_skipCount = (int(m_NSkip*(RandFlat::shoot())) + 1);
566 //}
567 bool next = false;
568 if(m_skip == true) {
569 int nskip = 0;
570 if(m_mixingMethod == 1) {
571 if(m_RealizationSvc->UseDBFlag() == true && m_dbUserRequest == false) {
572 if(m_skipCount >= m_ranStepLenInCurrentFile.size()) {
573 m_ranStepLenInCurrentFile.clear();
574 for(std::map<int,std::vector<int> >::iterator iter = map_stepLength.begin(); iter != map_stepLength.end(); iter++) {
575 if(currentBGFile == "") {
576 if((iter->second).size() == 0) continue;
577 if(m_fr) delete m_fr;
578 try {
579 if(m_readBGMethod == 1) m_fr = new RawFileReader(m_bgfiles[iter->first], m_bgfiles[iter->first]+".idx") ;
580 else m_fr = new RawFileReader(m_bgfiles[iter->first]) ;
581 m_totEvtNumInCurFile = m_ranTrgEvents[iter->first];
582 }
583 catch (RawFileException& ex) {
584 ex.print();
585 }
586 m_ranStepLenInCurrentFile = iter->second;
587 m_skipCount = 0;
588 currentBGFile = m_fr->currentFile();
589 break;
590 }
591 if(currentBGFile == m_bgfiles[iter->first]) {
592 iter++;
593 if(iter == map_stepLength.end()) return StatusCode::FAILURE;
594 if((iter->second).size() == 0) {
595 while(1) {
596 iter++;
597 if(iter == map_stepLength.end()) return StatusCode::FAILURE;
598 if((iter->second).size() > 0) break;
599 }
600 }
601 if(m_fr) delete m_fr;
602 try {
603 if(m_readBGMethod == 1) m_fr = new RawFileReader(m_bgfiles[iter->first], m_bgfiles[iter->first]+".idx") ;
604 else m_fr = new RawFileReader(m_bgfiles[iter->first]) ;
605 m_totEvtNumInCurFile = m_ranTrgEvents[iter->first];
606 }
607 catch (RawFileException& ex) {
608 ex.print();
609 }
610 m_ranStepLenInCurrentFile = iter->second;
611 m_skipCount = 0;
612 currentBGFile = m_fr->currentFile();
613 break;
614 }
615 }
616 }
617 //std::cout << "skipcount: " << m_skipCount << " stepLength: " << m_ranStepLenInCurrentFile[m_skipCount] <<" total event number: " << m_totEvtNumInCurFile << std::endl;
618
619 if(m_skipCount == 0) nskip = m_ranStepLenInCurrentFile[m_skipCount];
620 else nskip = m_ranStepLenInCurrentFile[m_skipCount] - m_ranStepLenInCurrentFile[m_skipCount - 1];
621
622 m_nEventsToEnd = (m_totEvtNumInCurFile - 1) - m_ranStepLenInCurrentFile[m_skipCount]; //number of events to the end of current file
623
624 if(m_skipCount == 0 && nskip == 0) nskip = 1;
625 //std::cout << "nskip: " << nskip << std::endl;
626 m_skipCount++;
627 }
628 if(m_RealizationSvc->UseDBFlag() == false || m_dbUserRequest == true) nskip = int (2*m_NSkip*(RandFlat::shoot())) + 1;
629 if(m_totalEvent == 0 && nskip == 0) nskip = 1;
630 }
631 if(m_mixingMethod == 2) {
632 nskip = int (2*m_NSkip*(RandFlat::shoot())) + 1;
633 }
634 if(m_ifOutPut) {
635 m_timer->stop();
636 m_time2 = m_timer->elapsed();
637 m_timer->start();
638 }
639
640 // get that bg event
641 if(m_readBGMethod == 0) {
642 // same with previous versions
643 for(int j = 0; j < nskip; j++) {
644 next = nextEvent();
645 if ( ! next )
646 {
647 (*log) << MSG::ERROR << "Cannot get next background event" << endreq;
648 return StatusCode::FAILURE;
649 }
650 }
651 }
652 if(m_readBGMethod == 1) {
653 // new method to read bg events, using index file.
654 next = nextEvent(nskip,0,m_nEventsToEnd);
655 if ( ! next )
656 {
657 (*log) << MSG::ERROR << "Cannot get next background event" << endreq;
658 return StatusCode::FAILURE;
659 }
660 }
661 if(m_readBGMethod == 2) {
662 // new method to read bg events, using rude localizer.
663 next = nextEvent(nskip, 14*1024);
664 if ( ! next )
665 {
666 (*log) << MSG::ERROR << "Cannot get next background event" << endreq;
667 return StatusCode::FAILURE;
668 }
669 }
670 }
671 else { // if skip = false
672 next = nextEvent();
673 }
674
675 if(m_mixingMethod == 1) {
676 if ( !next && m_totalEvent == 0) {
677 (*log) << MSG::ERROR << "Cannot get next background event" << endreq;
678 return StatusCode::FAILURE;
679 }
680 }
681
682 if(m_mixingMethod == 2) {
683 if ( !next ) {
684 (*log) << MSG::ERROR << "Cannot get next background event" << endreq;
685 return StatusCode::FAILURE;
686 }
687 }
688
689 mixDigi(mdcMcDigits, emcMcDigits, mucMcDigits, tofMcDigits);
690 }
691
692 m_totalEvent++;
693
694 if(m_ifOutPut) {
695 m_timer->stop();
696 m_time3 = m_timer->elapsed();
697 m_tuple1->write();
698 }
699
700
701 return StatusCode::SUCCESS;
702}
int runNo
EvtStreamInputIterator< typename Generator::result_type > iter(Generator gen, int N=0)
#define MAX_LOOP_TIMES
Definition MixerAlg.h:30
void start(void)
Definition BesTimer.cxx:27
float elapsed(void) const
Definition BesTimer.h:23
void stop(void)
Definition BesTimer.cxx:39
std::vector< int > getTotEvtNo()
Definition DataInfoSvc.h:26
void setRunId(int runId)
bool file_sort(std::vector< std::string > &files, std::vector< int > &ranEvtNums)
void mixDigi(SmartDataPtr< MdcDigiCol > &mdcMcDigits, SmartDataPtr< EmcDigiCol > &emcMcDigits, SmartDataPtr< MucDigiCol > &mucMcDigits, SmartDataPtr< TofDigiCol > &tofMcDigits)
Definition MixerAlg.cxx:991
bool nextEvent(int nskip=0, int evtbyte=0, int eventsToEnd=0)
Definition MixerAlg.cxx:712
void reset()
Definition RAWEVENT.cxx:6
virtual void print() const
static std::vector< int > getEventNumber(const VFileNames_t &idxfnames)
std::string currentFile()
std::vector< std::string > getBgFileName()
float getRunTotalTime()
static RootInterface * Instance(MsgStream log)
singleton behaviour
virtual std::string getCurrentFileName()
Index next(Index i)
char * c_str(Index i)

◆ file_sort()

bool MixerAlg::file_sort ( std::vector< std::string > & files,
std::vector< int > & ranEvtNums )
protected

Definition at line 1157 of file MixerAlg.cxx.

1157 {
1158 std::vector<std::string> tmp_files = files;
1159 std::vector<int> tmp_ranEvtNums = ranEvtNums;
1160 files.clear();
1161 ranEvtNums.clear();
1162 m_numSets.clear();
1163
1164 const char* file_index[100];
1165 int num_index[100];
1166 int set_index[100];
1167 for(int i = 0; i < 100; i++) {
1168 file_index[i] = "";
1169 num_index[i] = 0;
1170 set_index[i] = 0;
1171 }
1172
1173 if(tmp_files.size() >= 100) {
1174 std::cout << "ERROR: In MixerAlg::file_sort(), please change bigger array size" << std::endl;
1175 return false;
1176 }
1177
1178 for(unsigned int i = 0; i < tmp_files.size(); i++) {
1179 int index = 0;
1180 const char* file1 = tmp_files[i].c_str();
1181 const char* substr1 = strstr(file1,"_file");
1182 int strlen1 = strlen(substr1);
1183 char cset1[4];
1184 char cnum1[2];
1185
1186 for(int sub1 = 0; sub1 < strlen1; sub1++) {
1187 if(substr1[sub1] == 'e') {
1188 cset1[0] = substr1[sub1+1];
1189 cset1[1] = substr1[sub1+2];
1190 cset1[2] = substr1[sub1+3];
1191 cset1[3] = '\0';
1192 }
1193 else if(substr1[sub1] == '-') {
1194 cnum1[0] = substr1[sub1+1];
1195 cnum1[1] = '\0';
1196 break;
1197 }
1198 else {
1199 continue;
1200 }
1201 }
1202
1203 int set1 = atoi(cset1);
1204 int num1 = atoi(cnum1);
1205 int encode_set1 = set1*100 + num1;
1206
1207 for(unsigned int j = 0; j < tmp_files.size(); j++) {
1208 if(i == j) continue;
1209 const char* file2 = tmp_files[j].c_str();
1210 const char* substr2 = strstr(file2,"_file");
1211 int strlen2 = strlen(substr2);
1212 char cset2[4];
1213 char cnum2[2];
1214 for(int sub2 = 0; sub2 < strlen2; sub2++) {
1215 if(substr2[sub2] == 'e') {
1216 cset2[0] = substr2[sub2+1];
1217 cset2[1] = substr2[sub2+2];
1218 cset2[2] = substr2[sub2+3];
1219 cset2[3] = '\0';
1220 }
1221 else if(substr2[sub2] == '-') {
1222 cnum2[0] = substr2[sub2+1];
1223 cnum2[1] = '\0';
1224 break;
1225 }
1226 else {
1227 continue;
1228 }
1229 }
1230 int set2 = atoi(cset2);
1231 int num2 = atoi(cnum2);
1232 int encode_set2 = set2*100 + num2;
1233 if(encode_set1 > encode_set2) index++;
1234 }
1235 file_index[index] = tmp_files[i].c_str();
1236 num_index[index] = tmp_ranEvtNums[i];
1237 set_index[index] = set1;
1238 }
1239
1240 int setNo = -10;
1241 for(unsigned int i = 0; i < tmp_files.size(); i++) {
1242 files.push_back(file_index[i]);
1243 ranEvtNums.push_back(num_index[i]);
1244 if(setNo != set_index[i]) {
1245 setNo = set_index[i];
1246 int numSets_size = m_numSets.size();
1247 if(numSets_size == 0) m_numSets.push_back(1);
1248 if(numSets_size != 0) m_numSets.push_back(m_numSets[numSets_size - 1] + 1);
1249 }
1250 else {
1251 int numSets_size = m_numSets.size();
1252 m_numSets.push_back(m_numSets[numSets_size - 1]);
1253 }
1254 }
1255
1256 return true;
1257}
const int num1

Referenced by execute().

◆ finalize()

StatusCode MixerAlg::finalize ( )

Definition at line 704 of file MixerAlg.cxx.

704 {
705 if( m_raw_event ) delete m_raw_event;
706 if( log ) delete log;
707 if( m_fr) delete m_fr;
708 return StatusCode::SUCCESS;
709}

◆ getTiming()

int MixerAlg::getTiming ( )
protected

Definition at line 1103 of file MixerAlg.cxx.

1104{
1105 int timing = 0;
1106
1107 TrigGTD* trigGTD = NULL;
1108 TrigGTDCol* gtdCol = new TrigGTDCol;
1109
1110 const BufferHolder& gtdBuf = m_raw_event->getGTDBuf();
1111 uint32_t nbuf = gtdBuf.nBuf();
1112
1113 for (uint32_t i = 0; i < nbuf; i++) {
1114 uint32_t* buf = gtdBuf(i);
1115 uint32_t bufSize = gtdBuf.bufSize(i);
1116 uint32_t index = 0;
1117 while (bufSize - index > 1) {
1118 uint32_t blockSize = ( ((*(buf+index))>>14) & 0x3FF);
1119 uint32_t id = ((*(buf+index))>>24);
1120 if (blockSize == 0 || (index+blockSize) > bufSize) break;
1121 if ((id> 0xD1 && id < 0xD8 && id != 0xD5) || id == 0xDA || (id > 0xE1 && id < 0xED)) {
1122 trigGTD = new TrigGTD(buf+index);
1123 gtdCol->push_back(trigGTD);
1124 }
1125 index += blockSize;
1126 }
1127 }
1128
1129 TrigGTDCol::iterator iter = gtdCol->begin();
1130 for (;iter != gtdCol->end(); iter++ ) {
1131 const uint32_t boardId = (*iter)->getId(); //The board Id 0xd3: GTL, 0xD2: SAF1, 0xD4: SAF2, 0xD6: SAF3
1132 const uint32_t timeWindow = (*iter)->getTimeWindow(); //Time window, bit8 to bit13, total: 0--31
1133 const uint32_t size = (*iter)->getDataSize(); //The size of trigger data, not include head
1134 const uint32_t* trigData = (*iter)->getDataPtr(); //Trigger data
1135
1136 //Get data group 5 in GTL, including trigger channel, timing and prescale.
1137 if(boardId == 0xd3) {
1138 if(size%timeWindow != 0) {
1139 std::cout << "GTL data is NOT completed, exit." << std::endl;
1140 exit(0);
1141 }
1142 for(uint32_t j = 0; j < size; j++) {
1143 uint32_t dataId = ((trigData[j] >> 24) & 0x7);
1144 if(dataId != 5) continue; //find data group 5
1145 for(uint32_t i = 1, loop = 0; loop < 24; i <<= 1, loop++) {
1146 if((loop == 16) && (trigData[j] & i)) timing = 1;
1147 if((loop == 17) && (trigData[j] & i) && (timing != 1)) timing = 2;
1148 if((loop == 18) && (trigData[j] & i) && (timing == 0)) timing = 3;
1149 }
1150 }
1151 }
1152 }
1153
1154 return timing;
1155}
ObjectVector< TrigGTD > TrigGTDCol
Definition TrigGTD.h:39
uint32_t nBuf() const
uint32_t bufSize(int i) const
const BufferHolder & getGTDBuf() const
Definition RAWEVENT.h:93

Referenced by mixDigi().

◆ initialize()

StatusCode MixerAlg::initialize ( )

Definition at line 115 of file MixerAlg.cxx.

116{
117 log = new MsgStream(messageService(), name() );
118 //Caogf add
119 IRealizationSvc *tmpReal;
120 StatusCode status = service("RealizationSvc",tmpReal);
121 if (!status.isSuccess())
122 {
123 (*log) << MSG::FATAL << " Could not initialize Realization Service" << endreq;
124 } else {
125 m_RealizationSvc=dynamic_cast<RealizationSvc*>(tmpReal);
126 }
127
128 if(m_RealizationSvc->UseDBFlag() == true && m_RealizationSvc->ifReadRandTrg() == true && m_dbUserRequest == true) {
129 std::string query = prepareDbQuery();
130 m_bgfiles = m_RealizationSvc->getBgFileName(query);
131 }
132
133 if(! m_pattern.empty())
134 {
135 for(unsigned int k = 0; k < m_bgfiles.size(); k++) {
136 size_t pos_round = m_bgfiles[k].rfind("round");
137 (*log) << MSG::INFO <<"m_bgfiles: "<<m_bgfiles[k]<<endreq;
138 if(pos_round!=string::npos){
139 m_bgfiles[k].replace(m_bgfiles[k].begin(), m_bgfiles[k].begin()+pos_round, m_pattern);
140 (*log) << MSG::INFO<<"new random trigger data path: "<<m_bgfiles[k]<<endreq;
141 }
142 else{
143 (*log) << MSG::ERROR<<"string 'round' not found in random trigger path!"<<endreq;
144 exit(-1);
145 }
146 }
147 }
148 if (! m_newdatadir.empty())
149 {
150 for(unsigned int k = 0; k < m_bgfiles.size(); k++) {
151 char tmp[255];
152 std::strcpy (tmp, m_bgfiles[k].c_str());
153 string fname = basename(tmp);
154 m_bgfiles[k].replace(m_bgfiles[k].begin(), m_bgfiles[k].end(), m_newdatadir+'/'+fname);
155 (*log) << MSG::INFO<<"new random trigger data path: "<<m_bgfiles[k]<<endreq;
156 }
157 }
158
159
160 // initialize MDC converter
161 m_mdcCnv->init(m_exRunFrom,m_exRunTo);
162
163 //caogf for random seed
164 static const bool CREATEIFNOTTHERE(true);
165 StatusCode RndmStatus = service("BesRndmGenSvc", p_BesRndmGenSvc, CREATEIFNOTTHERE);
166 if (!RndmStatus.isSuccess() || 0 == p_BesRndmGenSvc)
167 {
168 (*log) << MSG::ERROR << " Could not initialize Random Number Service" << endreq;
169 return RndmStatus;
170 }
171
172 //get jobSvc
173 IDataInfoSvc *tmpInfoSvc;
174 status = service("DataInfoSvc",tmpInfoSvc);
175 if (status.isSuccess()) {
176 (*log) << MSG::INFO << "get the DataInfoSvc" << endreq;
177 m_jobInfoSvc=dynamic_cast<DataInfoSvc *>(tmpInfoSvc);
178 }else {
179 (*log) << MSG::WARNING << "could not get the DataInfoSvc." << endreq;
180 }
181 //end caogf add
182
183 if(m_RealizationSvc->UseDBFlag() == false || m_dbUserRequest == true) {
184 if(m_bgfiles.empty()) {
185 (*log) << MSG::WARNING << "No background datafiles found" << endreq;
186 return StatusCode::SUCCESS;
187 }
188
189 // open background stream
190 try {
191 m_bgfilesIndex.clear();
192 for(unsigned int bg_index = 0; bg_index < m_bgfiles.size(); bg_index++) {
193 m_bgfilesIndex.push_back(m_bgfiles[bg_index] + ".idx");
194 }
195 if(m_skip == true && m_readBGMethod == 1) m_fr = new RawFileReader(m_bgfiles, m_bgfilesIndex) ;
196 else m_fr = new RawFileReader(m_bgfiles) ;
197 }
198 catch (RawFileException& ex) {
199 ex.print();
200 return StatusCode::FAILURE;
201 }
202
203 }
204 m_raw_event = new RAWEVENT;
205
206 if(m_ifOutPut) {
207 NTuplePtr nt1(ntupleSvc(), "FILE1/n1");
208 if(nt1) m_tuple1 = nt1;
209 else {
210 m_tuple1 = ntupleSvc()->book("FILE1/n1",CLID_ColumnWiseTuple,"Field");
211 if( m_tuple1 ) {
212 status = m_tuple1->addItem("time1", m_time1 );
213 status = m_tuple1->addItem("time2", m_time2 );
214 status = m_tuple1->addItem("time3", m_time3 );
215 }
216 else {
217 (*log) << MSG::ERROR << " Cannot book N-tuple:" <<long(m_tuple1)<< endreq;
218 return StatusCode::FAILURE;
219 }
220 }
221
222 NTuplePtr nt2(ntupleSvc(), "FILE1/n2");
223 if(nt2) m_tuple2 = nt2;
224 else {
225 m_tuple2 = ntupleSvc()->book("FILE1/n2",CLID_ColumnWiseTuple,"Field");
226 if( m_tuple2 ) {
227 status = m_tuple2->addItem("tdc", m_tdc );
228 }
229 else {
230 (*log) << MSG::ERROR << " Cannot book N-tuple:" <<long(m_tuple2)<< endreq;
231 return StatusCode::FAILURE;
232 }
233 }
234
235 NTuplePtr nt3(ntupleSvc(), "FILE1/n3");
236 if(nt3) m_tuple3 = nt3;
237 else {
238 m_tuple3 = ntupleSvc()->book("FILE1/n3",CLID_ColumnWiseTuple,"Field");
239 if( m_tuple3 ) {
240 status = m_tuple3->addItem("time4", m_time4 );
241 status = m_tuple3->addItem("time5", m_time5 );
242 }
243 else {
244 (*log) << MSG::ERROR << " Cannot book N-tuple:" <<long(m_tuple3)<< endreq;
245 return StatusCode::FAILURE;
246 }
247 }
248
249 status = service("BesTimerSvc", m_timersvc);
250 if (status.isFailure()) {
251 (*log) << MSG::ERROR << name() << ": Unable to locate BesTimer Service" << endreq;
252 return StatusCode::FAILURE;
253 }
254 m_timer = m_timersvc->addItem("Read field Time");
255 m_timer1 = m_timersvc->addItem("Read raw files");
256 }
257
258 //For random seed added by caogf. Note the position of the code, otherwise it is not available.
259 CLHEP::HepRandomEngine* engine = p_BesRndmGenSvc->GetEngine("MIX");
260 HepRandom::setTheEngine(engine);
261 HepRandom::showEngineStatus();
262
263 return StatusCode::SUCCESS;
264}
INTupleSvc * ntupleSvc()
virtual CLHEP::HepRandomEngine * GetEngine(const std::string &StreamName)=0
Interface to the CLHEP engine.
virtual BesTimer * addItem(const std::string &name)=0
void init(int runFrom, int runTo)
std::string prepareDbQuery()
Definition MixerAlg.cxx:84

◆ mixDigi()

void MixerAlg::mixDigi ( SmartDataPtr< MdcDigiCol > & mdcMcDigits,
SmartDataPtr< EmcDigiCol > & emcMcDigits,
SmartDataPtr< MucDigiCol > & mucMcDigits,
SmartDataPtr< TofDigiCol > & tofMcDigits )
protected

Definition at line 991 of file MixerAlg.cxx.

995{
996 if( b_mdc )// MDC
997 {
998 MdcDigiCol mdcCol;
999 decodeMdc(&mdcCol);
1000 //combineDigits<MdcDigiCol, MdcDigi>(mdcMcDigits, mdcCol, log->level());
1001
1002 // Find minimal tdc and maximum tdc and calculate mean tdc.
1003 if(m_ifSmearT0 && getTiming() > 0) {
1004 int tdc_min = -9, tdc_max = -9, tdc_tot = 0, tdc_num = 0;
1005 for(MdcDigiCol::const_iterator bg = mdcCol.begin(); bg != mdcCol.end(); bg++ )
1006 {
1007 if((*bg)->getTimeChannel() < 0x7FFFFFFF) {
1008 tdc_tot += (*bg)->getTimeChannel();
1009 tdc_num++;
1010 if(tdc_min < 0) tdc_min = (*bg)->getTimeChannel();
1011 else {
1012 if(tdc_min > (*bg)->getTimeChannel()) tdc_min = (*bg)->getTimeChannel();
1013 }
1014 if(tdc_max < 0) tdc_max = (*bg)->getTimeChannel();
1015 else {
1016 if(tdc_max < (*bg)->getTimeChannel()) tdc_max = (*bg)->getTimeChannel();
1017 }
1018 }
1019 }
1020 int tdc_mean = (int) ((double)tdc_tot/(double)tdc_num);
1021 tdc_num = 0;
1022 int tdc_shift;
1023 while(1) {
1024 tdc_shift = tdc_mean - CLHEP::RandFlat::shootInt(long(0), long(80*24/0.09375));
1025 if((tdc_min - tdc_shift)>=0 && (tdc_max - tdc_shift) <= int(80*24/0.09375)) break;
1026 tdc_num++;
1027 if(tdc_num > m_maxLoop) break;
1028 }
1029
1030 // Set new tdc
1031 for(MdcDigiCol::const_iterator bg = mdcCol.begin(); bg != mdcCol.end(); bg++ )
1032 {
1033 if((*bg)->getTimeChannel() >= 0x7FFFFFFF) continue;
1034 int newTDC = (*bg)->getTimeChannel() - tdc_shift;
1035 if(newTDC < 0 || newTDC > int(80*24/0.09375)) newTDC = int(CLHEP::RandFlat::shoot()*80*24/0.09375);
1036 (*bg)->setTimeChannel(newTDC);
1037
1038 //m_tdc = (*bg)->getTimeChannel();
1039 //m_tuple2->write();
1040 }
1041 }
1042 //combineDigits<MdcDigiCol, MdcDigi>(mdcMcDigits, mdcCol, log->level());
1043 combineMdcDigits(mdcMcDigits, mdcCol, log->level());
1044 }
1045 if( b_emc )//EMC
1046 {
1047 EmcDigiCol emcCol;
1048 decodeEmc(&emcCol);
1049 combineDigits<EmcDigiCol, EmcDigi>(emcMcDigits, emcCol, log->level());
1050 }
1051 if( b_muc )// MUC
1052 {
1053 MucDigiCol mucCol;
1054 decodeMuc(&mucCol);
1055 combineDigits<MucDigiCol, MucDigi>(mucMcDigits, mucCol, log->level());
1056 }
1057 if( b_tof )// TOF
1058 {
1059 TofDigiCol tofCol;
1060 decodeTof(&tofCol);
1061 //combineDigits<TofDigiCol, TofDigi>(tofMcDigits, tofCol, log->level());
1062 combineTofDigits(tofMcDigits, tofCol, log->level());
1063 }
1064}
ObjectVector< EmcDigi > EmcDigiCol
Definition EmcDigi.h:43
ObjectVector< MdcDigi > MdcDigiCol
Definition MdcDigi.h:39
void combineMdcDigits(SmartDataPtr< MdcDigiCol > &mcDigits, MdcDigiCol &bgDigits, int verbosity)
Definition MixerAlg.cxx:927
void combineTofDigits(SmartDataPtr< TofDigiCol > &mcDigits, TofDigiCol &bgDigits, int verbosity)
Definition MixerAlg.cxx:976
void combineDigits(SmartDataPtr< T1 > &mcDigits, T1 &bgDigits, int verbosity)
Definition MixerAlg.cxx:879
ObjectVector< MucDigi > MucDigiCol
Definition MucDigi.h:29
ObjectVector< TofDigi > TofDigiCol
Definition TofDigi.h:41
void bg(int i, double p)
Definition betagamma.cxx:1
void decodeMuc(MucDigiCol *digiCol)
void decodeEmc(EmcDigiCol *digiCol)
int getTiming()
void decodeMdc(MdcDigiCol *digiCol)
void decodeTof(TofDigiCol *digiCol)

Referenced by execute().

◆ nextEvent()

bool MixerAlg::nextEvent ( int nskip = 0,
int evtbyte = 0,
int eventsToEnd = 0 )
protected

Definition at line 712 of file MixerAlg.cxx.

713{
714
715 m_raw_event->reset();
716
717 try {
718 if(m_ifOutPut) {
719 m_timer1->start();
720 }
721
722 const uint32_t* fragment;
723 if(m_skip == true && m_readBGMethod == 0) fragment = m_fr->nextEvent();
724 if(m_skip == true && m_readBGMethod == 1) {
725 if(nskip == 0) fragment = m_fr->currentEvent();
726 else fragment = m_fr->nextEvent(nskip - 1);
727 }
728 if(m_skip == true && m_readBGMethod == 2) {
729 if(nskip == 0) fragment = m_fr->currentEvent();
730 else fragment = m_fr->roughlyNextEvent(nskip - 1, evtbyte);
731 }
732 if(m_skip == false) fragment = m_fr->nextEvent();
733
734 if(m_ifOutPut) {
735 m_timer1->stop();
736 m_time4 = m_timer1->elapsed();
737 m_timer1->start();
738 }
739 //if (fragment == NULL) {
740 // (*log) << MSG::ERROR << "RawFileReader::nextEvent() Failed!!!" << endreq;
741 // exit(1);
742 // }
743
744 RawEvent f(fragment);
745 if (!f.check()) {
746 std::cerr << "Found invalid event (traceback):" << std::endl;
747 std::exit(1);
748 }
749 //1.print basic event information
750 uint32_t fFragmentSize = f.fragment_size_word();
751 (*log) << MSG::DEBUG << "[Event No. #" << f.global_id()
752 << "] " << f.fragment_size_word() << " words in "
753 << f.nchildren() << " subdetectors "
754 << endreq;
755 m_raw_event->setRunNo(f.run_no());
756 m_raw_event->setEventNo(f.global_id());
757
758 //fucd: get event filter information
759 const uint32_t* ef=NULL;
760 f.event_filter_info(ef);
761 if(!ef){
762 (*log) << MSG::ERROR << "Event Filter Data Failed!!!" << endreq;
763 exit(1);
764 }
765 else{
766 (*log) << MSG::DEBUG<< "Event Filter Information*********" <<std::hex<<endreq
767 <<*ef<< " "<<*(ef+1)<<" "<<*(ef+2)<<" "<<*(ef+3)<<std::dec<<endreq;
768 m_raw_event->addReHltRaw((uint32_t*)ef, (uint32_t)4);
769 }
770
771 uint32_t *robs[64];
772 int nrobs = eformat::get_robs(fragment, (const uint32_t **)robs, 64);
773
774 for (int robi = 0; robi < nrobs; robi++) {
775 eformat::ROBFragment<uint32_t*> rob(robs[robi]);
776 if ((rob.rod_detev_type() & 0x2) != 0) continue; //bad data caogf add
777 uint32_t* dataptr = NULL;
778 rob.rod_data(dataptr);
779
780 uint32_t source_id_number = rob.rod_source_id();
781 //std::cout<<"#####source_id_number#####"<<source_id_number<<std::endl;
782 source_id_number <<= 8;
783 source_id_number >>= 24;
784 //std::cout<<"#####(source_id_number<<24)>>29#####"<<source_id_number<<std::endl;
785 //be careful here!!!
786 switch(source_id_number) {
787 case 161:
788 m_raw_event->addReMdcDigi(dataptr, rob.rod_ndata());
789 break;
790 case 163:
791 m_raw_event->addReEmcDigi(dataptr, rob.rod_ndata());
792 break;
793 case 162:
794 m_raw_event->addReTofDigi(dataptr, rob.rod_ndata());
795 break;
796 case 164:
797 m_raw_event->addReMucDigi(dataptr, rob.rod_ndata());
798 break;
799 case 165: // trigger !!!
800 //std::cout << "Get Trigger Data -" << std::endl;
801 //for (int i = 0; i < rob.rod_ndata(); i++) {
802 // std::cout << "\t0x" << std::hex << dataptr[i] << std::dec << std::endl;
803 //}
804 m_raw_event->addReTrigGTD(dataptr, rob.rod_ndata());
805 break;
806 case 124: // EventFilter
807 m_raw_event->addReHltRaw(dataptr, rob.rod_ndata());
808 break;
809 case 241: // McParticle
810 m_raw_event->addMcParticle(dataptr, rob.rod_ndata());
811 break;
812 default:
813 //std::cerr << "no such subdetector type: " << source_id_number << std::endl;
814 break;
815 }
816 }
817 if(m_ifOutPut) {
818 m_timer1->stop();
819 m_time5 = m_timer1->elapsed();
820 m_tuple3->write();
821 }
822
823 if(m_usingFilter == true) {
824 if(eventType() == "GHadron" || eventType() == "GEBhabha" || eventType() == "GBBhabha" || eventType() == "GCosmic" || eventType() == "GDimuon") {
825 if(m_skip == true && m_readBGMethod == 0) {
826 return nextEvent(1, evtbyte, eventsToEnd);
827 }
828 if(m_skip == true && m_readBGMethod == 1) {
829 if(m_RealizationSvc->UseDBFlag() == false || m_dbUserRequest == true) return nextEvent(1, evtbyte, eventsToEnd);
830 if(eventsToEnd > 0 && m_RealizationSvc->UseDBFlag() == true && m_dbUserRequest == false ) {
831 eventsToEnd--;
832 return nextEvent(1, evtbyte, eventsToEnd);
833 }
834 }
835 if(m_skip == true && m_readBGMethod == 2) {
836 return nextEvent(1, evtbyte, eventsToEnd);
837 }
838 if(m_skip == false) return nextEvent(nskip, evtbyte, eventsToEnd);
839 }
840 }
841
842 return true;
843 }
844 catch (ReachEndOfFileList& ex){
845 ex.print();
846
847 delete m_fr;
848 try {
849 if(m_skip == true && m_readBGMethod == 1) m_fr = new RawFileReader(m_bgfiles, m_bgfilesIndex) ;
850 else m_fr = new RawFileReader(m_bgfiles);
851 }
852 catch (RawFileException& ex) {
853 ex.print();
854 return false;
855 }
856
857 return nextEvent(nskip, evtbyte, eventsToEnd);
858 }
859 catch (RawFileException& ex) {
860 ex.print();
861 }
862 catch (eformat::Issue& ex) {
863 std::cerr << std::endl << "Uncaught eformat issue: " << ex.what() << std::endl;
864 }
865 catch (ers::Issue& ex) {
866 std::cerr << std::endl << "Uncaught ERS issue: " << ex.what() << std::endl;
867 }
868 catch (std::exception& ex) {
869 std::cerr << std::endl << "Uncaught std exception: " << ex.what() << std::endl;
870 }
871 catch (...) {
872 std::cerr << std::endl << "Uncaught unknown exception" << std::endl;
873 }
874
875 return false;
876}
std::string eventType()
void addReTofDigi(uint32_t *digi, uint32_t size)
Definition RAWEVENT.h:59
void setRunNo(uint32_t run_no)
Definition RAWEVENT.h:46
void addReMdcDigi(uint32_t *digi, uint32_t size)
Definition RAWEVENT.h:53
void addReTrigGTD(uint32_t *digi, uint32_t size)
Definition RAWEVENT.h:65
void addReMucDigi(uint32_t *digi, uint32_t size)
Definition RAWEVENT.h:62
void addMcParticle(uint32_t *buf, uint32_t size)
Definition RAWEVENT.h:76
void setEventNo(uint32_t event_no)
Definition RAWEVENT.h:47
void addReEmcDigi(uint32_t *digi, uint32_t size)
Definition RAWEVENT.h:56
void addReHltRaw(uint32_t *digi, uint32_t size)
Definition RAWEVENT.h:71
const uint32_t * roughlyNextEvent(int nIgnore, int evtByte=0)
const uint32_t * nextEvent()
const uint32_t * currentEvent() const
virtual void print() const
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:105

Referenced by execute(), and nextEvent().

◆ prepareDbQuery()

std::string MixerAlg::prepareDbQuery ( )
protected

Definition at line 84 of file MixerAlg.cxx.

85{
86 std::string query = "SELECT FilePath,FileName,NumEvent FROM RanTrgData";
87
88 if (! m_run.empty() || m_runs.size()==2 || m_dates.size()==2)
89 { // use additional parameters for query
90 query = query + " WHERE ";
91 bool use_and = false;
92 if(! m_run.empty() )
93 {
94 query = query + " RunNo=" + m_run;
95 use_and = true;
96 }
97 if( m_runs.size()==2 )
98 {
99 if(use_and) query = query + " AND ";
100 query = query + " RunNo>=" + m_runs[0] + " AND RunNo<=" + m_runs[1];
101 use_and = true;
102 }
103 if( m_dates.size()==2 )
104 {
105 if(use_and) query = query + " AND ";
106 query = query + " TimeSOR>='" + m_dates[0] + "' AND TimeEOR<='" + m_dates[1] + "'";
107 }
108 }
109
110 query = query + ";";
111 return query;
112}

Referenced by initialize().


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