ATLAS Offline Software
MuonDigitizationTool.icc
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 #ifndef MUONDIGITIZATION_MUONDIGITIZATIONTOOL_ICC
5 #define MUONDIGITIZATION_MUONDIGITIZATIONTOOL_ICC
6 
7 #include <StoreGate/ReadHandle.h>
8 #include <StoreGate/WriteHandle.h>
9 #include <StoreGate/ReadCondHandle.h>
10 
11 namespace MuonR4{
12  template <class Container>
13  StatusCode MuonDigitizationTool::retrieveContainer(const EventContext& ctx,
14  const SG::ReadHandleKey<Container>& key,
15  const Container* & contPtr) const {
16  if (key.empty()) {
17  ATH_MSG_VERBOSE("No container key has been set for "<<typeid(Container).name());
18  contPtr = nullptr;
19  return StatusCode::SUCCESS;
20  }
21  SG::ReadHandle<Container> readHandle{key, ctx};
22  ATH_CHECK(readHandle.isPresent());
23  contPtr = readHandle.cptr();
24  return StatusCode::SUCCESS;
25  }
26  template <class Container> StatusCode MuonDigitizationTool::retrieveConditions(const EventContext&ctx,
27  const SG::ReadCondHandleKey<Container>& key,
28  const Container* & contPtr) const {
29  if (key.empty()) {
30  ATH_MSG_VERBOSE("No conditions key has been set for "<<typeid(Container).name());
31  contPtr = nullptr;
32  return StatusCode::SUCCESS;
33  }
34  SG::ReadCondHandle<Container> readCondHandle{key, ctx};
35  ATH_CHECK(readCondHandle.isValid());
36  contPtr = readCondHandle.cptr();
37  return StatusCode::SUCCESS;
38  }
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)};
43 
44  if (static_cast<unsigned>(hash) >= digitCache.size()) {
45  digitCache.resize(static_cast<unsigned>(hash) + 1);
46  }
47  std::unique_ptr<DigitColl>& coll = digitCache[static_cast<unsigned>(hash)];
48  if (!coll) {
49  coll = std::make_unique<DigitColl>(m_idHelperSvc->chamberId(hitId), hash);
50  }
51  return coll.get();
52  }
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));
63  }
64  }
65  return StatusCode::SUCCESS;
66  }
67 }
68 #endif