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