ATLAS Offline Software
FCALHVManager.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/FCALHVManager.h"
6 #include "LArHV/FCALHVLine.h"
7 
8 #include "FCALHVPayload.h"
9 
11 #include "GaudiKernel/ISvcLocator.h"
12 #include "GaudiKernel/IToolSvc.h"
13 #include "GaudiKernel/Bootstrap.h"
14 #include "GaudiKernel/ServiceHandle.h"
15 #include "StoreGate/StoreGateSvc.h"
22 
23 #if !(defined(SIMULATIONBASE) || defined(GENERATIONBASE))
25 #endif
26 
27 #include <atomic>
28 
29 
30 namespace {
31 
32 
33 struct SimIdFunc
34 {
35  SimIdFunc();
36  std::vector<HWIdentifier> operator()(HWIdentifier id) const
37  {
38  return m_cablingTool->getLArElectrodeIDvec (id);
39  }
40  LArHVCablingSimTool* m_cablingTool;
41 };
42 
43 
44 SimIdFunc::SimIdFunc()
45 {
46  ToolHandle<LArHVCablingSimTool> tool ("LArHVCablingSimTool");
47  if (!tool.retrieve().isSuccess()) {
48  std::abort();
49  }
50  m_cablingTool = tool.get();
51 }
52 
53 
54 } // Anonymous namespace
55 
56 
58 public:
59  explicit Clockwork(const FCALHVManager* manager)
60  {
61  for(int iSide=0; iSide<2; ++iSide) {
62  for(int iSector=0; iSector<16; ++iSector) {
63  for(int iSampling=0; iSampling<3; ++iSampling) {
64  moduleArray[iSide][iSector][iSampling] = std::make_unique<FCALHVModule>(manager,iSide,iSector,iSampling);
65  }
66  }
67  }
68 
69  ServiceHandle<StoreGateSvc> detStore ("DetectorStore", "HECHVManager");
70  if (StatusCode::SUCCESS!=detStore->retrieve(elecId, "LArElectrodeID")) {
71  throw std::runtime_error("FCALHVManager failed to retrieve LArElectrodeID");
72  }
73 
74  if (StatusCode::SUCCESS!=detStore->retrieve(hvId,"LArHVLineID")) {
75  throw std::runtime_error("FCALHVManager failed to retrieve LArHVLineID");
76  }
77  }
78  ~Clockwork() = default;
79  std::unique_ptr<const FCALHVModule> moduleArray[2][16][3];
80  const LArElectrodeID* elecId = nullptr;
81  const LArHVLineID* hvId = nullptr;
82 };
83 
84 
86 {
87 public:
88  std::vector<FCALHVPayload> m_payloadArray;
89 };
90 
91 
93 
94 
96  : m_payload (std::move (payload))
97 {
98 }
99 
100 
103  if (this != &other) {
104  m_payload = std::move (other.m_payload);
105  }
106  return *this;
107 }
108 
109 
111 
112 
114 {
115  return voltage (line) > INVALID;
116 }
117 
118 
120 {
121  return m_payload->m_payloadArray[index(line)].voltage;
122 }
123 
124 
126 {
127  return m_payload->m_payloadArray[index(line)].current;
128 }
129 
130 
132 {
133  return m_payload->m_payloadArray[index(line)].hvLineNo;
134 }
135 
136 
138 {
139  unsigned int lineIndex = line.getLineIndex();
140  const FCALHVModule& module = line.getModule();
141  unsigned int sectorIndex = module.getSectorIndex();
142  unsigned int sideIndex = module.getSideIndex();
143  unsigned int samplingIndex = module.getSamplingIndex();
144  unsigned int index = 192*sideIndex+12*sectorIndex+4*samplingIndex+lineIndex;
145  return index;
146 }
147 
148 
150  : m_c (std::make_unique<Clockwork> (this))
151 {
152 }
153 
155 = default;
156 
158 {
159  return 0;
160 }
161 
163 {
164  return 2;
165 }
166 
167 unsigned int FCALHVManager::beginSectorIndex(unsigned int /*iSampling*/)
168 {
169  return 0;
170 }
171 
172 unsigned int FCALHVManager::endSectorIndex(unsigned int iSampling)
173 {
174  if (iSampling==0) return 16;
175  if (iSampling==1) return 8;
176  if (iSampling==2) return 4;
177  return 0;
178 }
179 
181 {
182  return 0;
183 }
184 
186 {
187  return 3;
188 }
189 
190 const FCALHVModule& FCALHVManager::getHVModule(unsigned int iSide, unsigned int iSector, unsigned int iSampling) const
191 {
192  return *(m_c->moduleArray[iSide][iSector][iSampling]);
193 }
194 
197  const std::vector<const CondAttrListCollection*>& attrLists) const
198 {
199  auto payload = std::make_unique<FCALHVData::Payload>();
200  payload->m_payloadArray.reserve(2*16*3*4);
201  for (unsigned int i=0;i<384;i++) {
202  payload->m_payloadArray[i].voltage = FCALHVData::INVALID;
203  }
204 
205  for (const CondAttrListCollection* atrlistcol : attrLists) {
206 
207  for (CondAttrListCollection::const_iterator citr=atrlistcol->begin(); citr!=atrlistcol->end();++citr) {
208 
209  // 1. decode COOL Channel ID
210  unsigned int chanID = (*citr).first;
211  int cannode = chanID/1000;
212  int line = chanID%1000;
213 
214  // 2. Construct the identifier
215  HWIdentifier id = m_c->hvId->HVLineId(1,1,cannode,line);
216 
217  std::vector<HWIdentifier> electrodeIdVec = idfunc(id);
218 
219  for(size_t i=0;i<electrodeIdVec.size();i++) {
220 
221  HWIdentifier& elecHWID = electrodeIdVec[i];
222  int detector = m_c->elecId->detector(elecHWID);
223  if (detector==5) {
224 
225  float voltage = FCALHVData::INVALID;;
226  if (!((*citr).second)["R_VMEAS"].isNull()) voltage = ((*citr).second)["R_VMEAS"].data<float>();
227  float current = 0.;
228  if (!((*citr).second)["R_IMEAS"].isNull()) current = ((*citr).second)["R_IMEAS"].data<float>();
229 
230  unsigned int sideIndex=1-m_c->elecId->zside(elecHWID); // 0 C side, 1 A side (unline HV numbering)
231  unsigned int samplingIndex=m_c->elecId->hv_eta(elecHWID)-1; // 0 to 2 for the FCAL modules 1-2-3
232  unsigned int sectorIndex=m_c->elecId->module(elecHWID); // 0-15 FCAL1, 0-7 FCAl2, 0-3 FCAL3
233  unsigned int lineIndex=m_c->elecId->gap(elecHWID); // 0-3
234 
235  // do we have to worry about phi sector numbering running backwards in phi for z<0 like in EM/HEC ????
236 
237  unsigned int index = 192*sideIndex+12*sectorIndex+4*samplingIndex+lineIndex;
238 
239  if (index>384) {
240  MsgStream msg (Athena::getMessageSvc(), "EMECHVManager");
241  msg << MSG::ERROR << " invalid index for FCAL " << sideIndex << " " << samplingIndex << " " << sectorIndex << " " << lineIndex << endmsg;
242  continue;
243  }
244 
245 
246  payload->m_payloadArray[index].voltage=voltage;
247  payload->m_payloadArray[index].current=current;
248  payload->m_payloadArray[index].hvLineNo=chanID;
249  } // if FCAL
250  } // loop over electrodes
251  } // loop over collection
252  } // loop over folders
253 
254  return {std::move (payload)};
255 }
256 
259 {
260  std::vector<const CondAttrListCollection*> attrLists;
261  ServiceHandle<StoreGateSvc> detStore ("DetectorStore", "EMBHVManager");
262  const CondAttrListCollection* atrlistcol = nullptr;
263  // Not a typo --- this folder has a lower-case l in the database...
264  if (detStore->retrieve(atrlistcol, "/LAR/DCS/HV/BARREl/I16").isSuccess()) {
265  attrLists.push_back (atrlistcol);
266  }
267  if (detStore->retrieve(atrlistcol, "/LAR/DCS/HV/BARREL/I8").isSuccess()) {
268  attrLists.push_back (atrlistcol);
269  }
270  return getData (SimIdFunc(), attrLists);
271 }
272 
273 
274 #if !(defined(SIMULATIONBASE) || defined(GENERATIONBASE))
277  const std::vector<const CondAttrListCollection*>& attrLists) const
278 {
279  auto idfunc = [&] (HWIdentifier id) { return hvIdMapping.getLArElectrodeIDvec(id); };
280  return getData (idfunc, attrLists);
281 }
282 
283 
285  , const LArHVIdMapping* hvIdMapping) const
286 {
287  const FCALHVModule& module = line.getModule();
288  int sideIndex = module.getSideIndex();
289  int sectorIndex = module.getSectorIndex();
290  int samplingIndex = module.getSamplingIndex();
291  int lineIndex = line.getLineIndex();
292 
293  // ________________________ Construct ElectrodeID ________________________________
294  int id_detector = 5;
295  int id_zside = 1-sideIndex;
296  int id_module = sectorIndex;
297  int id_hv_phi{0};
298  int id_hv_eta = samplingIndex + 1;
299  int id_gap = lineIndex;
300  int id_electrode{0};
301 
302  HWIdentifier elecHWID = m_c->elecId->ElectrodeId(id_detector
303  , id_zside
304  , id_module
305  , id_hv_phi
306  , id_hv_eta
307  , id_gap
308  , id_electrode);
309  // ________________________ ________________________________
310 
311  // Get LArHVLineID corresponding to a given LArElectrodeId
312  HWIdentifier id = hvIdMapping->getLArHVLineID(elecHWID);
313 
314  // Extract HV Line No
315  return m_c->hvId->can_node(id)*1000 + m_c->hvId->hv_line(id);
316 }
317 #endif
FCALHVManager::getData
FCALHVData getData(const LArHVIdMapping &hvIdMapping, const std::vector< const CondAttrListCollection * > &attrLists) const
Definition: FCALHVManager.cxx:276
FCALHVManager::FCALHVData::hvLineNo
int hvLineNo(const FCALHVLine &line) const
Definition: FCALHVManager.cxx:131
fillPileUpNoiseLumi.current
current
Definition: fillPileUpNoiseLumi.py:52
checkFileSG.line
line
Definition: checkFileSG.py:75
FCALHVManager::m_c
std::unique_ptr< const Clockwork > m_c
Definition: FCALHVManager.h:92
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
FCALHVManager::FCALHVManager
FCALHVManager()
Definition: FCALHVManager.cxx:149
FCALHVManager::FCALHVData::Payload::m_payloadArray
std::vector< FCALHVPayload > m_payloadArray
Definition: FCALHVManager.cxx:88
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
FCALHVManager::FCALHVData::voltage
double voltage(const FCALHVLine &line) const
Definition: FCALHVManager.cxx:119
FCALHVManager::~FCALHVManager
~FCALHVManager()
LArHVIdMapping::getLArHVLineID
const HWIdentifier getLArHVLineID(HWIdentifier &electrodeId) const
Return the LArHVLineID corresponding to a given LArElectrodeId.
Definition: LArHVIdMapping.cxx:22
FCALHVManager::getHVModule
const FCALHVModule & getHVModule(unsigned int iSide, unsigned int iSector, unsigned int iSampling) const
Definition: FCALHVManager.cxx:190
LArHVLineID.h
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
CxxUtils::INVALID
@ INVALID
Definition: CachedValue.h:28
AthenaAttributeList.h
Athena::getMessageSvc
IMessageSvc * getMessageSvc(bool quiet=false)
Definition: getMessageSvc.cxx:20
FCALHVManager::getDataSim
FCALHVData getDataSim() const
Definition: FCALHVManager.cxx:258
FCALHVManager::Clockwork::moduleArray
std::unique_ptr< const FCALHVModule > moduleArray[2][16][3]
Definition: FCALHVManager.cxx:79
TRT::Hit::detector
@ detector
Definition: HitInfo.h:78
FCALHVLine.h
FCALHVManager::Clockwork::Clockwork
Clockwork(const FCALHVManager *manager)
Definition: FCALHVManager.cxx:59
python.PyAthena.module
module
Definition: PyAthena.py:134
FCALHVLine
Definition: FCALHVLine.h:15
LArHVCablingSimTool
Mapping from HV lines to electrodes.
Definition: LArHVCablingSimTool.h:29
lumiFormat.i
int i
Definition: lumiFormat.py:92
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
LArHVIdMapping.h
FCALHVManager::Clockwork::~Clockwork
~Clockwork()=default
FCALHVManager::FCALHVData::INVALID
static constexpr double INVALID
Definition: FCALHVManager.h:40
FCALHVManager::FCALHVData::current
double current(const FCALHVLine &line) const
Definition: FCALHVManager.cxx:125
FCALHVManager::Clockwork::hvId
const LArHVLineID * hvId
Definition: FCALHVManager.cxx:81
python.PyKernel.detStore
detStore
Definition: PyKernel.py:41
HWIdentifier.h
id
SG::auxid_t id
Definition: Control/AthContainers/Root/debug.cxx:194
FCALHVManager::FCALHVData::Payload
Definition: FCALHVManager.cxx:86
FCALHVManager::FCALHVData::hvOn
bool hvOn(const FCALHVLine &line) const
Definition: FCALHVManager.cxx:113
AtlCoolConsole.tool
tool
Definition: AtlCoolConsole.py:453
FCALHVManager::FCALHVData::~FCALHVData
~FCALHVData()
FCALHVManager::Clockwork::elecId
const LArElectrodeID * elecId
Definition: FCALHVManager.cxx:80
PixelModuleFeMask_create_db.payload
string payload
Definition: PixelModuleFeMask_create_db.py:69
FCALHVManager::endSamplingIndex
static unsigned int endSamplingIndex()
Definition: FCALHVManager.cxx:185
FCALHVManager::beginSectorIndex
static unsigned int beginSectorIndex(unsigned int iSampling)
Definition: FCALHVManager.cxx:167
DeMoScan.index
string index
Definition: DeMoScan.py:362
InDetDD::other
@ other
Definition: InDetDD_Defs.h:16
LArHVIdMapping
Definition: LArHVIdMapping.h:21
FCALHVManager.h
CondAttrListCollection::const_iterator
ChanAttrListMap::const_iterator const_iterator
Definition: CondAttrListCollection.h:63
FCALHVPayload.h
FCALHVManager::endSectorIndex
static unsigned int endSectorIndex(unsigned int iSampling)
Definition: FCALHVManager.cxx:172
FCALHVManager::FCALHVData::operator=
FCALHVData & operator=(FCALHVData &&other) noexcept
Definition: FCALHVManager.cxx:102
FCALHVModule
Describes one HV Module within the FCAL.
Definition: FCALHVModule.h:20
FCALHVManager::Clockwork
Definition: FCALHVManager.cxx:57
LArHVCablingSimTool.h
FCALHVManager::beginSideIndex
static unsigned int beginSideIndex()
Definition: FCALHVManager.cxx:157
FCALHVManager::idfunc_t
std::function< std::vector< HWIdentifier >(HWIdentifier)> idfunc_t
Definition: FCALHVManager.h:85
python.Logging.manager
manager
Definition: PhysicsAnalysis/D3PDTools/AnaAlgorithm/python/Logging.py:92
LArElectrodeID.h
FCALHVManager::FCALHVData::index
static int index(const FCALHVLine &line)
Definition: FCALHVManager.cxx:137
FCALHVManager::hvLineNo
int hvLineNo(const FCALHVLine &line, const LArHVIdMapping *hvIdMapping) const
Definition: FCALHVManager.cxx:284
FCALHVManager
This class provides direct access to information on the HV electrodes within the barrels....
Definition: FCALHVManager.h:35
StoreGateSvc.h
python.AutoConfigFlags.msg
msg
Definition: AutoConfigFlags.py:7
FCALHVManager::FCALHVData
Definition: FCALHVManager.h:38
LArHVIdMapping::getLArElectrodeIDvec
const std::vector< HWIdentifier > & getLArElectrodeIDvec(HWIdentifier &hvlineId) const
Return a vector of LArElectrodeID corresponding to a given LArHVLineID.
Definition: LArHVIdMapping.cxx:83
FCALHVManager::FCALHVData::FCALHVData
FCALHVData()
FCALHVManager::beginSamplingIndex
static unsigned int beginSamplingIndex()
Definition: FCALHVManager.cxx:180
FCALHVManager::endSideIndex
static unsigned int endSideIndex()
Definition: FCALHVManager.cxx:162
ServiceHandle< StoreGateSvc >
LArHVLineID
Helper for the Liquid Argon Calorimeter High-Voltage identifiers.
Definition: LArHVLineID.h:48