9 from PyCool
import cool
10 from CoolConvUtilities.AtlCoolLib
import indirectOpen
17 "Wrapper class to hold magnetic field current info from DCS data and the filename tag for the SOR"
18 def __init__(self,solC,solSetC,torC,torSetC,fnt):
19 "Initialise given values for solenoid & toroid acual and set currents and filename tag"
27 "Return the solenoid current"
31 "Return the requested solenoid current (set point)"
35 "Return the toroid current"
39 "Return the requested toroid current (set point)"
43 "Return the Filename tag for this run"
48 "Get the magnetic field currents (MagFieldDCSInfo) for a given run"
52 runiov=(run << 32)+(lumiblock
or 0)
53 if runiov
in _fieldForLB:
54 return _fieldForLB[runiov]
58 print (
"Reading magnetic field for run %i, CONDBR2 %s" % (run,newdb))
62 sorfolder=
'/TDAQ/RunCtrl/SOR'
63 fntname=
'T0ProjectTag'
66 sorfolder=
'/TDAQ/RunCtrl/SOR_Params'
71 print (
"MagFieldUtils.getFieldForRun ERROR: Cannot connect to COOLONL_TDAQ/%s" % dbname)
75 tdaqfolder=tdaqDB.getFolder(sorfolder)
77 obj=tdaqfolder.findObject(runiov,0)
79 sortime=payload[
'SORTime']
81 except Exception
as e:
82 print (
"MagFieldUtils.getFieldForRun ERROR accessing folder %s" % sorfolder)
84 tdaqDB.closeDatabase()
87 if lumiblock
is not None:
89 print (
"Reading specific timestamp for lumiblock %i" % lumiblock)
92 if (lbtime==0
and lumiblock>1):
94 print (
"MagFieldUtils.getFieldForRun WARNING: Cannot find LB %i, trying %i" % (lumiblock,lumiblock-1))
97 print (
"MagFieldUtils.getFieldForRun WARNING: Cannot find LB %i, fall back on SOR time" % lumiblock)
101 print (
"Lumiblock starts %i seconds from start of run" %
int((lbtime-sortime)/1.E9))
104 print (
"MagFieldUtils.getFieldForRun ERROR accessing /TRIGGER/LUMI/LBLB")
105 print (
"Fall back on SOR time from %s" % sorfolder)
109 if (sortime==0):
return None
114 print (
"MagFieldUtils.getFieldForRun ERROR: Cannot connect to COOLOFL_DCS/%s" % dbname)
121 currentmap={
'CentralSol_Current':0,
'CentralSol_SCurrent':1,
122 'Toroids_Current':2,
'Toroids_SCurrent':3}
123 dcsfolder=dcsDB.getFolder(
'/EXT/DCS/MAGNETS/SENSORDATA')
124 objs=dcsfolder.findObjects(sortime,cool.ChannelSelection.all())
125 data=[-1.,-1.,-1.,-1.]
128 channame=dcsfolder.channelName(chan)
129 if channame
in currentmap.keys():
130 data[currentmap[channame]]=obj.payload()[
'value']
131 except Exception
as e:
132 print (
"MagFieldUtils.getFieldForRun ERROR accessing /EXT/DCS/MAGNETS/SENSORDATA")
134 dcsDB.closeDatabase()
140 _fieldForLB[runiov]=retval
144 "Return the time a specific run/LB, given the folder, or 0 for bad/no data"
148 runiov=(run << 32)+LB
150 if runiov
in _timeForLB:
151 print (
"getTimeForLB: Returning cached time for run %i, LumiBlock %i " % (run,LB))
152 return _timeForLB[runiov]
164 print (
"MagFieldUtils.getTimeForLB ERROR: Cannot connect to COOLONL_TDAQ/%s" % dbname)
167 lblbfolder=trigDB.getFolder(
'/TRIGGER/LUMI/LBLB')
168 obj=lblbfolder.findObject(runiov,0)
169 payload=obj.payload()
170 lbtime=payload[
'StartTime']
171 _timeForLB[runiov]=lbtime
172 trigDB.closeDatabase()
174 except Exception
as e:
175 print (
"MagFieldUtils.getTimeForLB WARNING: accessing /TRIGGER/LUMI/LBLB for run %i, LB %i" % (run,LB))
181 if __name__==
'__main__':
184 print (
"Syntax",sys.argv[0],
'<run>')
189 lumiblock=
int(sys.argv[2])
191 print (
"Magnetic field information for run %i" % run)
192 if (magfield
is not None):
193 print (
"Solenoid current %8.2f (requested %8.2f)" % (magfield.solenoidCurrent(),magfield.solenoidSetCurrent()))
194 print (
"Toroid current %8.2f (requested %8.2f)" % (magfield.toroidCurrent(),magfield.toroidSetCurrent()))
195 print (
"Filename Tag: %s" % (magfield.fileNameTag()))
197 print (
"Not available")