ATLAS Offline Software
Loading...
Searching...
No Matches
LArOnOffMappingAlg.cxx
Go to the documentation of this file.
1//dear emacs, this is -*-c++-*-
2
3/*
4 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
5*/
6
9#include "CoralBase/Blob.h"
10
15
16
18
19 ATH_MSG_DEBUG("initializing");
20
21 // Read Handles
22 ATH_CHECK( m_readKey.initialize() );
23 ATH_CHECK( m_writeKey.initialize() );
24
25 return StatusCode::SUCCESS;
26}
27
28
29StatusCode LArOnOffMappingAlg::execute(const EventContext& ctx) const {
30 ATH_MSG_DEBUG("executing");
31
33
34 if (writeHandle.isValid()) {
35 ATH_MSG_DEBUG("Found valid write handle");
36 return StatusCode::SUCCESS;
37 }
38
40 const AthenaAttributeList* attr{*readHandle};
41
42 if (attr==nullptr) {
43 ATH_MSG_ERROR("Failed to retrieve CondAttributeListCollection with key " << m_readKey.key());
44 return StatusCode::FAILURE;
45 }
46
47 writeHandle.addDependency(readHandle);
48
49 const LArOnlineID_Base* larOnlineID=nullptr;
50 const CaloCell_Base_ID* calocellID=nullptr;
51
52 //Identifier helper:
53 if (m_isSuperCell) {
54 const LArOnline_SuperCellID* scidhelper = nullptr;
55 ATH_CHECK(detStore()->retrieve(scidhelper,"LArOnline_SuperCellID"));
56 larOnlineID=scidhelper; //cast to base-class
57
58 const CaloCell_SuperCell_ID* sccaloid = nullptr;
59 ATH_CHECK(detStore()->retrieve(sccaloid,"CaloCell_SuperCell_ID"));
60 calocellID=sccaloid; //cast to base-class
61
62 }
63 else {//regular cells
64 const LArOnlineID* idhelper = nullptr;
65 ATH_CHECK(detStore()->retrieve(idhelper,"LArOnlineID"));
66 larOnlineID=idhelper; //cast to base-class
67
68 const CaloCell_ID* sccaloid = nullptr;
69 ATH_CHECK(detStore()->retrieve(sccaloid,"CaloCell_ID"));
70 calocellID=sccaloid; //cast to base-class
71
72 }
73
74
75 std::unique_ptr<LArOnOffIdMapping> onOffMap=std::make_unique<LArOnOffIdMapping>(larOnlineID,calocellID);
76
77 const coral::Blob& blobOnOff=(*attr)["OnlineHashToOfflineId"].data<coral::Blob>();
78 unsigned nChan=blobOnOff.size()/sizeof(uint32_t);
79 const uint32_t* pBlobOnOff=static_cast<const uint32_t*>(blobOnOff.startingAddress());
80
81 if (nChan!=larOnlineID->channelHashMax()) {
82 ATH_MSG_ERROR("Number of channels read from DB (" << nChan << ") does not match online hash max ("
83 <<larOnlineID->channelHashMax() << ")");
84 return StatusCode::FAILURE;
85 }
86
87
88 unsigned nConnected=0;
89
90 for (unsigned i=0;i<nChan;++i) {
91 const Identifier id=Identifier(Identifier32(pBlobOnOff[i]));
92 if (id.is_valid()) {
93 const IdentifierHash oflHash=calocellID->calo_cell_hash(id);
94 const HWIdentifier hwid=larOnlineID->channel_Id(IdentifierHash(i));
95 ++nConnected;
96 onOffMap->m_onlHashToOffline[i]=id;
97 onOffMap->m_oflHashToOnline[oflHash]=hwid;
98 onOffMap->m_onlHashToOflHash[i]=oflHash;
99 }
100 }//end loop over channels
101
102 ATH_MSG_INFO("Done reading online/offline identifier mapping");
103 ATH_MSG_INFO("Found " << nChan << " online identifier and " << nConnected << " offline identifier. "
104 << nChan-nConnected << " disconnected channels.");
105
106 if(writeHandle.record(std::move(onOffMap)).isFailure()) {
107 ATH_MSG_ERROR("Could not record LArOnOffMapping object with "
108 << writeHandle.key()
109 << " with EventRange " << writeHandle.getRange()
110 << " into Conditions Store");
111 return StatusCode::FAILURE;
112 }
113 ATH_MSG_INFO("recorded new " << writeHandle.key() << " with range " << writeHandle.getRange() << " into Conditions Store");
114
115 return StatusCode::SUCCESS;
116}
117
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_DEBUG(x)
Helper class for offline supercell identifiers.
const ServiceHandle< StoreGateSvc > & detStore() const
An AttributeList represents a logical row of attributes in a metadata table.
Helper base class for offline cell identifiers.
IdentifierHash calo_cell_hash(const Identifier cellId) const
create hash id from 'global' cell id
Helper class for offline cell identifiers.
Definition CaloCell_ID.h:34
Helper class for offline supercell identifiers.
This is a "hash" representation of an Identifier.
virtual StatusCode initialize() override
Gaudi::Property< bool > m_isSuperCell
SG::ReadCondHandleKey< AthenaAttributeList > m_readKey
SG::WriteCondHandleKey< LArOnOffIdMapping > m_writeKey
virtual StatusCode execute(const EventContext &ctx) const override
Helper for the Liquid Argon Calorimeter cell identifiers.
HWIdentifier channel_Id(int barrel_ec, int pos_neg, int feedthrough, int slot, int channel) const
create channel identifier from fields
size_type channelHashMax() const
Define channel hash tables max size.
const std::string & key() const
void addDependency(const EventIDRange &range)
const EventIDRange & getRange() const
StatusCode record(const EventIDRange &range, T *t)
record handle, with explicit range DEPRECATED