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

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

Member Function Documentation

◆ channel2PMT()

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

Definition at line 1522 of file TileCalibTools.py.

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

◆ getData()

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

Definition at line 1505 of file TileCalibTools.py.

1505 def getData(self, ros, drawer, channel, adc, iov=(MAXRUN,MAXLBK)):
1506 dictKey = (int(ros), int(drawer), int(channel), int(adc))
1507 data = self.__dataDict.get(dictKey,[])
1508 if self.__manyIOVs and len(data)>0:
1509 before= [i for i in sorted(data) if i[0] <= iov ]
1510 if len(before)>0:
1511 data = before[-1][1]
1512 else:
1513 data = []
1514 return data
1515
T * get(TKey *tobj)
get a TObject* from a TKey* (why can't a TObject be a TKey?)
Definition hcg.cxx:132

◆ getDict()

python.TileCalibTools.TileASCIIParser2.getDict ( self)

Definition at line 1517 of file TileCalibTools.py.

1517 def getDict(self):
1518 import copy
1519 return copy.deepcopy(self.__dataDict)
1520

◆ PMT2channel()

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

Definition at line 1551 of file TileCalibTools.py.

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

Member Data Documentation

◆ __dataDict

python.TileCalibTools.TileASCIIParser2.__dataDict = {}
private

Definition at line 1369 of file TileCalibTools.py.

◆ __manyIOVs

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

Definition at line 1370 of file TileCalibTools.py.

◆ __readGain

python.TileCalibTools.TileASCIIParser2.__readGain = readGain
private

Definition at line 1371 of file TileCalibTools.py.


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