DD4hep - The AIDA detector description toolkit for high energy physics experiments
DD4hep  Rev:Unversioneddirectory
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
IOV.cpp
Go to the documentation of this file.
1 // $Id$
2 //==========================================================================
3 // AIDA Detector description implementation for LCD
4 //--------------------------------------------------------------------------
5 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
6 // All rights reserved.
7 //
8 // For the licensing terms see $DD4hepINSTALL/LICENSE.
9 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
10 //
11 // Author : M.Frank
12 //
13 //==========================================================================
14 
15 // Framework includes
16 #include "DD4hep/IOV.h"
17 
18 // C/C++ include files
19 #include <climits>
20 #include <iomanip>
21 #include <cstring>
22 
23 using namespace std;
24 using namespace DD4hep;
25 
27 IOVType& IOVType::operator=(const IOVType& copy) {
28  if ( &copy != this ) {
29  name = copy.name;
30  type = copy.type;
31  }
32  return *this;
33 }
34 
36 std::string IOVType::str() const {
37  char text[256];
38  ::snprintf(text,sizeof(text),"%s(%d)",name.c_str(),int(type));
39  return text;
40 }
41 
43 IOV::IOV(const IOVType* t) : iovType(t), keyData(0,0), optData(0) {
44  type = t ? t->type : int(IOVType::UNKNOWN_IOV);
45 }
46 
48 IOV::IOV(const IOVType* t, const Key& k)
49  : iovType(t), keyData(k), optData(0)
50 {
51  type = t ? t->type : int(IOVType::UNKNOWN_IOV);
52 }
53 
55 void IOV::set(const Key& value) {
56  keyData = value;
57 }
58 
60 void IOV::set(Key::first_type value) {
61  keyData.first = keyData.second = value;
62 }
63 
65 void IOV::set(Key::first_type val_1, Key::second_type val_2) {
66  keyData.first = val_1;
67  keyData.second = val_2;
68 }
69 
72  keyData.first = LONG_MAX;
73  keyData.second = LONG_MIN;
74  return *this;
75 }
76 
79  Key::first_type tmp = keyData.first;
80  keyData.first = keyData.second;
81  keyData.second = tmp;
82  return *this;
83 }
84 
85 void IOV::iov_intersection(const IOV& validity) {
86  if ( !iovType )
87  *this = validity;
88  else if ( validity.keyData.first > keyData.first )
89  keyData.first = validity.keyData.first;
90  if ( validity.keyData.second < keyData.second )
91  keyData.second = validity.keyData.second;
92 }
93 
94 void IOV::iov_intersection(const IOV::Key& validity) {
95  if ( validity.first > keyData.first )
96  keyData.first = validity.first;
97  if ( validity.second < keyData.second )
98  keyData.second = validity.second;
99 }
100 
101 void IOV::iov_union(const IOV& validity) {
102  if ( !iovType )
103  *this = validity;
104  else if ( validity.keyData.first < keyData.first )
105  keyData.first = validity.keyData.first;
106  if ( validity.keyData.second > keyData.second )
107  keyData.second = validity.keyData.second;
108 }
109 
110 void IOV::iov_union(const IOV::Key& validity) {
111  if ( validity.first < keyData.first )
112  keyData.first = validity.first;
113  if ( validity.second > keyData.second )
114  keyData.second = validity.second;
115 }
116 
118 void IOV::move(IOV& from) {
119  ::memcpy(this,&from,sizeof(IOV));
120  from.keyData.first = from.keyData.second = from.optData = 0;
121  from.type = int(IOVType::UNKNOWN_IOV);
122  from.iovType = 0;
123 }
124 
126 string IOV::str() const {
127  char text[256];
128  if ( iovType ) {
129  if ( iovType->name[0] != 'e' ) {
130  ::snprintf(text,sizeof(text),"%s(%d):[%ld-%ld]",
131  iovType->name.c_str(),int(iovType->type),keyData.first, keyData.second);
132  }
133  else if ( iovType->name == "epoch" ) {
134  time_t since = keyData.first;
135  time_t until = keyData.second;
136  char c_since[64], c_until[64];
137  struct tm time_buff;
138  ::strftime(c_since,sizeof(c_since),"%d-%m-%Y %H:%M:%S",::gmtime_r(&since,&time_buff));
139  ::strftime(c_until,sizeof(c_until),"%d-%m-%Y %H:%M:%S",::gmtime_r(&until,&time_buff));
140  ::snprintf(text,sizeof(text),"%s(%d):[%s - %s]",
141  iovType->name.c_str(),iovType->type,
142  c_since, c_until);
143  }
144  else {
145  ::snprintf(text,sizeof(text),"%s(%d):[%ld-%ld]",
146  iovType->name.c_str(),int(iovType->type),keyData.first, keyData.second);
147  }
148  }
149  else {
150  ::snprintf(text,sizeof(text),"%d:[%ld-%ld]",type,keyData.first, keyData.second);
151  }
152  return text;
153 }
154 
156 bool IOV::contains(const IOV& iov) const {
157  if ( key_is_contained(iov.keyData,keyData) ) {
158  unsigned int typ1 = iov.iovType ? iov.iovType->type : iov.type;
159  unsigned int typ2 = iovType ? iovType->type : type;
160  return typ1 == typ2;
161  }
162  return false;
163 }
int optData
Definition: IOV.h:71
void set(const Key &value)
Set discrete IOV value.
Definition: IOV.cpp:55
bool contains(const IOV &iov) const
Check for validity containment.
Definition: IOV.cpp:156
void copy(Alignment from, Alignment to)
Copy alignment object from source object.
void iov_intersection(const IOV &comparator)
Set the intersection of this IOV with the argument IOV.
Definition: IOV.cpp:85
std::string name
String name.
Definition: IOV.h:39
const IOVType * iovType
Definition: IOV.h:69
Class describing the interval of validty.
Definition: IOV.h:59
IOV & invert()
Invert the key values (first=second and second=first)
Definition: IOV.cpp:78
Key keyData
Definition: IOV.h:70
Class describing the interval of validty type.
Definition: IOV.h:33
IOV & reset()
Set keys to unphysical values (LONG_MAX, LONG_MIN)
Definition: IOV.cpp:71
unsigned int type
integer identifier ised internally
Definition: IOV.h:37
IOV()=delete
Initializing constructor: Does not set reference to IOVType !
static bool key_is_contained(const Key &key, const Key &test)
Check if IOV 'test' is fully contained in IOV 'key'.
Definition: IOV.h:127
unsigned int type
IOV buffer type: Must be a bitmap!
Definition: IOV.h:73
void move(IOV &from)
Move the data content: 'from' will be reset to NULL.
Definition: IOV.cpp:118
void iov_union(const IOV &comparator)
Set the union of this IOV with the argument IOV.
Definition: IOV.cpp:101
std::pair< Key_first_type, Key_second_type > Key
Definition: IOV.h:67
std::string str() const
Create string representation of the IOV.
Definition: IOV.cpp:126