DD4hep  1.30.0
Detector Description Toolkit for High Energy Physics
ConditionsMappedPool.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 #ifndef DDCOND_CONDITIONSMAPPEDPOOL_H
14 #define DDCOND_CONDITIONSMAPPEDPOOL_H
15 
16 // Framework include files
17 #include <DD4hep/Printout.h>
19 
20 #include <DDCond/ConditionsPool.h>
22 
23 // C/C++ include files
24 #include <map>
25 #include <unordered_map>
26 
28 namespace dd4hep {
29 
31  namespace cond {
32 
34 
46  template<typename MAPPING, typename BASE>
47  class ConditionsMappedPool : public BASE {
48  public:
49  typedef BASE Base;
50  typedef MAPPING Mapping;
52 
53  protected:
55 
57  template <typename R,typename T> std::size_t loop(R& result, T functor) {
58  size_t len = result.size();
59  for_each(m_entries.begin(),m_entries.end(),functor);
60  return result.size() - len;
61  }
62  public:
65 
67  virtual ~ConditionsMappedPool();
68 
70  virtual size_t size() const final {
71  return m_entries.size();
72  }
73 
75  virtual bool insert(Condition condition) final {
76  Condition::Object* c = condition.access();
77  bool result = m_entries.emplace(c->hash,c).second;
78  if ( result ) return true;
79  auto i = m_entries.find(c->hash);
80  Condition present = (*i).second;
81 
82  printout(ERROR,"MappedPool","ConditionsClash: %s %08llX <> %08llX %s",
83  present.name(), present.key(), condition.key(), condition.name());
84  return false;
85  }
86 
88  virtual void insert(RangeConditions& new_entries) final {
90  for( Condition c : new_entries ) {
91  o = c.access();
92  m_entries.emplace(o->hash,o);
93  }
94  }
95 
97  virtual void clear() final {
98  for_each(m_entries.begin(), m_entries.end(), Operators::poolRemove(*this));
99  m_entries.clear();
100  }
101 
103  virtual Condition exists(Condition::key_type key) const final {
104  auto i=find_if(m_entries.begin(), m_entries.end(), Operators::keyFind(key));
105  return i==m_entries.end() ? Condition() : (*i).second;
106  }
107 
109  virtual size_t select(Condition::key_type key, RangeConditions& result) final
110  { return loop(result, Operators::keyedSelect(key,result)); }
111 
113  virtual size_t select_all(const ConditionsSelect& result) final
114  { return loop(result, Operators::operatorWrapper(result)); }
115 
117  virtual size_t select_all(RangeConditions& result) final
118  { return loop(result, Operators::sequenceSelect(result)); }
119 
121  virtual size_t select_all(ConditionsPool& result) final
122  { return loop(result, Operators::poolSelect(result)); }
123  };
124 
126 
132  template<typename MAPPING, typename BASE> class ConditionsMappedUpdatePool
133  : public ConditionsMappedPool<MAPPING,BASE>
134  {
135  public:
137  public:
140  : ConditionsMappedPool<MAPPING,BASE>(mgr) { }
141 
144 
147  detail::ClearOnReturn<MAPPING> clr(this->Self::m_entries);
148  return this->Self::loop(entries, [&entries](const std::pair<Condition::key_type,Condition::Object*>& o) {
149  entries[o.second->iov].emplace_back(o.second);});
150  }
151 
154  const IOV& req,
155  RangeConditions& result) final
156  {
158  if ( !m.empty() ) {
159  unsigned int req_typ = req.iovType ? req.iovType->type : req.type;
160  const IOV::Key& req_key = req.key();
161  result.reserve(m.size());
162  for(const auto& e : m) {
163  Condition::Object* o = e.second;
164  if ( key == o->hash ) {
165  const IOV* _iov = o->iov;
166  unsigned int typ = _iov->iovType ? _iov->iovType->type : _iov->type;
167  if ( req_typ == typ ) {
168  if ( IOV::key_is_contained(_iov->key(),req_key) )
169  // IOV test contained in key. Take it!
170  result.emplace_back(o);
171  else if ( IOV::key_overlaps_lower_end(_iov->key(),req_key) )
172  // IOV overlap on test on the lower end of key
173  result.emplace_back(o);
174  else if ( IOV::key_overlaps_higher_end(_iov->key(),req_key) )
175  // IOV overlap of test on the higher end of key
176  result.emplace_back(o);
177  }
178  }
179  }
180  }
181  }
182  };
183  } /* End namespace cond */
184 } /* End namespace dd4hep */
185 #endif /* DDCOND_CONDITIONSMAPPEDPOOL_H */
186 
187 //==========================================================================
188 // AIDA Detector description implementation
189 //--------------------------------------------------------------------------
190 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
191 // All rights reserved.
192 //
193 // For the licensing terms see $DD4hepINSTALL/LICENSE.
194 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
195 //
196 // Author : M.Frank
197 //
198 //==========================================================================
199 
200 // Framework include files
201 //#include <DDCond/ConditionsMappedPool.h>
202 #include <DD4hep/InstanceCount.h>
203 
204 using dd4hep::Handle;
205 using namespace dd4hep::cond;
206 
208 template<typename MAPPING, typename BASE>
210  this->BASE::SetName("");
211  this->BASE::SetTitle("ConditionsMappedPool");
213 }
214 
216 template<typename MAPPING, typename BASE>
218  clear();
220 }
221 
222 #include <DD4hep/Factories.h>
223 namespace {
224  ConditionsManager _mgr(int argc, char** argv) {
225  if ( argc > 0 ) {
227  return m;
228  }
229  dd4hep::except("ConditionsMappedPool","++ Insufficient arguments: arg[0] = ConditionManager!");
230  return ConditionsManager(0);
231  }
232 #define _CR(fun,x,b,y) void* fun(dd4hep::Detector&, int argc, char** argv) \
233  { return new b<x<dd4hep::Condition::key_type,dd4hep::Condition::Object*>,y>(_mgr(argc,argv)); }
234 
236  _CR(create_map_pool,std::map,ConditionsMappedPool,ConditionsPool)
238  _CR(create_unordered_map_pool,std::unordered_map,ConditionsMappedPool,ConditionsPool)
240  _CR(create_map_update_pool,std::map,ConditionsMappedUpdatePool,UpdatePool)
242  _CR(create_unordered_map_update_pool,std::unordered_map,ConditionsMappedUpdatePool,UpdatePool)
243 }
244 DECLARE_DD4HEP_CONSTRUCTOR(DD4hep_ConditionsMappedPool, create_map_pool)
245 DECLARE_DD4HEP_CONSTRUCTOR(DD4hep_ConditionsHashedPool, create_unordered_map_pool)
246 DECLARE_DD4HEP_CONSTRUCTOR(DD4hep_ConditionsMappedUpdatePool, create_map_update_pool)
247 DECLARE_DD4HEP_CONSTRUCTOR(DD4hep_ConditionsHashedUpdatePool, create_unordered_map_update_pool)
dd4hep::cond::ConditionsMappedPool::Base
BASE Base
Definition: ConditionsMappedPool.cpp:49
dd4hep::cond::Operators::keyedSelect
ConditionsOperation< KeyedSelect< C > > keyedSelect(Condition::key_type key, C &coll)
Helper to create functor to select keyed objects from a conditions pool.
Definition: ConditionsSelectors.h:274
dd4hep::RangeConditions
std::vector< Condition > RangeConditions
Definition: Conditions.h:491
dd4hep::cond::ConditionsMappedPool::select
virtual size_t select(Condition::key_type key, RangeConditions &result) final
Select the conditions matching the DetElement and the conditions name.
Definition: ConditionsMappedPool.cpp:109
ConditionsSelectors.h
cond
AlignmentCondition::Object * cond
Definition: AlignmentsCalculator.cpp:68
dd4hep::cond::ConditionsMappedPool::ConditionsMappedPool
ConditionsMappedPool(ConditionsManager mgr)
Default constructor.
Definition: ConditionsMappedPool.cpp:209
dd4hep::cond::Operators::keyFind
ConditionsOperation< KeyFind > keyFind(Condition::key_type key)
Helper to create functor to find conditions objects by hash key.
Definition: ConditionsSelectors.h:283
dd4hep::cond::ConditionsMappedPool::insert
virtual bool insert(Condition condition) final
Register a new condition to this pool.
Definition: ConditionsMappedPool.cpp:75
dd4hep::detail::ConditionObject::hash
Condition::key_type hash
Hash value of the name.
Definition: ConditionsInterna.h:85
dd4hep::cond::Operators::operatorWrapper
OperatorWrapper< oper_type > operatorWrapper(oper_type &oper)
Helper function to create a OperatorWrapper<T> object from the argument type.
Definition: ConditionsSelectors.h:203
dd4hep::cond::ConditionsMappedUpdatePool::~ConditionsMappedUpdatePool
virtual ~ConditionsMappedUpdatePool()
Default destructor.
Definition: ConditionsMappedPool.cpp:143
ConditionsInterna.h
dd4hep::cond::ConditionsMappedPool::size
virtual size_t size() const final
Total entry count.
Definition: ConditionsMappedPool.cpp:70
dd4hep::cond::ConditionsMappedUpdatePool::select_range
virtual void select_range(Condition::key_type key, const IOV &req, RangeConditions &result) final
Select the conditions matching the DetElement and the conditions name.
Definition: ConditionsMappedPool.cpp:153
dd4hep::cond::ConditionsMappedUpdatePool::Self
ConditionsMappedPool< MAPPING, BASE > Self
Definition: ConditionsMappedPool.cpp:136
dd4hep::cond::Operators::poolRemove
ConditionsOperation< PoolRemove< P > > poolRemove(P &pool)
Helper to create functor to remove objects from a conditions pool.
Definition: ConditionsSelectors.h:213
dd4hep::Handle
Handle: a templated class like a shared pointer, which allows specialized access to tgeometry objects...
Definition: Handle.h:84
dd4hep::cond::ConditionsMappedPool::insert
virtual void insert(RangeConditions &new_entries) final
Register a new condition to this pool. May overload for performance reasons.
Definition: ConditionsMappedPool.cpp:88
dd4hep::Condition::key
key_type key() const
Hash identifier.
Definition: Conditions.cpp:171
dd4hep::IOV::Key
std::pair< Key_value_type, Key_value_type > Key
Definition: IOV.h:74
dd4hep::InstanceCount::increment
static void increment(T *)
Increment count according to type information.
Definition: InstanceCount.h:98
Factories.h
dd4hep::Handle::name
const char * name() const
Access the object name (or "" if not supported by the object)
dd4hep::ConditionsSelect
Conditions selector functor. Default implementation selects everything evaluated.
Definition: Conditions.h:422
dd4hep::cond::ConditionsMappedUpdatePool::popEntries
virtual size_t popEntries(UpdatePool::UpdateEntries &entries) final
Adopt all entries sorted by IOV. Entries will be removed from the pool.
Definition: ConditionsMappedPool.cpp:146
dd4hep::cond::ConditionsMappedUpdatePool::ConditionsMappedUpdatePool
ConditionsMappedUpdatePool(ConditionsManager mgr)
Default constructor.
Definition: ConditionsMappedPool.cpp:139
entries
Entries entries
Definition: AlignmentsCalculator.cpp:81
dd4hep::cond::ConditionsManagerObject
Basic conditions manager implementation.
Definition: ConditionsManagerObject.h:54
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::IOV
Class describing the interval of validty.
Definition: IOV.h:67
dd4hep::cond::ConditionsMappedPool::select_all
virtual size_t select_all(ConditionsPool &result) final
Select the conditons, used also by the DetElement of the condition.
Definition: ConditionsMappedPool.cpp:121
dd4hep::cond::ConditionsMappedPool::m_entries
Mapping m_entries
Definition: ConditionsMappedPool.cpp:54
dd4hep::cond::Operators::sequenceSelect
ConditionsOperation< SequenceSelect< C > > sequenceSelect(C &coll)
Helper to create functor to select objects from a conditions pool into a sequential container.
Definition: ConditionsSelectors.h:241
dd4hep::cond::ConditionsPool
Class implementing the conditions collection for a given IOV type.
Definition: ConditionsPool.h:54
dd4hep::IOV::key_overlaps_lower_end
static bool key_overlaps_lower_end(const Key &key, const Key &test)
Check if IOV 'test' has an overlap on the lower interval edge with IOV 'key'.
Definition: IOV.h:159
dd4hep::InstanceCount::decrement
static void decrement(T *)
Decrement count according to type information.
Definition: InstanceCount.h:102
dd4hep::cond::ConditionsMappedPool::select_all
virtual size_t select_all(RangeConditions &result) final
Select the conditons, used also by the DetElement of the condition.
Definition: ConditionsMappedPool.cpp:117
DECLARE_DD4HEP_CONSTRUCTOR
#define DECLARE_DD4HEP_CONSTRUCTOR(name, func)
Definition: Factories.h:291
dd4hep::IOV::key_overlaps_higher_end
static bool key_overlaps_higher_end(const Key &key, const Key &test)
Check if IOV 'test' has an overlap on the upper interval edge with IOV 'key'.
Definition: IOV.h:162
dd4hep::IOV::key_is_contained
static bool key_is_contained(const Key &key, const Key &test)
Check if IOV 'test' is fully contained in IOV 'key'.
Definition: IOV.h:153
dd4hep::IOV::key
Key key() const
Get the local key of the IOV.
Definition: IOV.h:115
dd4hep::Condition::key_type
unsigned long long int key_type
Forward definition of the key type.
Definition: Conditions.h:54
dd4hep::detail::ConditionObject
The data class behind a conditions handle.
Definition: ConditionsInterna.h:68
dd4hep::cond::ConditionsMappedPool::exists
virtual Condition exists(Condition::key_type key) const final
Check if a condition exists in the pool.
Definition: ConditionsMappedPool.cpp:103
dd4hep::cond::ConditionsManager
Manager class for condition handles.
Definition: ConditionsManager.h:46
dd4hep::cond::ConditionsMappedUpdatePool
Class implementing the conditions update pool for a given IOV type.
Definition: ConditionsMappedPool.cpp:134
dd4hep::IOV::type
unsigned int type
IOV buffer type: Must be a bitmap!
Definition: IOV.h:86
key
unsigned char key
Definition: AlignmentsCalculator.cpp:69
dd4hep::cond::ConditionsMappedPool::Mapping
MAPPING Mapping
Definition: ConditionsMappedPool.cpp:50
dd4hep::IOV::iovType
const IOVType * iovType
Reference to IOV type.
Definition: IOV.h:80
dd4hep
Namespace for the AIDA detector description toolkit.
Definition: AlignmentsCalib.h:28
dd4hep::cond::UpdatePool::UpdateEntries
std::map< const IOV *, ConditionEntries > UpdateEntries
Update container specification.
Definition: ConditionsPool.h:114
dd4hep::cond::Operators::poolSelect
ConditionsOperation< PoolSelect< P > > poolSelect(P &pool)
Helper to create functor to insert objects into a conditions pool.
Definition: ConditionsSelectors.h:222
dd4hep::cond::ConditionsMappedPool
Class implementing the conditions collection for a given IOV type.
Definition: ConditionsMappedPool.cpp:47
ConditionsPool.h
dd4hep::cond::ConditionsMappedPool::clear
virtual void clear() final
Full cleanup of all managed conditions.
Definition: ConditionsMappedPool.cpp:97
dd4hep::cond::ConditionsMappedPool::loop
std::size_t loop(R &result, T functor)
Helper function to loop over the conditions container and apply a functor.
Definition: ConditionsMappedPool.cpp:57
dd4hep::cond::UpdatePool
Interface for conditions pool optimized to host conditions updates.
Definition: ConditionsPool.h:109
_CR
#define _CR(fun, x, b, y)
Definition: ConditionsMappedPool.cpp:232
InstanceCount.h
dd4hep::cond::ConditionsMappedPool::select_all
virtual size_t select_all(const ConditionsSelect &result) final
Select the conditons, used also by the DetElement of the condition.
Definition: ConditionsMappedPool.cpp:113
dd4hep::IOVType::type
unsigned int type
integer identifier used internally
Definition: IOV.h:41
dd4hep::detail::ConditionObject::iov
const IOV * iov
Interval of validity.
Definition: ConditionsInterna.h:83
dd4hep::cond::ConditionsMappedPool::Self
ConditionsMappedPool< Mapping, Base > Self
Definition: ConditionsMappedPool.cpp:51
Printout.h
dd4hep::cond::ConditionsMappedPool::~ConditionsMappedPool
virtual ~ConditionsMappedPool()
Default destructor.
Definition: ConditionsMappedPool.cpp:217