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