Jpp  15.0.5
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JEditMechanics.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <iomanip>
3 #include <map>
4 
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 mechanics
20 
21  /**
22  * Auxiliary class to apply mechanics modifications.
23  */
24  struct JModifier {
25  /**
26  * Apply modification to given mechanics.
27  *
28  * \param mechanics mechanics
29  * \return true if valid action; else false
30  */
31  bool apply(JMechanics& mechanics) const
32  {
33  if (action == set_t)
34  mechanics = this->mechanics;
35  else
36  return false;
37 
38  return true;
39  }
40 
41 
42  /**
43  * Read modifier from input.
44  *
45  * \param in input stream
46  * \param modifier modifier
47  * \return input stream
48  */
49  friend inline std::istream& operator>>(std::istream& in, JModifier& modifier)
50  {
51  return in >> modifier.id >> modifier.action >> modifier.mechanics;
52  }
53 
54 
55  /**
56  * Write modifier to output.
57  *
58  * \param out output stream
59  * \param modifier modifier
60  * \return output stream
61  */
62  friend inline std::ostream& operator<<(std::ostream& out, const JModifier& modifier)
63  {
64  out << modifier.id;
65  out << ' ';
66  out << modifier.action;
67  out << ' ';
68  out << modifier.mechanics;
69 
70  return out;
71  }
72 
73 
74  int id;
75  std::string action;
76  JMechanics mechanics;
77  };
78 }
79 
80 /**
81  * \file
82  *
83  * Auxiliary program to modify mechanical model data.
84  *
85  * Syntax:
86  * <pre>
87  * -M "<string number> (set) a b"
88  * </pre>
89  *
90  * \author mdejong
91  */
92 int main(int argc, char **argv)
93 {
94  using namespace std;
95  using namespace JPP;
96 
97  typedef JContainer< map<int, JMechanics> > container_type;
98 
99  string file_name;
100  vector<JModifier> mod;
101  int debug;
102 
103  try {
104 
105  JParser<> zap("Auxiliary program to modify mechanical model data.");
106 
107  zap['f'] = make_field(file_name, "mechanics file");
108  zap['M'] = make_field(mod, "mechanics modifier") = JPARSER::initialised();
109  zap['d'] = make_field(debug) = 1;
110 
111  zap(argc, argv);
112  }
113  catch(const exception &error) {
114  FATAL(error.what() << endl);
115  }
116 
117  container_type data;
118 
119  data.load(file_name.c_str());
120 
121  data.comment.add(JMeta(argc, argv));
122 
123  for (vector<JModifier>::const_iterator i = mod.begin(); i != mod.end(); ++i) {
124 
125  DEBUG("Modifier" << ' '
126  << "(" << FILL(2,'0') << i->id << FILL() << ")" << ' '
127  << "action" << ' ' << i->mechanics << endl);
128 
129  JMechanics mechanics;
130 
131  container_type::iterator p = data.find(i->id);
132 
133  if (p != data.end()) {
134  mechanics = p->second;
135  }
136 
137  if (!i->apply(mechanics))
138  ERROR("No valid action: " << *i << endl);
139  else
140  data[i->id] = mechanics;
141  }
142 
143  data.store(file_name.c_str());
144 }
Auxiliary class for ROOT I/O of application specific meta data.
Definition: JMeta.hh:70
Mechanical modelling of string.
Utility class to parse command line options.
Definition: JParser.hh:1500
int main(int argc, char *argv[])
Definition: Main.cc:15
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Definition: JParser.hh:66
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
std::ostream & operator<<(std::ostream &stream, const CLBCommonHeader &header)
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.
Auxiliary data structure for parameters of mechanical model.
Definition: JMechanics.hh:39