DD4hep  1.30.0
Detector Description Toolkit for High Energy Physics
ConditionsLinearPool.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_CONDITIONSLINEARPOOL_H
14 #define DDCOND_CONDITIONSLINEARPOOL_H
15 
16 // Framework include files
17 #include <DDCond/ConditionsPool.h>
20 
21 #include <DD4hep/Printout.h>
22 
23 // C/C++ include files
24 #include <list>
25 
27 namespace dd4hep {
28 
30  namespace cond {
31 
33 
44  template<typename MAPPING, typename BASE>
45  class ConditionsLinearPool : public BASE {
46  protected:
47  MAPPING m_entries;
48 
50  template <typename R,typename T> size_t loop(R& result, T functor) {
51  size_t len = result.size();
52  for_each(m_entries.begin(),m_entries.end(),functor);
53  return result.size() - len;
54  }
55  public:
58 
60  virtual ~ConditionsLinearPool();
61 
63  virtual size_t size() const final {
64  return m_entries.size();
65  }
66 
68  virtual void clear() final {
69  for_each(m_entries.begin(), m_entries.end(), Operators::poolRemove(*this));
70  m_entries.clear();
71  }
72 
74  virtual Condition exists(Condition::key_type key) const final {
75  auto i = find_if(m_entries.begin(), m_entries.end(), Operators::keyFind(key));
76  return i==m_entries.end() ? Condition() : (*i);
77  }
78 
80  virtual bool insert(Condition condition) final
81  { m_entries.emplace(m_entries.end(),condition.access()); return true; }
82 
84  virtual void insert(RangeConditions& rc) final
85  { for_each(rc.begin(), rc.end(), Operators::sequenceSelect(m_entries)); }
86 
88  virtual size_t select(Condition::key_type key, RangeConditions& result) final
89  { return loop(result, Operators::keyedSelect(key, result)); }
90 
92  virtual size_t select_all(const ConditionsSelect& result) final
93  { return loop(result, Operators::operatorWrapper(result)); }
94 
96  virtual size_t select_all(RangeConditions& result) final
97  { return loop(result, Operators::sequenceSelect(result)); }
98 
100  virtual size_t select_all(ConditionsPool& result) final
101  { return loop(result, Operators::poolSelect(result)); }
102  };
103 
105 
111  template<typename MAPPING, typename BASE> class ConditionsLinearUpdatePool
112  : public ConditionsLinearPool<MAPPING,BASE>
113  {
114  public:
117  : ConditionsLinearPool<MAPPING,BASE>(mgr,0)
118  {
119  this->BASE::SetTitle("ConditionsLinearUpdatePool");
120  }
121 
124  }
125 
129  size_t len = entries.size();
130  if ( !m.empty() ) {
131  for(auto* o : m)
132  entries[o->iov].emplace_back(o);
133  m.clear();
134  }
135  return entries.size()-len;
136  }
137 
140  const IOV& req,
141  RangeConditions& result) final
142  {
144  if ( !m.empty() ) {
145  unsigned int req_typ = req.iovType ? req.iovType->type : req.type;
146  const IOV::Key& req_key = req.key();
147  for(auto* e : m ) {
148  if ( key == e->hash ) {
149  const IOV* _iov = e->iov;
150  unsigned int typ = _iov->iovType ? _iov->iovType->type : _iov->type;
151  if ( req_typ == typ ) {
152  if ( IOV::key_is_contained(_iov->key(),req_key) )
153  // IOV test contained in key. Take it!
154  result.emplace_back(e);
155  else if ( IOV::key_overlaps_lower_end(_iov->key(),req_key) )
156  // IOV overlap on test on the lower end of key
157  result.emplace_back(e);
158  else if ( IOV::key_overlaps_higher_end(_iov->key(),req_key) )
159  // IOV overlap of test on the higher end of key
160  result.emplace_back(e);
161  }
162  }
163  }
164  }
165  }
166 
167  };
168 
169 
170  } /* End namespace cond */
171 } /* End namespace dd4hep */
172 #endif // DDCOND_CONDITIONSLINEARPOOL_H
173 
174 //==========================================================================
175 // AIDA Detector description implementation
176 //--------------------------------------------------------------------------
177 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
178 // All rights reserved.
179 //
180 // For the licensing terms see $DD4hepINSTALL/LICENSE.
181 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
182 //
183 // Author : M.Frank
184 //
185 //==========================================================================
186 
187 // Framework include files
188 //#include <DDCond/ConditionsLinearPool.h>
189 #include <DD4hep/InstanceCount.h>
190 
191 using namespace dd4hep::cond;
192 
194 template<typename MAPPING, typename BASE>
196  : BASE(mgr, i)
197 {
198  this->BASE::SetName(i ? i->str().c_str() : "Unknown IOV");
199  this->BASE::SetTitle("ConditionsLinearPool");
201 }
202 
204 template<typename MAPPING, typename BASE>
206  clear();
207  detail::deletePtr(this->BASE::iov);
209 }
210 
212 namespace dd4hep {
213 
215  namespace cond {
216 
217  } /* End namespace cond */
218 } /* End namespace dd4hep */
219 
220 #include <DD4hep/Factories.h>
221 namespace {
222  ConditionsManager _mgr(int argc, char** argv) {
223  if ( argc > 0 ) {
225  return m;
226  }
227  dd4hep::except("ConditionsLinearPool","++ Insufficient arguments: arg[0] = ConditionManager!");
228  return ConditionsManager(0);
229  }
230  dd4hep::IOV* _iov(int argc, char** argv) {
231  if ( argc > 1 ) {
232  dd4hep::IOV* i = (dd4hep::IOV*)argv[1];
233  return i;
234  }
235  dd4hep::except("ConditionsLinearPool","++ Insufficient arguments: arg[1] = IOV!");
236  return nullptr;
237  }
238 
239 #define _CR(fun,x,b,y) void* fun(dd4hep::Detector&, int argc, char** argv) \
240  { return new b<x<dd4hep::Condition::Object*>,y>(_mgr(argc,argv), _iov(argc,argv)); }
241  _CR(create_vector_pool,std::vector,ConditionsLinearPool,ConditionsPool)
244  _CR(create_list_pool,std::list,ConditionsLinearPool,ConditionsPool)
246  _CR(create_vector_update_pool,std::vector,ConditionsLinearUpdatePool,UpdatePool)
248  _CR(create_list_update_pool,std::list,ConditionsLinearUpdatePool,UpdatePool)
249 }
250 
251 DECLARE_DD4HEP_CONSTRUCTOR(DD4hep_ConditionsLinearPool, create_vector_pool)
252 DECLARE_DD4HEP_CONSTRUCTOR(DD4hep_ConditionsLinearVectorPool, create_vector_pool)
253 DECLARE_DD4HEP_CONSTRUCTOR(DD4hep_ConditionsLinearUpdatePool, create_vector_update_pool)
254 DECLARE_DD4HEP_CONSTRUCTOR(DD4hep_ConditionsLinearVectorUpdatePool,create_vector_update_pool)
255 
256 DECLARE_DD4HEP_CONSTRUCTOR(DD4hep_ConditionsLinearListPool, create_list_pool)
257 DECLARE_DD4HEP_CONSTRUCTOR(DD4hep_ConditionsLinearListUpdatePool, create_list_update_pool)
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::cond::ConditionsLinearPool
Class implementing the conditions collection for a given IOV type.
Definition: ConditionsLinearPool.cpp:45
dd4hep::RangeConditions
std::vector< Condition > RangeConditions
Definition: Conditions.h:491
ConditionsSelectors.h
cond
AlignmentCondition::Object * cond
Definition: AlignmentsCalculator.cpp:68
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::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::ConditionsLinearUpdatePool
Class implementing the conditions update pool for a given IOV type.
Definition: ConditionsLinearPool.cpp:113
dd4hep::cond::ConditionsLinearUpdatePool::popEntries
virtual size_t popEntries(UpdatePool::UpdateEntries &entries) final
Adopt all entries sorted by IOV. Entries will be removed from the pool.
Definition: ConditionsLinearPool.cpp:127
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::cond::ConditionsLinearUpdatePool::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: ConditionsLinearPool.cpp:139
dd4hep::IOV::str
std::string str() const
Create string representation of the IOV.
Definition: IOV.cpp:141
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
dd4hep::cond::ConditionsLinearPool::select_all
virtual size_t select_all(ConditionsPool &result) final
Select the conditons, used also by the DetElement of the condition.
Definition: ConditionsLinearPool.cpp:100
ConditionsManager.h
Factories.h
dd4hep::cond::ConditionsLinearPool::insert
virtual void insert(RangeConditions &rc) final
Register a new condition to this pool. May overload for performance reasons.
Definition: ConditionsLinearPool.cpp:84
dd4hep::ConditionsSelect
Conditions selector functor. Default implementation selects everything evaluated.
Definition: Conditions.h:422
dd4hep::cond::ConditionsLinearPool::select_all
virtual size_t select_all(const ConditionsSelect &result) final
Select the conditons, used also by the DetElement of the condition.
Definition: ConditionsLinearPool.cpp:92
_CR
#define _CR(fun, x, b, y)
Definition: ConditionsLinearPool.cpp:239
dd4hep::cond::ConditionsLinearPool::exists
virtual Condition exists(Condition::key_type key) const final
Check if a condition exists in the pool.
Definition: ConditionsLinearPool.cpp:74
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::cond::ConditionsLinearPool::size
virtual size_t size() const final
Total entry count.
Definition: ConditionsLinearPool.cpp:63
dd4hep::IOV
Class describing the interval of validty.
Definition: IOV.h:67
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::ConditionsLinearPool::insert
virtual bool insert(Condition condition) final
Register a new condition to this pool.
Definition: ConditionsLinearPool.cpp:80
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::cond::ConditionsLinearPool::m_entries
MAPPING m_entries
Definition: ConditionsLinearPool.cpp:47
dd4hep::InstanceCount::decrement
static void decrement(T *)
Decrement count according to type information.
Definition: InstanceCount.h:102
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::cond::ConditionsLinearPool::select
virtual size_t select(Condition::key_type key, RangeConditions &result) final
Select the conditions matching the DetElement and the conditions name.
Definition: ConditionsLinearPool.cpp:88
dd4hep::cond::ConditionsLinearPool::loop
size_t loop(R &result, T functor)
Helper function to loop over the conditions container and apply a functor.
Definition: ConditionsLinearPool.cpp:50
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::cond::ConditionsLinearPool::clear
virtual void clear() final
Full cleanup of all managed conditions.
Definition: ConditionsLinearPool.cpp:68
dd4hep::cond::ConditionsLinearPool::~ConditionsLinearPool
virtual ~ConditionsLinearPool()
Default destructor.
Definition: ConditionsLinearPool.cpp:205
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::cond::ConditionsManager
Manager class for condition handles.
Definition: ConditionsManager.h:46
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::ConditionsLinearUpdatePool::ConditionsLinearUpdatePool
ConditionsLinearUpdatePool(ConditionsManager mgr, IOV *)
Default constructor.
Definition: ConditionsLinearPool.cpp:116
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
ConditionsPool.h
dd4hep::cond::UpdatePool
Interface for conditions pool optimized to host conditions updates.
Definition: ConditionsPool.h:109
dd4hep::cond::ConditionsLinearPool::select_all
virtual size_t select_all(RangeConditions &result) final
Select the conditons, used also by the DetElement of the condition.
Definition: ConditionsLinearPool.cpp:96
InstanceCount.h
dd4hep::IOVType::type
unsigned int type
integer identifier used internally
Definition: IOV.h:41
dd4hep::cond::ConditionsLinearPool::ConditionsLinearPool
ConditionsLinearPool(ConditionsManager mgr, IOV *iov)
Default constructor.
Definition: ConditionsLinearPool.cpp:195
dd4hep::cond::ConditionsLinearUpdatePool::~ConditionsLinearUpdatePool
virtual ~ConditionsLinearUpdatePool()
Default destructor.
Definition: ConditionsLinearPool.cpp:123
Printout.h