File indexing completed on 2025-01-30 09:17:00
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #include <DD4hep/IOV.h>
0016 #include <DD4hep/Printout.h>
0017 #include <DD4hep/Primitives.h>
0018
0019
0020 #include <climits>
0021 #include <iomanip>
0022 #include <cstring>
0023
0024 using namespace dd4hep;
0025
0026 #if __cplusplus == 201402
0027 const IOV::Key_value_type IOV::MIN_KEY;
0028 const IOV::Key_value_type IOV::MAX_KEY;
0029 #endif
0030
0031 #if 0
0032
0033 IOVType& IOVType::operator=(const IOVType& copy) {
0034 if ( © != this ) {
0035 name = copy.name;
0036 type = copy.type;
0037 }
0038 return *this;
0039 }
0040 #endif
0041
0042
0043 std::string IOVType::str() const {
0044 char text[256];
0045 ::snprintf(text,sizeof(text),"%s(%d)",name.c_str(),int(type));
0046 return text;
0047 }
0048
0049
0050 IOV::IOV(const IOVType* t) : iovType(t) {
0051 if ( t ) type = t->type;
0052 }
0053
0054
0055 IOV::IOV(const IOVType* t, Key_value_type iov_value)
0056 : iovType(t), keyData(iov_value,iov_value)
0057 {
0058 if ( t ) type = t->type;
0059 }
0060
0061
0062 IOV::IOV(const IOVType* t, const Key& k)
0063 : iovType(t), keyData(k)
0064 {
0065 if ( t ) type = t->type;
0066 }
0067
0068
0069 void IOV::set(const Key& value) {
0070 keyData = value;
0071 }
0072
0073
0074 void IOV::set(Key::first_type value) {
0075 keyData.first = keyData.second = value;
0076 }
0077
0078
0079 void IOV::set(Key::first_type val_1, Key::second_type val_2) {
0080 keyData.first = val_1;
0081 keyData.second = val_2;
0082 }
0083
0084
0085 IOV& IOV::reset() {
0086 keyData.first = LONG_MAX;
0087 keyData.second = LONG_MIN;
0088 return *this;
0089 }
0090
0091
0092 IOV& IOV::invert() {
0093 Key::first_type tmp = keyData.first;
0094 keyData.first = keyData.second;
0095 keyData.second = tmp;
0096 return *this;
0097 }
0098
0099 void IOV::iov_intersection(const IOV& validity) {
0100 if ( !iovType )
0101 *this = validity;
0102 else if ( validity.keyData.first > keyData.first )
0103 keyData.first = validity.keyData.first;
0104 if ( validity.keyData.second < keyData.second )
0105 keyData.second = validity.keyData.second;
0106 }
0107
0108 void IOV::iov_intersection(const IOV::Key& validity) {
0109 if ( validity.first > keyData.first )
0110 keyData.first = validity.first;
0111 if ( validity.second < keyData.second )
0112 keyData.second = validity.second;
0113 }
0114
0115 void IOV::iov_union(const IOV& validity) {
0116 if ( !iovType )
0117 *this = validity;
0118 else if ( validity.keyData.first < keyData.first )
0119 keyData.first = validity.keyData.first;
0120 if ( validity.keyData.second > keyData.second )
0121 keyData.second = validity.keyData.second;
0122 }
0123
0124 void IOV::iov_union(const IOV::Key& validity) {
0125 if ( validity.first < keyData.first )
0126 keyData.first = validity.first;
0127 if ( validity.second > keyData.second )
0128 keyData.second = validity.second;
0129 }
0130
0131
0132 void IOV::move(IOV& from) {
0133
0134 *this = from;
0135 from.keyData.first = from.keyData.second = from.optData = 0;
0136 from.type = int(IOVType::UNKNOWN_IOV);
0137 from.iovType = 0;
0138 }
0139
0140
0141 std::string IOV::str() const {
0142 char text[256];
0143 if ( iovType ) {
0144
0145 if ( iovType->name[0] != 'e' ) {
0146 ::snprintf(text,sizeof(text),"%s(%u):[%ld-%ld]",
0147 iovType->name.c_str(), iovType->type, long(keyData.first), long(keyData.second));
0148 }
0149 else if ( iovType->name == "epoch" ) {
0150 struct tm time_buff;
0151 char c_since[64], c_until[64];
0152 static constexpr const Key_value_type nil = 0;
0153 static const Key_value_type max_time = detail::makeTime(2099,12,31,24,59,59);
0154 std::time_t since = std::min(std::max(keyData.first, nil), max_time);
0155 std::time_t until = std::min(std::max(keyData.second,nil), max_time);
0156 struct tm* tm_since = ::gmtime_r(&since,&time_buff);
0157 struct tm* tm_until = ::gmtime_r(&until,&time_buff);
0158 if ( nullptr == tm_since || nullptr == tm_until ) {
0159 except("IOV::str"," Invalid epoch time stamp: %d:[%ld-%ld]",
0160 type, long(keyData.first), long(keyData.second));
0161 }
0162 ::strftime(c_since,sizeof(c_since),"%d-%m-%Y %H:%M:%S", tm_since);
0163 ::strftime(c_until,sizeof(c_until),"%d-%m-%Y %H:%M:%S", tm_until);
0164 ::snprintf(text,sizeof(text),"%s(%u):[%s - %s]",
0165 iovType->name.c_str(), iovType->type,
0166 c_since, c_until);
0167 }
0168 else {
0169 ::snprintf(text,sizeof(text),"%s(%u):[%ld-%ld]",
0170 iovType->name.c_str(), iovType->type, long(keyData.first), long(keyData.second));
0171 }
0172 }
0173 else {
0174 ::snprintf(text,sizeof(text),"%u:[%ld-%ld]", type, long(keyData.first), long(keyData.second));
0175 }
0176 return text;
0177 }
0178
0179
0180 bool IOV::contains(const IOV& iov) const {
0181 if ( key_is_contained(iov.keyData,keyData) ) {
0182 unsigned int typ1 = iov.iovType ? iov.iovType->type : iov.type;
0183 unsigned int typ2 = iovType ? iovType->type : type;
0184 return typ1 == typ2;
0185 }
0186 return false;
0187 }