ATLAS Offline Software
Loading...
Searching...
No Matches
HECHVManager.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
6#include "LArHV/HECHVModule.h"
7#include "LArHV/HECHVSubgap.h"
8#include <cmath>
9
10#include "HECHVPayload.h"
11
14#include "GaudiKernel/ISvcLocator.h"
15#include "GaudiKernel/IToolSvc.h"
16#include "GaudiKernel/Bootstrap.h"
17#include "GaudiKernel/ServiceHandle.h"
18
21
25
26#if !(defined(SIMULATIONBASE) || defined(GENERATIONBASE))
28#endif
29
31
32
33namespace {
34
35
36struct SimIdFunc
37{
38 SimIdFunc();
39 std::vector<HWIdentifier> operator()(HWIdentifier id) const
40 {
41 return m_cablingTool->getLArElectrodeIDvec (id);
42 }
43 LArHVCablingSimTool* m_cablingTool;
44};
45
46
47SimIdFunc::SimIdFunc()
48{
49 ToolHandle<LArHVCablingSimTool> tool ("LArHVCablingSimTool");
50 if (!tool.retrieve().isSuccess()) {
51 std::abort();
52 }
53 m_cablingTool = tool.get();
54}
55
56
57} // Anonymous namespace
58
59
61public:
62 explicit Clockwork(const HECHVManager* manager)
63 {
64 for(int iSide=0; iSide<2; ++iSide) {
65 for(int iPhi=0; iPhi<32; ++iPhi) {
66 for(int iSampling=0; iSampling<4; ++iSampling) {
67 moduleArray[iSide][iPhi][iSampling] = std::make_unique<HECHVModule>(manager,iSide,iPhi,iSampling);
68 }
69 }
70 }
71
72 ServiceHandle<StoreGateSvc> detStore ("DetectorStore", "HECHVManager");
73 if (StatusCode::SUCCESS!=detStore->retrieve(elecId, "LArElectrodeID")) {
74 throw std::runtime_error("HECHVManager failed to retrieve LArElectrodeID");
75 }
76
77 if (StatusCode::SUCCESS!=detStore->retrieve(hvId,"LArHVLineID")) {
78 throw std::runtime_error("HECHVManager failed to retrieve LArHVLineID");
79 }
80 }
81 ~Clockwork() = default;
82 HECHVDescriptor descriptor{CellBinning(0,2*M_PI,32)};
83 std::unique_ptr<const HECHVModule> moduleArray[2][32][4];
84 const LArElectrodeID* elecId = nullptr;
85 const LArHVLineID* hvId = nullptr;
86};
87
88
90{
91public:
92 std::vector<HECHVPayload> m_payloadArray;
93};
94
95
97
98
99HECHVManager::HECHVData::HECHVData (std::unique_ptr<Payload> payload)
100 : m_payload (std::move (payload))
101{
102}
103
104
107 if (this != &other) {
108 m_payload = std::move (other.m_payload);
109 }
110 return *this;
111}
112
113
115= default;
116
117
119{
120 return voltage (subgap) > INVALID;
121}
122
123
125{
126 return m_payload->m_payloadArray[index(subgap)].voltage;
127}
128
129
131{
132 return m_payload->m_payloadArray[index(subgap)].current;
133}
134
135
137{
138 return m_payload->m_payloadArray[index(subgap)].hvLineNo;
139}
140
141
143{
144 unsigned int subgapIndex = subgap.getSubgapIndex();
145 const HECHVModule& module = subgap.getModule();
146 unsigned int phiIndex = module.getPhiIndex();
147 unsigned int samplingIndex = module.getSamplingIndex();
148 unsigned int sideIndex = module.getSideIndex();
149 unsigned int index = 512*sideIndex+16*phiIndex+4*samplingIndex+subgapIndex;
150 return index;
151}
152
153
155 : m_c (std::make_unique<Clockwork> (this))
156{
157}
158
160{
161 return m_c->descriptor;
162}
163
165{
166 return 0;
167}
168
170{
171 return 2;
172}
173
175{
176 return 0;
177}
178
180{
181 return 32;
182}
183
185{
186 return 0;
187}
188
190{
191 return 4;
192}
193
194const HECHVModule& HECHVManager::getHVModule(unsigned int iSide
195 , unsigned int iPhi
196 , unsigned int iSampling) const
197{
198 return *(m_c->moduleArray[iSide][iPhi][iSampling]);
199}
200
202= default;
203
206 const std::vector<const CondAttrListCollection*>& attrLists) const
207{
208 auto payload = std::make_unique<HECHVData::Payload>();
209 payload->m_payloadArray.reserve(2*32*4*4);
210 for (unsigned int i=0;i<1024;i++) {
211 payload->m_payloadArray[i].voltage = HECHVData::INVALID;
212 }
213
214 for (const CondAttrListCollection* atrlistcol : attrLists) {
215
216 for (CondAttrListCollection::const_iterator citr=atrlistcol->begin(); citr!=atrlistcol->end();++citr) {
217
218 // Construct HWIdentifier
219 // 1. decode COOL Channel ID
220 unsigned int chanID = (*citr).first;
221 int cannode = chanID/1000;
222 int line = chanID%1000;
223
224 // 2. Construct the identifier
225 HWIdentifier id = m_c->hvId->HVLineId(1,1,cannode,line);
226
227 const std::vector<HWIdentifier>& electrodeIdVec = idfunc(id);
228
229 for(size_t i=0;i<electrodeIdVec.size();i++) {
230 HWIdentifier elecHWID = electrodeIdVec[i];
231
232 int detector = m_c->elecId->detector(elecHWID);
233
234 // check we are in HEC
235 if (detector != 4) {
236 continue;
237 }
238
239 float voltage = HECHVData::INVALID;
240 if (!((*citr).second)["R_VMEAS"].isNull()) voltage = ((*citr).second)["R_VMEAS"].data<float>();
241 float current = 0.;
242 if (!((*citr).second)["R_IMEAS"].isNull()) current = ((*citr).second)["R_IMEAS"].data<float>();
243
244
245 unsigned int sideIndex=1-m_c->elecId->zside(elecHWID); // 0 for C side, 1 for A side, opposite to HV numbering
246 unsigned int phiIndex=m_c->elecId->module(elecHWID); // 0 to 31
247 unsigned int samplingIndex=m_c->elecId->hv_eta(elecHWID)-1; // 0 to 3
248 unsigned int subgapIndex=m_c->elecId->gap(elecHWID); // 0 to 3
249
250 unsigned int index = 512*sideIndex+16*phiIndex+4*samplingIndex+subgapIndex;
251
252
253 if (index>1023) {
254 MsgStream msg (Athena::getMessageSvc(), "EMECHVManager");
255 msg << MSG::ERROR << "invalid index " << index << " side,phi,sampling,gap " << sideIndex << " " << phiIndex << " " << samplingIndex
256 << " " << subgapIndex << endmsg;
257 continue;
258 }
259
260 payload->m_payloadArray[index].voltage=voltage;
261 payload->m_payloadArray[index].current=current;
262 payload->m_payloadArray[index].hvLineNo=chanID;
263 } // For (electrodeIdVec)
264 } // for (atrlistcol)
265 }
266
267 return {std::move (payload)};
268}
269
270
273{
274 std::vector<const CondAttrListCollection*> attrLists;
275 ServiceHandle<StoreGateSvc> detStore ("DetectorStore", "EMBHVManager");
276 const CondAttrListCollection* atrlistcol = nullptr;
277 // Not a typo --- this folder has a lower-case l in the database...
278 if (detStore->retrieve(atrlistcol, "/LAR/DCS/HV/BARREl/I16").isSuccess()) {
279 attrLists.push_back (atrlistcol);
280 }
281 if (detStore->retrieve(atrlistcol, "/LAR/DCS/HV/BARREL/I8").isSuccess()) {
282 attrLists.push_back (atrlistcol);
283 }
284 return getData (SimIdFunc(), attrLists);
285}
286
287
288#if !(defined(SIMULATIONBASE) || defined(GENERATIONBASE))
291 const std::vector<const CondAttrListCollection*>& attrLists) const
292{
293 auto idfunc = [&] (HWIdentifier id) -> const std::vector<HWIdentifier>
294 { return hvIdMapping.getLArElectrodeIDvec(id); };
295 return getData (idfunc, attrLists);
296}
297
298
300 , const LArHVIdMapping* hvIdMapping\
301 , HWIdentifier *hvlId) const {
302
303 const HECHVModule& module = subgap.getModule();
304 int sideIndex = module.getSideIndex();
305 int phiIndex = module.getPhiIndex();
306 int samplingIndex = module.getSamplingIndex();
307 int subgapIndex = subgap.getSubgapIndex();
308
309 // ________________________ Construct ElectrodeID ________________________________
310 int id_detector = 4;
311 int id_zside = 1-sideIndex;
312 int id_module = phiIndex;
313 int id_hv_phi = 0;
314 int id_hv_eta = samplingIndex+1;
315 int id_gap = subgapIndex;
316 int id_electrode{0};
317
318 switch(samplingIndex) {
319 case 0:
320 id_electrode=1;
321 break;
322 case 1:
323 id_electrode=9;
324 break;
325 case 2:
326 id_electrode=25;
327 break;
328 case 3:
329 id_electrode=33;
330 break;
331 default:
332 throw std::runtime_error("Unexpected value for samplingIndex in HEC: " + std::to_string(samplingIndex));
333 }
334
335 HWIdentifier elecHWID = m_c->elecId->ElectrodeId(id_detector
336 , id_zside
337 , id_module
338 , id_hv_phi
339 , id_hv_eta
340 , id_gap
341 , id_electrode);
342 // ________________________ ________________________________
343
344 // Get LArHVLineID corresponding to a given LArElectrodeId
345 HWIdentifier id = hvIdMapping->getLArHVLineID(elecHWID);
346
347 if(hvlId) *hvlId=id;
348
349 // Extract HV Line No
350 return m_c->hvId->can_node(id)*1000 + m_c->hvId->hv_line(id);
351}
352#endif
#define M_PI
#define endmsg
This file defines the class for a collection of AttributeLists where each one is associated with a ch...
char data[hepevt_bytes_allocation_ATLAS]
Definition HepEvt.cxx:11
This class is a collection of AttributeLists where each one is associated with a channel number.
ChanAttrListMap::const_iterator const_iterator
HECHVDescriptor descriptor
Clockwork(const HECHVManager *manager)
const LArHVLineID * hvId
const LArElectrodeID * elecId
std::unique_ptr< const HECHVModule > moduleArray[2][32][4]
std::vector< HECHVPayload > m_payloadArray
double current(const HECHVSubgap &subgap) const
bool hvOn(const HECHVSubgap &subgap) const
std::unique_ptr< Payload > m_payload
int hvLineNo(const HECHVSubgap &subgap) const
static int index(const HECHVSubgap &subgap)
static constexpr double INVALID
HECHVData & operator=(HECHVData &&other) noexcept
double voltage(const HECHVSubgap &subgap) const
static unsigned int beginPhiIndex()
std::unique_ptr< const Clockwork > m_c
static unsigned int endSamplingIndex()
const HECHVModule & getHVModule(unsigned int iSide, unsigned int iPhi, unsigned int iSampling) const
const HECHVDescriptor & getDescriptor() const
static unsigned int endSideIndex()
HECHVData getData(const LArHVIdMapping &hvIdMapping, const std::vector< const CondAttrListCollection * > &attrLists) const
static unsigned int beginSideIndex()
int hvLineNo(const HECHVSubgap &subgap, const LArHVIdMapping *hvIdMapping, HWIdentifier *hvlId=nullptr) const
HECHVData getDataSim() const
std::function< std::vector< HWIdentifier >(HWIdentifier)> idfunc_t
static unsigned int beginSamplingIndex()
static unsigned int endPhiIndex()
Describes one HV Module within the HEC.
Definition HECHVModule.h:21
const HECHVModule & getModule() const
unsigned int getSubgapIndex() const
Helper for the Liquid Argon Calorimeter cell at the electrode level.
const std::vector< HWIdentifier > & getLArElectrodeIDvec(HWIdentifier &hvlineId) const
Return a vector of LArElectrodeID corresponding to a given LArHVLineID.
const HWIdentifier getLArHVLineID(HWIdentifier &electrodeId) const
Return the LArHVLineID corresponding to a given LArElectrodeId.
Helper for the Liquid Argon Calorimeter High-Voltage identifiers.
Definition LArHVLineID.h:43
singleton-like access to IMessageSvc via open function and helper
IMessageSvc * getMessageSvc(bool quiet=false)
Definition index.py:1
STL namespace.
MsgStream & msg
Definition testRead.cxx:32