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