BOSS 7.1.1
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 38 of file MixerAlg.cxx.

38 : Algorithm(name, pSvcLocator){
39 declareProperty("MixMdcDigi", b_mdc=true);
40 declareProperty("MixEmcDigi", b_emc=true);
41 declareProperty("MixMucDigi", b_muc=true);
42 declareProperty("MixTofDigi", b_tof=true);
43
44 declareProperty("DBUserRequest", m_dbUserRequest=false);
45 declareProperty("RandomTrgRun", m_run);
46 declareProperty("RandomTrgRunRange", m_runs);
47 declareProperty("RandomTrgTimeRange", m_dates);
48
49 declareProperty("BackgroundDataFiles", m_bgfiles);
50 declareProperty("NumRanTrgEvents", m_ranTrgEvents);
51 declareProperty("NBgEventsToSignal", m_nevent=1);
52 // declareProperty("LoopBgData", b_loop=true);
53 declareProperty("ReplaceDataPath", m_pattern);
54 declareProperty("UseNewDataDir", m_newdatadir);
55 declareProperty("IfSkip", m_skip=true);
56 declareProperty("NSkip", m_NSkip=150);
57 declareProperty("OutPut", m_ifOutPut=false);
58 declareProperty("MixingMethod", m_mixingMethod=1);
59 declareProperty("MaxLoop", m_maxLoop=10);
60 declareProperty("SmearT0", m_ifSmearT0=true);
61 declareProperty("ReadBGMethod", m_readBGMethod=1);
62
63 declareProperty("UsingFilter", m_usingFilter = true);
64 declareProperty("dump", m_dump = false);
65 declareProperty("RawDataReviseConfFile", m_rawReviseConfig);
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 1086 of file MixerAlg.cxx.

1087{
1088 const BufferHolder& emcBuf = m_raw_event->getEmcBuf();
1089 m_emcCnv->convert(emcBuf, digiCol);
1090}
StatusCode convert(const BufferHolder &src, EmcDigiCol *des)
const BufferHolder & getEmcBuf() const
Definition RAWEVENT.h:97

Referenced by mixDigi().

◆ decodeMdc()

void MixerAlg::decodeMdc ( MdcDigiCol * digiCol)
protected

Definition at line 1074 of file MixerAlg.cxx.

1075{
1076 const BufferHolder& mdcBuf = m_raw_event->getMdcBuf();
1077 m_mdcCnv->convert(mdcBuf, digiCol);
1078}
StatusCode convert(const BufferHolder &src, MdcDigiCol *des)
const BufferHolder & getMdcBuf() const
Definition RAWEVENT.h:95

Referenced by mixDigi().

◆ decodeMuc()

void MixerAlg::decodeMuc ( MucDigiCol * digiCol)
protected

Definition at line 1080 of file MixerAlg.cxx.

1081{
1082 const BufferHolder& mucBuf = m_raw_event->getMucBuf();
1083 m_mucCnv->convert(mucBuf, digiCol);
1084}
StatusCode convert(const BufferHolder &src, MucDigiCol *des)
const BufferHolder & getMucBuf() const
Definition RAWEVENT.h:98

Referenced by mixDigi().

◆ decodeTof()

void MixerAlg::decodeTof ( TofDigiCol * digiCol)
protected

Definition at line 1092 of file MixerAlg.cxx.

1093{
1094 const BufferHolder& tofBuf = m_raw_event->getTofBuf();
1095 const BufferHolder& etfBuf = m_raw_event->getEtfBuf();
1096 if( etfBuf.nBuf()>0 ) {
1097 m_tofCnv->convert(tofBuf, etfBuf, digiCol);
1098 }
1099 else {
1100 m_tofCnv->convert(tofBuf, digiCol);
1101 }
1102}
uint32_t nBuf() const
const BufferHolder & getEtfBuf() const
Definition RAWEVENT.h:102
const BufferHolder & getTofBuf() const
Definition RAWEVENT.h:96
StatusCode convert(const BufferHolder &src, TofDigiCol *des, LumiDigiCol *des2=0)

Referenced by mixDigi().

◆ eventType()

std::string MixerAlg::eventType ( )
protected

Definition at line 1104 of file MixerAlg.cxx.

1105{
1106 const BufferHolder& hltBuf = m_raw_event->getHltBuf();
1107 DstHltInf* hlt = new DstHltInf();
1108 hlt->setEventType(hltBuf(0)[0]);
1109
1110 std::string evtType = hlt->getEventName();
1111
1112 if(hlt) delete hlt;
1113
1114 return evtType;
1115}
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:101

Referenced by nextEvent().

◆ execute()

StatusCode MixerAlg::execute ( )

Definition at line 267 of file MixerAlg.cxx.

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

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

Referenced by execute().

◆ finalize()

StatusCode MixerAlg::finalize ( )

Definition at line 705 of file MixerAlg.cxx.

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

◆ getTiming()

int MixerAlg::getTiming ( )
protected

Definition at line 1117 of file MixerAlg.cxx.

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

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 std::ifstream conff(m_rawReviseConfig.c_str());
162 m_mdcCnv->init(SniperJSON::load(conff)["MDCID_FIX"]);
163
164 //caogf for random seed
165 static const bool CREATEIFNOTTHERE(true);
166 StatusCode RndmStatus = service("BesRndmGenSvc", p_BesRndmGenSvc, CREATEIFNOTTHERE);
167 if (!RndmStatus.isSuccess() || 0 == p_BesRndmGenSvc)
168 {
169 (*log) << MSG::ERROR << " Could not initialize Random Number Service" << endreq;
170 return RndmStatus;
171 }
172
173 //get jobSvc
174 IDataInfoSvc *tmpInfoSvc;
175 status = service("DataInfoSvc",tmpInfoSvc);
176 if (status.isSuccess()) {
177 (*log) << MSG::INFO << "get the DataInfoSvc" << endreq;
178 m_jobInfoSvc=dynamic_cast<DataInfoSvc *>(tmpInfoSvc);
179 }else {
180 (*log) << MSG::WARNING << "could not get the DataInfoSvc." << endreq;
181 }
182 //end caogf add
183
184 if(m_RealizationSvc->UseDBFlag() == false || m_dbUserRequest == true) {
185 if(m_bgfiles.empty()) {
186 (*log) << MSG::WARNING << "No background datafiles found" << endreq;
187 return StatusCode::SUCCESS;
188 }
189
190 // open background stream
191 try {
192 m_bgfilesIndex.clear();
193 for(unsigned int bg_index = 0; bg_index < m_bgfiles.size(); bg_index++) {
194 m_bgfilesIndex.push_back(m_bgfiles[bg_index] + ".idx");
195 }
196 if(m_skip == true && m_readBGMethod == 1) m_fr = new RawFileReader(m_bgfiles, m_bgfilesIndex) ;
197 else m_fr = new RawFileReader(m_bgfiles) ;
198 }
199 catch (RawFileException& ex) {
200 ex.print();
201 return StatusCode::FAILURE;
202 }
203
204 }
205 m_raw_event = new RAWEVENT;
206
207 if(m_ifOutPut) {
208 NTuplePtr nt1(ntupleSvc(), "FILE1/n1");
209 if(nt1) m_tuple1 = nt1;
210 else {
211 m_tuple1 = ntupleSvc()->book("FILE1/n1",CLID_ColumnWiseTuple,"Field");
212 if( m_tuple1 ) {
213 status = m_tuple1->addItem("time1", m_time1 );
214 status = m_tuple1->addItem("time2", m_time2 );
215 status = m_tuple1->addItem("time3", m_time3 );
216 }
217 else {
218 (*log) << MSG::ERROR << " Cannot book N-tuple:" <<long(m_tuple1)<< endreq;
219 return StatusCode::FAILURE;
220 }
221 }
222
223 NTuplePtr nt2(ntupleSvc(), "FILE1/n2");
224 if(nt2) m_tuple2 = nt2;
225 else {
226 m_tuple2 = ntupleSvc()->book("FILE1/n2",CLID_ColumnWiseTuple,"Field");
227 if( m_tuple2 ) {
228 status = m_tuple2->addItem("tdc", m_tdc );
229 }
230 else {
231 (*log) << MSG::ERROR << " Cannot book N-tuple:" <<long(m_tuple2)<< endreq;
232 return StatusCode::FAILURE;
233 }
234 }
235
236 NTuplePtr nt3(ntupleSvc(), "FILE1/n3");
237 if(nt3) m_tuple3 = nt3;
238 else {
239 m_tuple3 = ntupleSvc()->book("FILE1/n3",CLID_ColumnWiseTuple,"Field");
240 if( m_tuple3 ) {
241 status = m_tuple3->addItem("time4", m_time4 );
242 status = m_tuple3->addItem("time5", m_time5 );
243 }
244 else {
245 (*log) << MSG::ERROR << " Cannot book N-tuple:" <<long(m_tuple3)<< endreq;
246 return StatusCode::FAILURE;
247 }
248 }
249
250 status = service("BesTimerSvc", m_timersvc);
251 if (status.isFailure()) {
252 (*log) << MSG::ERROR << name() << ": Unable to locate BesTimer Service" << endreq;
253 return StatusCode::FAILURE;
254 }
255 m_timer = m_timersvc->addItem("Read field Time");
256 m_timer1 = m_timersvc->addItem("Read raw files");
257 }
258
259 //For random seed added by caogf. Note the position of the code, otherwise it is not available.
260 CLHEP::HepRandomEngine* engine = p_BesRndmGenSvc->GetEngine("MIX");
261 HepRandom::setTheEngine(engine);
262 HepRandom::showEngineStatus();
263
264 return StatusCode::SUCCESS;
265}
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(const SniperJSON &config)
std::string prepareDbQuery()
Definition MixerAlg.cxx:84
static SniperJSON load(std::istream &is)

◆ mixDigi()

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

Definition at line 999 of file MixerAlg.cxx.

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

Referenced by execute().

◆ nextEvent()

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

Definition at line 713 of file MixerAlg.cxx.

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

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: