Jpp  18.0.1-rc.1
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 
62 
63  try {
64  load(detectorFile, detector);
65  }
66  catch(const JException& error) {
67  FATAL(error);
68  }
69 
70  const JModuleRouter router(detector);
71 
72 
73  typedef JTOOLS::JHashCollection<int> JHashCollection_t;
74 
75  const JHashCollection_t string(make_array(detector.begin(), detector.end(), &JModule::getString));
76  const JHashCollection_t floor (make_array(detector.begin(), detector.end(), &JModule::getFloor));
77 
78  TFile out(outputFile.c_str(), "recreate");
79 
80  TProfile2D h2("h2", NULL,
81  string.size(), -0.5, string.size() - 0.5,
82  floor .size(), -0.5, floor .size() - 0.5);
83 
84  for (Int_t i = 1; i <= h2.GetXaxis()->GetNbins(); ++i) {
85  h2.GetXaxis()->SetBinLabel(i, MAKE_CSTRING(string.at(i-1)));
86  }
87  for (Int_t i = 1; i <= h2.GetYaxis()->GetNbins(); ++i) {
88  h2.GetYaxis()->SetBinLabel(i, MAKE_CSTRING(floor .at(i-1)));
89  }
90 
91  while (inputFile.hasNext()) {
92 
93  STATUS("event: " << setw(10) << inputFile.getCounter() << '\r'); DEBUG(endl);
94 
95  const JDAQSummaryslice* summary = inputFile.next();
96 
97  for (JDAQSummaryslice::const_iterator frame = summary->begin(); frame != summary->end(); ++frame) {
98 
99  if (router.hasModule(frame->getModuleID())) {
100 
101  const JModule& module = router.getModule(frame->getModuleID());
102 
103  for (int pmt = 0; pmt != NUMBER_OF_PMTS; ++pmt) {
104  if (!frame->testHighRateVeto(pmt) && !frame->testFIFOStatus(pmt)) {
105  h2.Fill((double) string.getIndex(module.getString()),
106  (double) floor .getIndex(module.getFloor()),
107  frame->getRate(pmt) * 1.0e-3); // [kHz]
108  }
109  }
110  } else {
111  FATAL("JModuleRouter trying to access non existing identifier: " << frame->getModuleID());
112  }
113  }
114  }
115  STATUS(endl);
116 
117  out.Write();
118  out.Close();
119 }
Utility class to parse command line options.
Definition: JParser.hh:1514
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:136
General purpose class for a hash collection of unique elements.
string outputFile
Data structure for detector geometry and calibration.
JMODEL::JString getString(const JFit &fit)
Get model parameters of string.
Auxiliary class for defining the range of iterations of objects.
Definition: JLimit.hh:41
Detector file.
Definition: JHead.hh:226
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1989
const array_type< JValue_t > & make_array(const JValue_t(&array)[N])
Method to create array of values.
Definition: JVectorize.hh:54
then awk string
int getIndex()
Get index for user I/O manipulation.
Definition: JManip.hh:26
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.
bool hasModule(const JObjectID &id) const
Has module.
const JLimit & getLimit() const
Get limit.
Definition: JLimit.hh:84
do set_variable DETECTOR_TXT $WORKDIR detector
static const int NUMBER_OF_PMTS
Total number of PMTs in module.
Definition: JDAQ.hh:26
int debug
debug level
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62