Jpp  18.0.0-rc.1
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JMergeDetector.cc
Go to the documentation of this file.
1 #include <string>
2 #include <iostream>
3 #include <iomanip>
4 
5 #include "JDetector/JDetector.hh"
10 
11 #include "JLang/JEquation_t.hh"
12 
13 #include "JSupport/JMeta.hh"
14 
15 #include "Jeep/JParser.hh"
16 #include "Jeep/JMessage.hh"
17 
18 namespace {
19 
20  using namespace JPP;
21 
22  /**
23  * List of valid keys.
24  */
25  static const std::set<std::string> keys = { TCAL, PCAL, RCAL, ACAL, CCAL, SCAL };
26 }
27 
28 
29 /**
30  * \file
31  *
32  * Auxiliary program to merge detector files.
33  *
34  * \author mdejong
35  */
36 int main(int argc, char **argv)
37 {
38  using namespace std;
39  using namespace JPP;
40 
41  vector<string> detectorFile;
42  vector<JEquation_t> calset;
43  string outputFile;
44  int debug;
45 
46  try {
47 
48  JParser<> zap("Auxiliary program to merge detector files.");
49 
50  zap['a'] = make_field(detectorFile);
51  zap['o'] = make_field(outputFile);
52  zap['@'] = make_field(calset, "import calibration sets \"<key> = <file name>[; <key> = <file name>]\"" << endl
53  << "possible keys: " << JEEPZ() << keys) = JPARSER::initialised();
54  zap['d'] = make_field(debug) = 1;
55 
56  zap(argc, argv);
57  }
58  catch(const exception &error) {
59  FATAL(error.what() << endl);
60  }
61 
62 
63  map<string, string> calibration;
64 
65  for (vector<JEquation_t>::const_iterator i = calset.begin(); i != calset.end(); ++i) {
66 
67  if (keys.count(i->getKey()) == 0)
68  FATAL("Invalid calibration set \"" << i->getKey() << "\"" << endl);
69  else
70  calibration[i->getKey()] = trim(i->getValue());
71  }
72 
73 
75 
76  for (vector<string>::const_iterator i = detectorFile.begin(); i != detectorFile.end(); ++i) {
77 
78  JDetector buffer;
79 
80  try {
81  load(*i, buffer);
82  }
83  catch(const JException& error) {
84  FATAL(error);
85  }
86 
87  if (detector.empty())
88  detector = buffer;
89  else
90  copy(buffer.begin(), buffer.end(), back_inserter(detector));
91  }
92 
93 
94  if (calibration.count(TCAL)) {
95 
96  JDetector buffer;
97 
98  try {
99  load(calibration[TCAL], buffer);
100  }
101  catch(const JException& error) {
102  FATAL(error);
103  }
104 
105  JPMTRouter router(detector);
106 
107  for (const auto& module : buffer) {
108  for (const auto& pmt : module) {
109  if (router.hasPMT(pmt.getID()))
110  detector.getPMT(router.getAddress(pmt.getID())).setCalibration(pmt.getCalibration());
111  else
112  FATAL("Missing PMT " << pmt.getID() << endl);
113  }
114  }
115  }
116 
117 
118  if (calibration.count(PCAL)) {
119 
120  JDetector buffer;
121 
122  try {
123  load(calibration[PCAL], buffer);
124  }
125  catch(const JException& error) {
126  FATAL(error);
127  }
128 
129  JModuleRouter router(detector);
130 
131  for (const auto& module : buffer) {
132  if (router.hasModule(module.getID())) {
133 
134  if (module.getFloor() != 0)
135  detector.getModule(router.getAddress(module.getID())).set(module.getCenter());
136  else
137  detector.getModule(router.getAddress(module.getID())).set(module.getPosition());
138 
139  } else
140  FATAL("Missing module " << module.getID() << endl);
141  }
142  }
143 
144 
145  if (calibration.count(RCAL)) {
146 
147  JDetector buffer;
148 
149  try {
150  load(calibration[RCAL], buffer);
151  }
152  catch(const JException& error) {
153  FATAL(error);
154  }
155 
156  JModuleRouter router(detector);
157 
158  for (const auto& module : buffer) {
159  if (router.hasModule(module.getID())) {
160 
161  if (module.getFloor() != 0) {
162 
163  JModule& object = detector.getModule(router.getAddress(module.getID()));
164 
165  const JRotation3D R = getRotation(object, module);
166  const JPosition3D center = object.getCenter();
167 
168  object.sub(center);
169  object.rotate(R);
170  object.add(center);
171  }
172 
173  } else
174  FATAL("Missing module " << module.getID() << endl);
175  }
176  }
177 
178 
179  if (calibration.count(ACAL)) {
180 
181  JDetector buffer;
182 
183  try {
184  load(calibration[ACAL], buffer);
185  }
186  catch(const JException& error) {
187  FATAL(error);
188  }
189 
190  JModuleRouter router(detector);
191 
192  for (const auto& module : buffer) {
193  if (router.hasModule(module.getID())) {
194 
195  detector.getModule(router.getAddress(module.getID())).setT0(module.getT0());
196 
197  } else
198  FATAL("Missing module " << module.getID() << endl);
199  }
200  }
201 
202 
203  if (calibration.count(CCAL)) {
204 
205  JDetector buffer;
206 
207  try {
208  load(calibration[CCAL], buffer);
209  }
210  catch(const JException& error) {
211  FATAL(error);
212  }
213 
214  JModuleRouter router(detector);
215 
216  for (const auto& module : buffer) {
217  if (router.hasModule(module.getID())) {
218 
219  detector.getModule(router.getAddress(module.getID())).setQuaternion(module.getQuaternion());
220 
221  } else
222  FATAL("Missing module " << module.getID() << endl);
223  }
224  }
225 
226 
227  if (calibration.count(SCAL)) {
228 
229  JDetector buffer;
230 
231  try {
232  load(calibration[SCAL], buffer);
233  }
234  catch(const JException& error) {
235  FATAL(error);
236  }
237 
238  JPMTRouter router(detector);
239 
240  for (const auto& module : buffer) {
241  for (const auto& pmt : module) {
242  if (router.hasPMT(pmt.getID()))
243  detector.getPMT(router.getAddress(pmt.getID())).setStatus(pmt.getStatus());
244  else
245  FATAL("Missing PMT " << pmt.getID() << endl);
246  }
247  }
248  }
249 
250 
251  detector.comment.add(JMeta(argc,argv));
252 
253  try {
255  }
256  catch(const JException& error) {
257  FATAL(error);
258  }
259 }
Router for direct addressing of PMT data in detector data structure.
Definition: JPMTRouter.hh:35
Auxiliary class for ROOT I/O of application specific meta data.
Definition: JMeta.hh:70
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
Data structure for a composite optical module.
Definition: JModule.hh:68
static const std::string ACAL
acoustic time offsets (piezo sensor or hydrophone)
static const std::string CCAL
compass alignment (a.k.a. quaternion calibration)
Detector data structure.
Definition: JDetector.hh:89
Router for direct addressing of module data in detector data structure.
Rotation matrix.
Definition: JRotation3D.hh:111
static JRotation getRotation
Function object to get rotation matrix to go from first to second module.
bool hasPMT(const JObjectID &id) const
Has PMT.
Definition: JPMTRouter.hh:116
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Definition: JParser.hh:83
string outputFile
Data structure for detector geometry and calibration.
std::string trim(const std::string &buffer)
Trim string.
Definition: JLangToolkit.hh:79
static const std::string TCAL
PMT time offsets.
JVector3D & sub(const JVector3D &vector)
Subtract vector.
Definition: JVector3D.hh:158
Detector file.
Definition: JHead.hh:226
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1989
void store(const std::string &file_name, const JDetector &detector)
Store detector to output file.
ROOT I/O of application specific meta data.
Direct access to PMT in detector data structure.
Auxiliary data structure for streaming of STL containers.
Definition: JPrint.hh:65
static const std::string RCAL
optical module orientations
General purpose messaging.
#define FATAL(A)
Definition: JMessage.hh:67
Direct access to module in detector data structure.
then JCookie sh JDataQuality D $DETECTOR_ID R
Definition: JDataQuality.sh:41
void load(const std::string &file_name, JDetector &detector)
Load detector from input file.
Utility class to parse command line options.
static const std::string SCAL
(module|PMT) status
const JModuleAddress & getAddress(const JObjectID &id) const
Get address of module.
bool hasModule(const JObjectID &id) const
Has module.
void copy(const Head &from, JHead &to)
Copy header from from to to.
Definition: JHead.cc:162
Data structure for position in three dimensions.
Definition: JPosition3D.hh:36
do set_variable DETECTOR_TXT $WORKDIR detector
static const std::string PCAL
(optical|base) module positions
const JPMTAddress & getAddress(const JObjectID &id) const
Get address of PMT.
Definition: JPMTRouter.hh:80
JVector3D & add(const JVector3D &vector)
Add vector.
Definition: JVector3D.hh:142
int debug
debug level