134 log << MSG::INFO <<
"TofRawDataProvider::tofDataMapFull()" << endreq;
136 if( !m_tofDataMap.empty() ) {
138 log << MSG::WARNING <<
"TofRawDataProvider::tofDataMapFull: m_tofDataMap is NOT empty!" << endreq;
141 for( ;
iter != m_tofDataMap.end();
iter++ ) {
142 delete (*iter).second;
144 m_tofDataMap.clear();
147 std::string evtDataSvc_name(
"EventDataSvc");
148 if(isGaudiThreaded(
m_name)){
149 evtDataSvc_name += getGaudiThreadIDfromName(
m_name);
153 IDataProviderSvc* eventSvc;
154 StatusCode sc =
m_svcLocator->service( evtDataSvc_name.c_str(),eventSvc,
true );
155 if( !sc.isSuccess() ) {
156 log << MSG::FATAL <<
"TofRawDataProvider::tofDataMapFull: ERROR Could not load EventDataSvc" << endreq;
161 SmartDataPtr<Event::EventHeader> eventHeader(eventSvc,
"/Event/EventHeader");
163 log << MSG::FATAL <<
"TofRawDataProvider could not find Event Header!" << endreq;
166 int run = eventHeader->runNumber();
168 bool mc = ( run < 0 ) ?
true:
false;
170 qCorr = qCorr && (!mc);
173 misLable = ( !mc && misLable );
177 for(
unsigned int i=0; i<5; i++ ) {
180 if( identmp != 0x2fffffff ) {
182 deadId.push_back( identmp );
187 if( identmp != 0x2fffffff ) {
189 deadId.push_back( identmp );
193 if( identmp != 0x2fffffff ) {
195 deadId.push_back( identmp );
200 SmartDataPtr<TofDigiCol> tofDigiCol(eventSvc,
"/Event/Digi/TofDigiCol");
202 log << MSG::WARNING <<
"TofRawDataProvider::tofDataMapFull: Could not find Tof Digi Data!" << endreq;
209 std::vector<Adc*> chargeVec;
210 std::vector<Tdc*> timeVec;
215 TofDigiCol::iterator
iter = tofDigiCol->begin();
217for( ;
iter != tofDigiCol->end();
iter++ ) {
225 if(barrel_ec_help == 0 || barrel_ec_help ==1 || barrel_ec_help==2)
228 unsigned int overflow = (*iter)->getOverflow();
232 if( ( overflow & 0xfe000000 ) == 0xfe000000 )
240 bool multiQ = ( ( overflow & 0x8 ) != 0 );
241 bool multiT = ( ( overflow & 0x4 ) != 0 );
245 unsigned int iden_value = iden.
get_value();
251 vector<int>::iterator iter_dead = deadId.begin();
252 for( ; iter_dead != deadId.end(); iter_dead++ ) {
253 if( iden_value == (*iter_dead) ) {
259 if( mc ) {
continue; }
261 log << MSG::ERROR <<
"TofRawDataProvider::tofDataMapFull: Dead Channel Number is not Correct, please check TOF Calibration Constants!" << endreq;
272 if( ( barrel_ec != 1 ) && ( end == 1 ) )
continue;
274 if( ( barrel_ec != 1 ) && (
id == 48 ) )
continue;
276 unsigned int tdcChannel = (*iter)->getTimeChannel();
277 unsigned int adcChannel = (*iter)->getChargeChannel();
282 if( ( overflow & 0x2 ) != 0 )
284 adcChannel = ( adcChannel | 0x80000 );
287 if( (adcChannel&0x7fffffff) != 0x7fffffff ) {
296 chargeVec.push_back( adc );
301 if( tdcChannel != 0x7fffffff ) {
306 timeVec.push_back( tdc );
311 if( multiT || multiQ ) {
312 TofDigiCol::iterator iter_next =
iter + 1;
313 if( iter_next != tofDigiCol->end() ) {
314 unsigned int idenNext_value = ((*iter_next)->identify()).get_value();
315 if( iden_value == idenNext_value )
continue;
324 std::vector<PmtData*> pmtDataVec;
325 std::vector<Tdc*>::iterator iter_t = timeVec.begin();
326 for( ; iter_t != timeVec.end(); iter_t++ ) {
327 int tclock = (*iter_t)->clock();
331 std::vector<Adc*>::iterator iter_q = chargeVec.begin();
332 for( ; iter_q != chargeVec.end(); iter_q++ ) {
333 int qclock = (*iter_q)->clock();
335 if(
abs(tclock-qclock)<2 ) {
336 if( ( pmt->
quality() & 0x2 ) != 0 ) {
337 if( (*iter_q)->value() > pmt->
adc() ) {
349 pmtDataVec.push_back( pmt );
354 std::vector<Adc*>::iterator iter_q = chargeVec.begin();
355 for( ; iter_q != chargeVec.end(); iter_q++ ) {
357 if( (*iter_q)->times() != -1 )
365 pmtDataVec.push_back( pmt );
374 unsigned int iden_value_key = (iden_value & 0xfffffffe );
375 if( ( barrel_ec == 0 ) || ( barrel_ec == 2 ) ) {
376 std::vector<PmtData*>::iterator iter_pmt = pmtDataVec.begin();
377 for( ; iter_pmt != pmtDataVec.end(); iter_pmt++ ) {
382 if( barrel_ec==2 &&
id==42 ) {
385 iden_value_key = iden91;
388 if( barrel_ec==2 &&
id==43 ) {
390 iden_value_key = iden90;
399 m_tofDataMap.insert( make_pair( iden_value_key, tof ) );
402 else if( barrel_ec == 1 ) {
403 unsigned int count = m_tofDataMap.count( iden_value_key );
405 std::vector<PmtData*>::iterator iter_pmt = pmtDataVec.begin();
406 for( ; iter_pmt != pmtDataVec.end(); iter_pmt++ ) {
417 m_tofDataMap.insert( make_pair( iden_value_key, tof ) );
421 pair< IterTofDataMap, IterTofDataMap > range = m_tofDataMap.equal_range( iden_value_key );
422 std::vector<PmtData*>::iterator iter_pmt = pmtDataVec.begin();
423 for( ; iter_pmt != pmtDataVec.end(); iter_pmt++ ) {
426 for(
unsigned int tofDataNumber = 0; tofDataNumber < count; tofDataNumber++,
iter++ ) {
427 bool matched =
false;
429 if( ( ( (*iter_pmt)->quality() & 0x1 ) != 0 ) && ( ( ((*iter).second)->quality() & 0x1 ) != 0 ) ) {
430 double time1 = (*iter_pmt)->tdc();
431 double time2 = ((*iter).second)->tdc2();
434 else if( ( ( (*iter_pmt)->quality() & 0x1 ) == 0 ) && ( ( (*iter_pmt)->quality() & 0x2 ) != 0 ) && ( ( ((*iter).second)->quality() & 0x1 ) != 0 ) ) {
435 double time1 = (*iter_pmt)->qclock();
436 double time2 = ((*iter).second)->tclock2();
437 double time3 = ((*iter).second)->qclock2();
440 else if( ( ( (*iter_pmt)->quality() & 0x1 ) != 0 ) && ( ( ((*iter).second)->quality() & 0x1 ) == 0 ) && ( ( ((*iter).second)->quality() & 0x2 ) != 0 ) ) {
441 double time1 = (*iter_pmt)->tclock();
442 double time2 = (*iter_pmt)->qclock();
443 double time3 = ((*iter).second)->qclock2();
446 else if( ( ( (*iter_pmt)->quality() & 0x1 ) == 0 ) && ( ( (*iter_pmt)->quality() & 0x2 ) != 0 ) && ( ( ((*iter).second)->quality() & 0x1 ) == 0 ) && ( ( ((*iter).second)->quality() & 0x2 ) != 0 ) ) {
447 double time1 = (*iter_pmt)->qclock();
448 double time2 = ((*iter).second)->qclock2();
454 if( ( ( (*iter).second)->quality() & 0xc ) == 0 ) {
455 ((*iter).second)->setForward( (*iter_pmt) );
463 m_tofDataMap.insert( make_pair( iden_value_key, tof ) );
469 if( ( ( (*iter_pmt)->quality() & 0x1 ) != 0 ) && ( ( ((*iter).second)->quality() & 0x4 ) != 0 ) ) {
470 double time1 = (*iter_pmt)->tdc();
471 double time2 = ((*iter).second)->tdc1();
474 else if( ( ( (*iter_pmt)->quality() & 0x1 ) == 0 ) && ( ( (*iter_pmt)->quality() & 0x2 ) != 0 ) && ( ( ((*iter).second)->quality() & 0x4 ) != 0 ) ) {
475 double time1 = (*iter_pmt)->qclock();
476 double time2 = ((*iter).second)->tclock1();
477 double time3 = ((*iter).second)->qclock1();
480 else if( ( ( (*iter_pmt)->quality() & 0x1 ) != 0 ) && ( ( ((*iter).second)->quality() & 0x4 ) == 0 ) && ( ( ((*iter).second)->quality() & 0x8 ) != 0 ) ) {
481 double time1 = (*iter_pmt)->tclock();
482 double time2 = (*iter_pmt)->qclock();
483 double time3 = ((*iter).second)->qclock1();
486 else if( ( ( (*iter_pmt)->quality() & 0x1 ) == 0 ) && ( ( (*iter_pmt)->quality() & 0x2 ) != 0 ) && ( ( ((*iter).second)->quality() & 0x4 ) == 0 ) && ( ( ((*iter).second)->quality() & 0x8 ) != 0 ) ) {
487 double time1 = (*iter_pmt)->qclock();
488 double time2 = ((*iter).second)->qclock1();
494 if( ( ( (*iter).second)->quality() & 0x3 ) == 0 ) {
495 ((*iter).second)->setBackward( (*iter_pmt) );
496 if( ( ( ((*iter).second)->quality() & 0x5 )==0x5 ) || ( ( ( ((*iter).second)->quality() & 0x5 )==0x4 ) && ( ((*iter).second)->ttimes1()==1 ) ) || ( ( ( ((*iter).second)->quality() & 0x5 )==0x1 ) && ( ((*iter).second)->ttimes2()==1 ) ) ) {
497 ((*iter).second)->setTMatched(
true );
500 ((*iter).second)->setTMatched(
false );
506 tof->
setForward( ((*iter).second)->forward() );
508 if( ( ( tof->
quality() & 0x5 )==0x5 ) || ( ( ( tof->
quality() & 0x5 )==0x4 ) && ( tof->
ttimes1()==1 ) ) || ( ( ( tof->
quality() & 0x5 )==0x1 ) && ( tof->
ttimes2()==1 ) ) ) {
514 m_tofDataMap.insert( make_pair( iden_value_key, tof ) );
529 m_tofDataMap.insert( make_pair( iden_value_key, tof ) );
540 else if(barrel_ec_help==3 || barrel_ec_help==4 || barrel_ec_help==5 || barrel_ec_help==6)
555 unsigned int iden_value = iden.
get_value();
562 unsigned int tdcChannel = (*iter)->getTimeChannel();
563 unsigned int tdc2Channel = (*iter)->getChargeChannel();
567 unsigned int pulse_length_channel_without_correction = tdc2Channel-tdcChannel;
570 if(correction_ta<0)
continue;
572 time_of_flight=time_of_flight - correction_ta/1000.;
582 adc->
setValue_mrpc( pulse_length_channel_without_correction,(tdcChannel & 0x07e000) );
610 unsigned int iden_value_key_mrpc = (iden_value & 0xffffffff );
620 m_tofDataMap.insert( make_pair( iden_value_key_mrpc, tof ) );
643 log << MSG::INFO <<
"TofRawDataProvider::tofDataMapOnlineMode()" << endreq;
645 if( ! m_tofDataMapOnline.empty() ) {
648 for( ;
iter != m_tofDataMapOnline.end();
iter++ ) {
649 delete (*iter).second;
651 m_tofDataMapOnline.clear();
653 else return m_tofDataMapOnline;
656 std::string evtDataSvc_name(
"EventDataSvc");
657 if(isGaudiThreaded(
m_name)){
658 evtDataSvc_name += getGaudiThreadIDfromName(
m_name);
662 IDataProviderSvc* eventSvc;
663 StatusCode sc =
m_svcLocator->service( evtDataSvc_name.c_str(), eventSvc,
true );
664 if( !sc.isSuccess() ) {
665 log << MSG::FATAL <<
"TofRawDataProvider::tofDataMapOnlineMode(): ERROR Could not load EventDataSvc" << endreq;
666 return m_tofDataMapOnline;
670 SmartDataPtr<TofDigiCol> tofDigiCol(eventSvc,
"/Event/Digi/TofDigiCol");
672 log << MSG::WARNING <<
"TofRawDataProvider::tofDataMapOnlineMode(): Could not find Tof Digi Data!" << endreq;
673 return m_tofDataMapOnline;
676 TofDigiCol::iterator
iter = tofDigiCol->begin();
677 for( ;
iter != tofDigiCol->end();
iter++ ) {
678 unsigned int overflow = (*iter)->getOverflow();
679 if( ( overflow & 0xfe000000 ) == 0xfe000000 )
continue;
683 bool noT = ( ( overflow & 0x10 ) != 0 );
689 unsigned int iden_value = iden.
get_value();
693 if( ( barrel_ec != 1 ) && ( end == 1 ) )
continue;
694 if( ( barrel_ec != 1 ) && (
id == 48 ) )
continue;
696 unsigned int tdcChannel = (*iter)->getTimeChannel();
697 if( tdcChannel == 0x7fffffff )
continue;
704 unsigned int iden_value_key = ( iden_value & 0xfffffffe );
706 if( barrel_ec == 0 || barrel_ec == 2 ) {
710 m_tofDataMapOnline.insert( make_pair( iden_value_key, tof ) );
712 else if( barrel_ec == 1 ) {
713 unsigned int count = m_tofDataMapOnline.count( iden_value_key );
724 m_tofDataMapOnline.insert( make_pair( iden_value_key, tof ) );
728 pair< IterTofDataMap, IterTofDataMap > range = m_tofDataMapOnline.equal_range( iden_value_key );
730 for(
unsigned int i=0; i<count; i++,
iter++ ) {
731 if( ( end == 0 ) && ( ( ( (*iter).second)->quality() & 0x1 ) != 0 ) ) {
732 double time1 = pmt->
tdc();
733 double time2 = ((*iter).second)->tdc2();
736 if( ( ( (*iter).second)->quality() & 0x4 ) == 0 ) {
737 ((*iter).second)->setForward( pmt );
744 m_tofDataMapOnline.insert( make_pair( iden_value_key, tof ) );
748 else if( ( end == 1 ) && ( ( ((*iter).second)->quality() & 0x4 ) != 0 ) ) {
749 double time1 = ((*iter).second)->tdc1();
750 double time2 = pmt->
tdc();
754 if( ( ( (*iter).second)->quality() & 0x1 ) == 0 ) {
755 ((*iter).second)->setBackward( pmt );
760 tof->
setForward( ((*iter).second)->forward() );
762 m_tofDataMapOnline.insert( make_pair( iden_value_key, tof ) );
776 m_tofDataMapOnline.insert( make_pair( iden_value_key, tof ) );
782 return m_tofDataMapOnline;