Jpp 19.3.0-rc.1
the software that should make you happy
Loading...
Searching...
No Matches
JEditMechanics.cc
Go to the documentation of this file.
1#include <iostream>
2#include <iomanip>
3#include <map>
4#include <set>
5
7
8#include "JSupport/JMeta.hh"
9
10#include "Jeep/JContainer.hh"
11#include "Jeep/JPrint.hh"
12#include "Jeep/JParser.hh"
13#include "Jeep/JMessage.hh"
14
15
16namespace {
17
18 using namespace JPP;
19
20 static const std::string set_t = "set"; //!< Set mechanics
21
22 /**
23 * Auxiliary class to apply mechanics modifications.
24 */
25 struct JModifier {
26 /**
27 * Apply modification to given mechanics.
28 *
29 * \param mechanics mechanics
30 * \return true if valid action; else false
31 */
32 bool apply(JMechanics& mechanics) const
33 {
34 if (action == set_t)
35 mechanics = this->mechanics;
36 else
37 return false;
38
39 return true;
40 }
41
42
43 /**
44 * Read modifier from input.
45 *
46 * \param in input stream
47 * \param modifier modifier
48 * \return input stream
49 */
50 friend inline std::istream& operator>>(std::istream& in, JModifier& modifier)
51 {
52 return in >> modifier.id >> modifier.action >> modifier.mechanics;
53 }
54
55
56 /**
57 * Write modifier to output.
58 *
59 * \param out output stream
60 * \param modifier modifier
61 * \return output stream
62 */
63 friend inline std::ostream& operator<<(std::ostream& out, const JModifier& modifier)
64 {
65 out << modifier.id;
66 out << ' ';
67 out << modifier.action;
68 out << ' ';
69 out << modifier.mechanics;
70
71 return out;
72 }
73
74
75 int id;
76 std::string action;
77 JMechanics mechanics;
78 };
79}
80
81/**
82 * \file
83 *
84 * Auxiliary program to add or modify mechanical model data of detector string.
85 *
86 * Syntax:
87 * <pre>
88 * -M "<string number> (set) a b"
89 * </pre>
90 *
91 * The options
92 * <pre>
93 * -A "<string number> a b"
94 * -r "<string number>"
95 * </pre>
96 * can be used to add or remove a specific string, respectively.
97 *
98 * \author mdejong
99 */
100int main(int argc, char **argv)
101{
102 using namespace std;
103 using namespace JPP;
104
105 typedef JContainer< map<int, JMechanics> > container_type;
106
107 string inputFile;
108 string outputFile;
111 set<int> rm;
112 bool squash;
113 int debug;
114
115 try {
116
117 JParser<> zap("Auxiliary program to add or modify mechanical model data of detector string.");
118
119 zap['f'] = make_field(inputFile, "mechanics input file");
120 zap['o'] = make_field(outputFile, "mechanics output file");
121 zap['M'] = make_field(mod, "mechanics modifier") = JPARSER::initialised();
122 zap['A'] = make_field(add, "add string mechanics") = JPARSER::initialised();
123 zap['r'] = make_field(rm, "remove string[s]") = JPARSER::initialised();
124 zap['q'] = make_field(squash, "squash meta data");
125 zap['d'] = make_field(debug, "debug level") = 2;
126
127 zap(argc, argv);
128 }
129 catch(const exception &error) {
130 FATAL(error.what() << endl);
131 }
132
133 container_type data;
134
135 try {
136 data.load(inputFile.c_str());
137 }
138 catch(const exception&) {}
139
140 if (squash) {
141 data.comment.clear();
142 }
143
144 data.comment.add(JMeta(argc,argv));
145
146 for (map<int, JMechanics>::const_iterator i = add.begin(); i != add.end(); ++i) {
147 if (data.count(i->first) == 0u)
148 data[i->first] = i->second;
149 else
150 ERROR("String " << i->first << " already exists." << endl);
151 }
152
153 for (vector<JModifier>::const_iterator i = mod.begin(); i != mod.end(); ++i) {
154
155 DEBUG("Modifier" << ' '
156 << "(" << FILL(2,'0') << i->id << FILL() << ")" << ' '
157 << "action" << ' ' << i->mechanics << endl);
158
159 JMechanics mechanics;
160
161 container_type::iterator p = data.find(i->id);
162
163 if (p != data.end()) {
164 mechanics = p->second;
165 }
166
167 if (!i->apply(mechanics))
168 ERROR("No valid action: " << *i << endl);
169 else
170 data[i->id] = mechanics;
171 }
172
173 for (set<int>::const_iterator i = rm.begin(); i != rm.end(); ++i) {
174
175 container_type::iterator p = data.find(*i);
176
177 if (p != data.end()) {
178 data.erase(p);
179 }
180 }
181
182 data.store(outputFile.c_str());
183}
Container I/O.
string outputFile
int main(int argc, char **argv)
Mechanical modelling of string.
General purpose messaging.
#define DEBUG(A)
Message macros.
Definition JMessage.hh:62
#define FATAL(A)
Definition JMessage.hh:67
int debug
debug level
Definition JSirene.cc:72
ROOT I/O of application specific meta data.
Utility class to parse command line options.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition JParser.hh:2142
I/O formatting auxiliaries.
Utility class to parse command line options.
Definition JParser.hh:1698
std::istream & operator>>(std::istream &in, JAHRSCalibration &calibration)
Read AHRS calibration from input stream.
std::ostream & operator<<(std::ostream &out, const JAHRSCalibration &calibration)
Write AHRS calibration to output stream.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Auxiliary data structure for sequence of same character.
Definition JManip.hh:330
Auxiliary data structure for parameters of mechanical model.
Definition JMechanics.hh:41
Auxiliary wrapper for I/O of container with optional comment (see JComment).
Definition JContainer.hh:42
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Definition JParser.hh:68
Auxiliary class for ROOT I/O of application specific meta data.
Definition JMeta.hh:72