Jpp  15.0.1-rc.2-highQE
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JEditTripod.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <iomanip>
3 #include <vector>
4 
5 #include "TRandom3.h"
6 
7 #include "JDetector/JTripod.hh"
8 
9 #include "JSupport/JMeta.hh"
10 
11 #include "Jeep/JContainer.hh"
12 #include "Jeep/JPrint.hh"
13 #include "Jeep/JParser.hh"
14 #include "Jeep/JMessage.hh"
15 
16 
17 namespace {
18 
19  using namespace JPP;
20 
21  /**
22  * Wild card for tripod identifier.
23  */
24  static const int WILDCARD = -1;
25 
26  static const std::string set_t = "set"; //!< Set position
27  static const std::string add_t = "add"; //!< Add position
28  static const std::string sub_t = "sub"; //!< Subtract position
29 
30  static const std::string rand_t = "rand"; //!< Random value(s)
31  static const std::string randset_t = rand_t + set_t; //!< Set position
32  static const std::string randadd_t = rand_t + add_t; //!< Add position
33  static const std::string randsub_t = rand_t + sub_t; //!< Subtract position
34 
35  /**
36  * Auxiliary class to apply tripod modifications.
37  */
38  struct JModifier {
39  /**
40  * Apply modification to given tripod.
41  *
42  * \param tripod tripod
43  * \return true if valid action; else false
44  */
45  bool apply(JTripod& tripod) const
46  {
47  const JUTMPosition randpos(gRandom->Gaus(0.0, pos.getUTMEast()),
48  gRandom->Gaus(0.0, pos.getUTMNorth()),
49  gRandom->Gaus(0.0, pos.getUTMZ()));
50 
51  if (action == set_t) // actions with fixed values
52  tripod.setUTMPosition(pos);
53  else if (action == add_t)
54  tripod.add(pos);
55  else if (action == sub_t)
56  tripod.sub(pos);
57  else if (action == randset_t) // actions with random values
58  tripod.setUTMPosition(randpos);
59  else if (action == randadd_t)
60  tripod.add(randpos);
61  else if (action == randsub_t)
62  tripod.sub(randpos);
63  else
64  return false;
65 
66  return true;
67  }
68 
69 
70  /**
71  * Read modifier from input.
72  *
73  * \param in input stream
74  * \param modifier modifier
75  * \return input stream
76  */
77  friend inline std::istream& operator>>(std::istream& in, JModifier& modifier)
78  {
79  return in >> modifier.id >> modifier.action >> modifier.pos;
80  }
81 
82 
83  /**
84  * Write modifier to output.
85  *
86  * \param out output stream
87  * \param modifier modifier
88  * \return output stream
89  */
90  friend inline std::ostream& operator<<(std::ostream& out, const JModifier& modifier)
91  {
92  out << modifier.id;
93  out << ' ';
94  out << modifier.action;
95  out << ' ';
96  out << modifier.pos;
97 
98  return out;
99  }
100 
101 
102  int id;
103  std::string action;
104  JUTMPosition pos;
105  };
106 }
107 
108 /**
109  * \file
110  *
111  * Auxiliary program to modify tripod configuration.
112  *
113  * Syntax:
114  * <pre>
115  * -T "<tripod identifier> (set|add|sub) east north z"
116  * </pre>
117  *
118  * \author mdejong
119  */
120 int main(int argc, char **argv)
121 {
122  using namespace std;
123  using namespace JPP;
124 
125  typedef JContainer< vector<JTripod> > container_type;
126 
127  string file_name;
128  vector<JModifier> mod;
129  int debug;
130 
131  try {
132 
133  JParser<> zap("Auxiliary program to modify tripod configuration.");
134 
135  zap['f'] = make_field(file_name, "tripod file");
136  zap['T'] = make_field(mod, "tripod modifier") = JPARSER::initialised();
137  zap['d'] = make_field(debug) = 1;
138 
139  zap(argc, argv);
140  }
141  catch(const exception &error) {
142  FATAL(error.what() << endl);
143  }
144 
145  gRandom->SetSeed(0);
146 
147  container_type data;
148 
149  data.load(file_name.c_str());
150 
151  data.comment.add(JMeta(argc, argv));
152 
153  for (vector<JModifier>::const_iterator i = mod.begin(); i != mod.end(); ++i) {
154 
155  for (container_type::iterator target = data.begin(); target != data.end(); ++target) {
156 
157  if (target->getID() == i->id || i->id == WILDCARD) {
158 
159  DEBUG("Modifier" << ' '
160  << "(" << FILL(2,'0') << target->getID() << FILL() << ")" << ' '
161  << "action" << ' ' << i->pos << endl);
162 
163  if (!i->apply(*target)) {
164  ERROR("No valid action: " << *i << endl);
165  }
166  }
167  }
168  }
169 
170  data.store(file_name.c_str());
171 }
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
int main(int argc, char *argv[])
Definition: Main.cc:15
Target.
Definition: JHead.hh:268
JUTMPosition & sub(const JUTMPosition &pos)
Subtract UTM position.
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Definition: JParser.hh:66
void setUTMPosition(const JUTMPosition &position)
Set UTM position.
Definition: JUTMPosition.hh:95
Data structure for UTM position.
Definition: JUTMPosition.hh:36
I/O formatting auxiliaries.
Auxiliary wrapper for I/O of container with optional comment (see JComment).
Definition: JContainer.hh:39
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1961
ROOT I/O of application specific meta data.
#define ERROR(A)
Definition: JMessage.hh:66
int debug
debug level
Definition: JSirene.cc:63
General purpose messaging.
Auxiliary data structure for sequence of same character.
Definition: JManip.hh:328
#define FATAL(A)
Definition: JMessage.hh:67
std::istream & operator>>(std::istream &in, JAANET::JHead &header)
Read header from input.
Definition: JHead.hh:1618
Utility class to parse command line options.
then usage $script< input_file >< detector_file > fi set_variable OUTPUT_DIR set_variable SELECTOR JDAQTimesliceL1 set_variable DEBUG case set_variable DEBUG
Data structure for tripod.
Definition: JTripod.hh:32
std::ostream & operator<<(std::ostream &stream, const CLBCommonHeader &header)
JUTMPosition & add(const JUTMPosition &pos)
Add UTM position.
Data structure for tripod.
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:41
Container I/O.