DD4hep  1.30.0
Detector Description Toolkit for High Energy Physics
ConditionsContent.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 include files
16 #include <DD4hep/InstanceCount.h>
17 #include <DD4hep/Printout.h>
18 
19 using namespace dd4hep::cond;
20 
24 }
25 
29 }
30 
33 {
35 }
36 
39  detail::releaseObjects(m_derived);
40  detail::releaseObjects(m_conditions);
42 }
43 
46  detail::releaseObjects(m_derived);
47  detail::releaseObjects(m_conditions);
48 }
49 
52  auto& cond = to_add.conditions();
53  auto& deriv = to_add.derived();
54  for( const auto& c : cond ) {
55  auto ret = m_conditions.emplace(c);
56  if ( ret.second ) {
57  c.second->addRef();
58  continue;
59  }
60  // Need error handling here ?
61  ConditionKey key(c.first);
62  printout(WARNING,"ConditionsContent",
63  "++ Condition %s already present in content. Not merged",key.toString().c_str());
64 
65  }
66  for( const auto& d : deriv ) {
67  auto ret = m_derived.emplace(d);
68  if ( ret.second ) {
69  d.second->addRef();
70  continue;
71  }
72  // Need error handling here ?
73  ConditionKey key(d.first);
74  printout(WARNING,"ConditionsContent",
75  "++ Dependency %s already present in content. Not merged",key.toString().c_str());
76  }
77 }
78 
81  auto i = m_conditions.find(hash);
82  if ( i != m_conditions.end() ) {
83  detail::releasePtr((*i).second);
84  m_conditions.erase(i);
85  return true;
86  }
87  auto j = m_derived.find(hash);
88  if ( j != m_derived.end() ) {
89  detail::releasePtr((*j).second);
90  m_derived.erase(j);
91  return true;
92  }
93  return false;
94 }
95 
96 std::pair<dd4hep::Condition::key_type, ConditionsLoadInfo*>
98  auto ret = m_conditions.emplace(hash,(ConditionsLoadInfo*)0);
99  //printout(DEBUG,"ConditionsContent","++ Insert key: %016X",hash);
100  if ( ret.second ) return { hash, 0 };
101  return { 0,0 };
102 }
103 
105 std::pair<dd4hep::Condition::key_type, ConditionsLoadInfo*>
107  if ( info ) {
108  //printout(DEBUG,"ConditionsContent","++ Add location key: %016X",hash);
109  auto ret = m_conditions.emplace(hash,info);
110  if ( ret.second ) {
111  info->addRef();
112  return *(ret.first);
113  }
114  info->release();
115  }
116  return { 0,0 };
117 }
118 
120 std::pair<dd4hep::Condition::key_type, ConditionDependency*>
122 {
123  auto ret = m_derived.emplace(dep->key(),dep);
124  if ( ret.second ) {
125  //printout(DEBUG,"ConditionsContent","++ Add dependency key: %016X",dep->key());
126  dep->addRef();
127  return *(ret.first);
128  }
129  ConditionKey::KeyMaker maker(dep->target.hash);
130 #if defined(DD4HEP_CONDITIONS_DEBUG)
131  DetElement de(dep->detector);
132  const char* path = de.isValid() ? de.path().c_str() : "(global)";
133 #else
134  const char* path = "";
135 #endif
136  dep->release();
137  except("DeConditionsRequests",
138  "++ Dependency already exists: %s [%08X] [%016llX]",
139  path, maker.values.item_key, maker.hash);
140  return std::pair<Condition::key_type, ConditionDependency*>(0,0);
141 }
142 
144 std::pair<dd4hep::Condition::key_type, ConditionDependency*>
147  std::shared_ptr<ConditionUpdateCall> callback)
148 {
149  ConditionDependency* dep = new ConditionDependency(de, item, std::move(callback));
150  return addDependency(dep);
151 }
152 
dd4hep::DetElement::path
const std::string & path() const
Path of the detector element (not necessarily identical to placement path!)
Definition: DetElement.cpp:158
dd4hep::cond::ConditionsContent::m_derived
Dependencies m_derived
Container of derived conditions required by this content.
Definition: ConditionsContent.h:109
cond
AlignmentCondition::Object * cond
Definition: AlignmentsCalculator.cpp:68
dd4hep::cond::ConditionsContent::m_conditions
Conditions m_conditions
Container of conditions required by this content.
Definition: ConditionsContent.h:107
dd4hep::cond::ConditionsContent::conditions
Conditions & conditions()
Access to the real condition entries to be loaded.
Definition: ConditionsContent.h:123
dd4hep::info
std::size_t info(const std::string &src, const std::string &msg)
Definition: RootDictionary.h:65
dd4hep::ConditionKey::hash
Condition::key_type hash
Hashed key representation.
Definition: Conditions.h:287
dd4hep::cond::ConditionDependency::target
ConditionKey target
Key to the condition to be updated.
Definition: ConditionDerived.h:326
dd4hep::Handle::isValid
bool isValid() const
Check the validity of the object held by the handle.
Definition: Handle.h:128
dd4hep::InstanceCount::increment
static void increment(T *)
Increment count according to type information.
Definition: InstanceCount.h:98
dd4hep::cond::ConditionDependency::release
void release()
Release object. May not be used any longer.
Definition: ConditionDerived.h:356
dd4hep::cond::ConditionsContent::~ConditionsContent
virtual ~ConditionsContent()
Default destructor.
Definition: ConditionsContent.cpp:38
dd4hep::cond::ConditionDependency::detector
DetElement detector
Reference to the target's detector element.
Definition: ConditionDerived.h:324
dd4hep::ConditionKey
Key definition to optimize ans simplyfy the access to conditions entities.
Definition: Conditions.h:280
dd4hep::ConditionKey::KeyMaker
Helper union to interprete conditions keys.
Definition: Conditions.h:295
dd4hep::cond::ConditionsContent::remove
bool remove(Condition::key_type condition)
Remove a condition from the content.
Definition: ConditionsContent.cpp:80
dd4hep::cond::ConditionsLoadInfo::~ConditionsLoadInfo
virtual ~ConditionsLoadInfo()
Default destructor.
Definition: ConditionsContent.cpp:27
dd4hep::cond
Namespace for implementation details of the AIDA detector description toolkit.
Definition: ConditionsCleanup.h:23
dd4hep::cond::ConditionsContent
Conditions content object. Defines which conditions should be loaded by the ConditionsManager.
Definition: ConditionsContent.h:74
dd4hep::cond::ConditionDependency
Condition dependency definition.
Definition: ConditionDerived.h:316
dd4hep::cond::ConditionsContent::derived
Dependencies & derived()
Access to the derived condition entries to be computed.
Definition: ConditionsContent.h:127
dd4hep::DetElement
Handle class describing a detector element.
Definition: DetElement.h:188
dd4hep::cond::ConditionsContent::addLocationInfo
std::pair< Condition::key_type, ConditionsLoadInfo * > addLocationInfo(Condition::key_type hash, ConditionsLoadInfo *info)
Add a new conditions key. T must inherit from class ConditionsContent::Info.
Definition: ConditionsContent.cpp:106
dd4hep::cond::ConditionDependency::key
Condition::key_type key() const
Access the dependency key.
Definition: ConditionDerived.h:348
dd4hep::cond::ConditionsContent::merge
void merge(const ConditionsContent &to_add)
Merge the content of "to_add" into the this content.
Definition: ConditionsContent.cpp:51
dd4hep::cond::ConditionsContent::ConditionsContent
ConditionsContent()
Default constructor.
Definition: ConditionsContent.cpp:32
dd4hep::InstanceCount::decrement
static void decrement(T *)
Decrement count according to type information.
Definition: InstanceCount.h:102
dd4hep::Condition::itemkey_type
unsigned int itemkey_type
Low part of the key identifies the item identifier.
Definition: Conditions.h:58
dd4hep::cond::ConditionsLoadInfo
Base class for data loading information.
Definition: ConditionsContent.h:39
dd4hep::Condition::key_type
unsigned long long int key_type
Forward definition of the key type.
Definition: Conditions.h:54
key
unsigned char key
Definition: AlignmentsCalculator.cpp:69
dd4hep::ConditionKey::KeyMaker::hash
Condition::key_type hash
Definition: Conditions.h:296
dd4hep::cond::ConditionsContent::addDependency
std::pair< Condition::key_type, ConditionDependency * > addDependency(ConditionDependency *dep)
Add a new shared conditions dependency.
Definition: ConditionsContent.cpp:121
dd4hep::sim::hash
unsigned int hash(unsigned int initialSeed, unsigned int eventNumber, unsigned int runNumber)
calculate hash from initialSeed, eventID and runID
Definition: Geant4EventSeed.h:201
ConditionsContent.h
InstanceCount.h
dd4hep::cond::ConditionsLoadInfo::ConditionsLoadInfo
ConditionsLoadInfo()
Default constructor.
Definition: ConditionsContent.cpp:22
dd4hep::cond::ConditionsContent::clear
void clear()
Clear the conditions content definitions.
Definition: ConditionsContent.cpp:45
dd4hep::ConditionKey::KeyMaker::values
struct dd4hep::ConditionKey::KeyMaker::@2 values
Printout.h
dd4hep::cond::ConditionsContent::insertKey
std::pair< Condition::key_type, ConditionsLoadInfo * > insertKey(Condition::key_type hash)
Add a new conditions key representing a real (not derived) condition.
Definition: ConditionsContent.cpp:97
dd4hep::cond::ConditionDependency::addRef
ConditionDependency * addRef()
Add use count to the object.
Definition: ConditionDerived.h:354
dd4hep::ConditionKey::KeyMaker::item_key
Condition::itemkey_type item_key
Definition: Conditions.h:302