Jpp  18.6.0-rc.1
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JUTCProfile.cc
Go to the documentation of this file.
1 
2 #include <string>
3 #include <iostream>
4 #include <iomanip>
5 
6 #include "TROOT.h"
7 #include "TFile.h"
8 #include "TH1D.h"
9 
10 #include "JDAQ/JDAQTimesliceIO.hh"
11 #include "JDAQ/JDAQEvaluator.hh"
13 
15 #include "JSupport/JTreeScanner.hh"
16 #include "JSupport/JSupport.hh"
17 
18 #include "Jeep/JParser.hh"
19 #include "Jeep/JMessage.hh"
20 
21 
22 namespace {
23 
25 
26  typedef long long int JUTCTime_t;
27 
28  /**
29  * Get time.
30  *
31  * \param utc UTC time
32  * \return time [ns]
33  */
34  inline JUTCTime_t getTime(const JDAQUTCExtended& utc)
35  {
36  JUTCTime_t t0 = utc.getUTCseconds();
37  JUTCTime_t t1 = utc.getUTC16nanosecondcycles();
38 
39  t0 *= 1000000000;
40  t1 *= 16;
41 
42  return t0 + t1;
43  }
44 
45 
46  /**
47  * Get time.
48  *
49  * \param frame_index frame index
50  * \return time [ns]
51  */
52  inline JUTCTime_t getTime(const int frame_index)
53  {
55 
56  return (JUTCTime_t) (frame_index * getFrameTime());
57  }
58 }
59 
60 
61 /**
62  * \file
63  *
64  * Example program to histogram UTC profiles.
65  * \author mdejong
66  */
67 int main(int argc, char **argv)
68 {
69  using namespace std;
70  using namespace JPP;
71  using namespace KM3NETDAQ;
72 
73  JMultipleFileScanner<> inputFile;
74  JLimit_t& numberOfEvents = inputFile.getLimit();
75  string outputFile;
76  int debug;
77 
78  try {
79 
80  JParser<> zap("Example program to histogram UTC profiles.");
81 
82  zap['f'] = make_field(inputFile);
83  zap['o'] = make_field(outputFile) = "profile.root";
84  zap['n'] = make_field(numberOfEvents) = JLimit::max();
85  zap['d'] = make_field(debug) = 1;
86 
87  zap(argc, argv);
88  }
89  catch(const exception& error) {
90  FATAL(error.what() << endl);
91  }
92 
93 
95 
96  counter_type N = in.getEntries();
97 
98  if (N > numberOfEvents.getUpperLimit()) {
99  N = numberOfEvents.getUpperLimit();
100  }
101 
102  if (N == 0) {
103  FATAL("Number of time slices in file(s) " << N << endl);
104  }
105 
106  const Long64_t NX = in.getEntry(N-1)->getFrameIndex() - in.getEntry(0)->getFrameIndex() + 1;
107  const Double_t xmin = (Double_t) in.getEntry( 0 )->getFrameIndex() - 0.5;
108  const Double_t xmax = (Double_t) in.getEntry(N-1)->getFrameIndex() + 0.5;
109 
110 
111  TFile out(outputFile.c_str(), "recreate");
112 
113  TH1D h0("UTC", NULL, NX, xmin, xmax);
114  TH1D h1("!utc", NULL, NX, xmin, xmax);
115  TH1D h2("dt", NULL, 1001, -500.5, +500.5);
116 
117 
118  const int frame_index = in.getEntry(0)->getFrameIndex();
119  const JUTCTime_t t0 = getTime(in.getEntry(0)->getTimesliceStart());
120 
121  for (in.rewind(); in.hasNext() && in.getCounter() != numberOfEvents.getUpperLimit(); ) {
122 
123  STATUS("event: " << setw(10) << in.getCounter() << '\r'); DEBUG(endl);
124 
125  JDAQTimeslice* timeslice = in.next();
126 
127  const Double_t x = timeslice->getFrameIndex();
128  const JDAQUTCExtended utc = timeslice->getTimesliceStart();
129 
130  const JUTCTime_t t1 = t0 + getTime(timeslice->getFrameIndex() - frame_index);
131 
132  h0.Fill(x, getTime(utc) - t0);
133 
134  for (JDAQTimeslice::const_iterator frame = timeslice->begin(); frame != timeslice->end(); ++frame) {
135 
136  if (utc != frame->getTimesliceStart()) {
137  h1.Fill(x);
138  }
139 
140  h2.Fill(getTime(frame->getTimesliceStart()) - t1);
141  }
142  }
143  STATUS(endl);
144 
145  out.Write();
146  out.Close();
147 }
const double xmax
Definition: JQuadrature.cc:24
Utility class to parse command line options.
Definition: JParser.hh:1711
uint32_t getUTC16nanosecondcycles() const
Get minor time.
int main(int argc, char *argv[])
Definition: Main.cc:15
JDAQUTCExtended getTimesliceStart() const
Get start of timeslice.
ROOT TTree parameter settings of various packages.
#define STATUS(A)
Definition: JMessage.hh:63
Long64_t counter_type
Type definition for counter.
double getTime(const Hit &hit)
Get true time of hit.
string outputFile
Data structure for UTC time.
Template definition for direct access of elements in ROOT TChain.
int getFrameIndex() const
Get frame index.
Auxiliary class for defining the range of iterations of objects.
Definition: JLimit.hh:41
uint32_t getUTCseconds() const
Get major time.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:2158
double getFrameTime()
Get frame time duration.
Definition: JDAQClock.hh:162
Data time slice.
General purpose messaging.
#define FATAL(A)
Definition: JMessage.hh:67
Scanning of objects from multiple files according a format that follows from the extension of each fi...
const double xmin
Definition: JQuadrature.cc:23
then usage $script< input file >[option[primary[working directory]]] nWhere option can be N
Definition: JMuonPostfit.sh:40
then fatal The output file must have the wildcard in the e g root fi eval JPrintDetector a $DETECTOR O IDENTIFIER eval JPrintDetector a $DETECTOR O SUMMARY JAcoustics sh $DETECTOR_ID source JAcousticsToolkit sh CHECK_EXIT_CODE typeset A EMITTERS get_tripods $WORKDIR tripod txt EMITTERS get_transmitters $WORKDIR transmitter txt EMITTERS for EMITTER in
Definition: JCanberra.sh:48
Utility class to parse command line options.
const JLimit & getLimit() const
Get limit.
Definition: JLimit.hh:84
int debug
debug level
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62