233{
234 using namespace std;
236
237 typedef JContainer< vector<JTripod> > container_type;
238
239 string inputFile;
240 string outputFile;
241 vector<JModifier> mod;
242 vector<JTripod> add;
243 set<int> rm;
244 set<int> keep;
245 bool squash;
246 int debug;
247
248 try {
249
250 JParser<> zap("Auxiliary program to modify tripod configuration.");
251
252 zap['f'] = make_field(inputFile, "tripod input file");
253 zap['o'] = make_field(outputFile, "tripod output file");
254 zap['T'] = make_field(mod, "tripod modifier") = JPARSER::initialised();
255 zap['A'] = make_field(add, "add tripod") = JPARSER::initialised();
256 zap['r'] = make_field(rm, "remove tripod[s]") = JPARSER::initialised();
257 zap['k'] = make_field(keep, "keep tripod[s]") = JPARSER::initialised();
258 zap['q'] = make_field(squash, "squash meta data");
259 zap['d'] = make_field(debug, "debug level") = 2;
260
261 zap(argc, argv);
262 }
263 catch(const exception &error) {
264 FATAL(error.what() << endl);
265 }
266
267 gRandom->SetSeed(0);
268
269
270 if (!rm.empty() && !keep.empty()) {
271 FATAL("Use either option -K or -D." << endl);
272 }
273
274 container_type data;
275
276 if (inputFile != "") {
277 try {
278 data.load(inputFile.c_str());
279 }
280 catch(const exception& error) {
281
282 }
283 }
284
285 if (squash) {
286 data.comment.clear();
287 }
288
289 data.comment.add(JMeta(argc, argv));
290
291 for (vector<JTripod>::const_iterator i = add.begin(); i != add.end(); ++i) {
292 data.push_back(*i);
293 }
294
295 for (vector<JModifier>::const_iterator i = mod.begin(); i != mod.end(); ++i) {
296
297 for (container_type::iterator target = data.begin(); target != data.end(); ++target) {
298
299 if (target->getID() == i->id || i->id == WILDCARD) {
300
301 DEBUG("Modifier" << ' '
302 << "(" << FILL(2,'0') << target->getID() << FILL() << ")" << ' '
303 << i->action << ' ' << JEEPZ() << i->data << endl);
304
305 if (!i->apply(*target)) {
306 ERROR("No valid action: " << *i << endl);
307 }
308 }
309 }
310 }
311
312 if (!rm.empty()) {
313 for (container_type::iterator target = data.begin(); target != data.end(); ) {
314 if (rm.count(target->getID()) != 0)
315 target = data.erase(target);
316 else
317 ++target;
318 }
319 }
320
321 if (!keep.empty()) {
322 for (container_type::iterator target = data.begin(); target != data.end(); ) {
323 if (keep.count(target->getID()) == 0)
324 target = data.erase(target);
325 else
326 ++target;
327 }
328 }
329
330 sort(data.begin(), data.end(), make_comparator(&JTripod::getID));
331
332 data.store(outputFile.c_str());
333}