#include #include #include #include #include "JAcoustics/JMechanics.hh" #include "JSupport/JMeta.hh" #include "Jeep/JContainer.hh" #include "Jeep/JPrint.hh" #include "Jeep/JParser.hh" #include "Jeep/JMessage.hh" namespace { using namespace JPP; static const std::string set_t = "set"; //!< Set mechanics /** * Auxiliary class to apply mechanics modifications. */ struct JModifier { /** * Apply modification to given mechanics. * * \param mechanics mechanics * \return true if valid action; else false */ bool apply(JMechanics& mechanics) const { if (action == set_t) mechanics = this->mechanics; else return false; return true; } /** * Read modifier from input. * * \param in input stream * \param modifier modifier * \return input stream */ friend inline std::istream& operator>>(std::istream& in, JModifier& modifier) { return in >> modifier.id >> modifier.action >> modifier.mechanics; } /** * Write modifier to output. * * \param out output stream * \param modifier modifier * \return output stream */ friend inline std::ostream& operator<<(std::ostream& out, const JModifier& modifier) { out << modifier.id; out << ' '; out << modifier.action; out << ' '; out << modifier.mechanics; return out; } int id; std::string action; JMechanics mechanics; }; } /** * \file * * Auxiliary program to add or modify mechanical model data of detector string. * * Syntax: *
 *     -M "     (set) a b"
 * 
* * The options *
 *     -A " a b"
 *     -r ""
 * 
* can be used to add or remove a specific string, respectively. * * \author mdejong */ int main(int argc, char **argv) { using namespace std; using namespace JPP; typedef JContainer< map > container_type; string inputFile; string outputFile; vector mod; map add; set rm; bool squash; int debug; try { JParser<> zap("Auxiliary program to add or modify mechanical model data of detector string."); zap['f'] = make_field(inputFile, "mechanics input file"); zap['o'] = make_field(outputFile, "mechanics output file"); zap['M'] = make_field(mod, "mechanics modifier") = JPARSER::initialised(); zap['A'] = make_field(add, "add string mechanics") = JPARSER::initialised(); zap['r'] = make_field(rm, "remove string[s]") = JPARSER::initialised(); zap['q'] = make_field(squash, "squash meta data"); zap['d'] = make_field(debug, "debug level") = 2; zap(argc, argv); } catch(const exception &error) { FATAL(error.what() << endl); } container_type data; try { data.load(inputFile.c_str()); } catch(const exception&) {} if (squash) { data.comment.clear(); } data.comment.add(JMeta(argc,argv)); for (map::const_iterator i = add.begin(); i != add.end(); ++i) { if (data.count(i->first) == 0u) data[i->first] = i->second; else ERROR("String " << i->first << " already exists." << endl); } for (vector::const_iterator i = mod.begin(); i != mod.end(); ++i) { DEBUG("Modifier" << ' ' << "(" << FILL(2,'0') << i->id << FILL() << ")" << ' ' << "action" << ' ' << i->mechanics << endl); JMechanics mechanics; container_type::iterator p = data.find(i->id); if (p != data.end()) { mechanics = p->second; } if (!i->apply(mechanics)) ERROR("No valid action: " << *i << endl); else data[i->id] = mechanics; } for (set::const_iterator i = rm.begin(); i != rm.end(); ++i) { container_type::iterator p = data.find(*i); if (p != data.end()) { data.erase(p); } } data.store(outputFile.c_str()); }