5 from PyCool
import cool
6 from CoolConvUtilities.AtlCoolLib
import indirectOpen
36 raise Exception(
'ReadPhysicsLumiInfo - duplicate lb=%d' ,self.
lb)
48 raise Exception(
'GetLBSecs - invalid start/end times')
102 s =
'Run %s peak lumi=%s int lumi=%s' ,(self.
run_number, ip, il)
109 run = (obj.since() >> 32)
110 lb = (obj.since() & 0xffff)
115 print(
'INFO::getRunLB - will search for ATLAS runs in the following range:')
116 print(
'INFO:: beg run: ' ,(beg_run))
117 print(
'INFO:: end run: ' ,(end_run))
119 f=dbObj.getFolder(
'/TRIGGER/LUMI/LBLB')
120 fit = f.browseObjects(beg_run << 32, end_run << 32, cool.ChannelSelection.all())
124 while fit.goToNext():
132 runs[lb.run][lb.lb] = lb
134 print(
'INFO::getRunLB - found ', len(runs),
' ATLAS runs')
141 print(
'INFO::getRunOnlineLumi - will read online luminosity for ', len(runs),
' ATLAS runs')
143 f= dbObj.getFolder(
'/TRIGGER/LUMI/OnlPrefLumi')
146 for run_, lbs
in runs.items():
148 fit = f.browseObjects(run_ << 32, (run_ << 32) + 100000, cool.ChannelSelection(0))
150 while fit.goToNext():
151 obj = fit.currentRef()
153 run = (obj.since() >> 32)
154 lb = (obj.since() & 0xffff)
157 raise Exception(
'getRunOnlineLumi - logic error: run=', run,
', run_=', run_)
165 print(
'WANRING::getRunOnlineLumi - failed to find LumiBlock for run, lb: ', run, lb)
168 lblock.ReadLumiInfo(obj)
176 collect_runs =
getRunLB(beg_run, end_run,dbInst)
180 physics_runs = [
Run(run, lbs.values())
for run,lbs
in collect_runs.items()]
182 dbInst.closeDatabase()
184 if len(physics_runs) == 0:
185 print(
'WARNING::Found 0 physics runs')
188 physics_runs.sort(key =
lambda x: x.run_number)
193 for run
in physics_runs:
196 key_since = run.GetRunStartTime() - 100000
197 key_until = run.GetRunEndTime() + 100000
199 f = oflDb.getFolder(
'/TRIGGER/OFLLUMI/LumiAccounting')
203 objs = f.browseObjects(key_since, key_until, cool.ChannelSelection.all(), tag)
205 filledTags[tag] = len(objs)
207 if len(filledTags) == 0:
208 print (
"ERROR: no filled tag")
210 elif len(filledTags) > 1:
211 print (
"WARNING: the number filled tags is more than 1")
213 filledTags =
sorted(filledTags.items(),key=
lambda x:x[1],reverse=
True)
214 objs = f.browseObjects(key_since, key_until, cool.ChannelSelection.all(), filledTags[0][0])
217 crun = obj.payload()[
'Run']
218 clb = obj.payload()[
'LumiBlock']
220 if crun != run.run_number:
225 lb.ReadPhysicsLumiInfo(obj.payload())
229 i_LB = obj.payload()[
'LumiBlock']
231 'AtlasPhysics' : obj.payload()[
'AtlasPhysics'],
232 'InstLumi' : obj.payload()[
'InstLumi']/10000.,
233 'LiveFraction' : obj.payload()[
'LiveFraction'],
234 'Duration' : lb.GetLBSecs(),
235 'start_time' : lb.start_time,
236 'end_time' : lb.end_time
239 if len(run.lbs) != icount:
240 print(
'WARNING::getRunPhysicsLumi - number of missed lbs=%d' ,(len(run.lbs) - icount))
241 print(
'WARNING:: number of run lbs=%d' ,(len(run.lbs)))
242 print(
'WARNING:: number of matched lbs=%d' ,(icount))
244 RunsLumiDic = LumiDic
246 oflDb.closeDatabase()
252 for lb, lumiInfo
in RunsLumiDic.items():
255 s =
'lb=%4d - AtlasPhysics=%d, InstLumi=%f, LiveFraction=%f, Duration=%f' %(
257 lumiInfo[
'AtlasPhysics'],
258 lumiInfo[
'InstLumi'],
259 lumiInfo[
'LiveFraction'],
266 if __name__ ==
'__main__':
267 print (
"GetRunInfoFromCOOL: Hello, World !")