/search.css" rel="stylesheet" type="text/css"/> /search.js">
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

In This Package:

Public Member Functions | Protected Attributes | Private Attributes
LiveTimeAlg Class Reference

#include <LiveTimeAlg.h>

Inheritance diagram for LiveTimeAlg:
Inheritance graph
[legend]
Collaboration diagram for LiveTimeAlg:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 LiveTimeAlg (const std::string &name)
virtual ~LiveTimeAlg ()
virtual bool initialize ()
virtual bool execute ()
virtual bool finalize ()
const std::string & name ()
SvcBaseservice (const std::string &name)
TOutputSvcntupleSvc ()
bool setOption (const std::string &option, Type &var)

Protected Attributes

std::string m_name

Private Attributes

PhyEventBufm_buffer
LiveTimeSvcm_liveTimeSvc
PhyEventm_lastEvt
TTimeStamp m_beginTime
TTimeStamp m_endTime
double m_timeGap
MuonVetom_muonVeto
int m_timeBin
double m_timeGapInCurBin

Detailed Description

Definition at line 11 of file LiveTimeAlg.h.


Constructor & Destructor Documentation

LiveTimeAlg::LiveTimeAlg ( const std::string &  name)

Definition at line 11 of file LiveTimeAlg.cc.

virtual LiveTimeAlg::~LiveTimeAlg ( ) [inline, virtual]

Definition at line 15 of file LiveTimeAlg.h.

{}

Member Function Documentation

bool LiveTimeAlg::initialize ( ) [virtual]

Implements AlgBase.

Definition at line 16 of file LiveTimeAlg.cc.

{
  m_buffer = dynamic_cast<PhyEventBuf*>(service("Cycler"));
  m_liveTimeSvc = dynamic_cast<LiveTimeSvc*>(service("LiveTimeSvc"));
  if(!m_liveTimeSvc) {
    LogError << "Can't get LiveTimeSvc." << endl;
    return false;
  }
  m_liveTimeSvc->initHist();
  m_muonVeto = MuonVeto::instance();

  ntupleSvc()->attach("FILE1/LiveTime/",m_liveTimeSvc->hDaqTime());
  for(int det=1;det<=GlobalVar::NumADs;det++) {
    ntupleSvc()->attach("FILE1/LiveTime/",m_liveTimeSvc->hLiveTime(det));
  }

  return true;
}
bool LiveTimeAlg::execute ( ) [virtual]

Implements AlgBase.

Definition at line 48 of file LiveTimeAlg.cc.

{
  PhyEvent *event = m_buffer->curEvt();

  if(!m_lastEvt) {  // This is the first event
    m_lastEvt = event->GrabInstance();
    m_beginTime = event->m_trigTime;
    m_timeBin = m_liveTimeSvc->bin(event->m_trigTime);
    m_timeGapInCurBin = m_beginTime - m_liveTimeSvc->startTime(m_timeBin);
    return true;
  } else {
    m_endTime = event->m_trigTime;
  }

  // caculate daq time in each time bin
  int bin = m_liveTimeSvc->bin(event->m_trigTime);
  double binWidth = m_liveTimeSvc->binWidth();
  if(bin > m_timeBin) { // a new time bin
    double timeGap = m_liveTimeSvc->endTime(m_timeBin) - m_lastEvt->m_trigTime;
    m_timeGapInCurBin += timeGap;
    m_liveTimeSvc->setDaqTimePerBin(m_timeBin,binWidth-m_timeGapInCurBin);
    LogDebug << "bin:" << bin
      << ", m_timeBin: " << m_timeBin
      << ", m_timeGapInCurBin: " << m_timeGapInCurBin
      << endl;
    m_timeGapInCurBin = 0.;
    m_timeBin = bin;
  }

  double dt = event->m_trigTime - m_lastEvt->m_trigTime;
  LogDebug << "Time interval: " << dt << " second." << endl;
  if(dt < 0) {
    LogWarn << "Find wrong event time order." << endl;
    cout << "Current event: " << endl;
    cout << "------entry=" << event->m_entry
      << ", fileNum=" << event->m_fileNum
      << ", local entry=" << event->m_localEntry
      << ", trigtime=" << event->m_trigTime
      << ", det=" << event->m_det
      << endl;
    cout << "Previous event: " << endl;
    cout << "------entry=" << m_lastEvt->m_entry
      << ", fileNum=" << m_lastEvt->m_fileNum
      << ", local entry=" << m_lastEvt->m_localEntry
      << ", trigtime=" << m_lastEvt->m_trigTime
      << ", det=" << m_lastEvt->m_det
      << endl;
  }

  if(dt > m_liveTimeSvc->evtTimeGap()) {
    LogWarn << "Find " << dt << " second event time gap." << endl;
    cout << "Current event: " << endl;
    cout << "------entry=" << event->m_entry
      << ", fileNum=" << event->m_fileNum
      << ", local entry=" << event->m_localEntry
      << ", trigtime=" << event->m_trigTime
      << ", det=" << event->m_det
      << endl;
    cout << "Previous event: " << endl;
    cout << "------entry=" << m_lastEvt->m_entry
      << ", fileNum=" << m_lastEvt->m_fileNum
      << ", local entry=" << m_lastEvt->m_localEntry
      << ", trigtime=" << m_lastEvt->m_trigTime
      << ", det=" << m_lastEvt->m_det
      << endl;
    m_timeGap += dt;
    double timeGap = event->m_trigTime - m_liveTimeSvc->startTime(m_timeBin);
    m_timeGapInCurBin += dt < timeGap ? dt : timeGap;
  }

  m_lastEvt->ReleaseInstance();
  m_lastEvt = event->GrabInstance();

  m_liveTimeSvc->setWallTime(m_endTime - m_beginTime);
  m_liveTimeSvc->setDaqTime((m_endTime - m_beginTime) - m_timeGap);
  //for(int det=1;det<=GlobalVar::NumADs;det++) {
  //  m_liveTimeSvc->setLiveTime(det, (m_endTime - m_beginTime) 
  //      - m_timeGap - m_muonVeto->m_deadTime[det-1]);
  //}

  return true;
}
bool LiveTimeAlg::finalize ( ) [virtual]

Implements AlgBase.

Definition at line 35 of file LiveTimeAlg.cc.

{
  // set daq time for the last time bin
  m_liveTimeSvc->setDaqTimePerBin(m_timeBin,m_endTime-m_liveTimeSvc->startTime(m_timeBin)-m_timeGapInCurBin);

  // Fill DAQ time histogram
  //for(int i=0;i<m_liveTimeSvc->nBins();i++) {
  //  m_liveTimeSvc->hDaqTime()->Fill(m_liveTimeSvc->startTime(i) + m_liveTimeSvc->binWidth()/2,
  //      m_liveTimeSvc->daqTimePerBin(i));
  //}
  return true;
}

Member Data Documentation

Definition at line 23 of file LiveTimeAlg.h.

Definition at line 24 of file LiveTimeAlg.h.

Definition at line 25 of file LiveTimeAlg.h.

TTimeStamp LiveTimeAlg::m_beginTime [private]

Definition at line 27 of file LiveTimeAlg.h.

TTimeStamp LiveTimeAlg::m_endTime [private]

Definition at line 28 of file LiveTimeAlg.h.

double LiveTimeAlg::m_timeGap [private]

Definition at line 29 of file LiveTimeAlg.h.

Definition at line 31 of file LiveTimeAlg.h.

int LiveTimeAlg::m_timeBin [private]

Definition at line 33 of file LiveTimeAlg.h.

Definition at line 34 of file LiveTimeAlg.h.


The documentation for this class was generated from the following files:
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Fri May 16 2014 09:50:49 for Algorithms by doxygen 1.7.4