ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Database
CoolRunQuery
python
selector
AtlRunQuerySelectorRuntime.py
Go to the documentation of this file.
1
# Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
2
3
from
time
import
time
4
import
sys
5
6
from
PyCool
import
cool
7
8
from
CoolRunQuery.utils.AtlRunQueryUtils
import
coolDbConn, GetRanges
9
10
from
CoolRunQuery.selector.AtlRunQuerySelectorBase
import
Selector
11
12
from
CoolRunQuery.AtlRunQueryRun
import
Run
13
14
class
RunTimeSelector
(Selector):
15
def
__init__
(self, name, runlist):
16
super(RunTimeSelector,self).
__init__
(name)
17
if
not
runlist:
18
runlist = [
'-'
]
19
runlist =
','
.join(runlist).
split
(
','
)
20
runlist = [rr
for
rr
in
runlist
if
not
rr.startswith(
'last'
)]
21
self.
runranges
= GetRanges(
','
.join(runlist))
22
23
def
__str__
(self):
24
rr = []
25
for
r
in
self.
runranges
:
26
if
r[0]==r[1]:
27
rr += [ str(r[0]) ]
28
elif
r[0]==r[1]-1:
29
rr += [
'%i, %i'
% tuple(r) ]
30
else
:
31
rr += [
'%i-%i'
% tuple(r) ]
32
return
"SELOUT Checking for runs in %s"
%
', '
.join(rr)
33
34
35
def
select
(self):
36
37
if
len(self.
runranges
)==0:
# no run specified
38
return
[]
39
40
runlist = []
41
firstRun = self.
runranges
[0][0]
42
start = time()
43
folder = coolDbConn.GetDBConn(schema=
"COOLONL_TRIGGER"
, db = Selector.condDB(firstRun) ).getFolder(
'/TRIGGER/LUMI/LBLB'
)
44
print
(self, end=
''
)
45
sys.stdout.flush()
46
currentRun =
None
47
currentEOR =
None
48
for
rr
in
self.
runranges
:
49
objs = folder.browseObjects( rr[0] << 32, ((rr[1]+1) << 32)-1, cool.ChannelSelection(0))
50
while
objs.goToNext():
51
obj=objs.currentRef()
52
payload=obj.payload()
53
runNr,lbNr = RunTimeSelector.runlb(obj.since())
54
if
lbNr==0:
55
lbNr=1
# this is an aweful hack to make MC work (there only one LB exists in LBLB and it is nr 0) need to rethink this
56
if
not
currentRun
or
runNr > currentRun.runNr:
57
if
currentRun:
58
currentRun.eor = currentEOR
59
runlist.append(currentRun)
60
currentRun = Run(runNr)
61
currentRun.sor = payload[
'StartTime'
]
62
currentRun.lbtimes.extend([(0,0)]*(lbNr-len(currentRun.lbtimes)))
63
currentRun.lbtimes[lbNr-1] = ( payload[
'StartTime'
], payload[
'EndTime'
] )
64
currentRun.lastlb = lbNr
65
currentEOR = payload[
'EndTime'
]
66
if
currentRun:
67
currentRun.eor = currentEOR
68
runlist.append(currentRun)
69
runlist.sort()
70
71
duration = time() - start
72
print
(
" ==> %i runs found (%.2f sec)"
% (len(runlist),duration))
73
return
runlist
74
75
@staticmethod
76
def
runlb
(time):
77
run = time>>32
78
lb = time&0xFFFFFFFF
79
return
(run,lb)
80
81
def
runNrFromTime
(self,timeiov):
82
listOfCoveredRuns = []
83
runlist = self.runTimes.keys()
84
runlist.sort()
85
lastEOR = 0
86
for
rt
in
runlist:
87
x = self.runTimes[rt]
88
if
timeiov[0]>=x[0]
and
timeiov[1]<x[1]
or
timeiov[0]<x[0]
and
timeiov[1]>x[0]:
89
listOfCoveredRuns += [rt]
90
lastEOR = x[1]
91
return
(listOfCoveredRuns,lastEOR)
92
93
94
class
TimeRunSelector
(Selector):
95
def
__init__
(self, name, timelist):
96
super(TimeRunSelector,self).
__init__
(name)
97
self.
timelist
=
','
.join(timelist)
98
99
def
select
(self):
100
start = time()
101
runlist = []
102
folder = coolDbConn.GetDBConn(schema=
"COOLONL_TRIGGER"
, db=Selector.condDB()).getFolder(
'/TRIGGER/LUMI/LBTIME'
)
103
print
(
'SELOUT Checking for runs in time range "%s"'
% self.
timelist
, end=
''
)
104
sys.stdout.flush()
105
ranges = GetRanges(self.
timelist
, maxval=int(time()*1E09))
106
currentRun =
None
107
currentEOR =
None
108
for
rr
in
ranges:
109
objs = folder.browseObjects( rr[0], rr[1]+86400000000000, cool.ChannelSelection(0))
110
while
objs.goToNext():
111
obj=objs.currentRef()
112
payload=obj.payload()
113
runNr = int(payload[
'Run'
])
114
if
runNr==0:
115
continue
# mistakenly runnr=0 was stored
116
117
if
runNr>1<<30:
118
# there is a problem with runs between
119
# usetimes 2009-04-14:00:00:00 2009-04-16:13:00:00
120
# there the runnumbers are off the chart (> 1<<30)
121
continue
122
123
if
not
currentRun
or
runNr != currentRun.runNr:
124
if
currentRun:
125
currentRun.eor = currentEOR
126
runlist.append(currentRun)
127
currentRun = Run(runNr)
128
currentRun.sor = obj.since()
129
lbNr = int(payload[
'LumiBlock'
])
130
currentRun.lbtimes.extend([(0,0)]*(lbNr-len(currentRun.lbtimes)))
131
currentRun.lbtimes[lbNr-1] = ( obj.since(), obj.until() )
132
currentRun.lastlb = lbNr
133
currentEOR = obj.until()
134
if
currentRun:
135
currentRun.eor = currentEOR
136
runlist.append(currentRun)
137
138
runlist.sort()
139
duration = time() - start
140
print
(
" ==> %i runs selected (%g sec)"
% (len(runlist), duration))
141
return
runlist
142
python.selector.AtlRunQuerySelectorRuntime.RunTimeSelector
Definition
AtlRunQuerySelectorRuntime.py:14
python.selector.AtlRunQuerySelectorRuntime.RunTimeSelector.runlb
runlb(time)
Definition
AtlRunQuerySelectorRuntime.py:76
python.selector.AtlRunQuerySelectorRuntime.RunTimeSelector.__init__
__init__(self, name, runlist)
Definition
AtlRunQuerySelectorRuntime.py:15
python.selector.AtlRunQuerySelectorRuntime.RunTimeSelector.select
select(self)
Definition
AtlRunQuerySelectorRuntime.py:35
python.selector.AtlRunQuerySelectorRuntime.RunTimeSelector.runranges
runranges
Definition
AtlRunQuerySelectorRuntime.py:21
python.selector.AtlRunQuerySelectorRuntime.RunTimeSelector.runNrFromTime
runNrFromTime(self, timeiov)
Definition
AtlRunQuerySelectorRuntime.py:81
python.selector.AtlRunQuerySelectorRuntime.RunTimeSelector.__str__
__str__(self)
Definition
AtlRunQuerySelectorRuntime.py:23
python.selector.AtlRunQuerySelectorRuntime.TimeRunSelector
Definition
AtlRunQuerySelectorRuntime.py:94
python.selector.AtlRunQuerySelectorRuntime.TimeRunSelector.select
select(self)
Definition
AtlRunQuerySelectorRuntime.py:99
python.selector.AtlRunQuerySelectorRuntime.TimeRunSelector.__init__
__init__(self, name, timelist)
Definition
AtlRunQuerySelectorRuntime.py:95
python.selector.AtlRunQuerySelectorRuntime.TimeRunSelector.timelist
str timelist
Definition
AtlRunQuerySelectorRuntime.py:97
split
std::vector< std::string > split(const std::string &s, const std::string &t=":")
Definition
hcg.cxx:179
Generated on
for ATLAS Offline Software by
1.17.0