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 1271 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 1279 of file TileCalibTools.py.

1279  def __init__(self, fileName, calibId="", readGain=True):
1280  """
1281  Input:
1282  - fileName : input file name
1283  - calibId : like Ped, Las, ... or (r,l) or (run,lumi) but can be empty string as well
1284  - readGain : if False, no gain field in input file
1285  """
1286 
1287  TileCalibLogger.__init__(self,"TileASCIIParser2")
1288  self.__dataDict = {}
1289  self.__manyIOVs = (calibId=="(run,lumi)" or calibId=="(r,l)" )
1290  self.__readGain = readGain
1291  iov=(0,0)
1292  gain=-1
1293 
1294  try:
1295  lines = open(fileName,"r").readlines()
1296  except Exception as e:
1297  self.log().error( "TileCalibASCIIParser2::ERROR: Problem opening input file:" )
1298  self.log().error( e )
1299  return
1300 
1301  self.log().info("Parsing file %s",fileName)
1302  if len(calibId)>0:
1303  self.log().info("Looking for prefix %s",calibId)
1304 
1305  for line in lines:
1306  fields = line.strip().split()
1307  #=== ignore empty and comment lines
1308  if not len(fields) :
1309  continue
1310  if fields[0].startswith("#"):
1311  continue
1312 
1313  #=== read in fields
1314  if len(calibId)>0:
1315  pref = fields[0]
1316  frag = fields[1]
1317  chan = fields[2]
1318  if str(chan)[0:2].lower() == "pm":
1319  chan = self.PMT2channel(frag,fields.pop(2))
1320  if readGain:
1321  gain = fields[3]
1322  data = fields[4:]
1323  else:
1324  data = fields[3:]
1325 
1326  #=== check for correct calibId
1327  if self.__manyIOVs:
1328  iov=tuple(int(i) for i in pref[1:-1].split(","))
1329  if len(iov)!=2 or pref[0]!="(" or pref[-1]!=")":
1330  raise Exception("%s is not %s IOV" % (pref,calibId))
1331  elif pref!=calibId:
1332  raise Exception("%s is not calibId=%s" % (pref,calibId))
1333  else:
1334  frag = fields[0]
1335  chan = fields[1]
1336  if str(chan)[0:2].lower() == "pm":
1337  chan = self.PMT2channel(frag,fields.pop(2))
1338  if readGain:
1339  gain = fields[2]
1340  data = fields[3:]
1341  else:
1342  data = fields[2:]
1343 
1344  #=== decode fragment
1345  if frag.startswith('0x') or frag.startswith('-0x'):
1346  frg = int(frag,16)
1347  ros = frg>>8
1348  if frg<0:
1349  mod = (-frg)&255
1350  else:
1351  mod = frg&255
1352  elif (frag.startswith("AUX") or
1353  frag.startswith("LBA") or
1354  frag.startswith("LBC") or
1355  frag.startswith("EBA") or
1356  frag.startswith("EBC") or
1357  frag.startswith("ALL") or
1358  frag.startswith("XXX") ):
1359  part_dict = {'AUX':0,'LBA':1,'LBC':2,'EBA':3,'EBC':4,'ALL':5,'XXX':-1}
1360  partname = str(frag[0:3])
1361  ros=part_dict[partname]
1362  mod = int(frag[3:])-1
1363  else:
1364  raise Exception("Unknown fragment %s" % frag)
1365 
1366  chn = int(chan)
1367  adc = int(gain)
1368 
1369  #=== fill dictionary
1370  if ros<0:
1371  rosmin=0
1372  rosmax=5
1373  elif ros>=5:
1374  rosmin=1
1375  rosmax=5
1376  else:
1377  rosmin=ros
1378  rosmax=ros+1
1379 
1380  if mod<0 or mod>=64:
1381  modmin=0
1382  modmax=64
1383  else:
1384  modmin=mod
1385  modmax=mod+1
1386 
1387  allchannels=True
1388  if chn<-2:
1389  chnmin=0
1390  chnmax=-chn
1391  elif chn<0:
1392  chnmin=0
1393  chnmax=48
1394  allchannels=(chn==-1) # if chn=-2 only connected channels will be updated
1395  else:
1396  chnmin=chn
1397  chnmax=chn+1
1398 
1399  if adc<-1:
1400  adcmin=0
1401  adcmax=-adc
1402  elif adc<0:
1403  adcmin=0
1404  adcmax=2
1405  else:
1406  adcmin=adc
1407  adcmax=adc+1
1408 
1409  for ros in range(rosmin,rosmax):
1410  for mod in range(modmin,modmax):
1411  for chn in range(chnmin,chnmax):
1412  if allchannels or self.channel2PMT(ros,mod,chn)>0:
1413  for adc in range (adcmin,adcmax):
1414  dictKey = (ros,mod,chn,adc)
1415  if self.__manyIOVs:
1416  if dictKey in self.__dataDict:
1417  self.__dataDict[dictKey] += [(iov,data)]
1418  else:
1419  self.__dataDict[dictKey] = [(iov,data)]
1420  else:
1421  self.__dataDict[dictKey] = data
1422 

Member Function Documentation

◆ channel2PMT()

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

Definition at line 1441 of file TileCalibTools.py.

1441  def channel2PMT(self,ros,drawer,chan):
1442  "Convert channel numbet to PMT number, negative for disconnected channels"
1443  "This takes ros [1-4], drawer [0-63], chan [0-47]"
1444 
1445  chan2PMT_LB=[ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
1446  13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
1447  27, 26, 25, 30, 29, 28,-33,-32, 31, 36, 35, 34,
1448  39, 38, 37, 42, 41, 40, 45,-44, 43, 48, 47, 46 ]
1449 
1450  chan2PMT_EB=[ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
1451  13, 14, 15, 16, 17, 18,-19,-20, 21, 22, 23, 24,
1452  -27,-26,-25,-31,-32,-28, 33, 29, 30,-36,-35, 34,
1453  44, 38, 37, 43, 42, 41,-45,-39,-40,-48,-47,-46 ]
1454 
1455  chan2PMT_Sp=[ -1, -2, -3, -4, 5, 6, 7, 8, 9, 10, 11, 12, # first 4 do not exist
1456  13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, # PMT 19 and 20 exist
1457  -27,-26,-25,-31,-32,-28, 33, 29, 30,-36,-35, 34,
1458  44, 38, 37, 43, 42, 41,-45,-39,-40,-48,-47,-46 ]
1459 
1460  if ros <= 2:
1461  pmt = chan2PMT_LB[chan]
1462  elif (ros == 3 and drawer == 14) or (ros == 4 and drawer == 17):
1463  pmt = chan2PMT_Sp[chan]
1464  else:
1465  pmt = chan2PMT_EB[chan]
1466 
1467  return pmt
1468 

◆ getData()

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

Definition at line 1424 of file TileCalibTools.py.

1424  def getData(self, ros, drawer, channel, adc, iov=(MAXRUN,MAXLBK)):
1425  dictKey = (int(ros), int(drawer), int(channel), int(adc))
1426  data = self.__dataDict.get(dictKey,[])
1427  if self.__manyIOVs and len(data)>0:
1428  before= [i for i in sorted(data) if i[0] <= iov ]
1429  if len(before)>0:
1430  data = before[-1][1]
1431  else:
1432  data = []
1433  return data
1434 

◆ getDict()

def python.TileCalibTools.TileASCIIParser2.getDict (   self)

Definition at line 1436 of file TileCalibTools.py.

1436  def getDict(self):
1437  import copy
1438  return copy.deepcopy(self.__dataDict)
1439 

◆ PMT2channel()

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

Definition at line 1470 of file TileCalibTools.py.

1470  def PMT2channel(self,partition,pmt):
1471  "Convert PMT number to channel numbet"
1472  "This takes partition (LBA,LBC,EBA,EBC) and pmt [1-48]"
1473 
1474  chan2PMT_LB=[ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
1475  13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
1476  27, 26, 25, 30, 29, 28, 33, 32, 31, 36, 35, 34,
1477  39, 38, 37, 42, 41, 40, 45, 44, 43, 48, 47, 46 ]
1478 
1479  chan2PMT_EB=[ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
1480  13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
1481  27, 26, 25, 31, 32, 28, 33, 29, 30, 36, 35, 34,
1482  44, 38, 37, 43, 42, 41, 45, 39, 40, 48, 47, 46 ]
1483 
1484  chan = -1
1485  pm=abs(int(pmt))
1486 
1487  if pm>0 and pm<=48:
1488  if str(partition)[0].upper() == "E":
1489  chan = chan2PMT_EB.index(pm)
1490  else:
1491  chan = chan2PMT_LB.index(pm)
1492 
1493  return chan
1494 
1495 #======================================================================
1496 #===
1497 #=== TileASCIIParser3
1498 #===
1499 #======================================================================
1500 
1501 #______________________________________________________________________

Member Data Documentation

◆ __dataDict

python.TileCalibTools.TileASCIIParser2.__dataDict
private

Definition at line 1288 of file TileCalibTools.py.

◆ __manyIOVs

python.TileCalibTools.TileASCIIParser2.__manyIOVs
private

Definition at line 1289 of file TileCalibTools.py.

◆ __readGain

python.TileCalibTools.TileASCIIParser2.__readGain
private

Definition at line 1290 of file TileCalibTools.py.


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