DD4hep  1.30.0
Detector Description Toolkit for High Energy Physics
ConditionsSlice.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
15 #include <DDCond/ConditionsSlice.h>
17 #include <DD4hep/InstanceCount.h>
18 #include <DD4hep/Printout.h>
19 
20 using namespace dd4hep::cond;
21 
24 {
26 }
27 
30  const std::shared_ptr<ConditionsContent>& cont)
31  : manager(mgr), content(cont)
32 {
34 }
35 
38  : manager(copy.manager), content(copy.content)
39 {
41 }
42 
45  reset();
47 }
48 
51  used_pools.clear(); // Drop all refs possibly pending
52  this->flags &= ~REF_POOLS;
53 }
54 
57  if ( pool.get() ) return pool->validity();
58  except("ConditionsSlice",
59  "pool-iov: Failed to access validity of non-existing pool.");
60  return pool->validity();
61 }
62 
65  derefPools();
66  if ( pool.get() ) pool->clear();
67 }
68 
71  if ( condition.isValid() ) {
72  bool ret = false;
73  if ( flg&REGISTER_MANAGER ) {
74  if ( !p ) {
75  except("ConditionsSlice",
76  "manage_condition: Cannot access conditions pool according to IOV:%s.",
77  pool->validity().str().c_str());
78  }
79  ret = manager.registerUnlocked(*p,condition);
80  if ( !ret ) {
81  except("ConditionsSlice",
82  "manage_condition: Failed to register condition %016llx according to IOV:%s.",
83  condition->hash, pool->validity().str().c_str());
84  }
85  }
86  if ( flg&REGISTER_POOL ) {
87  ret = pool->insert(condition);
88  if ( !ret ) {
89  except("ConditionsSlice",
90  "manage_condition: Failed to register condition %016llx to user pool with IOV:%s.",
91  condition->hash, pool->validity().str().c_str());
92  }
93  }
94  return ret;
95  }
96  except("ConditionsSlice",
97  "manage_condition: Cannot manage invalid condition!");
98  return false;
99 }
100 
103  ConditionsPool* p = (flg&REGISTER_MANAGER) ? manager.registerIOV(pool->validity()) : 0;
104  return manage(p, condition, flg);
105 }
106 
108 std::vector<dd4hep::Condition> ConditionsSlice::get(DetElement detector) const {
109  return pool->get(detector,FIRST_ITEM,LAST_ITEM);
110 }
111 
113 std::vector<dd4hep::Condition> ConditionsSlice::get(DetElement detector,
115  Condition::itemkey_type upper) const {
116  return pool->get(detector, lower, upper);
117 }
118 
121  if ( condition.isValid() ) {
122  ConditionsPool* p = manager.registerIOV(pool->validity());
123  if ( !p ) {
124  except("ConditionsSlice",
125  "manage_condition: Cannot access conditions pool according to IOV:%s.",
126  pool->validity().str().c_str());
127  }
128  bool ret = manager.registerUnlocked(*p,condition);
129  if ( !ret ) {
130  except("ConditionsSlice",
131  "manage_condition: Failed to register condition %016llx according to IOV:%s.",
132  condition->hash, pool->validity().str().c_str());
133  }
134  return pool->insert(detector, key, condition);
135  }
136  except("ConditionsSlice",
137  "insert_condition: Cannot insert invalid condition to the user pool!");
138  return false;
139 }
140 
143  return pool->get(detector, key);
144 }
145 
147 void ConditionsSlice::scan(const Condition::Processor& processor) const {
148  pool->scan(processor);
149 }
150 
155  const Condition::Processor& processor) const {
156  pool->scan(detector, lower, upper, processor);
157 }
158 
159 namespace {
160 
161  struct SliceOper : public dd4hep::ConditionsSelect {
162  ConditionsContent& content;
163  SliceOper(ConditionsContent& c) : content(c) {}
164  void operator()(const ConditionsIOVPool::Elements::value_type& v) {
165  v.second->select_all(*this);
166  }
167  bool operator()(dd4hep::Condition::Object* c) const {
168  if ( 0 == (c->flags&dd4hep::Condition::DERIVED) ) {
169 #if !defined(DD4HEP_MINIMAL_CONDITIONS)
170  content.addLocation(c->hash,c->address);
171 #endif
172  return true;
173  }
174  return true;
175  }
177  virtual size_t size() const { return content.conditions().size(); }
178  };
179 }
180 
183  ConditionsContent& content,
184  const IOVType& typ)
185 {
186  ConditionsIOVPool* iovPool = mgr.iovPool(typ);
187  ConditionsIOVPool::Elements& pools = iovPool->elements;
188  for_each(begin(pools),end(pools),SliceOper(content));
189 }
dd4hep::cond::ConditionsSlice::flags
unsigned long flags
Flag to steer conditions management.
Definition: ConditionsSlice.h:116
dd4hep::cond::ConditionsSlice::get
std::vector< Condition > get(DetElement detector) const
Access all conditions from a given detector element.
Definition: ConditionsSlice.cpp:108
dd4hep::cond::ConditionsManager::registerIOV
ConditionsPool * registerIOV(const IOV &iov) const
Register IOV with type and key.
Definition: ConditionsManager.cpp:231
ConditionsSlice.h
dd4hep::cond::ConditionsSlice::used_pools
ContainedPools used_pools
If requested refence the used pools with a shared pointer to inhibit cleanup.
Definition: ConditionsSlice.h:114
dd4hep::cond::ConditionsSlice::REF_POOLS
@ REF_POOLS
Definition: ConditionsSlice.h:64
dd4hep::cond::ConditionsSlice::derefPools
void derefPools()
Set flag to not reference the used pools during prepare (and drop possibly pending)
Definition: ConditionsSlice.cpp:50
dd4hep::detail::ConditionObject::hash
Condition::key_type hash
Hash value of the name.
Definition: ConditionsInterna.h:85
dd4hep::cond::ConditionsContent::conditions
Conditions & conditions()
Access to the real condition entries to be loaded.
Definition: ConditionsContent.h:123
v
View * v
Definition: MultiView.cpp:28
dd4hep::cond::ConditionsSlice::REGISTER_POOL
@ REGISTER_POOL
Definition: ConditionsSlice.h:60
dd4hep::cond::ConditionsSlice::manage
virtual bool manage(ConditionsPool *pool, Condition condition, ManageFlag flg)
Local optimization: Insert a set of conditions to the slice AND register them to the conditions manag...
Definition: ConditionsSlice.cpp:70
dd4hep::cond::ConditionsIOVPool::Elements
std::map< IOV::Key, Element > Elements
Shortcut name for the actual conditions container.
Definition: ConditionsIOVPool.h:43
dd4hep::detail::ConditionObject::flags
Condition::mask_type flags
Flags.
Definition: ConditionsInterna.h:87
dd4hep::cond::ConditionsSlice::manager
ConditionsManager manager
Reference to the conditions manager.
Definition: ConditionsSlice.h:105
dd4hep::Handle::isValid
bool isValid() const
Check the validity of the object held by the handle.
Definition: Handle.h:128
dd4hep::cond::ConditionsSlice::reset
void reset()
Clear the conditions content and the user pool.
Definition: ConditionsSlice.cpp:64
dd4hep::InstanceCount::increment
static void increment(T *)
Increment count according to type information.
Definition: InstanceCount.h:98
dd4hep::detail::ConditionObject::address
std::string address
Condition address.
Definition: ConditionsInterna.h:76
dd4hep::cond::ConditionsIOVPool::elements
Elements elements
Container of IOV dependent conditions pools.
Definition: ConditionsIOVPool.h:46
dd4hep::ConditionsSelect
Conditions selector functor. Default implementation selects everything evaluated.
Definition: Conditions.h:422
dd4hep::IOVType
Class describing the interval of validty type.
Definition: IOV.h:37
dd4hep::cond::ConditionsManager::iovPool
ConditionsIOVPool * iovPool(const IOVType &type) const
Access conditions multi IOV pool by iov type.
Definition: ConditionsManager.cpp:204
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::ConditionsContent
Conditions content object. Defines which conditions should be loaded by the ConditionsManager.
Definition: ConditionsContent.h:74
dd4hep::IOV
Class describing the interval of validty.
Definition: IOV.h:67
dd4hep::DetElement
Handle class describing a detector element.
Definition: DetElement.h:188
dd4hep::cond::ConditionsSlice::ConditionsSlice
ConditionsSlice()=delete
Default constructor.
dd4hep::cond::ConditionsPool
Class implementing the conditions collection for a given IOV type.
Definition: ConditionsPool.h:54
dd4hep::cond::ConditionsManager::registerUnlocked
bool registerUnlocked(ConditionsPool &pool, Condition cond) const
Register new condition with the conditions store. Unlocked version, not multi-threaded.
Definition: ConditionsManager.cpp:254
dd4hep::InstanceCount::decrement
static void decrement(T *)
Decrement count according to type information.
Definition: InstanceCount.h:102
ConditionsIOVPool.h
dd4hep::Condition::itemkey_type
unsigned int itemkey_type
Low part of the key identifies the item identifier.
Definition: Conditions.h:58
dd4hep::ConditionsMap::FIRST_ITEM
@ FIRST_ITEM
Definition: ConditionsMap.h:62
dd4hep::cond::ConditionsSlice::scan
virtual void scan(const Condition::Processor &processor) const override
ConditionsMap overload: Interface to scan data content of the conditions mapping.
Definition: ConditionsSlice.cpp:147
dd4hep::cond::ConditionsSlice::iov
const IOV & iov() const
Access the combined IOV of the slice from the pool.
Definition: ConditionsSlice.cpp:56
dd4hep::detail::ConditionObject
The data class behind a conditions handle.
Definition: ConditionsInterna.h:68
dd4hep::cond::ConditionsManager
Manager class for condition handles.
Definition: ConditionsManager.h:46
dd4hep::cond::ConditionsSlice::pool
std::unique_ptr< UserPool > pool
Reference to the user pool managing all conditions of this slice.
Definition: ConditionsSlice.h:107
key
unsigned char key
Definition: AlignmentsCalculator.cpp:69
dd4hep::ConditionsMap::LAST_ITEM
@ LAST_ITEM
Definition: ConditionsMap.h:63
dd4hep::cond::fill_content
void fill_content(ConditionsManager mgr, ConditionsContent &content, const IOVType &typ)
Populate the conditions slice from the conditions manager (convenience)
Definition: ConditionsSlice.cpp:182
dd4hep::Condition::DERIVED
@ DERIVED
Definition: Conditions.h:79
dd4hep::cond::ConditionsSlice::REGISTER_MANAGER
@ REGISTER_MANAGER
Definition: ConditionsSlice.h:59
dd4hep::cond::ConditionsSlice::~ConditionsSlice
virtual ~ConditionsSlice()
Default destructor.
Definition: ConditionsSlice.cpp:44
dd4hep::detail::tools::copy
void copy(Alignment from, Alignment to)
Copy alignment object from source object.
Definition: AlignmentTools.cpp:43
InstanceCount.h
dd4hep::cond::ConditionsSlice::insert
virtual bool insert(DetElement detector, Condition::itemkey_type key, Condition condition) override
ConditionsMap overload: Add a condition directly to the slice.
Definition: ConditionsSlice.cpp:120
dd4hep::cond::ConditionsIOVPool
Pool of conditions satisfying one IOV type (epoch, run, fill, etc)
Definition: ConditionsIOVPool.h:38
dd4hep::cond::ConditionsContent::addLocation
std::pair< Condition::key_type, ConditionsLoadInfo * > addLocation(Condition::key_type hash, const T &info)
Add a new conditions key. T must inherit from class ConditionsContent::Info.
Definition: ConditionsContent.h:144
dd4hep::cond::ConditionsSlice::ManageFlag
ManageFlag
Definition: ConditionsSlice.h:58
dd4hep::Condition::Processor
Abstract base for processing callbacks to conditions objects.
Definition: Conditions.h:112
Printout.h
dd4hep::cond::ConditionsSlice
Conditions slice object. Defines which conditions should be loaded by the ConditionsManager.
Definition: ConditionsSlice.h:53