Jpp - 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 "JDetector/JTripod.hh"
6 
7 #include "JSupport/JMeta.hh"
8 
9 #include "Jeep/JContainer.hh"
10 #include "Jeep/JPrint.hh"
11 #include "Jeep/JParser.hh"
12 #include "Jeep/JMessage.hh"
13 
14 
15 namespace {
16 
17  using namespace JPP;
18 
19  /**
20  * Wild card for tripod identifier.
21  */
22  static const int WILDCARD = -1;
23 
24  static const std::string set_t = "set"; //!< Set position
25  static const std::string add_t = "add"; //!< Add position
26  static const std::string sub_t = "sub"; //!< Subtract position
27 
28  /**
29  * Auxiliary class to apply tripod modifications.
30  */
31  struct JModifier {
32  /**
33  * Apply modification to given tripod.
34  *
35  * \param tripod tripod
36  * \return true if valid action; else false
37  */
38  bool apply(JTripod& tripod) const
39  {
40  if (action == set_t)
41  tripod.setUTMPosition(pos);
42  else if (action == add_t)
43  tripod.add(pos);
44  else if (action == sub_t)
45  tripod.sub(pos);
46  else
47  return false;
48 
49  return true;
50  }
51 
52 
53  /**
54  * Read modifier from input.
55  *
56  * \param in input stream
57  * \param modifier modifier
58  * \return input stream
59  */
60  friend inline std::istream& operator>>(std::istream& in, JModifier& modifier)
61  {
62  return in >> modifier.id >> modifier.action >> modifier.pos;
63  }
64 
65 
66  /**
67  * Write modifier to output.
68  *
69  * \param out output stream
70  * \param modifier modifier
71  * \return output stream
72  */
73  friend inline std::ostream& operator<<(std::ostream& out, const JModifier& modifier)
74  {
75  out << modifier.id;
76  out << ' ';
77  out << modifier.action;
78  out << ' ';
79  out << modifier.pos;
80 
81  return out;
82  }
83 
84 
85  int id;
86  std::string action;
87  JUTMPosition pos;
88  };
89 }
90 
91 /**
92  * \file
93  *
94  * Auxiliary program to modify tripod configuration.
95  *
96  * Syntax:
97  * <pre>
98  * -T "<tripod identifier> (set|add|sub) east north z"
99  * </pre>
100  *
101  * \author mdejong
102  */
103 int main(int argc, char **argv)
104 {
105  using namespace std;
106  using namespace JPP;
107 
108  typedef JContainer< vector<JTripod> > container_type;
109 
110  string file_name;
111  vector<JModifier> mod;
112  int debug;
113 
114  try {
115 
116  JParser<> zap("Auxiliary program to modify tripod configuration.");
117 
118  zap['f'] = make_field(file_name, "tripod file");
119  zap['T'] = make_field(mod, "tripod modifier") = JPARSER::initialised();
120  zap['d'] = make_field(debug) = 1;
121 
122  zap(argc, argv);
123  }
124  catch(const exception &error) {
125  FATAL(error.what() << endl);
126  }
127 
128  container_type data;
129 
130  data.load(file_name.c_str());
131 
132  data.comment.add(JMeta(argc, argv));
133 
134  for (vector<JModifier>::const_iterator i = mod.begin(); i != mod.end(); ++i) {
135 
136  for (container_type::iterator target = data.begin(); target != data.end(); ++target) {
137 
138  if (target->getID() == i->id || i->id == WILDCARD) {
139 
140  DEBUG("Modifier" << ' '
141  << "(" << FILL(2,'0') << target->getID() << FILL() << ")" << ' '
142  << "action" << ' ' << i->pos << endl);
143 
144  if (!i->apply(*target)) {
145  ERROR("No valid action: " << *i << endl);
146  }
147  }
148  }
149  }
150 
151  data.store(file_name.c_str());
152 }
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:38
Container I/O.