Jpp  18.0.0-rc.4
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JDOMMap.cc
Go to the documentation of this file.
1 #include <string>
2 #include <iostream>
3 #include <iomanip>
4 #include <fstream>
5 
6 #include "JDetector/JDetector.hh"
10 
11 #include "JSon/JSon.hh"
12 
13 #include "Jeep/JeepToolkit.hh"
14 #include "Jeep/JPrint.hh"
15 #include "Jeep/JParser.hh"
16 #include "Jeep/JMessage.hh"
17 
18 
19 /**
20  * \file
21  *
22  * Auxiliary program to create module map of PMT addresses.
23  * \author mdejong
24  */
25 int main(int argc, char **argv)
26 {
27  using namespace std;
28  using namespace JPP;
29 
30  string detectorFile;
31  string outputFile;
32  int debug;
33 
34  try {
35 
36  JParser<> zap("Auxiliary program to create module map of PMT addresses.");
37 
38  zap['a'] = make_field(detectorFile, "detector file");
39  zap['o'] = make_field(outputFile, "JSon formatted output file");
40  zap['d'] = make_field(debug) = 1;
41 
42  zap(argc, argv);
43  }
44  catch(const exception &error) {
45  FATAL(error.what() << endl);
46  }
47 
48 
49  JDetector detector;
50 
51  try {
52  load(detectorFile, detector);
53  }
54  catch(const JException& error) {
55  FATAL(error);
56  }
57 
58  if (!hasDetectorAddressMap(detector.getID())) {
59  FATAL("No detector address map for detector identier " << detector.getID() << endl);
60  }
61 
62  const JDetectorAddressMap& demo = getDetectorAddressMap(detector.getID());
63 
64 
65  const json error = { {Message_t, "" },
66  {Code_t, OK_t },
67  {Arguments_t, json::array() } };
68 
69  json js;
71 
72  for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
73 
74  const JModuleAddressMap& memo = demo.get(module->getID());
75 
76  JModuleMap_t buffer(module->getID());
77 
78  for (size_t i = 0; i != module->size(); ++i) {
79  buffer[memo.getPMTPhysicalAddress(i).toString()] = (*module)[i].getID();
80  }
81 
82  data.push_back(buffer);
83  }
84 
85  js[Comment_t] = json(detector.comment);
86  js[Data_t][0][DetID_t] = json(detector.getID());
87  js[Data_t][0][DOMMap_t] = json(data);
88  js[Error_t] = json(error);
89 
90  store(outputFile.c_str(), js);
91 
92  return 0;
93 }
static const std::string Arguments_t
Utility class to parse command line options.
Definition: JParser.hh:1514
int main(int argc, char *argv[])
Definition: Main.cc:15
static const std::string Code_t
std::vector< JModuleMap_t > JModuleMap
module map
bool hasDetectorAddressMap(const int id)
Check if detector address map is available.
static const std::string Error_t
string outputFile
Data structure for detector geometry and calibration.
static const std::string Comment_t
Detector specific mapping between logical positions and readout channels of PMTs in optical modules...
I/O formatting auxiliaries.
static const std::string DOMMap_t
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1989
Auxiliary methods for handling file names, type names and environment.
void store(const std::string &file_name, const JDetector &detector)
Store detector to output file.
JDetectorAddressMap & getDetectorAddressMap()
Get detector address map.
General purpose messaging.
static const std::string Message_t
#define FATAL(A)
Definition: JMessage.hh:67
static const std::string Data_t
void load(const std::string &file_name, JDetector &detector)
Load detector from input file.
Utility class to parse command line options.
nlohmann::json json
do set_variable DETECTOR_TXT $WORKDIR detector
static const std::string DetID_t
int debug
debug level
static const std::string OK_t