DD4hep  1.30.0
Detector Description Toolkit for High Energy Physics
ConditionDerived.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_CONDITIONDERIVED_H
14 #define DD4HEP_CONDITIONDERIVED_H
15 
16 // Framework include files
17 #include <DD4hep/Memory.h>
18 #include <DD4hep/Conditions.h>
20 
21 // C/C++ include files
22 #include <memory>
23 
25 namespace dd4hep {
26 
28  class BasicGrammar;
29 
31  namespace cond {
32 
34  class DependencyBuilder;
35  class ConditionResolver;
36  class ConditionDependency;
37  class ConditionUpdateCall;
38  class ConditionUpdateContext;
39  class ConditionUpdateUserContext;
40 
42 
50  public:
53  };
54 
56 
62  public:
64  virtual ~ConditionResolver();
66  virtual Handle<NamedObject> manager() const = 0;
68  virtual Detector& detectorDescription() const = 0;
70  virtual const IOV& requiredValidity() const = 0;
72  virtual ConditionsMap& conditionsMap() const = 0;
74  virtual Condition get(const ConditionKey& key) = 0;
76  virtual Condition get(const ConditionKey& key, bool throw_if_not) = 0;
80  virtual Condition get(Condition::key_type key, bool throw_if_not) = 0;
83  const ConditionDependency* dependency,
84  bool throw_if_not) = 0;
86  virtual std::vector<Condition> get(DetElement de) = 0;
88  virtual std::vector<Condition> get(Condition::detkey_type key) = 0;
90  virtual std::vector<Condition> getByItem(Condition::itemkey_type key) = 0;
91 
93 
95  virtual bool registerOne(const IOV& iov, Condition cond) = 0;
97  virtual size_t registerMany(const IOV& iov, const std::vector<Condition>& values) = 0;
99  template <typename CONT> size_t registerUnmapped(const IOV& iov, CONT& c) {
100  std::vector<Condition> conditions;
101  conditions.reserve(c.size());
102  std::copy(std::begin(c), std::end(c), std::back_inserter(conditions));
103  return this->registerMany(iov, conditions);
104  }
106  template <typename CONT> size_t registerMapping(const IOV& iov, CONT& c) {
107  std::vector<Condition> conditions;
108  conditions.reserve(c.size());
109  std::transform(std::begin(c), std::end(c), std::back_inserter(conditions), detail::get_2nd<CONT>());
110  return this->registerMany(iov, conditions);
111  }
112  };
113 
115 
137  public:
146 
147  public:
150  const ConditionDependency* d,
151  IOV* iov,
153 
155  void accessFailure(const ConditionKey& key_value) const;
156 
159  return resolver->detectorDescription();
160  }
161 
163  DetElement world() const;
164 
166  const IOV& requiredValidity() const {
167  return resolver->requiredValidity();
168  }
169 
172  return resolver->conditionsMap();
173  }
174 
176  const ConditionKey& key(size_t which) const;
177 
179  template<typename Q> Q* param() const {
180  return static_cast<Q*>(parameter);
181  }
182 
184 
188  std::vector<Condition> conditions(DetElement det) const {
189  return conditions(det.key());
190  }
191 
193 
197  std::vector<Condition> conditions(Condition::detkey_type det_key) const;
198 
200 
204  std::vector<Condition> getByItem(Condition::itemkey_type key) const;
205 
207 
211  Condition condition(const ConditionKey& key_value) const;
212 
214 
218  Condition condition(Condition::key_type key_value) const;
219 
221 
225  Condition condition(Condition::key_type key_value, bool throw_if_not) const;
226 
228 
232  template<typename T> T& get(const ConditionKey& key_value);
233 
235 
239  template<typename T> const T& get(const ConditionKey& key_value) const;
240 
242 
246  template<typename T> T& get(Condition::key_type key_value);
247 
249 
253  template<typename T> const T& get(Condition::key_type key_value) const;
254 
256 
258  bool registerOne(const IOV& iov, Condition cond);
260  size_t registerMany(const IOV& iov, const std::vector<Condition>& values);
262  template <typename CONT> size_t registerUnmapped(const IOV& iov_val, CONT& values) {
263  std::vector<Condition> conds;
264  conds.reserve(values.size());
265  std::copy(std::begin(values), std::end(values), std::back_inserter(conds));
266  return this->registerMany(iov_val, conds);
267  }
269  template <typename CONT> size_t registerMapping(const IOV& iov_val, CONT& values) {
270  std::vector<Condition> conds;
271  conds.reserve(values.size());
272  std::transform(std::begin(values), std::end(values), std::back_inserter(conds), detail::get_2nd<CONT>());
273  return this->registerMany(iov_val, conds);
274  }
275  };
276 
278 
284  protected:
290  virtual ~ConditionUpdateCall();
293 
294  public:
296  virtual Condition operator()(const ConditionKey& target,
297  ConditionUpdateContext& ctxt) = 0;
299  virtual void resolve(Condition /* c */, ConditionUpdateContext& /* ctxt */) {}
300  };
301 
303 
317  friend std::default_delete<ConditionDependency>;
318  protected:
320  int m_refCount {0};
321 
322  public:
328  std::vector<ConditionKey> dependencies;
330  std::shared_ptr<ConditionUpdateCall> callback;
331 
332  protected:
338  virtual ~ConditionDependency();
339 
340  public:
342  ConditionDependency(DetElement de, const std::string& item, std::shared_ptr<ConditionUpdateCall> call);
344  ConditionDependency(DetElement de, Condition::itemkey_type item_key, std::shared_ptr<ConditionUpdateCall> call);
348  Condition::key_type key() const { return target.hash; }
349 #if defined(DD4HEP_CONDITIONS_HAVE_NAME)
350  const char* name() const { return target.name.c_str(); }
352 #endif
353  ConditionDependency* addRef() { ++m_refCount; return this; }
356  void release() { if ( --m_refCount <= 0 ) delete this; }
357  };
358 
360 
366  protected:
368  std::unique_ptr<ConditionDependency> m_dependency;
369  public:
371  DependencyBuilder(DetElement de, Condition::itemkey_type item_key, std::shared_ptr<ConditionUpdateCall> call);
373  DependencyBuilder(DetElement de, const std::string& item, std::shared_ptr<ConditionUpdateCall> call);
375  virtual ~DependencyBuilder();
377  ConditionDependency* operator->() { return m_dependency.operator->(); }
379  void add(const ConditionKey& source_key);
382  };
383 
386  const ConditionDependency* dep,
387  IOV* i,
388  ConditionUpdateUserContext* user_param)
389  : resolver(resolv), dependency(dep), iov(i), parameter(user_param)
390  {
391  }
392 
394  inline const ConditionKey&
395  ConditionUpdateContext::key(size_t which) const {
396  return dependency->dependencies.at(which);
397  }
398 
400  template<typename T> inline T&
402  Condition cond = condition(key_value);
403  if ( cond.isValid() ) {
404  return cond.get<T>();
405  }
406  accessFailure(key_value);
407  throw std::runtime_error("ConditionUpdateCall");
408  }
409 
411  template<typename T> inline const T&
412  ConditionUpdateContext::get(const ConditionKey& key_value) const {
413  Condition cond = condition(key_value);
414  if ( cond.isValid() ) {
415  return cond.get<T>();
416  }
417  accessFailure(key_value);
418  throw std::runtime_error("ConditionUpdateCall");
419  }
420 
422  template<typename T> inline T&
424  return condition(key_value).get<T>();
425  }
426 
428  template<typename T> inline const T&
430  return condition(key_value).get<T>();
431  }
432 
433  } /* End namespace cond */
434 } /* End namespace dd4hep */
435 #endif // DD4HEP_CONDITIONDERIVED_H
dd4hep::cond::ConditionResolver
ConditionResolver class used by the derived conditions calculation mechanism.
Definition: ConditionDerived.h:61
dd4hep::cond::ConditionDependency::~ConditionDependency
virtual ~ConditionDependency()
Default destructor.
Definition: ConditionDerived.cpp:160
dd4hep::cond::ConditionResolver::get
virtual Condition get(Condition::key_type key)=0
Interface to access conditions by hash value.
cond
AlignmentCondition::Object * cond
Definition: AlignmentsCalculator.cpp:68
dd4hep::cond::ConditionResolver::~ConditionResolver
virtual ~ConditionResolver()
Standard destructor.
Definition: ConditionDerived.cpp:115
dd4hep::cond::ConditionResolver::conditionsMap
virtual ConditionsMap & conditionsMap() const =0
Accessor for the current conditons mapping.
dd4hep::cond::ConditionResolver::manager
virtual Handle< NamedObject > manager() const =0
Access to the conditions manager.
ConditionsInterna.h
dd4hep::cond::ConditionResolver::get
virtual Condition get(const ConditionKey &key)=0
Interface to access conditions by conditions key.
dd4hep::cond::ConditionUpdateContext::resolver
ConditionResolver * resolver
Internal reference to the resolver to access other conditions (Be careful)
Definition: ConditionDerived.h:139
dd4hep::cond::ConditionDependency::operator=
ConditionDependency & operator=(const ConditionDependency &c)=delete
Assignment operator.
dd4hep::ConditionKey::hash
Condition::key_type hash
Hashed key representation.
Definition: Conditions.h:287
dd4hep::cond::ConditionUpdateContext::accessFailure
void accessFailure(const ConditionKey &key_value) const
Throw exception on conditions access failure.
Definition: ConditionDerived.cpp:119
dd4hep::cond::ConditionUpdateContext::parameter
ConditionUpdateUserContext * parameter
A refernce to the user parameter.
Definition: ConditionDerived.h:145
dd4hep::cond::ConditionResolver::getByItem
virtual std::vector< Condition > getByItem(Condition::itemkey_type key)=0
Interface to access conditions by hash value of the item (only valid at resolve!)
dd4hep::cond::ConditionDependency::target
ConditionKey target
Key to the condition to be updated.
Definition: ConditionDerived.h:326
dd4hep::cond::ConditionUpdateContext::world
DetElement world() const
Access to the top level detector element.
Definition: ConditionDerived.cpp:30
dd4hep::Handle< NamedObject >
dd4hep::cond::ConditionUpdateContext::get
T & get(const ConditionKey &key_value)
Access of other conditions data from the resolver.
Definition: ConditionDerived.h:401
dd4hep::cond::ConditionResolver::registerUnmapped
size_t registerUnmapped(const IOV &iov, CONT &c)
Handle multi-condition inserts by callbacks with identical key. Handle unmapped containers.
Definition: ConditionDerived.h:99
dd4hep::cond::DependencyBuilder::release
ConditionDependency * release()
Release the created dependency and take ownership.
Definition: ConditionDerived.cpp:195
dd4hep::cond::ConditionUpdateCall::ConditionUpdateCall
ConditionUpdateCall()
Standard destructor.
Definition: ConditionDerived.cpp:105
dd4hep::cond::ConditionDependency::release
void release()
Release object. May not be used any longer.
Definition: ConditionDerived.h:356
dd4hep::cond::ConditionUpdateContext::iov
IOV * iov
The reference to the combined IOV resulting from the cumputation.
Definition: ConditionDerived.h:143
dd4hep::cond::ConditionDependency::detector
DetElement detector
Reference to the target's detector element.
Definition: ConditionDerived.h:324
dd4hep::cond::DependencyBuilder::m_dependency
std::unique_ptr< ConditionDependency > m_dependency
The created dependency.
Definition: ConditionDerived.h:368
dd4hep::cond::ConditionResolver::registerOne
virtual bool registerOne(const IOV &iov, Condition cond)=0
Interface to handle multi-condition inserts by callbacks: One single insert.
dd4hep::ConditionKey
Key definition to optimize ans simplyfy the access to conditions entities.
Definition: Conditions.h:280
dd4hep::cond::ConditionResolver::get
virtual Condition get(Condition::key_type key, bool throw_if_not)=0
Interface to access conditions by hash value.
dd4hep::cond::ConditionUpdateContext::key
const ConditionKey & key(size_t which) const
Access to dependency keys.
Definition: ConditionDerived.h:395
dd4hep::cond::ConditionUpdateUserContext
ConditionUpdateUserContext class used by the derived conditions calculation mechanism.
Definition: ConditionDerived.h:49
dd4hep::cond::ConditionDependency::m_refCount
int m_refCount
Reference count.
Definition: ConditionDerived.h:320
dd4hep::cond::ConditionUpdateCall::operator=
ConditionUpdateCall & operator=(const ConditionUpdateCall &copy)=delete
No assignment operator.
dd4hep::Condition::detkey_type
unsigned int detkey_type
High part of the key identifies the detector element.
Definition: Conditions.h:56
dd4hep::Condition
Main condition object handle.
Definition: Conditions.h:51
dd4hep::cond::ConditionUpdateCall::ConditionUpdateCall
ConditionUpdateCall(const ConditionUpdateCall &copy)=delete
No copy constructor.
dd4hep::cond::ConditionDependency
Condition dependency definition.
Definition: ConditionDerived.h:316
dd4hep::cond::ConditionResolver::get
virtual std::vector< Condition > get(Condition::detkey_type key)=0
Interface to access conditions by hash value of the DetElement (only valid at resolve!...
dd4hep::IOV
Class describing the interval of validty.
Definition: IOV.h:67
dd4hep::cond::ConditionUpdateContext::registerMany
size_t registerMany(const IOV &iov, const std::vector< Condition > &values)
Handle multi-condition inserts by callbacks: block insertions of conditions with identical IOV.
Definition: ConditionDerived.cpp:100
dd4hep::cond::ConditionUpdateContext::condition
Condition condition(const ConditionKey &key_value) const
Access to condition object by dependency key.
Definition: ConditionDerived.cpp:51
dd4hep::DetElement
Handle class describing a detector element.
Definition: DetElement.h:188
dd4hep::cond::ConditionResolver::registerMany
virtual size_t registerMany(const IOV &iov, const std::vector< Condition > &values)=0
Handle multi-condition inserts by callbacks: block insertions of conditions with identical IOV.
dd4hep::cond::ConditionDependency::key
Condition::key_type key() const
Access the dependency key.
Definition: ConditionDerived.h:348
dd4hep::cond::ConditionDependency::ConditionDependency
ConditionDependency(const ConditionDependency &c)=delete
Copy constructor.
dd4hep::cond::ConditionUpdateContext::param
Q * param() const
Access user parameter.
Definition: ConditionDerived.h:179
dd4hep::cond::ConditionUpdateUserContext::~ConditionUpdateUserContext
virtual ~ConditionUpdateUserContext()
Default destructor.
Definition: ConditionDerived.cpp:26
dd4hep::cond::ConditionResolver::registerMapping
size_t registerMapping(const IOV &iov, CONT &c)
Handle multi-condition inserts by callbacks with identical key. Handle mapped containers.
Definition: ConditionDerived.h:106
dd4hep::cond::ConditionDependency::callback
std::shared_ptr< ConditionUpdateCall > callback
Reference to the update callback. No auto pointer. callback may be shared.
Definition: ConditionDerived.h:330
dd4hep::cond::ConditionUpdateContext::registerOne
bool registerOne(const IOV &iov, Condition cond)
Interface to handle multi-condition inserts by callbacks: One single insert.
Definition: ConditionDerived.cpp:95
dd4hep::cond::ConditionUpdateContext::registerMapping
size_t registerMapping(const IOV &iov_val, CONT &values)
Handle multi-condition inserts by callbacks with identical key. Handle mapped containers.
Definition: ConditionDerived.h:269
dd4hep::Condition::get
T & get()
Generic getter. Specify the exact type, not a polymorph type.
Definition: Conditions.h:258
dd4hep::Condition::itemkey_type
unsigned int itemkey_type
Low part of the key identifies the item identifier.
Definition: Conditions.h:58
dd4hep::cond::DependencyBuilder::~DependencyBuilder
virtual ~DependencyBuilder()
Default destructor.
Definition: ConditionDerived.cpp:182
Conditions.h
dd4hep::Condition::key_type
unsigned long long int key_type
Forward definition of the key type.
Definition: Conditions.h:54
dd4hep::cond::ConditionUpdateCall::~ConditionUpdateCall
virtual ~ConditionUpdateCall()
Standard destructor.
Definition: ConditionDerived.cpp:110
dd4hep::cond::ConditionUpdateCall::operator()
virtual Condition operator()(const ConditionKey &target, ConditionUpdateContext &ctxt)=0
Interface to client callback in order to update/create the condition.
dd4hep::cond::ConditionUpdateCall
Callback interface.
Definition: ConditionDerived.h:283
Memory.h
dd4hep::cond::ConditionUpdateContext::detectorDescription
Detector & detectorDescription() const
Access to the detector description instance.
Definition: ConditionDerived.h:158
dd4hep::cond::DependencyBuilder::add
void add(const ConditionKey &source_key)
Add a new dependency.
Definition: ConditionDerived.cpp:186
dd4hep::cond::DependencyBuilder
Condition dependency builder.
Definition: ConditionDerived.h:365
dd4hep::cond::ConditionDependency::dependencies
std::vector< ConditionKey > dependencies
Dependency keys this condition depends on.
Definition: ConditionDerived.h:328
key
unsigned char key
Definition: AlignmentsCalculator.cpp:69
dd4hep::cond::ConditionResolver::get
virtual Condition get(const ConditionKey &key, bool throw_if_not)=0
Interface to access conditions by conditions key.
dd4hep::cond::ConditionUpdateCall::resolve
virtual void resolve(Condition, ConditionUpdateContext &)
Interface to client callback for resolving references or to use data from other conditions.
Definition: ConditionDerived.h:299
dd4hep
Namespace for the AIDA detector description toolkit.
Definition: AlignmentsCalib.h:28
dd4hep::cond::ConditionResolver::detectorDescription
virtual Detector & detectorDescription() const =0
Access to the detector description instance.
det
DetElement::Object * det
Definition: AlignmentsCalculator.cpp:66
dd4hep::cond::DependencyBuilder::operator->
ConditionDependency * operator->()
Access underlying object directly.
Definition: ConditionDerived.h:377
dd4hep::cond::ConditionUpdateContext::conditionsMap
ConditionsMap & conditionsMap() const
Accessor for the current conditons mapping.
Definition: ConditionDerived.h:171
dd4hep::cond::ConditionUpdateContext::requiredValidity
const IOV & requiredValidity() const
Required IOV value for update cycle.
Definition: ConditionDerived.h:166
dd4hep::cond::ConditionUpdateContext::registerUnmapped
size_t registerUnmapped(const IOV &iov_val, CONT &values)
Handle multi-condition inserts by callbacks with identical key. Handle unmapped containers.
Definition: ConditionDerived.h:262
dd4hep::Detector
The main interface to the dd4hep detector description package.
Definition: Detector.h:90
dd4hep::cond::ConditionResolver::get
virtual Condition get(Condition::key_type key, const ConditionDependency *dependency, bool throw_if_not)=0
Interface to access conditions by hash value.
dd4hep::cond::DependencyBuilder::DependencyBuilder
DependencyBuilder(DetElement de, Condition::itemkey_type item_key, std::shared_ptr< ConditionUpdateCall > call)
Initializing constructor.
Definition: ConditionDerived.cpp:166
dd4hep::cond::ConditionUpdateContext::ConditionUpdateContext
ConditionUpdateContext(ConditionResolver *r, const ConditionDependency *d, IOV *iov, ConditionUpdateUserContext *parameter)
Initializing constructor.
Definition: ConditionDerived.h:385
dd4hep::detail::tools::copy
void copy(Alignment from, Alignment to)
Copy alignment object from source object.
Definition: AlignmentTools.cpp:43
dd4hep::cond::ConditionResolver::get
virtual std::vector< Condition > get(DetElement de)=0
Interface to access conditions by hash value of the DetElement (only valid at resolve!...
dd4hep::cond::ConditionUpdateContext::dependency
const ConditionDependency * dependency
The dependency to be handled within this context.
Definition: ConditionDerived.h:141
dd4hep::cond::ConditionUpdateContext::getByItem
std::vector< Condition > getByItem(Condition::itemkey_type key) const
Access conditions by the condition item key.
Definition: ConditionDerived.cpp:43
dd4hep::cond::ConditionResolver::requiredValidity
virtual const IOV & requiredValidity() const =0
Required IOV value for update cycle.
dd4hep::cond::ConditionUpdateContext
ConditionUpdateContext class used by the derived conditions calculation mechanism.
Definition: ConditionDerived.h:136
dd4hep::ConditionsMap
ConditionsMap class.
Definition: ConditionsMap.h:59
dd4hep::cond::ConditionDependency::ConditionDependency
ConditionDependency()
Default constructor.
Definition: ConditionDerived.cpp:154
dd4hep::cond::ConditionDependency::addRef
ConditionDependency * addRef()
Add use count to the object.
Definition: ConditionDerived.h:354
dd4hep::cond::ConditionUpdateContext::conditions
std::vector< Condition > conditions(DetElement det) const
Access to all conditions of a detector element.
Definition: ConditionDerived.h:188