diff --git a/GeoModelTools/GeoModelXML/GeoModelXml/GeoModelXml/GmxInterface.h b/GeoModelTools/GeoModelXML/GeoModelXml/GeoModelXml/GmxInterface.h index 7c64ebee49558473421ee9262d20068c6650c1bb..f1854c2e9849fcdf765b867fde8c0c929c0495ad 100644 --- a/GeoModelTools/GeoModelXML/GeoModelXml/GeoModelXml/GmxInterface.h +++ b/GeoModelTools/GeoModelXML/GeoModelXml/GeoModelXml/GmxInterface.h @@ -23,13 +23,65 @@ class GmxInterface { public: - virtual int sensorId(std::map<std::string, int> &index) const; - virtual int splitSensorId(std::map<std::string, int> &index, std::pair<std::string, int> &extraIndex, std::map<std::string, int> &updatedIndex) const; //For "artificially" adding to Identifiers; specify the field (e.g. "eta_module") and the value to add - virtual void addSensorType(std::string type, std::string name, std::map<std::string, std::string> parameters); - virtual void addSensor(std::string name, std::map<std::string, int> &index, int id, GeoVFullPhysVol *fpv); - virtual void addSplitSensor(std::string name, std::map<std::string, int> &index, std::pair<std::string, int> &extraIndex, int id, GeoVFullPhysVol *fpv); - virtual void addAlignable(int level, std::map<std::string, int> &index, - GeoVFullPhysVol *fpv, GeoAlignableTransform *transform); + virtual int sensorId(std::map<std::string, int> &index) const; + virtual int splitSensorId(std::map<std::string, int> &index, std::pair<std::string, int> &extraIndex, std::map<std::string, int> &updatedIndex) const; //For "artificially" adding to Identifiers; specify the field (e.g. "eta_module") and the value to add + virtual void addSensorType(std::string type, std::string name, std::map<std::string, std::string> parameters); + virtual void addSensor(std::string name, std::map<std::string, int> &index, int id, GeoVFullPhysVol *fpv); + virtual void addSplitSensor(std::string name, std::map<std::string, int> &index, std::pair<std::string, int> &extraIndex, int id, GeoVFullPhysVol *fpv); + virtual void addAlignable(int level, std::map<std::string, int> &index, + GeoVFullPhysVol *fpv, GeoAlignableTransform *transform); + // helpers + template <typename T> + bool checkParameter(const std::string /* &typeName */, + const std::map<std::string, std::string> ¶meters, + const std::string &name, + T &value) + { + // Needs some kind of versioning to stop this being abused... + auto it = parameters.find(name); + if (it != parameters.end()) { + std::istringstream(it->second) >> value; + return true; + } + return false; + } + + template <typename T> + void getParameter(const std::string &typeName, + const std::map<std::string, std::string> ¶meters, + const std::string &name, + T &value) const + { + auto it = parameters.find(name); + if (it != parameters.end()) { + std::istringstream(it->second) >> value; + } else { + std::string err("GmxInterface Error: missing parameter " + name + " for " + typeName); + throw std::runtime_error(err); + } + } + + template <typename T, typename A> + void getParameters(const std::string &typeName, + const std::map<std::string, std::string> ¶meters, + const std::string &name, + std::vector<T, A> &vec) const + { + auto it = parameters.find(name); + if (it != parameters.end()) { + T value; + std::string strVal(it->second); + strVal.erase(strVal.find_last_not_of(" \t\n\r\f\v") + 1); // trailing white space or you get an extra 0 + std::istringstream inString(strVal); + do { + inString >> value; + vec.push_back(value); + } while (inString.good()); + } else { + std::string err("GmxInterface Error: missing parameters " + name + " for " + typeName); + throw std::runtime_error(err); + } + } }; #endif // GMX_INTERFACE_H diff --git a/GeoModelTools/GeoModelXML/GeoModelXml/src/MulticopyProcessor.cxx b/GeoModelTools/GeoModelXML/GeoModelXml/src/MulticopyProcessor.cxx index abf291e834b3805108694bdde12e2ff169bd7341..e1ca7f39d9f6b201aa8b46b287f14c77125cca0a 100644 --- a/GeoModelTools/GeoModelXML/GeoModelXml/src/MulticopyProcessor.cxx +++ b/GeoModelTools/GeoModelXML/GeoModelXml/src/MulticopyProcessor.cxx @@ -236,11 +236,11 @@ DOMDocument *doc = element->getOwnerDocument(); objectProcessor->process(object, gmxUtil, toAdd); if (alignable) { - cout << "copy = " << copy << "; level = " << level << endl; - cout << "\nAdd Alignable named " << endl; - cout << ((GeoNameTag *) (toAdd[lastTransform + 1]))->getName() << endl; - cout << " with id " << endl; - cout << ((GeoIdentifierTag *) (toAdd[lastTransform + 2]))->getIdentifier() << endl; + msglog << "copy = " << copy << "; level = " << level << endmsg; + msglog << "Add Alignable named "; + msglog << ((GeoNameTag *) (toAdd[lastTransform + 1]))->getName(); + msglog << " with id "; + msglog << ((GeoIdentifierTag *) (toAdd[lastTransform + 2]))->getIdentifier() << endmsg; gmxUtil.positionIndex.incrementLevel(); // Logvol has unfortunately already decremented this; temp. restore it gmxUtil.positionIndex.indices(index, gmxUtil.eval);