ATLAS Offline Software
Loading...
Searching...
No Matches
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
13from CoolLumiUtilities.CoolDataReader import CoolDataReader
14
15from PyCool import cool
16
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
__init__(self, dbstr=None, folderstr=None)