ATLAS Offline Software
AccessorMacros.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 #ifndef XAODMUONPREPDATA_ACCESSOR_MACROS_H
5 #define XAODMUONPREPDATA_ACCESSOR_MACROS_H
6 #include "GeoModelHelpers/throwExcept.h"
10 #define IMPLEMENT_SETTER_GETTER( CLASS_NAME, DTYPE, GETTER, SETTER) \
11  DTYPE CLASS_NAME::GETTER() const { \
12  static const SG::AuxElement::Accessor<DTYPE> acc{preFixStr + #GETTER}; \
13  return acc(*this); \
14  } \
15  \
16  void CLASS_NAME::SETTER(DTYPE value) { \
17  static const SG::AuxElement::Accessor<DTYPE> acc{preFixStr + #GETTER}; \
18  acc(*this) = value; \
19  }
20 
24 #define IMPLEMENT_SETTER_GETTER_WITH_CAST( CLASS_NAME, STORE_DTYPE, CAST_DTYPE, GETTER, SETTER) \
25  CAST_DTYPE CLASS_NAME::GETTER() const { \
26  static const SG::AuxElement::Accessor<STORE_DTYPE> acc{preFixStr + #GETTER}; \
27  return static_cast<CAST_DTYPE>(acc(*this)); \
28  } \
29  \
30  void CLASS_NAME::SETTER(CAST_DTYPE value) { \
31  static const SG::AuxElement::Accessor<STORE_DTYPE> acc{preFixStr + #GETTER}; \
32  acc(*this) = static_cast<STORE_DTYPE>(value); \
33  }
34 
37 #define IMPLEMENT_VECTOR_SETTER_GETTER(CLASS_NAME, DTYPE, GETTER, SETTER) \
38  const std::vector<DTYPE>& CLASS_NAME::GETTER() const { \
39  static const SG::AuxElement::Accessor<std::vector<DTYPE>> acc{preFixStr + #GETTER}; \
40  return acc(*this); \
41  } \
42  \
43  void CLASS_NAME::SETTER(const std::vector<DTYPE>& value) { \
44  static const SG::AuxElement::Accessor<std::vector<DTYPE>> acc{preFixStr + #GETTER}; \
45  acc(*this) = value; \
46  }
47 
55 #define IMPLEMENT_READOUTELEMENT(CLASS_NAME, CACHED_VALUE, READOUT_ELEMENT_TYPE) \
56  void CLASS_NAME::setReadoutElement(const MuonGMR4::READOUT_ELEMENT_TYPE* readoutEle) { \
57  CACHED_VALUE.set(readoutEle); \
58  } \
59  \
60  const MuonGMR4::READOUT_ELEMENT_TYPE* CLASS_NAME::readoutElement() const { \
61  if (!CACHED_VALUE.isValid()) { \
62  ServiceHandle<StoreGateSvc> service{"DetectorStore", #CLASS_NAME}; \
63  const MuonGMR4::MuonDetectorManager* detMgr{}; \
64  if (!service.retrieve().isSuccess() || \
65  !service->retrieve(detMgr).isSuccess()){ \
66  THROW_EXCEPTION("Failed to retrieve the Run4 muon detector manager. "<< \
67  "Please schedule the MuonGeometry in your job"); \
68  } \
69  const IdentifierHash hash{identifierHash()}; \
70  const MuonGMR4::READOUT_ELEMENT_TYPE* re = detMgr->get##READOUT_ELEMENT_TYPE(hash); \
71  if (!re) { \
72  const Identifier id{static_cast<Identifier::value_type>(identifier())}; \
73  THROW_EXCEPTION(detMgr->idHelperSvc()->toString(id) \
74  <<" does not have a readout element."); \
75  } \
76  CACHED_VALUE.set(re); \
77  } \
78  return (*CACHED_VALUE.ptr()); \
79  }
80 
84 #define PRD_AUXVARIABLE(VAR) \
85  do { \
86  static const std::string varName =preFixStr+#VAR; \
87  static const auxid_t auxid = getAuxID(varName, VAR); \
88  regAuxVar(auxid, varName, VAR); \
89  } while (false);
90 
91 #endif