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