101{
102 using namespace std;
104
105 typedef JContainer< map<int, JMechanics> > container_type;
106
107 string inputFile;
108 string outputFile;
109 vector<JModifier> mod;
110 map<int, JMechanics> add;
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
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}
Auxiliary data structure for parameters of mechanical model.