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 1223 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 1231 of file TileCalibTools.py.

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

Member Function Documentation

◆ channel2PMT()

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

Definition at line 1393 of file TileCalibTools.py.

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

◆ getData()

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

Definition at line 1376 of file TileCalibTools.py.

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

◆ getDict()

def python.TileCalibTools.TileASCIIParser2.getDict (   self)

Definition at line 1388 of file TileCalibTools.py.

1388  def getDict(self):
1389  import copy
1390  return copy.deepcopy(self.__dataDict)
1391 

◆ PMT2channel()

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

Definition at line 1422 of file TileCalibTools.py.

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

Member Data Documentation

◆ __dataDict

python.TileCalibTools.TileASCIIParser2.__dataDict
private

Definition at line 1240 of file TileCalibTools.py.

◆ __manyIOVs

python.TileCalibTools.TileASCIIParser2.__manyIOVs
private

Definition at line 1241 of file TileCalibTools.py.

◆ __readGain

python.TileCalibTools.TileASCIIParser2.__readGain
private

Definition at line 1242 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
upper
int upper(int c)
Definition: LArBadChannelParser.cxx:49
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:194
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
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:127
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