DD4hep  1.28.0
Detector Description Toolkit for High Energy Physics
ConditionDerived.cpp
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 
14 // Framework includes
15 #include <DD4hep/Printout.h>
16 #include <DD4hep/Detector.h>
17 #include <DD4hep/InstanceCount.h>
19 
20 // C/C++ include files
21 
22 using namespace dd4hep;
23 using namespace dd4hep::cond;
24 
27 }
28 
32 }
33 
35 std::vector<Condition> ConditionUpdateContext::conditions(Condition::detkey_type det_key) const {
36  std::vector<Condition> v = resolver->get(det_key);
38  for(Condition c : v) iov->iov_intersection(c.iov());
39  return v;
40 }
41 
43 std::vector<Condition> ConditionUpdateContext::getByItem(Condition::itemkey_type item_key) const {
44  std::vector<Condition> v = resolver->getByItem(item_key);
46  for(Condition c : v) iov->iov_intersection(c.iov());
47  return v;
48 }
49 
52  Condition c = this->resolver->get(key_value, this->dependency, true);
53  if ( c.isValid() ) {
55  iov->iov_intersection(c.iov());
56  return c;
57  }
58 #if defined(DD4HEP_CONDITIONS_HAVE_NAME)
59  except("ConditionUpdateCall:","Failed to access non-existing condition:"+key_value.name);
60 #else
61  ConditionKey::KeyMaker key(key_value.hash);
62  except("ConditionUpdateCall:","Failed to access non-existing condition with key [%08X %08X]:",
63  key.values.det_key, key.values.item_key);
64 #endif
65  return Condition();
66 }
67 
70  Condition c = resolver->get(key_value);
71  if ( c.isValid() ) {
73  iov->iov_intersection(c.iov());
74  return c;
75  }
76  throw std::runtime_error("ConditionUpdateCall: Failed to access non-existing condition.");
77 }
78 
81  bool throw_if_not) const {
82  Condition c = resolver->get(key_value, throw_if_not);
83  if ( c.isValid() ) {
85  iov->iov_intersection(c.iov());
86  return c;
87  }
88  else if ( throw_if_not ) {
89  throw std::runtime_error("ConditionUpdateCall: Failed to access non-existing condition.");
90  }
91  return Condition();
92 }
93 
96  return resolver->registerOne(iov_val, cond);
97 }
98 
100 size_t ConditionUpdateContext::registerMany(const IOV& iov_val, const std::vector<Condition>& values) {
101  return resolver->registerMany(iov_val, values);
102 }
103 
107 }
108 
112 }
113 
116 }
117 
120 #if defined(DD4HEP_CONDITIONS_HAVE_NAME)
121  except("ConditionUpdateCall",
122  "%s [%016llX]: FAILED to access non-existing item:%s [%016llX]",
123  dependency->target.name.c_str(), dependency->target.hash,
124  key_value.name.c_str(), key_value.hash);
125 #else
126  ConditionKey::KeyMaker key(key_value.hash);
128  except("ConditionUpdateCall",
129  "Derived condition [%08X %08X]: FAILED to access non-existing item:%s [%08X %08X]",
130  dep.values.det_key, dep.values.item_key, key.values.det_key, key.values.item_key);
131 #endif
132 }
133 
136  Condition::itemkey_type item_key,
137  std::shared_ptr<ConditionUpdateCall> call)
138  : m_refCount(0), detector(de), target(de, item_key), callback(std::move(call))
139 {
141 }
142 
145  const std::string& item,
146  std::shared_ptr<ConditionUpdateCall> call)
147  :
148  detector(de), target(de, item), callback(std::move(call))
149 {
151 }
152 
155 {
157 }
158 
161 {
163 }
164 
167  unsigned int item_key,
168  std::shared_ptr<ConditionUpdateCall> call)
169  : m_dependency(new ConditionDependency(de,item_key,std::move(call)))
170 {
171 }
172 
175  const std::string& item,
176  std::shared_ptr<ConditionUpdateCall> call)
177  : m_dependency(new ConditionDependency(de,item,std::move(call)))
178 {
179 }
180 
183 }
184 
187  if ( m_dependency ) {
188  m_dependency->dependencies.emplace_back(source);
189  return;
190  }
191  except("Dependency","++ Invalid object. No further source may be added!");
192 }
193 
196  if ( m_dependency ) {
197  return m_dependency.release();
198  }
199  except("Dependency","++ Invalid object. Cannot access built objects!");
200  return m_dependency.release(); // Not necessary, but need to satisfy compiler
201 }
202 
dd4hep::IOV::iov_intersection
void iov_intersection(const IOV &comparator)
Set the intersection of this IOV with the argument IOV.
Definition: IOV.cpp:99
dd4hep::cond::ConditionDependency::~ConditionDependency
virtual ~ConditionDependency()
Default destructor.
Definition: ConditionDerived.cpp:160
dd4hep::Detector::world
virtual DetElement world() const =0
Return reference to the top-most (world) detector element.
cond
AlignmentCondition::Object * cond
Definition: AlignmentsCalculator.cpp:68
dd4hep::cond::ConditionResolver::~ConditionResolver
virtual ~ConditionResolver()
Standard destructor.
Definition: ConditionDerived.cpp:115
v
View * v
Definition: MultiView.cpp:28
dd4hep::cond::ConditionResolver::get
virtual Condition get(const ConditionKey &key)=0
Interface to access conditions by conditions key.
Detector.h
dd4hep::cond::ConditionUpdateContext::resolver
ConditionResolver * resolver
Internal reference to the resolver to access other conditions (Be careful)
Definition: ConditionDerived.h:139
dd4hep::ConditionKey::hash
Condition::key_type hash
Hashed key representation.
Definition: Conditions.h:290
dd4hep::cond::ConditionUpdateContext::accessFailure
void accessFailure(const ConditionKey &key_value) const
Throw exception on conditions access failure.
Definition: ConditionDerived.cpp:119
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::isValid
bool isValid() const
Check the validity of the object held by the handle.
Definition: Handle.h:128
dd4hep::cond::DependencyBuilder::release
ConditionDependency * release()
Release the created dependency and take ownership.
Definition: ConditionDerived.cpp:195
dd4hep::InstanceCount::increment
static void increment(T *)
Increment count according to type information.
Definition: InstanceCount.h:98
dd4hep::cond::ConditionUpdateCall::ConditionUpdateCall
ConditionUpdateCall()
Standard destructor.
Definition: ConditionDerived.cpp:105
dd4hep::cond::ConditionUpdateContext::iov
IOV * iov
The reference to the combined IOV resulting from the cumputation.
Definition: ConditionDerived.h:143
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:283
dd4hep::cond::ConditionUpdateContext::key
const ConditionKey & key(size_t which) const
Access to dependency keys.
Definition: ConditionDerived.h:395
dd4hep::ConditionKey::KeyMaker
Helper union to interprete conditions keys.
Definition: Conditions.h:298
dd4hep::ConditionKey::KeyMaker::values
struct dd4hep::ConditionKey::KeyMaker::@3 values
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
Namespace for implementation details of the AIDA detector description toolkit.
Definition: ConditionsCleanup.h:23
dd4hep::cond::ConditionDependency
Condition dependency definition.
Definition: ConditionDerived.h:316
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::InstanceCount::decrement
static void decrement(T *)
Decrement count according to type information.
Definition: InstanceCount.h:102
dd4hep::cond::ConditionUpdateUserContext::~ConditionUpdateUserContext
virtual ~ConditionUpdateUserContext()
Default destructor.
Definition: ConditionDerived.cpp:26
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::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
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::DependencyBuilder::add
void add(const ConditionKey &source_key)
Add a new dependency.
Definition: ConditionDerived.cpp:186
std
Definition: Plugins.h:30
ConditionDerived.h
dd4hep::ConditionKey::KeyMaker::det_key
Condition::detkey_type det_key
Definition: Conditions.h:306
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.
dd4hep::ConditionKey::item_key
Condition::itemkey_type item_key() const
Access the detector element part of the key.
Definition: Conditions.h:358
dd4hep::cond::DependencyBuilder::DependencyBuilder
DependencyBuilder(DetElement de, Condition::itemkey_type item_key, std::shared_ptr< ConditionUpdateCall > call)
Initializing constructor.
Definition: ConditionDerived.cpp:166
InstanceCount.h
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
Printout.h
dd4hep::Condition::iov
const IOV & iov() const
Access the IOV block.
Definition: Conditions.cpp:139
dd4hep::cond::ConditionDependency::ConditionDependency
ConditionDependency()
Default constructor.
Definition: ConditionDerived.cpp:154
dd4hep::ConditionKey::KeyMaker::item_key
Condition::itemkey_type item_key
Definition: Conditions.h:305
dd4hep::cond::ConditionUpdateContext::conditions
std::vector< Condition > conditions(DetElement det) const
Access to all conditions of a detector element.
Definition: ConditionDerived.h:188