ATLAS Offline Software
Loading...
Searching...
No Matches
python.TileCalibTools.TileASCIIParser2 Class Reference
Inheritance diagram for python.TileCalibTools.TileASCIIParser2:
Collaboration diagram for python.TileCalibTools.TileASCIIParser2:

Public Member Functions

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

Private Attributes

dict __dataDict = {}
tuple __manyIOVs = (calibId=="(run,lumi)" or calibId=="(r,l)" )
 __readGain = 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 1340 of file TileCalibTools.py.

Constructor & Destructor Documentation

◆ __init__()

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

1348 def __init__(self, fileName, calibId="", readGain=True):
1349 """
1350 Input:
1351 - fileName : input file name
1352 - calibId : like Ped, Las, ... or (r,l) or (run,lumi) but can be empty string as well
1353 - readGain : if False, no gain field in input file
1354 """
1355
1356 TileCalibLogger.__init__(self,"TileASCIIParser2")
1357 self.__dataDict = {}
1358 self.__manyIOVs = (calibId=="(run,lumi)" or calibId=="(r,l)" )
1359 self.__readGain = readGain
1360 iov=(0,0)
1361 gain=-1
1362
1363 try:
1364 lines = open(fileName,"r").readlines()
1365 except Exception as e:
1366 self.log().error( "TileCalibASCIIParser2::ERROR: Problem opening input file:" )
1367 self.log().error( e )
1368 return
1369
1370 self.log().info("Parsing file %s",fileName)
1371 if len(calibId)>0:
1372 self.log().info("Looking for prefix %s",calibId)
1373
1374 for line in lines:
1375 fields = line.strip().split()
1376 #=== ignore empty and comment lines
1377 if not len(fields) :
1378 continue
1379 if fields[0].startswith("#"):
1380 continue
1381
1382 #=== read in fields
1383 if len(calibId)>0:
1384 pref = fields[0]
1385 frag = fields[1]
1386 chan = fields[2]
1387 if str(chan)[0:2].lower() == "pm":
1388 chan = self.PMT2channel(frag,fields.pop(2))
1389 if readGain:
1390 gain = fields[3]
1391 data = fields[4:]
1392 else:
1393 data = fields[3:]
1394
1395 #=== check for correct calibId
1396 if self.__manyIOVs:
1397 iov=tuple(int(i) for i in pref[1:-1].split(","))
1398 if len(iov)!=2 or pref[0]!="(" or pref[-1]!=")":
1399 raise Exception("%s is not %s IOV" % (pref,calibId))
1400 elif pref!=calibId:
1401 raise Exception("%s is not calibId=%s" % (pref,calibId))
1402 else:
1403 frag = fields[0]
1404 chan = fields[1]
1405 if str(chan)[0:2].lower() == "pm":
1406 chan = self.PMT2channel(frag,fields.pop(2))
1407 if readGain:
1408 gain = fields[2]
1409 data = fields[3:]
1410 else:
1411 data = fields[2:]
1412
1413 #=== decode fragment
1414 if frag.startswith('0x') or frag.startswith('-0x'):
1415 frg = int(frag,16)
1416 ros = frg>>8
1417 if frg<0:
1418 mod = (-frg)&255
1419 else:
1420 mod = frg&255
1421 elif (frag.startswith("AUX") or
1422 frag.startswith("LBA") or
1423 frag.startswith("LBC") or
1424 frag.startswith("EBA") or
1425 frag.startswith("EBC") or
1426 frag.startswith("ALL") or
1427 frag.startswith("XXX") ):
1428 part_dict = {'AUX':0,'LBA':1,'LBC':2,'EBA':3,'EBC':4,'ALL':5,'XXX':-1}
1429 partname = str(frag[0:3])
1430 ros=part_dict[partname]
1431 mod = int(frag[3:])-1
1432 else:
1433 raise Exception("Unknown fragment %s" % frag)
1434
1435 chn = int(chan)
1436 adc = int(gain)
1437
1438 #=== fill dictionary
1439 if ros<0:
1440 rosmin=0
1441 rosmax=5
1442 elif ros>=5:
1443 rosmin=1
1444 rosmax=5
1445 else:
1446 rosmin=ros
1447 rosmax=ros+1
1448
1449 if mod<0 or mod>=64:
1450 modmin=0
1451 modmax=64
1452 else:
1453 modmin=mod
1454 modmax=mod+1
1455
1456 allchannels=True
1457 if chn<-2:
1458 chnmin=0
1459 chnmax=-chn
1460 elif chn<0:
1461 chnmin=0
1462 chnmax=48
1463 allchannels=(chn==-1) # if chn=-2 only connected channels will be updated
1464 else:
1465 chnmin=chn
1466 chnmax=chn+1
1467
1468 if adc<-1:
1469 adcmin=0
1470 adcmax=-adc
1471 elif adc<0:
1472 adcmin=0
1473 adcmax=2
1474 else:
1475 adcmin=adc
1476 adcmax=adc+1
1477
1478 for ros in range(rosmin,rosmax):
1479 for mod in range(modmin,modmax):
1480 for chn in range(chnmin,chnmax):
1481 if allchannels or self.channel2PMT(ros,mod,chn)>0:
1482 for adc in range (adcmin,adcmax):
1483 dictKey = (ros,mod,chn,adc)
1484 if self.__manyIOVs:
1485 if dictKey in self.__dataDict:
1486 self.__dataDict[dictKey] += [(iov,data)]
1487 else:
1488 self.__dataDict[dictKey] = [(iov,data)]
1489 else:
1490 self.__dataDict[dictKey] = data
1491
std::vector< std::string > split(const std::string &s, const std::string &t=":")
Definition hcg.cxx:177

Member Function Documentation

◆ channel2PMT()

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

Definition at line 1510 of file TileCalibTools.py.

1510 def channel2PMT(self,ros,drawer,chan):
1511 "Convert channel numbet to PMT number, negative for disconnected channels"
1512 "This takes ros [1-4], drawer [0-63], chan [0-47]"
1513
1514 chan2PMT_LB=[ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
1515 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
1516 27, 26, 25, 30, 29, 28,-33,-32, 31, 36, 35, 34,
1517 39, 38, 37, 42, 41, 40, 45,-44, 43, 48, 47, 46 ]
1518
1519 chan2PMT_EB=[ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
1520 13, 14, 15, 16, 17, 18,-19,-20, 21, 22, 23, 24,
1521 -27,-26,-25,-31,-32,-28, 33, 29, 30,-36,-35, 34,
1522 44, 38, 37, 43, 42, 41,-45,-39,-40,-48,-47,-46 ]
1523
1524 chan2PMT_Sp=[ -1, -2, -3, -4, 5, 6, 7, 8, 9, 10, 11, 12, # first 4 do not exist
1525 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, # PMT 19 and 20 exist
1526 -27,-26,-25,-31,-32,-28, 33, 29, 30,-36,-35, 34,
1527 44, 38, 37, 43, 42, 41,-45,-39,-40,-48,-47,-46 ]
1528
1529 if ros <= 2:
1530 pmt = chan2PMT_LB[chan]
1531 elif (ros == 3 and drawer == 14) or (ros == 4 and drawer == 17):
1532 pmt = chan2PMT_Sp[chan]
1533 else:
1534 pmt = chan2PMT_EB[chan]
1535
1536 return pmt
1537

◆ getData()

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

Definition at line 1493 of file TileCalibTools.py.

1493 def getData(self, ros, drawer, channel, adc, iov=(MAXRUN,MAXLBK)):
1494 dictKey = (int(ros), int(drawer), int(channel), int(adc))
1495 data = self.__dataDict.get(dictKey,[])
1496 if self.__manyIOVs and len(data)>0:
1497 before= [i for i in sorted(data) if i[0] <= iov ]
1498 if len(before)>0:
1499 data = before[-1][1]
1500 else:
1501 data = []
1502 return data
1503
T * get(TKey *tobj)
get a TObject* from a TKey* (why can't a TObject be a TKey?)
Definition hcg.cxx:130

◆ getDict()

python.TileCalibTools.TileASCIIParser2.getDict ( self)

Definition at line 1505 of file TileCalibTools.py.

1505 def getDict(self):
1506 import copy
1507 return copy.deepcopy(self.__dataDict)
1508

◆ PMT2channel()

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

Definition at line 1539 of file TileCalibTools.py.

1539 def PMT2channel(self,partition,pmt):
1540 "Convert PMT number to channel numbet"
1541 "This takes partition (LBA,LBC,EBA,EBC) and pmt [1-48]"
1542
1543 chan2PMT_LB=[ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
1544 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
1545 27, 26, 25, 30, 29, 28, 33, 32, 31, 36, 35, 34,
1546 39, 38, 37, 42, 41, 40, 45, 44, 43, 48, 47, 46 ]
1547
1548 chan2PMT_EB=[ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
1549 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
1550 27, 26, 25, 31, 32, 28, 33, 29, 30, 36, 35, 34,
1551 44, 38, 37, 43, 42, 41, 45, 39, 40, 48, 47, 46 ]
1552
1553 chan = -1
1554 pm=abs(int(pmt))
1555
1556 if pm>0 and pm<=48:
1557 if str(partition)[0].upper() == "E":
1558 chan = chan2PMT_EB.index(pm)
1559 else:
1560 chan = chan2PMT_LB.index(pm)
1561
1562 return chan
1563
1564#======================================================================
1565#===
1566#=== TileASCIIParser3
1567#===
1568#======================================================================
1569
1570#______________________________________________________________________
int upper(int c)

Member Data Documentation

◆ __dataDict

python.TileCalibTools.TileASCIIParser2.__dataDict = {}
private

Definition at line 1357 of file TileCalibTools.py.

◆ __manyIOVs

tuple python.TileCalibTools.TileASCIIParser2.__manyIOVs = (calibId=="(run,lumi)" or calibId=="(r,l)" )
private

Definition at line 1358 of file TileCalibTools.py.

◆ __readGain

python.TileCalibTools.TileASCIIParser2.__readGain = readGain
private

Definition at line 1359 of file TileCalibTools.py.


The documentation for this class was generated from the following file: