ATLAS Offline Software
LArIdMapConvert.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include "LArIdMapConvert.h"
6 
9 #include "CoralBase/Blob.h"
10 
11 #include <fstream>
12 
14  ISvcLocator* pSvcLocator ) :
15  ::AthAlgorithm( name, pSvcLocator ),
16  m_onlineID(nullptr),
17  m_caloCellID(nullptr)
18 {
19 
20 }
21 
23 
24 {}
25 
27 
28  ATH_CHECK(detStore()->retrieve(m_onlineID, "LArOnlineID"));
29 
30  ATH_CHECK(detStore()->retrieve(m_caloCellID, "CaloCell_ID"));
31 
33 
34  return StatusCode::SUCCESS;
35 }
36 
38 {
39 
40  return StatusCode::SUCCESS;
41 }
42 
43 
45 
46  const uint32_t onlHashMax=m_onlineID->channelHashMax();
47 
49  const LArOnOffIdMapping* cabling{*cablingHdl};
50  if(!cabling) {
51  ATH_MSG_ERROR( "Do not have cabling mapping from key " << m_cablingKey.key() );
52  return StatusCode::FAILURE;
53  }
55  const LArCalibLineMapping *clCont {*clHdl};
56  if(!clCont) {
57  ATH_MSG_ERROR( "Do not have calib line mapping !!!" );
58  return StatusCode::FAILURE;
59  }
60 
61  coral::AttributeListSpecification* spec_onOff = new coral::AttributeListSpecification();
62  spec_onOff->extend("OnlineHashToOfflineId", "blob");
63  spec_onOff->extend<unsigned>("version");
64  AthenaAttributeList* al_onOff = new AthenaAttributeList(*spec_onOff);
65  coral::Blob& blobOnOff=(*al_onOff)["OnlineHashToOfflineId"].data<coral::Blob>();
66  (*al_onOff)["version"].setValue(0U);
67  blobOnOff.resize(onlHashMax*sizeof(uint32_t));
68 
69  spec_onOff->release();
70  // cppcheck-suppress memleak
71  spec_onOff = nullptr;
72 
73  coral::AttributeListSpecification* spec_calib = new coral::AttributeListSpecification();
74  spec_calib->extend("OnlineHashToCalibIds", "blob");
75  spec_calib->extend<unsigned>("version");
76  AthenaAttributeList* al_calib = new AthenaAttributeList(*spec_calib);
77  coral::Blob& blobCalib=(*al_calib)["OnlineHashToCalibIds"].data<coral::Blob>();
78  (*al_calib)["version"].setValue(0U);
79  blobCalib.resize(onlHashMax*sizeof(uint32_t)*3); //Bigger than necessary
80 
81  spec_calib->release();
82  // cppcheck-suppress memleak
83  spec_calib = nullptr;
84 
85  uint32_t* pBlobOnOff=static_cast<uint32_t*>(blobOnOff.startingAddress());
86  uint32_t* pBlobCalib=static_cast<uint32_t*>(blobCalib.startingAddress());
87 
88  size_t index=0;
89  size_t calibIndex=0;
90 
91  std::vector<unsigned> calibHist(5,0);
92 
93  std::ofstream outfile("identifiers.txt");
94 
95  outfile << "hash id bec pn FT SL chan id calo pn sampl reg eta phi calib" << std::endl;
96 
97  for (uint32_t onlHash=0;onlHash<onlHashMax;++onlHash) {
98  const HWIdentifier hwid=m_onlineID->channel_Id(onlHash);
99  print(hwid,outfile);
100  const Identifier id=cabling->cnvToIdentifierFromHash(onlHash);
101  pBlobOnOff[index++]=id.get_identifier32().get_compact();
102 
103  const std::vector<HWIdentifier>& calibIDs=clCont->calibSlotLine(hwid);
104  const size_t nCalibLines=calibIDs.size();
105  (calibHist[nCalibLines])++;
106  pBlobCalib[calibIndex++]=nCalibLines;
107  for(uint32_t iCalib=0;iCalib<nCalibLines;++iCalib)
108  pBlobCalib[calibIndex++]=calibIDs[iCalib].get_identifier32().get_compact();
109  }
110 
111  blobCalib.resize(calibIndex*sizeof(uint32_t)); //Size down to actual size
112 
113 
114  outfile.close();
115 
116  ATH_MSG_INFO("BlobSize OnOffId:" << index);
117  ATH_MSG_INFO("BlobSize CalibId:" << calibIndex);
118  msg(MSG::INFO) << "nCalib[i] ";
119  for (unsigned j=0;j<5;++j)
120  msg() << calibHist[j] << "/";
121  msg() << endmsg;
122 
123  ATH_CHECK(detStore()->record(al_onOff,"/LAR/Identifier/OnOffIdMap"));
124 
125  ATH_CHECK(detStore()->record(al_calib,"/LAR/Identifier/CalibIdMap"));
126 
127  return StatusCode::SUCCESS;
128 }
129 
130 
131 void LArIdMapConvert::print (const HWIdentifier& hwid, std::ostream& out) {
132  const IdentifierHash hwid_hash=m_onlineID->channel_Hash(hwid);
134  const LArOnOffIdMapping* cabling{*cablingHdl};
135  if(!cabling) {
136  ATH_MSG_ERROR( "Do not have cabling mapping from key " << m_cablingKey.key() );
137  return;
138  }
140  const LArCalibLineMapping *clCont {*clHdl};
141  if(!clCont) {
142  ATH_MSG_ERROR( "Do not have calib line mapping !!!" );
143  return;
144  }
145  out << hwid_hash << " " << std::hex << "0x" << hwid.get_identifier32().get_compact() << std::dec << " "
146  << m_onlineID->barrel_ec(hwid) << " "
147  << m_onlineID->pos_neg(hwid) << " "
148  << m_onlineID->feedthrough(hwid) << " "
149  << m_onlineID->slot(hwid) << " "
150  << m_onlineID->channel(hwid) << " : ";
151  if (cabling->isOnlineConnected(hwid)) {
152  const Identifier id=cabling->cnvToIdentifier(hwid);
153  out << std::hex << "0x" << id.get_identifier32().get_compact() << std::dec << " "
154  << m_caloCellID->sub_calo(id) << " "
155  << m_caloCellID->pos_neg(id) << " "
156  << m_caloCellID->sampling(id) << " "
157  << m_caloCellID->region(id) << " "
158  << m_caloCellID->eta(id) << " "
159  << m_caloCellID->phi(id) << " ";
160  }
161  else
162  out << " disconnected ";
163 
164  const std::vector<HWIdentifier>& calibIDs=clCont->calibSlotLine(hwid);
165  for (size_t i=0;i<calibIDs.size();++i) {
166  out << std::hex << "0x" << calibIDs[i].get_identifier32().get_compact() << " ";
167  }
168  out << std::dec << std::endl;
169 }
170 
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
LArIdMapConvert::print
void print(const HWIdentifier &hwid, std::ostream &out=std::cout)
Definition: LArIdMapConvert.cxx:131
LArIdMapConvert::LArIdMapConvert
LArIdMapConvert()
Default constructor:
LArOnlineID_Base::channel_Hash
IdentifierHash channel_Hash(HWIdentifier channelId) const
Create channel_hash from channel_Id.
Definition: LArOnlineID_Base.cxx:1636
CaloCell_Base_ID::region
int region(const Identifier id) const
LAr field values (NOT_VALID == invalid request)
LArIdMapConvert::initialize
virtual StatusCode initialize() override
Definition: LArIdMapConvert.cxx:26
LArIdMapConvert::~LArIdMapConvert
virtual ~LArIdMapConvert()
Destructor:
Definition: LArIdMapConvert.cxx:22
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
LArIdMapConvert::m_onlineID
const LArOnlineID * m_onlineID
Definition: LArIdMapConvert.h:49
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
index
Definition: index.py:1
CaloCell_Base_ID::pos_neg
int pos_neg(const Identifier id) const
LAr field values (NOT_VALID == invalid request)
LArCalibLineMapping
Definition: LArCalibLineMapping.h:17
ReadCellNoiseFromCool.cabling
cabling
Definition: ReadCellNoiseFromCool.py:154
LArIdMapConvert.h
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:71
LArOnlineID_Base::slot
int slot(const HWIdentifier id) const
Return the slot number of a hardware cell identifier: slot = [1,15] Slot-ID in top part of the crat...
Definition: LArOnlineID_Base.cxx:1961
python.subdetectors.tile.Blob
Blob
Definition: tile.py:17
LArIdMapConvert::execute
virtual StatusCode execute() override
Definition: LArIdMapConvert.cxx:44
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
HWIdentifier
Definition: HWIdentifier.h:13
LArOnlineID_Base::barrel_ec
int barrel_ec(const HWIdentifier id) const
Return the position barrel or endcap of a hardware cell identifier: barrel_ec = [0,...
Definition: LArOnlineID_Base.cxx:1942
AthenaAttributeList.h
LArIdMapConvert::finalize
virtual StatusCode finalize() override
Definition: LArIdMapConvert.cxx:37
AthCommonDataStore< AthCommonMsg< Algorithm > >::detStore
const ServiceHandle< StoreGateSvc > & detStore() const
The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:95
LArOnlineID_Base::channel
int channel(const HWIdentifier id) const
Return the channel number of a hardware cell identifier channel = [0,127] in all FEB.
Definition: LArOnlineID_Base.cxx:1967
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
Identifier32::get_compact
value_type get_compact(void) const
Get the compact id.
Definition: Identifier32.h:171
lumiFormat.i
int i
Definition: lumiFormat.py:92
Identifier
Definition: DetectorDescription/Identifier/Identifier/Identifier.h:32
CaloCell_Base_ID::sampling
int sampling(const Identifier id) const
LAr field values (NOT_VALID == invalid request)
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
LArOnlineID_Base::channel_Id
HWIdentifier channel_Id(int barrel_ec, int pos_neg, int feedthrough, int slot, int channel) const
create channel identifier from fields
Definition: LArOnlineID_Base.cxx:1569
LArOnlineID_Base::pos_neg
int pos_neg(const HWIdentifier id) const
Return the side of a hardware cell identifier pos_neg = [0,1] positive-side or negative-side Barrel...
Definition: LArOnlineID_Base.cxx:1954
CaloCell_Base_ID::eta
int eta(const Identifier id) const
LAr field values (NOT_VALID == invalid request)
CaloCell_Base_ID::sub_calo
int sub_calo(const Identifier id) const
returns an int taken from SUBCALO enum and describing the subCalo to which the Id belongs.
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
AthenaAttributeList
An AttributeList represents a logical row of attributes in a metadata table. The name and type of eac...
Definition: PersistentDataModel/PersistentDataModel/AthenaAttributeList.h:45
LArIdMapConvert::m_caloCellID
const CaloCell_ID * m_caloCellID
Definition: LArIdMapConvert.h:50
AthAlgorithm
Definition: AthAlgorithm.h:47
LArIdMapConvert::m_CLKey
SG::ReadCondHandleKey< LArCalibLineMapping > m_CLKey
Definition: LArIdMapConvert.h:43
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
LArOnlineID_Base::channelHashMax
size_type channelHashMax(void) const
Define channel hash tables max size.
Definition: LArOnlineID_Base.cxx:1901
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
CaloCell_Base_ID::phi
int phi(const Identifier id) const
LAr field values (NOT_VALID == invalid request)
LArOnlineID_Base::feedthrough
int feedthrough(const HWIdentifier id) const
Return the feedthrough of a hardware cell identifier : feedthrough = [0,31] Barrel - A/C side or H/...
Definition: LArOnlineID_Base.cxx:1948
AthCommonMsg< Algorithm >::msg
MsgStream & msg() const
Definition: AthCommonMsg.h:24
LArIdMapConvert::m_cablingKey
SG::ReadCondHandleKey< LArOnOffIdMapping > m_cablingKey
Definition: LArIdMapConvert.h:42
IdentifierHash
Definition: IdentifierHash.h:38
Identifier::get_identifier32
Identifier32 get_identifier32(void) const
Get the 32-bit version Identifier, will be invalid if >32 bits needed.
PrepareReferenceFile.outfile
outfile
Definition: PrepareReferenceFile.py:42
LArOnlineID.h
LArOnOffIdMapping
Definition: LArOnOffIdMapping.h:20