DD4hep - The AIDA detector description toolkit for high energy physics experiments
DD4hep  Rev:Unversioneddirectory
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
IOV.h
Go to the documentation of this file.
1 //==========================================================================
2 // AIDA Detector description implementation for LCD
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_CONDITIONS_IOV_H
14 #define DD4HEP_CONDITIONS_IOV_H
15 
16 // C/C++ include files
17 #include <string>
18 #include <algorithm>
19 
21 namespace DD4hep {
22 
23  class IOVType;
24  class IOV;
25 
27 
33  class IOVType {
34  public:
35  enum { UNKNOWN_IOV = ~0x0 } _IOVTypes;
37  unsigned int type = UNKNOWN_IOV;
39  std::string name;
41  IOVType() = default;
43  ~IOVType() = default;
45  IOVType(const IOVType& copy) : type(copy.type), name(copy.name) {}
47  IOVType& operator=(const IOVType& copy);
49  std::string str() const;
50  };
51 
53 
59  class IOV {
60  private:
62  explicit IOV() = delete;
63  public:
65  typedef long Key_first_type;
66  typedef long Key_second_type;
67  typedef std::pair<Key_first_type,Key_second_type> Key;
68 
69  const IOVType* iovType;
71  int optData;
73  unsigned int type;
74 
76  explicit IOV(const IOVType* typ);
78  explicit IOV(const IOVType* typ, const Key& key);
80  IOV(const IOV& copy) = default;
82  ~IOV() = default;
84  IOV& operator=(const IOV& c) = default;
86  void move(IOV& from);
88  std::string str() const;
90  bool has_range() const { return keyData.first != keyData.second; }
92  bool is_discrete() const { return keyData.first == keyData.second; }
94  Key key() const { return keyData; }
95 
97  void set(const Key& value);
99  void set(Key_first_type value);
101  void set(Key_first_type val_1, Key_second_type val_2);
103  IOV& reset();
105  IOV& invert();
107  void iov_intersection(const IOV& comparator);
109  void iov_intersection(const IOV::Key& comparator);
111  void iov_union(const IOV& comparator);
113  void iov_union(const IOV::Key& comparator);
114 
116 
119  bool contains(const IOV& iov) const;
121  static bool same_type(const IOV& iov, const IOV& test) {
122  unsigned int typ1 = iov.iovType ? iov.iovType->type : iov.type;
123  unsigned int typ2 = test.iovType ? test.iovType->type : test.type;
124  return typ1 == typ2;
125  }
127  static bool key_is_contained(const Key& key, const Key& test)
128  { return key.first >= test.first && key.second <= test.second; }
130  static bool key_contains_range(const Key& key, const Key& test)
131  { return key.first <= test.first && key.second >= test.second; }
133  static bool key_overlaps_lower_end(const Key& key, const Key& test)
134  { return key.first <= test.second && key.first >= test.first; }
136  static bool key_overlaps_higher_end(const Key& key, const Key& test)
137  { return key.second >= test.first && key.second <= test.second; }
139  static bool key_partially_contained(const Key& key, const Key& test)
140  {
141  return
142  (test.first <= key.first && key.second >= test.second) || // test fully contained in key
143  (test.first <= key.first && key.first <= test.second) || // test overlaps left edge of key
144  (test.first <= key.second && key.second <= test.second); // test overlaps right edge of key
145  }
147  static bool full_match(const IOV& iov, const IOV& test)
148  { return same_type(iov,test) && key_is_contained(iov.keyData,test.keyData); }
150  static bool partial_match(const IOV& iov, const IOV& test)
151  { return same_type(iov,test) && key_partially_contained(iov.keyData,test.keyData); }
152  };
153 
154 } /* End namespace DD4hep */
155 #endif /* DD4HEP_CONDITIONS_IOV_H */
std::string str() const
Conversion to string.
Definition: IOV.cpp:36
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:147
IOVType()=default
Standard Constructor.
int optData
Definition: IOV.h:71
void set(const Key &value)
Set discrete IOV value.
Definition: IOV.cpp:55
bool has_range() const
Check if the IOV corresponds to a range.
Definition: IOV.h:90
bool contains(const IOV &iov) const
Check for validity containment.
Definition: IOV.cpp:156
IOVType(const IOVType &copy)
Copy constructor.
Definition: IOV.h:45
void copy(Alignment from, Alignment to)
Copy alignment object from source object.
Key key() const
Get the local key of the IOV.
Definition: IOV.h:94
void iov_intersection(const IOV &comparator)
Set the intersection of this IOV with the argument IOV.
Definition: IOV.cpp:85
std::string name
String name.
Definition: IOV.h:39
const IOVType * iovType
Definition: IOV.h:69
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:139
Class describing the interval of validty.
Definition: IOV.h:59
IOV & invert()
Invert the key values (first=second and second=first)
Definition: IOV.cpp:78
Key keyData
Definition: IOV.h:70
Class describing the interval of validty type.
Definition: IOV.h:33
IOV & operator=(const IOV &c)=default
Assignment operator.
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:130
IOV & reset()
Set keys to unphysical values (LONG_MAX, LONG_MIN)
Definition: IOV.cpp:71
unsigned int type
integer identifier ised internally
Definition: IOV.h:37
IOV()=delete
Initializing constructor: Does not set reference to IOVType !
static bool key_is_contained(const Key &key, const Key &test)
Check if IOV 'test' is fully contained in IOV 'key'.
Definition: IOV.h:127
~IOVType()=default
Standard Destructor.
IOVType & operator=(const IOVType &copy)
Assignment operator.
Definition: IOV.cpp:27
unsigned int type
IOV buffer type: Must be a bitmap!
Definition: IOV.h:73
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:133
static bool same_type(const IOV &iov, const IOV &test)
Check if 2 IOV objects are of the same type.
Definition: IOV.h:121
void move(IOV &from)
Move the data content: 'from' will be reset to NULL.
Definition: IOV.cpp:118
long Key_first_type
Key definition.
Definition: IOV.h:65
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:136
long Key_second_type
Definition: IOV.h:66
~IOV()=default
Standard Destructor.
enum DD4hep::IOVType::@3 _IOVTypes
void iov_union(const IOV &comparator)
Set the union of this IOV with the argument IOV.
Definition: IOV.cpp:101
bool is_discrete() const
Check if the IOV corresponds to a range.
Definition: IOV.h:92
std::pair< Key_first_type, Key_second_type > Key
Definition: IOV.h:67
std::string str() const
Create string representation of the IOV.
Definition: IOV.cpp:126
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:150