Jpp  18.0.0-rc.2
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JDAQTimesliceSelector.cc
Go to the documentation of this file.
1 
2 #include <string>
3 #include <iostream>
4 #include <iomanip>
5 #include <limits>
6 
7 #include "TROOT.h"
8 #include "TFile.h"
9 #include "TH1D.h"
10 
11 #include "JDAQ/JDAQTimesliceIO.hh"
13 
15 #include "JSupport/JSupport.hh"
16 
18 #include "JLang/JTypeSelector.hh"
20 #include "JLang/JPipe.hh"
21 #include "JLang/JObjectOutput.hh"
22 
23 #include "Jeep/JParser.hh"
24 #include "Jeep/JMessage.hh"
25 
26 
27 using namespace std;
28 using namespace JPP;
29 using namespace KM3NETDAQ;
30 
31 
32 /**
33  * Command line options.
34  */
36 int debug;
37 string outputFile;
38 
39 
40 /**
41  * Example class for data analysis.
42  */
43 struct JAnalysis :
44  public JObjectOutput<JDAQTimeslice>
45 {
46  /**
47  * Constructor.
48  */
50  //
51  // Book histograms
52  //
53  h0("h0", NULL, numeric_limits<JDAQHit::JPMT_t>::max(), -0.5, numeric_limits<JDAQHit::JPMT_t>::max() - 0.5),
54  h1("h1", NULL, numeric_limits<JDAQHit::JTOT_t>::max(), -0.5, numeric_limits<JDAQHit::JTOT_t>::max() - 0.5),
55  h2("h2", NULL, 100, -0.5, getFrameTime() + 0.5),
56  //
57  counter(0)
58  {}
59 
60 
61  /**
62  * Destructior.
63  */
65  {
66  STATUS(endl);
67 
68  // save histograms
69 
70  TFile out(outputFile.c_str(), "recreate");
71 
72  out << h0 << h1 << h2;
73 
74  out.Write();
75  out.Close();
76  }
77 
78 
79  /**
80  * Process data.
81  *
82  * \param timeslice timeslice
83  * \return true
84  */
85  virtual bool put(const JDAQTimeslice& timeslice)
86  {
87  STATUS("event: " << setw(10) << ++counter << '\r'); DEBUG(endl);
88 
89  for (JDAQTimeslice::const_iterator frame = timeslice.begin(); frame != timeslice.end(); ++frame) {
90  for (JDAQSuperFrame::const_iterator hit = frame->begin(); hit != frame->end(); ++hit) {
91 
92  if (JDAQPMTIdentifier::compare(PMT, JDAQPMTIdentifier(frame->getModuleID(), hit->getPMT()))) {
93  h0.Fill(hit->getPMT());
94  h1.Fill(hit->getToT());
95  h2.Fill(hit->getT());
96  }
97  }
98  }
99 
100  return true;
101  }
102 
103  TH1D h0;
104  TH1D h1;
105  TH1D h2;
106 
108 };
109 
110 
111 /**
112  * \file
113  *
114  * Example program to histogram KM3NETDAQ::JDAQTimeslice.
115  * \author mdejong
116  */
117 int main(int argc, char **argv)
118 {
119  using namespace std;
120  using namespace JPP;
121  using namespace KM3NETDAQ;
122 
124  JLimit_t& numberOfEvents = inputFile.getLimit();
125  JROOTClassSelector selector;
126 
127  try {
128 
129  JParser<> zap("Example program to histogram timeslice data.");
130 
131  zap['f'] = make_field(inputFile);
132  zap['o'] = make_field(outputFile) = "timeslice.root";
133  zap['n'] = make_field(numberOfEvents) = JLimit::max();
134  zap['P'] = make_field(PMT) = JDAQPMTIdentifier(-1, -1);
135  zap['C'] = make_field(selector) = getROOTClassSelection<JDAQTimesliceTypes_t>();
136  zap['d'] = make_field(debug) = 1;
137 
138  zap(argc, argv);
139  }
140  catch(const exception& error) {
141  FATAL(error.what() << endl);
142  }
143 
144 
145  JAnalysis analysis;
146 
147  inputFile | JValve<JDAQTimesliceTypes_t>(selector) | JType<JDAQTimeslice>() | analysis;
148 }
Utility class to parse command line options.
Definition: JParser.hh:1514
int main(int argc, char *argv[])
Definition: Main.cc:15
ROOT TTree parameter settings of various packages.
static const JPBS_t PMT(3, 4, 2, 3)
PBS of photo-multiplier tube (PMT)
#define STATUS(A)
Definition: JMessage.hh:63
Auxiliary class to select ROOT class based on class name.
Long64_t counter_type
Type definition for counter.
Auxiliary class for a type holder.
Definition: JType.hh:19
string outputFile
Auxiliary class for selection of data type.
Auxiliary class for defining the range of iterations of objects.
Definition: JLimit.hh:41
Example class for data analysis.
Hit data structure.
Definition: JDAQHit.hh:34
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1989
double getFrameTime()
Get frame time duration.
Definition: JDAQClock.hh:162
Implementation of pipe operation for object iterators.
~JAnalysis()
Destructior.
counter_type counter
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...
General purpose class for object reading from a list of file names.
Utility class to parse command line options.
JAnalysis()
Constructor.
const JLimit & getLimit() const
Get limit.
Definition: JLimit.hh:84
int debug
debug level
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62
virtual bool put(const JDAQTimeslice &timeslice)
Process data.