DD4hep  1.35.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 <cstring>
22 #include <ctime>
23 
24 using namespace dd4hep;
25 
26 
27 #if 0
30  if ( &copy != this ) {
31  name = copy.name;
32  type = copy.type;
33  }
34  return *this;
35 }
36 #endif
37 
39 std::string IOVType::str() const {
40  char text[256];
41  ::snprintf(text,sizeof(text),"%s(%d)",name.c_str(),int(type));
42  return text;
43 }
44 
46 IOV::IOV(const IOVType* t) : iovType(t) {
47  if ( t ) type = t->type;
48 }
49 
51 IOV::IOV(const IOVType* t, Key_value_type iov_value)
52  : iovType(t), keyData(iov_value,iov_value)
53 {
54  if ( t ) type = t->type;
55 }
56 
58 IOV::IOV(const IOVType* t, const Key& k)
59  : iovType(t), keyData(k)
60 {
61  if ( t ) type = t->type;
62 }
63 
65 void IOV::set(const Key& value) {
66  keyData = value;
67 }
68 
70 void IOV::set(Key::first_type value) {
71  keyData.first = keyData.second = value;
72 }
73 
75 void IOV::set(Key::first_type val_1, Key::second_type val_2) {
76  keyData.first = val_1;
77  keyData.second = val_2;
78 }
79 
82  keyData.first = LONG_MAX;
83  keyData.second = LONG_MIN;
84  return *this;
85 }
86 
89  Key::first_type tmp = keyData.first;
90  keyData.first = keyData.second;
91  keyData.second = tmp;
92  return *this;
93 }
94 
95 void IOV::iov_intersection(const IOV& validity) {
96  if ( !iovType )
97  *this = validity;
98  else if ( validity.keyData.first > keyData.first )
99  keyData.first = validity.keyData.first;
100  if ( validity.keyData.second < keyData.second )
101  keyData.second = validity.keyData.second;
102 }
103 
104 void IOV::iov_intersection(const IOV::Key& validity) {
105  if ( validity.first > keyData.first )
106  keyData.first = validity.first;
107  if ( validity.second < keyData.second )
108  keyData.second = validity.second;
109 }
110 
111 void IOV::iov_union(const IOV& validity) {
112  if ( !iovType )
113  *this = validity;
114  else if ( validity.keyData.first < keyData.first )
115  keyData.first = validity.keyData.first;
116  if ( validity.keyData.second > keyData.second )
117  keyData.second = validity.keyData.second;
118 }
119 
120 void IOV::iov_union(const IOV::Key& validity) {
121  if ( validity.first < keyData.first )
122  keyData.first = validity.first;
123  if ( validity.second > keyData.second )
124  keyData.second = validity.second;
125 }
126 
128 void IOV::move(IOV& from) {
129  //::memcpy(this,&from,sizeof(IOV));
130  *this = from;
131  from.keyData.first = from.keyData.second = from.optData = 0;
132  from.type = int(IOVType::UNKNOWN_IOV);
133  from.iovType = 0;
134 }
135 
137 std::string IOV::str() const {
138  char text[256];
139  if ( iovType ) {
141  if ( iovType->name[0] != 'e' ) {
142  ::snprintf(text,sizeof(text),"%s(%u):[%ld-%ld]",
143  iovType->name.c_str(), iovType->type, long(keyData.first), long(keyData.second));
144  }
145  else if ( iovType->name == "epoch" ) {
146  struct tm time_buff;
147  char c_since[64], c_until[64];
148  static constexpr const Key_value_type nil = 0;
149  static const Key_value_type max_time = detail::makeTime(2099,12,31,24,59,59);
150  std::time_t since = std::min(std::max(keyData.first, nil), max_time);
151  std::time_t until = std::min(std::max(keyData.second,nil), max_time);
152  struct tm* tm_since = ::gmtime_r(&since,&time_buff);
153  struct tm* tm_until = ::gmtime_r(&until,&time_buff);
154  if ( nullptr == tm_since || nullptr == tm_until ) {
155  except("IOV::str"," Invalid epoch time stamp: %d:[%ld-%ld]",
156  type, long(keyData.first), long(keyData.second));
157  }
158  ::strftime(c_since,sizeof(c_since),"%d-%m-%Y %H:%M:%S", tm_since);
159  ::strftime(c_until,sizeof(c_until),"%d-%m-%Y %H:%M:%S", tm_until);
160  ::snprintf(text,sizeof(text),"%s(%u):[%s - %s]",
161  iovType->name.c_str(), iovType->type,
162  c_since, c_until);
163  }
164  else {
165  ::snprintf(text,sizeof(text),"%s(%u):[%ld-%ld]",
166  iovType->name.c_str(), iovType->type, long(keyData.first), long(keyData.second));
167  }
168  }
169  else {
170  ::snprintf(text,sizeof(text),"%u:[%ld-%ld]", type, long(keyData.first), long(keyData.second));
171  }
172  return text;
173 }
174 
176 bool IOV::contains(const IOV& iov) const {
177  if ( key_is_contained(iov.keyData,keyData) ) {
178  unsigned int typ1 = iov.iovType ? iov.iovType->type : iov.type;
179  unsigned int typ2 = iovType ? iovType->type : type;
180  return typ1 == typ2;
181  }
182  return false;
183 }
dd4hep::IOV::iov_intersection
void iov_intersection(const IOV &comparator)
Set the intersection of this IOV with the argument IOV.
Definition: IOV.cpp:95
dd4hep::IOV::contains
bool contains(const IOV &iov) const
Check for validity containment.
Definition: IOV.cpp:176
dd4hep::IOVType::name
std::string name
String name.
Definition: IOV.h:42
dd4hep::IOV::optData
int optData
Optional user data.
Definition: IOV.h:83
dd4hep::IOV::invert
IOV & invert()
Invert the key values (first=second and second=first)
Definition: IOV.cpp:88
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:72
dd4hep::IOVType::UNKNOWN_IOV
static constexpr unsigned int UNKNOWN_IOV
Definition: IOV.h:38
dd4hep::IOVType::str
std::string str() const
Conversion to string.
Definition: IOV.cpp:39
dd4hep::IOV::str
std::string str() const
Create string representation of the IOV.
Definition: IOV.cpp:137
dd4hep::IOV::Key
std::pair< Key_value_type, Key_value_type > Key
Definition: IOV.h:73
dd4hep::IOVType
Class describing the interval of validty type.
Definition: IOV.h:36
dd4hep::IOV::IOV
IOV()=delete
Initializing constructor: Does not set reference to IOVType !
dd4hep::IOV
Class describing the interval of validty.
Definition: IOV.h:66
dd4hep::IOV::move
void move(IOV &from)
Move the data content: 'from' will be reset to NULL.
Definition: IOV.cpp:128
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:65
dd4hep::IOV::keyData
Key keyData
IOV key (if second==first, discrete, otherwise range)
Definition: IOV.h:81
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:152
dd4hep::IOV::type
unsigned int type
IOV buffer type: Must be a bitmap!
Definition: IOV.h:85
Primitives.h
dd4hep::IOV::iov_union
void iov_union(const IOV &comparator)
Set the union of this IOV with the argument IOV.
Definition: IOV.cpp:111
dd4hep::IOV::reset
IOV & reset()
Set keys to unphysical values (LONG_MAX, LONG_MIN)
Definition: IOV.cpp:81
dd4hep::IOV::iovType
const IOVType * iovType
Reference to IOV type.
Definition: IOV.h:79
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::IOVType::type
unsigned int type
integer identifier used internally
Definition: IOV.h:40
Printout.h