File indexing completed on 2025-01-30 09:16:28
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #ifndef DDCOND_CONDITIONSLINEARPOOL_H
0014 #define DDCOND_CONDITIONSLINEARPOOL_H
0015
0016
0017 #include <DDCond/ConditionsPool.h>
0018 #include <DDCond/ConditionsManager.h>
0019 #include <DDCond/ConditionsSelectors.h>
0020
0021 #include <DD4hep/Printout.h>
0022
0023
0024 #include <list>
0025
0026
0027 namespace dd4hep {
0028
0029
0030 namespace cond {
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044 template<typename MAPPING, typename BASE>
0045 class ConditionsLinearPool : public BASE {
0046 protected:
0047 MAPPING m_entries;
0048
0049
0050 template <typename R,typename T> size_t loop(R& result, T functor) {
0051 size_t len = result.size();
0052 for_each(m_entries.begin(),m_entries.end(),functor);
0053 return result.size() - len;
0054 }
0055 public:
0056
0057 ConditionsLinearPool(ConditionsManager mgr, IOV* iov);
0058
0059
0060 virtual ~ConditionsLinearPool();
0061
0062
0063 virtual size_t size() const final {
0064 return m_entries.size();
0065 }
0066
0067
0068 virtual void clear() final {
0069 for_each(m_entries.begin(), m_entries.end(), Operators::poolRemove(*this));
0070 m_entries.clear();
0071 }
0072
0073
0074 virtual Condition exists(Condition::key_type key) const final {
0075 auto i = find_if(m_entries.begin(), m_entries.end(), Operators::keyFind(key));
0076 return i==m_entries.end() ? Condition() : (*i);
0077 }
0078
0079
0080 virtual bool insert(Condition condition) final
0081 { m_entries.emplace(m_entries.end(),condition.access()); return true; }
0082
0083
0084 virtual void insert(RangeConditions& rc) final
0085 { for_each(rc.begin(), rc.end(), Operators::sequenceSelect(m_entries)); }
0086
0087
0088 virtual size_t select(Condition::key_type key, RangeConditions& result) final
0089 { return loop(result, Operators::keyedSelect(key, result)); }
0090
0091
0092 virtual size_t select_all(const ConditionsSelect& result) final
0093 { return loop(result, Operators::operatorWrapper(result)); }
0094
0095
0096 virtual size_t select_all(RangeConditions& result) final
0097 { return loop(result, Operators::sequenceSelect(result)); }
0098
0099
0100 virtual size_t select_all(ConditionsPool& result) final
0101 { return loop(result, Operators::poolSelect(result)); }
0102 };
0103
0104
0105
0106
0107
0108
0109
0110
0111 template<typename MAPPING, typename BASE> class ConditionsLinearUpdatePool
0112 : public ConditionsLinearPool<MAPPING,BASE>
0113 {
0114 public:
0115
0116 ConditionsLinearUpdatePool(ConditionsManager mgr, IOV*)
0117 : ConditionsLinearPool<MAPPING,BASE>(mgr,0)
0118 {
0119 this->BASE::SetTitle("ConditionsLinearUpdatePool");
0120 }
0121
0122
0123 virtual ~ConditionsLinearUpdatePool() {
0124 }
0125
0126
0127 virtual size_t popEntries(UpdatePool::UpdateEntries& entries) final {
0128 MAPPING& m = this->ConditionsLinearPool<MAPPING,BASE>::m_entries;
0129 size_t len = entries.size();
0130 if ( !m.empty() ) {
0131 for(auto* o : m)
0132 entries[o->iov].emplace_back(o);
0133 m.clear();
0134 }
0135 return entries.size()-len;
0136 }
0137
0138
0139 virtual void select_range(Condition::key_type key,
0140 const IOV& req,
0141 RangeConditions& result) final
0142 {
0143 MAPPING& m = this->ConditionsLinearPool<MAPPING,BASE>::m_entries;
0144 if ( !m.empty() ) {
0145 unsigned int req_typ = req.iovType ? req.iovType->type : req.type;
0146 const IOV::Key& req_key = req.key();
0147 for(auto* e : m ) {
0148 if ( key == e->hash ) {
0149 const IOV* _iov = e->iov;
0150 unsigned int typ = _iov->iovType ? _iov->iovType->type : _iov->type;
0151 if ( req_typ == typ ) {
0152 if ( IOV::key_is_contained(_iov->key(),req_key) )
0153
0154 result.emplace_back(e);
0155 else if ( IOV::key_overlaps_lower_end(_iov->key(),req_key) )
0156
0157 result.emplace_back(e);
0158 else if ( IOV::key_overlaps_higher_end(_iov->key(),req_key) )
0159
0160 result.emplace_back(e);
0161 }
0162 }
0163 }
0164 }
0165 }
0166
0167 };
0168
0169
0170 }
0171 }
0172 #endif
0173
0174
0175
0176
0177
0178
0179
0180
0181
0182
0183
0184
0185
0186
0187
0188
0189 #include <DD4hep/InstanceCount.h>
0190
0191 using namespace dd4hep::cond;
0192
0193
0194 template<typename MAPPING, typename BASE>
0195 ConditionsLinearPool<MAPPING,BASE>::ConditionsLinearPool(ConditionsManager mgr, IOV* i)
0196 : BASE(mgr, i)
0197 {
0198 this->BASE::SetName(i ? i->str().c_str() : "Unknown IOV");
0199 this->BASE::SetTitle("ConditionsLinearPool");
0200 InstanceCount::increment(this);
0201 }
0202
0203
0204 template<typename MAPPING, typename BASE>
0205 ConditionsLinearPool<MAPPING,BASE>::~ConditionsLinearPool() {
0206 clear();
0207 detail::deletePtr(this->BASE::iov);
0208 InstanceCount::decrement(this);
0209 }
0210
0211
0212 namespace dd4hep {
0213
0214
0215 namespace cond {
0216
0217 }
0218 }
0219
0220 #include <DD4hep/Factories.h>
0221 namespace {
0222 ConditionsManager _mgr(int argc, char** argv) {
0223 if ( argc > 0 ) {
0224 ConditionsManager::Object* m = (ConditionsManager::Object*)argv[0];
0225 return m;
0226 }
0227 dd4hep::except("ConditionsLinearPool","++ Insufficient arguments: arg[0] = ConditionManager!");
0228 return ConditionsManager(0);
0229 }
0230 dd4hep::IOV* _iov(int argc, char** argv) {
0231 if ( argc > 1 ) {
0232 dd4hep::IOV* i = (dd4hep::IOV*)argv[1];
0233 return i;
0234 }
0235 dd4hep::except("ConditionsLinearPool","++ Insufficient arguments: arg[1] = IOV!");
0236 return nullptr;
0237 }
0238
0239 #define _CR(fun,x,b,y) void* fun(dd4hep::Detector&, int argc, char** argv) \
0240 { return new b<x<dd4hep::Condition::Object*>,y>(_mgr(argc,argv), _iov(argc,argv)); }
0241
0242 _CR(create_vector_pool,std::vector,ConditionsLinearPool,ConditionsPool)
0243
0244 _CR(create_list_pool,std::list,ConditionsLinearPool,ConditionsPool)
0245
0246 _CR(create_vector_update_pool,std::vector,ConditionsLinearUpdatePool,UpdatePool)
0247
0248 _CR(create_list_update_pool,std::list,ConditionsLinearUpdatePool,UpdatePool)
0249 }
0250
0251 DECLARE_DD4HEP_CONSTRUCTOR(DD4hep_ConditionsLinearPool, create_vector_pool)
0252 DECLARE_DD4HEP_CONSTRUCTOR(DD4hep_ConditionsLinearVectorPool, create_vector_pool)
0253 DECLARE_DD4HEP_CONSTRUCTOR(DD4hep_ConditionsLinearUpdatePool, create_vector_update_pool)
0254 DECLARE_DD4HEP_CONSTRUCTOR(DD4hep_ConditionsLinearVectorUpdatePool,create_vector_update_pool)
0255
0256 DECLARE_DD4HEP_CONSTRUCTOR(DD4hep_ConditionsLinearListPool, create_list_pool)
0257 DECLARE_DD4HEP_CONSTRUCTOR(DD4hep_ConditionsLinearListUpdatePool, create_list_update_pool)