ATLAS Offline Software
HECHVManager.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include "LArHV/HECHVManager.h"
6 #include "LArHV/HECHVModule.h"
7 #include "LArHV/HECHVSubgap.h"
8 #include <cmath>
9 
10 #include "HECHVPayload.h"
11 
12 #include "StoreGate/StoreGateSvc.h"
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 
33 namespace {
34 
35 
36 struct 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 
47 SimIdFunc::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 
61 public:
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 {
91 public:
92  std::vector<HECHVPayload> m_payloadArray;
93 };
94 
95 
97 
98 
99 HECHVManager::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 
118 bool HECHVManager::HECHVData::hvOn (const HECHVSubgap& subgap) const
119 {
120  return voltage (subgap) > INVALID;
121 }
122 
123 
124 double HECHVManager::HECHVData::voltage (const HECHVSubgap& subgap) const
125 {
126  return m_payload->m_payloadArray[index(subgap)].voltage;
127 }
128 
129 
130 double HECHVManager::HECHVData::current (const HECHVSubgap& subgap) const
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 
194 const 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  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) { return hvIdMapping.getLArElectrodeIDvec(id); };
294  return getData (idfunc, attrLists);
295 }
296 
297 
299  , const LArHVIdMapping* hvIdMapping) const {
300  const HECHVModule& module = subgap.getModule();
301  int sideIndex = module.getSideIndex();
302  int phiIndex = module.getPhiIndex();
303  int samplingIndex = module.getSamplingIndex();
304  int subgapIndex = subgap.getSubgapIndex();
305 
306  // ________________________ Construct ElectrodeID ________________________________
307  int id_detector = 4;
308  int id_zside = 1-sideIndex;
309  int id_module = phiIndex;
310  int id_hv_phi = 0;
311  int id_hv_eta = samplingIndex+1;
312  int id_gap = subgapIndex;
313  int id_electrode{0};
314 
315  switch(samplingIndex) {
316  case 0:
317  id_electrode=1;
318  break;
319  case 1:
320  id_electrode=9;
321  break;
322  case 2:
323  id_electrode=25;
324  break;
325  case 3:
326  id_electrode=33;
327  break;
328  default:
329  throw std::runtime_error("Unexpected value for samplingIndex in HEC: " + std::to_string(samplingIndex));
330  }
331 
332  HWIdentifier elecHWID = m_c->elecId->ElectrodeId(id_detector
333  , id_zside
334  , id_module
335  , id_hv_phi
336  , id_hv_eta
337  , id_gap
338  , id_electrode);
339  // ________________________ ________________________________
340 
341  // Get LArHVLineID corresponding to a given LArElectrodeId
342  HWIdentifier id = hvIdMapping->getLArHVLineID(elecHWID);
343 
344  // Extract HV Line No
345  return m_c->hvId->can_node(id)*1000 + m_c->hvId->hv_line(id);
346 }
347 #endif
HECHVDescriptor
Definition: HECHVDescriptor.h:11
HECHVManager::m_c
std::unique_ptr< const Clockwork > m_c
Definition: HECHVManager.h:95
fillPileUpNoiseLumi.current
current
Definition: fillPileUpNoiseLumi.py:52
HECHVModule
Describes one HV Module within the HEC.
Definition: HECHVModule.h:21
checkFileSG.line
line
Definition: checkFileSG.py:75
HECHVManager::beginSideIndex
static unsigned int beginSideIndex()
Definition: HECHVManager.cxx:164
CondAttrListCollection.h
This file defines the class for a collection of AttributeLists where each one is associated with a ch...
getMessageSvc.h
singleton-like access to IMessageSvc via open function and helper
HECHVManager::getDataSim
HECHVData getDataSim() const
Definition: HECHVManager.cxx:272
HECHVManager::beginPhiIndex
static unsigned int beginPhiIndex()
Definition: HECHVManager.cxx:174
make_unique
std::unique_ptr< T > make_unique(Args &&... args)
Definition: SkimmingToolEXOT5.cxx:23
LArElectrodeID
Helper for the Liquid Argon Calorimeter cell at the electrode level.
Definition: LArElectrodeID.h:101
index
Definition: index.py:1
TRTCalib_cfilter.detector
detector
Definition: TRTCalib_cfilter.py:241
HECHVManager::getData
HECHVData getData(const LArHVIdMapping &hvIdMapping, const std::vector< const CondAttrListCollection * > &attrLists) const
Definition: HECHVManager.cxx:290
M_PI
#define M_PI
Definition: ActiveFraction.h:11
HECHVManager::Clockwork::~Clockwork
~Clockwork()=default
HECHVManager::HECHVData::index
static int index(const HECHVSubgap &subgap)
Definition: HECHVManager.cxx:142
LArHVIdMapping::getLArHVLineID
const HWIdentifier getLArHVLineID(HWIdentifier &electrodeId) const
Return the LArHVLineID corresponding to a given LArElectrodeId.
Definition: LArHVIdMapping.cxx:22
HECHVManager::HECHVData::hvLineNo
int hvLineNo(const HECHVSubgap &subgap) const
Definition: HECHVManager.cxx:136
HECHVManager::HECHVData::operator=
HECHVData & operator=(HECHVData &&other) noexcept
Definition: HECHVManager.cxx:106
HECHVManager::Clockwork::hvId
const LArHVLineID * hvId
Definition: HECHVManager.cxx:85
LArHVLineID.h
HECHVManager::HECHVData::HECHVData
HECHVData()
HWIdentifier
Definition: HWIdentifier.h:13
CondAttrListCollection
This class is a collection of AttributeLists where each one is associated with a channel number....
Definition: CondAttrListCollection.h:52
HECHVManager::HECHVData::Payload::m_payloadArray
std::vector< HECHVPayload > m_payloadArray
Definition: HECHVManager.cxx:92
CxxUtils::INVALID
@ INVALID
Definition: CachedValue.h:28
AthenaAttributeList.h
Athena::getMessageSvc
IMessageSvc * getMessageSvc(bool quiet=false)
Definition: getMessageSvc.cxx:20
HECHVManager.h
python.PyAthena.module
module
Definition: PyAthena.py:131
HECHVManager::HECHVData
Definition: HECHVManager.h:39
HECHVManager::endSideIndex
static unsigned int endSideIndex()
Definition: HECHVManager.cxx:169
HECHVManager::idfunc_t
std::function< std::vector< HWIdentifier >(HWIdentifier)> idfunc_t
Definition: HECHVManager.h:88
LArHVCablingSimTool
Mapping from HV lines to electrodes.
Definition: LArHVCablingSimTool.h:29
lumiFormat.i
int i
Definition: lumiFormat.py:85
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
LArHVIdMapping.h
HECHVManager::HECHVData::voltage
double voltage(const HECHVSubgap &subgap) const
Definition: HECHVManager.cxx:124
HECHVManager::endSamplingIndex
static unsigned int endSamplingIndex()
Definition: HECHVManager.cxx:189
HECHVManager::HECHVData::~HECHVData
~HECHVData()
HECHVManager::hvLineNo
int hvLineNo(const HECHVSubgap &subgap, const LArHVIdMapping *hvIdMapping) const
Definition: HECHVManager.cxx:298
HECHVManager::getDescriptor
const HECHVDescriptor & getDescriptor() const
Definition: HECHVManager.cxx:159
HECHVManager::HECHVManager
HECHVManager()
Definition: HECHVManager.cxx:154
HECHVManager::~HECHVManager
~HECHVManager()
HECHVManager::HECHVData::current
double current(const HECHVSubgap &subgap) const
Definition: HECHVManager.cxx:130
HECHVManager::Clockwork::descriptor
HECHVDescriptor descriptor
Definition: HECHVManager.cxx:82
HECHVSubgap.h
HECHVPayload.h
HECHVSubgap::getModule
const HECHVModule & getModule() const
Definition: HECHVSubgap.cxx:34
HECHVSubgap::getSubgapIndex
unsigned int getSubgapIndex() const
Definition: HECHVSubgap.cxx:39
python.PyKernel.detStore
detStore
Definition: PyKernel.py:41
HWIdentifier.h
id
SG::auxid_t id
Definition: Control/AthContainers/Root/debug.cxx:220
ActsTrk::to_string
std::string to_string(const DetectorType &type)
Definition: GeometryDefs.h:34
AtlCoolConsole.tool
tool
Definition: AtlCoolConsole.py:453
PixelModuleFeMask_create_db.payload
string payload
Definition: PixelModuleFeMask_create_db.py:69
Trk::iPhi
@ iPhi
Definition: ParamDefs.h:47
eflowRec::phiIndex
unsigned int phiIndex(float phi, float binsize)
calculate phi index for a given phi
Definition: EtaPhiLUT.cxx:23
HECHVManager
This class provides direct access to information on the HV electrodes within the barrels....
Definition: HECHVManager.h:36
DeMoScan.index
string index
Definition: DeMoScan.py:364
HECHVManager::HECHVData::hvOn
bool hvOn(const HECHVSubgap &subgap) const
Definition: HECHVManager.cxx:118
InDetDD::other
@ other
Definition: InDetDD_Defs.h:16
LArHVIdMapping
Definition: LArHVIdMapping.h:21
CondAttrListCollection::const_iterator
ChanAttrListMap::const_iterator const_iterator
Definition: CondAttrListCollection.h:63
HECHVManager::endPhiIndex
static unsigned int endPhiIndex()
Definition: HECHVManager.cxx:179
HECHVManager::Clockwork::elecId
const LArElectrodeID * elecId
Definition: HECHVManager.cxx:84
HECHVManager::Clockwork::Clockwork
Clockwork(const HECHVManager *manager)
Definition: HECHVManager.cxx:62
HECHVModule.h
HECHVManager::Clockwork::moduleArray
std::unique_ptr< const HECHVModule > moduleArray[2][32][4]
Definition: HECHVManager.cxx:83
LArHVCablingSimTool.h
python.Logging.manager
manager
Definition: PhysicsAnalysis/D3PDTools/AnaAlgorithm/python/Logging.py:92
HECHVManager::Clockwork
Definition: HECHVManager.cxx:60
LArElectrodeID.h
HECHVManager::beginSamplingIndex
static unsigned int beginSamplingIndex()
Definition: HECHVManager.cxx:184
HECHVManager::HECHVData::Payload
Definition: HECHVManager.cxx:90
StoreGateSvc.h
HECHVSubgap
Definition: HECHVSubgap.h:15
python.AutoConfigFlags.msg
msg
Definition: AutoConfigFlags.py:7
LArHVIdMapping::getLArElectrodeIDvec
const std::vector< HWIdentifier > & getLArElectrodeIDvec(HWIdentifier &hvlineId) const
Return a vector of LArElectrodeID corresponding to a given LArHVLineID.
Definition: LArHVIdMapping.cxx:83
HECHVManager::HECHVData::INVALID
static constexpr double INVALID
Definition: HECHVManager.h:41
HECHVManager::getHVModule
const HECHVModule & getHVModule(unsigned int iSide, unsigned int iPhi, unsigned int iSampling) const
Definition: HECHVManager.cxx:194
ServiceHandle< StoreGateSvc >
LArHVLineID
Helper for the Liquid Argon Calorimeter High-Voltage identifiers.
Definition: LArHVLineID.h:48