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