File indexing completed on 2025-02-21 09:58:00
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #ifndef DD4HEP_CONDITIONSDATA_H
0014 #define DD4HEP_CONDITIONSDATA_H
0015
0016
0017 #include <DD4hep/Objects.h>
0018 #include <DD4hep/Conditions.h>
0019
0020
0021 #include <vector>
0022 #include <stdexcept>
0023
0024
0025 namespace dd4hep {
0026
0027
0028 namespace cond {
0029
0030
0031
0032
0033
0034
0035
0036
0037 struct ClientData {
0038 virtual ~ClientData();
0039 virtual void release() = 0;
0040 };
0041
0042
0043
0044
0045
0046
0047
0048
0049 class AbstractMap {
0050 private:
0051 public:
0052 enum {
0053 REGULAR = 0,
0054 ALIGNMENT = 6
0055 };
0056 typedef std::map<std::string, OpaqueDataBlock> Params;
0057 ClientData* clientData;
0058 Params params;
0059 int classID;
0060
0061 AbstractMap();
0062
0063 AbstractMap(const AbstractMap& c);
0064
0065 virtual ~AbstractMap();
0066
0067 AbstractMap& operator=(const AbstractMap& c);
0068
0069 template <typename T> T* option() const {
0070 return static_cast<T*>(clientData);
0071 }
0072
0073 size_t size() const {
0074 return params.size();
0075 }
0076
0077 const Params::value_type& firstParam() const {
0078 Params::const_iterator i=std::begin(params);
0079 if ( i != std::end(params) ) return (*i);
0080 throw std::runtime_error("AbstractMap: Failed to access non-existing first parameter");
0081 }
0082
0083 Params::value_type& firstParam() {
0084 Params::iterator i=std::begin(params);
0085 if ( i != std::end(params) ) return (*i);
0086 throw std::runtime_error("AbstractMap: Failed to access non-existing first parameter");
0087 }
0088
0089 template <typename T> const T& first() const {
0090 Params::const_iterator i=std::begin(params);
0091 if ( i != std::end(params) ) return (*i).second.get<T>();
0092 throw std::runtime_error("AbstractMap: Failed to access non-existing first item");
0093 }
0094
0095 template <typename T> T& first() {
0096 Params::iterator i=std::begin(params);
0097 if ( i != std::end(params) ) return (*i).second.get<T>();
0098 throw std::runtime_error("AbstractMap: Failed to access non-existing first item");
0099 }
0100
0101 template <typename T> const T& operator[](const std::string& item) const {
0102 Params::const_iterator i=params.find(item);
0103 if ( i != std::end(params) ) return (*i).second.get<T>();
0104 throw std::runtime_error("AbstractMap: Failed to access non-existing item:"+item);
0105 }
0106
0107 template <typename T> T& operator[](const std::string& item) {
0108 Params::iterator i=params.find(item);
0109 if ( i != std::end(params) ) return (*i).second.get<T>();
0110 throw std::runtime_error("AbstractMap: Failed to access non-existing item:"+item);
0111 }
0112
0113 template <typename T> const T& get(const std::string& item) const {
0114 Params::const_iterator i=params.find(item);
0115 if ( i != std::end(params) ) return (*i).second.get<T>();
0116 throw std::runtime_error("AbstractMap: Failed to access non-existing item:"+item);
0117 }
0118
0119 template <typename T> T& get(const std::string& item) {
0120 Params::iterator i=params.find(item);
0121 if ( i != std::end(params) ) return (*i).second.get<T>();
0122 throw std::runtime_error("AbstractMap: Failed to access non-existing item:"+item);
0123 }
0124 };
0125
0126 }
0127 }
0128 #endif