#ifndef CONFIGDICTIONARY_H #define CONFIGDICTIONARY_H #include "TObject.h" #include "ReturnCodes.h" #include "TStopwatch.h" #include "TROOT.h" #include #include #include #include #include "TLorentzVector.h" #include #include "TMath.h" #include "TString.h" #include "TTree.h" #define ARRAY_DELIM '$' class ConfigDictionary{ public: typedef std::map::iterator CDIter; ConfigDictionary(); ConfigDictionary(std::string); virtual ~ConfigDictionary(){};//empty virtual destructor ClassDef(ConfigDictionary,1); std::string ToString(); void FromString(std::string); //These throw errors if couldn't find key: //Most of methods below are just using templates to //make them usable in Cint. std::string GetString(std::string)throw(std::string); int GetInt(std::string)throw(std::string); double GetDouble(std::string)throw(std::string); bool GetBool(std::string)throw(std::string); //These will always set 'something' into map: void SetString(std::string,std::string); void SetDouble(std::string,double); void SetInt(std::string,int); void SetBool(std::string,bool); CDIter Begin(){return configMap.begin();}; CDIter End(){return configMap.end();}; //_________________________________________________________________________ template T Get(std::string key) throw (std::string) { //This method will get object of any class //that was - presumably - stored before in string format in CD. //Object needs to have proper >> operator. //If operation fails, returned item should have default value //depending on its empty constructor. //For strings containing spaces it won't work properly, as it //would extract only first space followed item! if (configMap.find(key) == configMap.end()) { Error( "ConfigDictionary::Get", "Couldn't find the key: %s!", key.c_str()); throw(key); } std::istringstream inStream(configMap[key]); T item; inStream >> item; return item; } //_____________________________________________________________________________ template void Set(std::string key,T value){ //Sets value to key, converts T to string first with << operator. std::stringstream ss; ss< int GetArray(std::string key,std::vector & output)throw(std::string){ //Preconditions: T must have >> operator //Effect: searches for key in map and pushes values stored in it into output vector //Returns: number of elements pushed into vector int retNumber = 0; if (configMap.find(key) == configMap.end()){ Error( "ConfigDictionary::GetInt", "Couldn't find the key: %s!",key.c_str()); throw(key); } std::istringstream arrayString(configMap[key]); std::string itemString; //Dangerous - maybe? - exceptions for ss not handled... while (arrayString){ std::getline(arrayString,itemString,ARRAY_DELIM); std::stringstream itemStream(itemString); if (itemString.length() > 0){ T item; itemStream>>item; output.push_back(item); retNumber++; } } return retNumber; } //_________________________________________________________________________ template void SetArray(std::string key,std::vector & input){ std::ostringstream arrayString; for (unsigned int i=0;i configMap; }; #endif