#ifndef _EFFINFO_HPP #define _EFFINFO_HPP #include #include #include #include #include #include namespace eff_utils { class TrigVersion { float _min ; float _max ; public: TrigVersion() : _min(0), _max(0) {} TrigVersion(const std::string& version) ; TrigVersion(const std::string& version_min, const std::string& version_max) ; bool Contains(const TrigVersion& version) const { return (version._min >= _min) && (_max < 0 || version._min <= _max) && (_max <0 || version._max <= _max) && (version._max <0 || version._max >= _min) ; } bool isContainedBy(const TrigVersion& version) const { return version.Contains(*this); } bool operator== (const TrigVersion& version) const { return (_min == version._min) && (_max == version._max);} bool operator!= (const TrigVersion& version) const { return (_min != version._min) || (_max != version._max);} } ; class EffInfo { public: EffInfo() {;} virtual ~EffInfo(); // ------------ Efficiency meta data --------------------------------- void EffType( const std::string & type) { setEntry("EffType", type);} std::string EffType() const { std::string type="UNDEFINED"; getEntry("EffType",type); return type; } void EffName( const std::string & name) { setEntry("EffName",name);} std::string EffName() const { std::string name = "UNDEFINED"; getEntry("EffName",name); return name; } void EffVarNames(const std::vector& names ) { setEntry("EffVarNames",names); } std::vector EffVarNames() const { std::vector< std::string > names; getEntry("EffVarNames",names); return names; } int EffNVars() const { int n = 0; bool retval = NParameters("EffVarNames", n); if( retval ) return n; else return -1; }; void EffVersion( int version) { setEntry("EffVersion",version); } int EffVersion() const { int retval = -1; getEntry("EffVersion",retval); return retval; } void EffMethod( const std::string & input) { setEntry("EffMethod",input);} std::string EffMethod() const { std::string output="UNDEFINED"; getEntry("EffMethod",output); return output; } void EffTagQuality( const std::string & input) { setEntry("EffTagQuality",input);} std::string EffTagQuality() const { std::string output="UNDEFINED"; getEntry("EffTagQuality",output); return output; } //-------- Epoch defenition ------------------------------- void RunRangeLow( long lo) { setEntry("RunRangeLow",lo); } long RunRangeLow() const { long retval = -1; getEntry("RunRangeLow",retval); return retval; } void RunRangeHigh( long hi) { setEntry("RunRangeHigh",hi); } long RunRangeHigh() const { long retval = -1; getEntry("RunRangeHigh", retval); return retval; } void DQDefinition( const std::string & input) { setEntry("DQDefinition",input);} std::string DQDefinition() const { std::string output="UNDEFINED"; getEntry("DQDefinition",output); return output; } void DataSetName( const std::string & input) { setEntry("DataSetName",input);} std::string DataSetName() const { std::string output="UNDEFINED"; getEntry("DataSetName",output); return output; } // trigger version can be formatted as "v14" or "14" or "v14.99" or "14.99" // only one version allowed. If you need to specify minimal and maximal versions // use TriggerVersionLow and TriggerVersionHigh void TriggerVersion( const std::string & input) { if (TriggerVersionHigh() != "UNDEFINED" || TriggerVersionLow() != "UNDEFINED") throw std::runtime_error("TriggerVersion keyword can not be used if TriggerVersionHigh or TriggerVersionLow is used before"); setEntry("TriggerVersion",input); } std::string TriggerVersion() const { std::string output="UNDEFINED"; getEntry("TriggerVersion",output); return output; } // trigger version can be formatted as "v14" or "14" or "v14.99" or "14.99" void TriggerVersionHigh( const std::string & input) { if (TriggerVersion() != "UNDEFINED") throw std::runtime_error("TriggerVersionHigh keyword can not be used if TriggerVersion is used before"); setEntry("TriggerVersionHigh",input); } std::string TriggerVersionHigh() const { std::string output="UNDEFINED"; getEntry("TriggerVersionHigh",output); return output; } // trigger version can be formatted as "v14" or "14" or "v14.99" or "14.99" void TriggerVersionLow( const std::string & input) { if (TriggerVersion() != "UNDEFINED") throw std::runtime_error("TriggerVersionLow keyword can not be used if TriggerVersion is used before"); setEntry("TriggerVersionLow",input); } std::string TriggerVersionLow() const { std::string output="UNDEFINED"; getEntry("TriggerVersionLow",output); return output; } // ------------ Object meta data ------------------------------------ void ObjType( const std::string & type) { setEntry("ObjType",type);} std::string ObjType() const { std::string type="UNDEFINED"; getEntry("ObjType",type); return type; } void ObjQuality( const std::string & quality) { setEntry("ObjQuality",quality);} std::string ObjQuality() const { std::string quality = "UNDEFINED"; getEntry("ObjQuality",quality); return quality; } void ObjVersion( int version) { setEntry("ObjVersion",version); } int ObjVersion() const { int retval = -1; getEntry("ObjVersion",retval); return retval; } void ObjRelativeTo( const std::string & input) { setEntry("ObjRelativeTo",input);} std::string ObjRelativeTo() const { std::string output="UNDEFINED"; getEntry("ObjRelativeTo",output); return output; } // ------------ Additional meta data --------------------------------- int D0NoteID() const { int retval = -1; getEntry("D0NoteID",retval); return retval; } void D0NoteID( int id ) { setEntry("D0NoteID",id); } /// several comments line could be added void Comments( const std::string & input) { setEntry("Comments",input);} std::vector Comments() const { std::vector output; getEntry("Comments",output); return output; } // --------------- END of the META DATA -------------- // make standard name using meta data values // if ConvertToLower set to true, will use soem of the date in the lower register in the lower register std::string MakeFileName(bool ConvertToLower=false) const ; template void setEntry( const std::string & id, const T & value) { std::string entry = ToString( value ); if (entry.empty()) return ; std::vector< std::string> vec; vec.push_back( entry ); _map[id] = vec; } void setEntry( const std::string & id, const std::vector< std::string > & values) { _map[id] = values; } template< class T> bool addToEntry( const std::string & id, const T & value) { std::map< std::string, std::vector< std::string> >::iterator mapIter = _map.find(id); if( mapIter == _map.end() ) return false; std::vector< std::string > & vec = mapIter->second; std::string val = ToString( value ); vec.push_back( val ); return true; } template bool getEntry( const std::string & id, T & value, int i =0) const { T tmp; std::map >::const_iterator mapIter = _map.find(id); if( mapIter == _map.end() ) return false; const std::vector< std::string > & vec = mapIter->second; if( i > (int) vec.size() ) return false; const std::string & svalue = vec.at(i); std::istringstream ist( svalue ); if( ist >> tmp ) { value = tmp; return true; } else return false; } bool getEntry( const std::string & id, std::vector< std::string> & vec) const { // now lets get the whole vector! std::map >::const_iterator mapIter = _map.find(id); if( mapIter == _map.end() ) return false; vec = mapIter->second; return true; } bool NParameters( const std::string & id, int & i) const { std::map< std::string, std::vector >::const_iterator mapIter = _map.find(id); if( mapIter == _map.end() ) return false; else { const std::vector< std::string > & vec = mapIter->second; i = vec.size(); return true; } } template std::string ToString(const type & val) const { std::ostringstream streamOut; streamOut << val; return streamOut.str(); } virtual bool ParseInputLine( const std::string & key, const std::vector< std::string> & line ); /// return true if this object has exactly the same number of parameters and all parameters are the same /// D0Note number and Comments parameters are excluded from the comparison. bool operator== (const EffInfo& info) const {return isContainedBy(info) && Contains(info);} bool operator!= (const EffInfo& info) const {return !isContainedBy(info) || !Contains(info);} bool isContainedBy( const EffInfo & info) const {return info.Contains(*this) ;} // Return true if : // - info is more specific request than than this object // (has more parameters specified) AND // - all fields of this object are the same as fields in the info object AND // ( TriggerVersion matched to the trigger version in info object OR // triggerVersion inside region TriggerVersionLow -- TriggerVersionHigh) bool Contains( const EffInfo & info) const ; void Clear() {_map.clear();} private: std::map > _map; friend std::ostream & operator << ( std::ostream & os, const EffInfo & ei); }; } inline std::ostream & eff_utils::operator << ( std::ostream & os, const eff_utils::EffInfo & info) { for( std::map< std::string, std::vector >::const_iterator mapIter = info._map.begin(); mapIter != info._map.end(); ++mapIter) { const std::string & key = mapIter->first; std::vector< std:: string > vec = mapIter->second; os << key << " : "; int n = vec.size(); for( int i = 0; i < n; ++i) { os << vec.at(i) << " "; } os << std::endl; } return os; } #endif // _EFFINFO_HPP