ATLAS Offline Software
Database
EventIndex
EventIndexProducer
python
EI_Lib.py
Go to the documentation of this file.
1
# Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
2
3
""" EI classes"""
4
5
6
def
cmp
(x, y):
7
return
(x > y) - (x < y)
8
9
10
class
IOV
(
object
):
11
12
_iovs = {}
13
_cached = {}
14
15
def
__init__
(self):
16
pass
17
18
def
cmpBN
(self, a, b):
19
20
# compare a and b and return -1,0,1 if a is <,=,> than b
21
# a (and b) are represented as a pair of numbers
22
# (most significant part, least significant part)
23
24
try
:
25
(r, e) = a
26
(r1, e1) = b
27
except
Exception:
28
raise
TypeError(
"element must be a tuple with two components"
)
29
30
c =
cmp
(r, r1)
# compare most significant part
31
if
c == 0:
32
c =
cmp
(e, e1)
# if equal, compare least significant part
33
34
return
c
35
36
def
isInInterval
(self, point, interval):
37
38
try
:
39
if
len(interval) != 4:
40
raise
TypeError(
"interval must contain 4 elements"
)
41
except
Exception:
42
raise
TypeError(
"interval must be a tuple or list"
)
43
44
# broke down the two parts of the interval
45
46
i1 = interval[:2]
47
i2 = interval[2:]
48
49
# look if point belongs to [i1,i2[
50
if
self.
cmpBN
(point, i1) >= 0
and
self.
cmpBN
(point, i2) < 0:
51
return
True
52
else
:
53
return
False
54
55
def
add
(self, key, value, interval):
56
if
key
not
in
self.
_iovs
:
57
self.
_iovs
[key] = []
58
59
try
:
60
if
len(interval) != 4:
61
raise
TypeError(
"interval must contain 4 elements"
)
62
except
Exception:
63
raise
TypeError(
"interval must be a tuple or list"
)
64
65
try
:
66
# convert interval into ints to prevent lexicographic comparison
67
interval2 = []
68
for
number
in
interval:
69
interval2.append(
int
(number))
70
except
Exception:
71
raise
TypeError(
"interval ranges must be a integers or longs"
)
72
73
self.
_iovs
[key].
append
((interval2, value))
74
75
def
dump
(self):
76
for
k
in
self.
_iovs
:
77
print
(k)
78
for
e
in
self.
_iovs
[k]:
79
print
(
" "
, e)
80
81
def
get
(self, key, point):
82
if
key
not
in
self.
_iovs
:
83
return
None
84
if
key
in
self.
_cached
:
85
i, v = self.
_cached
[key]
86
if
self.
isInInterval
(point, i):
87
return
v
88
ivalues = self.
_iovs
[key]
89
for
i, v
in
ivalues:
90
if
self.
isInInterval
(point, i):
91
self.
_cached
[key] = (i, v)
92
return
v
93
return
None
python.EI_Lib.cmp
def cmp(x, y)
Definition:
EI_Lib.py:6
python.EI_Lib.IOV._cached
dictionary _cached
Definition:
EI_Lib.py:13
CaloCellPos2Ntuple.int
int
Definition:
CaloCellPos2Ntuple.py:24
python.EI_Lib.IOV._iovs
dictionary _iovs
Definition:
EI_Lib.py:12
python.EI_Lib.IOV
Definition:
EI_Lib.py:10
dumpHVPathFromNtuple.append
bool append
Definition:
dumpHVPathFromNtuple.py:91
python.EI_Lib.IOV.__init__
def __init__(self)
Definition:
EI_Lib.py:15
python.EI_Lib.IOV.isInInterval
def isInInterval(self, point, interval)
Definition:
EI_Lib.py:36
python.EI_Lib.IOV.add
def add(self, key, value, interval)
Definition:
EI_Lib.py:55
python.EI_Lib.IOV.get
def get(self, key, point)
Definition:
EI_Lib.py:81
print
void print(char *figname, TCanvas *c1)
Definition:
TRTCalib_StrawStatusPlots.cxx:25
python.EI_Lib.IOV.dump
def dump(self)
Definition:
EI_Lib.py:75
pickleTool.object
object
Definition:
pickleTool.py:30
python.EI_Lib.IOV.cmpBN
def cmpBN(self, a, b)
Definition:
EI_Lib.py:18
Generated on Fri Jan 10 2025 21:09:44 for ATLAS Offline Software by
1.8.18