8 from __future__
import print_function
10 from PyCool
import cool
11 from CoolConvUtilities.AtlCoolLib
import indirectOpen
18 "Wrapper class to hold magnetic field current info from DCS data and the filename tag for the SOR"
19 def __init__(self,solC,solSetC,torC,torSetC,fnt):
20 "Initialise given values for solenoid & toroid acual and set currents and filename tag"
28 "Return the solenoid current"
32 "Return the requested solenoid current (set point)"
36 "Return the toroid current"
40 "Return the requested toroid current (set point)"
44 "Return the Filename tag for this run"
49 "Get the magnetic field currents (MagFieldDCSInfo) for a given run"
53 runiov=(run << 32)+(lumiblock
or 0)
54 if runiov
in _fieldForLB:
55 return _fieldForLB[runiov]
59 print (
"Reading magnetic field for run %i, CONDBR2 %s" % (run,newdb))
63 sorfolder=
'/TDAQ/RunCtrl/SOR'
64 fntname=
'T0ProjectTag'
67 sorfolder=
'/TDAQ/RunCtrl/SOR_Params'
72 print (
"MagFieldUtils.getFieldForRun ERROR: Cannot connect to COOLONL_TDAQ/%s" % dbname)
76 tdaqfolder=tdaqDB.getFolder(sorfolder)
78 obj=tdaqfolder.findObject(runiov,0)
80 sortime=payload[
'SORTime']
82 except Exception
as e:
83 print (
"MagFieldUtils.getFieldForRun ERROR accessing folder %s" % sorfolder)
85 tdaqDB.closeDatabase()
88 if lumiblock
is not None:
90 print (
"Reading specific timestamp for lumiblock %i" % lumiblock)
93 if (lbtime==0
and lumiblock>1):
95 print (
"MagFieldUtils.getFieldForRun WARNING: Cannot find LB %i, trying %i" % (lumiblock,lumiblock-1))
98 print (
"MagFieldUtils.getFieldForRun WARNING: Cannot find LB %i, fall back on SOR time" % lumiblock)
102 print (
"Lumiblock starts %i seconds from start of run" %
int((lbtime-sortime)/1.E9))
105 print (
"MagFieldUtils.getFieldForRun ERROR accessing /TRIGGER/LUMI/LBLB")
106 print (
"Fall back on SOR time from %s" % sorfolder)
110 if (sortime==0):
return None
115 print (
"MagFieldUtils.getFieldForRun ERROR: Cannot connect to COOLOFL_DCS/%s" % dbname)
122 currentmap={
'CentralSol_Current':0,
'CentralSol_SCurrent':1,
123 'Toroids_Current':2,
'Toroids_SCurrent':3}
124 dcsfolder=dcsDB.getFolder(
'/EXT/DCS/MAGNETS/SENSORDATA')
125 objs=dcsfolder.findObjects(sortime,cool.ChannelSelection.all())
126 data=[-1.,-1.,-1.,-1.]
129 channame=dcsfolder.channelName(chan)
130 if channame
in currentmap.keys():
131 data[currentmap[channame]]=obj.payload()[
'value']
132 except Exception
as e:
133 print (
"MagFieldUtils.getFieldForRun ERROR accessing /EXT/DCS/MAGNETS/SENSORDATA")
135 dcsDB.closeDatabase()
141 _fieldForLB[runiov]=retval
145 "Return the time a specific run/LB, given the folder, or 0 for bad/no data"
149 runiov=(run << 32)+LB
151 if runiov
in _timeForLB:
152 print (
"getTimeForLB: Returning cached time for run %i, LumiBlock %i " % (run,LB))
153 return _timeForLB[runiov]
165 print (
"MagFieldUtils.getTimeForLB ERROR: Cannot connect to COOLONL_TDAQ/%s" % dbname)
168 lblbfolder=trigDB.getFolder(
'/TRIGGER/LUMI/LBLB')
169 obj=lblbfolder.findObject(runiov,0)
170 payload=obj.payload()
171 lbtime=payload[
'StartTime']
172 _timeForLB[runiov]=lbtime
173 trigDB.closeDatabase()
175 except Exception
as e:
176 print (
"MagFieldUtils.getTimeForLB WARNING: accessing /TRIGGER/LUMI/LBLB for run %i, LB %i" % (run,LB))
182 if __name__==
'__main__':
185 print (
"Syntax",sys.argv[0],
'<run>')
190 lumiblock=
int(sys.argv[2])
192 print (
"Magnetic field information for run %i" % run)
193 if (magfield
is not None):
194 print (
"Solenoid current %8.2f (requested %8.2f)" % (magfield.solenoidCurrent(),magfield.solenoidSetCurrent()))
195 print (
"Toroid current %8.2f (requested %8.2f)" % (magfield.toroidCurrent(),magfield.toroidSetCurrent()))
196 print (
"Filename Tag: %s" % (magfield.fileNameTag()))
198 print (
"Not available")