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