Jpp
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  cout.tie(&cerr);
146 
147  JAnalysis analysis;
148 
149  inputFile | JValve<JDAQTimesliceTypes_t>(selector) | JType<JDAQTimeslice>() | analysis;
150 }
JTypeSelector.hh
JAnalysis::put
virtual bool put(const JDAQTimeslice &timeslice)
Process data.
Definition: JDAQTimesliceSelector.cc:85
debug
int debug
debug level
Definition: JDAQTimesliceSelector.cc:36
JSUPPORT::JLimit
Auxiliary class for defining the range of iterations of objects.
Definition: JLimit.hh:41
JLANG::JType
Auxiliary class for a type holder.
Definition: JType.hh:19
JMessage.hh
JROOTClassSelector.hh
KM3NETDAQ::JDAQTimeslice
Data time slice.
Definition: JDAQTimeslice.hh:30
JPARSER::JParser
Utility class to parse command line options.
Definition: JParser.hh:1493
JAnalysis
Example class for data analysis.
Definition: JDAQTimesliceSelector.cc:43
JAnalysis::h0
TH1D h0
Definition: JDAQTimesliceSelector.cc:103
PMT
JDAQPMTIdentifier PMT
Command line options.
Definition: JDAQTimesliceSelector.cc:35
KM3NETDAQ::getFrameTime
double getFrameTime()
Get frame time duration.
Definition: JDAQClock.hh:162
JSupport.hh
JPP
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Definition: JAAnetToolkit.hh:37
KM3NETDAQ::JDAQSuperFrame::const_iterator
JDAQFrame::const_iterator const_iterator
Definition: JDAQSuperFrame.hh:29
JDAQTimesliceIO.hh
JROOT::JROOTClassSelector
Auxiliary class to select ROOT class based on class name.
Definition: JROOTClassSelector.hh:32
JLANG::JValve
Auxiliary class for selection of data type.
Definition: JObjectIterator.hh:32
JObjectMultiplexer.hh
JMultipleFileScanner.hh
STATUS
#define STATUS(A)
Definition: JMessage.hh:63
JParser.hh
make_field
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1954
JAnalysis::~JAnalysis
~JAnalysis()
Destructior.
Definition: JDAQTimesliceSelector.cc:64
KM3NETDAQ::JDAQPMTIdentifier
PMT identifier.
Definition: JDAQPMTIdentifier.hh:20
JSUPPORT::JMultipleFileScanner
General purpose class for object reading from a list of file names.
Definition: JMultipleFileScanner.hh:167
JPipe.hh
DEBUG
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62
std
Definition: jaanetDictionary.h:36
KM3NETDAQ
KM3NeT DAQ data structures and auxiliaries.
Definition: DataQueue.cc:39
JAnalysis::JAnalysis
JAnalysis()
Constructor.
Definition: JDAQTimesliceSelector.cc:49
JDAQPMTIdentifier.hh
KM3NETDAQ::JDAQHit
Hit data structure.
Definition: JDAQHit.hh:34
JAnalysis::counter
counter_type counter
Definition: JDAQTimesliceSelector.cc:107
JAnalysis::h2
TH1D h2
Definition: JDAQTimesliceSelector.cc:105
FATAL
#define FATAL(A)
Definition: JMessage.hh:67
outputFile
string outputFile
Definition: JDAQTimesliceSelector.cc:37
JROOT::counter_type
Long64_t counter_type
Type definition for counter.
Definition: JCounter.hh:24
JAnalysis::h1
TH1D h1
Definition: JDAQTimesliceSelector.cc:104
main
int main(int argc, char **argv)
Definition: JDAQTimesliceSelector.cc:117
JObjectOutput.hh