Jpp  pmt_effective_area_update
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JEditDetector.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <sstream>
3 #include <string>
4 #include <vector>
5 #include <map>
6 
7 #include "TRandom3.h"
8 
9 #include "JDetector/JDetector.hh"
18 #include "JGeometry3D/JVector3D.hh"
19 #include "JMath/JConstants.hh"
20 #include "JMath/JMath.hh"
21 #include "JTools/JRange.hh"
22 #include "JLang/JException.hh"
23 #include "JLang/JToken.hh"
24 #include "JSupport/JMeta.hh"
25 
26 #include "Jeep/JeepToolkit.hh"
27 #include "Jeep/JPrint.hh"
28 #include "Jeep/JParser.hh"
29 #include "Jeep/JMessage.hh"
30 
31 
32 namespace {
33 
34  using namespace JPP;
35 
36  /**
37  * Wild card for string identifier, module identifier or PMT address.
38  */
39  static const int WILDCARD = -1;
40 
41  static const std::string reset_t = "reset"; //!< Reset time offset, position and PMT status bit
42  static const std::string set_t = "set"; //!< Set time offset, position or PMT status bit
43  static const std::string add_t = "add"; //!< Add time offset or position
44  static const std::string sub_t = "sub"; //!< Subtract time offset or position
45  static const std::string rot_t = "rot"; //!< Rotate around z-axis by value [rad]
46  static const std::string mul_t = "mul"; //!< Multiply z-position by (1 + value)
47  static const std::string tilt_t = "tilt"; //!< Tilt string
48 
49  static const std::string assign_t = "assign"; //!< Assign module identifier
50  static const std::string string_t = "string"; //!< Assign string number
51 
52  static const std::string rand_t = "rand"; //!< Random value(s)
53  static const std::string randset_t = rand_t + set_t; //!< Set time offset or position
54  static const std::string randadd_t = rand_t + add_t; //!< Add time offset or position
55  static const std::string randsub_t = rand_t + sub_t; //!< Subtract time offset or position
56  static const std::string randrot_t = rand_t + rot_t; //!< Rotate around z-axis by value [rad]
57  static const std::string randmul_t = rand_t + mul_t; //!< Multiply z-position by (1 + value)
58  static const std::string randtilt_t = rand_t + tilt_t; //!< Tilt string
59 
60  static const std::string RESET_t = "RESET"; //!< Reset time offset of piezo/hydrophone and quaternion calibration of compass
61  static const std::string SET_t = "SET"; //!< Set time offset of piezo/hydrophone or quaternion calibration of compass
62  static const std::string ADD_t = "ADD"; //!< Add time offset of piezo/hydrophone or quaternion calibration of compass
63  static const std::string SUB_t = "SUB"; //!< Subtract time offset of piezo/hydrophone or quaternion calibration of compass
64  static const std::string ROT_t = "ROT"; //!< Rotate quaternion calibration of compass around z-axis by value [rad]
65 
66 
67  /**
68  * Apply action to given module.
69  *
70  * \param module module (I/O)
71  * \param action action
72  * \return true if valid action; else false
73  */
74  inline bool apply(JModule& module, const std::string& action)
75  {
76  if (action == reset_t) {
77 
78  // position does not depend on module but may not exactly be at origin
79 
80  module.set(getModule<JKM3NeT_t>(1).getPosition());
81 
82  for (JModule::iterator pmt = module.begin(); pmt != module.end(); ++pmt) {
84  pmt->setStatus(JStatus());
85  }
86 
87  } else if (action == RESET_t) {
88 
89  module.setCalibration(JCalibration());
90  module.setQuaternion(JQuaternion3D());
91 
92  } else if (action == SET_t) {
93 
94  const double t0 = getAverage(make_array(module.begin(), module.end(), &JPMT::getT0), 0.0);
95 
96  if (module.getFloor() != 0)
97  module.setT0(t0 - PIEZO_DELAYTIME_US * 1.0e+3);
98  else
99  module.setT0(t0 - HYDROPHONE_DELAYTIME_US * 1.0e+3);
100 
101  } else {
102 
103  return false;
104  }
105 
106  return true;
107  }
108 
109 
110  /**
111  * Apply action to given module.
112  *
113  * \param module module (I/O)
114  * \param action action
115  * \param value value
116  * \return true if valid action; else false
117  */
118  inline bool apply(JModule& module, const std::string& action, const double value)
119  {
120  if (action == set_t) { // actions with fixed values
121 
122  module.set(value);
123 
124  } else if (action == add_t) {
125 
126  module.add(value);
127 
128  } else if (action == sub_t) {
129 
130  module.sub(value);
131 
132  } else if (action == rot_t) {
133 
134  const JVector3D center = module.getPosition();
135 
136  module.sub(center);
137 
138  module.rotate(JRotation3Z(value));
139 
140  module.add(center);
141 
142  } else if (action == mul_t) {
143 
144  const JVector3D center(module.getPosition().getX(),
145  module.getPosition().getY(),
146  module.getPosition().getZ() * (1.0 + value));
147 
148  module.set(center);
149 
150  } else if (action == SET_t) {
151 
152  module.setT0(value);
153 
154  } else if (action == ADD_t) {
155 
156  module.addT0(value);
157 
158  } else if (action == SUB_t) {
159 
160  module.subT0(value);
161 
162  } else if (action == ROT_t) {
163 
164  module.setQuaternion(JQuaternion3Z(value) * module.getQuaternion());
165 
166  } else if (action == randadd_t) { // actions with random values
167 
168  module.add(gRandom->Gaus(0.0, value));
169 
170  } else if (action == randsub_t) {
171 
172  module.sub(gRandom->Gaus(0.0, value));
173 
174  } else if (action == randrot_t){
175 
176  const JVector3D center = module.getPosition();
177 
178  module.sub(center);
179 
180  module.rotate(JRotation3Z(gRandom->Gaus(0.0, value)));
181 
182  module.add(center);
183 
184  } else if (action == randmul_t) {
185 
186  if (module.getFloor() != 0) {
187 
188  const JVector3D center(module.getPosition().getX(),
189  module.getPosition().getY(),
190  module.getPosition().getZ() * gRandom->Gaus(1.0, value));
191 
192  module.set(center);
193  }
194 
195  } else if (action == assign_t) { // action with assigments
196 
197  module.setID((int) value);
198 
199  } else if (action == string_t) {
200 
201  module.setLocation(JLocation((int) value, module.getFloor()));
202 
203  } else { //
204 
205  return false;
206  }
207 
208  return true;
209  }
210 
211 
212  /**
213  * Apply action to given module.
214  *
215  * \param module module (I/O)
216  * \param action action
217  * \param first first value
218  * \param second second value
219  * \return true if valid action; else false
220  */
221  inline bool apply(JModule& module, const std::string& action, const double first, const double second)
222  {
223  if (action == tilt_t) { // actions with fixed values
224 
225  const double Tx = first;
226  const double Ty = second;
227  const double Tz = sqrt(1.0 - Tx*Tx - Ty*Ty);
228 
229  const double x = Tx * module.getZ() + module.getX();
230  const double y = Ty * module.getZ() + module.getY();
231  const double z = Tz * module.getZ();
232 
233  module.set(JPosition3D(x,y,z));
234 
235  } else { //
236 
237  return false;
238  }
239 
240  return true;
241  }
242 
243 
244  /**
245  * Apply action to given module.
246  *
247  * \param module module (I/O)
248  * \param action action
249  * \param pos pos
250  * \return true if valid action; else false
251  */
252  inline bool apply(JModule& module, const std::string& action, const JVector3D& pos)
253  {
254  const JVector3D randpos(gRandom->Gaus(0.0, pos.getX()),
255  gRandom->Gaus(0.0, pos.getY()),
256  gRandom->Gaus(0.0, pos.getZ()));
257 
258  if (action == set_t) // actions with fixed values
259  module.set(pos);
260  else if (action == add_t)
261  module.add(pos);
262  else if (action == sub_t)
263  module.sub(pos);
264  else if (action == randset_t) // actions with random values
265  module.set(randpos);
266  else if (action == randadd_t)
267  module.add(randpos);
268  else if (action == randsub_t)
269  module.sub(randpos);
270  else
271  return false;
272 
273  return true;
274  }
275 
276 
277  /**
278  * Apply action to given module.
279  *
280  * \param module module (I/O)
281  * \param action action
282  * \param Q quaternion
283  * \return true if valid action; else false
284  */
285  inline bool apply(JModule& module, const std::string& action, const JQuaternion3D& Q)
286  {
287  if (action == SET_t)
288  module.setQuaternion(Q);
289  else if (action == ADD_t)
290  module.setQuaternion(Q * module.getQuaternion());
291  else if (action == SUB_t)
292  module.setQuaternion(Q.getConjugate() * module.getQuaternion());
293  else
294  return false;
295 
296  return true;
297  }
298 
299 
300  /**
301  * Apply action to given PMT.
302  *
303  * \param pmt PMT (I/O)
304  * \param action action
305  * \param value value
306  * \return true if valid action; else false
307  */
308  inline bool apply(JPMT& pmt, const std::string& action, const std::string& value)
309  {
310  try {
311 
312  if (action == set_t)
313  pmt.set(getPMTStatusBit(value));
314  else if (action == reset_t)
315  pmt.reset(getPMTStatusBit(value));
316  else
317  return false;
318 
319  return true;
320  }
321  catch(const std::exception&) {
322  return false;
323  }
324  }
325 
326 
327  /**
328  * Auxiliary class for module modifications.
329  */
330  struct JModifier {
331  /**
332  * Default constructor.
333  */
334  JModifier()
335  {}
336 
337 
338  /**
339  * Check validity.
340  *
341  * \return true if valid modifier; else false
342  */
343  bool is_valid() const
344  {
345  return (action != "" && !data.empty());
346  }
347 
348 
349  /**
350  * Apply action to given module depending on number of values.
351  *
352  * \param module module
353  * \return true if valid action; else false
354  */
355  bool apply(JModule& module) const
356  {
357  switch (data.size()) {
358 
359  case 0:
360  return ::apply(module, action);
361 
362  case 1:
363  return ::apply(module, action, data[0]);
364 
365  case 2:
366  return ::apply(module, action, data[0], data[1]);
367 
368  case 3:
369  return ::apply(module, action, JVector3D(data[0], data[1], data[2]));
370 
371  case 4:
372  return ::apply(module, action, JQuaternion3D(data[0], data[1], data[2], data[3]));
373 
374  default:
375  return false;
376  }
377  }
378 
379 
380  /**
381  * Read modifier from input.
382  *
383  * \param in input stream
384  * \param modifier modifier
385  * \return input stream
386  */
387  friend inline std::istream& operator>>(std::istream& in, JModifier& modifier)
388  {
389  if (in >> modifier.action) {
390 
391  modifier.data.clear();
392 
393  for (double x; in >> x; ) {
394  modifier.data.push_back(x);
395  }
396 
397  in.clear(std::ios_base::eofbit);
398  }
399 
400  return in;
401  }
402 
403 
404  /**
405  * Write modifier to output.
406  *
407  * \param out output stream
408  * \param modifier modifier
409  * \return output stream
410  */
411  friend inline std::ostream& operator<<(std::ostream& out, const JModifier& modifier)
412  {
413  out << modifier.action;
414 
415  for (std::vector<double>::const_iterator i = modifier.data.begin(); i != modifier.data.end(); ++i) {
416  out << ' ' << *i;
417  }
418 
419  return out;
420  }
421 
422 
423  std::string action;
424  std::vector<double> data;
425  };
426 
427 
428  /**
429  * Get modifier for given string.
430  *
431  * For actions <tt>ranXXX</tt>, the corresponding action <tt>XXX</tt> is made the same for all modules in the given string.\n
432  * For all other options, the input action is maintained.
433  *
434  * \param id string number
435  * \param modifier modifier
436  * \return modifier
437  */
438  inline const JModifier& getModifier(const int id, const JModifier& modifier)
439  {
440  using namespace std;
441 
443 
444  const string::size_type pos = modifier.action.find(rand_t);
445 
446  if (pos != string::npos) {
447 
448  JModifier& result = buffer[id][modifier.action][modifier.data.size()];
449 
450  if (!result.is_valid()) {
451 
452  result.action = modifier.action.substr(pos + rand_t.length());
453 
454  for (size_t i = 0; i != modifier.data.size(); ++i) {
455  result.data.push_back(gRandom->Gaus(0.0, modifier.data[i]));
456  }
457  }
458 
459  return result;
460 
461  } else {
462 
463  return modifier;
464  }
465  }
466 
467 
468  /**
469  * Auxiliary class for PMT status modifications.
470  */
471  struct JPMTModifier {
472  /**
473  * Default constructor.
474  */
475  JPMTModifier()
476  {}
477 
478 
479  /**
480  * Apply action to given PMT.
481  *
482  * \param pmt PMT
483  * \return true if valid action; else false
484  */
485  bool apply(JPMT& pmt) const
486  {
487  return ::apply(pmt, action, value);
488  }
489 
490 
491  /**
492  * Read PMT modifier from input.
493  *
494  * \param in input stream
495  * \param modifier modifier
496  * \return input stream
497  */
498  friend inline std::istream& operator>>(std::istream& in, JPMTModifier& modifier)
499  {
500  return in >> modifier.action >> modifier.value;
501  }
502 
503 
504  /**
505  * Write modifier to output.
506  *
507  * \param out output stream
508  * \param modifier modifier
509  * \return output stream
510  */
511  friend inline std::ostream& operator<<(std::ostream& out, const JPMTModifier& modifier)
512  {
513  out << modifier.action;
514  out << ' ';
515  out << modifier.value;
516 
517  return out;
518  }
519 
520 
521  std::string action;
522  std::string value;
523  };
524 
525 
526  /**
527  * Range of string numbers.
528  *
529  * The input format could be a single number or two numbers separated by JRange_t::SEPARATOR.
530  */
531  struct JRange_t :
532  public JRange<int>
533  {
534  /**
535  * Separator between two identifier values.
536  */
537  static const char SEPARATOR = '-';
538 
539  /**
540  * Default constructor.
541  */
542  JRange_t() :
543  JRange(-1, -1)
544  {}
545 
546 
547  /**
548  * Read range from input.
549  *
550  * \param in input stream
551  * \param range range
552  * \return input stream
553  */
554  friend inline std::istream& operator>>(std::istream& in, JRange_t& range)
555  {
556  if (in >> range.first) {
557 
558  range.second = range.first;
559 
560  if (in.peek() == (int) JRange_t::SEPARATOR) {
561 
562  in.get();
563 
564  in >> range.second;
565 
566  } else {
567 
568  in.clear();
569  }
570  }
571 
572  return in;
573  }
574 
575 
576  /**
577  * Write range to output.
578  *
579  * \param out output stream
580  * \param range range
581  * \return output stream
582  */
583  friend inline std::ostream& operator<<(std::ostream& out, const JRange_t& range)
584  {
585  return out << range.first << JRange_t::SEPARATOR << range.second;
586  }
587  };
588 
589 
590  /**
591  * Print module modification.
592  *
593  * \param out output stream
594  * \param module module
595  * \param modifier modifier
596  */
597  inline void print(std::ostream& out, const JModule& module, const JModifier& modifier)
598  {
599  using namespace std;
600  using namespace JPP;
601 
602  out << "Modifier" << ' '
603  << "(" << FILL(4,'0') << module.getString() << "," << FILL(2,'0') << module.getFloor() << FILL() << ")" << ' '
604  << setw(10) << module.getID() << ' '
605  << "action" << ' ' << modifier.action << JEEPZ() << modifier.data << endl;
606  }
607 
608 
609  /**
610  * Print PMT modification.
611  *
612  * \param out output stream
613  * \param pmt pmt identifier
614  * \param modifier modifier
615  */
616  inline void print(std::ostream& out, const JPMTIdentifier& pmt, const JPMTModifier& modifier)
617  {
618  using namespace std;
619  using namespace JPP;
620 
621  out << "PMT modifier" << ' '
622  << "(" << setw(10) << pmt.getID() << "," << setw(2) << pmt.getPMTAddress() << ")" << ' '
623  << "action" << ' ' << modifier.action << ' '
624  << "value" << ' ' << modifier.value << endl;
625  }
626 }
627 
628 
629 /**
630  * \file
631  *
632  * Auxiliary program to modify detector calibration.
633  *
634  * Syntax:
635  * <pre>
636  * -M "<module identifier> (set|add|sub|randset|randadd|randsub) x0 [x1 x2]"
637  * -(S|s) "<string number> (set|add|sub|randset|randadd|randsub) x0 [x1 x2]"
638  * -M "<module identifier> (rot|randrot) phi"
639  * -(S|s) "<string number> (rot|randrot) phi"
640  * -M "<module identifier> (mul|randmul) factor"
641  * -(S|s) "<string number> (mul|randmul) factor"
642  * -M "<module identifier> (reset)"
643  * -(S|s) "<string number> (reset)"
644  * -M "<module identifier> (assign) identifier"
645  * -M "<module identifier> (SET|ADD|SUB|) x0 [x1 x2 x3]"
646  * -(S|s) "<string number> (SET|ADD|SUB|) x0 [x1 x2 x3]"
647  * -M "<module identifier> (ROT) phi"
648  * -(S|s) "<string number> (ROT) phi"
649  * -M "<module identifier> (SET)"
650  * -(S|s) "<string number> (SET)"
651  * -(S|s) "<string number> (tilt|randtilt) Tx Ty"
652  * -P "<PMT identifier> (set|reset) (PMT_DISABLE|HIGH_RATE_VETO_DISABLE|FIFO_FULL_DISABLE|UDP_COUNTER_DISABLE|UDP_TRAILER_DISABLE|OUT_OF_SYNC)"
653  * -p "<PMT physical address> (set|reset) (PMT_DISABLE|HIGH_RATE_VETO_DISABLE|FIFO_FULL_DISABLE|UDP_COUNTER_DISABLE|UDP_TRAILER_DISABLE|OUT_OF_SYNC)"
654  * -k "<string number>[-<string number>]"
655  * -r "<string number>[-<string number>]"
656  * -m "<module identifier>"
657  * -D "<string number> <floor>"
658  * -\@ "<key>=<value>[;<key>=<value>"
659  * </pre>
660  * Options <tt>-M</tt> and <tt>-S</tt> refer to a module and a string, respectively.\n
661  * The values provided for a string modification coherently apply to the modules of the specified string number.\n
662  * The option <tt>-s</tt> is equivalent to option <tt>-S</tt> except that
663  * the action applies only to the optical modules in the string and not the base module.
664  *
665  * The options <tt>randxxx</tt> correspond to a randomisation of the specified option.
666  *
667  * If the module identifier or string number is -1,
668  * the action is applied to all modules or strings in the detector, respectively.
669  *
670  * For options <tt>[rand]set</tt>, <tt>[rand]add</tt> and <tt>[rand]sub</tt>,
671  * the number of values apply to position or time calibration in the following way:
672  * -# time calibration <tt>(t = x0)</tt>
673  * -# invalid
674  * -# position calibration <tt>(x = x0, y = x1, z = x2)</tt>
675  *
676  * For options <tt>[rand]rot</tt>,
677  * the angle <tt>phi</tt> refers to an anti-clockwise rotation around the z-axis.\n
678  * The rotation angle is defined in radians.
679  *
680  * For options <tt>[rand]mul</tt>,
681  * the multiplication <tt>factor</tt> (a.k.a.\ "stretching") applies to
682  * the z-coordinates of the optical modules and not to the base module (read anchor).\n
683  * The factor is defined as a fraction; the actual multiplication factor is <tt>(1 + factor)</tt>.
684  *
685  * For options <tt>SET</tt>, <tt>ADD</tt> and <tt>SUB</tt>,
686  * the number of values apply to time or quaternion calibration of the module in the following way:
687  * -# time calibration of piezo sensor or hydrophone <tt>(t = x0)</tt>
688  * -# invalid
689  * -# invalid
690  * -# quaternion calibration of compass <tt>(qa = x0, qb = x1, qc = x2, qd = x3)</tt>
691  *
692  * For options <tt>ROT</tt>,
693  * the angle <tt>phi</tt> refers to an anti-clockwise rotation around the z-axis of the quaternion calibration of the compass.\n
694  * The rotation angle is defined in radians.
695  *
696  * If no values are given at the option <tt>SET</tt>,
697  * - the time calibration of the piezo sensor is set to the average time calibration of the PMTs in that module,
698  * - the time calibration of the hydrophone is set to 0.
699  *
700  * In this, the time calibration is corrected for the delay time of the piezo sensor and hydrophone \n
701  * which are defined by JDETECTOR::PIEZO_DELAYTIME_US JDETECTOR::HYDROPHONE_DELAYTIME_US, respectively.\n
702  *
703  * The units of all positions and time values are <tt>m</tt> and <tt>ns</tt>, respectively.
704  *
705  * Note that for string modifiers with option <tt>randxxx</tt>,
706  * the action is coherently applied to the modules in the specified string.\n
707  * Only one type of action (defined by <tt>xxx</tt> and the number of values) is then allowed per string.
708  *
709  * Option <tt>-\@</tt> refers to the header information.\n
710  * The list of possible keys can be obtained using JPrintDetector.cc with option <tt>-O header</tt>.
711  *
712  * Multiple options <tt>-M</tt>, <tt>-S</tt>, <tt>-s</tt> or <tt>-\@</tt> will be processed in order of appearance.
713  *
714  * Options <tt>-k</tt> and <tt>-r</tt> can be used to keep and remove (a range of) string numbers, respectively.
715  *
716  * The options <tt>-m</tt> and <tt>-D</tt> can be used to maintain a specific module (and remove all others) and
717  * to delete a floor from a string, respectively.
718  *
719  * Note finally that if the output file name is the same as the input file name,
720  * the original file will be overwritten.
721  *
722  * \author mdejong
723  */
724 int main(int argc, char **argv)
725 {
726  using namespace std;
727  using namespace JPP;
728 
729  typedef JToken<';'> JToken_t;
730 
731  string inputFile;
732  string outputFile;
733  vector<JToken_t> hdr;
738  JPMTModifier> > pmt;
740  JPMTModifier> > alt;
741  vector<JRange_t> keep;
742  vector<JRange_t> rm;
743  vector<int> id;
744  multimap<int, int> del;
745  int debug;
746 
747  try {
748 
749  JParser<> zap("Auxiliary program to modify detector.");
750 
751  zap['a'] = make_field(inputFile);
752  zap['o'] = make_field(outputFile);
753  zap['@'] = make_field(hdr, "header modification") = JPARSER::initialised();
754  zap['M'] = make_field(mod, "module modification") = JPARSER::initialised();
755  zap['S'] = make_field(str, "string modification (optical modules and base module") = JPARSER::initialised();
756  zap['s'] = make_field(dos, "string modification (optical modules only)") = JPARSER::initialised();
757  zap['P'] = make_field(pmt, "PMT modification by PMT logical address") = JPARSER::initialised();
758  zap['p'] = make_field(alt, "PMT modification by PMT physical address") = JPARSER::initialised();
759  zap['k'] = make_field(keep, "keep string[s]") = JPARSER::initialised();
760  zap['r'] = make_field(rm, "remove string[s]") = JPARSER::initialised();
761  zap['m'] = make_field(id, "remove module by identifier") = JPARSER::initialised();
762  zap['D'] = make_field(del, "remove module by location") = JPARSER::initialised();
763  zap['d'] = make_field(debug) = 2;
764 
765  zap(argc, argv);
766  }
767  catch(const exception &error) {
768  FATAL(error.what() << endl);
769  }
770 
772 
773  try {
774  load(inputFile, detector);
775  }
776  catch(const JException& error) {
777  FATAL(error);
778  }
779 
780 
781  gRandom->SetSeed(0);
782 
783 
784  if ((keep.empty() ? 0 : 1 +
785  rm .empty() ? 0 : 1 +
786  id .empty() ? 0 : 1) > 1) {
787  FATAL("Use either option -k, -r or -m." << endl);
788  }
789 
790 
791  detector.comment.add(JMeta(argc,argv));
792 
793  if (detector.setToLatestVersion()) {
794  NOTICE("Set detector version to " << detector.getVersion() << endl);
795  }
796 
797 
798  if (!hdr.empty()) {
799 
800  int id = -1;
801 
802  JProperties helper = detector.getProperties();
803 
804  helper["id"] = id;
805 
806  for (vector<JToken_t>::const_iterator i = hdr.begin(); i != hdr.end(); ++i) {
807 
808  istringstream is(*i);
809 
810  is >> helper;
811  }
812 
813  if (id != -1) {
814  detector.setID(id);
815  }
816  }
817 
818 
819  for (JDetector::iterator module = detector.begin(); module != detector.end(); ) {
820 
821  bool __rm__ = !keep.empty() && rm.empty();
822 
823  for (vector<JRange_t>::const_iterator i = keep.begin(); i != keep.end(); ++i) {
824  if (module->getString() >= i->first && module->getString() <= i->second) {
825  __rm__ = false;
826  }
827  }
828 
829  for (vector<JRange_t>::const_iterator i = rm.begin(); i != rm.end(); ++i) {
830  if (module->getString() >= i->first && module->getString() <= i->second) {
831  __rm__ = true;
832  }
833  }
834 
835  if (!id.empty()) {
836  __rm__ = find(id.begin(), id.end(), module->getID()) == id.end();
837  }
838 
839  const auto range = del.equal_range(module->getString());
840 
841  for (auto i = range.first; i != range.second; ++i) {
842  if (i->second == module->getFloor()) {
843  __rm__ = true;
844  }
845  }
846 
847  if (__rm__)
848  module = detector.erase(module);
849  else
850  ++module;
851  }
852 
853 
854  for (vector< pair<int, JModifier> >::const_iterator i = mod.begin(); i != mod.end(); ++i) {
855 
856  for (JDetector::iterator module = detector.begin(); module != detector.end(); ++module) {
857 
858  if (module->getID() == i->first || i->first == WILDCARD ){
859 
860  if (debug >= debug_t) {
861  print(cout, *module, i->second);
862  }
863 
864  if (!i->second.apply(*module)) {
865  ERROR("No valid action: " << i->first << ' ' << i->second << endl);
866  }
867  }
868  }
869  }
870 
871 
872  for (vector< pair<int, JModifier> >::const_iterator i = str.begin(); i != str.end(); ++i) {
873 
874  for (JDetector::iterator module = detector.begin(); module != detector.end(); ++module) {
875 
876  if (module->getString() == i->first || i->first == WILDCARD) {
877 
878  const JModifier modifier = getModifier(module->getString(), i->second);
879 
880  if (debug >= debug_t) {
881  print(cout, *module, i->second);
882  }
883 
884  if (!modifier.apply(*module)) {
885  ERROR("No valid action: " << i->first << ' ' << i->second << endl);
886  }
887  }
888  }
889  }
890 
891 
892  for (vector< pair<int, JModifier> >::const_iterator i = dos.begin(); i != dos.end(); ++i) {
893 
894  for (JDetector::iterator module = detector.begin(); module != detector.end(); ++module) {
895 
896  if (module->getFloor() != 0) {
897 
898  if (module->getString() == i->first || i->first == WILDCARD) {
899 
900  const JModifier modifier = getModifier(module->getString(), i->second);
901 
902  if (debug >= debug_t) {
903  print(cout, *module, i->second);
904  }
905 
906  if (!modifier.apply(*module)) {
907  ERROR("No valid action: " << i->first << ' ' << i->second << endl);
908  }
909  }
910  }
911  }
912  }
913 
914 
915  for (vector< pair<JPMTIdentifier, JPMTModifier> >::const_iterator i = pmt.begin(); i != pmt.end(); ++i) {
916 
917  for (JDetector::iterator module = detector.begin(); module != detector.end(); ++module) {
918 
919  if (module->getID() == i->first.getModuleID() || i->first.getModuleID() == WILDCARD) {
920 
921  if (debug >= debug_t) {
922  print(cout, i->first, i->second);
923  }
924 
925  if (i->first.getPMTAddress() == WILDCARD) {
926 
927  for (int pmt = 0; pmt != getNumberOfPMTs(*module); ++pmt) {
928  if (!i->second.apply(module->getPMT(pmt))) {
929  ERROR("No valid action: " << i->first << ' ' << i->second << endl);
930  }
931  }
932 
933  } else if (i->first.getPMTAddress() < 0 ||
934  i->first.getPMTAddress() >= getNumberOfPMTs(*module) ||
935  !i->second.apply(module->getPMT(i->first.getPMTAddress()))) {
936  ERROR("No valid action: " << i->first << ' ' << i->second << endl);
937  }
938  }
939  }
940  }
941 
942 
943  if (!alt.empty()) {
944 
945  if (!hasDetectorAddressMap(detector.getID())) {
946  FATAL("Invalid detector identifier " << detector.getID() << endl);
947  }
948 
949  const JDetectorAddressMap& demo = getDetectorAddressMap(detector.getID());
950 
951  for (JDetector::iterator module = detector.begin(); module != detector.end(); ++module) {
952 
953  const JModuleAddressMap memo = demo.get(module->getID());
954 
955  for (vector< pair<JPMTPhysicalAddress, JPMTModifier> >::const_iterator i = alt.begin(); i != alt.end(); ++i) {
956 
957  const JPMTIdentifier id(module->getID(), memo.getAddressTranslator(i->first).tdc);
958 
959  if (debug >= debug_t) {
960  print(cout, id, i->second);
961  }
962 
963  if (!i->second.apply(module->getPMT(id.getPMTAddress()))) {
964  ERROR("No valid action: " << i->first << ' ' << i->second << endl);
965  }
966  }
967  }
968  }
969 
970 
971  try {
973  }
974  catch(const JException& error) {
975  FATAL(error);
976  }
977 }
void set(const int bit)
Set PMT status.
Definition: JStatus.hh:123
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 JGetPMTStatusBit getPMTStatusBit
Function object to map key to PMT status bit.
Definition: JStatus.hh:280
Exceptions.
Q(UTCMax_s-UTCMin_s)-livetime_s
debug
Definition: JMessage.hh:29
int main(int argc, char *argv[])
Definition: Main.cc:15
int getFloor() const
Get floor number.
Definition: JLocation.hh:145
Data structure for a composite optical module.
Definition: JModule.hh:66
static const double HYDROPHONE_DELAYTIME_US
Hydrophone delay time [us].
JQuaternion3D getConjugate() const
Get conjugate of this quaternion.
void setLocation(const JLocation &location)
Set location.
Definition: JLocation.hh:91
Detector data structure.
Definition: JDetector.hh:81
bool hasDetectorAddressMap(const int id)
Check if detector address map is available.
Utility class to parse parameter values.
Definition: JProperties.hh:496
std::iterator_traits< T >::value_type getAverage(T __begin, T __end)
Get average.
Definition: JMath.hh:497
int getNumberOfPMTs(const JModule &module)
Get number of PMTs.
void subT0(const double t0)
Subtract time offset.
Auxiliary class for controlling PMT status.
Definition: JStatus.hh:41
Lookup table for PMT addresses in detector.
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Definition: JParser.hh:66
Data structure for time calibration.
void reset(const int bit)
Reset PMT status.
Definition: JStatus.hh:134
string outputFile
is
Definition: JDAQCHSM.chsm:167
Data structure for detector geometry and calibration.
const JModuleAddressMap & get(const int id) const
Get module address map.
then echo The file $DIR KM3NeT_00000001_00000000 root already please rename or remove it first
const JQuaternion3D & getQuaternion() const
Get quaternion.
Rotation around Z-axis.
Definition: JRotation3D.hh:85
JModule & sub(const JVector3D &pos)
Subtract position.
Definition: JModule.hh:432
Lookup table for PMT addresses in optical module.
Detector specific mapping between logical positions and readout channels of PMTs in optical modules...
I/O formatting auxiliaries.
Detector file.
Definition: JHead.hh:196
static const double PIEZO_DELAYTIME_US
Piezo delay time [us].
Data structure for vector in three dimensions.
Definition: JVector3D.hh:34
void setQuaternion(const JQuaternion3D &quaternion)
Set quaternion.
Logical location of module.
Definition: JLocation.hh:37
Mathematical constants.
#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
Auxiliary methods for handling file names, type names and environment.
return result
Definition: JPolint.hh:727
int getID() const
Get identifier.
Definition: JObjectID.hh:50
This class represents a rotation around the z-axis.
bool is_valid(const json &js)
Check validity of JSon data.
Data structure for PMT geometry, calibration and status.
Definition: JPMT.hh:42
void store(const std::string &file_name, const JDetector &detector)
Store detector to output file.
ROOT I/O of application specific meta data.
JPosition3D getPosition(const Vec &pos)
Get position.
#define NOTICE(A)
Definition: JMessage.hh:64
#define ERROR(A)
Definition: JMessage.hh:66
int getPMTAddress() const
Get PMT address (= TDC).
double getY() const
Get y position.
Definition: JVector3D.hh:104
int debug
debug level
Definition: JSirene.cc:63
Auxiliary data structure for streaming of STL containers.
Definition: JPrint.hh:65
const JPosition3D & getPosition() const
Get position.
Definition: JPosition3D.hh:130
JDetectorAddressMap & getDetectorAddressMap()
Get detector address map.
print
Definition: JConvertDusj.sh:44
const JPMT & getPMT(const int index) const
Get PMT.
Definition: JModule.hh:163
void rotate(const JRotation3D &R)
Rotate module.
Definition: JModule.hh:309
Range of values.
Definition: JRange.hh:38
General purpose messaging.
Auxiliary data structure for sequence of same character.
Definition: JManip.hh:328
#define FATAL(A)
Definition: JMessage.hh:67
Data structure for unit quaternion in three dimensions.
Direct access to module in detector data structure.
z range($ZMAX-$ZMIN)< $MINIMAL_DZ." fi fi typeset -Z 4 STRING typeset -Z 2 FLOOR JPlot1D -f $
int getString() const
Get string number.
Definition: JLocation.hh:134
std::istream & operator>>(std::istream &in, JAANET::JHead &header)
Read header from input.
Definition: JHead.hh:1618
const JPMTAddressTranslator & getAddressTranslator(const int tdc) const
Get PMT address translator.
void load(const std::string &file_name, JDetector &detector)
Load detector from input file.
void setT0(const double t0)
Set time offset.
Auxiliary class to define a range between two values.
Utility class to parse command line options.
Wrapper class around string.
Definition: JToken.hh:23
void setCalibration(const JCalibration &cal)
Set calibration.
void setID(const int id)
Set identifier.
Definition: JObjectID.hh:72
double getX() const
Get x position.
Definition: JVector3D.hh:94
Base class for data structures with artithmetic capabilities.
std::ostream & operator<<(std::ostream &stream, const CLBCommonHeader &header)
void addT0(const double t0)
Add time offset.
Data structure for position in three dimensions.
Definition: JPosition3D.hh:36
Data structure for PMT physical address.
do set_variable DETECTOR_TXT $WORKDIR detector
then fatal Wrong number of arguments fi set_variable DETECTOR $argv[1] set_variable INPUT_FILE $argv[2] eval JPrintDetector a $DETECTOR O IDENTIFIER eval JPrintDetector a $DETECTOR O SUMMARY source JAcoustics sh $DETECTOR_ID CHECK_EXIT_CODE typeset A TRIPODS get_tripods $WORKDIR tripod txt TRIPODS for EMITTER in
Definition: JCanberra.sh:40
JModule & set(const JVector3D &pos)
Set position.
Definition: JModule.hh:402
double getZ() const
Get z position.
Definition: JVector3D.hh:115
JModule & add(const JVector3D &pos)
Add position.
Definition: JModule.hh:414
double getT0() const
Get time offset.