Jpp - 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 
7 #include "TRandom3.h"
8 
9 #include "JDetector/JDetector.hh"
18 #include "JGeometry3D/JVector3D.hh"
19 #include "JMath/JConstants.hh"
20 #include "JMath/JMath.hh"
21 #include "JTools/JRange.hh"
22 #include "JLang/JException.hh"
23 #include "JLang/JToken.hh"
24 #include "JSupport/JMeta.hh"
25 
26 #include "Jeep/JeepToolkit.hh"
27 #include "Jeep/JPrint.hh"
28 #include "Jeep/JParser.hh"
29 #include "Jeep/JMessage.hh"
30 
31 
32 namespace {
33 
34  using namespace JPP;
35 
36  /**
37  * Wild card for string identifier, module identifier or PMT address.
38  */
39  static const int WILDCARD = -1;
40 
41  static const std::string reset_t = "reset"; //!< Reset time offset, position and PMT status bit
42  static const std::string set_t = "set"; //!< Set time offset, position or PMT status bit
43  static const std::string add_t = "add"; //!< Add time offset or position
44  static const std::string sub_t = "sub"; //!< Subtract time offset or position
45  static const std::string rot_t = "rot"; //!< Rotate around z-axis by value [rad]
46  static const std::string mul_t = "mul"; //!< Multiply z-position by (1 + value)
47  static const std::string tilt_t = "tilt"; //!< Tilt string
48 
49  static const std::string assign_t = "assign"; //!< Assign module identifier
50  static const std::string string_t = "string"; //!< Assign string number
51 
52  static const std::string rand_t = "rand"; //!< Random value(s)
53  static const std::string randset_t = rand_t + set_t; //!< Set time offset or position
54  static const std::string randadd_t = rand_t + add_t; //!< Add time offset or position
55  static const std::string randsub_t = rand_t + sub_t; //!< Subtract time offset or position
56  static const std::string randrot_t = rand_t + rot_t; //!< Rotate around z-axis by value [rad]
57  static const std::string randmul_t = rand_t + mul_t; //!< Multiply z-position by (1 + value)
58  static const std::string randtilt_t = rand_t + tilt_t; //!< Tilt string
59 
60  static const std::string RESET_t = "RESET"; //!< Reset time offset of piezo/hydrophone and quaternion calibration of compass
61  static const std::string SET_t = "SET"; //!< Set time offset of piezo/hydrophone or quaternion calibration of compass
62  static const std::string ADD_t = "ADD"; //!< Add time offset of piezo/hydrophone or quaternion calibration of compass
63  static const std::string SUB_t = "SUB"; //!< Subtract time offset of piezo/hydrophone or quaternion calibration of compass
64  static const std::string ROT_t = "ROT"; //!< Rotate quaternion calibration of compass around z-axis by value [rad]
65 
66 
67  /**
68  * Apply action to given module.
69  *
70  * \param module module (I/O)
71  * \param action action
72  * \return true if valid action; else false
73  */
74  inline bool apply(JModule& module, const std::string& action)
75  {
76  if (action == reset_t) {
77 
79 
80  for (JModule::iterator pmt = module.begin(); pmt != module.end(); ++pmt) {
82  pmt->setStatus(JStatus());
83  }
84 
85  } else if (action == RESET_t) {
86 
87  module.setCalibration(JCalibration());
88  module.setQuaternion(JQuaternion3D());
89 
90  } else if (action == SET_t) {
91 
92  const double t0 = getAverage(make_array(module.begin(), module.end(), &JPMT::getT0), 0.0);
93 
94  if (module.getFloor() != 0)
95  module.setT0(t0 - PIEZO_DELAYTIME_US * 1.0e+3);
96  else
97  module.setT0(t0 - HYDROPHONE_DELAYTIME_US * 1.0e+3);
98 
99  } else {
100 
101  return false;
102  }
103 
104  return true;
105  }
106 
107 
108  /**
109  * Apply action to given module.
110  *
111  * \param module module (I/O)
112  * \param action action
113  * \param value value
114  * \return true if valid action; else false
115  */
116  inline bool apply(JModule& module, const std::string& action, const double value)
117  {
118  if (action == set_t) { // actions with fixed values
119 
120  module.set(value);
121 
122  } else if (action == add_t) {
123 
124  module.add(value);
125 
126  } else if (action == sub_t) {
127 
128  module.sub(value);
129 
130  } else if (action == rot_t) {
131 
132  const JVector3D center = module.getPosition();
133 
134  module.sub(center);
135 
136  module.rotate(JRotation3Z(value));
137 
138  module.add(center);
139 
140  } else if (action == mul_t) {
141 
142  const JVector3D center(module.getPosition().getX(),
143  module.getPosition().getY(),
144  module.getPosition().getZ() * (1.0 + value));
145 
146  module.set(center);
147 
148  } else if (action == SET_t) {
149 
150  module.setT0(value);
151 
152  } else if (action == ADD_t) {
153 
154  module.addT0(value);
155 
156  } else if (action == SUB_t) {
157 
158  module.subT0(value);
159 
160  } else if (action == ROT_t) {
161 
162  module.setQuaternion(JQuaternion3Z(value) * module.getQuaternion());
163 
164  } else if (action == randadd_t) { // actions with random values
165 
166  module.add(gRandom->Gaus(0.0, value));
167 
168  } else if (action == randsub_t) {
169 
170  module.sub(gRandom->Gaus(0.0, value));
171 
172  } else if (action == randrot_t){
173 
174  const JVector3D center = module.getPosition();
175 
176  module.sub(center);
177 
178  module.rotate(JRotation3Z(gRandom->Gaus(0.0, value)));
179 
180  module.add(center);
181 
182  } else if (action == randmul_t) {
183 
184  if (module.getFloor() != 0) {
185 
186  const JVector3D center(module.getPosition().getX(),
187  module.getPosition().getY(),
188  module.getPosition().getZ() * gRandom->Gaus(1.0, value));
189 
190  module.set(center);
191  }
192 
193  } else if (action == assign_t) { // action with assigments
194 
195  module.setID((int) value);
196 
197  } else if (action == string_t) {
198 
199  module.setLocation(JLocation((int) value, module.getFloor()));
200 
201  } else { //
202 
203  return false;
204  }
205 
206  return true;
207  }
208 
209 
210  /**
211  * Apply action to given module.
212  *
213  * \param module module (I/O)
214  * \param action action
215  * \param first first value
216  * \param second second value
217  * \return true if valid action; else false
218  */
219  inline bool apply(JModule& module, const std::string& action, const double first, const double second)
220  {
221  if (action == tilt_t) { // actions with fixed values
222 
223  const double Tx = first;
224  const double Ty = second;
225  const double Tz = sqrt(1.0 - Tx*Tx - Ty*Ty);
226 
227  const double x = Tx * module.getZ() + module.getX();
228  const double y = Ty * module.getZ() + module.getY();
229  const double z = Tz * module.getZ();
230 
231  module.set(JPosition3D(x,y,z));
232 
233  } else { //
234 
235  return false;
236  }
237 
238  return true;
239  }
240 
241 
242  /**
243  * Apply action to given module.
244  *
245  * \param module module (I/O)
246  * \param action action
247  * \param pos pos
248  * \return true if valid action; else false
249  */
250  inline bool apply(JModule& module, const std::string& action, const JVector3D& pos)
251  {
252  const JVector3D randpos(gRandom->Gaus(0.0, pos.getX()),
253  gRandom->Gaus(0.0, pos.getY()),
254  gRandom->Gaus(0.0, pos.getZ()));
255 
256  if (action == set_t) // actions with fixed values
257  module.set(pos);
258  else if (action == add_t)
259  module.add(pos);
260  else if (action == sub_t)
261  module.sub(pos);
262  else if (action == randset_t) // actions with random values
263  module.set(randpos);
264  else if (action == randadd_t)
265  module.add(randpos);
266  else if (action == randsub_t)
267  module.sub(randpos);
268  else
269  return false;
270 
271  return true;
272  }
273 
274 
275  /**
276  * Apply action to given module.
277  *
278  * \param module module (I/O)
279  * \param action action
280  * \param Q quaternion
281  * \return true if valid action; else false
282  */
283  inline bool apply(JModule& module, const std::string& action, const JQuaternion3D& Q)
284  {
285  if (action == SET_t)
286  module.setQuaternion(Q);
287  else if (action == ADD_t)
288  module.setQuaternion(Q * module.getQuaternion());
289  else if (action == SUB_t)
290  module.setQuaternion(Q.getConjugate() * module.getQuaternion());
291  else
292  return false;
293 
294  return true;
295  }
296 
297 
298  /**
299  * Apply action to given PMT.
300  *
301  * \param pmt PMT (I/O)
302  * \param action action
303  * \param value value
304  * \return true if valid action; else false
305  */
306  inline bool apply(JPMT& pmt, const std::string& action, const std::string& value)
307  {
308  try {
309 
310  if (action == set_t)
311  pmt.set(getPMTStatusBit(value));
312  else if (action == reset_t)
313  pmt.reset(getPMTStatusBit(value));
314  else
315  return false;
316 
317  return true;
318  }
319  catch(const std::exception&) {
320  return false;
321  }
322  }
323 
324 
325  /**
326  * Auxiliary class for module modifications.
327  */
328  struct JModifier {
329  /**
330  * Default constructor.
331  */
332  JModifier()
333  {}
334 
335 
336  /**
337  * Check validity.
338  *
339  * \return true if valid modifier; else false
340  */
341  bool is_valid() const
342  {
343  return (action != "" && !data.empty());
344  }
345 
346 
347  /**
348  * Apply action to given module depending on number of values.
349  *
350  * \param module module
351  * \return true if valid action; else false
352  */
353  bool apply(JModule& module) const
354  {
355  switch (data.size()) {
356 
357  case 0:
358  return ::apply(module, action);
359 
360  case 1:
361  return ::apply(module, action, data[0]);
362 
363  case 2:
364  return ::apply(module, action, data[0], data[1]);
365 
366  case 3:
367  return ::apply(module, action, JVector3D(data[0], data[1], data[2]));
368 
369  case 4:
370  return ::apply(module, action, JQuaternion3D(data[0], data[1], data[2], data[3]));
371 
372  default:
373  return false;
374  }
375  }
376 
377 
378  /**
379  * Read modifier from input.
380  *
381  * \param in input stream
382  * \param modifier modifier
383  * \return input stream
384  */
385  friend inline std::istream& operator>>(std::istream& in, JModifier& modifier)
386  {
387  if (in >> modifier.action) {
388 
389  modifier.data.clear();
390 
391  for (double x; in >> x; ) {
392  modifier.data.push_back(x);
393  }
394 
395  in.clear(std::ios_base::eofbit);
396  }
397 
398  return in;
399  }
400 
401 
402  /**
403  * Write modifier to output.
404  *
405  * \param out output stream
406  * \param modifier modifier
407  * \return output stream
408  */
409  friend inline std::ostream& operator<<(std::ostream& out, const JModifier& modifier)
410  {
411  out << modifier.action;
412 
413  for (std::vector<double>::const_iterator i = modifier.data.begin(); i != modifier.data.end(); ++i) {
414  out << ' ' << *i;
415  }
416 
417  return out;
418  }
419 
420 
421  std::string action;
422  std::vector<double> data;
423  };
424 
425 
426  /**
427  * Get modifier for given string.
428  *
429  * For actions <tt>ranXXX</tt>, the corresponding action <tt>XXX</tt> is made the same for all modules in the given string.\n
430  * For all other options, the input action is maintained.
431  *
432  * \param id string number
433  * \param modifier modifier
434  * \return modifier
435  */
436  inline const JModifier& getModifier(const int id, const JModifier& modifier)
437  {
438  using namespace std;
439 
441 
442  const string::size_type pos = modifier.action.find(rand_t);
443 
444  if (pos != string::npos) {
445 
446  JModifier& result = buffer[id][modifier.action][modifier.data.size()];
447 
448  if (!result.is_valid()) {
449 
450  result.action = modifier.action.substr(pos + rand_t.length());
451 
452  for (size_t i = 0; i != modifier.data.size(); ++i) {
453  result.data.push_back(gRandom->Gaus(0.0, modifier.data[i]));
454  }
455  }
456 
457  return result;
458 
459  } else {
460 
461  return modifier;
462  }
463  }
464 
465 
466  /**
467  * Auxiliary class for PMT status modifications.
468  */
469  struct JPMTModifier {
470  /**
471  * Default constructor.
472  */
473  JPMTModifier()
474  {}
475 
476 
477  /**
478  * Apply action to given PMT.
479  *
480  * \param pmt PMT
481  * \return true if valid action; else false
482  */
483  bool apply(JPMT& pmt) const
484  {
485  return ::apply(pmt, action, value);
486  }
487 
488 
489  /**
490  * Read PMT modifier from input.
491  *
492  * \param in input stream
493  * \param modifier modifier
494  * \return input stream
495  */
496  friend inline std::istream& operator>>(std::istream& in, JPMTModifier& modifier)
497  {
498  return in >> modifier.action >> modifier.value;
499  }
500 
501 
502  /**
503  * Write modifier to output.
504  *
505  * \param out output stream
506  * \param modifier modifier
507  * \return output stream
508  */
509  friend inline std::ostream& operator<<(std::ostream& out, const JPMTModifier& modifier)
510  {
511  out << modifier.action;
512  out << ' ';
513  out << modifier.value;
514 
515  return out;
516  }
517 
518 
519  std::string action;
520  std::string value;
521  };
522 
523 
524  /**
525  * Range of string numbers.
526  *
527  * The input format could be a single number or two numbers separated by JRange_t::SEPARATOR.
528  */
529  struct JRange_t :
530  public JRange<int>
531  {
532  /**
533  * Separator between two identifier values.
534  */
535  static const char SEPARATOR = '-';
536 
537  /**
538  * Default constructor.
539  */
540  JRange_t() :
541  JRange(-1, -1)
542  {}
543 
544 
545  /**
546  * Read range from input.
547  *
548  * \param in input stream
549  * \param range range
550  * \return input stream
551  */
552  friend inline std::istream& operator>>(std::istream& in, JRange_t& range)
553  {
554  if (in >> range.first) {
555 
556  range.second = range.first;
557 
558  if (in.peek() == (int) JRange_t::SEPARATOR) {
559 
560  in.get();
561 
562  in >> range.second;
563 
564  } else {
565 
566  in.clear();
567  }
568  }
569 
570  return in;
571  }
572 
573 
574  /**
575  * Write range to output.
576  *
577  * \param out output stream
578  * \param range range
579  * \return output stream
580  */
581  friend inline std::ostream& operator<<(std::ostream& out, const JRange_t& range)
582  {
583  return out << range.first << JRange_t::SEPARATOR << range.second;
584  }
585  };
586 
587 
588  /**
589  * Print module modification.
590  *
591  * \param out output stream
592  * \param module module
593  * \param modifier modifier
594  */
595  inline void print(std::ostream& out, const JModule& module, const JModifier& modifier)
596  {
597  using namespace std;
598  using namespace JPP;
599 
600  out << "Modifier" << ' '
601  << "(" << FILL(4,'0') << module.getString() << "," << FILL(2,'0') << module.getFloor() << FILL() << ")" << ' '
602  << setw(10) << module.getID() << ' '
603  << "action" << ' ' << modifier.action << JEEPZ() << modifier.data << endl;
604  }
605 
606 
607  /**
608  * Print PMT modification.
609  *
610  * \param out output stream
611  * \param pmt pmt identifier
612  * \param modifier modifier
613  */
614  inline void print(std::ostream& out, const JPMTIdentifier& pmt, const JPMTModifier& modifier)
615  {
616  using namespace std;
617  using namespace JPP;
618 
619  out << "PMT modifier" << ' '
620  << "(" << setw(10) << pmt.getID() << "," << setw(2) << pmt.getPMTAddress() << ")" << ' '
621  << "action" << ' ' << modifier.action << ' '
622  << "value" << ' ' << modifier.value << endl;
623  }
624 }
625 
626 
627 /**
628  * \file
629  *
630  * Auxiliary program to modify detector calibration.
631  *
632  * Syntax:
633  * <pre>
634  * -M "<module identifier> (set|add|sub|randset|randadd|randsub) x0 [x1 x2]"
635  * -(S|s) "<string number> (set|add|sub|randset|randadd|randsub) x0 [x1 x2]"
636  * -M "<module identifier> (rot|randrot) phi"
637  * -(S|s) "<string number> (rot|randrot) phi"
638  * -M "<module identifier> (mul|randmul) factor"
639  * -(S|s) "<string number> (mul|randmul) factor"
640  * -M "<module identifier> (reset)"
641  * -(S|s) "<string number> (reset)"
642  * -M "<module identifier> (assign) identifier"
643  * -M "<module identifier> (SET|ADD|SUB|) x0 [x1 x2 x3]"
644  * -(S|s) "<string number> (SET|ADD|SUB|) x0 [x1 x2 x3]"
645  * -M "<module identifier> (ROT) phi"
646  * -(S|s) "<string number> (ROT) phi"
647  * -M "<module identifier> (SET)"
648  * -(S|s) "<string number> (SET)"
649  * -(S|s) "<string number> (tilt|randtilt) Tx Ty"
650  * -P "<PMT identifier> (set|reset) (PMT_DISABLE|HIGH_RATE_VETO_DISABLE|FIFO_FULL_DISABLE|UDP_COUNTER_DISABLE|UDP_TRAILER_DISABLE|OUT_OF_SYNC)"
651  * -p "<PMT physical address> (set|reset) (PMT_DISABLE|HIGH_RATE_VETO_DISABLE|FIFO_FULL_DISABLE|UDP_COUNTER_DISABLE|UDP_TRAILER_DISABLE|OUT_OF_SYNC)"
652  * -k "<string number>[-<string number>]"
653  * -r "<string number>[-<string number>]"
654  * -m "<module identifier>"
655  * -D "<string number> <floor>"
656  * -\@ "<key>=<value>[;<key>=<value>"
657  * </pre>
658  * Options <tt>-M</tt> and <tt>-S</tt> refer to a module and a string, respectively.\n
659  * The values provided for a string modification coherently apply to the modules of the specified string number.\n
660  * The option <tt>-s</tt> is equivalent to option <tt>-S</tt> except that
661  * the action applies only to the optical modules in the string and not the base module.
662  *
663  * The options <tt>randxxx</tt> correspond to a randomisation of the specified option.
664  *
665  * If the module identifier or string number is -1,
666  * the action is applied to all modules or strings in the detector, respectively.
667  *
668  * For options <tt>[rand]set</tt>, <tt>[rand]add</tt> and <tt>[rand]sub</tt>,
669  * the number of values apply to position or time calibration in the following way:
670  * -# time calibration <tt>(t = x0)</tt>
671  * -# invalid
672  * -# position calibration <tt>(x = x0, y = x1, z = x2)</tt>
673  *
674  * For options <tt>[rand]rot</tt>,
675  * the angle <tt>phi</tt> refers to an anti-clockwise rotation around the z-axis.\n
676  * The rotation angle is defined in radians.
677  *
678  * For options <tt>[rand]mul</tt>,
679  * the multiplication <tt>factor</tt> (a.k.a.\ "stretching") applies to
680  * the z-coordinates of the optical modules and not to the base module (read anchor).\n
681  * The factor is defined as a fraction; the actual multiplication factor is <tt>(1 + factor)</tt>.
682  *
683  * For options <tt>SET</tt>, <tt>ADD</tt> and <tt>SUB</tt>,
684  * the number of values apply to time or quaternion calibration of the module in the following way:
685  * -# time calibration of piezo sensor or hydrophone <tt>(t = x0)</tt>
686  * -# invalid
687  * -# invalid
688  * -# quaternion calibration of compass <tt>(qa = x0, qb = x1, qc = x2, qd = x3)</tt>
689  *
690  * For options <tt>ROT</tt>,
691  * the angle <tt>phi</tt> refers to an anti-clockwise rotation around the z-axis of the quaternion calibration of the compass.\n
692  * The rotation angle is defined in radians.
693  *
694  * If no values are given at the option <tt>SET</tt>,
695  * - the time calibration of the piezo sensor is set to the average time calibration of the PMTs in that module,
696  * - the time calibration of the hydrophone is set to 0.
697  *
698  * In this, the time calibration is corrected for the delay time of the piezo sensor and hydrophone \n
699  * which are defined by JDETECTOR::PIEZO_DELAYTIME_US JDETECTOR::HYDROPHONE_DELAYTIME_US, respectively.\n
700  *
701  * The units of all positions and time values are <tt>m</tt> and <tt>ns</tt>, respectively.
702  *
703  * Note that for string modifiers with option <tt>randxxx</tt>,
704  * the action is coherently applied to the modules in the specified string.\n
705  * Only one type of action (defined by <tt>xxx</tt> and the number of values) is then allowed per string.
706  *
707  * Option <tt>-\@</tt> refers to the header information.\n
708  * The list of possible keys can be obtained using JPrintDetector.cc with option <tt>-O header</tt>.
709  *
710  * Multiple options <tt>-M</tt>, <tt>-S</tt>, <tt>-s</tt> or <tt>-\@</tt> will be processed in order of appearance.
711  *
712  * Options <tt>-k</tt> and <tt>-r</tt> can be used to keep and remove (a range of) string numbers, respectively.
713  *
714  * The options <tt>-m</tt> and <tt>-D</tt> can be used to maintain a specific module (and remove all others) and
715  * to delete a floor from a string, respectively.
716  *
717  * Note finally that if the output file name is the same as the input file name,
718  * the original file will be overwritten.
719  *
720  * \author mdejong
721  */
722 int main(int argc, char **argv)
723 {
724  using namespace std;
725  using namespace JPP;
726 
727  typedef JToken<';'> JToken_t;
728 
729  string inputFile;
730  string outputFile;
731  vector<JToken_t> hdr;
736  JPMTModifier> > pmt;
738  JPMTModifier> > alt;
739  vector<JRange_t> keep;
740  vector<JRange_t> rm;
741  vector<int> id;
742  multimap<int, int> del;
743  int debug;
744 
745  try {
746 
747  JParser<> zap("Auxiliary program to modify detector.");
748 
749  zap['a'] = make_field(inputFile);
750  zap['o'] = make_field(outputFile);
751  zap['@'] = make_field(hdr) = JPARSER::initialised();
752  zap['M'] = make_field(mod) = JPARSER::initialised();
753  zap['S'] = make_field(str) = JPARSER::initialised();
754  zap['s'] = make_field(dos) = JPARSER::initialised();
755  zap['P'] = make_field(pmt) = JPARSER::initialised();
756  zap['p'] = make_field(alt) = JPARSER::initialised();
757  zap['k'] = make_field(keep) = JPARSER::initialised();
758  zap['r'] = make_field(rm) = JPARSER::initialised();
759  zap['m'] = make_field(id) = JPARSER::initialised();
760  zap['D'] = make_field(del) = JPARSER::initialised();
761  zap['d'] = make_field(debug) = 2;
762 
763  zap(argc, argv);
764  }
765  catch(const exception &error) {
766  FATAL(error.what() << endl);
767  }
768 
770 
771  try {
772  load(inputFile, detector);
773  }
774  catch(const JException& error) {
775  FATAL(error);
776  }
777 
778 
779  gRandom->SetSeed(0);
780 
781 
782  if ((keep.empty() ? 0 : 1 +
783  rm .empty() ? 0 : 1 +
784  id .empty() ? 0 : 1) > 1) {
785  FATAL("Use either option -k, -r or -m." << endl);
786  }
787 
788 
789  detector.comment.add(JMeta(argc,argv));
790 
791  if (detector.setToLatestVersion()) {
792  NOTICE("Set detector version to " << detector.getVersion() << endl);
793  }
794 
795 
796  if (!hdr.empty()) {
797 
798  int id = -1;
799 
800  JProperties helper = detector.getProperties();
801 
802  helper["id"] = id;
803 
804  for (vector<JToken_t>::const_iterator i = hdr.begin(); i != hdr.end(); ++i) {
805 
806  istringstream is(*i);
807 
808  is >> helper;
809  }
810 
811  if (id != -1) {
812  detector.setID(id);
813  }
814  }
815 
816 
817  for (JDetector::iterator module = detector.begin(); module != detector.end(); ) {
818 
819  bool __rm__ = !keep.empty() && rm.empty();
820 
821  for (vector<JRange_t>::const_iterator i = keep.begin(); i != keep.end(); ++i) {
822  if (module->getString() >= i->first && module->getString() <= i->second) {
823  __rm__ = false;
824  }
825  }
826 
827  for (vector<JRange_t>::const_iterator i = rm.begin(); i != rm.end(); ++i) {
828  if (module->getString() >= i->first && module->getString() <= i->second) {
829  __rm__ = true;
830  }
831  }
832 
833  if (!id.empty()) {
834  __rm__ = find(id.begin(), id.end(), module->getID()) == id.end();
835  }
836 
837  const auto range = del.equal_range(module->getString());
838 
839  for (auto i = range.first; i != range.second; ++i) {
840  if (i->second == module->getFloor()) {
841  __rm__ = true;
842  }
843  }
844 
845  if (__rm__)
846  module = detector.erase(module);
847  else
848  ++module;
849  }
850 
851 
852  for (vector< pair<int, JModifier> >::const_iterator i = mod.begin(); i != mod.end(); ++i) {
853 
854  for (JDetector::iterator module = detector.begin(); module != detector.end(); ++module) {
855 
856  if (module->getID() == i->first || i->first == WILDCARD ){
857 
858  if (debug >= debug_t) {
859  print(cout, *module, i->second);
860  }
861 
862  if (!i->second.apply(*module)) {
863  ERROR("No valid action: " << i->first << ' ' << i->second << endl);
864  }
865  }
866  }
867  }
868 
869 
870  for (vector< pair<int, JModifier> >::const_iterator i = str.begin(); i != str.end(); ++i) {
871 
872  for (JDetector::iterator module = detector.begin(); module != detector.end(); ++module) {
873 
874  if (module->getString() == i->first || i->first == WILDCARD) {
875 
876  const JModifier modifier = getModifier(module->getString(), i->second);
877 
878  if (debug >= debug_t) {
879  print(cout, *module, i->second);
880  }
881 
882  if (!modifier.apply(*module)) {
883  ERROR("No valid action: " << i->first << ' ' << i->second << endl);
884  }
885  }
886  }
887  }
888 
889 
890  for (vector< pair<int, JModifier> >::const_iterator i = dos.begin(); i != dos.end(); ++i) {
891 
892  for (JDetector::iterator module = detector.begin(); module != detector.end(); ++module) {
893 
894  if (module->getFloor() != 0) {
895 
896  if (module->getString() == i->first || i->first == WILDCARD) {
897 
898  const JModifier modifier = getModifier(module->getString(), i->second);
899 
900  if (debug >= debug_t) {
901  print(cout, *module, i->second);
902  }
903 
904  if (!modifier.apply(*module)) {
905  ERROR("No valid action: " << i->first << ' ' << i->second << endl);
906  }
907  }
908  }
909  }
910  }
911 
912 
913  for (vector< pair<JPMTIdentifier, JPMTModifier> >::const_iterator i = pmt.begin(); i != pmt.end(); ++i) {
914 
915  for (JDetector::iterator module = detector.begin(); module != detector.end(); ++module) {
916 
917  if (module->getID() == i->first.getModuleID() || i->first.getModuleID() == WILDCARD) {
918 
919  if (debug >= debug_t) {
920  print(cout, i->first, i->second);
921  }
922 
923  if (i->first.getPMTAddress() == WILDCARD) {
924 
925  for (int pmt = 0; pmt != getNumberOfPMTs(*module); ++pmt) {
926  if (!i->second.apply(module->getPMT(pmt))) {
927  ERROR("No valid action: " << i->first << ' ' << i->second << endl);
928  }
929  }
930 
931  } else if (i->first.getPMTAddress() < 0 ||
932  i->first.getPMTAddress() >= getNumberOfPMTs(*module) ||
933  !i->second.apply(module->getPMT(i->first.getPMTAddress()))) {
934  ERROR("No valid action: " << i->first << ' ' << i->second << endl);
935  }
936  }
937  }
938  }
939 
940 
941  if (!alt.empty()) {
942 
943  if (!hasDetectorAddressMap(detector.getID())) {
944  FATAL("Invalid detector identifier " << detector.getID() << endl);
945  }
946 
947  const JDetectorAddressMap& demo = getDetectorAddressMap(detector.getID());
948 
949  for (JDetector::iterator module = detector.begin(); module != detector.end(); ++module) {
950 
951  const JModuleAddressMap memo = demo.get(module->getID());
952 
953  for (vector< pair<JPMTPhysicalAddress, JPMTModifier> >::const_iterator i = alt.begin(); i != alt.end(); ++i) {
954 
955  const JPMTIdentifier id(module->getID(), memo.getAddressTranslator(i->first).tdc);
956 
957  if (debug >= debug_t) {
958  print(cout, id, i->second);
959  }
960 
961  if (!i->second.apply(module->getPMT(id.getPMTAddress()))) {
962  ERROR("No valid action: " << i->first << ' ' << i->second << endl);
963  }
964  }
965  }
966  }
967 
968 
969  try {
971  }
972  catch(const JException& error) {
973  FATAL(error);
974  }
975 }
void set(const int bit)
Set PMT status.
Definition: JStatus.hh:124
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: JStatus.hh:281
Exceptions.
Q(UTCMax_s-UTCMin_s)-livetime_s
debug
Definition: JMessage.hh:29
int main(int argc, char *argv[])
Definition: Main.cc:15
int getFloor() const
Get floor number.
Definition: JLocation.hh:145
Data structure for a composite optical module.
Definition: JModule.hh:57
static const double HYDROPHONE_DELAYTIME_US
Hydrophone delay time [us].
JQuaternion3D getConjugate() const
Get conjugate of this quaternion.
void setLocation(const JLocation &location)
Set location.
Definition: JLocation.hh:91
Detector data structure.
Definition: JDetector.hh:80
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.
Auxiliary class for controlling PMT status.
Definition: JStatus.hh:42
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.
void reset(const int bit)
Reset PMT status.
Definition: JStatus.hh:135
string outputFile
is
Definition: JDAQCHSM.chsm:167
Data structure for detector geometry and calibration.
const JModuleAddressMap & get(const int id) const
Get module address map.
then echo The file $DIR KM3NeT_00000001_00000000 root already please rename or remove it first
const JQuaternion3D & getQuaternion() const
Get quaternion.
Rotation around Z-axis.
Definition: JRotation3D.hh:85
JModule & sub(const JVector3D &pos)
Subtract position.
Definition: JModule.hh:474
Lookup table for PMT addresses in optical module.
Detector specific mapping between logical positions and readout channels of PMTs in optical modules...
I/O formatting auxiliaries.
Detector file.
Definition: JHead.hh:196
static const double PIEZO_DELAYTIME_US
Piezo delay time [us].
Data structure for vector in three dimensions.
Definition: JVector3D.hh:34
void setQuaternion(const JQuaternion3D &quaternion)
Set quaternion.
Logical location of module.
Definition: JLocation.hh:37
Mathematical constants.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1961
const array_type< JValue_t > & make_array(const JValue_t(&array)[N])
Method to create array of values.
Definition: JVectorize.hh:54
Auxiliary methods for handling file names, type names and environment.
return result
Definition: JPolint.hh:727
int getID() const
Get identifier.
Definition: JObjectID.hh:50
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 and calibration.
Definition: JPMT.hh:47
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 identifier (= TDC).
double getY() const
Get y position.
Definition: JVector3D.hh:104
int debug
debug level
Definition: JSirene.cc:63
Auxiliary data structure for streaming of STL containers.
Definition: JPrint.hh:65
const JPosition3D & getPosition() const
Get position.
Definition: JPosition3D.hh:130
JDetectorAddressMap & getDetectorAddressMap()
Get detector address map.
static const JModule & getInstance()
Get reference to unique instance of this class object.
Definition: JModule.hh:103
print
Definition: JConvertDusj.sh:44
const JPMT & getPMT(const int index) const
Get PMT.
Definition: JModule.hh:211
void rotate(const JRotation3D &R)
Rotate module.
Definition: JModule.hh:351
Range of values.
Definition: JRange.hh:38
General purpose messaging.
Auxiliary data structure for sequence of same character.
Definition: JManip.hh:328
#define FATAL(A)
Definition: JMessage.hh:67
Data structure for unit quaternion in three dimensions.
Direct access to module in detector data structure.
z range($ZMAX-$ZMIN)< $MINIMAL_DZ." fi fi typeset -Z 4 STRING typeset -Z 2 FLOOR JPlot1D -f $
int getString() const
Get string number.
Definition: JLocation.hh:134
std::istream & operator>>(std::istream &in, JAANET::JHead &header)
Read header from input.
Definition: JHead.hh:1618
const JPMTAddressTranslator & getAddressTranslator(const int tdc) const
Get PMT address translator.
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.
Wrapper class around string.
Definition: JToken.hh:23
void setCalibration(const JCalibration &cal)
Set calibration.
void setID(const int id)
Set identifier.
Definition: JObjectID.hh:72
double getX() const
Get x position.
Definition: JVector3D.hh:94
Base class for data structures with artithmetic capabilities.
std::ostream & operator<<(std::ostream &stream, const CLBCommonHeader &header)
void addT0(const double t0)
Add time offset.
Data structure for position in three dimensions.
Definition: JPosition3D.hh:36
Data structure for PMT physical address.
do set_variable DETECTOR_TXT $WORKDIR detector
then fatal Wrong number of arguments fi set_variable DETECTOR $argv[1] set_variable INPUT_FILE $argv[2] eval JPrintDetector a $DETECTOR O IDENTIFIER eval JPrintDetector a $DETECTOR O SUMMARY source JAcoustics sh $DETECTOR_ID CHECK_EXIT_CODE typeset A TRIPODS get_tripods $WORKDIR tripod txt TRIPODS for EMITTER in
Definition: JCanberra.sh:38
JModule & set(const JVector3D &pos)
Set position.
Definition: JModule.hh:444
double getZ() const
Get z position.
Definition: JVector3D.hh:115
JModule & add(const JVector3D &pos)
Add position.
Definition: JModule.hh:456
double getT0() const
Get time offset.