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