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