Jpp  17.0.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 
94  cout.tie(&cerr);
95 
97 
98  counter_type N = in.getEntries();
99 
100  if (N > numberOfEvents.getUpperLimit()) {
101  N = numberOfEvents.getUpperLimit();
102  }
103 
104  if (N == 0) {
105  FATAL("Number of time slices in file(s) " << N << endl);
106  }
107 
108  const Long64_t NX = in.getEntry(N-1)->getFrameIndex() - in.getEntry(0)->getFrameIndex() + 1;
109  const Double_t xmin = (Double_t) in.getEntry( 0 )->getFrameIndex() - 0.5;
110  const Double_t xmax = (Double_t) in.getEntry(N-1)->getFrameIndex() + 0.5;
111 
112 
113  TFile out(outputFile.c_str(), "recreate");
114 
115  TH1D h0("UTC", NULL, NX, xmin, xmax);
116  TH1D h1("!utc", NULL, NX, xmin, xmax);
117  TH1D h2("dt", NULL, 1001, -500.5, +500.5);
118 
119 
120  const int frame_index = in.getEntry(0)->getFrameIndex();
121  const JUTCTime_t t0 = getTime(in.getEntry(0)->getTimesliceStart());
122 
123  for (in.rewind(); in.hasNext() && in.getCounter() != numberOfEvents.getUpperLimit(); ) {
124 
125  STATUS("event: " << setw(10) << in.getCounter() << '\r'); DEBUG(endl);
126 
127  JDAQTimeslice* timeslice = in.next();
128 
129  const Double_t x = timeslice->getFrameIndex();
130  const JDAQUTCExtended utc = timeslice->getTimesliceStart();
131 
132  const JUTCTime_t t1 = t0 + getTime(timeslice->getFrameIndex() - frame_index);
133 
134  h0.Fill(x, getTime(utc) - t0);
135 
136  for (JDAQTimeslice::const_iterator frame = timeslice->begin(); frame != timeslice->end(); ++frame) {
137 
138  if (utc != frame->getTimesliceStart()) {
139  h1.Fill(x);
140  }
141 
142  h2.Fill(getTime(frame->getTimesliceStart()) - t1);
143  }
144  }
145  STATUS(endl);
146 
147  out.Write();
148  out.Close();
149 }
const double xmax
Definition: JQuadrature.cc:24
Utility class to parse command line options.
Definition: JParser.hh:1500
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
then JShowerPostfit f $INPUT_FILE o $OUTPUT_FILE N
then for HISTOGRAM in h0 h1
Definition: JMatrixNZ.sh:71
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
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1961
double getFrameTime()
Get frame time duration.
Definition: JDAQClock.hh:162
JUINT32_t getUTC16nanosecondcycles() const
Get time.
Data time slice.
int debug
debug level
Definition: JSirene.cc:66
JUINT32_t getUTCseconds() const
Get time.
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
Utility class to parse command line options.
const JLimit & getLimit() const
Get limit.
Definition: JLimit.hh:73
then fatal Wrong number of arguments fi set_variable DETECTOR $argv[1] set_variable INPUT_FILE $argv[2] 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:46
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62