ATLAS Offline Software
ChamberViewer.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3 */
4 #ifndef XAODMUONPREPDATA_CHAMBERVIEWER_H
5 #define XAODMUONPREPDATA_CHAMBERVIEWER_H
6 
7 #include <stdexcept>
8 #include <format>
9 
12 
13 #include "Acts/Utilities/PointerTraits.hpp"
14 
15 namespace xAOD{
35  namespace ChamberViewConcepts{
37  template <typename ObjType> concept identifyConcept = requires (const ObjType theObj) {
38  theObj.identify();
39  };
41  template <typename ObjType> concept identifierHashConcept = requires(const ObjType theObj) {
42  theObj.identifierHash();
43  };
44  template<class HitObjContainer> concept ContainerConcept =
45  (identifyConcept<typename Acts::RemovePointer_t<typename HitObjContainer::value_type>> ||
46  identifierHashConcept<typename Acts::RemovePointer_t<typename HitObjContainer::value_type>>);
47  }
48 
49  namespace ChamberView {
51  enum class Mode: std::uint8_t{
52  DetElement ,
53  Chamber
54  };
55  }
56 
57 
58  template<ChamberViewConcepts::ContainerConcept HitObjContainer>
59  class ChamberViewer {
60  public:
61  using value_type = typename HitObjContainer::value_type;
62  using element_type = typename Acts::RemovePointer_t<value_type>;
63 
64  using const_iterator = typename HitObjContainer::const_iterator;
67 
70  ChamberViewer(const HitObjContainer& container) noexcept
71  requires(ChamberViewConcepts::identifierHashConcept<element_type>):
72  m_container{container} {
73  next();
74  }
77  ChamberViewer(const HitObjContainer& container,
78  const Muon::IMuonIdHelperSvc* idHelperSvc,
79  const ViewMode mode = ViewMode::DetElement) noexcept
80  requires(ChamberViewConcepts::identifyConcept<element_type>):
81  m_container{container},
82  m_idHelperSvc{idHelperSvc},
83  m_mode{mode} {
84  next();
85  }
87  ChamberViewer(const ChamberViewer& other) = delete;
96  return m_begin;
97  }
99  const_iterator end() const noexcept {
100  return m_end;
101  }
103  std::size_t size() const noexcept {
104  return std::distance(m_begin, m_end);
105  }
107  const_ref at(const std::size_t idx) const {
108  if (idx >= size()) {
109  throw std::domain_error(std::format("Invalid index given {:}. size: {:}, requested:{:} ",
110  typeid(const_ref).name(), size(), idx));
111  }
112  return (*m_begin +idx);
113  }
116  bool next() noexcept {
117  if (m_end == m_container.end()) {
118  return false;
119  }
120  m_begin = m_end;
121  if constexpr (ChamberViewConcepts::identifierHashConcept<element_type>) {
122  const IdentifierHash currentHash = (*m_end)->identifierHash();
123  m_end = std::find_if(m_begin, m_container.end(),
124  [&currentHash](const_ref meas){
125  return meas->identifierHash() != currentHash;
126  });
127  } else {
128  const IdentifierHash currentHash = idHash((*m_end)->identify());
129  m_end = std::find_if(m_begin, m_container.end(),
130  [this,&currentHash](const_ref meas){
131  return idHash(meas->identify()) != currentHash;
132  });
133  }
134  if (m_begin == m_end) {
135  return next(); // veto empty views
136  }
137  return true;
138  }
139 
143  bool loadView(const Identifier& chamberId)
144  requires(ChamberViewConcepts::identifyConcept<element_type>) {
145 
146  const IdentifierHash detId = idHash(chamberId);
147  m_begin = std::ranges::find_if(m_container,[this,&detId](const_ref meas) {
148  return idHash(meas->identify()) == detId;
149  });
150  m_end = std::find_if(m_begin, m_container.end(),[this,&detId](const_ref meas) {
151  return idHash(meas->identify()) != detId;
152  });
153  return m_begin != m_end;
154  }
159  requires(ChamberViewConcepts::identifierHashConcept<element_type>) {
160  m_begin = std::ranges::find_if(m_container,[&idHash](const_ref meas) {
161  return meas->identifierHash() == idHash;
162  });
163  m_end = std::find_if(m_begin, m_container.end(),[&idHash](const_ref meas) {
164  return meas->identifierHash() != idHash;
165  });
166  return m_begin != m_end;
167  }
170  bool loadView(std::function<bool(const_ref)> selector) {
171  m_begin = std::ranges::find_if(m_container, selector);
172  m_end = std::find_if(m_begin, m_container.end(),
173  [&selector](const_ref meas) {
174  return !selector(meas);
175  });
176  return m_begin != m_end;
177  }
178  bool next(std::function<bool(const_ref)> selector) {
179  if (m_end == m_container.end()) {
180  return false;
181  }
183  const_iterator nextBegin = std::ranges::find_if(m_end, m_container.end(), selector);
184  if (nextBegin == m_container.end()) {
185  return false;
186  }
187  m_begin = nextBegin;
188  m_end = std::find_if(m_begin, m_container.end(),
189  [&selector](const_ref meas) {
190  return !selector(meas);
191  });
192  return true;
193  }
194 
195  private:
197  IdentifierHash idHash(const Identifier& id) const {
198  return m_mode == ViewMode::DetElement ? m_idHelperSvc->detElementHash(id)
199  : m_idHelperSvc->moduleHash(id);
200  }
201  const HitObjContainer& m_container;
203  const ViewMode m_mode{ViewMode::DetElement};
206  };
207 }
208 #endif
209 
xAOD::ChamberViewConcepts::ContainerConcept
concept ContainerConcept
Definition: ChamberViewer.h:44
xAOD::name
name
Definition: TriggerMenuJson_v1.cxx:29
xAOD::ChamberViewer::size
std::size_t size() const noexcept
Returns how many hits are in the current chamber.
Definition: ChamberViewer.h:103
vtune_athena.format
format
Definition: vtune_athena.py:14
xAOD::ChamberViewer::next
bool next() noexcept
Loads the hits from the next chamber.
Definition: ChamberViewer.h:116
xAOD::uint8_t
uint8_t
Definition: Muon_v1.cxx:558
xAOD::ChamberViewer::end
const_iterator end() const noexcept
End iterator of the current chamber view.
Definition: ChamberViewer.h:99
xAOD::ChamberViewer::begin
const_iterator begin() const noexcept
Begin iterator of the current chamber view.
Definition: ChamberViewer.h:95
xAOD::other
@ other
Definition: TrackingPrimitives.h:510
requires
requires requires()
This specialization is used for classes deriving from DataObject.
Definition: Control/AthenaKernel/AthenaKernel/ClassID_traits.h:68
xAOD
ICaloAffectedTool is abstract interface for tools checking if 4 mom is in calo affected region.
Definition: ICaloAffectedTool.h:24
xAOD::ChamberViewer::ChamberViewer
ChamberViewer(const HitObjContainer &container) noexcept requires(ChamberViewConcepts
Standard constructor.
Definition: ChamberViewer.h:70
Muon::IMuonIdHelperSvc::moduleHash
virtual IdentifierHash moduleHash(const Identifier &id) const =0
Returns the module hash associated to an Identifier.
const
bool const RAWDATA *ch2 const
Definition: LArRodBlockPhysicsV0.cxx:560
xAOD::ChamberViewer::m_idHelperSvc
const Muon::IMuonIdHelperSvc * m_idHelperSvc
Definition: ChamberViewer.h:202
xAOD::ChamberViewConcepts::identifierHashConcept
concept identifierHashConcept
Define the concept that the object needs to have an IdentifierHash method
Definition: ChamberViewer.h:41
xAOD::ChamberViewer::const_iterator
typename HitObjContainer::const_iterator const_iterator
Definition: ChamberViewer.h:64
xAOD::ChamberViewer::ChamberViewer
ChamberViewer(const ChamberViewer &other)=delete
Delete the copy constructor.
xAOD::ChamberView::Mode::Chamber
@ Chamber
View ends if the moduleHash changes.
xAOD::ChamberViewer
Definition: ChamberViewer.h:59
xAOD::ChamberViewer::ChamberViewer
ChamberViewer(ChamberViewer &&other)=default
Standard move constructor.
xAOD::ChamberView::Mode
Mode
Switch setting the view mode if the chamber viewer is initialized with the IdHelperSvc.
Definition: ChamberViewer.h:51
xAOD::ChamberView::Mode::DetElement
@ DetElement
View ends if the detElementHash changes.
Preparation.mode
mode
Definition: Preparation.py:107
xAOD::ChamberViewer::loadView
bool loadView(const IdentifierHash &idHash) requires(ChamberViewConcepts
Loads the view matching the parsed IdentifierHash.
Definition: ChamberViewer.h:158
xAOD::ChamberViewer::const_ref
typename const_iterator::reference const_ref
Definition: ChamberViewer.h:65
xAOD::ChamberViewer::m_end
const_iterator m_end
Definition: ChamberViewer.h:204
xAOD::ChamberViewer::ChamberViewer
ChamberViewer(const HitObjContainer &container, const Muon::IMuonIdHelperSvc *idHelperSvc, const ViewMode mode=ViewMode::DetElement) noexcept requires(ChamberViewConcepts
Standard constructor.
Definition: ChamberViewer.h:77
MeasurementDefs.h
xAOD::ChamberViewer::operator=
ChamberViewer & operator=(const ChamberViewer &other)=delete
Delete the copy assignment operator.
xAOD::ChamberViewer::idHash
IdentifierHash idHash(const Identifier &id) const
Returns the IdentifierHash from an Identifier.
Definition: ChamberViewer.h:197
xAOD::ChamberViewer::m_mode
const ViewMode m_mode
Definition: ChamberViewer.h:203
xAOD::ChamberViewer::element_type
typename Acts::RemovePointer_t< value_type > element_type
Definition: ChamberViewer.h:62
python.selector.AtlRunQuerySelectorLhcOlc.selector
selector
Definition: AtlRunQuerySelectorLhcOlc.py:610
xAOD::ChamberViewer::next
bool next(std::function< bool(const_ref)> selector)
Definition: ChamberViewer.h:178
dq_make_web_display.reference
reference
Definition: dq_make_web_display.py:43
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::at
const_ref at(const std::size_t idx) const
Returns the i-the measurement from the current chamber.
Definition: ChamberViewer.h:107
xAOD::ChamberViewer::loadView
bool loadView(std::function< bool(const_ref)> selector)
Loads the view range based on a generic selector function.
Definition: ChamberViewer.h:170
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::ChamberViewer::operator=
ChamberViewer & operator=(ChamberViewer &&other)=default
Standard move operator.
value_type
Definition: EDM_MasterSearch.h:11
xAOD::ChamberViewer::m_container
const HitObjContainer & m_container
Definition: ChamberViewer.h:201
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::ChamberViewer::m_begin
const_iterator m_begin
Definition: ChamberViewer.h:205
xAOD::ChamberViewer::loadView
bool loadView(const Identifier &chamberId) requires(ChamberViewConcepts
Loads the view matching the parsed identifier.
Definition: ChamberViewer.h:143
IMuonIdHelperSvc.h
xAOD::ChamberViewConcepts::identifyConcept
concept identifyConcept
Define the concept that the object needs to have an Identifier method
Definition: ChamberViewer.h:37
Muon::IMuonIdHelperSvc::detElementHash
virtual IdentifierHash detElementHash(const Identifier &id) const =0
Returns the detector element hash associated to an Identifier.
Identifier
Definition: IdentifierFieldParser.cxx:14