Jpp  15.0.0-rc.2
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JDAQModuleRouter.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 #include "TH2D.h"
10 #include "TProfile2D.h"
11 
13 
15 #include "JDetector/JDetector.hh"
18 
20 #include "JSupport/JSupport.hh"
21 
22 #include "Jeep/JParser.hh"
23 #include "Jeep/JMessage.hh"
24 
25 
26 /**
27  * \file
28  *
29  * Example program to histogram string and floor rates.
30  * \author mdejong
31  */
32 int main(int argc, char **argv)
33 {
34  using namespace std;
35  using namespace JPP;
36  using namespace KM3NETDAQ;
37 
39  JLimit_t& numberOfEvents = inputFile.getLimit();
40  string outputFile;
41  string detectorFile;
42  int debug;
43 
44  try {
45 
46  JParser<> zap("Example program to histogram string and floor rates.");
47 
48  zap['f'] = make_field(inputFile);
49  zap['o'] = make_field(outputFile) = "router.root";
50  zap['a'] = make_field(detectorFile);
51  zap['n'] = make_field(numberOfEvents) = JLimit::max();
52  zap['d'] = make_field(debug) = 2;
53 
54  zap(argc, argv);
55  }
56  catch(const exception& error) {
57  FATAL(error.what() << endl);
58  }
59 
60 
61  cout.tie(&cerr);
62 
63 
65 
66  try {
67  load(detectorFile, detector);
68  }
69  catch(const JException& error) {
70  FATAL(error);
71  }
72 
73  const JModuleRouter router(detector);
74 
75 
76  typedef JTOOLS::JHashCollection<int> JHashCollection_t;
77 
78  const JHashCollection_t string(make_array(detector.begin(), detector.end(), &JModule::getString));
79  const JHashCollection_t floor (make_array(detector.begin(), detector.end(), &JModule::getFloor));
80 
81  TFile out(outputFile.c_str(), "recreate");
82 
83  TProfile2D h2("h2", NULL,
84  string.size(), -0.5, string.size() - 0.5,
85  floor .size(), -0.5, floor .size() - 0.5);
86 
87  for (Int_t i = 1; i <= h2.GetXaxis()->GetNbins(); ++i) {
88  h2.GetXaxis()->SetBinLabel(i, MAKE_CSTRING(string.at(i-1)));
89  }
90  for (Int_t i = 1; i <= h2.GetYaxis()->GetNbins(); ++i) {
91  h2.GetYaxis()->SetBinLabel(i, MAKE_CSTRING(floor .at(i-1)));
92  }
93 
94  while (inputFile.hasNext()) {
95 
96  STATUS("event: " << setw(10) << inputFile.getCounter() << '\r'); DEBUG(endl);
97 
98  const JDAQSummaryslice* summary = inputFile.next();
99 
100  for (JDAQSummaryslice::const_iterator frame = summary->begin(); frame != summary->end(); ++frame) {
101 
102  if (router.hasModule(frame->getModuleID())) {
103 
104  const JModule& module = router.getModule(frame->getModuleID());
105 
106  for (int pmt = 0; pmt != NUMBER_OF_PMTS; ++pmt) {
107  if (!frame->testHighRateVeto(pmt) && !frame->testFIFOStatus(pmt)) {
108  h2.Fill((double) string.getIndex(module.getString()),
109  (double) floor .getIndex(module.getFloor()),
110  frame->getRate(pmt) * 1.0e-3); // [kHz]
111  }
112  }
113  } else {
114  FATAL("JModuleRouter trying to access non existing identifier: " << frame->getModuleID());
115  }
116  }
117  }
118  STATUS(endl);
119 
120  out.Write();
121  out.Close();
122 }
Utility class to parse command line options.
Definition: JParser.hh:1500
General exception.
Definition: JException.hh:23
int main(int argc, char *argv[])
Definition: Main.cc:15
ROOT TTree parameter settings of various packages.
int getFloor() const
Get floor number.
Definition: JLocation.hh:145
const JModule & getModule(const JObjectID &id) const
Get module parameters.
Data structure for a composite optical module.
Definition: JModule.hh:68
#define STATUS(A)
Definition: JMessage.hh:63
Detector data structure.
Definition: JDetector.hh:89
Router for direct addressing of module data in detector data structure.
#define MAKE_CSTRING(A)
Make C-string.
Definition: JPrint.hh:151
General purpose class for a hash collection of unique elements.
string outputFile
Data structure for detector geometry and calibration.
Auxiliary class for defining the range of iterations of objects.
Definition: JLimit.hh:41
Detector file.
Definition: JHead.hh:196
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1961
const array_type< JValue_t > & make_array(const JValue_t(&array)[N])
Method to create array of values.
Definition: JVectorize.hh:54
int getIndex()
Get index for user I/O manipulation.
Definition: JManip.hh:26
int debug
debug level
Definition: JSirene.cc:63
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...
Direct access to module in detector data structure.
int getString() const
Get string number.
Definition: JLocation.hh:134
void load(const std::string &file_name, JDetector &detector)
Load detector from input file.
Utility class to parse command line options.
then usage $script< input_file >< detector_file > fi set_variable OUTPUT_DIR set_variable SELECTOR JDAQTimesliceL1 set_variable DEBUG case set_variable DEBUG
bool hasModule(const JObjectID &id) const
Has module.
const JLimit & getLimit() const
Get limit.
Definition: JLimit.hh:73
do set_variable DETECTOR_TXT $WORKDIR detector
static const int NUMBER_OF_PMTS
Total number of PMTs in module.
Definition: JDAQ.hh:26