DD4hep  1.30.0
Detector Description Toolkit for High Energy Physics
IOV.h
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 #ifndef DD4HEP_IOV_H
14 #define DD4HEP_IOV_H
15 
16 // C/C++ include files
17 #include <string>
18 #include <limits>
19 #include <algorithm>
20 #include <utility>
21 #include <cstdint>
22 
24 namespace dd4hep {
25 
26  // Forward declarations
27  class IOVType;
28  class IOV;
29 
31 
37  class IOVType {
38  public:
39  static constexpr unsigned int UNKNOWN_IOV = ~0x0;
41  unsigned int type = UNKNOWN_IOV;
43  std::string name;
45  IOVType() = default;
47  ~IOVType() = default;
49  IOVType(const IOVType& copy) = default; //: type(copy.type), name(copy.name) {}
51  IOVType(IOVType&& copy) = default;
53  IOVType& operator=(const IOVType& copy) = default;
55  IOVType& operator=(IOVType&& copy) = default;
57  std::string str() const;
58  };
59 
61 
67  class IOV {
68  private:
70  explicit IOV() = delete;
71  public:
73  using Key_value_type = std::int64_t;
74  using Key = std::pair<Key_value_type, Key_value_type>;
75 
76  static constexpr Key_value_type MIN_KEY = std::numeric_limits<Key_value_type>::min();
77  static constexpr Key_value_type MAX_KEY = std::numeric_limits<Key_value_type>::max();
78 
80  const IOVType* iovType = 0;
84  int optData = 0;
86  unsigned int type = IOVType::UNKNOWN_IOV;
87 
89  explicit IOV(const IOVType* typ);
91  explicit IOV(const IOVType* typ, const Key& key);
93  explicit IOV(const IOVType* typ, Key_value_type iov_value);
95  IOV(const IOV& copy) = default;
97  IOV(IOV&& copy) = default;
99  ~IOV() = default;
101  IOV& operator=(const IOV& c) = default;
103  IOV& operator=(IOV&& c) = default;
105  bool operator<(const IOV& test) const;
107  void move(IOV& from);
109  std::string str() const;
111  bool has_range() const { return keyData.first != keyData.second; }
113  bool is_discrete() const { return keyData.first == keyData.second; }
115  Key key() const { return keyData; }
117  void set(const Key& value);
119  void set(Key_value_type value);
121  void set(Key_value_type val_1, Key_value_type val_2);
123  IOV& reset();
125  IOV& invert();
127  void iov_intersection(const IOV& comparator);
129  void iov_intersection(const IOV::Key& comparator);
131  void iov_union(const IOV& comparator);
133  void iov_union(const IOV::Key& comparator);
134 
136 
139  bool contains(const IOV& iov) const;
141  static IOV forever(const IOVType* typ)
142  { return IOV(typ, Key(MIN_KEY, MAX_KEY)); }
144  static Key key_forever()
145  { return Key(MIN_KEY, MAX_KEY); }
147  static bool same_type(const IOV& iov, const IOV& test) {
148  unsigned int typ1 = iov.iovType ? iov.iovType->type : iov.type;
149  unsigned int typ2 = test.iovType ? test.iovType->type : test.type;
150  return typ1 == typ2;
151  }
153  static bool key_is_contained(const Key& key, const Key& test)
154  { return key.first >= test.first && key.second <= test.second; }
156  static bool key_contains_range(const Key& key, const Key& test)
157  { return key.first <= test.first && key.second >= test.second; }
159  static bool key_overlaps_lower_end(const Key& key, const Key& test)
160  { return key.first <= test.second && key.first >= test.first; }
162  static bool key_overlaps_higher_end(const Key& key, const Key& test)
163  { return key.second >= test.first && key.second <= test.second; }
165  static bool key_partially_contained(const Key& key, const Key& test)
166  {
167  return
168  (test.first <= key.first && key.second >= test.second) || // test fully contained in key
169  (test.first <= key.first && key.first <= test.second) || // test overlaps left edge of key
170  (test.first <= key.second && key.second <= test.second); // test overlaps right edge of key
171  }
173  static bool full_match(const IOV& iov, const IOV& test)
174  { return same_type(iov,test) && key_is_contained(iov.keyData,test.keyData); }
176  static bool partial_match(const IOV& iov, const IOV& test)
177  { return same_type(iov,test) && key_partially_contained(iov.keyData,test.keyData); }
178  };
179 
181  inline bool IOV::operator<(const IOV& test) const {
182  if ( type > test.type ) return false; // Actually this should never happen!
183  if ( keyData.first > test.keyData.first ) return false;
184  if ( keyData.second > test.keyData.second ) return false;
185  return true;
186  }
187 
188 } /* End namespace dd4hep */
189 #endif // DD4HEP_IOV_H
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::IOVType::operator=
IOVType & operator=(IOVType &&copy)=default
Move assignment operator.
dd4hep::IOV::contains
bool contains(const IOV &iov) const
Check for validity containment.
Definition: IOV.cpp:180
dd4hep::IOVType::name
std::string name
String name.
Definition: IOV.h:43
dd4hep::IOV::key_partially_contained
static bool key_partially_contained(const Key &key, const Key &test)
Check if IOV 'test' has an overlap on the upper interval edge with IOV 'key'.
Definition: IOV.h:165
dd4hep::IOV::optData
int optData
Optional user data.
Definition: IOV.h:84
dd4hep::IOV::IOV
IOV(IOV &&copy)=default
Move constructor.
dd4hep::IOV::~IOV
~IOV()=default
Standard Destructor.
dd4hep::IOV::invert
IOV & invert()
Invert the key values (first=second and second=first)
Definition: IOV.cpp:92
dd4hep::IOV::Key_value_type
std::int64_t Key_value_type
Key definition. Use fixed width type, though not portable!
Definition: IOV.h:73
dd4hep::IOVType::UNKNOWN_IOV
static constexpr unsigned int UNKNOWN_IOV
Definition: IOV.h:39
dd4hep::IOV::forever
static IOV forever(const IOVType *typ)
Conditions key representing eternity.
Definition: IOV.h:141
dd4hep::IOVType::str
std::string str() const
Conversion to string.
Definition: IOV.cpp:43
dd4hep::IOV::str
std::string str() const
Create string representation of the IOV.
Definition: IOV.cpp:141
dd4hep::IOV::Key
std::pair< Key_value_type, Key_value_type > Key
Definition: IOV.h:74
dd4hep::IOVType::IOVType
IOVType(const IOVType &copy)=default
Copy constructor.
dd4hep::IOV::key_forever
static Key key_forever()
Conditions key representing eternity.
Definition: IOV.h:144
dd4hep::IOVType
Class describing the interval of validty type.
Definition: IOV.h:37
dd4hep::IOV::IOV
IOV()=delete
Initializing constructor: Does not set reference to IOVType !
dd4hep::IOV::set
void set(Key_value_type val_1, Key_value_type val_2)
Set range IOV value.
dd4hep::IOV
Class describing the interval of validty.
Definition: IOV.h:67
dd4hep::IOV::move
void move(IOV &from)
Move the data content: 'from' will be reset to NULL.
Definition: IOV.cpp:132
dd4hep::IOVType::operator=
IOVType & operator=(const IOVType &copy)=default
Assignment operator.
dd4hep::IOV::set
void set(const Key &value)
Set discrete IOV value.
Definition: IOV.cpp:69
dd4hep::IOV::is_discrete
bool is_discrete() const
Check if the IOV corresponds to a range.
Definition: IOV.h:113
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::IOV::keyData
Key keyData
IOV key (if second==first, discrete, otherwise range)
Definition: IOV.h:82
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::IOV::has_range
bool has_range() const
Check if the IOV corresponds to a range.
Definition: IOV.h:111
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::partial_match
static bool partial_match(const IOV &iov, const IOV &test)
Check if IOV 'test' is of same type and is at least partially contained in iov.
Definition: IOV.h:176
dd4hep::IOV::key
Key key() const
Get the local key of the IOV.
Definition: IOV.h:115
dd4hep::IOVType::IOVType
IOVType(IOVType &&copy)=default
Move constructor.
dd4hep::IOV::type
unsigned int type
IOV buffer type: Must be a bitmap!
Definition: IOV.h:86
dd4hep::IOVType::IOVType
IOVType()=default
Standard Constructor.
dd4hep::IOV::MIN_KEY
static constexpr Key_value_type MIN_KEY
Definition: IOV.h:76
dd4hep::IOVType::~IOVType
~IOVType()=default
Standard Destructor.
dd4hep::IOV::iov_union
void iov_union(const IOV &comparator)
Set the union of this IOV with the argument IOV.
Definition: IOV.cpp:115
dd4hep::IOV::operator=
IOV & operator=(const IOV &c)=default
Assignment operator.
dd4hep::IOV::operator<
bool operator<(const IOV &test) const
Allow for IOV sorting in maps.
Definition: IOV.h:181
dd4hep::IOV::full_match
static bool full_match(const IOV &iov, const IOV &test)
Check if IOV 'test' is of same type and is fully contained in iov.
Definition: IOV.h:173
dd4hep::IOV::reset
IOV & reset()
Set keys to unphysical values (LONG_MAX, LONG_MIN)
Definition: IOV.cpp:85
dd4hep::IOV::iovType
const IOVType * iovType
Reference to IOV type.
Definition: IOV.h:80
dd4hep
Namespace for the AIDA detector description toolkit.
Definition: AlignmentsCalib.h:28
dd4hep::IOV::IOV
IOV(const IOV &copy)=default
Copy constructor.
dd4hep::detail::tools::copy
void copy(Alignment from, Alignment to)
Copy alignment object from source object.
Definition: AlignmentTools.cpp:43
dd4hep::IOV::operator=
IOV & operator=(IOV &&c)=default
Move assignment operator.
dd4hep::IOV::MAX_KEY
static constexpr Key_value_type MAX_KEY
Definition: IOV.h:77
dd4hep::IOVType::type
unsigned int type
integer identifier used internally
Definition: IOV.h:41
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
dd4hep::IOV::same_type
static bool same_type(const IOV &iov, const IOV &test)
Check if 2 IOV objects are of the same type.
Definition: IOV.h:147
dd4hep::IOV::set
void set(Key_value_type value)
Set discrete IOV value.