DD4hep  1.28.0
Detector Description Toolkit for High Energy Physics
IOV.cpp
Go to the documentation of this file.
1 //==========================================================================
2 // AIDA Detector description implementation
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 
14 // Framework includes
15 #include <DD4hep/IOV.h>
16 #include <DD4hep/Printout.h>
17 #include <DD4hep/Primitives.h>
18 
19 // C/C++ include files
20 #include <climits>
21 #include <iomanip>
22 #include <cstring>
23 
24 using namespace dd4hep;
25 
26 #if __cplusplus == 201402
29 #endif
30 
31 #if 0
34  if ( &copy != this ) {
35  name = copy.name;
36  type = copy.type;
37  }
38  return *this;
39 }
40 #endif
41 
43 std::string IOVType::str() const {
44  char text[256];
45  ::snprintf(text,sizeof(text),"%s(%d)",name.c_str(),int(type));
46  return text;
47 }
48 
50 IOV::IOV(const IOVType* t) : iovType(t) {
51  if ( t ) type = t->type;
52 }
53 
55 IOV::IOV(const IOVType* t, Key_value_type iov_value)
56  : iovType(t), keyData(iov_value,iov_value)
57 {
58  if ( t ) type = t->type;
59 }
60 
62 IOV::IOV(const IOVType* t, const Key& k)
63  : iovType(t), keyData(k)
64 {
65  if ( t ) type = t->type;
66 }
67 
69 void IOV::set(const Key& value) {
70  keyData = value;
71 }
72 
74 void IOV::set(Key::first_type value) {
75  keyData.first = keyData.second = value;
76 }
77 
79 void IOV::set(Key::first_type val_1, Key::second_type val_2) {
80  keyData.first = val_1;
81  keyData.second = val_2;
82 }
83 
86  keyData.first = LONG_MAX;
87  keyData.second = LONG_MIN;
88  return *this;
89 }
90 
93  Key::first_type tmp = keyData.first;
94  keyData.first = keyData.second;
95  keyData.second = tmp;
96  return *this;
97 }
98 
99 void IOV::iov_intersection(const IOV& validity) {
100  if ( !iovType )
101  *this = validity;
102  else if ( validity.keyData.first > keyData.first )
103  keyData.first = validity.keyData.first;
104  if ( validity.keyData.second < keyData.second )
105  keyData.second = validity.keyData.second;
106 }
107 
108 void IOV::iov_intersection(const IOV::Key& validity) {
109  if ( validity.first > keyData.first )
110  keyData.first = validity.first;
111  if ( validity.second < keyData.second )
112  keyData.second = validity.second;
113 }
114 
115 void IOV::iov_union(const IOV& validity) {
116  if ( !iovType )
117  *this = validity;
118  else if ( validity.keyData.first < keyData.first )
119  keyData.first = validity.keyData.first;
120  if ( validity.keyData.second > keyData.second )
121  keyData.second = validity.keyData.second;
122 }
123 
124 void IOV::iov_union(const IOV::Key& validity) {
125  if ( validity.first < keyData.first )
126  keyData.first = validity.first;
127  if ( validity.second > keyData.second )
128  keyData.second = validity.second;
129 }
130 
132 void IOV::move(IOV& from) {
133  //::memcpy(this,&from,sizeof(IOV));
134  *this = from;
135  from.keyData.first = from.keyData.second = from.optData = 0;
136  from.type = int(IOVType::UNKNOWN_IOV);
137  from.iovType = 0;
138 }
139 
141 std::string IOV::str() const {
142  char text[256];
143  if ( iovType ) {
145  if ( iovType->name[0] != 'e' ) {
146  ::snprintf(text,sizeof(text),"%s(%u):[%ld-%ld]",
147  iovType->name.c_str(), iovType->type, long(keyData.first), long(keyData.second));
148  }
149  else if ( iovType->name == "epoch" ) {
150  struct tm time_buff;
151  char c_since[64], c_until[64];
152  static constexpr const Key_value_type nil = 0;
153  static const Key_value_type max_time = detail::makeTime(2099,12,31,24,59,59);
154  std::time_t since = std::min(std::max(keyData.first, nil), max_time);
155  std::time_t until = std::min(std::max(keyData.second,nil), max_time);
156  struct tm* tm_since = ::gmtime_r(&since,&time_buff);
157  struct tm* tm_until = ::gmtime_r(&until,&time_buff);
158  if ( nullptr == tm_since || nullptr == tm_until ) {
159  except("IOV::str"," Invalid epoch time stamp: %d:[%ld-%ld]",
160  type, long(keyData.first), long(keyData.second));
161  }
162  ::strftime(c_since,sizeof(c_since),"%d-%m-%Y %H:%M:%S", tm_since);
163  ::strftime(c_until,sizeof(c_until),"%d-%m-%Y %H:%M:%S", tm_until);
164  ::snprintf(text,sizeof(text),"%s(%u):[%s - %s]",
165  iovType->name.c_str(), iovType->type,
166  c_since, c_until);
167  }
168  else {
169  ::snprintf(text,sizeof(text),"%s(%u):[%ld-%ld]",
170  iovType->name.c_str(), iovType->type, long(keyData.first), long(keyData.second));
171  }
172  }
173  else {
174  ::snprintf(text,sizeof(text),"%u:[%ld-%ld]", type, long(keyData.first), long(keyData.second));
175  }
176  return text;
177 }
178 
180 bool IOV::contains(const IOV& iov) const {
181  if ( key_is_contained(iov.keyData,keyData) ) {
182  unsigned int typ1 = iov.iovType ? iov.iovType->type : iov.type;
183  unsigned int typ2 = iovType ? iovType->type : type;
184  return typ1 == typ2;
185  }
186  return false;
187 }
dd4hep::IOV::iov_intersection
void iov_intersection(const IOV &comparator)
Set the intersection of this IOV with the argument IOV.
Definition: IOV.cpp:99
dd4hep::IOV::contains
bool contains(const IOV &iov) const
Check for validity containment.
Definition: IOV.cpp:180
dd4hep::IOVType::name
std::string name
String name.
Definition: IOV.h:43
dd4hep::IOV::optData
int optData
Optional user data.
Definition: IOV.h:84
dd4hep::IOV::invert
IOV & invert()
Invert the key values (first=second and second=first)
Definition: IOV.cpp:92
IOV.h
dd4hep::IOV::Key_value_type
std::int64_t Key_value_type
Key definition. Use fixed width type, though not portable!
Definition: IOV.h:73
dd4hep::IOVType::UNKNOWN_IOV
static constexpr unsigned int UNKNOWN_IOV
Definition: IOV.h:39
dd4hep::IOVType::str
std::string str() const
Conversion to string.
Definition: IOV.cpp:43
dd4hep::IOV::str
std::string str() const
Create string representation of the IOV.
Definition: IOV.cpp:141
dd4hep::IOV::Key
std::pair< Key_value_type, Key_value_type > Key
Definition: IOV.h:74
dd4hep::IOVType
Class describing the interval of validty type.
Definition: IOV.h:37
dd4hep::IOV::IOV
IOV()=delete
Initializing constructor: Does not set reference to IOVType !
dd4hep::IOV
Class describing the interval of validty.
Definition: IOV.h:67
dd4hep::IOV::move
void move(IOV &from)
Move the data content: 'from' will be reset to NULL.
Definition: IOV.cpp:132
dd4hep::IOVType::operator=
IOVType & operator=(const IOVType &copy)=default
Assignment operator.
dd4hep::IOV::set
void set(const Key &value)
Set discrete IOV value.
Definition: IOV.cpp:69
dd4hep::IOV::keyData
Key keyData
IOV key (if second==first, discrete, otherwise range)
Definition: IOV.h:82
dd4hep::IOV::key_is_contained
static bool key_is_contained(const Key &key, const Key &test)
Check if IOV 'test' is fully contained in IOV 'key'.
Definition: IOV.h:153
dd4hep::IOV::type
unsigned int type
IOV buffer type: Must be a bitmap!
Definition: IOV.h:86
Primitives.h
dd4hep::IOV::MIN_KEY
static constexpr Key_value_type MIN_KEY
Definition: IOV.h:76
dd4hep::IOV::iov_union
void iov_union(const IOV &comparator)
Set the union of this IOV with the argument IOV.
Definition: IOV.cpp:115
dd4hep::IOV::reset
IOV & reset()
Set keys to unphysical values (LONG_MAX, LONG_MIN)
Definition: IOV.cpp:85
dd4hep::IOV::iovType
const IOVType * iovType
Reference to IOV type.
Definition: IOV.h:80
dd4hep
Namespace for the AIDA detector description toolkit.
Definition: AlignmentsCalib.h:28
dd4hep::detail::tools::copy
void copy(Alignment from, Alignment to)
Copy alignment object from source object.
Definition: AlignmentTools.cpp:43
dd4hep::IOV::MAX_KEY
static constexpr Key_value_type MAX_KEY
Definition: IOV.h:77
dd4hep::IOVType::type
unsigned int type
integer identifier used internally
Definition: IOV.h:41
Printout.h