File indexing completed on 2025-07-09 08:29:55
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #ifndef DD4HEP_IOV_H
0014 #define DD4HEP_IOV_H
0015
0016
0017 #include <string>
0018 #include <limits>
0019 #include <utility>
0020 #include <cstdint>
0021
0022
0023 namespace dd4hep {
0024
0025
0026 class IOVType;
0027 class IOV;
0028
0029
0030
0031
0032
0033
0034
0035
0036 class IOVType {
0037 public:
0038 static constexpr unsigned int UNKNOWN_IOV = ~0x0;
0039
0040 unsigned int type = UNKNOWN_IOV;
0041
0042 std::string name;
0043
0044 IOVType() = default;
0045
0046 ~IOVType() = default;
0047
0048 IOVType(const IOVType& copy) = default;
0049
0050 IOVType(IOVType&& copy) = default;
0051
0052 IOVType& operator=(const IOVType& copy) = default;
0053
0054 IOVType& operator=(IOVType&& copy) = default;
0055
0056 std::string str() const;
0057 };
0058
0059
0060
0061
0062
0063
0064
0065
0066 class IOV {
0067 private:
0068
0069 explicit IOV() = delete;
0070 public:
0071
0072 using Key_value_type = std::int64_t;
0073 using Key = std::pair<Key_value_type, Key_value_type>;
0074
0075 static constexpr Key_value_type MIN_KEY = std::numeric_limits<Key_value_type>::min();
0076 static constexpr Key_value_type MAX_KEY = std::numeric_limits<Key_value_type>::max();
0077
0078
0079 const IOVType* iovType = 0;
0080
0081 Key keyData{MIN_KEY,MIN_KEY};
0082
0083 int optData = 0;
0084
0085 unsigned int type = IOVType::UNKNOWN_IOV;
0086
0087
0088 explicit IOV(const IOVType* typ);
0089
0090 explicit IOV(const IOVType* typ, const Key& key);
0091
0092 explicit IOV(const IOVType* typ, Key_value_type iov_value);
0093
0094 IOV(const IOV& copy) = default;
0095
0096 IOV(IOV&& copy) = default;
0097
0098 ~IOV() = default;
0099
0100 IOV& operator=(const IOV& c) = default;
0101
0102 IOV& operator=(IOV&& c) = default;
0103
0104 bool operator<(const IOV& test) const;
0105
0106 void move(IOV& from);
0107
0108 std::string str() const;
0109
0110 bool has_range() const { return keyData.first != keyData.second; }
0111
0112 bool is_discrete() const { return keyData.first == keyData.second; }
0113
0114 Key key() const { return keyData; }
0115
0116 void set(const Key& value);
0117
0118 void set(Key_value_type value);
0119
0120 void set(Key_value_type val_1, Key_value_type val_2);
0121
0122 IOV& reset();
0123
0124 IOV& invert();
0125
0126 void iov_intersection(const IOV& comparator);
0127
0128 void iov_intersection(const IOV::Key& comparator);
0129
0130 void iov_union(const IOV& comparator);
0131
0132 void iov_union(const IOV::Key& comparator);
0133
0134
0135
0136
0137
0138 bool contains(const IOV& iov) const;
0139
0140 static IOV forever(const IOVType* typ)
0141 { return IOV(typ, Key(MIN_KEY, MAX_KEY)); }
0142
0143 static Key key_forever()
0144 { return Key(MIN_KEY, MAX_KEY); }
0145
0146 static bool same_type(const IOV& iov, const IOV& test) {
0147 unsigned int typ1 = iov.iovType ? iov.iovType->type : iov.type;
0148 unsigned int typ2 = test.iovType ? test.iovType->type : test.type;
0149 return typ1 == typ2;
0150 }
0151
0152 static bool key_is_contained(const Key& key, const Key& test)
0153 { return key.first >= test.first && key.second <= test.second; }
0154
0155 static bool key_contains_range(const Key& key, const Key& test)
0156 { return key.first <= test.first && key.second >= test.second; }
0157
0158 static bool key_overlaps_lower_end(const Key& key, const Key& test)
0159 { return key.first <= test.second && key.first >= test.first; }
0160
0161 static bool key_overlaps_higher_end(const Key& key, const Key& test)
0162 { return key.second >= test.first && key.second <= test.second; }
0163
0164 static bool key_partially_contained(const Key& key, const Key& test)
0165 {
0166 return
0167 (test.first <= key.first && key.second >= test.second) ||
0168 (test.first <= key.first && key.first <= test.second) ||
0169 (test.first <= key.second && key.second <= test.second);
0170 }
0171
0172 static bool full_match(const IOV& iov, const IOV& test)
0173 { return same_type(iov,test) && key_is_contained(iov.keyData,test.keyData); }
0174
0175 static bool partial_match(const IOV& iov, const IOV& test)
0176 { return same_type(iov,test) && key_partially_contained(iov.keyData,test.keyData); }
0177 };
0178
0179
0180 inline bool IOV::operator<(const IOV& test) const {
0181 if ( type > test.type ) return false;
0182 if ( keyData.first > test.keyData.first ) return false;
0183 if ( keyData.second > test.keyData.second ) return false;
0184 return true;
0185 }
0186
0187 }
0188 #endif