1 #include "gearxml/GearParametersXML.h"
3 #include "gearxml/tinyxml.h"
4 #include "gearimpl/GearParametersImpl.h"
5 #include "gear/GearMgr.h"
17 int intVal(
const std::string& str ) {
18 return atoi( str.c_str() ) ;
23 return (
double) atof( str.c_str() ) ;
30 std::vector< std::string >& _tokens ;
35 Tokenizer( std::vector< std::string >& tokens,
char del ) : _tokens(tokens) , _del(del), _last(del) {
39 void operator()(
const char& c) {
44 _tokens.push_back(
"") ;
56 std::vector<std::string> & result() {
102 typedef const std::vector< std::string > KeyVec ;
104 if( xmlElement == 0 || gearParams == 0 ){
109 for(
unsigned int i=0 ; i < intKeys.size() ; ++i ){
123 for(
unsigned int i=0 ; i < doubleKeys.size() ; ++i ){
137 for(
unsigned int i=0 ; i < stringKeys.size() ; ++i ){
150 for(
unsigned int i=0 ; i < intVecKeys.size() ; ++i ){
157 IntVec vec = gearParams->
getIntVals( intVecKeys[i] ) ;
158 std::stringstream str ;
159 for(
unsigned int j=0 ; j < vec.size() ; ++j ){
172 for(
unsigned int i=0 ; i < doubleVecKeys.size() ; ++i ){
179 DoubleVec vec = gearParams->
getDoubleVals( doubleVecKeys[i] ) ;
181 std::stringstream str ;
183 str << std::scientific << std::setprecision(9) ;
184 for(
unsigned int j=0 ; j < vec.size() ; ++j ){
197 for(
unsigned int i=0 ; i < stringVecKeys.size() ; ++i ){
204 StringVec vec = gearParams->
getStringVals( stringVecKeys[i] ) ;
205 std::stringstream str ;
206 for(
unsigned int j=0 ; j < vec.size() ; ++j ){
224 while( ( par = xmlElement->
IterateChildren(
"parameter", par ) ) != 0 ){
230 std::string value(
"") ;
243 std::vector<std::string> stringValues ;
247 std::for_each( value.begin(), value.end(), t ) ;
251 if( stringValues.size() == 0 )
265 }
else if( type ==
"double" ){
269 }
else if( type ==
"string" ){
273 }
else if( type ==
"IntVec" ){
276 transform( stringValues.begin() , stringValues.end() , back_inserter(v) ,
intVal ) ;
280 }
else if( type ==
"DoubleVec" ){
283 transform( stringValues.begin() , stringValues.end() , back_inserter(v) ,
doubleVal ) ;
286 }
else if( type ==
"StringVec" ){
Implementation of GearParameters - a set off parameters that can be used to describe the geometrical ...
virtual const std::vector< std::string > & getIntVecKeys() const =0
All keys of IntVec variables.
virtual const std::vector< std::string > & getStringVecKeys() const =0
All keys of StringVec variables.
virtual void setIntVals(const std::string &key, const std::vector< int > &vals)
Integer values for key.
virtual void setDoubleVals(const std::string &key, const std::vector< double > &vals)
Double values for key.
virtual int getIntVal(const std::string &key) const =0
Integer value for key.
virtual const std::vector< std::string > & getDoubleKeys() const =0
All keys of double variables.
const char * Value() const
The meaning of 'value' changes for the specific type of TiXmlNode.
virtual void setStringVals(const std::string &key, const std::vector< std::string > &vals)
String values for key.
static void setParametersFromXML(const TiXmlElement *xmlElement, GearParametersImpl *gearParams)
Static helper function that can be used by other subclass handlers to read parameters.
virtual const std::vector< std::string > & getIntKeys() const =0
All keys of int variables.
virtual const std::vector< double > & getDoubleVals(const std::string &key) const =0
Double values for key.
Abstract interface for a set of parameters that can be used to describe the geometrical properties of...
Helper class for XMLParser.
virtual const std::vector< std::string > & getStringKeys() const =0
All keys of string variables.
virtual void setGearParameters(const std::string &key, GearParameters *gearParameters)=0
Set named parameters for key.
static void getXMLForParameters(TiXmlElement *xmlElement, const GearParameters *gearParams)
Static helper function that can be used by other subclass handlers to create XML for parameters...
The parent class for everything in the Document Object Model.
double doubleVal(const std::string &str)
helper method
ParseException used for parse errors, e.g.
std::string getXMLAttribute(const TiXmlNode *node, const std::string &name)
Helper method used for parsing XML.
virtual GearParameters * fromXML(const TiXmlElement *xmlElement, GearMgr *gearMgr=0) const
Creates the appropriate GearParameters subclass from the given XML element (node) ...
virtual const std::vector< int > & getIntVals(const std::string &key) const =0
Integer values for key.
virtual const std::vector< std::string > & getDoubleVecKeys() const =0
All keys of DoubleVec variables.
The element is a container class.
virtual void setIntVal(const std::string &key, int val)
Set Integer value for key.
TiXmlNode * InsertEndChild(const TiXmlNode &addThis)
Add a new node related to this.
virtual TiXmlElement toXML(const GearParameters ¶meters) const
Creates an XML node for the given parameters.
void SetDoubleAttribute(const char *name, double value)
Sets an attribute of name to a given value.
virtual const std::string & getStringVal(const std::string &key) const =0
String value for key.
const TiXmlNode * FirstChild() const
The first child of this node. Will be null if there are no children.
virtual const std::vector< std::string > & getStringVals(const std::string &key) const =0
String values for key.
Abstract interface for a manager class that returns the Gear classes for the relevant subdetectors...
const TiXmlNode * IterateChildren(const TiXmlNode *previous) const
An alternate way to walk the children of a node.
void SetAttribute(const char *name, const char *value)
Sets an attribute of name to a given value.
virtual void setStringVal(const std::string &key, const std::string &val)
String value for key.
int intVal(const std::string &str)
helper method
virtual void setDoubleVal(const std::string &key, double val)
Double value for key.
virtual double getDoubleVal(const std::string &key) const =0
Double value for key.