/search.css" rel="stylesheet" type="text/css"/> /search.js">
00001 #include "Algorithms/LiveTimeAlg.h" 00002 #include "MuonVeto/MuonVeto.h" 00003 #include "LafKernel/GlobalVar.h" 00004 #include "LiveTimeSvc/LiveTimeSvc.h" 00005 #include "TTimeStamp.h" 00006 #include "TH1F.h" 00007 #include <iostream> 00008 00009 using namespace std; 00010 00011 LiveTimeAlg::LiveTimeAlg(const std::string& name) 00012 : AlgBase(name),m_lastEvt(0),m_timeGap(0.),m_timeBin(-1) 00013 { 00014 } 00015 00016 bool LiveTimeAlg::initialize() 00017 { 00018 m_buffer = dynamic_cast<PhyEventBuf*>(service("Cycler")); 00019 m_liveTimeSvc = dynamic_cast<LiveTimeSvc*>(service("LiveTimeSvc")); 00020 if(!m_liveTimeSvc) { 00021 LogError << "Can't get LiveTimeSvc." << endl; 00022 return false; 00023 } 00024 m_liveTimeSvc->initHist(); 00025 m_muonVeto = MuonVeto::instance(); 00026 00027 ntupleSvc()->attach("FILE1/LiveTime/",m_liveTimeSvc->hDaqTime()); 00028 for(int det=1;det<=GlobalVar::NumADs;det++) { 00029 ntupleSvc()->attach("FILE1/LiveTime/",m_liveTimeSvc->hLiveTime(det)); 00030 } 00031 00032 return true; 00033 } 00034 00035 bool LiveTimeAlg::finalize() 00036 { 00037 // set daq time for the last time bin 00038 m_liveTimeSvc->setDaqTimePerBin(m_timeBin,m_endTime-m_liveTimeSvc->startTime(m_timeBin)-m_timeGapInCurBin); 00039 00040 // Fill DAQ time histogram 00041 //for(int i=0;i<m_liveTimeSvc->nBins();i++) { 00042 // m_liveTimeSvc->hDaqTime()->Fill(m_liveTimeSvc->startTime(i) + m_liveTimeSvc->binWidth()/2, 00043 // m_liveTimeSvc->daqTimePerBin(i)); 00044 //} 00045 return true; 00046 } 00047 00048 bool LiveTimeAlg::execute() 00049 { 00050 PhyEvent *event = m_buffer->curEvt(); 00051 00052 if(!m_lastEvt) { // This is the first event 00053 m_lastEvt = event->GrabInstance(); 00054 m_beginTime = event->m_trigTime; 00055 m_timeBin = m_liveTimeSvc->bin(event->m_trigTime); 00056 m_timeGapInCurBin = m_beginTime - m_liveTimeSvc->startTime(m_timeBin); 00057 return true; 00058 } else { 00059 m_endTime = event->m_trigTime; 00060 } 00061 00062 // caculate daq time in each time bin 00063 int bin = m_liveTimeSvc->bin(event->m_trigTime); 00064 double binWidth = m_liveTimeSvc->binWidth(); 00065 if(bin > m_timeBin) { // a new time bin 00066 double timeGap = m_liveTimeSvc->endTime(m_timeBin) - m_lastEvt->m_trigTime; 00067 m_timeGapInCurBin += timeGap; 00068 m_liveTimeSvc->setDaqTimePerBin(m_timeBin,binWidth-m_timeGapInCurBin); 00069 LogDebug << "bin:" << bin 00070 << ", m_timeBin: " << m_timeBin 00071 << ", m_timeGapInCurBin: " << m_timeGapInCurBin 00072 << endl; 00073 m_timeGapInCurBin = 0.; 00074 m_timeBin = bin; 00075 } 00076 00077 double dt = event->m_trigTime - m_lastEvt->m_trigTime; 00078 LogDebug << "Time interval: " << dt << " second." << endl; 00079 if(dt < 0) { 00080 LogWarn << "Find wrong event time order." << endl; 00081 cout << "Current event: " << endl; 00082 cout << "------entry=" << event->m_entry 00083 << ", fileNum=" << event->m_fileNum 00084 << ", local entry=" << event->m_localEntry 00085 << ", trigtime=" << event->m_trigTime 00086 << ", det=" << event->m_det 00087 << endl; 00088 cout << "Previous event: " << endl; 00089 cout << "------entry=" << m_lastEvt->m_entry 00090 << ", fileNum=" << m_lastEvt->m_fileNum 00091 << ", local entry=" << m_lastEvt->m_localEntry 00092 << ", trigtime=" << m_lastEvt->m_trigTime 00093 << ", det=" << m_lastEvt->m_det 00094 << endl; 00095 } 00096 00097 if(dt > m_liveTimeSvc->evtTimeGap()) { 00098 LogWarn << "Find " << dt << " second event time gap." << endl; 00099 cout << "Current event: " << endl; 00100 cout << "------entry=" << event->m_entry 00101 << ", fileNum=" << event->m_fileNum 00102 << ", local entry=" << event->m_localEntry 00103 << ", trigtime=" << event->m_trigTime 00104 << ", det=" << event->m_det 00105 << endl; 00106 cout << "Previous event: " << endl; 00107 cout << "------entry=" << m_lastEvt->m_entry 00108 << ", fileNum=" << m_lastEvt->m_fileNum 00109 << ", local entry=" << m_lastEvt->m_localEntry 00110 << ", trigtime=" << m_lastEvt->m_trigTime 00111 << ", det=" << m_lastEvt->m_det 00112 << endl; 00113 m_timeGap += dt; 00114 double timeGap = event->m_trigTime - m_liveTimeSvc->startTime(m_timeBin); 00115 m_timeGapInCurBin += dt < timeGap ? dt : timeGap; 00116 } 00117 00118 m_lastEvt->ReleaseInstance(); 00119 m_lastEvt = event->GrabInstance(); 00120 00121 m_liveTimeSvc->setWallTime(m_endTime - m_beginTime); 00122 m_liveTimeSvc->setDaqTime((m_endTime - m_beginTime) - m_timeGap); 00123 //for(int det=1;det<=GlobalVar::NumADs;det++) { 00124 // m_liveTimeSvc->setLiveTime(det, (m_endTime - m_beginTime) 00125 // - m_timeGap - m_muonVeto->m_deadTime[det-1]); 00126 //} 00127 00128 return true; 00129 }