Jpp  17.0.0
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
JMergeDetector.cc File Reference

Auxiliary program to merge detector files. More...

#include <string>
#include <iostream>
#include <iomanip>
#include "JDetector/JDetector.hh"
#include "JDetector/JDetectorToolkit.hh"
#include "JDetector/JModuleRouter.hh"
#include "JDetector/JPMTRouter.hh"
#include "JDetector/JDetectorCalibration.hh"
#include "JLang/JEquation_t.hh"
#include "JSupport/JMeta.hh"
#include "Jeep/JParser.hh"
#include "Jeep/JMessage.hh"

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Detailed Description

Auxiliary program to merge detector files.

Author
mdejong

Definition in file JMergeDetector.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 36 of file JMergeDetector.cc.

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:1500
General exception.
Definition: JException.hh:23
static const std::string RCAL
(optical|base) module orientations
Data structure for a composite optical module.
Definition: JModule.hh:68
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 const std::string TCAL
PMT time offsets.
static JRotation getRotation
Function object to get rotation matrix to go from first to second module.
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Definition: JParser.hh:66
static const std::string CCAL
compass alignment (a.k.a. quaternion calibration)
string outputFile
std::string trim(const std::string &buffer)
Trim string.
Definition: JLangToolkit.hh:79
JVector3D & sub(const JVector3D &vector)
Subtract vector.
Definition: JVector3D.hh:158
Detector file.
Definition: JHead.hh:224
static const std::string SCAL
PMT status.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1961
static const std::string PCAL
(optical|base) module positions
static const std::string ACAL
acoustic time offsets (piezo sensor or hydrophone)
void store(const std::string &file_name, const JDetector &detector)
Store detector to output file.
int debug
debug level
Definition: JSirene.cc:66
Auxiliary data structure for streaming of STL containers.
Definition: JPrint.hh:65
then usage $script[distance] fi case set_variable R
Definition: JDrawLED.sh:43
#define FATAL(A)
Definition: JMessage.hh:67
void load(const std::string &file_name, JDetector &detector)
Load detector from input file.
void copy(const Head &from, JHead &to)
Copy header from from to to.
Definition: JHead.cc:139
Data structure for position in three dimensions.
Definition: JPosition3D.hh:36
do set_variable DETECTOR_TXT $WORKDIR detector
JVector3D & add(const JVector3D &vector)
Add vector.
Definition: JVector3D.hh:142