ATLAS Offline Software
Public Member Functions | Private Attributes | List of all members
python.TileCalibTools.TileASCIIParser2 Class Reference
Inheritance diagram for python.TileCalibTools.TileASCIIParser2:
Collaboration diagram for python.TileCalibTools.TileASCIIParser2:

Public Member Functions

def __init__ (self, fileName, calibId="", readGain=True)
 
def getData (self, ros, drawer, channel, adc, iov=(MAXRUN, MAXLBK))
 
def getDict (self)
 
def channel2PMT (self, ros, drawer, chan)
 
def PMT2channel (self, partition, pmt)
 

Private Attributes

 __dataDict
 
 __manyIOVs
 
 __readGain
 

Detailed Description

This is a class capable of parsing TileCal conditions data stored in
ASCII files. This version of parser can be used when mutiple IOVs are
given in the file. First column is (run,lumi) pair in this case

Definition at line 1218 of file TileCalibTools.py.

Constructor & Destructor Documentation

◆ __init__()

def python.TileCalibTools.TileASCIIParser2.__init__ (   self,
  fileName,
  calibId = "",
  readGain = True 
)
Input:
- fileName          : input file name
- calibId           : like Ped, Las, ... or (r,l) or (run,lumi) but can be empty string as well
- readGain          : if False, no gain field in input file

Definition at line 1226 of file TileCalibTools.py.

1226  def __init__(self, fileName, calibId="", readGain=True):
1227  """
1228  Input:
1229  - fileName : input file name
1230  - calibId : like Ped, Las, ... or (r,l) or (run,lumi) but can be empty string as well
1231  - readGain : if False, no gain field in input file
1232  """
1233 
1234  TileCalibLogger.__init__(self,"TileASCIIParser2")
1235  self.__dataDict = {}
1236  self.__manyIOVs = (calibId=="(run,lumi)" or calibId=="(r,l)" )
1237  self.__readGain = readGain
1238  iov=(0,0)
1239  gain=-1
1240 
1241  try:
1242  lines = open(fileName,"r").readlines()
1243  except Exception as e:
1244  self.log().error( "TileCalibASCIIParser2::ERROR: Problem opening input file:" )
1245  self.log().error( e )
1246  return
1247 
1248  self.log().info("Parsing file %s",fileName)
1249  if len(calibId)>0:
1250  self.log().info("Looking for prefix %s",calibId)
1251 
1252  for line in lines:
1253  fields = line.strip().split()
1254  #=== ignore empty and comment lines
1255  if not len(fields) :
1256  continue
1257  if fields[0].startswith("#"):
1258  continue
1259 
1260  #=== read in fields
1261  if len(calibId)>0:
1262  pref = fields[0]
1263  frag = fields[1]
1264  chan = fields[2]
1265  if str(chan)[0:2].lower() == "pm":
1266  chan = self.PMT2channel(frag,fields.pop(2))
1267  if readGain:
1268  gain = fields[3]
1269  data = fields[4:]
1270  else:
1271  data = fields[3:]
1272 
1273  #=== check for correct calibId
1274  if self.__manyIOVs:
1275  iov=tuple(int(i) for i in pref[1:-1].split(","))
1276  if len(iov)!=2 or pref[0]!="(" or pref[-1]!=")":
1277  raise Exception("%s is not %s IOV" % (pref,calibId))
1278  elif pref!=calibId:
1279  raise Exception("%s is not calibId=%s" % (pref,calibId))
1280  else:
1281  frag = fields[0]
1282  chan = fields[1]
1283  if str(chan)[0:2].lower() == "pm":
1284  chan = self.PMT2channel(frag,fields.pop(2))
1285  if readGain:
1286  gain = fields[2]
1287  data = fields[3:]
1288  else:
1289  data = fields[2:]
1290 
1291  #=== decode fragment
1292  if frag.startswith('0x') or frag.startswith('-0x'):
1293  frg = int(frag,16)
1294  ros = frg>>8
1295  if frg<0:
1296  mod = (-frg)&255
1297  else:
1298  mod = frg&255
1299  elif (frag.startswith("AUX") or
1300  frag.startswith("LBA") or
1301  frag.startswith("LBC") or
1302  frag.startswith("EBA") or
1303  frag.startswith("EBC") or
1304  frag.startswith("ALL") or
1305  frag.startswith("XXX") ):
1306  part_dict = {'AUX':0,'LBA':1,'LBC':2,'EBA':3,'EBC':4,'ALL':5,'XXX':-1}
1307  partname = str(frag[0:3])
1308  ros=part_dict[partname]
1309  mod = int(frag[3:])-1
1310  else:
1311  raise Exception("Unknown fragment %s" % frag)
1312 
1313  chn = int(chan)
1314  adc = int(gain)
1315 
1316  #=== fill dictionary
1317  if ros<0:
1318  rosmin=0
1319  rosmax=5
1320  elif ros>=5:
1321  rosmin=1
1322  rosmax=5
1323  else:
1324  rosmin=ros
1325  rosmax=ros+1
1326 
1327  if mod<0 or mod>=64:
1328  modmin=0
1329  modmax=64
1330  else:
1331  modmin=mod
1332  modmax=mod+1
1333 
1334  allchannels=True
1335  if chn<-2:
1336  chnmin=0
1337  chnmax=-chn
1338  elif chn<0:
1339  chnmin=0
1340  chnmax=48
1341  allchannels=(chn==-1) # if chn=-2 only connected channels will be updated
1342  else:
1343  chnmin=chn
1344  chnmax=chn+1
1345 
1346  if adc<-1:
1347  adcmin=0
1348  adcmax=-adc
1349  elif adc<0:
1350  adcmin=0
1351  adcmax=2
1352  else:
1353  adcmin=adc
1354  adcmax=adc+1
1355 
1356  for ros in range(rosmin,rosmax):
1357  for mod in range(modmin,modmax):
1358  for chn in range(chnmin,chnmax):
1359  if allchannels or self.channel2PMT(ros,mod,chn)>0:
1360  for adc in range (adcmin,adcmax):
1361  dictKey = (ros,mod,chn,adc)
1362  if self.__manyIOVs:
1363  if dictKey in self.__dataDict:
1364  self.__dataDict[dictKey] += [(iov,data)]
1365  else:
1366  self.__dataDict[dictKey] = [(iov,data)]
1367  else:
1368  self.__dataDict[dictKey] = data
1369 

Member Function Documentation

◆ channel2PMT()

def python.TileCalibTools.TileASCIIParser2.channel2PMT (   self,
  ros,
  drawer,
  chan 
)

Definition at line 1388 of file TileCalibTools.py.

1388  def channel2PMT(self,ros,drawer,chan):
1389  "Convert channel numbet to PMT number, negative for disconnected channels"
1390  "This takes ros [1-4], drawer [0-63], chan [0-47]"
1391 
1392  chan2PMT_LB=[ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
1393  13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
1394  27, 26, 25, 30, 29, 28,-33,-32, 31, 36, 35, 34,
1395  39, 38, 37, 42, 41, 40, 45,-44, 43, 48, 47, 46 ]
1396 
1397  chan2PMT_EB=[ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
1398  13, 14, 15, 16, 17, 18,-19,-20, 21, 22, 23, 24,
1399  -27,-26,-25,-31,-32,-28, 33, 29, 30,-36,-35, 34,
1400  44, 38, 37, 43, 42, 41,-45,-39,-40,-48,-47,-46 ]
1401 
1402  chan2PMT_Sp=[ -1, -2, -3, -4, 5, 6, 7, 8, 9, 10, 11, 12, # first 4 do not exist
1403  13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, # PMT 19 and 20 exist
1404  -27,-26,-25,-31,-32,-28, 33, 29, 30,-36,-35, 34,
1405  44, 38, 37, 43, 42, 41,-45,-39,-40,-48,-47,-46 ]
1406 
1407  if ros <= 2:
1408  pmt = chan2PMT_LB[chan]
1409  elif (ros == 3 and drawer == 14) or (ros == 4 and drawer == 17):
1410  pmt = chan2PMT_Sp[chan]
1411  else:
1412  pmt = chan2PMT_EB[chan]
1413 
1414  return pmt
1415 

◆ getData()

def python.TileCalibTools.TileASCIIParser2.getData (   self,
  ros,
  drawer,
  channel,
  adc,
  iov = (MAXRUN,MAXLBK) 
)

Definition at line 1371 of file TileCalibTools.py.

1371  def getData(self, ros, drawer, channel, adc, iov=(MAXRUN,MAXLBK)):
1372  dictKey = (int(ros), int(drawer), int(channel), int(adc))
1373  data = self.__dataDict.get(dictKey,[])
1374  if self.__manyIOVs and len(data)>0:
1375  before= [i for i in sorted(data) if i[0] <= iov ]
1376  if len(before)>0:
1377  data = before[-1][1]
1378  else:
1379  data = []
1380  return data
1381 

◆ getDict()

def python.TileCalibTools.TileASCIIParser2.getDict (   self)

Definition at line 1383 of file TileCalibTools.py.

1383  def getDict(self):
1384  import copy
1385  return copy.deepcopy(self.__dataDict)
1386 

◆ PMT2channel()

def python.TileCalibTools.TileASCIIParser2.PMT2channel (   self,
  partition,
  pmt 
)

Definition at line 1417 of file TileCalibTools.py.

1417  def PMT2channel(self,partition,pmt):
1418  "Convert PMT number to channel numbet"
1419  "This takes partition (LBA,LBC,EBA,EBC) and pmt [1-48]"
1420 
1421  chan2PMT_LB=[ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
1422  13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
1423  27, 26, 25, 30, 29, 28, 33, 32, 31, 36, 35, 34,
1424  39, 38, 37, 42, 41, 40, 45, 44, 43, 48, 47, 46 ]
1425 
1426  chan2PMT_EB=[ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
1427  13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
1428  27, 26, 25, 31, 32, 28, 33, 29, 30, 36, 35, 34,
1429  44, 38, 37, 43, 42, 41, 45, 39, 40, 48, 47, 46 ]
1430 
1431  chan = -1
1432  pm=abs(int(pmt))
1433 
1434  if pm>0 and pm<=48:
1435  if str(partition)[0].upper() == "E":
1436  chan = chan2PMT_EB.index(pm)
1437  else:
1438  chan = chan2PMT_LB.index(pm)
1439 
1440  return chan
1441 
1442 #======================================================================
1443 #===
1444 #=== TileASCIIParser3
1445 #===
1446 #======================================================================
1447 
1448 #______________________________________________________________________

Member Data Documentation

◆ __dataDict

python.TileCalibTools.TileASCIIParser2.__dataDict
private

Definition at line 1235 of file TileCalibTools.py.

◆ __manyIOVs

python.TileCalibTools.TileASCIIParser2.__manyIOVs
private

Definition at line 1236 of file TileCalibTools.py.

◆ __readGain

python.TileCalibTools.TileASCIIParser2.__readGain
private

Definition at line 1237 of file TileCalibTools.py.


The documentation for this class was generated from the following file:
grepfile.info
info
Definition: grepfile.py:38
InDetSimDataHelpers::getData
const InDetSimData * getData(const InDetSimDataCollection &coll, const Identifier &id)
Definition: InDetSimDataDict.h:24
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
upper
int upper(int c)
Definition: LArBadChannelParser.cxx:49
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
DerivationFramework::TriggerMatchingUtils::sorted
std::vector< typename T::value_type > sorted(T begin, T end)
Helper function to create a sorted vector from an unsorted one.
python.processes.powheg.ZZ.ZZ.__init__
def __init__(self, base_directory, **kwargs)
Constructor: all process options are set here.
Definition: ZZ.py:18
Trk::open
@ open
Definition: BinningType.h:40
get
T * get(TKey *tobj)
get a TObject* from a TKey* (why can't a TObject be a TKey?)
Definition: hcg.cxx:127
str
Definition: BTagTrackIpAccessor.cxx:11
error
Definition: IImpactPoint3dEstimator.h:70
Trk::split
@ split
Definition: LayerMaterialProperties.h:38