ATLAS Offline Software
BunchSpacingUtils.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
2 
3 from __future__ import print_function
4 
5 from PyCool import cool
6 from CoolConvUtilities.MagFieldUtils import getTimeForLB
7 from CoolConvUtilities.AtlCoolLib import indirectOpen
8 from os import environ
9 
10 def bunchSpacingOfRun(runnumber,LB,verbose=False):
11  if (runnumber<236107):
12  print ("WARNING BunchSpacingUtils don't work for run-1 data")
13  return None
14 
15  tdaqDBName="COOLONL_TDAQ/CONDBR2"
16  folder="/TDAQ/OLC/LHC/FILLPARAMS"
17  iovtime=getTimeForLB(runnumber,LB,readOracle="DBRELEASE" not in environ)
18 
19  if iovtime==0:
20  print ("ERROR, can't get start time of run %i, LB %i" % (runnumber,LB))
21  return None
22 
23  obj=None
24  db = None
25  try:
26  db=indirectOpen(tdaqDBName)
27  print (db)
28  print (iovtime)
29  f=db.getFolder(folder)
30  obj=f.findObject(cool.ValidityKey(iovtime),0)
31  except Exception as e:
32  print (e)
33  if len(e.args)>1 and e.args[0].find("Object not found - 0"):
34  print ("WARNING No data found in folder %s for run/LB %i/%i" % (folder,runnumber,LB))
35  else:
36  print ("BunchSpacingUtils: ERROR accesssing folder",folder,"on db",tdaqDBName)
37  print (e)
38 
39  if db is not None:
40  db.closeDatabase()
41  return None
42 
43  pl=obj.payload()
44  buf=pl["BCIDmasks"]
45 
46 
47  bucketDiff=0
48  firstFilled=-1
49  lastFilled=-1
50  bucketDiffs=[]
51 
52  for iBucket,filled in enumerate(buf):
53  if filled!=0:
54  if (verbose): print ("Bucket",iBucket,"filled")
55  lastFilled=iBucket
56  if firstFilled<0:
57  firstFilled=iBucket
58  if (verbose): print ("First filled bucket=",iBucket)
59  else:
60  if (verbose): print ("Bucket #%i, bunch spacing=%i * 25ns" % (iBucket,bucketDiff))
61  bucketDiffs.append(bucketDiff)
62  bucketDiff=1
63 
64  pass
65  else: # not filled
66  if (verbose): print ("Bucket",iBucket,"not filled")
67  bucketDiff+=1
68  pass
69 
70  #Handle wrap-around:
71  if (firstFilled>=0 and lastFilled>0):
72  bucketDiffs.append(len(buf)-lastFilled+firstFilled)
73  if (verbose): print ("Bunchdiff at wrap-around:",(len(buf)-lastFilled+firstFilled))
74  if db is not None:
75  db.closeDatabase()
76  if len(bucketDiffs)==0:
77  return None
78  else:
79  return min(bucketDiffs)
80 
81 
82 if __name__=="__main__":
83  import sys
84  if len(sys.argv)<3:
85  print ("Usage: BunchSpacingUtils.py <run> <lb>")
86  sys.exit(-1)
87  rn=int(sys.argv[1])
88  lb=int(sys.argv[2])
89  print ("Checking bunch spacing for run,lb",rn,lb)
90  print (bunchSpacingOfRun(rn,lb,True))
find
std::string find(const std::string &s)
return a remapped string
Definition: hcg.cxx:135
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
min
constexpr double min()
Definition: ap_fixedTest.cxx:26
python.BunchSpacingUtils.bunchSpacingOfRun
def bunchSpacingOfRun(runnumber, LB, verbose=False)
Definition: BunchSpacingUtils.py:10
python.MagFieldUtils.getTimeForLB
def getTimeForLB(run, LB)
Definition: MagFieldUtils.py:144
python.AtlCoolLib.indirectOpen
def indirectOpen(coolstr, readOnly=True, debug=False)
Definition: AtlCoolLib.py:130