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
ConditionDerived.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_GEOMETRY_CONDITIONDERIVED_H
14 #define DD4HEP_GEOMETRY_CONDITIONDERIVED_H
15 
16 // Framework include files
17 #include "DD4hep/Memory.h"
18 #include "DD4hep/Conditions.h"
20 
22 namespace DD4hep {
23 
25  class BasicGrammar;
26 
28  namespace Conditions {
29 
30  class ConditionManager;
31  class ConditionResolver;
32  class ConditionDependency;
33  class ConditionUpdateCall;
34 
36 
42  public:
44  virtual ~ConditionResolver();
46  virtual Condition get(const ConditionKey& key) const = 0;
48  virtual Condition get(unsigned int key) const = 0;
50  virtual Ref_t manager() const = 0;
52  virtual Geometry::LCDD& lcdd() const = 0;
54  virtual const IOV& requiredValidity() const = 0;
55  };
56 
58 
64  public:
68  void* parameter;
71  const ConditionDependency& d,
72  void* parameter,
75  const ConditionKey& key(size_t which) const;
77  Condition condition(size_t which) const;
79  Condition condition(const ConditionKey& key_value) const;
81  template<typename Q> Q* param() const {
82  return static_cast<Q*>(parameter);
83  }
85  template<typename T> T& get(const ConditionKey& key_value) {
86  Condition cond = resolver.get(key_value);
87  if ( cond.isValid() ) {
88  T& data = cond.get<T>();
89  iov->iov_intersection(cond.iov());
91  return data;
92  }
93  throw std::runtime_error("ConditionUpdateCall: Failed to access non-existing item:"+key_value.name);
94  }
96  template<typename T> const T& get(const ConditionKey& key_value) const {
97  Condition cond = resolver.get(key_value);
98  if ( cond.isValid() ) {
99  const T& data = cond.get<T>();
100  iov->iov_intersection(cond.iov());
102  return data;
103  }
104  throw std::runtime_error("ConditionUpdateCall: Failed to access non-existing item:"+key_value.name);
105  }
107  template<typename T> T& get(size_t key_id) {
108  const ConditionKey& key_value = this->key(key_id);
109  return this->get<T>(key_value);
110  }
112  template<typename T> const T& get(size_t key_id) const {
113  const ConditionKey& key_value = this->key(key_id);
114  return this->get<T>(key_value);
115  }
116  };
117 
119 
125  public:
127  protected:
133  virtual ~ConditionUpdateCall();
134 
135  public:
137  ConditionUpdateCall* addRef() { ++m_refCount; return this; }
139  void release() { if ( --m_refCount <= 0 ) delete this; }
141  virtual Condition operator()(const ConditionKey& target, const Context& ctxt) = 0;
142  };
143 
145 
153  protected:
156 
157  public:
160  typedef std::vector<ConditionKey> Dependencies;
163 
172 
173  protected:
179  virtual ~ConditionDependency();
180 
181  public:
183  ConditionDependency(const ConditionKey& tar, const Dependencies deps, ConditionUpdateCall* call);
189  key_type key() const { return target.hash; }
191  ConditionDependency* addRef() { ++m_refCount; return this; }
193  void release() { if ( --m_refCount <= 0 ) delete this; }
194  };
195 
197 
203  protected:
206  public:
208  DependencyBuilder(const ConditionKey& target, ConditionUpdateCall* call);
212  virtual ~DependencyBuilder();
216  void add(const ConditionKey& source);
219  };
220 
223  const ConditionDependency& dep,
224  void* user_param,
225  Condition::iov_type& iov_ref)
226  : resolver(resolv), dependency(dep), iov(&iov_ref), parameter(user_param)
227  {
228  }
229 
231  inline const ConditionKey& ConditionUpdateContext::key(size_t which) const {
232  return dependency.dependencies[which];
233  }
234 
237  Condition c = resolver.get(key_value);
238  if ( c.isValid() ) return c;
239  throw std::runtime_error("ConditionUpdateCall: Failed to access non-existing condition:"+key_value.name);
240  }
241 
243  inline Condition ConditionUpdateContext::condition(size_t which) const {
244  const ConditionKey& key_value = this->key(which);
245  return this->condition(key_value);
246  }
247 
248  } /* End namespace Conditions */
249 } /* End namespace DD4hep */
250 #endif /* DD4HEP_GEOMETRY_CONDITIONDERIVED_H */
Condition dependency builder.
Q * param() const
Access user parameter.
ConditionDependency & operator=(const ConditionDependency &c)
Assignment operator.
virtual Condition operator()(const ConditionKey &target, const Context &ctxt)=0
Interface to client Callback in order to update the condition.
bool isValid() const
Check the validity of the object held by the handle.
Definition: Handle.h:124
T & get()
Generic getter. Specify the exact type, not a polymorph type.
ConditionResolver class used by the derived conditions calculation mechanism.
void release()
Release object. May not be used any longer.
Condition condition(size_t which) const
Access to condition object by dependency index.
Main condition object handle.
Definition: Conditions.h:70
unsigned int key_type
Forward definition of the key type.
Definition: Conditions.h:75
virtual Condition get(const ConditionKey &key) const =0
Interface to access conditions by conditions key.
void iov_intersection(const IOV &comparator)
Set the intersection of this IOV with the argument IOV.
Definition: IOV.cpp:85
const ConditionDependency & dependency
Condition dependency definition.
Key definition to optimize ans simplyfy the access to conditions entities.
Definition: Conditions.h:273
key_type key() const
Access the dependency key.
Class describing the interval of validty.
Definition: IOV.h:59
virtual Geometry::LCDD & lcdd() const =0
Access to the detector description instance.
ConditionUpdateCall * callback
Reference to the update callback. No auto pointer. callback may be shared.
ConditionUpdateContext class used by the derived conditions calculation mechanism.
ConditionDependency * release()
Release the created dependency and take ownership.
void add(const ConditionKey &source)
Add a new dependency.
virtual const IOV & requiredValidity() const =0
Required IOV value for update cycle.
DetElement detector
Reference to the target's detector element.
Dependencies dependencies
Dependency keys this condition depends on.
const iov_type & iov() const
Access the IOV block.
Definition: Conditions.cpp:102
const ConditionKey & key(size_t which) const
Access to dependency keys.
virtual Ref_t manager() const =0
Access to the conditions manager.
std::string name
String representation of the key object.
Definition: Conditions.h:279
ConditionUpdateCall * addRef()
Add use count to the object.
ConditionDependency * addRef()
Add use count to the object.
std::vector< ConditionKey > Dependencies
Defintion of the depencency container.
Handle class describing a detector element.
Definition: Detector.h:172
ConditionDependency * operator->()
Access underlying object directly.
key_type hash
Hashed key representation.
Definition: Conditions.h:281
virtual ~ConditionDependency()
Default destructor.
virtual ~ConditionResolver()
Standard destructor.
The main interface to the DD4hep detector description package.
Definition: LCDD.h:82
virtual ~ConditionUpdateCall()
Standard destructor.
ConditionUpdateContext(const ConditionResolver &r, const ConditionDependency &d, void *parameter, Condition::iov_type &iov)
Initializing constructor.
ConditionKey target
Key to the condition to be updated.
DependencyBuilder(const ConditionKey &target, ConditionUpdateCall *call)
Initializing constructor.
virtual ~DependencyBuilder()
Default destructor.
Condition::key_type key_type
Forward definition of the key type.
void release()
Release object. May not be used any longer.
ConditionDependency * m_dependency
The created dependency.