5 from PyCool
import cool
16 self.
db = cool.DatabaseSvcFactory.databaseService().
openDatabase(dbconnect, readonly)
17 except Exception
as e:
18 print (
'ERROR::Can not open DB or get chain folder because of exception: %s' ,e)
21 if not self.
db.existsFolder(name):
22 raise Exception(
'Folder does not exist: "%s"' ,name)
55 raise Exception(
'ReadPhysicsLumiInfo - duplicate lb=%d' ,self.
lb)
67 raise Exception(
'GetLBSecs - invalid start/end times')
121 s =
'Run %s peak lumi=%s int lumi=%s' ,(self.
run_number, ip, il)
128 run = (obj.since() >> 32)
129 lb = (obj.since() & 0xffff)
134 print(
'INFO::getRunLB - will search for ATLAS runs in the following range:')
135 print(
'INFO:: beg run: ' ,(beg_run))
136 print(
'INFO:: end run: ' ,(end_run))
138 f =
Folder(
'COOLONL_TRIGGER/CONDBR2',
'/TRIGGER/LUMI/LBLB')
140 fit = f.folder.browseObjects(beg_run << 32, end_run << 32, cool.ChannelSelection.all())
144 while fit.goToNext():
152 runs[lb.run][lb.lb] = lb
154 print(
'INFO::getRunLB - found ', len(runs),
' ATLAS runs')
161 print(
'INFO::getRunOnlineLumi - will read online luminosity for ', len(runs),
' ATLAS runs')
163 f =
Folder(
'COOLONL_TRIGGER/CONDBR2',
'/TRIGGER/LUMI/OnlPrefLumi')
166 for run_, lbs
in runs.items():
168 fit = f.folder.browseObjects(run_ << 32, (run_ << 32) + 100000, cool.ChannelSelection(0))
170 while fit.goToNext():
171 obj = fit.currentRef()
173 run = (obj.since() >> 32)
174 lb = (obj.since() & 0xffff)
177 raise Exception(
'getRunOnlineLumi - logic error: run=', run,
', run_=', run_)
185 print(
'WANRING::getRunOnlineLumi - failed to find LumiBlock for run, lb: ', run, lb)
188 lblock.ReadLumiInfo(obj)
194 collect_runs =
getRunLB(beg_run, end_run)
198 physics_runs = [
Run(run, lbs.values())
for run,lbs
in collect_runs.items()]
200 if len(physics_runs) == 0:
201 print(
'WARNING::Found 0 physics runs')
204 physics_runs.sort(key =
lambda x: x.run_number)
207 for run
in physics_runs:
210 key_since = run.GetRunStartTime() - 100000
211 key_until = run.GetRunEndTime() + 100000
213 f =
Folder(
'COOLOFL_TRIGGER/CONDBR2',
'/TRIGGER/OFLLUMI/LumiAccounting')
214 taglist=f.folder.listTags()
217 objs = f.folder.browseObjects(key_since, key_until, cool.ChannelSelection.all(), tag)
219 filledTags[tag] = len(objs)
221 if len(filledTags) == 0:
222 print (
"ERROR: no filled tag")
224 elif len(filledTags) > 1:
225 print (
"WARNING: the number filled tags is more than 1")
227 filledTags =
sorted(filledTags.items(),key=
lambda x:x[1],reverse=
True)
228 objs = f.folder.browseObjects(key_since, key_until, cool.ChannelSelection.all(), filledTags[0][0])
231 crun = obj.payload()[
'Run']
232 clb = obj.payload()[
'LumiBlock']
234 if crun != run.run_number:
239 lb.ReadPhysicsLumiInfo(obj.payload())
243 i_LB = obj.payload()[
'LumiBlock']
245 'AtlasPhysics' : obj.payload()[
'AtlasPhysics'],
246 'InstLumi' : obj.payload()[
'InstLumi']/10000.,
247 'LiveFraction' : obj.payload()[
'LiveFraction'],
248 'Duration' : lb.GetLBSecs(),
249 'start_time' : lb.start_time,
250 'end_time' : lb.end_time
253 if len(run.lbs) != icount:
254 print(
'WARNING::getRunPhysicsLumi - number of missed lbs=%d' ,(len(run.lbs) - icount))
255 print(
'WARNING:: number of run lbs=%d' ,(len(run.lbs)))
256 print(
'WARNING:: number of matched lbs=%d' ,(icount))
258 RunsLumiDic = LumiDic
265 for lb, lumiInfo
in RunsLumiDic.items():
268 s =
'lb=%4d - AtlasPhysics=%d, InstLumi=%f, LiveFraction=%f, Duration=%f' %(
270 lumiInfo[
'AtlasPhysics'],
271 lumiInfo[
'InstLumi'],
272 lumiInfo[
'LiveFraction'],
279 if __name__ ==
'__main__':
280 print (
"GetRunInfoFromCOOL: Hello, World !")