Jpp  15.0.0-rc.2
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 #include <algorithm>
7 
8 #include "TRandom3.h"
9 
10 #include "JDetector/JDetector.hh"
17 #include "JDetector/JPMTStatus.hh"
21 #include "JGeometry3D/JVector3D.hh"
22 #include "JMath/JConstants.hh"
23 #include "JMath/JMath.hh"
24 #include "JTools/JRange.hh"
25 #include "JLang/JException.hh"
26 #include "JLang/JToken.hh"
27 #include "JLang/JComparator.hh"
28 #include "JLang/JComparison.hh"
29 #include "JSupport/JMeta.hh"
30 
31 #include "Jeep/JeepToolkit.hh"
32 #include "Jeep/JPrint.hh"
33 #include "Jeep/JParser.hh"
34 #include "Jeep/JMessage.hh"
35 
36 
37 namespace {
38 
39  using namespace JPP;
40 
41  /**
42  * Wild card for string identifier, module identifier or PMT address.
43  */
44  static const int WILDCARD = -1;
45 
46  static const std::string reset_t = "reset"; //!< Reset time offset, position and PMT status bit
47  static const std::string set_t = "set"; //!< Set time offset, position or PMT status bit
48  static const std::string setx_t = "setx"; //!< Set x-position
49  static const std::string sety_t = "sety"; //!< Set y-position
50  static const std::string setz_t = "setz"; //!< Set z-position
51  static const std::string add_t = "add"; //!< Add time offset or position
52  static const std::string sub_t = "sub"; //!< Subtract time offset or position
53  static const std::string rot_t = "rot"; //!< Rotate around z-axis by value [rad]
54  static const std::string mul_t = "mul"; //!< Multiply z-position by (1 + value)
55  static const std::string div_t = "div"; //!< Divide z-position by (1 + value)
56  static const std::string tilt_t = "tilt"; //!< Tilt string
57  static const std::string swap_t = "swap"; //!< Swap PMTs
58 
59  static const std::string assign_t = "assign"; //!< Assign module identifier
60  static const std::string locate_t = "locate"; //!< Locate module identifier
61  static const std::string string_t = "string"; //!< Assign string number
62 
63  static const std::string rand_t = "rand"; //!< Random value(s)
64  static const std::string randset_t = rand_t + set_t; //!< Set time offset or position
65  static const std::string randadd_t = rand_t + add_t; //!< Add time offset or position
66  static const std::string randsub_t = rand_t + sub_t; //!< Subtract time offset or position
67  static const std::string randrot_t = rand_t + rot_t; //!< Rotate around z-axis by value [rad]
68  static const std::string randmul_t = rand_t + mul_t; //!< Multiply z-position by (1 + value)
69  static const std::string randdiv_t = rand_t + div_t; //!< Divide z-position by (1 + value)
70  static const std::string randtilt_t = rand_t + tilt_t; //!< Tilt string
71 
72  static const std::string RESET_t = "RESET"; //!< Reset time offset of piezo/hydrophone and quaternion calibration of compass
73  static const std::string SET_t = "SET"; //!< Set time offset of piezo/hydrophone or quaternion calibration of compass
74  static const std::string ADD_t = "ADD"; //!< Add time offset of piezo/hydrophone or quaternion calibration of compass
75  static const std::string SUB_t = "SUB"; //!< Subtract time offset of piezo/hydrophone or quaternion calibration of compass
76  static const std::string ROT_t = "ROT"; //!< Rotate quaternion calibration of compass around z-axis by value [rad]
77 
78 
79  /**
80  * Apply action to given module.
81  *
82  * \param module module (I/O)
83  * \param action action
84  * \return true if valid action; else false
85  */
86  inline bool apply(JModule& module, const std::string& action)
87  {
88  if (action == reset_t) {
89 
90  // position does not depend on module but may not exactly be at origin
91 
92  module.set(getModule<JKM3NeT_t>(1).getPosition());
93 
94  for (JModule::iterator pmt = module.begin(); pmt != module.end(); ++pmt) {
96  pmt->setStatus(JStatus());
97  }
98 
99  } else if (action == RESET_t) {
100 
101  module.setCalibration(JCalibration());
102  module.setQuaternion(JQuaternion3D());
103 
104  } else if (action == SET_t) {
105 
106  const double t0 = getAverage(make_array(module.begin(), module.end(), &JPMT::getT0), 0.0);
107 
108  if (module.getFloor() != 0)
109  module.getCalibration().setT0(t0 - PIEZO_DELAYTIME_US * 1.0e+3);
110  else
111  module.getCalibration().setT0(t0 - HYDROPHONE_DELAYTIME_US * 1.0e+3);
112 
113  } else {
114 
115  return false;
116  }
117 
118  return true;
119  }
120 
121 
122  /**
123  * Apply action to given module.
124  *
125  * \param module module (I/O)
126  * \param action action
127  * \param value value
128  * \return true if valid action; else false
129  */
130  inline bool apply(JModule& module, const std::string& action, const double value)
131  {
132  if (action == set_t) { // actions with fixed values
133 
134  module.set(value);
135 
136  } else if (action == setx_t) {
137 
138  module.set(JVector3D(value, module.getY(), module.getZ()));
139 
140  } else if (action == sety_t) {
141 
142  module.set(JVector3D(module.getX(), value, module.getZ()));
143 
144  } else if (action == setz_t) {
145 
146  module.set(JVector3D(module.getX(), module.getY(), value));
147 
148  } else if (action == add_t) {
149 
150  module.add(value);
151 
152  } else if (action == sub_t) {
153 
154  module.sub(value);
155 
156  } else if (action == rot_t) {
157 
158  const JVector3D center = module.getPosition();
159 
160  module.sub(center);
161 
162  module.rotate(JRotation3Z(value));
163 
164  module.add(center);
165 
166  } else if (action == mul_t) {
167 
168  const JVector3D center(module.getPosition().getX(),
169  module.getPosition().getY(),
170  module.getPosition().getZ() * (1.0 + value));
171 
172  module.set(center);
173 
174  } else if (action == div_t) {
175 
176  const JVector3D center(module.getPosition().getX(),
177  module.getPosition().getY(),
178  module.getPosition().getZ() / (1.0 + value));
179 
180  module.set(center);
181 
182  } else if (action == SET_t) {
183 
184  module.getCalibration().setT0(value);
185 
186  } else if (action == ADD_t) {
187 
188  module.getCalibration().addT0(value);
189 
190  } else if (action == SUB_t) {
191 
192  module.getCalibration().subT0(value);
193 
194  } else if (action == ROT_t) {
195 
196  module.setQuaternion(JQuaternion3Z(value) * module.getQuaternion());
197 
198  } else if (action == randadd_t) { // actions with random values
199 
200  module.add(gRandom->Gaus(0.0, value));
201 
202  } else if (action == randsub_t) {
203 
204  module.sub(gRandom->Gaus(0.0, value));
205 
206  } else if (action == randrot_t){
207 
208  const JVector3D center = module.getPosition();
209 
210  module.sub(center);
211 
212  module.rotate(JRotation3Z(gRandom->Gaus(0.0, value)));
213 
214  module.add(center);
215 
216  } else if (action == randmul_t) {
217 
218  const JVector3D center(module.getPosition().getX(),
219  module.getPosition().getY(),
220  module.getPosition().getZ() * gRandom->Gaus(1.0, value));
221 
222  module.set(center);
223 
224  } else if (action == randdiv_t) {
225 
226  const JVector3D center(module.getPosition().getX(),
227  module.getPosition().getY(),
228  module.getPosition().getZ() / gRandom->Gaus(1.0, value));
229 
230  module.set(center);
231 
232  } else if (action == assign_t) { // action with assigments
233 
234  module.setID((int) value);
235 
236  } else if (action == string_t) {
237 
238  module.setLocation(JLocation((int) value, module.getFloor()));
239 
240  } else { //
241 
242  return false;
243  }
244 
245  return true;
246  }
247 
248 
249  /**
250  * Apply action to given module.
251  *
252  * \param module module (I/O)
253  * \param action action
254  * \param first first value
255  * \param second second value
256  * \return true if valid action; else false
257  */
258  inline bool apply(JModule& module, const std::string& action, const double first, const double second)
259  {
260  if (action == tilt_t) { // actions with fixed values
261 
262  const double Tx = first;
263  const double Ty = second;
264  const double Tz = sqrt(1.0 - Tx*Tx - Ty*Ty);
265 
266  const double x = Tx * module.getZ() + module.getX();
267  const double y = Ty * module.getZ() + module.getY();
268  const double z = Tz * module.getZ();
269 
270  module.set(JPosition3D(x,y,z));
271 
272  } else if (action == locate_t) {
273 
274  module.setLocation(JLocation((int) first, (int) second));
275 
276  } else if (action == swap_t) {
277 
278  std::swap(module[(int) first], module[(int) second]);
279 
280  } else { //
281 
282  return false;
283  }
284 
285  return true;
286  }
287 
288 
289  /**
290  * Apply action to given module.
291  *
292  * \param module module (I/O)
293  * \param action action
294  * \param pos pos
295  * \return true if valid action; else false
296  */
297  inline bool apply(JModule& module, const std::string& action, const JVector3D& pos)
298  {
299  const JVector3D randpos(gRandom->Gaus(0.0, pos.getX()),
300  gRandom->Gaus(0.0, pos.getY()),
301  gRandom->Gaus(0.0, pos.getZ()));
302 
303  if (action == set_t) // actions with fixed values
304  module.set(pos);
305  else if (action == add_t)
306  module.add(pos);
307  else if (action == sub_t)
308  module.sub(pos);
309  else if (action == randset_t) // actions with random values
310  module.set(randpos);
311  else if (action == randadd_t)
312  module.add(randpos);
313  else if (action == randsub_t)
314  module.sub(randpos);
315  else
316  return false;
317 
318  return true;
319  }
320 
321 
322  /**
323  * Apply action to given module.
324  *
325  * \param module module (I/O)
326  * \param action action
327  * \param Q quaternion
328  * \return true if valid action; else false
329  */
330  inline bool apply(JModule& module, const std::string& action, const JQuaternion3D& Q)
331  {
332  if (action == SET_t)
333  module.setQuaternion(Q);
334  else if (action == ADD_t)
335  module.setQuaternion(Q * module.getQuaternion());
336  else if (action == SUB_t)
337  module.setQuaternion(Q.getConjugate() * module.getQuaternion());
338  else
339  return false;
340 
341  return true;
342  }
343 
344 
345  /**
346  * Apply action to given module.
347  *
348  * \param module module (I/O)
349  * \param action action
350  * \param value value
351  * \return true if valid action; else false
352  */
353  inline bool apply(JModule& module, const std::string& action, const std::string& value)
354  {
355  try {
356 
357  if (action == set_t)
358  module.getStatus().set (getModuleStatusBit(value));
359  else if (action == reset_t)
360  module.getStatus().reset(getModuleStatusBit(value));
361  else
362  return false;
363 
364  return true;
365  }
366  catch(const std::exception&) {
367  return false;
368  }
369  }
370 
371 
372  /**
373  * Apply action to given PMT.
374  *
375  * \param pmt PMT (I/O)
376  * \param action action
377  * \param value value
378  * \return true if valid action; else false
379  */
380  inline bool apply(JPMT& pmt, const std::string& action, const std::string& value)
381  {
382  try {
383 
384  if (action == set_t)
385  pmt.getStatus().set (getPMTStatusBit(value));
386  else if (action == reset_t)
387  pmt.getStatus().reset(getPMTStatusBit(value));
388  else
389  return false;
390 
391  return true;
392  }
393  catch(const std::exception&) {
394  return false;
395  }
396  }
397 
398 
399  /**
400  * Auxiliary class for module modifications.
401  */
402  struct JModifier {
403  /**
404  * Default constructor.
405  */
406  JModifier()
407  {}
408 
409 
410  /**
411  * Check validity.
412  *
413  * \return true if valid modifier; else false
414  */
415  bool is_valid() const
416  {
417  return (action != "" && !data.empty());
418  }
419 
420 
421  /**
422  * Apply action to given module depending on number of values.
423  *
424  * \param module module
425  * \return true if valid action; else false
426  */
427  bool apply(JModule& module) const
428  {
429  switch (data.size()) {
430 
431  case 0:
432  return ::apply(module, action);
433 
434  case 1:
435  return ::apply(module, action, data[0]);
436 
437  case 2:
438  return ::apply(module, action, data[0], data[1]);
439 
440  case 3:
441  return ::apply(module, action, JVector3D(data[0], data[1], data[2]));
442 
443  case 4:
444  return ::apply(module, action, JQuaternion3D(data[0], data[1], data[2], data[3]));
445 
446  default:
447  return false;
448  }
449  }
450 
451 
452  /**
453  * Read modifier from input.
454  *
455  * \param in input stream
456  * \param modifier modifier
457  * \return input stream
458  */
459  friend inline std::istream& operator>>(std::istream& in, JModifier& modifier)
460  {
461  if (in >> modifier.action) {
462 
463  modifier.data.clear();
464 
465  for (double x; in >> x; ) {
466  modifier.data.push_back(x);
467  }
468 
469  in.clear(std::ios_base::eofbit);
470  }
471 
472  return in;
473  }
474 
475 
476  /**
477  * Write modifier to output.
478  *
479  * \param out output stream
480  * \param modifier modifier
481  * \return output stream
482  */
483  friend inline std::ostream& operator<<(std::ostream& out, const JModifier& modifier)
484  {
485  out << modifier.action;
486 
487  for (std::vector<double>::const_iterator i = modifier.data.begin(); i != modifier.data.end(); ++i) {
488  out << ' ' << *i;
489  }
490 
491  return out;
492  }
493 
494 
495  std::string action;
496  std::vector<double> data;
497  };
498 
499 
500  /**
501  * Get modifier for given string.
502  *
503  * For actions <tt>ranXXX</tt>, the corresponding action <tt>XXX</tt> is made the same for all modules in the given string.\n
504  * For all other options, the input action is maintained.
505  *
506  * \param id string number
507  * \param modifier modifier
508  * \return modifier
509  */
510  inline const JModifier& getModifier(const int id, const JModifier& modifier)
511  {
512  using namespace std;
513 
515 
516  const string::size_type pos = modifier.action.find(rand_t);
517 
518  if (pos != string::npos) {
519 
520  JModifier& result = buffer[id][modifier.action][modifier.data.size()];
521 
522  if (!result.is_valid()) {
523 
524  result.action = modifier.action.substr(pos + rand_t.length());
525 
526  for (size_t i = 0; i != modifier.data.size(); ++i) {
527  result.data.push_back(gRandom->Gaus(0.0, modifier.data[i]));
528  }
529  }
530 
531  return result;
532 
533  } else {
534 
535  return modifier;
536  }
537  }
538 
539 
540  /**
541  * Auxiliary class for module status modifications.
542  */
543  struct JModuleModifier {
544  /**
545  * Default constructor.
546  */
547  JModuleModifier()
548  {}
549 
550 
551  /**
552  * Apply action to given module.
553  *
554  * \param module module
555  * \return true if valid action; else false
556  */
557  bool apply(JModule& module) const
558  {
559  return ::apply(module, action, value);
560  }
561 
562 
563  /**
564  * Read module modifier from input.
565  *
566  * \param in input stream
567  * \param modifier modifier
568  * \return input stream
569  */
570  friend inline std::istream& operator>>(std::istream& in, JModuleModifier& modifier)
571  {
572  return in >> modifier.action >> modifier.value;
573  }
574 
575 
576  /**
577  * Write module modifier to output.
578  *
579  * \param out output stream
580  * \param modifier modifier
581  * \return output stream
582  */
583  friend inline std::ostream& operator<<(std::ostream& out, const JModuleModifier& modifier)
584  {
585  out << modifier.action;
586  out << ' ';
587  out << modifier.value;
588 
589  return out;
590  }
591 
592 
593  std::string action;
594  std::string value;
595  };
596 
597 
598  /**
599  * Auxiliary class for PMT status modifications.
600  */
601  struct JPMTModifier {
602  /**
603  * Default constructor.
604  */
605  JPMTModifier()
606  {}
607 
608 
609  /**
610  * Apply action to given PMT.
611  *
612  * \param pmt PMT
613  * \return true if valid action; else false
614  */
615  bool apply(JPMT& pmt) const
616  {
617  return ::apply(pmt, action, value);
618  }
619 
620 
621  /**
622  * Read PMT modifier from input.
623  *
624  * \param in input stream
625  * \param modifier modifier
626  * \return input stream
627  */
628  friend inline std::istream& operator>>(std::istream& in, JPMTModifier& modifier)
629  {
630  return in >> modifier.action >> modifier.value;
631  }
632 
633 
634  /**
635  * Write PMT modifier to output.
636  *
637  * \param out output stream
638  * \param modifier modifier
639  * \return output stream
640  */
641  friend inline std::ostream& operator<<(std::ostream& out, const JPMTModifier& modifier)
642  {
643  out << modifier.action;
644  out << ' ';
645  out << modifier.value;
646 
647  return out;
648  }
649 
650 
651  std::string action;
652  std::string value;
653  };
654 
655 
656  /**
657  * Range of string numbers.
658  *
659  * The input format could be a single number or two numbers separated by JRange_t::SEPARATOR.
660  */
661  struct JRange_t :
662  public JRange<int>
663  {
664  /**
665  * Separator between two identifier values.
666  */
667  static const char SEPARATOR = '-';
668 
669  /**
670  * Default constructor.
671  */
672  JRange_t() :
673  JRange(-1, -1)
674  {}
675 
676 
677  /**
678  * Read range from input.
679  *
680  * \param in input stream
681  * \param range range
682  * \return input stream
683  */
684  friend inline std::istream& operator>>(std::istream& in, JRange_t& range)
685  {
686  if (in >> range.first) {
687 
688  range.second = range.first;
689 
690  if (in.peek() == (int) JRange_t::SEPARATOR) {
691 
692  in.get();
693 
694  in >> range.second;
695 
696  } else {
697 
698  in.clear();
699  }
700  }
701 
702  return in;
703  }
704 
705 
706  /**
707  * Write range to output.
708  *
709  * \param out output stream
710  * \param range range
711  * \return output stream
712  */
713  friend inline std::ostream& operator<<(std::ostream& out, const JRange_t& range)
714  {
715  return out << range.first << JRange_t::SEPARATOR << range.second;
716  }
717  };
718 
719 
720  /**
721  * Print module modification.
722  *
723  * \param out output stream
724  * \param module module
725  * \param modifier modifier
726  */
727  inline void print(std::ostream& out, const JModule& module, const JModifier& modifier)
728  {
729  using namespace std;
730  using namespace JPP;
731 
732  out << "Modifier" << ' '
733  << "(" << FILL(4,'0') << module.getString() << "," << FILL(2,'0') << module.getFloor() << FILL() << ")" << ' '
734  << setw(10) << module.getID() << ' '
735  << "action" << ' ' << modifier.action << JEEPZ() << modifier.data << endl;
736  }
737 
738 
739  /**
740  * Print module modification.
741  *
742  * \param out output stream
743  * \param id module identifier
744  * \param modifier modifier
745  */
746  inline void print(std::ostream& out, const JModuleIdentifier& id, const JModuleModifier& modifier)
747  {
748  using namespace std;
749  using namespace JPP;
750 
751  out << "module modifier" << ' '
752  << "(" << setw(10) << id.getID() << ")" << ' '
753  << "action" << ' ' << modifier.action << ' '
754  << "value" << ' ' << modifier.value << endl;
755  }
756 
757 
758  /**
759  * Print PMT modification.
760  *
761  * \param out output stream
762  * \param pmt PMT identifier
763  * \param modifier modifier
764  */
765  inline void print(std::ostream& out, const JPMTIdentifier& pmt, const JPMTModifier& modifier)
766  {
767  using namespace std;
768  using namespace JPP;
769 
770  out << "PMT modifier" << ' '
771  << "(" << setw(10) << pmt.getID() << "," << setw(2) << pmt.getPMTAddress() << ")" << ' '
772  << "action" << ' ' << modifier.action << ' '
773  << "value" << ' ' << modifier.value << endl;
774  }
775 }
776 
777 
778 /**
779  * \file
780  *
781  * Auxiliary program to modify detector calibration.
782  *
783  * Syntax:
784  * <pre>
785  * -M "<module identifier> (set|add|sub|randset|randadd|randsub) x0 [x1 x2]"
786  * -(S|s) "<string number> (set|add|sub|randset|randadd|randsub) x0 [x1 x2]"
787  * -M "<module identifier> (rot|randrot) phi"
788  * -(S|s) "<string number> (rot|randrot) phi"
789  * -M "<module identifier> (mul|randmul) factor"
790  * -(S|s) "<string number> (mul|randmul) factor"
791  * -M "<module identifier> (div|randdiv) factor"
792  * -(S|s) "<string number> (div|randdiv) factor"
793  * -M "<module identifier> (reset)"
794  * -(S|s) "<string number> (reset)"
795  * -M "<module identifier> (assign) identifier"
796  * -M "<module identifier> (locate) <string> <floor>"
797  * -M "<module identifier> (swap) <PMT> <PMT>"
798  * -M "<module identifier> (SET|ADD|SUB|) x0 [x1 x2 x3]"
799  * -(S|s) "<string number> (SET|ADD|SUB|) x0 [x1 x2 x3]"
800  * -M "<module identifier> (ROT) phi"
801  * -(S|s) "<string number> (ROT) phi"
802  * -M "<module identifier> (SET)"
803  * -(S|s) "<string number> (SET)"
804  * -(S|s) "<string number> (tilt|randtilt) Tx Ty"
805  * -W "<module identifier> (set|reset) (MODULE_DISABLE|COMPASS_DISABLE|HYDROPHONE_DISABLE|PIEZO_DISABLE|MODULE_OUT_OF_SYNC)"
806  * -P "<PMT identifier> (set|reset) (PMT_DISABLE|HIGH_RATE_VETO_DISABLE|FIFO_FULL_DISABLE|UDP_COUNTER_DISABLE|UDP_TRAILER_DISABLE|OUT_OF_SYNC)"
807  * -p "<PMT physical address> (set|reset) (PMT_DISABLE|HIGH_RATE_VETO_DISABLE|FIFO_FULL_DISABLE|UDP_COUNTER_DISABLE|UDP_TRAILER_DISABLE|OUT_OF_SYNC)"
808  * -k "<string number>[-<string number>]"
809  * -r "<string number>[-<string number>]"
810  * -m "<module identifier>"
811  * -D "<string number> <floor>"
812  * -\@ "<key>=<value>[;<key>=<value>"
813  * </pre>
814  * Options <tt>-M</tt> and <tt>-S</tt> refer to a module and a string, respectively.\n
815  * The values provided for a string modification coherently apply to the modules of the specified string number.\n
816  * The option <tt>-s</tt> is equivalent to option <tt>-S</tt> except that
817  * the action applies only to the optical modules in the string and not the base module.
818  *
819  * The options <tt>randxxx</tt> correspond to a randomisation of the specified option.
820  *
821  * If the module identifier or string number is -1,
822  * the action is applied to all modules or strings in the detector, respectively.
823  *
824  * For options <tt>[rand]set</tt>, <tt>[rand]add</tt> and <tt>[rand]sub</tt>,
825  * the number of values apply to position or time calibration in the following way:
826  * -# time calibration <tt>(t = x0)</tt>
827  * -# invalid
828  * -# position calibration <tt>(x = x0, y = x1, z = x2)</tt>
829  *
830  * For options <tt>[rand]rot</tt>,
831  * the angle <tt>phi</tt> refers to an anti-clockwise rotation around the z-axis.\n
832  * The rotation angle is defined in radians.
833  *
834  * For options <tt>[rand]mul</tt> and <tt>[rand]div</tt>,
835  * the multiplication/division <tt>factor</tt> (a.k.a.\ "stretching") applies to the z-coordinates of the modules.\n
836  * The factor is defined as a fraction; the actual multiplication/division factor is <tt>(1 + factor)</tt>.
837  *
838  * For options <tt>SET</tt>, <tt>ADD</tt> and <tt>SUB</tt>,
839  * the number of values apply to time or quaternion calibration of the module in the following way:
840  * -# time calibration of piezo sensor or hydrophone <tt>(t = x0)</tt>
841  * -# invalid
842  * -# invalid
843  * -# quaternion calibration of compass <tt>(qa = x0, qb = x1, qc = x2, qd = x3)</tt>
844  *
845  * For options <tt>ROT</tt>,
846  * the angle <tt>phi</tt> refers to an anti-clockwise rotation around the z-axis of the quaternion calibration of the compass.\n
847  * The rotation angle is defined in radians.
848  *
849  * If no values are given at the option <tt>SET</tt>,
850  * - the time calibration of the piezo sensor is set to the average time calibration of the PMTs in that module,
851  * - the time calibration of the hydrophone is set to 0.
852  *
853  * In this, the time calibration is corrected for the delay time of the piezo sensor and hydrophone \n
854  * which are defined by JDETECTOR::PIEZO_DELAYTIME_US and JDETECTOR::HYDROPHONE_DELAYTIME_US, respectively.\n
855  *
856  * The units of all positions and time values are <tt>m</tt> and <tt>ns</tt>, respectively.
857  *
858  * Note that for string modifiers with option <tt>randxxx</tt>,
859  * the action is coherently applied to the modules in the specified string.\n
860  * Only one type of action (defined by <tt>xxx</tt> and the number of values) is then allowed per string.
861  *
862  * Option <tt>-\@</tt> refers to the header information.\n
863  * The list of possible keys can be obtained using JPrintDetector.cc with option <tt>-O header</tt>.
864  *
865  * Multiple options <tt>-M</tt>, <tt>-S</tt>, <tt>-s</tt> or <tt>-\@</tt> will be processed in order of appearance.
866  *
867  * Options <tt>-k</tt> and <tt>-r</tt> can be used to keep and remove (a range of) string numbers, respectively.
868  *
869  * The options <tt>-m</tt> and <tt>-D</tt> can be used to maintain a specific module (and remove all others) and
870  * to delete a floor from a string, respectively.
871  *
872  * Note finally that if the output file name is the same as the input file name,
873  * the original file will be overwritten.
874  *
875  * \author mdejong
876  */
877 int main(int argc, char **argv)
878 {
879  using namespace std;
880  using namespace JPP;
881 
882  typedef JToken<';'> JToken_t;
883 
884  string inputFile;
885  string outputFile;
886  vector<JToken_t> hdr;
890  vector< pair<int,
891  JModuleModifier> > wip;
893  JPMTModifier> > pmt;
895  JPMTModifier> > alt;
896  vector<JRange_t> keep;
898  vector<int> id;
899  multimap<int, int> del;
900  int option;
901  int debug;
902 
903  try {
904 
905  JParser<> zap("Auxiliary program to modify detector.");
906 
907  zap['a'] = make_field(inputFile);
908  zap['o'] = make_field(outputFile);
909  zap['@'] = make_field(hdr, "header modification") = JPARSER::initialised();
910  zap['M'] = make_field(mod, "module modification") = JPARSER::initialised();
911  zap['S'] = make_field(str, "string modification (optical modules and base module") = JPARSER::initialised();
912  zap['s'] = make_field(dos, "string modification (optical modules only)") = JPARSER::initialised();
913  zap['W'] = make_field(wip, "module status modification") = JPARSER::initialised();
914  zap['P'] = make_field(pmt, "PMT status modification by PMT logical address") = JPARSER::initialised();
915  zap['p'] = make_field(alt, "PMT status modification by PMT physical address") = JPARSER::initialised();
916  zap['k'] = make_field(keep, "keep string[s]") = JPARSER::initialised();
917  zap['r'] = make_field(rm, "remove string[s]") = JPARSER::initialised();
918  zap['m'] = make_field(id, "remove module by identifier") = JPARSER::initialised();
919  zap['D'] = make_field(del, "remove module by location") = JPARSER::initialised();
920  zap['O'] = make_field(option, "sort modules") = 0, 1, 2;
921  zap['d'] = make_field(debug) = 2;
922 
923  zap(argc, argv);
924  }
925  catch(const exception &error) {
926  FATAL(error.what() << endl);
927  }
928 
930 
931  try {
932  load(inputFile, detector);
933  }
934  catch(const JException& error) {
935  FATAL(error);
936  }
937 
938 
939  gRandom->SetSeed(0);
940 
941 
942  if ((keep.empty() ? 0 : 1 +
943  rm .empty() ? 0 : 1 +
944  id .empty() ? 0 : 1) > 1) {
945  FATAL("Use either option -k, -r or -m." << endl);
946  }
947 
948 
949  detector.comment.add(JMeta(argc,argv));
950 
951  if (detector.setToLatestVersion()) {
952  NOTICE("Set detector version to " << detector.getVersion() << endl);
953  }
954 
955 
956  if (!hdr.empty()) {
957 
958  int id = -1;
959 
960  JProperties helper = detector.getProperties();
961 
962  helper["id"] = id;
963 
964  for (vector<JToken_t>::const_iterator i = hdr.begin(); i != hdr.end(); ++i) {
965 
966  istringstream is(*i);
967 
968  is >> helper;
969  }
970 
971  if (id != -1) {
972  detector.setID(id);
973  }
974  }
975 
976 
977  for (JDetector::iterator module = detector.begin(); module != detector.end(); ) {
978 
979  bool __rm__ = !keep.empty() && rm.empty();
980 
981  for (vector<JRange_t>::const_iterator i = keep.begin(); i != keep.end(); ++i) {
982  if (module->getString() >= i->first && module->getString() <= i->second) {
983  __rm__ = false;
984  }
985  }
986 
987  for (vector<JRange_t>::const_iterator i = rm.begin(); i != rm.end(); ++i) {
988  if (module->getString() >= i->first && module->getString() <= i->second) {
989  __rm__ = true;
990  }
991  }
992 
993  if (!id.empty()) {
994  __rm__ = find(id.begin(), id.end(), module->getID()) == id.end();
995  }
996 
997  const auto range = del.equal_range(module->getString());
998 
999  for (auto i = range.first; i != range.second; ++i) {
1000  if (i->second == module->getFloor()) {
1001  __rm__ = true;
1002  }
1003  }
1004 
1005  if (__rm__)
1006  module = detector.erase(module);
1007  else
1008  ++module;
1009  }
1010 
1011 
1012  for (vector< pair<int, JModifier> >::const_iterator i = mod.begin(); i != mod.end(); ++i) {
1013 
1014  for (JDetector::iterator module = detector.begin(); module != detector.end(); ++module) {
1015 
1016  if (module->getID() == i->first || i->first == WILDCARD ){
1017 
1018  if (debug >= debug_t) {
1019  print(cout, *module, i->second);
1020  }
1021 
1022  if (!i->second.apply(*module)) {
1023  ERROR("No valid action: " << i->first << ' ' << i->second << endl);
1024  }
1025  }
1026  }
1027  }
1028 
1029 
1030  for (vector< pair<int, JModifier> >::const_iterator i = str.begin(); i != str.end(); ++i) {
1031 
1032  for (JDetector::iterator module = detector.begin(); module != detector.end(); ++module) {
1033 
1034  if (module->getString() == i->first || i->first == WILDCARD) {
1035 
1036  const JModifier modifier = getModifier(module->getString(), i->second);
1037 
1038  if (debug >= debug_t) {
1039  print(cout, *module, i->second);
1040  }
1041 
1042  if (!modifier.apply(*module)) {
1043  ERROR("No valid action: " << i->first << ' ' << i->second << endl);
1044  }
1045  }
1046  }
1047  }
1048 
1049 
1050  for (vector< pair<int, JModifier> >::const_iterator i = dos.begin(); i != dos.end(); ++i) {
1051 
1052  for (JDetector::iterator module = detector.begin(); module != detector.end(); ++module) {
1053 
1054  if (module->getFloor() != 0) {
1055 
1056  if (module->getString() == i->first || i->first == WILDCARD) {
1057 
1058  const JModifier modifier = getModifier(module->getString(), i->second);
1059 
1060  if (debug >= debug_t) {
1061  print(cout, *module, i->second);
1062  }
1063 
1064  if (!modifier.apply(*module)) {
1065  ERROR("No valid action: " << i->first << ' ' << i->second << endl);
1066  }
1067  }
1068  }
1069  }
1070  }
1071 
1072 
1073  for (vector< pair<int, JModuleModifier> >::const_iterator i = wip.begin(); i != wip.end(); ++i) {
1074 
1075  for (JDetector::iterator module = detector.begin(); module != detector.end(); ++module) {
1076 
1077  if (module->getID() == i->first || i->first == WILDCARD ){
1078 
1079  if (debug >= debug_t) {
1080  print(cout, *module, i->second);
1081  }
1082 
1083  if (!i->second.apply(*module)) {
1084  ERROR("No valid action: " << i->first << ' ' << i->second << endl);
1085  }
1086  }
1087  }
1088  }
1089 
1090 
1091  for (vector< pair<JPMTIdentifier, JPMTModifier> >::const_iterator i = pmt.begin(); i != pmt.end(); ++i) {
1092 
1093  for (JDetector::iterator module = detector.begin(); module != detector.end(); ++module) {
1094 
1095  if (module->getID() == i->first.getModuleID() || i->first.getModuleID() == WILDCARD) {
1096 
1097  if (debug >= debug_t) {
1098  print(cout, i->first, i->second);
1099  }
1100 
1101  if (i->first.getPMTAddress() == WILDCARD) {
1102 
1103  for (int pmt = 0; pmt != getNumberOfPMTs(*module); ++pmt) {
1104  if (!i->second.apply(module->getPMT(pmt))) {
1105  ERROR("No valid action: " << i->first << ' ' << i->second << endl);
1106  }
1107  }
1108 
1109  } else if (i->first.getPMTAddress() < 0 ||
1110  i->first.getPMTAddress() >= getNumberOfPMTs(*module) ||
1111  !i->second.apply(module->getPMT(i->first.getPMTAddress()))) {
1112  ERROR("No valid action: " << i->first << ' ' << i->second << endl);
1113  }
1114  }
1115  }
1116  }
1117 
1118 
1119  if (!alt.empty()) {
1120 
1121  if (!hasDetectorAddressMap(detector.getID())) {
1122  FATAL("Invalid detector identifier " << detector.getID() << endl);
1123  }
1124 
1125  const JDetectorAddressMap& demo = getDetectorAddressMap(detector.getID());
1126 
1127  for (JDetector::iterator module = detector.begin(); module != detector.end(); ++module) {
1128 
1129  const JModuleAddressMap memo = demo.get(module->getID());
1130 
1131  for (vector< pair<JPMTPhysicalAddress, JPMTModifier> >::const_iterator i = alt.begin(); i != alt.end(); ++i) {
1132 
1133  const JPMTIdentifier id(module->getID(), memo.getAddressTranslator(i->first).tdc);
1134 
1135  if (debug >= debug_t) {
1136  print(cout, id, i->second);
1137  }
1138 
1139  if (!i->second.apply(module->getPMT(id.getPMTAddress()))) {
1140  ERROR("No valid action: " << i->first << ' ' << i->second << endl);
1141  }
1142  }
1143  }
1144  }
1145 
1146 
1147  switch (option) {
1148  case 1:
1149  sort(detector.begin(), detector.end(), make_comparator(&JModule::getID));
1150  break;
1151 
1152  case 2:
1153  sort(detector.begin(), detector.end(), make_comparator(&JModule::getLocation));
1154  break;
1155 
1156  default:
1157  break;
1158  };
1159 
1160 
1161  try {
1163  }
1164  catch(const JException& error) {
1165  FATAL(error);
1166  }
1167 }
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: JPMTStatus.hh:65
Exceptions.
Q(UTCMax_s-UTCMin_s)-livetime_s
debug
Definition: JMessage.hh:29
int main(int argc, char *argv[])
Definition: Main.cc:15
JComparator< JResult_t T::*, JComparison::lt > make_comparator(JResult_t T::*member)
Helper method to create comparator between values of data member.
Definition: JComparator.hh:185
int getFloor() const
Get floor number.
Definition: JLocation.hh:145
Data structure for a composite optical module.
Definition: JModule.hh:68
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
const JCalibration & getCalibration() const
Get calibration.
Detector data structure.
Definition: JDetector.hh:89
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.
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
void reset(const int bit)
Reset PMT status.
Definition: JStatus.hh:130
Data structure for time calibration.
static const JGetModuleStatusBit getModuleStatusBit
Function object to map key to module status bit.
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:442
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
const JLocation & getLocation() const
Get location.
Definition: JLocation.hh:69
void set(const int bit)
Set PMT status.
Definition: JStatus.hh:119
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
Auxiliary class for handling status.
Definition: JStatus.hh:37
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:43
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:173
void rotate(const JRotation3D &R)
Rotate module.
Definition: JModule.hh:319
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.
const JStatus & getStatus() const
Get status.
Definition: JStatus.hh:63
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.
Auxiliary class for object identification.
Definition: JObjectID.hh:22
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:41
JModule & set(const JVector3D &pos)
Set position.
Definition: JModule.hh:412
double getZ() const
Get z position.
Definition: JVector3D.hh:115
JModule & add(const JVector3D &pos)
Add position.
Definition: JModule.hh:424
double getT0() const
Get time offset.