ATLAS Offline Software
Loading...
Searching...
No Matches
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
15namespace xAOD{
33
34
37 template <typename ObjType> concept identifyConcept = requires (const ObjType theObj) {
38 theObj.identify();
39 };
40
41 template <typename ObjType> concept identifierHashConcept = requires(const ObjType theObj) {
42 theObj.identifierHash();
43 };
44 template<class HitObjContainer> concept ContainerConcept =
47 }
48
49 namespace ChamberView {
51 enum class Mode: std::uint8_t{
54 };
55 }
56
57
58 template<ChamberViewConcepts::ContainerConcept HitObjContainer>
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
73 next();
74 }
75
77 ChamberViewer(const HitObjContainer& container,
78 const Muon::IMuonIdHelperSvc* idHelperSvc,
79 const ViewMode mode = ViewMode::DetElement) noexcept
82 m_idHelperSvc{idHelperSvc},
83 m_mode{mode} {
84 next();
85 }
86
96 return m_begin;
97 }
98
100 return m_end;
101 }
102
103 std::size_t size() const noexcept {
104 return std::distance(m_begin, m_end);
105 }
106
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 }
114
116 bool next() noexcept {
117 if (m_end == m_container.end()) {
118 return false;
119 }
120 m_begin = m_end;
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)
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 }
155
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 }
168
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:
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
CONT::reference reference
This is a "hash" representation of an Identifier.
Interface for Helper service that creates muon Identifiers and can be used to print Identifiers.
bool next() noexcept
Loads the hits from the next chamber.
const_iterator m_end
const_iterator m_begin
const Muon::IMuonIdHelperSvc * m_idHelperSvc
IdentifierHash idHash(const Identifier &id) const
Returns the IdentifierHash from an Identifier.
typename const_iterator::reference const_ref
ChamberViewer(ChamberViewer &&other)=default
Standard move constructor.
const ViewMode m_mode
bool next(std::function< bool(const_ref)> selector)
typename Acts::RemovePointer_t< value_type > element_type
const_iterator end() const noexcept
End iterator of the current chamber view.
ChamberViewer(const HitObjContainer &container) noexcept
Standard constructor.
bool loadView(const IdentifierHash &idHash)
Loads the view matching the parsed IdentifierHash.
const_ref at(const std::size_t idx) const
Returns the i-the measurement from the current chamber.
std::size_t size() const noexcept
Returns how many hits are in the current chamber.
ChamberView::Mode ViewMode
bool loadView(const Identifier &chamberId)
Loads the view matching the parsed identifier.
bool loadView(std::function< bool(const_ref)> selector)
Loads the view range based on a generic selector function.
ChamberViewer & operator=(const ChamberViewer &other)=delete
Delete the copy assignment operator.
typename HitObjContainer::const_iterator const_iterator
const_iterator begin() const noexcept
Begin iterator of the current chamber view.
typename HitObjContainer::value_type value_type
ChamberViewer(const HitObjContainer &container, const Muon::IMuonIdHelperSvc *idHelperSvc, const ViewMode mode=ViewMode::DetElement) noexcept
Standard constructor.
ChamberViewer(const ChamberViewer &other)=delete
Delete the copy constructor.
ChamberViewer & operator=(ChamberViewer &&other)=default
Standard move operator.
const HitObjContainer & m_container
Define the concept that the object needs to have an IdentifierHash method.
Define the concept that the object needs to have an Identifier method.
Under the assumption that all measurements in an uncalibrated measurement container are sorted by the...
Mode
Switch setting the view mode if the chamber viewer is initialized with the IdHelperSvc.
@ Chamber
View ends if the moduleHash changes.
@ DetElement
View ends if the detElementHash changes.
ICaloAffectedTool is abstract interface for tools checking if 4 mom is in calo affected region.