ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
LArCalorimeter
LArExample
LArConditionsCommon
python
LArIdHelperStandalone.py
Go to the documentation of this file.
1
# Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
2
from
PyCool
import
cool
3
from
CoolConvUtilities.AtlCoolLib
import
indirectOpen
4
import
ROOT
5
import
os,sys
6
from
AthenaCommon.Logging
import
logging
7
8
def
IdToNum
(ident):
9
return
ident.get_identifier32().get_compact()
10
11
def
NumToId
(idnum):
12
return
ROOT.Identifier(ROOT.Identifier32(idnum))
13
14
15
class
LArIdHelper
:
16
def
__init__
(self):
17
self.
_msg
=logging.getLogger(
"LArIdHelper"
)
18
#Set up LArOnlineID helper class in standalone mode (from xml file)
19
from
ROOT
import
IdDictParser
20
parser=
IdDictParser
()
21
#Get xml files:
22
xmlpath=
None
23
for
dd
in
os.getenv(
'XMLPATH'
).
split
(os.pathsep):
24
d=dd+
"/IdDictParser/ATLAS_IDS.xml"
25
if
os.access(d,os.R_OK):
26
xmlpath=dd
27
break
28
if
not
xmlpath:
29
self.
_msg
.
error
(
"unable to locate identifier dictionaries in $XMLPATH"
)
30
sys.exit(-1)
31
32
parser.register_external_entity(
"LArCalorimeter"
,xmlpath+
"/IdDictParser/IdDictLArCalorimeter_DC3-05-Comm-01.xml"
)
33
parser.register_external_entity(
"Calorimeter"
,xmlpath+
"/IdDictParser/IdDictCalorimeter_L1Onl.xml"
)
34
parser.register_external_entity(
"TileCalorimeter"
,xmlpath+
"/IdDictParser/IdDictTileCalorimeter.xml"
)
35
36
37
idd = parser.parse(xmlpath+
"/IdDictParser/ATLAS_IDS.xml"
)
38
from
ROOT
import
LArOnlineID
39
self.
_larOnlHelper
=
LArOnlineID
()
40
stat=self.
_larOnlHelper
.initialize_from_dictionary(idd)
41
if
stat==1:
42
self.
_msg
.
error
(
"failed to init LArOnlineID"
)
43
sys.exit(-1)
44
45
46
from
ROOT
import
LArEM_ID, LArHEC_ID, LArFCAL_ID, LArMiniFCAL_ID, TileID
47
48
self.
_allHelpers
=[]
49
for
subHelper
in
(LArEM_ID, LArHEC_ID, LArFCAL_ID, LArMiniFCAL_ID, TileID):
50
helper=subHelper()
51
helper.set_do_neighbours(
False
)
52
stat=helper.initialize_from_dictionary(idd)
53
if
stat==1:
54
self.
_msg
.
error
(
"failed to init"
+ str(subHelper))
55
else
:
56
self.
_allHelpers
.append(helper)
57
pass
58
from
ROOT
import
CaloCell_ID
59
self.
_caloHelper
=
CaloCell_ID
(*self.
_allHelpers
)
60
self.
_caloHelper
.initialize_from_dictionary(idd)
61
#Note: It's important that all sub-helpers are part of this class. The CaloCell_ID keeps pointers to the individual sub-helpers,
62
#but python's garbage collector doesn't know about this relationship. So it may delete the sub-helpers at any time.
63
64
self.
_cabling
=
None
65
return
66
67
68
def
larOnlHelper
(self):
69
return
self.
_larOnlHelper
70
71
def
caloHelper
(self):
72
return
self.
_caloHelper
73
74
def
getCabling
(self):
75
if
self.
_cabling
:
return
self.
_cabling
76
77
lardb=indirectOpen(
"COOLONL_LAR/CONDBR2"
)
78
f=lardb.getFolder(
"/LAR/Identifier/OnOffIdMap"
)
79
ptr=f.findObject(cool.ValidityKeyMax-1,cool.ChannelId(0),
"LARIdentifierOnOffIdMap-RUN2-001"
)
80
payload=ptr.payload()[
"OnlineHashToOfflineId"
]
81
on2off=payload.read()
82
nChans=int(payload.size()/4)
83
84
self.
_cabling
=ROOT.LArOnOffIdMapping(self.
_larOnlHelper
,self.
_caloHelper
)
85
onlHash2OflIdVec=self.
_cabling
.getOnlHash2OflId()
86
oflHash2OnlIdVec=self.
_cabling
.getOflHash2OnId()
87
88
89
i=0
90
nConnected=0
91
iChan=0
92
while
(iChan<nChans):
93
idnum=int.from_bytes(on2off[i:i+4],
'little'
)
94
#self._msg.debug("From Blob[%i]=0x%x" % (iChan,idnum))
95
oflId=ROOT.Identifier(ROOT.Identifier32(idnum))
96
if
oflId.is_valid():
97
oflHash=self.
_caloHelper
.calo_cell_hash(oflId)
98
onlHash=ROOT.IdentifierHash(iChan)
99
if
oflHash.value()>=oflHash2OnlIdVec.size():
100
self.
_msg
.
error
(
"invalid offline hash %i"
, oflHash.value())
101
return
102
103
if
onlHash.value()>=onlHash2OflIdVec.size():
104
self.
_msg
.
error
(
"invalid offline hash %i"
, onlHash.value())
105
return
106
nConnected+=1
107
onlId=self.
_larOnlHelper
.channel_Id(onlHash)
108
onlHash2OflIdVec[iChan]=oflId
109
oflHash2OnlIdVec[oflHash.value()]=onlId
110
pass
111
else
:
112
#print ("idnum %i give invalid offline id 0x%x",(idnum,oflId.get_identifier32().get_compact()))
113
pass
114
i+=4
115
iChan+=1
116
pass
117
118
self.
_msg
.info(
"Found identifier mapping for %i connected channels"
, nConnected)
119
120
return
self.
_cabling
121
122
123
if
__name__==
"__main__"
:
124
125
#usage example & self-test
126
c=
LArIdHelper
()
127
cc=c.getCabling()
128
129
onlId1=
NumToId
(978347776)
130
oflId1=
IdToNum
(cc.cnvToIdentifier(onlId1))
131
assert(oflId1==740295168)
132
133
134
#cell_id (const int subCalo,
135
# const int barec_or_posneg,
136
# const int sampling_or_fcalmodule,
137
# const int region_or_dummy,
138
# const int eta,
139
# const int phi ) const;
140
141
oflId2=c.caloHelper().cell_id(0,
#LArEM
142
-3,
#EMECIW-C
143
1,
#layer 0
144
0,
#region 0
145
1,
#ieta
146
0,
#iphi
147
)
148
oflId2Num=
IdToNum
(oflId2)
149
print
(oflId2Num)
150
assert(oflId2Num==740295168)
151
152
onlId2=cc.createSignalChannelID(oflId2)
153
assert(c.larOnlHelper().channel(onlId2)==103)
#Channel on FrontEnd board
154
assert(c.larOnlHelper().feedthrough(onlId2)==10)
#Feed-though number
155
156
onlId2Num=
IdToNum
(onlId2)
157
assert(onlId2Num==978347776)
158
CaloCell_ID
Helper class for offline cell identifiers.
Definition
CaloCell_ID.h:34
IdDictParser
Definition
IdDictParser.h:21
LArOnlineID
Definition
LArOnlineID.h:21
python.LArIdHelperStandalone.LArIdHelper
Definition
LArIdHelperStandalone.py:15
python.LArIdHelperStandalone.LArIdHelper._allHelpers
list _allHelpers
Definition
LArIdHelperStandalone.py:48
python.LArIdHelperStandalone.LArIdHelper.__init__
__init__(self)
Definition
LArIdHelperStandalone.py:16
python.LArIdHelperStandalone.LArIdHelper.caloHelper
caloHelper(self)
Definition
LArIdHelperStandalone.py:71
python.LArIdHelperStandalone.LArIdHelper.getCabling
getCabling(self)
Definition
LArIdHelperStandalone.py:74
python.LArIdHelperStandalone.LArIdHelper._msg
_msg
Definition
LArIdHelperStandalone.py:17
python.LArIdHelperStandalone.LArIdHelper._caloHelper
_caloHelper
Definition
LArIdHelperStandalone.py:59
python.LArIdHelperStandalone.LArIdHelper.larOnlHelper
larOnlHelper(self)
Definition
LArIdHelperStandalone.py:68
python.LArIdHelperStandalone.LArIdHelper._cabling
return self._cabling _cabling
Definition
LArIdHelperStandalone.py:64
python.LArIdHelperStandalone.LArIdHelper._larOnlHelper
_larOnlHelper
Definition
LArIdHelperStandalone.py:39
split
std::vector< std::string > split(const std::string &s, const std::string &t=":")
Definition
hcg.cxx:179
error
Definition
IImpactPoint3dEstimator.h:72
python.LArIdHelperStandalone.NumToId
NumToId(idnum)
Definition
LArIdHelperStandalone.py:11
python.LArIdHelperStandalone.IdToNum
IdToNum(ident)
Definition
LArIdHelperStandalone.py:8
Generated on
for ATLAS Offline Software by
1.17.0