2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
4 #ifndef MUONDIGITIZATION_MUONDIGITIZATIONTOOL_ICC
5 #define MUONDIGITIZATION_MUONDIGITIZATIONTOOL_ICC
7 #include <StoreGate/ReadHandle.h>
8 #include <StoreGate/WriteHandle.h>
9 #include <StoreGate/ReadCondHandle.h>
12 template <class Container>
13 StatusCode MuonDigitizationTool::retrieveContainer(const EventContext& ctx,
14 const SG::ReadHandleKey<Container>& key,
15 const Container* & contPtr) const {
17 ATH_MSG_VERBOSE("No container key has been set for "<<typeid(Container).name());
19 return StatusCode::SUCCESS;
21 SG::ReadHandle<Container> readHandle{key, ctx};
22 ATH_CHECK(readHandle.isPresent());
23 contPtr = readHandle.cptr();
24 return StatusCode::SUCCESS;
26 template <class Container> StatusCode MuonDigitizationTool::retrieveConditions(const EventContext&ctx,
27 const SG::ReadCondHandleKey<Container>& key,
28 const Container* & contPtr) const {
30 ATH_MSG_VERBOSE("No conditions key has been set for "<<typeid(Container).name());
32 return StatusCode::SUCCESS;
34 SG::ReadCondHandle<Container> readCondHandle{key, ctx};
35 ATH_CHECK(readCondHandle.isValid());
36 contPtr = readCondHandle.cptr();
37 return StatusCode::SUCCESS;
39 template <class DigitColl>
40 DigitColl* MuonDigitizationTool::fetchCollection(const Identifier& hitId,
41 OutDigitCache_t<DigitColl>& digitCache) const {
42 const IdentifierHash hash{m_idHelperSvc->moduleHash(hitId)};
44 if (static_cast<unsigned>(hash) >= digitCache.size()) {
45 digitCache.resize(static_cast<unsigned>(hash) + 1);
47 std::unique_ptr<DigitColl>& coll = digitCache[static_cast<unsigned>(hash)];
49 coll = std::make_unique<DigitColl>(m_idHelperSvc->chamberId(hitId), hash);
53 template <class DigitCont, class DigitColl>
54 StatusCode MuonDigitizationTool:: writeDigitContainer(const EventContext& ctx,
55 const SG::WriteHandleKey<DigitCont>& key,
56 OutDigitCache_t<DigitColl>&& digitCache,
57 unsigned int hashMax) const {
58 SG::WriteHandle<DigitCont> writeHandle{key, ctx};
59 ATH_CHECK(writeHandle.record(std::make_unique<DigitCont>(hashMax)));
60 for (size_t coll_hash = 0; coll_hash < digitCache.size(); ++coll_hash) {
61 if (digitCache[coll_hash] && digitCache[coll_hash]->size()) {
62 ATH_CHECK(writeHandle->addCollection(digitCache[coll_hash].release(), coll_hash));
65 return StatusCode::SUCCESS;