ATLAS Offline Software
Classes | Functions | Variables
python.MagFieldUtils Namespace Reference

Classes

class  MagFieldDCSInfo
 

Functions

def getFieldForRun (run, quiet=False, lumiblock=None)
 
def getTimeForLB (run, LB)
 

Variables

 _timeForLB = dict()
 
 _fieldForLB = dict()
 
 run = int(sys.argv[1])
 
 lumiblock = None
 
def magfield = getFieldForRun(run,lumiblock=lumiblock)
 

Function Documentation

◆ getFieldForRun()

def python.MagFieldUtils.getFieldForRun (   run,
  quiet = False,
  lumiblock = None 
)

Definition at line 48 of file MagFieldUtils.py.

48 def getFieldForRun(run,quiet=False,lumiblock=None):
49  "Get the magnetic field currents (MagFieldDCSInfo) for a given run"
50  # access the TDAQ schema to translate run number into timestamp
51  # and get the filename tag
52 
53  runiov=(run << 32)+(lumiblock or 0)
54  if runiov in _fieldForLB:
55  return _fieldForLB[runiov]
56 
57  newdb=(run>=236107)
58  if not quiet:
59  print ("Reading magnetic field for run %i, CONDBR2 %s" % (run,newdb))
60  # setup appropriate connection and folder parameters
61  if newdb:
62  dbname='CONDBR2'
63  sorfolder='/TDAQ/RunCtrl/SOR'
64  fntname='T0ProjectTag'
65  else:
66  dbname='COMP200'
67  sorfolder='/TDAQ/RunCtrl/SOR_Params'
68  fntname='FilenameTag'
69 
70  tdaqDB=indirectOpen('COOLONL_TDAQ/%s' % dbname)
71  if (tdaqDB is None):
72  print ("MagFieldUtils.getFieldForRun ERROR: Cannot connect to COOLONL_TDAQ/%s" % dbname)
73  return None
74  sortime=0
75  try:
76  tdaqfolder=tdaqDB.getFolder(sorfolder)
77  runiov=run << 32
78  obj=tdaqfolder.findObject(runiov,0)
79  payload=obj.payload()
80  sortime=payload['SORTime']
81  fnt=payload[fntname]
82  except Exception as e:
83  print ("MagFieldUtils.getFieldForRun ERROR accessing folder %s" % sorfolder)
84  print (e)
85  tdaqDB.closeDatabase()
86 
87  # if lumiblock is specifed, actually want the start time of the LB
88  if lumiblock is not None:
89  if not quiet:
90  print ("Reading specific timestamp for lumiblock %i" % lumiblock)
91 
92  lbtime=getTimeForLB(run,lumiblock)
93  if (lbtime==0 and lumiblock>1):
94  # sometimes fails as last LB is missing in LBLB - try previous
95  print ("MagFieldUtils.getFieldForRun WARNING: Cannot find LB %i, trying %i" % (lumiblock,lumiblock-1))
96  lbtime=getTimeForLB(run,lumiblock-1)
97  if (lbtime==0):
98  print ("MagFieldUtils.getFieldForRun WARNING: Cannot find LB %i, fall back on SOR time" % lumiblock)
99  if (lbtime>0):
100  # use this time instead of SORtime
101  if not quiet:
102  print ("Lumiblock starts %i seconds from start of run" % int((lbtime-sortime)/1.E9))
103  sortime=lbtime
104  else:
105  print ("MagFieldUtils.getFieldForRun ERROR accessing /TRIGGER/LUMI/LBLB")
106  print ("Fall back on SOR time from %s" % sorfolder)
107  lbtime=sortime
108 
109  # if we do not have a valid time, exit
110  if (sortime==0): return None
111 
112  # now having got the start of run timestamp, lookup the field info in DCS
113  dcsDB=indirectOpen('COOLOFL_DCS/%s' % dbname)
114  if (dcsDB is None):
115  print ("MagFieldUtils.getFieldForRun ERROR: Cannot connect to COOLOFL_DCS/%s" % dbname)
116  return None
117  data=None
118  try:
119  # map of expected channel names to slots in data[] variable
120  # follows original order from run1/COMP200
121  # has changed in CONDBR2, but use of named channels recovers this
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.]
127  for obj in objs:
128  chan=obj.channelId()
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")
134  print (e)
135  dcsDB.closeDatabase()
136  # if problem accessing folder, exit
137  if data is None:
138  return None
139  # return a MagFIeldDCSInfo object containing the result
140  retval=MagFieldDCSInfo(data[0],data[1],data[2],data[3],fnt)
141  _fieldForLB[runiov]=retval
142  return retval
143 

◆ getTimeForLB()

def python.MagFieldUtils.getTimeForLB (   run,
  LB 
)

Definition at line 144 of file MagFieldUtils.py.

144 def getTimeForLB(run,LB):
145  "Return the time a specific run/LB, given the folder, or 0 for bad/no data"
146  if LB is None:
147  LB=0
148 
149  runiov=(run << 32)+LB
150 
151  if runiov in _timeForLB:
152  print ("getTimeForLB: Returning cached time for run %i, LumiBlock %i " % (run,LB))
153  return _timeForLB[runiov]
154 
155  if (run>=236107):
156  dbname="CONDBR2"
157  else:
158  dbname="COMP200"
159 
160  #print ("Querying DB for time of run %i LB %i" % (run,LB))
161 
162  try:
163  trigDB=indirectOpen('COOLONL_TRIGGER/%s' % dbname)
164  if (trigDB is None):
165  print ("MagFieldUtils.getTimeForLB ERROR: Cannot connect to COOLONL_TDAQ/%s" % dbname)
166  return 0
167 
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()
174  return lbtime
175  except Exception as e:
176  print ("MagFieldUtils.getTimeForLB WARNING: accessing /TRIGGER/LUMI/LBLB for run %i, LB %i" % (run,LB))
177  print (e)
178  return 0
179 
180 
181 # command line driver for convenience

Variable Documentation

◆ _fieldForLB

python.MagFieldUtils._fieldForLB = dict()
private

Definition at line 15 of file MagFieldUtils.py.

◆ _timeForLB

python.MagFieldUtils._timeForLB = dict()
private

Definition at line 14 of file MagFieldUtils.py.

◆ lumiblock

python.MagFieldUtils.lumiblock = None

Definition at line 188 of file MagFieldUtils.py.

◆ magfield

def python.MagFieldUtils.magfield = getFieldForRun(run,lumiblock=lumiblock)

Definition at line 191 of file MagFieldUtils.py.

◆ run

python.MagFieldUtils.run = int(sys.argv[1])

Definition at line 187 of file MagFieldUtils.py.

CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
python.MagFieldUtils.getFieldForRun
def getFieldForRun(run, quiet=False, lumiblock=None)
Definition: MagFieldUtils.py:48
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