#include #include #include #include "TROOT.h" #include "TFile.h" #include "TH1D.h" #include "JDAQ/JDAQTimesliceIO.hh" #include "JDAQ/JDAQEvaluator.hh" #include "km3net-dataformat/online/JDAQClock.hh" #include "JSupport/JMultipleFileScanner.hh" #include "JSupport/JTreeScanner.hh" #include "JSupport/JSupport.hh" #include "Jeep/JParser.hh" #include "Jeep/JMessage.hh" namespace { using KM3NETDAQ::JDAQUTCExtended; typedef long long int JUTCTime_t; /** * Get time. * * \param utc UTC time * \return time [ns] */ inline JUTCTime_t getTime(const JDAQUTCExtended& utc) { JUTCTime_t t0 = utc.getUTCseconds(); JUTCTime_t t1 = utc.getUTC16nanosecondcycles(); t0 *= 1000000000; t1 *= 16; return t0 + t1; } /** * Get time. * * \param frame_index frame index * \return time [ns] */ inline JUTCTime_t getTime(const int frame_index) { using KM3NETDAQ::getFrameTime; return (JUTCTime_t) (frame_index * getFrameTime()); } } /** * \file * * Example program to histogram UTC profiles. * \author mdejong */ int main(int argc, char **argv) { using namespace std; using namespace JPP; using namespace KM3NETDAQ; JMultipleFileScanner<> inputFile; JLimit_t& numberOfEvents = inputFile.getLimit(); string outputFile; int debug; try { JParser<> zap("Example program to histogram UTC profiles."); zap['f'] = make_field(inputFile); zap['o'] = make_field(outputFile) = "profile.root"; zap['n'] = make_field(numberOfEvents) = JLimit::max(); zap['d'] = make_field(debug) = 1; zap(argc, argv); } catch(const exception& error) { FATAL(error.what() << endl); } JTreeScanner in(inputFile); counter_type N = in.getEntries(); if (N > numberOfEvents.getUpperLimit()) { N = numberOfEvents.getUpperLimit(); } if (N == 0) { FATAL("Number of time slices in file(s) " << N << endl); } const Long64_t NX = in.getEntry(N-1)->getFrameIndex() - in.getEntry(0)->getFrameIndex() + 1; const Double_t xmin = (Double_t) in.getEntry( 0 )->getFrameIndex() - 0.5; const Double_t xmax = (Double_t) in.getEntry(N-1)->getFrameIndex() + 0.5; TFile out(outputFile.c_str(), "recreate"); TH1D h0("UTC", NULL, NX, xmin, xmax); TH1D h1("!utc", NULL, NX, xmin, xmax); TH1D h2("dt", NULL, 1001, -500.5, +500.5); const int frame_index = in.getEntry(0)->getFrameIndex(); const JUTCTime_t t0 = getTime(in.getEntry(0)->getTimesliceStart()); for (in.rewind(); in.hasNext() && in.getCounter() != numberOfEvents.getUpperLimit(); ) { STATUS("event: " << setw(10) << in.getCounter() << '\r'); DEBUG(endl); JDAQTimeslice* timeslice = in.next(); const Double_t x = timeslice->getFrameIndex(); const JDAQUTCExtended utc = timeslice->getTimesliceStart(); const JUTCTime_t t1 = t0 + getTime(timeslice->getFrameIndex() - frame_index); h0.Fill(x, getTime(utc) - t0); for (JDAQTimeslice::const_iterator frame = timeslice->begin(); frame != timeslice->end(); ++frame) { if (utc != frame->getTimesliceStart()) { h1.Fill(x); } h2.Fill(getTime(frame->getTimesliceStart()) - t1); } } STATUS(endl); out.Write(); out.Close(); }