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