ATLAS Offline Software
LArLATOMEMappingAlg.cxx
Go to the documentation of this file.
1 //dear emacs, this is -*-c++-*-
2 
3 /*
4  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
5 */
6 
7 #include "LArLATOMEMappingAlg.h"
9 #include "CoralBase/Blob.h"
10 #include "CoralBase/AttributeList.h"
11 
14 
16 
17  ATH_MSG_DEBUG("initializing");
18 
19  // Read Handles
22 
23  return StatusCode::SUCCESS;
24 }
25 
26 
28  ATH_MSG_DEBUG("executing");
29 
31 
32  if (writeHandle.isValid()) {
33  ATH_MSG_DEBUG("Found valid write handle");
34  return StatusCode::SUCCESS;
35  }
36 
38  const CondAttrListCollection * catr{*readHandle};
39 
40  if (catr==nullptr) {
41  ATH_MSG_ERROR("Failed to retrieve CondAttrListCollection with key " << m_readKey.key());
42  return StatusCode::FAILURE;
43  }
44 
45 
46  writeHandle.addDependency(readHandle);
47 
48  //Loop over COOL channels:
49  CondAttrListCollection::const_iterator chanIt=catr->begin();
50  CondAttrListCollection::const_iterator chanIt_e=catr->end();
51  // needs a length of blobs first
52  const coral::Blob& bls = chanIt->second["SourceIDs"].data<coral::Blob>();
53  unsigned nLat=bls.size()/sizeof(uint32_t);
54  std::unique_ptr<LArLATOMEMapping> latomeMap=std::make_unique<LArLATOMEMapping>(nLat);
55 
56  for (;chanIt!=chanIt_e;++chanIt) {
57 
58  const coral::AttributeList& attr = chanIt->second;
59  const coral::Blob& blobsourceId=attr["SourceIDs"].data<coral::Blob>();
60  unsigned nLatome=blobsourceId.size()/sizeof(uint32_t);
61  const coral::Blob& blobonlineId=attr["OnlineIDs"].data<coral::Blob>();
62  unsigned nChan=blobonlineId.size()/blobsourceId.size();
63  const uint32_t* pblobsourceId=static_cast<const uint32_t*>(blobsourceId.startingAddress());
64  const uint32_t* pblobonlineId=static_cast<const uint32_t*>(blobonlineId.startingAddress());
65 
66  if (nChan!=N_LATOME_CHANNELS) {
67  ATH_MSG_ERROR("Number of channels read from DB (" << nChan << ") does not match expected "
68  <<N_LATOME_CHANNELS << ")");
69  return StatusCode::FAILURE;
70  }
71 
72  for (unsigned i=0;i<nLatome;++i) {
73  const unsigned sid=pblobsourceId[i];
74  ATH_MSG_DEBUG("Latome SID: "<<sid);
75  std::pair<unsigned, std::vector<HWIdentifier> > entry{sid,{}};
76  entry.second.reserve(N_LATOME_CHANNELS);
77  for (unsigned j=0;j<N_LATOME_CHANNELS ;++j) {
78  const HWIdentifier hwid=HWIdentifier(Identifier32(pblobonlineId[i*N_LATOME_CHANNELS + j]));
79  if (hwid.is_valid() && hwid != 0) {
80  entry.second.push_back(hwid);
81  } else {
82  entry.second.push_back(latomeMap->m_hwidEmpty);
83  }
84  }
85  latomeMap->m_map.insert(std::move(entry));
86  }//end loop over LATOME sourceIDs
87  ATH_MSG_INFO("Done reading latome mapping");
88  ATH_MSG_INFO("Found " << nLatome << " LATOMEs ");
89  } // end over cool channels
90 
91  if(writeHandle.record(std::move(latomeMap)).isFailure()) {
92  ATH_MSG_ERROR("Could not record LArLATOMEMapping object with "
93  << writeHandle.key()
94  << " with EventRange " << writeHandle.getRange()
95  << " into Conditions Store");
96  return StatusCode::FAILURE;
97  }
98  ATH_MSG_INFO("recorded new " << writeHandle.key() << " with range " << writeHandle.getRange() << " into Conditions Store");
99 
100  return StatusCode::SUCCESS;
101 }
102 
Identifier32
Definition: Identifier32.h:25
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
LArLATOMEMapping::m_map
std::unordered_map< unsigned, std::vector< HWIdentifier > > m_map
Definition: LArLATOMEMapping.h:54
python.subdetectors.tile.Blob
Blob
Definition: tile.py:17
python.PyKernel.AttributeList
AttributeList
Definition: PyKernel.py:36
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
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
AthenaAttributeList.h
Identifier::is_valid
bool is_valid() const
Check if id is in a valid state.
N_LATOME_CHANNELS
#define N_LATOME_CHANNELS
fixed number of channels on one LATOME board
Definition: LArLATOMEMapping.h:22
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
lumiFormat.i
int i
Definition: lumiFormat.py:92
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
LArLATOMEMappingAlg::m_readKey
SG::ReadCondHandleKey< CondAttrListCollection > m_readKey
Definition: LArLATOMEMappingAlg.h:34
CaloCell_SuperCell_ID.h
Helper class for offline supercell identifiers.
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
LArLATOMEMappingAlg::initialize
virtual StatusCode initialize() override
Definition: LArLATOMEMappingAlg.cxx:15
LArLATOMEMappingAlg.h
GetAllXsec.entry
list entry
Definition: GetAllXsec.py:132
LArLATOMEMapping::m_hwidEmpty
const HWIdentifier m_hwidEmpty
Invalid default instance of HWIdentifier.
Definition: LArLATOMEMapping.h:50
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
CondAttrListCollection::const_iterator
ChanAttrListMap::const_iterator const_iterator
Definition: CondAttrListCollection.h:63
LArOnline_SuperCellID.h
LArLATOMEMappingAlg::m_writeKey
SG::WriteCondHandleKey< LArLATOMEMapping > m_writeKey
Definition: LArLATOMEMappingAlg.h:35
LArLATOMEMappingAlg::execute
virtual StatusCode execute() override
Definition: LArLATOMEMappingAlg.cxx:27
SG::WriteCondHandle
Definition: WriteCondHandle.h:26