ATLAS Offline Software
Loading...
Searching...
No Matches
Database
CoolLumiUtilities
python
LumiDBCache.py
Go to the documentation of this file.
1
# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
2
3
#
4
# LumiDBCache
5
#
6
# Eric Torrence - October 2011
7
#
8
# Contents
9
# LumiDBCache - simple caching object to store slowly-varying DB data
10
#
11
# This works in conjunction with CoolDataReader to access COOL
12
# User must set up the reader before trying to access payload
13
from
CoolLumiUtilities.CoolDataReader
import
CoolDataReader
14
15
from
PyCool
import
cool
16
17
class
LumiDBCache
:
18
19
def
__init__
(self, dbstr=None, folderstr=None):
20
21
self.
reader
= CoolDataReader(dbstr, folderstr)
22
self.
clearValidity
()
23
24
def
clearValidity
(self):
25
26
self.
validStartTime
= cool.ValidityKeyMax
27
self.
validEndTime
= cool.ValidityKeyMin
28
self.
payload
=
None
29
30
def
setValidity
(self, obj):
31
self.
validStartTime
= obj.since()
32
self.
validEndTime
= obj.until()
33
self.
payload
= obj.payload()
34
35
def
isValid
(self, time):
36
return
(self.
validStartTime
<= time < self.
validEndTime
)
37
38
def
getPayload
(self, time):
39
40
# Is existing version valid?
41
if
self.
isValid
(time):
42
return
self.
payload
43
44
# Nope, invalidate cache
45
self.
clearValidity
()
46
47
# Check if we already have the pre-fetched in the reader
48
for
obj
in
self.
reader
.data:
49
if
not
obj.since() <= time < obj.until():
continue
50
self.
setValidity
(obj)
51
52
# Did we find it?
53
if
self.
isValid
(time):
54
return
self.
payload
55
56
# Guess not, try reading directly from DB
57
self.
reader
.setIOVRange(time, time)
58
self.
reader
.readData()
59
60
# Try once more to find the object
61
for
obj
in
self.
reader
.data:
62
if
not
obj.since() <= time < obj.until():
continue
63
self.
setValidity
(obj)
64
65
# Did we find it?
66
if
self.
isValid
(time):
67
return
self.
payload
68
69
return
None
70
python.LumiDBCache.LumiDBCache
Definition
LumiDBCache.py:17
python.LumiDBCache.LumiDBCache.validEndTime
validEndTime
Definition
LumiDBCache.py:27
python.LumiDBCache.LumiDBCache.isValid
isValid(self, time)
Definition
LumiDBCache.py:35
python.LumiDBCache.LumiDBCache.__init__
__init__(self, dbstr=None, folderstr=None)
Definition
LumiDBCache.py:19
python.LumiDBCache.LumiDBCache.validStartTime
validStartTime
Definition
LumiDBCache.py:26
python.LumiDBCache.LumiDBCache.setValidity
setValidity(self, obj)
Definition
LumiDBCache.py:30
python.LumiDBCache.LumiDBCache.reader
reader
Definition
LumiDBCache.py:21
python.LumiDBCache.LumiDBCache.payload
payload
Definition
LumiDBCache.py:28
python.LumiDBCache.LumiDBCache.getPayload
getPayload(self, time)
Definition
LumiDBCache.py:38
python.LumiDBCache.LumiDBCache.clearValidity
clearValidity(self)
Definition
LumiDBCache.py:24
Generated on
for ATLAS Offline Software by
1.14.0