BOSS 6.6.4.p01
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)
Definition: EmcConverter.cxx:9
static MdcConverter * instance(int runMode=2)
Definition: MdcConverter.cxx:6
static MucConverter * instance()
Definition: MucConverter.cxx:5
static TofConverter * instance()
Definition: TofConverter.cxx:5

◆ ~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 1074 of file MixerAlg.cxx.

1075{
1076 const BufferHolder& emcBuf = m_raw_event->getEmcBuf();
1077 m_emcCnv->convert(emcBuf, digiCol);
1078}
StatusCode convert(const BufferHolder &src, EmcDigiCol *des)
const BufferHolder & getEmcBuf() const
Definition: RAWEVENT.h:88

Referenced by mixDigi().

◆ decodeMdc()

void MixerAlg::decodeMdc ( MdcDigiCol digiCol)
protected

Definition at line 1062 of file MixerAlg.cxx.

1063{
1064 const BufferHolder& mdcBuf = m_raw_event->getMdcBuf();
1065 m_mdcCnv->convert(mdcBuf, digiCol);
1066}
StatusCode convert(const BufferHolder &src, MdcDigiCol *des)
const BufferHolder & getMdcBuf() const
Definition: RAWEVENT.h:86

Referenced by mixDigi().

◆ decodeMuc()

void MixerAlg::decodeMuc ( MucDigiCol digiCol)
protected

Definition at line 1068 of file MixerAlg.cxx.

1069{
1070 const BufferHolder& mucBuf = m_raw_event->getMucBuf();
1071 m_mucCnv->convert(mucBuf, digiCol);
1072}
StatusCode convert(const BufferHolder &src, MucDigiCol *des)
const BufferHolder & getMucBuf() const
Definition: RAWEVENT.h:89

Referenced by mixDigi().

◆ decodeTof()

void MixerAlg::decodeTof ( TofDigiCol digiCol)
protected

Definition at line 1080 of file MixerAlg.cxx.

1081{
1082 const BufferHolder& tofBuf = m_raw_event->getTofBuf();
1083 m_tofCnv->convert(tofBuf, digiCol);
1084}
const BufferHolder & getTofBuf() const
Definition: RAWEVENT.h:87
StatusCode convert(const BufferHolder &src, TofDigiCol *des, LumiDigiCol *des2=0)

Referenced by mixDigi().

◆ eventType()

std::string MixerAlg::eventType ( )
protected

Definition at line 1086 of file MixerAlg.cxx.

1087{
1088 const BufferHolder& hltBuf = m_raw_event->getHltBuf();
1089 DstHltInf* hlt = new DstHltInf();
1090 hlt->setEventType(hltBuf(0)[0]);
1091
1092 std::string evtType = hlt->getEventName();
1093
1094 if(hlt) delete hlt;
1095
1096 return evtType;
1097}
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:91

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

◆ file_sort()

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

Definition at line 1153 of file MixerAlg.cxx.

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

Referenced by execute().

◆ finalize()

StatusCode MixerAlg::finalize ( )

Definition at line 700 of file MixerAlg.cxx.

700 {
701 if( m_raw_event ) delete m_raw_event;
702 if( log ) delete log;
703 if( m_fr) delete m_fr;
704 return StatusCode::SUCCESS;
705}

◆ getTiming()

int MixerAlg::getTiming ( )
protected

Definition at line 1099 of file MixerAlg.cxx.

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

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 987 of file MixerAlg.cxx.

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

Referenced by execute().

◆ nextEvent()

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

Definition at line 708 of file MixerAlg.cxx.

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