ATLAS Offline Software
LArRunFormat.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 # Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
4 
5 from CoolConvUtilities.AtlCoolLib import indirectOpen
6 
7 class LArRunInfo:
8  "Wrapper class to hold LAr run configuration information"
9  def __init__(self,nSamples,gainType,latency,firstSample,format,runType):
10  self._nSamples = nSamples
11  self._gainType = gainType
12  self._latency = latency
13  self._firstSample = firstSample
14  self._format = format
15  self._runType = runType
16 
17  def nSamples(self):
18  "Number of samples readout from FEB"
19  return self._nSamples
20 
21  def gainType(self):
22  "gainType: 0=auto,1=L,2=M,3=H,4=LM,5=LH,6=ML,7=MH,8=HL,9=HM,10=LMH,11=LHM,12=MLH,13=MHL,14=HLM,15=HML"
23  return self._gainType
24 
25  def latency(self):
26  "latency between l1 trigger and readout"
27  return self._latency
28 
29  def firstSample(self):
30  "firstsample"
31  return self._firstSample
32 
33  def format(self):
34  "format:0=Transparent, 1=Format 1, 2=Format 2"
35  return self._format
36 
37  def runType(self):
38  "runType: 0=RawData, 1=RawDataResult, 2=Result"
39  return self._runType
40 
41  def stringFormat(self):
42  if (self._format == 0) :
43  return 'transparent'
44  if (self._format == 1) :
45  return 'Format1'
46  if (self._format == 2) :
47  return 'Format2'
48 
49  def stringRunType(self):
50  if (self._runType ==0) :
51  return 'RawData'
52  if (self._runType ==1) :
53  return 'RawDataResult'
54  if (self._runType ==2) :
55  return 'Result'
56 
57 
58 def getLArFormatForRun(run,quiet=False,connstring="COOLONL_LAR/CONDBR2"):
59  from AthenaCommon.Logging import logging
60  mlog_LRF = logging.getLogger( 'getLArRunFormatForRun' )
61 
62  mlog_LRF.info("Connecting to database %s", connstring)
63 
64  mlog_LRF.info("Found LAr info for run %i",run)
65  runDB=indirectOpen(connstring)
66  if (runDB is None):
67  mlog_LRF.error("Cannot connect to database %s",connstring)
68  raise RuntimeError("getLArFormatForRun ERROR: Cannot connect to database %s",connstring)
69  format=None
70  nSamples=None
71  gainType=None
72  runType=None
73  latency=None
74  firstSample=None
75  try:
76  folder=runDB.getFolder('/LAR/Configuration/RunLog')
77  runiov=run << 32
78  obj=folder.findObject(runiov,0)
79  payload=obj.payload()
80  format=payload['format']
81  nSamples=ord(payload['nbOfSamples'])
82  gainType=payload['gainType']
83  runType=payload['runType']
84  latency=ord(payload['l1aLatency'])
85  firstSample=ord(payload['firstSample'])
86  except Exception:
87  mlog_LRF.warning("No information in /LAR/Configuration/RunLog for run %i", run)
88  #mlog_LRF.warning(e)
89  return None
90  runDB.closeDatabase()
91  mlog_LRF.info("Found info for run %i", run)
92  return LArRunInfo(nSamples,gainType,latency,firstSample,format,runType)
93 
95  "Wrapper class to hold LAr DT run configuration information"
96  def __init__(self,streamTypes, streamLengths, timing, adccalib):
97  self._sTypes = streamTypes
98  self._sLengths = streamLengths
99  self._tim = timing
100  self._adcc = adccalib
101 
102  def streamTypes(self):
103  return self._sTypes
104 
105  def streamLengths(self):
106  return self._sLengths
107 
108  def timing(self):
109  return self._tim
110 
111  def ADCCalib(self):
112  return self._adcc
113 
114 def getLArDTInfoForRun(run,quiet=False,connstring="COOLONL_LAR/CONDBR2"):
115  from AthenaCommon.Logging import logging
116  mlog_LRF = logging.getLogger( 'getLArDTRunInfoForRun' )
117  mlog_LRF.info("Connecting to database %s", connstring)
118 
119  mlog_LRF.info("Found DT info for run %i",run)
120  runDB=indirectOpen(connstring)
121  if (runDB is None):
122  mlog_LRF.error("Cannot connect to database %s",connstring)
123  raise RuntimeError("getLArFormatForRun ERROR: Cannot connect to database %s",connstring)
124  typesMap={0:"ADC", 1:"RawADC", 2:"Energy", 3:"SelectedEnergy",15:"Invalid"}
125  sTypes=[]
126  sLengths=[]
127  timing="LAR"
128  adccalib=0
129  mux=[]
130  try:
131  folder=runDB.getFolder('/LAR/Configuration/RunLogDT')
132  runiov=run << 32
133  obj=folder.findObject(runiov,0)
134  payload=obj.payload()
135  timing=payload['timing_configuration']
136  recipe=payload['recipe_tdaq']
137  mux.append(ord(payload['mux_setting_0']))
138  mux.append(ord(payload['mux_setting_1']))
139  adccalib=payload['ADCCalibMode']
140  except Exception:
141  mlog_LRF.warning("No information in /LAR/Configuration/RunLogDT for run %i", run)
142  mlog_LRF.warning("Using defaults: MUX0: ADC MUX1: ET_ID receipe: at0_bc5-at1_bc1_ts1-q")
143  recipe="at0_bc5-at1_bc1_ts1-q"
144  mux.append(0)
145  mux.append(3)
146 
147  runDB.closeDatabase()
148  mlog_LRF.info("Found DT info for run %d", run)
149  print(mux)
150  # parse recipe string of the type at0_bcX-at1_bcY...
151  for s,m in ["at0_bc",0],["at1_bc",1]:
152  pos=recipe.find(s)
153  if pos >=0:
154  n=-1
155  try:
156  n=int(recipe[pos+6:pos+8])
157  except Exception:
158  try:
159  n=int(recipe[pos+6:pos+7])
160  except Exception:
161  mlog_LRF.warning("could not decode %s",recipe[pos+6:])
162  if n>=0:
163  sLengths.append(n)
164  if mux[m] in typesMap.keys():
165  sTypes.append(typesMap[mux[m]])
166  else:
167  sTypes.append(15)
168  pass
169  pass
170 
171  return LArDTRunInfo(sTypes, sLengths, timing, adccalib)
172 
173 # command line driver for convenience
174 if __name__=='__main__':
175  import sys
176  if len(sys.argv)!=2:
177  print("Syntax",sys.argv[0],'<run>')
178  sys.exit(-1)
179  run=int(sys.argv[1])
180  myformat=getLArFormatForRun(run, connstring="COOLONL_LAR/CONDBR2")
181  if (myformat is not None):
182  print(" LAr run configuration: Nsamples:%d GainType:%d Latency:%d FirstSample:%d Format:%s runType:%s" % (myformat.nSamples(),myformat.gainType(),myformat.latency(),myformat.firstSample(),myformat.stringFormat(),myformat.stringRunType()))
183  else:
184  print(" LAr run information not available")
185 
186  myformat1=getLArDTInfoForRun(run, connstring="COOLONL_LAR/CONDBR2")
187  if (myformat1 is not None):
188  print(" LAr DT run configuration: timing:%s adccalib:%d" % (myformat1.timing(),myformat1.ADCCalib()))
189  for i in range(0,len(myformat1.streamTypes())):
190  print(" stream: %s size: %d" % (myformat1.streamTypes()[i], myformat1.streamLengths()[i]))
191  else:
192  print(" LAr DT run information not available")
python.LArRunFormat.LArDTRunInfo._adcc
_adcc
Definition: LArRunFormat.py:100
python.LArRunFormat.LArRunInfo.nSamples
def nSamples(self)
Definition: LArRunFormat.py:17
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
python.LArRunFormat.LArRunInfo._runType
_runType
Definition: LArRunFormat.py:15
python.LArRunFormat.LArRunInfo.gainType
def gainType(self)
Definition: LArRunFormat.py:21
python.LArRunFormat.LArDTRunInfo
Definition: LArRunFormat.py:94
python.LArRunFormat.LArDTRunInfo._tim
_tim
Definition: LArRunFormat.py:99
python.LArRunFormat.LArRunInfo.firstSample
def firstSample(self)
Definition: LArRunFormat.py:29
python.LArRunFormat.LArDTRunInfo.streamTypes
def streamTypes(self)
Definition: LArRunFormat.py:102
python.LArRunFormat.LArRunInfo
Definition: LArRunFormat.py:7
python.LArRunFormat.LArDTRunInfo.streamLengths
def streamLengths(self)
Definition: LArRunFormat.py:105
python.LArRunFormat.LArRunInfo.stringRunType
def stringRunType(self)
Definition: LArRunFormat.py:49
python.LArRunFormat.LArDTRunInfo.timing
def timing(self)
Definition: LArRunFormat.py:108
python.LArRunFormat.getLArDTInfoForRun
def getLArDTInfoForRun(run, quiet=False, connstring="COOLONL_LAR/CONDBR2")
Definition: LArRunFormat.py:114
python.LArRunFormat.LArRunInfo.runType
def runType(self)
Definition: LArRunFormat.py:37
python.LArRunFormat.LArRunInfo.stringFormat
def stringFormat(self)
Definition: LArRunFormat.py:41
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
python.LArRunFormat.LArRunInfo._latency
_latency
Definition: LArRunFormat.py:12
python.LArRunFormat.LArDTRunInfo.ADCCalib
def ADCCalib(self)
Definition: LArRunFormat.py:111
python.LArRunFormat.LArDTRunInfo._sTypes
_sTypes
Definition: LArRunFormat.py:97
python.LArRunFormat.LArRunInfo.latency
def latency(self)
Definition: LArRunFormat.py:25
python.LArRunFormat.getLArFormatForRun
def getLArFormatForRun(run, quiet=False, connstring="COOLONL_LAR/CONDBR2")
Definition: LArRunFormat.py:58
python.LArRunFormat.LArRunInfo._firstSample
_firstSample
Definition: LArRunFormat.py:13
python.LArRunFormat.LArRunInfo._format
_format
Definition: LArRunFormat.py:14
Muon::print
std::string print(const MuPatSegment &)
Definition: MuonTrackSteering.cxx:28
python.LArRunFormat.LArRunInfo.format
def format(self)
Definition: LArRunFormat.py:33
python.LArRunFormat.LArRunInfo._nSamples
_nSamples
Definition: LArRunFormat.py:10
python.LArRunFormat.LArDTRunInfo.__init__
def __init__(self, streamTypes, streamLengths, timing, adccalib)
Definition: LArRunFormat.py:96
python.LArRunFormat.LArRunInfo._gainType
_gainType
Definition: LArRunFormat.py:11
python.AtlCoolLib.indirectOpen
def indirectOpen(coolstr, readOnly=True, debug=False)
Definition: AtlCoolLib.py:130
python.LArRunFormat.LArDTRunInfo._sLengths
_sLengths
Definition: LArRunFormat.py:98
python.LArRunFormat.LArRunInfo.__init__
def __init__(self, nSamples, gainType, latency, firstSample, format, runType)
Definition: LArRunFormat.py:9