Warning, file /DD4hep/DDCond/src/plugins/ConditionsMappedPool.cpp was not indexed
or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #ifndef DDCOND_CONDITIONSMAPPEDPOOL_H
0014 #define DDCOND_CONDITIONSMAPPEDPOOL_H
0015
0016
0017 #include <DD4hep/Printout.h>
0018 #include <DD4hep/detail/ConditionsInterna.h>
0019
0020 #include <DDCond/ConditionsPool.h>
0021 #include <DDCond/ConditionsSelectors.h>
0022
0023
0024 #include <map>
0025 #include <unordered_map>
0026
0027
0028 namespace dd4hep {
0029
0030
0031 namespace cond {
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046 template<typename MAPPING, typename BASE>
0047 class ConditionsMappedPool : public BASE {
0048 public:
0049 typedef BASE Base;
0050 typedef MAPPING Mapping;
0051 typedef ConditionsMappedPool<Mapping,Base> Self;
0052
0053 protected:
0054 Mapping m_entries;
0055
0056
0057 template <typename R,typename T> std::size_t loop(R& result, T functor) {
0058 size_t len = result.size();
0059 for_each(m_entries.begin(),m_entries.end(),functor);
0060 return result.size() - len;
0061 }
0062 public:
0063
0064 ConditionsMappedPool(ConditionsManager mgr);
0065
0066
0067 virtual ~ConditionsMappedPool();
0068
0069
0070 virtual size_t size() const final {
0071 return m_entries.size();
0072 }
0073
0074
0075 virtual bool insert(Condition condition) final {
0076 Condition::Object* c = condition.access();
0077 bool result = m_entries.emplace(c->hash,c).second;
0078 if ( result ) return true;
0079 auto i = m_entries.find(c->hash);
0080 Condition present = (*i).second;
0081
0082 printout(ERROR,"MappedPool","ConditionsClash: %s %08llX <> %08llX %s",
0083 present.name(), present.key(), condition.key(), condition.name());
0084 return false;
0085 }
0086
0087
0088 virtual void insert(RangeConditions& new_entries) final {
0089 Condition::Object* o;
0090 for( Condition c : new_entries ) {
0091 o = c.access();
0092 m_entries.emplace(o->hash,o);
0093 }
0094 }
0095
0096
0097 virtual void clear() final {
0098 for_each(m_entries.begin(), m_entries.end(), Operators::poolRemove(*this));
0099 m_entries.clear();
0100 }
0101
0102
0103 virtual Condition exists(Condition::key_type key) const final {
0104 auto i=find_if(m_entries.begin(), m_entries.end(), Operators::keyFind(key));
0105 return i==m_entries.end() ? Condition() : (*i).second;
0106 }
0107
0108
0109 virtual size_t select(Condition::key_type key, RangeConditions& result) final
0110 { return loop(result, Operators::keyedSelect(key,result)); }
0111
0112
0113 virtual size_t select_all(const ConditionsSelect& result) final
0114 { return loop(result, Operators::operatorWrapper(result)); }
0115
0116
0117 virtual size_t select_all(RangeConditions& result) final
0118 { return loop(result, Operators::sequenceSelect(result)); }
0119
0120
0121 virtual size_t select_all(ConditionsPool& result) final
0122 { return loop(result, Operators::poolSelect(result)); }
0123 };
0124
0125
0126
0127
0128
0129
0130
0131
0132 template<typename MAPPING, typename BASE> class ConditionsMappedUpdatePool
0133 : public ConditionsMappedPool<MAPPING,BASE>
0134 {
0135 public:
0136 typedef ConditionsMappedPool<MAPPING,BASE> Self;
0137 public:
0138
0139 ConditionsMappedUpdatePool(ConditionsManager mgr)
0140 : ConditionsMappedPool<MAPPING,BASE>(mgr) { }
0141
0142
0143 virtual ~ConditionsMappedUpdatePool() { }
0144
0145
0146 virtual size_t popEntries(UpdatePool::UpdateEntries& entries) final {
0147 detail::ClearOnReturn<MAPPING> clr(this->Self::m_entries);
0148 return this->Self::loop(entries, [&entries](const std::pair<Condition::key_type,Condition::Object*>& o) {
0149 entries[o.second->iov].emplace_back(o.second);});
0150 }
0151
0152
0153 virtual void select_range(Condition::key_type key,
0154 const IOV& req,
0155 RangeConditions& result) final
0156 {
0157 MAPPING& m = this->ConditionsMappedPool<MAPPING,BASE>::m_entries;
0158 if ( !m.empty() ) {
0159 unsigned int req_typ = req.iovType ? req.iovType->type : req.type;
0160 const IOV::Key& req_key = req.key();
0161 result.reserve(m.size());
0162 for(const auto& e : m) {
0163 Condition::Object* o = e.second;
0164 if ( key == o->hash ) {
0165 const IOV* _iov = o->iov;
0166 unsigned int typ = _iov->iovType ? _iov->iovType->type : _iov->type;
0167 if ( req_typ == typ ) {
0168 if ( IOV::key_is_contained(_iov->key(),req_key) )
0169
0170 result.emplace_back(o);
0171 else if ( IOV::key_overlaps_lower_end(_iov->key(),req_key) )
0172
0173 result.emplace_back(o);
0174 else if ( IOV::key_overlaps_higher_end(_iov->key(),req_key) )
0175
0176 result.emplace_back(o);
0177 }
0178 }
0179 }
0180 }
0181 }
0182 };
0183 }
0184 }
0185 #endif
0186
0187
0188
0189
0190
0191
0192
0193
0194
0195
0196
0197
0198
0199
0200
0201
0202 #include <DD4hep/InstanceCount.h>
0203
0204 using dd4hep::Handle;
0205 using namespace dd4hep::cond;
0206
0207
0208 template<typename MAPPING, typename BASE>
0209 ConditionsMappedPool<MAPPING,BASE>::ConditionsMappedPool(ConditionsManager mgr) : BASE(mgr,0) {
0210 this->BASE::SetName("");
0211 this->BASE::SetTitle("ConditionsMappedPool");
0212 InstanceCount::increment(this);
0213 }
0214
0215
0216 template<typename MAPPING, typename BASE>
0217 ConditionsMappedPool<MAPPING,BASE>::~ConditionsMappedPool() {
0218 clear();
0219 InstanceCount::decrement(this);
0220 }
0221
0222 #include <DD4hep/Factories.h>
0223 namespace {
0224 ConditionsManager _mgr(int argc, char** argv) {
0225 if ( argc > 0 ) {
0226 ConditionsManagerObject* m = (ConditionsManagerObject*)argv[0];
0227 return m;
0228 }
0229 dd4hep::except("ConditionsMappedPool","++ Insufficient arguments: arg[0] = ConditionManager!");
0230 return ConditionsManager(0);
0231 }
0232 #define _CR(fun,x,b,y) void* fun(dd4hep::Detector&, int argc, char** argv) \
0233 { return new b<x<dd4hep::Condition::key_type,dd4hep::Condition::Object*>,y>(_mgr(argc,argv)); }
0234
0235
0236 _CR(create_map_pool,std::map,ConditionsMappedPool,ConditionsPool)
0237
0238 _CR(create_unordered_map_pool,std::unordered_map,ConditionsMappedPool,ConditionsPool)
0239
0240 _CR(create_map_update_pool,std::map,ConditionsMappedUpdatePool,UpdatePool)
0241
0242 _CR(create_unordered_map_update_pool,std::unordered_map,ConditionsMappedUpdatePool,UpdatePool)
0243 }
0244 DECLARE_DD4HEP_CONSTRUCTOR(DD4hep_ConditionsMappedPool, create_map_pool)
0245 DECLARE_DD4HEP_CONSTRUCTOR(DD4hep_ConditionsHashedPool, create_unordered_map_pool)
0246 DECLARE_DD4HEP_CONSTRUCTOR(DD4hep_ConditionsMappedUpdatePool, create_map_update_pool)
0247 DECLARE_DD4HEP_CONSTRUCTOR(DD4hep_ConditionsHashedUpdatePool, create_unordered_map_update_pool)