ATLAS Offline Software
Loading...
Searching...
No Matches
LArHVPathologyDbCondAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
10
12#include "CoralBase/AttributeListException.h"
13#include "CoralBase/Blob.h"
14
21
25
26#include "TBufferFile.h"
27#include "TClass.h"
28
29
30LArHVPathologyDbCondAlg::LArHVPathologyDbCondAlg(const std::string& name, ISvcLocator* pSvcLocator)
31 : AthCondAlgorithm(name,pSvcLocator), m_hvmapTool("LArHVMapTool",this)
32{ }
33
36
38{
39 ATH_CHECK(m_pathologyFolderKey.initialize());
40 ATH_CHECK(m_hvMappingKey.initialize());
41 ATH_CHECK(m_hvPathologyKey.initialize());
42 ATH_CHECK(m_caloMgrKey.initialize());
43
44 const CaloCell_ID* idHelper = nullptr;
45 ATH_CHECK( detStore()->retrieve (idHelper, "CaloCell_ID") );
46
47 m_larem_id = idHelper->em_idHelper();
48 m_larhec_id = idHelper->hec_idHelper();
49 m_larfcal_id = idHelper->fcal_idHelper();
50
51 ATH_CHECK( detStore()->retrieve(m_laronline_id,"LArOnlineID") );
52 ATH_CHECK(detStore()->retrieve(m_hvlineHelper,"LArHVLineID"));
53
54
55 m_klass = TClass::GetClass("LArHVPathologiesDb");
56 if(m_klass==nullptr){
57 ATH_MSG_ERROR ( "Can't find TClass LArHVPathologiesDb" );
58 return StatusCode::FAILURE;
59 }
60 else
61 ATH_MSG_DEBUG ( "Got TClass LArHVPathologiesDb" );
62
63 m_klass->GetStreamerInfo();
64
65 return StatusCode::SUCCESS;
66}
67
69{
70 return StatusCode::SUCCESS;
71}
72
73
74StatusCode LArHVPathologyDbCondAlg::execute(const EventContext& ctx) const {
75
77
78 if (writeHandle.isValid()) {
79 ATH_MSG_DEBUG("Found valid write handle");
80 return StatusCode::SUCCESS;
81 }
82
83 //Get Conditions input
85 const AthenaAttributeList *attrList = *fldrHdl;
86 if (!attrList) {
87 ATH_MSG_ERROR("Do not have AthenaAttributeList for pathology");
88 return StatusCode::FAILURE;
89 }
90 writeHandle.addDependency(fldrHdl);
91
93 const CaloDetDescrManager* calodetdescrmgr = *caloMgrHandle;
94 writeHandle.addDependency(caloMgrHandle);
95
96 try {
97 const unsigned blobVersion=(*attrList)["blobVersion"].data<unsigned int>();
98 const coral::Blob& blob = (*attrList)["Constants"].data<coral::Blob>();
99
100 if (blobVersion!=0) {
101 ATH_MSG_ERROR ( "Can't interpret BLOB version " << blobVersion );
102 return StatusCode::FAILURE;
103 }
104
105
106 void* blob_data ATLAS_THREAD_SAFE = const_cast<void*> (blob.startingAddress());
107 TBufferFile buf(TBuffer::kRead, blob.size(), blob_data, false);
108 std::unique_ptr<LArHVPathologiesDb> hvpathdb
109 (static_cast<LArHVPathologiesDb*>(buf.ReadObjectAny(m_klass)));
110
111 auto hvpath = std::make_unique<LArHVPathology>(hvpathdb.get());
112
113 fillElectMap(calodetdescrmgr, hvpath.get(), writeHandle);
114
115
116 if(writeHandle.record(std::move(hvpath)).isFailure()) {
117 ATH_MSG_ERROR("Could not record LArHVPathology object with "
118 << writeHandle.key()
119 << " with EventRange " << writeHandle.getRange()
120 << " into Conditions Store");
121 return StatusCode::FAILURE;
122 }
123
124 return StatusCode::SUCCESS;
125
126 }catch (coral::AttributeListException &e) {
127 ATH_MSG_ERROR ( e.what() );
128 return StatusCode::FAILURE;
129 }
130 // should not come here, but syntactically
131 return StatusCode::SUCCESS;
132}
133
134void
136 LArHVPathology* hvpath,
137 SG::WriteCondHandle<LArHVPathology>& writeHandle) const
138{
140 const LArHVIdMapping* hvCabling = *cHdl;
141 if(!hvCabling) {
142 ATH_MSG_WARNING("Do not have HV mapping, will not fill LArHVPathology electIndMap !!!");
143 return;
144 }
145 writeHandle.addDependency (cHdl);
146
147 std::lock_guard<std::mutex> lock(m_mut);
148
149 std::map<std::pair<Identifier, unsigned int>, std::vector<unsigned short> > &elecMap = hvpath->getElecMap(); //shorthand
150
151 std::vector<unsigned short> list;
152 std::vector<HWIdentifier> hwlineId;
153 unsigned int HVline = 0;
154 // loop over all EM Identifiers
155 for (auto id: m_larem_id->channel_ids()) {
156 hwlineId.clear();
157 m_hvmapTool->GetHVLines(id,calodetdescrmgr, hwlineId);
158 // LAr EMB
159 if (abs(m_larem_id->barrel_ec(id))==1 && m_larem_id->sampling(id) > 0) {
160 if (const EMBDetectorElement* embElement = dynamic_cast<const EMBDetectorElement*>(calodetdescrmgr->get_element(id))) {
161 const EMBCellConstLink cell = embElement->getEMBCell();
162 unsigned int nelec = cell->getNumElectrodes();
163 for(auto hwid:hwlineId) {
164 list.clear();
165 HVline = m_hvlineHelper->hv_line(hwid);
166 for (unsigned int i=0;i<nelec;i++) {
167 const EMBHVElectrode& electrode = cell->getElectrode(i);
168 for (unsigned int igap=0;igap<2;igap++) {
169 if ((unsigned)electrode.hvLineNo(igap,hvCabling)==HVline) {
170 list.push_back(2*i+igap);
171 }
172 }
173 }
174 }
175 elecMap.insert(std::make_pair(std::make_pair(id,HVline) ,list));
176 continue;
177 }
178 }
179 // LAr EMEC
180 if (abs(m_larem_id->barrel_ec(id))>1 && m_larem_id->sampling(id) > 0) {
181 if (const EMECDetectorElement* emecElement = dynamic_cast<const EMECDetectorElement*>(calodetdescrmgr->get_element(id))) {
182 const EMECCellConstLink cell = emecElement->getEMECCell();
183 unsigned int nelec = cell->getNumElectrodes();
184 for(auto hwid:hwlineId) {
185 list.clear();
186 HVline = m_hvlineHelper->hv_line(hwid);
187 for (unsigned int i=0;i<nelec;i++) {
188 const EMECHVElectrode& electrode = cell->getElectrode(i);
189 for (unsigned int igap=0;igap<2;igap++) {
190 if ((unsigned)electrode.hvLineNo(igap,hvCabling)==HVline) {
191 list.push_back(2*i+igap);
192 }
193 }
194 }
195 }
196 elecMap.insert(std::make_pair(std::make_pair(id,HVline),list));
197 continue;
198 }
199 }
200 // EMBPS
201 if (abs(m_larem_id->barrel_ec(id))==1 && m_larem_id->sampling(id)==0) {
202 if (const EMBDetectorElement* embElement = dynamic_cast<const EMBDetectorElement*>(calodetdescrmgr->get_element(id))) {
203 const EMBCellConstLink cell = embElement->getEMBCell();
204 const EMBPresamplerHVModule& hvmodule = cell->getPresamplerHVModule ();
205 for(auto hwid:hwlineId) {
206 list.clear();
207 HVline = m_hvlineHelper->hv_line(hwid);
208 for (unsigned int igap=0;igap<2;igap++) {
209 if ((unsigned)hvmodule.hvLineNo(igap,hvCabling)==HVline) {
210 list.push_back(igap);
211 }
212 }
213 elecMap.insert(std::make_pair(std::make_pair(id,HVline),list));
214 continue;
215 }
216 }
217 }
218 // EMECPS
219 if (abs(m_larem_id->barrel_ec(id))>1 && m_larem_id->sampling(id)==0) {
220 if (const EMECDetectorElement* emecElement = dynamic_cast<const EMECDetectorElement*>(calodetdescrmgr->get_element(id))) {
221 const EMECCellConstLink cell = emecElement->getEMECCell();
222 const EMECPresamplerHVModule& hvmodule = cell->getPresamplerHVModule ();
223 for(auto hwid:hwlineId) {
224 list.clear();
225 HVline = m_hvlineHelper->hv_line(hwid);
226 for (unsigned int igap=0;igap<2;igap++) {
227 if ((unsigned)hvmodule.hvLineNo(igap,hvCabling)==HVline) {
228 list.push_back(igap);
229 }
230 }
231 elecMap.insert(std::make_pair(std::make_pair(id,HVline),list));
232 continue;
233 }
234 }
235 }
236 }
237 // loop over all HEC Identifiers
238 for (auto const& id: m_larhec_id->channel_ids()) {
239 hwlineId.clear();
240 m_hvmapTool->GetHVLines(id,calodetdescrmgr,hwlineId);
241 if (const HECDetectorElement* hecElement = dynamic_cast<const HECDetectorElement*>(calodetdescrmgr->get_element(id))) {
242 const HECCellConstLink cell = hecElement->getHECCell();
243 unsigned int nsubgaps = cell->getNumSubgaps();
244 for(auto hwid:hwlineId) {
245 list.clear();
246 HVline = m_hvlineHelper->hv_line(hwid);
247 for (unsigned int i=0;i<nsubgaps;i++) {
248 const HECHVSubgap& subgap = cell->getSubgap(i);
249 if ((unsigned)subgap.hvLineNo(hvCabling)==HVline) {
250 list.push_back(i);
251 }
252 }
253 elecMap.insert(std::make_pair(std::make_pair(id,HVline),list));
254 continue;
255 }
256 }
257 }
258 // loop over all FCAL Identifiers
259 for (auto const& id: m_larfcal_id->channel_ids()) {
260 hwlineId.clear();
261 m_hvmapTool->GetHVLines(id,calodetdescrmgr, hwlineId);
262 if (const FCALDetectorElement* fcalElement = dynamic_cast<const FCALDetectorElement*>(calodetdescrmgr->get_element(id))) {
263 const FCALTile* tile = fcalElement->getFCALTile();
264 unsigned int nlines = tile->getNumHVLines();
265 for(auto hwid:hwlineId) {
266 list.clear();
267 HVline = m_hvlineHelper->hv_line(hwid);
268 for (unsigned int i=0;i<nlines;i++) {
269 const FCALHVLine* line2 = tile->getHVLine(i);
270 if (line2) {
271 if ((unsigned)line2->hvLineNo(hvCabling)==HVline) {
272 list.push_back(i);
273 }
274 }
275 }
276 elecMap.insert(std::make_pair(std::make_pair(id,HVline),list));
277 continue;
278 }
279 }
280 }
281
282 return;
283
284}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
Calo Subsystem specific Detector Elements + Dummy element for testing.
Define macros for attributes used to control the static checker.
#define ATLAS_THREAD_SAFE
const ServiceHandle< StoreGateSvc > & detStore() const
Base class for conditions algorithms.
An AttributeList represents a logical row of attributes in a metadata table.
Helper class for offline cell identifiers.
Definition CaloCell_ID.h:34
const LArFCAL_ID * fcal_idHelper() const
access to FCAL idHelper
Definition CaloCell_ID.h:75
const LArEM_ID * em_idHelper() const
access to EM idHelper
Definition CaloCell_ID.h:63
const LArHEC_ID * hec_idHelper() const
access to HEC idHelper
Definition CaloCell_ID.h:69
const CaloDetDescrElement * get_element(const Identifier &cellId) const
get element by its identifier
This class provides the client interface for accessing the detector description information common to...
LAr EMB Detector Element.
int hvLineNo(int iGap, const LArHVIdMapping *hvIdMapping) const
Describes one HV Module within the EMB Presampler.
int hvLineNo(int iGap, const LArHVIdMapping *hvIdMapping) const
LAr EMEC Detector Element.
int hvLineNo(int iGap, const LArHVIdMapping *hvIdMapping) const
Describes one HV Module within the EMEc Presampler.
int hvLineNo(int iGap, const LArHVIdMapping *hvIdMapping) const
LAr FCAL Detector Element.
A tile of the forward calorimeter readout geometry.
Definition FCALTile.h:27
LAr HEC Detector Element.
int hvLineNo(const LArHVIdMapping *hvIdMapping) const
SG::ReadCondHandleKey< CaloDetDescrManager > m_caloMgrKey
SG::WriteCondHandleKey< LArHVPathology > m_hvPathologyKey
ToolHandle< ILArHVMapTool > m_hvmapTool
virtual StatusCode finalize() override
void fillElectMap(const CaloDetDescrManager *calodetdescrmgr, LArHVPathology *hvpath, SG::WriteCondHandle< LArHVPathology > &writeHandle) const
virtual StatusCode execute(const EventContext &ctx) const override
const LArOnlineID * m_laronline_id
const LArHVLineID * m_hvlineHelper
SG::ReadCondHandleKey< AthenaAttributeList > m_pathologyFolderKey
SG::ReadCondHandleKey< LArHVIdMapping > m_hvMappingKey
virtual StatusCode initialize() override
LArHVPathologyDbCondAlg(const std::string &name, ISvcLocator *pSvcLocator)
std::map< std::pair< Identifier, unsigned int >, std::vector< unsigned short > > & getElecMap()
const std::string & key() const
void addDependency(const EventIDRange &range)
const EventIDRange & getRange() const
StatusCode record(const EventIDRange &range, T *t)
record handle, with explicit range DEPRECATED