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