ATLAS Offline Software
ChamberViewer.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_CHAMBERVIEWER_H
5 #define XAODMUONPREPDATA_CHAMBERVIEWER_H
6 
7 #include <type_traits>
8 
11 #include <GeoModelKernel/throwExcept.h>
12 
13 #define BUILD_TRAIT(traitName, conceptPass) \
14  template <typename T> struct traitName{}; \
15  template <conceptPass T> struct traitName<T>{static constexpr bool value = true;}; \
16  template <typename T> requires (!conceptPass <T>) struct traitName<T>{static constexpr bool value = false;};
17 
18 namespace xAOD{
38  namespace ChamberViewConcepts{
40  template <typename ObjType> concept hasIdentifyConcept = requires (const ObjType theObj) {
41  theObj.identify();
42  };
44  template <typename ObjType> concept hasIdentifierHashConcept = requires(const ObjType theObj) {
45  theObj.identifierHash();
46  };
47 
48  BUILD_TRAIT(hasIdentify, hasIdentifyConcept)
49  BUILD_TRAIT(hasIdentifyHash, hasIdentifierHashConcept)
50  template<class HitObjContainer> concept ContainerConcept =
51  (hasIdentify<typename std::remove_pointer_t<typename HitObjContainer::value_type>>::value ||
52  hasIdentifyHash<typename std::remove_pointer_t<typename HitObjContainer::value_type>>::value);
53  }
54 
55  namespace ChamberView {
57  enum class Mode{
58  DetElement ,
59  Chamber
60  };
61  }
62 
63 
64  template<ChamberViewConcepts::ContainerConcept HitObjContainer>
65  class ChamberViewer {
66  public:
67  using value_type = typename HitObjContainer::value_type;
68  using element_type = typename std::remove_pointer_t<value_type>;
70  template <typename HitObjType> struct ref_trait{};
72  template <typename HitObjType> requires (std::is_pointer_v<HitObjType>) struct ref_trait<HitObjType>{
74  using element_type = typename std::remove_pointer_t<HitObjType>;
76  using const_type = typename std::add_const_t<element_type>;
78  using type = std::add_pointer_t<const_type>;
79  };
81  template <typename HitObjType> requires (!std::is_pointer_v<HitObjType>)struct ref_trait<HitObjType>{
83  using const_type = typename std::add_const_t<HitObjType>;
86  };
89 
92  ChamberViewer(const HitObjContainer& container) noexcept:
93  m_container{container} {
94  static_assert(ChamberViewConcepts::hasIdentifyHash<element_type>::value, "Object needs to provide identifierHash" );
95  next();
96  }
99  ChamberViewer(const HitObjContainer& container,
100  const Muon::IMuonIdHelperSvc* idHelperSvc,
101  const ViewMode mode = ViewMode::DetElement) noexcept:
102  m_container{container},
103  m_idHelperSvc{idHelperSvc},
104  m_mode{mode} {
105  static_assert(ChamberViewConcepts::hasIdentify<element_type>::value, "Object needs to provide identify()" );
106  next();
107  }
117  HitObjContainer::const_iterator begin() const noexcept{
118  return m_begin;
119  }
121  HitObjContainer::const_iterator end() const noexcept {
122  return m_end;
123  }
125  std::size_t size() const noexcept{
126  return std::distance(m_begin, m_end);
127  }
130  if (idx >= size()) {
131  THROW_EXCEPTION("Invalid index given "<<typeid(value_type).name()<<" Size: "<<size()<<", requested: "<<idx);
132  }
133  return (*m_begin +idx);
134  }
137  bool next() noexcept {
138  if (m_end == m_container.end()) {
139  return false;
140  }
141  m_begin = m_end;
143  m_currentHash = (*m_end)->identifierHash();
144  m_end = std::find_if(m_begin, m_container.end(),
145  [this](const_ref meas){
146  return meas->identifierHash() != m_currentHash;
147  });
148  } else {
149  m_currentHash = idHash((*m_end)->identify());
150  m_end = std::find_if(m_begin, m_container.end(),
151  [this](const_ref meas){
152  return idHash(meas->identify()) != m_currentHash;
153  });
154  }
155  if (m_begin == m_end) return next(); // veto empty views
156  return true;
157  }
158 
162  bool loadView(const Identifier& chamberId) {
163  static_assert(ChamberViewConcepts::hasIdentify<element_type>::value, "Object needs to provide identify()" );
164  const IdentifierHash detId = idHash(chamberId);
165  m_begin = std::ranges::find_if(m_container,[this,&detId](const_ref meas) {
166  return idHash(meas->identify()) == detId;
167  });
168  m_end = std::find_if(m_begin, m_container.end(),[this,&detId](const_ref meas) {
169  return idHash(meas->identify()) != detId;
170  });
171  return m_begin != m_end;
172  }
176  bool loadView(const IdentifierHash& idHash) {
177  static_assert(ChamberViewConcepts::hasIdentifyHash<element_type>::value, "Object needs to provide identify()" );
178  m_begin = std::ranges::find_if(m_container,[&idHash](const_ref meas) {
179  return meas->identifierHash() == idHash;
180  });
181  m_end = std::find_if(m_begin, m_container.end(),[&idHash](const_ref meas) {
182  return meas->identifierHash() != idHash;
183  });
184  return m_begin != m_end;
185  }
186 
187  bool loadView(std::function<bool(const_ref)> selector) {
188  m_begin = std::ranges::find_if(m_container, selector);
189  m_end = std::find_if(m_begin, m_container.end(),
190  [&selector](const_ref meas) {
191  return !selector(meas);
192  });
193  return m_begin != m_end;
194  }
195 
196  private:
198  IdentifierHash idHash(const Identifier& id) const {
199  return m_mode == ViewMode::DetElement ? m_idHelperSvc->detElementHash(id)
200  : m_idHelperSvc->moduleHash(id);
201  }
202  const HitObjContainer& m_container;
203  const Muon::IMuonIdHelperSvc* m_idHelperSvc{nullptr};
204  const ViewMode m_mode{ViewMode::DetElement};
205  DetectorIDHashType m_currentHash{0};
206  HitObjContainer::const_iterator m_end{m_container.begin()};
207  HitObjContainer::const_iterator m_begin{m_container.begin()};
208  };
209 }
210 #undef buildTrait
211 #endif
xAOD::ChamberViewConcepts::ContainerConcept
concept ContainerConcept
Definition: ChamberViewer.h:50
xAOD::name
name
Definition: TriggerMenuJson_v1.cxx:29
xAOD::ChamberViewer::loadView
bool loadView(const IdentifierHash &idHash)
Loads the view matching the parsed IdentifierHash.
Definition: ChamberViewer.h:176
xAOD::ChamberViewer::ChamberViewer
ChamberViewer(const HitObjContainer &container, const Muon::IMuonIdHelperSvc *idHelperSvc, const ViewMode mode=ViewMode::DetElement) noexcept
Standard constructor.
Definition: ChamberViewer.h:99
xAOD::ChamberViewer::size
std::size_t size() const noexcept
Returns how many hits are in the current chamber.
Definition: ChamberViewer.h:125
xAOD::ChamberViewer::next
bool next() noexcept
Loads the hits from the next chamber.
Definition: ChamberViewer.h:137
xAOD::ChamberViewer::end
HitObjContainer::const_iterator end() const noexcept
End iterator of the current chamber view.
Definition: ChamberViewer.h:121
taskman.template
dictionary template
Definition: taskman.py:317
xAOD::ChamberViewer::requires
requires(!std::is_pointer_v< HitObjType >) struct ref_trait< HitObjType >
Branch if the input value is an object.
Definition: ChamberViewer.h:81
xAOD::other
@ other
Definition: TrackingPrimitives.h:509
athena.value
value
Definition: athena.py:124
xAOD
ICaloAffectedTool is abstract interface for tools checking if 4 mom is in calo affected region.
Definition: ICaloAffectedTool.h:24
xAOD::ChamberViewer::begin
HitObjContainer::const_iterator begin() const noexcept
Begin iterator of the current chamber view.
Definition: ChamberViewer.h:117
const
bool const RAWDATA *ch2 const
Definition: LArRodBlockPhysicsV0.cxx:560
THROW_EXCEPTION
#define THROW_EXCEPTION(MSG)
Definition: MMReadoutElement.cxx:48
xAOD::ChamberView::Mode::DetElement
@ DetElement
View ends if the detElementHash changes.
xAOD::ChamberViewer::ChamberViewer
ChamberViewer(const ChamberViewer &other)=delete
Delete the copy constructor.
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
xAOD::ChamberViewer
Definition: ChamberViewer.h:65
xAOD::ChamberViewer::ChamberViewer
ChamberViewer(ChamberViewer &&other)=default
Standard move constructor.
fillPileUpNoiseLumi.next
next
Definition: fillPileUpNoiseLumi.py:52
xAOD::ChamberViewer::ChamberViewer
ChamberViewer(const HitObjContainer &container) noexcept
Standard constructor.
Definition: ChamberViewer.h:92
xAOD::ChamberViewConcepts::hasIdentifyConcept
concept hasIdentifyConcept
Define the concept that the object needs to have an Identifier method
Definition: ChamberViewer.h:40
xAOD::ChamberViewer::loadView
bool loadView(const Identifier &chamberId)
Loads the view matching the parsed identifier.
Definition: ChamberViewer.h:162
Preparation.mode
mode
Definition: Preparation.py:94
BUILD_TRAIT
#define BUILD_TRAIT(traitName, conceptPass)
Definition: ChamberViewer.h:13
MeasurementDefs.h
xAOD::ChamberViewer::at
HitObjContainer::const_iterator::reference at(const std::size_t idx) const
Returns the i-the measurement from the current chamber.
Definition: ChamberViewer.h:129
xAOD::DetectorIDHashType
unsigned int DetectorIDHashType
@ detector ID element hash
Definition: MeasurementDefs.h:42
xAOD::ChamberViewer::operator=
ChamberViewer & operator=(const ChamberViewer &other)=delete
Delete the copy assignment operator.
xAOD::ChamberViewer::element_type
typename std::remove_pointer_t< value_type > element_type
Definition: ChamberViewer.h:68
python.Dumpers.typename
def typename(t)
Definition: Dumpers.py:194
xAOD::ChamberViewer::idHash
IdentifierHash idHash(const Identifier &id) const
Returns the IdentifierHash from an Identifier.
Definition: ChamberViewer.h:198
xAOD::ChamberViewer::const_ref
ref_trait< value_type >::type const_ref
Definition: ChamberViewer.h:87
xAOD::ChamberViewer::ref_trait
Type trait to find the proper refernce type for the lambda function access.
Definition: ChamberViewer.h:70
python.selector.AtlRunQuerySelectorLhcOlc.selector
selector
Definition: AtlRunQuerySelectorLhcOlc.py:611
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
dq_make_web_display.reference
reference
Definition: dq_make_web_display.py:44
LArNewCalib_DelayDump_OFC_Cali.idx
idx
Definition: LArNewCalib_DelayDump_OFC_Cali.py:69
Muon::IMuonIdHelperSvc
Interface for Helper service that creates muon Identifiers and can be used to print Identifiers.
Definition: IMuonIdHelperSvc.h:27
xAOD::ChamberViewer::loadView
bool loadView(std::function< bool(const_ref)> selector)
Definition: ChamberViewer.h:187
IdentifierHash
This is a "hash" representation of an Identifier. This encodes a 32 bit index which can be used to lo...
Definition: IdentifierHash.h:25
xAOD::ChamberView::Mode
Mode
Switch setting the view mode if the chamber viewer is initialized with the IdHelperSvc.
Definition: ChamberViewer.h:57
xAOD::ChamberViewer::operator=
ChamberViewer & operator=(ChamberViewer &&other)=default
Standard move operator.
xAOD::ChamberViewer::requires
requires(std::is_pointer_v< HitObjType >) struct ref_trait< HitObjType >
Branch if the input value type is a pointer.
Definition: ChamberViewer.h:72
value_type
Definition: EDM_MasterSearch.h:11
xAOD::ChamberViewer::m_container
const HitObjContainer & m_container
Definition: ChamberViewer.h:202
Amg::distance
float distance(const Amg::Vector3D &p1, const Amg::Vector3D &p2)
calculates the distance between two point in 3D space
Definition: GeoPrimitivesHelpers.h:54
xAOD::ChamberViewConcepts::hasIdentifierHashConcept
concept hasIdentifierHashConcept
Define the concept that the object needs to have an IdentifierHash method
Definition: ChamberViewer.h:44
IMuonIdHelperSvc.h
Identifier
Definition: IdentifierFieldParser.cxx:14