#ifndef PREXMLMANAGERHH #define PREXMLMANAGERHH #include #include #include "xmlToolFinder.hh" #include "ExpatInterface/Document.h" #include "ExpatInterface/Element.h" #include "xmlToolDir.hh" #include "preXmlQuantity.hh" namespace preXml { class Manager { private: xmlTool::Finder _finder; xmlTool::Directory * _geometryManager; // WIPTMCH xmlTool::Directory * _sectionManager; // WIPTMCH xml::Document _doc; // IMCH const xml::Element * _geometry; // Will be the part of the // database which hold the // stuff we consider. // WIPTMNCH void _mandatoryInitialisation(); // NACOF public: // LESTER Take me out! xmlTool::Finder & getFinder() { return _finder; }; // Use one of the following constructors to start // the manager. You must provide them with either // an istream or a filename where the preXml xml // file can be found. Manager(const std::string & preXmlFileName); // WIPTWNCH NACOF Manager(std::istream & preXmlInputStream); // WIPTMCH NACOF // We will be needing this. ~Manager(); // NACOF // The use of the following method is STRONGLY discouraged, // but it is provided so that you may have access to the // document in emergencies. const xml::Document & getDocument() const { return _doc; }; // WIPTMNBCH ACOF // Use the geoManager to traverse the geometry hierarchy. xmlTool::Directory & geoManager() const; // WIPTMBCH ACOF // Use setGeometry to set the geometry to the current // geometry set in geoManager(). // setGeometry will (and must) fail if you are not at the // end of a branch of the geometry hierarchy. // Failure is signalled by an abort() ! That'll teach you. void setGeometry(); // NACOF // Once you've chosen a geometry, you can start wandering // around its section hierarchy. Be warned, I can't // report a reference to a section which isn't there, so // if you use secManager() before setting the geometry, // then there'll be another abort() on your hands. xmlTool::Directory & secManager() const; // WIPTMBCH ACF // Here follow methods to read "values" from the XML file. // They will read params into preXml::Quantity objects and // paramArrays into vector objects. // You should do something like the following: // // preXml::Number percentRadLength; // Manager.fill(percentRadLength, pcRadLengthElement); // cout << "The radiation length is "; // cout << percentRadLength / DWpercent << " %." << endl; // // preXml::Integer numberOfLayers; // Manager.fill(numberOfLayers, nLayElement); // cout << "The number of layers is "; // cout << numberOfLayers << "." << endl; // // preXml::Length layerRadius(numberOfLayers.value()); // Manager.fill(layerRadius, layerRadElement); // cout << "The radius of the 2nd layer (counting from zero) is "; // cout << layerRadius[2] / DWcm << " cm "; // cout << "which is "; // cout << layerRadius[2] / DWmm << " mm." << endl; // cout << "With automatic units: layerRadius[2] = "; // cout << layerRadius[2] << endl; // // In all the above cases, the variables ending in Element are // constant Elements (or references to them) from the XML file // contsining the params or paramArrays as appropriate. // Here's the bit that does the straight Quantities ... void fill(preXml::Quantity & quantity, const xml::Element & elt) const; // ... and here's the bit that does the arrays. template void fill(vector & quantityVec, const xml::Element & elt, int numberToFill=-1) const { // cout << "Hey, I am Vector Filler." << endl; assert(numberToFill>=-1); assert(elt.getTagName()==string("paramArray")); unsigned int num = (numberToFill=-1) ? quantityVec.size() : numberToFill; const xml::Element::ElementCollection & children = elt.getChildren(); assert(children.size() >= num); for (unsigned int i=0; i with the contents // of a paramArray called "paramArrayName" which can be uniquely // identified by that name somewhere under the current // section directory. template void fill(vector & quantityVec, const std::string & paramArrayName, int numberToFill=-1) { // Only allowed to start doing this once a geometry has been chosen. // However, the call to secManager will sort that check out. // Let's find the element corresponding to the name const xml::Element & elt = this->_finder.findUnderTheUniqueElement( this->secManager().getCurDirElt(), string("paramArray"), string("name"), paramArrayName); // Well, if that didn't complain, then the elt was found. this->fill(quantityVec, elt, numberToFill); }; }; // end of preXml class } // End of preXml namespace. #endif