DD4hep - The AIDA detector description toolkit for high energy physics experiments
DD4hep  Rev:Unversioneddirectory
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Conditions.h
Go to the documentation of this file.
1 //==========================================================================
2 // AIDA Detector description implementation for LCD
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_CONDITIONS_CONDITIONS_H
14 #define DD4HEP_CONDITIONS_CONDITIONS_H
15 
16 // Framework include files
17 #include "DD4hep/OpaqueData.h"
18 #include "DD4hep/Handle.h"
19 #include "DD4hep/IOV.h"
20 
21 // C/C++ include files
22 #include <vector>
23 
25 namespace DD4hep {
26 
28  class BasicGrammar;
29 
31  namespace Geometry {
32  // Forward declarations
33  class DetElement;
34  class LCDD;
35  }
36 
38  namespace Conditions {
39 
40  // The DetElement is a central object. We alias it here.
42  using Geometry::LCDD;
43 
44  // Forward declarations
45  class ConditionsManagerObject;
46  class ConditionsManager;
47  class ConditionsLoader;
48  class UserPool;
49 
51  namespace Interna {
52  class ConditionContainer;
53  class ConditionObject;
54  }
55 
57 
70  class Condition: public Handle<Interna::ConditionObject> {
71  public:
75  typedef unsigned int key_type;
77  typedef IOV iov_type;
79  typedef unsigned int mask_type;
80 
81  public:
82  enum StringFlags {
83  WITH_IOV = 1<<0,
84  WITH_ADDRESS = 1<<1,
85  WITH_TYPE = 1<<2,
86  WITH_COMMENT = 1<<4,
87  WITH_DATATYPE = 1<<5,
88  WITH_DATA = 1<<6,
89  NO_NAME = 1<<20,
91  };
93  INACTIVE = 0,
94  ACTIVE = 1<<0,
95  CHECKED = 1<<2,
96  DERIVED = 1<<3,
97  TEMPERATURE = 1<<4,
98  PRESSURE = 1<<5,
99  ALIGNMENT = 1<<6,
100  // Keep bit 7-15 for other generic types
101  // Bit 16-31 is reserved for user classifications
104  };
105 
107 
112  class Processor {
113  public:
115  Processor();
117  virtual ~Processor() = default;
119  virtual int operator()(Condition c) = 0;
120  };
121 
123  Condition() = default;
125  Condition(const Condition& c) = default;
127  Condition(Object* p);
129  template <typename Q> Condition(const Handle<Q>& e) : Handle<Object>(e) {}
131  Condition(const std::string& name, const std::string& type);
133  Condition& operator=(const Condition& c) = default;
134 
136  std::string str(int with_data=WITH_IOV|WITH_ADDRESS|WITH_DATATYPE) const;
137 
139  int dataType() const;
142  OpaqueData& data() const;
143 
145  const IOVType& iovType() const;
148  const iov_type& iov() const;
149 
151  const std::string& type() const;
154  const std::string& comment() const;
156  const std::string& value() const;
158  const std::string& address() const;
159 
161  const std::type_info& typeInfo() const;
164  const BasicGrammar& descriptor() const;
166  key_type key() const;
167 
169  Condition& rebind();
171 
177  template <typename T> T& bind();
183  template <typename T> T& bind(const std::string& val);
185  template <typename T> T& get();
187  template <typename T> const T& get() const;
189  bool is_bound() const { return isValid() ? data().is_bound() : false; }
190  };
191 
194  }
195 
197 
206  class Container : public Handle<Interna::ConditionContainer> {
207 
208  public:
210 
215  class Processor {
216  public:
218  Processor();
220  virtual ~Processor() = default;
222  virtual int operator()(Container container) = 0;
223  };
224 
232  typedef std::pair<key_type, std::string> key_value;
234  typedef std::map<key_type, key_value> Keys;
235 
236  public:
238  Container() = default;
240  Container(const Container& c) = default;
241 
243  template <typename Q> Container(const Handle<Q>& e) : Handle<Object>(e) {}
244 
246  Container& operator=(const Container& c) = default;
247 
249  size_t numKeys() const;
250 
252  const Keys& keys() const;
253 
255  Condition get(const std::string& condition_key, const iov_type& iov);
256 
258  Condition get(key_type condition_key, const iov_type& iov);
259 
261  Condition get(const std::string& condition_key, const UserPool& pool);
262 
264  Condition get(key_type condition_key, const UserPool& pool);
265  };
266 
268 
273  class ConditionKey {
274  public:
277 
279  std::string name;
282 
283  public:
285  ConditionKey() : hash(0) {}
287  ConditionKey(const std::string& compare);
289  ConditionKey(const std::string& s, key_type h) : name(s), hash(h) {}
291  ConditionKey(const ConditionKey& c) : name(c.name), hash(c.hash) {}
292 
294  static key_type hashCode(const char* value);
296  static key_type hashCode(const std::string& value);
297 
299  ConditionKey& operator=(const std::string& value);
301  ConditionKey& operator=(const ConditionKey& key);
303  bool operator==(const ConditionKey& compare) const;
305  bool operator==(const key_type compare) const;
307  bool operator==(const std::string& compare) const;
308 
310  bool operator<(const ConditionKey& compare) const;
312  bool operator<(const key_type compare) const;
314  bool operator<(const std::string& compare) const;
315 
317  operator const std::string& () const { return name; }
319  operator key_type () const { return hash; }
320  };
321 
324  { return hash32(value); }
325 
327  inline ConditionKey::key_type ConditionKey::hashCode(const std::string& value)
328  { return hash32(value); }
329 
332  if ( this != &key ) {
333  hash = key.hash;
334  name = key.name;
335  }
336  return *this;
337  }
338 
340  inline bool ConditionKey::operator==(const ConditionKey& compare) const
341  { return hash == compare.hash; }
342 
344  inline bool ConditionKey::operator==(const key_type compare) const
345  { return hash == compare; }
346 
348  inline bool ConditionKey::operator<(const ConditionKey& compare) const
349  { return hash < compare.hash; }
350 
352  inline bool ConditionKey::operator<(const key_type compare) const
353  { return hash < compare; }
354 
357 
358  // Utility type definitions
359  typedef std::vector<Condition> RangeConditions;
360  typedef std::pair<RangeConditions,bool> RangeStatus;
361 
362  } /* End namespace Conditions */
363 } /* End namespace DD4hep */
364 #endif /* DD4HEP_CONDITIONS_CONDITIONS_H */
ConditionKey & operator=(const std::string &value)
Assignment operator from the string representation.
Definition: Conditions.cpp:45
std::pair< key_type, std::string > key_value
Forward definition of the mapping type.
Definition: Conditions.h:232
Condition(const Handle< Q > &e)
Constructor to be used when reading the already parsed object.
Definition: Conditions.h:129
bool operator<(const ConditionKey &compare) const
Operator less (for map insertions) using key object.
Definition: Conditions.h:348
OpaqueData & data() const
Access the IOV block.
Definition: Conditions.cpp:92
Condition & operator=(const Condition &c)=default
Assignment operator.
const char * name() const
Access the object name (or "" if not supported by the object)
Condition & rebind()
Re-evaluate the conditions data according to the previous bound type definition.
Definition: Conditions.cpp:149
Interface for conditions pool optimized to host conditions updates.
T & bind()
Bind the data of the conditions object to a given format.
bool isValid() const
Check the validity of the object held by the handle.
Definition: Handle.h:124
bool operator==(const ConditionKey &compare) const
Equality operator using key object.
Definition: Conditions.h:340
ConditionKey(const ConditionKey &c)
Copy constructor.
Definition: Conditions.h:291
Condition::iov_type iov_type
Forward definition of the iov type.
Definition: Conditions.h:230
The data class behind a conditions container handle.
unsigned int mask_type
Forward definition of the object properties.
Definition: Conditions.h:79
const std::string & value() const
Access the value field of the condition as a string.
Definition: Conditions.cpp:112
The data class behind a conditions handle.
bool is_bound() const
Check if object is already bound....
Definition: Conditions.h:189
Base class describing string evaluation to C++ objects using boost::spirit.
Definition: BasicGrammar.h:37
Class describing an opaque data block.
Definition: OpaqueData.h:36
Interna::ConditionContainer Object
Standard object type.
Definition: Conditions.h:226
const std::string & address() const
Access the address string [e.g. database identifier].
Definition: Conditions.cpp:122
std::map< key_type, key_value > Keys
Definition of the keys.
Definition: Conditions.h:234
Main condition object handle.
Definition: Conditions.h:70
Container class for condition handles aggregated by a detector element.
Definition: Conditions.h:206
Condition::key_type key_type
Forward definition of the key type.
Definition: Conditions.h:228
TGeoShape * s
Definition: Volumes.cpp:294
virtual int operator()(Container container)=0
Container callback for object processing.
Abstract base for processing callbacks to container objects.
Definition: Conditions.h:215
return e
Definition: Volumes.cpp:297
unsigned int key_type
Forward definition of the key type.
Definition: Conditions.h:75
DD4hep::Geometry::DetElement DetElement
std::string str(int with_data=WITH_IOV|WITH_ADDRESS|WITH_DATATYPE) const
Output method.
Definition: Conditions.cpp:65
ConditionKey()
Default constructor.
Definition: Conditions.h:285
int dataType() const
Access the data type.
Definition: Conditions.cpp:87
ConditionKey(const std::string &s, key_type h)
Constructor from string.
Definition: Conditions.h:289
Key definition to optimize ans simplyfy the access to conditions entities.
Definition: Conditions.h:273
const Keys & keys() const
Known keys of conditions in this container.
Definition: Conditions.cpp:180
Class describing the interval of validty.
Definition: IOV.h:59
Container()=default
Default constructor.
virtual int operator()(Condition c)=0
Conditions callback for object processing.
const std::type_info & typeInfo() const
Access to the type information.
Definition: Conditions.cpp:127
Class describing the interval of validty type.
Definition: IOV.h:33
Condition()=default
Default constructor.
const IOVType & iovType() const
Access the IOV type.
Definition: Conditions.cpp:97
Interna::ConditionObject Object
Standard object type.
Definition: Conditions.h:73
std::pair< RangeConditions, bool > RangeStatus
Definition: Conditions.h:360
bool is_bound() const
Check if object is already bound....
Definition: OpaqueData.h:66
key_type key() const
Hash identifier.
Definition: Conditions.cpp:132
const iov_type & iov() const
Access the IOV block.
Definition: Conditions.cpp:102
const std::string & comment() const
Access the comment field of the condition.
Definition: Conditions.cpp:117
std::string name
String representation of the key object.
Definition: Conditions.h:279
unsigned int hash32(const char *key)
We need it so often: one-at-time 32 bit hash function.
Definition: Primitives.h:39
virtual ~Processor()=default
Default destructor.
Container & operator=(const Container &c)=default
Assignment operator.
const std::string & type() const
Access the type field of the condition.
Definition: Conditions.cpp:107
static key_type hashCode(const char *value)
Hash code generation from input string.
Definition: Conditions.h:323
const BasicGrammar & descriptor() const
Access to the grammar type.
Definition: Conditions.cpp:137
Handle: a templated class like a shared pointer, which allows specialized access to tgeometry objects...
Definition: Handle.h:87
key_type hash
Hashed key representation.
Definition: Conditions.h:281
ConditionKey make_key(Condition c)
Access the key of the condition.
Definition: Conditions.cpp:31
IOV iov_type
Forward definition of the iov type.
Definition: Conditions.h:77
std::vector< Condition > RangeConditions
Definition: Conditions.h:359
Abstract base for processing callbacks to conditions objects.
Definition: Conditions.h:112
Container(const Handle< Q > &e)
Constructor to be used when reading the already parsed object.
Definition: Conditions.h:243
Condition::key_type key_type
Forward definition of the key type.
Definition: Conditions.h:276
size_t numKeys() const
Access the number of conditons keys available for this detector element.
Definition: Conditions.cpp:171
virtual ~Processor()=default
Default destructor.