DD4hep  1.30.0
Detector Description Toolkit for High Energy Physics
ConditionsIOVPool.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 
14 // Framework include files
15 #include <DD4hep/Printout.h>
16 #include <DD4hep/InstanceCount.h>
20 
22 
23 using namespace dd4hep::cond;
24 
28 }
29 
32  try {
33  clean(-1);
34  }
35  catch(const std::exception& e) {
36  printout(ERROR,"ConditionsIOVPool","+++ Unexpected exception in destructor(ConditionsIOVPool): %s",e.what());
37  }
39 }
40 
42 {
43  if ( !elements.empty() ) {
44  size_t len = result.size();
45  const IOV::Key req_key = req_validity.key(); // 16 bytes => better copy!
46  for( const auto& e : elements ) {
47  if ( IOV::key_contains_range(e.first, req_key) ) {
48  e.second->select(key, result);
49  }
50  }
51  return result.size() - len;
52  }
53  return 0;
54 }
55 
57 {
58  size_t len = result.size();
59  const IOV::Key range = req_validity.key();
60  for( const auto& e : elements ) {
61  const IOV::Key& k = e.first;
62  if ( IOV::key_is_contained(k,range) )
63  // IOV test contained in key. Take it!
64  e.second->select(key, result);
65  else if ( IOV::key_overlaps_lower_end(k,range) )
66  // IOV overlap on test on the lower end of key
67  e.second->select(key, result);
68  else if ( IOV::key_overlaps_higher_end(k,range) )
69  // IOV overlap of test on the higher end of key
70  e.second->select(key, result);
71  }
72  return result.size() - len;
73 }
74 
77  Elements rest;
78  int count = 0;
79  for( const auto& e : elements ) {
80  const ConditionsPool* p = e.second.get();
81  if ( cleaner (*p) ) {
82  count += e.second->size();
83  e.second->print("Remove");
84  continue;
85  }
86  rest.insert(e);
87  }
88  elements = std::move(rest);
89  return count;
90 }
91 
93 int ConditionsIOVPool::clean(int max_age) {
94  Elements rest;
95  int count = 0;
96  for( const auto& e : elements ) {
97  if ( e.second->age_value >= max_age ) {
98  count += e.second->size();
99  e.second->print("Remove");
100  }
101  else {
102  rest.insert(e);
103  }
104  }
105  elements = std::move(rest);
106  return count;
107 }
108 
110 size_t ConditionsIOVPool::select(const IOV& req_validity,
112  IOV& cond_validity)
113 {
114  size_t num_selected = 0;
115  if ( !elements.empty() ) {
116  const IOV::Key req_key = req_validity.key(); // 16 bytes => better copy!
117  for( const auto& i : elements ) {
118  if ( !IOV::key_contains_range(i.first, req_key) ) {
119  ++i.second->age_value;
120  continue;
121  }
122  cond_validity.iov_intersection(i.first);
123  num_selected += i.second->select_all(valid);
124  i.second->age_value = 0;
125  }
126  }
127  return num_selected;
128 }
129 
131 size_t ConditionsIOVPool::select(const IOV& req_validity,
132  const ConditionsSelect& predicate_processor,
133  IOV& cond_validity)
134 {
135  size_t num_selected = 0, pool_selected = 0;
136  if ( !elements.empty() ) {
137  const IOV::Key req_key = req_validity.key(); // 16 bytes => better copy!
138  for( const auto& i : elements ) {
139  if ( !IOV::key_contains_range(i.first, req_key) ) {
140  ++i.second->age_value;
141  continue;
142  }
143  cond_validity.iov_intersection(i.first);
144  pool_selected = i.second->select_all(predicate_processor);
145  num_selected += pool_selected;
146  i.second->age_value = 0;
147  }
148  }
149  return num_selected;
150 }
151 
153 size_t ConditionsIOVPool::select(const IOV& req_validity,
154  Elements& valid,
155  IOV& cond_validity)
156 {
157  size_t num_selected = select(req_validity, valid);
158  cond_validity.invert().reset();
159  for( const auto& i : valid )
160  cond_validity.iov_intersection(*(i.second->iov));
161  return num_selected;
162 }
163 
165 size_t ConditionsIOVPool::select(const IOV& req_validity, Elements& valid)
166 {
167  size_t num_selected = 0;
168  if ( !elements.empty() ) {
169  const IOV::Key req_key = req_validity.key(); // 16 bytes => better copy!
170  for( const auto& i : elements ) {
171  if ( !IOV::key_contains_range(i.first, req_key) ) {
172  continue;
173  }
174  valid[i.first] = i.second;
175  ++num_selected;
176  }
177  }
178  return num_selected;
179 }
180 
182 size_t ConditionsIOVPool::select(const IOV& req_validity,
183  std::vector<Element>& valid,
184  IOV& cond_validity)
185 {
186  size_t num_selected = select(req_validity, valid);
187  cond_validity.invert().reset();
188  for( const auto& i : valid )
189  cond_validity.iov_intersection(*(i->iov));
190  return num_selected;
191 }
192 
194 size_t ConditionsIOVPool::select(const IOV& req_validity, std::vector<Element>& valid)
195 {
196  size_t num_selected = 0;
197  if ( !elements.empty() ) {
198  const IOV::Key req_key = req_validity.key(); // 16 bytes => better copy!
199  for( const auto& i : elements ) {
200  if ( !IOV::key_contains_range(i.first, req_key) ) {
201  continue;
202  }
203  valid.emplace_back(i.second);
204  ++num_selected;
205  }
206  }
207  return num_selected;
208 }
dd4hep::IOV::iov_intersection
void iov_intersection(const IOV &comparator)
Set the intersection of this IOV with the argument IOV.
Definition: IOV.cpp:99
dd4hep::RangeConditions
std::vector< Condition > RangeConditions
Definition: Conditions.h:491
dd4hep::cond::ConditionsIOVPool::ConditionsIOVPool
ConditionsIOVPool(const IOVType *type)
Not ROOT persistent.
Definition: ConditionsIOVPool.cpp:26
ConditionsCleanup.h
ConditionsInterna.h
dd4hep::exception
void exception(const std::string &src, const std::string &msg)
Definition: RootDictionary.h:69
dd4hep::cond::ConditionsIOVPool::Elements
std::map< IOV::Key, Element > Elements
Shortcut name for the actual conditions container.
Definition: ConditionsIOVPool.h:43
dd4hep::IOV::invert
IOV & invert()
Invert the key values (first=second and second=first)
Definition: IOV.cpp:92
ConditionsDataLoader.h
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::ConditionsIOVPool::elements
Elements elements
Container of IOV dependent conditions pools.
Definition: ConditionsIOVPool.h:46
dd4hep::cond::ConditionsIOVPool::clean
int clean(int max_age)
Remove all key based pools with an age beyon the minimum age.
Definition: ConditionsIOVPool.cpp:93
dd4hep::ConditionsSelect
Conditions selector functor. Default implementation selects everything evaluated.
Definition: Conditions.h:422
dd4hep::IOVType
Class describing the interval of validty type.
Definition: IOV.h:37
dd4hep::cond
Namespace for implementation details of the AIDA detector description toolkit.
Definition: ConditionsCleanup.h:23
dd4hep::IOV
Class describing the interval of validty.
Definition: IOV.h:67
dd4hep::cond::ConditionsIOVPool::~ConditionsIOVPool
virtual ~ConditionsIOVPool()
Default destructor.
Definition: ConditionsIOVPool.cpp:31
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::InstanceCount::decrement
static void decrement(T *)
Decrement count according to type information.
Definition: InstanceCount.h:102
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::ConditionsIOVPool::select
size_t select(Condition::key_type key, const IOV &req_validity, RangeConditions &result)
Retrieve a condition set given the key according to their validity.
Definition: ConditionsIOVPool.cpp:41
dd4hep::cond::ConditionsPool::size
virtual size_t size() const =0
Total entry count.
ConditionsIOVPool.h
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::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
key
unsigned char key
Definition: AlignmentsCalculator.cpp:69
dd4hep::cond::ConditionsCleanup
Base class to handle conditions cleanups.
Definition: ConditionsCleanup.h:32
dd4hep::IOV::reset
IOV & reset()
Set keys to unphysical values (LONG_MAX, LONG_MIN)
Definition: IOV.cpp:85
InstanceCount.h
dd4hep::IOV::key_contains_range
static bool key_contains_range(const Key &key, const Key &test)
Same as above, but reverse logic. Gives sometimes more understandable logic.
Definition: IOV.h:156
valid
unsigned char valid
Definition: AlignmentsCalculator.cpp:69
Printout.h
dd4hep::cond::ConditionsIOVPool::selectRange
size_t selectRange(Condition::key_type key, const IOV &req_validity, RangeConditions &result)
Retrieve a condition set given the key according to their validity.
Definition: ConditionsIOVPool.cpp:56