File indexing completed on 2025-01-18 09:13:29
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #include <DD4hep/Printout.h>
0016 #include <DD4hep/InstanceCount.h>
0017 #include <DDCond/ConditionsIOVPool.h>
0018 #include <DDCond/ConditionsCleanup.h>
0019 #include <DDCond/ConditionsDataLoader.h>
0020
0021 #include <DD4hep/detail/ConditionsInterna.h>
0022
0023 using namespace dd4hep::cond;
0024
0025
0026 ConditionsIOVPool::ConditionsIOVPool(const IOVType* typ) : type(typ) {
0027 InstanceCount::increment(this);
0028 }
0029
0030
0031 ConditionsIOVPool::~ConditionsIOVPool() {
0032 try {
0033 clean(-1);
0034 }
0035 catch(const std::exception& e) {
0036 printout(ERROR,"ConditionsIOVPool","+++ Unexpected exception in destructor(ConditionsIOVPool): %s",e.what());
0037 }
0038 InstanceCount::decrement(this);
0039 }
0040
0041 size_t ConditionsIOVPool::select(Condition::key_type key, const IOV& req_validity, RangeConditions& result)
0042 {
0043 if ( !elements.empty() ) {
0044 size_t len = result.size();
0045 const IOV::Key req_key = req_validity.key();
0046 for( const auto& e : elements ) {
0047 if ( IOV::key_contains_range(e.first, req_key) ) {
0048 e.second->select(key, result);
0049 }
0050 }
0051 return result.size() - len;
0052 }
0053 return 0;
0054 }
0055
0056 size_t ConditionsIOVPool::selectRange(Condition::key_type key, const IOV& req_validity, RangeConditions& result)
0057 {
0058 size_t len = result.size();
0059 const IOV::Key range = req_validity.key();
0060 for( const auto& e : elements ) {
0061 const IOV::Key& k = e.first;
0062 if ( IOV::key_is_contained(k,range) )
0063
0064 e.second->select(key, result);
0065 else if ( IOV::key_overlaps_lower_end(k,range) )
0066
0067 e.second->select(key, result);
0068 else if ( IOV::key_overlaps_higher_end(k,range) )
0069
0070 e.second->select(key, result);
0071 }
0072 return result.size() - len;
0073 }
0074
0075
0076 int ConditionsIOVPool::clean(const ConditionsCleanup& cleaner) {
0077 Elements rest;
0078 int count = 0;
0079 for( const auto& e : elements ) {
0080 const ConditionsPool* p = e.second.get();
0081 if ( cleaner (*p) ) {
0082 count += e.second->size();
0083 e.second->print("Remove");
0084 continue;
0085 }
0086 rest.insert(e);
0087 }
0088 elements = std::move(rest);
0089 return count;
0090 }
0091
0092
0093 int ConditionsIOVPool::clean(int max_age) {
0094 Elements rest;
0095 int count = 0;
0096 for( const auto& e : elements ) {
0097 if ( e.second->age_value >= max_age ) {
0098 count += e.second->size();
0099 e.second->print("Remove");
0100 }
0101 else {
0102 rest.insert(e);
0103 }
0104 }
0105 elements = std::move(rest);
0106 return count;
0107 }
0108
0109
0110 size_t ConditionsIOVPool::select(const IOV& req_validity,
0111 RangeConditions& valid,
0112 IOV& cond_validity)
0113 {
0114 size_t num_selected = 0;
0115 if ( !elements.empty() ) {
0116 const IOV::Key req_key = req_validity.key();
0117 for( const auto& i : elements ) {
0118 if ( !IOV::key_contains_range(i.first, req_key) ) {
0119 ++i.second->age_value;
0120 continue;
0121 }
0122 cond_validity.iov_intersection(i.first);
0123 num_selected += i.second->select_all(valid);
0124 i.second->age_value = 0;
0125 }
0126 }
0127 return num_selected;
0128 }
0129
0130
0131 size_t ConditionsIOVPool::select(const IOV& req_validity,
0132 const ConditionsSelect& predicate_processor,
0133 IOV& cond_validity)
0134 {
0135 size_t num_selected = 0, pool_selected = 0;
0136 if ( !elements.empty() ) {
0137 const IOV::Key req_key = req_validity.key();
0138 for( const auto& i : elements ) {
0139 if ( !IOV::key_contains_range(i.first, req_key) ) {
0140 ++i.second->age_value;
0141 continue;
0142 }
0143 cond_validity.iov_intersection(i.first);
0144 pool_selected = i.second->select_all(predicate_processor);
0145 num_selected += pool_selected;
0146 i.second->age_value = 0;
0147 }
0148 }
0149 return num_selected;
0150 }
0151
0152
0153 size_t ConditionsIOVPool::select(const IOV& req_validity,
0154 Elements& valid,
0155 IOV& cond_validity)
0156 {
0157 size_t num_selected = select(req_validity, valid);
0158 cond_validity.invert().reset();
0159 for( const auto& i : valid )
0160 cond_validity.iov_intersection(*(i.second->iov));
0161 return num_selected;
0162 }
0163
0164
0165 size_t ConditionsIOVPool::select(const IOV& req_validity, Elements& valid)
0166 {
0167 size_t num_selected = 0;
0168 if ( !elements.empty() ) {
0169 const IOV::Key req_key = req_validity.key();
0170 for( const auto& i : elements ) {
0171 if ( !IOV::key_contains_range(i.first, req_key) ) {
0172 continue;
0173 }
0174 valid[i.first] = i.second;
0175 ++num_selected;
0176 }
0177 }
0178 return num_selected;
0179 }
0180
0181
0182 size_t ConditionsIOVPool::select(const IOV& req_validity,
0183 std::vector<Element>& valid,
0184 IOV& cond_validity)
0185 {
0186 size_t num_selected = select(req_validity, valid);
0187 cond_validity.invert().reset();
0188 for( const auto& i : valid )
0189 cond_validity.iov_intersection(*(i->iov));
0190 return num_selected;
0191 }
0192
0193
0194 size_t ConditionsIOVPool::select(const IOV& req_validity, std::vector<Element>& valid)
0195 {
0196 size_t num_selected = 0;
0197 if ( !elements.empty() ) {
0198 const IOV::Key req_key = req_validity.key();
0199 for( const auto& i : elements ) {
0200 if ( !IOV::key_contains_range(i.first, req_key) ) {
0201 continue;
0202 }
0203 valid.emplace_back(i.second);
0204 ++num_selected;
0205 }
0206 }
0207 return num_selected;
0208 }