DD4hep  1.30.0
Detector Description Toolkit for High Energy Physics
ConditionsData.h
Go to the documentation of this file.
1 //==========================================================================
2 // AIDA Detector description implementation
3 //--------------------------------------------------------------------------
4 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
5 // All rights reserved.
6 //
7 // For the licensing terms see $DD4hepINSTALL/LICENSE.
8 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
9 //
10 // Author : M.Frank
11 //
12 //==========================================================================
13 #ifndef DD4HEP_CONDITIONSDATA_H
14 #define DD4HEP_CONDITIONSDATA_H
15 
16 // Framework include files
17 #include <DD4hep/Objects.h>
18 #include <DD4hep/Conditions.h>
19 
20 // C/C++ include files
21 #include <vector>
22 #include <stdexcept>
23 
25 namespace dd4hep {
26 
28  namespace cond {
29 
31 
37  struct ClientData {
38  virtual ~ClientData();
39  virtual void release() = 0;
40  };
41 
43 
49  class AbstractMap {
50  private:
51  public:
52  enum {
53  REGULAR = 0,
54  ALIGNMENT = 6
55  };
56  typedef std::map<std::string, OpaqueDataBlock> Params;
59  int classID;
61  AbstractMap();
63  AbstractMap(const AbstractMap& c);
65  virtual ~AbstractMap();
69  template <typename T> T* option() const {
70  return static_cast<T*>(clientData);
71  }
73  size_t size() const {
74  return params.size();
75  }
77  const Params::value_type& firstParam() const {
78  Params::const_iterator i=std::begin(params);
79  if ( i != std::end(params) ) return (*i);
80  throw std::runtime_error("AbstractMap: Failed to access non-existing first parameter");
81  }
83  Params::value_type& firstParam() {
84  Params::iterator i=std::begin(params);
85  if ( i != std::end(params) ) return (*i);
86  throw std::runtime_error("AbstractMap: Failed to access non-existing first parameter");
87  }
89  template <typename T> const T& first() const {
90  Params::const_iterator i=std::begin(params);
91  if ( i != std::end(params) ) return (*i).second.get<T>();
92  throw std::runtime_error("AbstractMap: Failed to access non-existing first item");
93  }
95  template <typename T> T& first() {
96  Params::iterator i=std::begin(params);
97  if ( i != std::end(params) ) return (*i).second.get<T>();
98  throw std::runtime_error("AbstractMap: Failed to access non-existing first item");
99  }
101  template <typename T> const T& operator[](const std::string& item) const {
102  Params::const_iterator i=params.find(item);
103  if ( i != std::end(params) ) return (*i).second.get<T>();
104  throw std::runtime_error("AbstractMap: Failed to access non-existing item:"+item);
105  }
107  template <typename T> T& operator[](const std::string& item) {
108  Params::iterator i=params.find(item);
109  if ( i != std::end(params) ) return (*i).second.get<T>();
110  throw std::runtime_error("AbstractMap: Failed to access non-existing item:"+item);
111  }
113  template <typename T> const T& get(const std::string& item) const {
114  Params::const_iterator i=params.find(item);
115  if ( i != std::end(params) ) return (*i).second.get<T>();
116  throw std::runtime_error("AbstractMap: Failed to access non-existing item:"+item);
117  }
119  template <typename T> T& get(const std::string& item) {
120  Params::iterator i=params.find(item);
121  if ( i != std::end(params) ) return (*i).second.get<T>();
122  throw std::runtime_error("AbstractMap: Failed to access non-existing item:"+item);
123  }
124  };
125 
126  } /* End namespace cond */
127 } /* End namespace dd4hep */
128 #endif // DD4HEP_CONDITIONSDATA_H
dd4hep::cond::AbstractMap::AbstractMap
AbstractMap()
Default constructor.
Definition: ConditionsData.cpp:51
Objects.h
cond
AlignmentCondition::Object * cond
Definition: AlignmentsCalculator.cpp:68
dd4hep::cond::ClientData
Client data addition.
Definition: ConditionsData.h:37
dd4hep::cond::AbstractMap::classID
int classID
Definition: ConditionsData.h:59
dd4hep::cond::AbstractMap::ALIGNMENT
@ ALIGNMENT
Definition: ConditionsData.h:54
dd4hep::cond::AbstractMap::firstParam
Params::value_type & firstParam()
Simplify access to first item of the parameter list.
Definition: ConditionsData.h:83
dd4hep::cond::AbstractMap::first
const T & first() const
Simplify access to first item of the parameter list (const access)
Definition: ConditionsData.h:89
dd4hep::cond::AbstractMap::first
T & first()
Simplify access to first item of the parameter list.
Definition: ConditionsData.h:95
dd4hep::cond::AbstractMap::option
T * option() const
Simplify access to client data.
Definition: ConditionsData.h:69
dd4hep::cond::AbstractMap::~AbstractMap
virtual ~AbstractMap()
Default destructor.
Definition: ConditionsData.cpp:63
dd4hep::cond::AbstractMap::firstParam
const Params::value_type & firstParam() const
Simplify access to first item of the parameter list (const access)
Definition: ConditionsData.h:77
dd4hep::cond::ClientData::release
virtual void release()=0
dd4hep::cond::AbstractMap::clientData
ClientData * clientData
Definition: ConditionsData.h:57
dd4hep::cond::AbstractMap::get
const T & get(const std::string &item) const
Simplify access to mapped item of the parameter list (const access)
Definition: ConditionsData.h:113
dd4hep::cond::AbstractMap::size
size_t size() const
Access the number of contained blocks.
Definition: ConditionsData.h:73
Conditions.h
dd4hep::cond::AbstractMap::REGULAR
@ REGULAR
Definition: ConditionsData.h:53
dd4hep::cond::AbstractMap::operator=
AbstractMap & operator=(const AbstractMap &c)
Assignment operator.
Definition: ConditionsData.cpp:70
dd4hep::cond::AbstractMap::get
T & get(const std::string &item)
Simplify access to mapped item of the parameter list.
Definition: ConditionsData.h:119
dd4hep::cond::AbstractMap::operator[]
const T & operator[](const std::string &item) const
Simplify access to mapped item of the parameter list (const access)
Definition: ConditionsData.h:101
dd4hep::cond::ClientData::~ClientData
virtual ~ClientData()
Default destructor.
Definition: ConditionsData.cpp:47
dd4hep::cond::AbstractMap::operator[]
T & operator[](const std::string &item)
Simplify access to mapped item of the parameter list.
Definition: ConditionsData.h:107
dd4hep
Namespace for the AIDA detector description toolkit.
Definition: AlignmentsCalib.h:28
dd4hep::cond::AbstractMap::params
Params params
Definition: ConditionsData.h:58
dd4hep::cond::AbstractMap::Params
std::map< std::string, OpaqueDataBlock > Params
Definition: ConditionsData.h:56
dd4hep::cond::AbstractMap
Conditions data block. Internaly maps other objects to abstract data blocks.
Definition: ConditionsData.h:49