ATLAS Offline Software
LArHVPathologyDbCondAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
10 
11 #include "GaudiKernel/IToolSvc.h"
12 #include "GaudiKernel/MsgStream.h"
13 
15 #include "CoralBase/AttributeListException.h"
16 #include "CoralBase/Blob.h"
17 
24 
28 
29 #include "TBufferFile.h"
30 #include "TClass.h"
31 
32 
33 LArHVPathologyDbCondAlg::LArHVPathologyDbCondAlg(const std::string& name, ISvcLocator* pSvcLocator)
34  : AthReentrantAlgorithm(name,pSvcLocator)
35 { }
36 
38 { }
39 
41 {
46 
47  const CaloCell_ID* idHelper = nullptr;
48  ATH_CHECK( detStore()->retrieve (idHelper, "CaloCell_ID") );
49 
50  m_larem_id = idHelper->em_idHelper();
51  m_larhec_id = idHelper->hec_idHelper();
52  m_larfcal_id = idHelper->fcal_idHelper();
53 
54  ATH_CHECK( detStore()->retrieve(m_laronline_id,"LArOnlineID") );
55  ATH_CHECK(detStore()->retrieve(m_hvlineHelper,"LArHVLineID"));
56 
57 
58  m_klass = TClass::GetClass("LArHVPathologiesDb");
59  if(m_klass==nullptr){
60  ATH_MSG_ERROR ( "Can't find TClass LArHVPathologiesDb" );
61  return StatusCode::FAILURE;
62  }
63  else
64  ATH_MSG_DEBUG ( "Got TClass LArHVPathologiesDb" );
65 
66  m_klass->GetStreamerInfo();
67 
68  return StatusCode::SUCCESS;
69 }
70 
72 {
73  return StatusCode::SUCCESS;
74 }
75 
76 /*
77 AthenaAttributeList* LArHVPathologyDbCondAlg::hvPathology2AttrList(const LArHVPathologiesDb& pathologyContainer)
78 {
79  coral::AttributeListSpecification* spec = new coral::AttributeListSpecification();
80 
81  spec->extend("blobVersion","unsigned int"); //Should allow schema evolution if needed
82  spec->extend("Constants","blob"); //Holds the container
83 
84  AthenaAttributeList* attrList = new AthenaAttributeList(*spec);
85 
86  (*attrList)["blobVersion"].data<unsigned int>()=(unsigned int)0;
87  coral::Blob& blob=(*attrList)["Constants"].data<coral::Blob>();
88 
89  TClass* klass = TClass::GetClass("LArHVPathologiesDb");
90  if (klass==NULL) {
91  ATH_MSG_ERROR ( "Can't find TClass LArHVPathologiesDb" );
92  return 0;
93  }
94  else
95  ATH_MSG_DEBUG ( "Got TClass LArHVPathologiesDb" );
96 
97  TBufferFile buf(TBuffer::kWrite);
98 
99  if(buf.WriteObjectAny(&pathologyContainer, klass)!=1) {
100  ATH_MSG_ERROR ( "Failed to stream LArHVPathologiesDb" );
101  return 0;
102  }
103 
104  blob.resize(buf.Length());
105  void* adr = blob.startingAddress();
106  memcpy(adr,buf.Buffer(),buf.Length());
107  return attrList;
108 }
109 */
110 
111 StatusCode LArHVPathologyDbCondAlg::execute(const EventContext& ctx) const {
112 
114 
115  if (writeHandle.isValid()) {
116  ATH_MSG_DEBUG("Found valid write handle");
117  return StatusCode::SUCCESS;
118  }
119 
120  //Get Conditions input
122  const AthenaAttributeList *attrList = *fldrHdl;
123  if (!attrList) {
124  ATH_MSG_ERROR("Do not have AthenaAttributeList for pathology");
125  return StatusCode::FAILURE;
126  }
127  writeHandle.addDependency(fldrHdl);
128 
130  const CaloDetDescrManager* calodetdescrmgr = *caloMgrHandle;
131  writeHandle.addDependency(caloMgrHandle);
132 
133  try {
134  const unsigned blobVersion=(*attrList)["blobVersion"].data<unsigned int>();
135  const coral::Blob& blob = (*attrList)["Constants"].data<coral::Blob>();
136 
137  if (blobVersion!=0) {
138  ATH_MSG_ERROR ( "Can't interpret BLOB version " << blobVersion );
139  return StatusCode::FAILURE;
140  }
141 
142 
143  void* blob_data ATLAS_THREAD_SAFE = const_cast<void*> (blob.startingAddress());
144  TBufferFile buf(TBuffer::kRead, blob.size(), blob_data, false);
145  std::unique_ptr<LArHVPathologiesDb> hvpathdb
146  (static_cast<LArHVPathologiesDb*>(buf.ReadObjectAny(m_klass)));
147 
148  auto hvpath = std::make_unique<LArHVPathology>(hvpathdb.get());
149 
150  fillElectMap(calodetdescrmgr, hvpath.get(), writeHandle);
151 
152 
153  if(writeHandle.record(std::move(hvpath)).isFailure()) {
154  ATH_MSG_ERROR("Could not record LArHVPathology object with "
155  << writeHandle.key()
156  << " with EventRange " << writeHandle.getRange()
157  << " into Conditions Store");
158  return StatusCode::FAILURE;
159  }
160 
161  return StatusCode::SUCCESS;
162 
163  }catch (coral::AttributeListException &e) {
164  ATH_MSG_ERROR ( e.what() );
165  return StatusCode::FAILURE;
166  }
167  // should not come here, but syntactically
168  return StatusCode::SUCCESS;
169 }
170 
171 void
173  LArHVPathology* hvpath,
174  SG::WriteCondHandle<LArHVPathology>& writeHandle) const
175 {
177  const LArHVIdMapping* hvCabling = *cHdl;
178  if(!hvCabling) {
179  ATH_MSG_WARNING("Do not have HV mapping, will not fill LArHVPathology electIndMap !!!");
180  return;
181  }
182  writeHandle.addDependency (cHdl);
183 
184  std::lock_guard<std::mutex> lock(m_mut);
185 
186  std::map<std::pair<Identifier, unsigned int>, std::vector<unsigned short> > &elecMap = hvpath->getElecMap(); //shorthand
187 
188  std::vector<unsigned short> list;
189  std::vector<HWIdentifier> hwlineId;
190  unsigned int HVline = 0;
191  // loop over all EM Identifiers
192  for (auto id: m_larem_id->channel_ids()) {
193  hwlineId.clear();
194  hvCabling->getHVLineInCell(id,hwlineId);
195  // LAr EMB
196  if (abs(m_larem_id->barrel_ec(id))==1 && m_larem_id->sampling(id) > 0) {
197  if (const EMBDetectorElement* embElement = dynamic_cast<const EMBDetectorElement*>(calodetdescrmgr->get_element(id))) {
198  const EMBCellConstLink cell = embElement->getEMBCell();
199  unsigned int nelec = cell->getNumElectrodes();
200  for(auto hwid:hwlineId) {
201  list.clear();
202  HVline = m_hvlineHelper->hv_line(hwid);
203  for (unsigned int i=0;i<nelec;i++) {
204  const EMBHVElectrode& electrode = cell->getElectrode(i);
205  for (unsigned int igap=0;igap<2;igap++) {
206  if ((unsigned)electrode.hvLineNo(igap,hvCabling)==HVline) {
207  list.push_back(2*i+igap);
208  }
209  }
210  }
211  }
212  elecMap.insert(std::make_pair(std::make_pair(id,HVline) ,list));
213  continue;
214  }
215  }
216  // LAr EMEC
217  if (abs(m_larem_id->barrel_ec(id))>1 && m_larem_id->sampling(id) > 0) {
218  if (const EMECDetectorElement* emecElement = dynamic_cast<const EMECDetectorElement*>(calodetdescrmgr->get_element(id))) {
219  const EMECCellConstLink cell = emecElement->getEMECCell();
220  unsigned int nelec = cell->getNumElectrodes();
221  for(auto hwid:hwlineId) {
222  list.clear();
223  HVline = m_hvlineHelper->hv_line(hwid);
224  for (unsigned int i=0;i<nelec;i++) {
225  const EMECHVElectrode& electrode = cell->getElectrode(i);
226  for (unsigned int igap=0;igap<2;igap++) {
227  if ((unsigned)electrode.hvLineNo(igap,hvCabling)==HVline) {
228  list.push_back(2*i+igap);
229  }
230  }
231  }
232  }
233  elecMap.insert(std::make_pair(std::make_pair(id,HVline),list));
234  continue;
235  }
236  }
237  // EMBPS
238  if (abs(m_larem_id->barrel_ec(id))==1 && m_larem_id->sampling(id)==0) {
239  if (const EMBDetectorElement* embElement = dynamic_cast<const EMBDetectorElement*>(calodetdescrmgr->get_element(id))) {
240  const EMBCellConstLink cell = embElement->getEMBCell();
241  const EMBPresamplerHVModule& hvmodule = cell->getPresamplerHVModule ();
242  for(auto hwid:hwlineId) {
243  list.clear();
244  HVline = m_hvlineHelper->hv_line(hwid);
245  for (unsigned int igap=0;igap<2;igap++) {
246  if ((unsigned)hvmodule.hvLineNo(igap,hvCabling)==HVline) {
247  list.push_back(igap);
248  }
249  }
250  elecMap.insert(std::make_pair(std::make_pair(id,HVline),list));
251  continue;
252  }
253  }
254  }
255  // EMECPS
256  if (abs(m_larem_id->barrel_ec(id))>1 && m_larem_id->sampling(id)==0) {
257  if (const EMECDetectorElement* emecElement = dynamic_cast<const EMECDetectorElement*>(calodetdescrmgr->get_element(id))) {
258  const EMECCellConstLink cell = emecElement->getEMECCell();
259  const EMECPresamplerHVModule& hvmodule = cell->getPresamplerHVModule ();
260  for(auto hwid:hwlineId) {
261  list.clear();
262  HVline = m_hvlineHelper->hv_line(hwid);
263  for (unsigned int igap=0;igap<2;igap++) {
264  if ((unsigned)hvmodule.hvLineNo(igap,hvCabling)==HVline) {
265  list.push_back(igap);
266  }
267  }
268  elecMap.insert(std::make_pair(std::make_pair(id,HVline),list));
269  continue;
270  }
271  }
272  }
273  }
274  // loop over all HEC Identifiers
275  for (auto const& id: m_larhec_id->channel_ids()) {
276  hwlineId.clear();
277  hvCabling->getHVLineInCell(id,hwlineId);
278  if (const HECDetectorElement* hecElement = dynamic_cast<const HECDetectorElement*>(calodetdescrmgr->get_element(id))) {
279  const HECCellConstLink cell = hecElement->getHECCell();
280  unsigned int nsubgaps = cell->getNumSubgaps();
281  for(auto hwid:hwlineId) {
282  list.clear();
283  HVline = m_hvlineHelper->hv_line(hwid);
284  for (unsigned int i=0;i<nsubgaps;i++) {
285  const HECHVSubgap& subgap = cell->getSubgap(i);
286  if ((unsigned)subgap.hvLineNo(hvCabling)==HVline) {
287  list.push_back(i);
288  }
289  }
290  elecMap.insert(std::make_pair(std::make_pair(id,HVline),list));
291  continue;
292  }
293  }
294  }
295  // loop over all FCAL Identifiers
296  for (auto const& id: m_larfcal_id->channel_ids()) {
297  hwlineId.clear();
298  hvCabling->getHVLineInCell(id,hwlineId);
299  if (const FCALDetectorElement* fcalElement = dynamic_cast<const FCALDetectorElement*>(calodetdescrmgr->get_element(id))) {
300  const FCALTile* tile = fcalElement->getFCALTile();
301  unsigned int nlines = tile->getNumHVLines();
302  for(auto hwid:hwlineId) {
303  list.clear();
304  HVline = m_hvlineHelper->hv_line(hwid);
305  for (unsigned int i=0;i<nlines;i++) {
306  const FCALHVLine* line2 = tile->getHVLine(i);
307  if (line2) {
308  if ((unsigned)line2->hvLineNo(hvCabling)==HVline) {
309  list.push_back(i);
310  }
311  }
312  }
313  elecMap.insert(std::make_pair(std::make_pair(id,HVline),list));
314  continue;
315  }
316  }
317  }
318 
319  return;
320 
321 }
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
AllowedVariables::e
e
Definition: AsgElectronSelectorTool.cxx:37
LArHVPathologyDbCondAlg::m_caloMgrKey
SG::ReadCondHandleKey< CaloDetDescrManager > m_caloMgrKey
Definition: LArHVPathologyDbCondAlg.h:47
LArHVPathologyDbCondAlg::initialize
virtual StatusCode initialize() override
Definition: LArHVPathologyDbCondAlg.cxx:40
EMBHVElectrode
Definition: EMBHVElectrode.h:15
LArEM_ID.h
LArHVPathologyDbCondAlg::m_larfcal_id
const LArFCAL_ID * m_larfcal_id
Definition: LArHVPathologyDbCondAlg.h:53
EMECDetectorElement
LAr EMEC Detector Element.
Definition: CaloDetectorElements.h:116
LArHVPathology.h
ReadCellNoiseFromCool.cell
cell
Definition: ReadCellNoiseFromCool.py:53
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
LArHVPathologyDbCondAlg::LArHVPathologyDbCondAlg
LArHVPathologyDbCondAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: LArHVPathologyDbCondAlg.cxx:33
CaloCell_ID::em_idHelper
const LArEM_ID * em_idHelper() const
access to EM idHelper
Definition: CaloCell_ID.h:63
LArHVPathologyDbCondAlg::m_klass
TClass * m_klass
Definition: LArHVPathologyDbCondAlg.h:59
CaloDetDescrManager_Base::get_element
const CaloDetDescrElement * get_element(const Identifier &cellId) const
get element by its identifier
Definition: CaloDetDescrManager.cxx:159
LArHVIdMapping::getHVLineInCell
void getHVLineInCell(const Identifier &offId, std::vector< HWIdentifier > &hvlineId) const
Returns a vector<HVLineID> given an input offlineID.
Definition: LArHVIdMapping.cxx:207
LArHVLineID::hv_line
int hv_line(const HWIdentifier id) const
Return the HV line number from an HighVoltage line identifier.
Definition: LArHVLineID.h:286
LArHVPathology::getElecMap
std::map< std::pair< Identifier, unsigned int >, std::vector< unsigned short > > & getElecMap()
Definition: LArHVPathology.h:26
LArHVPathologyDbCondAlg::fillElectMap
void fillElectMap(const CaloDetDescrManager *calodetdescrmgr, LArHVPathology *hvpath, SG::WriteCondHandle< LArHVPathology > &writeHandle) const
Definition: LArHVPathologyDbCondAlg.cxx:172
python.subdetectors.tile.Blob
Blob
Definition: tile.py:17
LArEM_Base_ID::sampling
int sampling(const Identifier id) const
return sampling according to :
LArHEC_ID.h
LArHVLineID.h
EMBDetectorElement
LAr EMB Detector Element.
Definition: CaloDetectorElements.h:52
AthenaAttributeList.h
LArHVPathologyDbCondAlg::execute
virtual StatusCode execute(const EventContext &ctx) const override
Definition: LArHVPathologyDbCondAlg.cxx:111
EMECPresamplerHVModule.h
CaloCell_ID.h
CaloCell_ID::hec_idHelper
const LArHEC_ID * hec_idHelper() const
access to HEC idHelper
Definition: CaloCell_ID.h:69
AthCommonDataStore< AthCommonMsg< Gaudi::Algorithm > >::detStore
const ServiceHandle< StoreGateSvc > & detStore() const
The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:95
HECDetectorElement
LAr HEC Detector Element.
Definition: CaloDetectorElements.h:189
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
ReadCellNoiseFromCool.tile
tile
Definition: ReadCellNoiseFromCool.py:92
FCALTile
A tile of the forward calorimeter readout geometry.
Definition: FCALTile.h:27
EMBCell.h
LArHVPathologyDbCondAlg::m_larem_id
const LArEM_ID * m_larem_id
Definition: LArHVPathologyDbCondAlg.h:51
LArHVPathologiesDb.h
FCALHVLine
Definition: FCALHVLine.h:15
EMBHVElectrode::hvLineNo
int hvLineNo(int iGap, const LArHVIdMapping *hvIdMapping) const
Definition: EMBHVElectrode.cxx:43
LArFCAL_Base_ID::channel_ids
const std::vector< Identifier > & channel_ids() const
provide acces to channel id vector, accessed via hash
LArHVPathologyDbCondAlg::m_pathologyFolderKey
SG::ReadCondHandleKey< AthenaAttributeList > m_pathologyFolderKey
Definition: LArHVPathologyDbCondAlg.h:45
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
lumiFormat.i
int i
Definition: lumiFormat.py:85
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
FCALDetectorElement
LAr FCAL Detector Element.
Definition: CaloDetectorElements.h:261
HECHVSubgap::hvLineNo
int hvLineNo(const LArHVIdMapping *hvIdMapping) const
Definition: HECHVSubgap.cxx:45
LArHVPathologyDbCondAlg::m_hvlineHelper
const LArHVLineID * m_hvlineHelper
Definition: LArHVPathologyDbCondAlg.h:55
EMBPresamplerHVModule::hvLineNo
int hvLineNo(int iGap, const LArHVIdMapping *hvIdMapping) const
Definition: EMBPresamplerHVModule.cxx:91
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
histSizes.list
def list(name, path='/')
Definition: histSizes.py:38
CaloCell_ID
Helper class for offline cell identifiers.
Definition: CaloCell_ID.h:34
LArHVPathologyDbCondAlg::finalize
virtual StatusCode finalize() override
Definition: LArHVPathologyDbCondAlg.cxx:71
LArHVPathologyDbCondAlg::m_mut
std::mutex m_mut
Definition: LArHVPathologyDbCondAlg.h:57
WriteCalibToCool.blobVersion
blobVersion
Definition: WriteCalibToCool.py:82
EMBPresamplerHVModule.h
EMECPresamplerHVModule::hvLineNo
int hvLineNo(int iGap, const LArHVIdMapping *hvIdMapping) const
Definition: EMECPresamplerHVModule.cxx:74
LArHVPathologiesDb
Definition: LArHVPathologiesDb.h:19
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
LArEM_Base_ID::barrel_ec
int barrel_ec(const Identifier id) const
return barrel_ec according to :
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
LArHVPathologyDbCondAlg::~LArHVPathologyDbCondAlg
virtual ~LArHVPathologyDbCondAlg()
Definition: LArHVPathologyDbCondAlg.cxx:37
LArFCAL_ID.h
LArHVIdMapping
Definition: LArHVIdMapping.h:21
CaloDetDescrManager
This class provides the client interface for accessing the detector description information common to...
Definition: CaloDetDescrManager.h:473
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
EMECPresamplerHVModule
Describes one HV Module within the EMEc Presampler.
Definition: EMECPresamplerHVModule.h:22
LArHVPathology
Definition: LArHVPathology.h:15
LArG4FSStartPointFilterLegacy.line2
line2
Definition: LArG4FSStartPointFilterLegacy.py:59
ATLAS_THREAD_SAFE
#define ATLAS_THREAD_SAFE
Definition: checker_macros.h:211
LArHVPathologyDbCondAlg::m_laronline_id
const LArOnlineID * m_laronline_id
Definition: LArHVPathologyDbCondAlg.h:54
EMECHVElectrode
Definition: EMECHVElectrode.h:15
LArEM_Base_ID::channel_ids
const std::vector< Identifier > & channel_ids() const
provide access to channel id vector, accessed via hash
LArHEC_Base_ID::channel_ids
const std::vector< Identifier > & channel_ids() const
provide access to channel id vector, accessed via hash
checker_macros.h
Define macros for attributes used to control the static checker.
LArHVPathologyDbCondAlg::m_hvPathologyKey
SG::WriteCondHandleKey< LArHVPathology > m_hvPathologyKey
Definition: LArHVPathologyDbCondAlg.h:49
LArHVPathologyDbCondAlg::m_larhec_id
const LArHEC_ID * m_larhec_id
Definition: LArHVPathologyDbCondAlg.h:52
SG::WriteCondHandle
Definition: WriteCondHandle.h:26
HECHVSubgap
Definition: HECHVSubgap.h:15
EMECHVElectrode::hvLineNo
int hvLineNo(int iGap, const LArHVIdMapping *hvIdMapping) const
Definition: EMECHVElectrode.cxx:49
EMBPresamplerHVModule
Describes one HV Module within the EMB Presampler.
Definition: EMBPresamplerHVModule.h:22
CaloCondBlobAlgs_fillNoiseFromASCII.blob
blob
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:96
CaloCell_ID::fcal_idHelper
const LArFCAL_ID * fcal_idHelper() const
access to FCAL idHelper
Definition: CaloCell_ID.h:75
CaloDetectorElements.h
Calo Subsystem specific Detector Elements + Dummy element for testing.
LArHVPathologyDbCondAlg.h
LArOnlineID.h
LArHVPathologyDbCondAlg::m_hvMappingKey
SG::ReadCondHandleKey< LArHVIdMapping > m_hvMappingKey
Definition: LArHVPathologyDbCondAlg.h:46
SG::WriteCondHandle::addDependency
void addDependency(const EventIDRange &range)
Definition: WriteCondHandle.h:275