File indexing completed on 2025-01-30 09:16:56
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #include <DD4hep/Printout.h>
0016 #include <DD4hep/ConditionsMap.h>
0017 #include <DD4hep/detail/ConditionsInterna.h>
0018
0019 using namespace dd4hep;
0020
0021
0022 void ConditionsMap::scan(DetElement detector,
0023 Condition::itemkey_type lower,
0024 Condition::itemkey_type upper,
0025 const Condition::Processor& processor) const
0026 {
0027
0028
0029
0030
0031
0032
0033 struct Scanner : public Condition::Processor {
0034 Condition::key_type lower, upper;
0035 const Condition::Processor& processor;
0036
0037 Scanner(Condition::key_type low, Condition::key_type up, const Condition::Processor& p)
0038 : lower(low), upper(up), processor(p) {}
0039
0040 virtual int process(Condition c) const override {
0041 Condition::key_type h = c->hash;
0042 if ( h >= lower && h <= upper )
0043 return processor(c);
0044 return 0;
0045 }
0046 };
0047 if ( detector.isValid() ) {
0048 Condition::detkey_type det_key = detector.key();
0049 Condition::key_type low = ConditionKey::KeyMaker(det_key,lower).hash;
0050 Condition::key_type up = ConditionKey::KeyMaker(det_key,upper).hash;
0051 Scanner scn(low,up,processor);
0052 this->scan(scn);
0053 return;
0054 }
0055 dd4hep::except("ConditionsMap","Cannot scan conditions map for conditions of an invalid detector element!");
0056 }
0057
0058
0059 std::vector<Condition> ConditionsMap::get(DetElement detector,
0060 Condition::itemkey_type lower,
0061 Condition::itemkey_type upper) const {
0062
0063
0064
0065
0066
0067
0068 struct Scanner : public Condition::Processor {
0069 Condition::key_type lower, upper;
0070 std::vector<Condition>& result;
0071
0072 Scanner(Condition::key_type low, Condition::key_type up, std::vector<Condition>& r) : lower(low), upper(up), result(r) {}
0073
0074 virtual int process(Condition c) const override {
0075 Condition::key_type h = c->hash;
0076 if ( h >= lower && h <= upper ) {
0077 result.emplace_back(c);
0078 return 1;
0079 }
0080 return 0;
0081 }
0082 };
0083 std::vector<Condition> result;
0084 if ( detector.isValid() ) {
0085 Condition::detkey_type det_key = detector.key();
0086 Condition::key_type low = ConditionKey::KeyMaker(det_key,lower).hash;
0087 Condition::key_type up = ConditionKey::KeyMaker(det_key,upper).hash;
0088 Scanner scn(low,up,result);
0089 this->scan(scn);
0090 return result;
0091 }
0092 dd4hep::except("ConditionsMap","Cannot scan conditions map for conditions of an invalid detector element!");
0093 return result;
0094 }
0095
0096
0097 template <typename T>
0098 bool ConditionsMapping<T>::insert(DetElement detector, Condition::itemkey_type key, Condition condition) {
0099 auto res = data.emplace(ConditionKey(detector,key).hash,condition);
0100 return res.second;
0101 }
0102
0103
0104 template <typename T>
0105 Condition ConditionsMapping<T>::get(DetElement detector, Condition::itemkey_type key) const {
0106 auto res = data.find(ConditionKey(detector,key).hash);
0107 return (res == data.end()) ? Condition() : res->second;
0108 }
0109
0110
0111 template <typename T>
0112 void ConditionsMapping<T>::scan(const Condition::Processor& processor) const {
0113 for( const auto& i : data )
0114 processor(i);
0115 }
0116
0117
0118 template <typename T>
0119 void ConditionsMapping<T>::scan(DetElement detector,
0120 Condition::itemkey_type lower,
0121 Condition::itemkey_type upper,
0122 const Condition::Processor& processor) const {
0123 if ( detector.isValid() ) {
0124 Condition::detkey_type det_key = detector.key();
0125 Condition::key_type low = ConditionKey::KeyMaker(det_key,lower).hash;
0126 Condition::key_type up = ConditionKey::KeyMaker(det_key,upper).hash;
0127 typename T::const_iterator first = data.lower_bound(low);
0128 for(; first != data.end() && (*first).first <= up; ++first )
0129 processor((*first).second);
0130 return;
0131 }
0132 dd4hep::except("ConditionsMap","Cannot scan conditions map for conditions of an invalid detector element!");
0133 }
0134
0135
0136
0137 namespace dd4hep {
0138
0139
0140 template <>
0141 bool ConditionsMapping<std::multimap<Condition::key_type,Condition> >
0142 ::insert(DetElement detector, Condition::itemkey_type key, Condition condition) {
0143 data.emplace(ConditionKey(detector,key).hash,condition);
0144 return true;
0145 }
0146
0147
0148 template <>
0149 void ConditionsMapping<std::unordered_map<Condition::key_type,Condition> >
0150 ::scan(DetElement detector, Condition::itemkey_type lower,
0151 Condition::itemkey_type upper,
0152 const Condition::Processor& proc) const
0153 {
0154 this->ConditionsMap::scan(detector, lower, upper, proc);
0155 }
0156
0157
0158 template class ConditionsMapping<std::map<Condition::key_type,Condition> >;
0159 template class ConditionsMapping<std::multimap<Condition::key_type,Condition> >;
0160 template class ConditionsMapping<std::unordered_map<Condition::key_type,Condition> >;
0161 }