ReadoutIDmapper.h
Go to the documentation of this file.
1 /**
2  * @file larcorealg/Geometry/ReadoutIDmapper.h
3  * @brief Mapping between geometry/readout ID and flat index.
4  * @author Gianluca Petrillo (petrillo@fnal.gov)
5  * @date October 26, 2019
6  * @ingroup Geometry
7  *
8  * This is a header-only library.
9  */
10 
11 #ifndef LARCOREALG_GEOMETRY_READOUTIDMAPPER_H
12 #define LARCOREALG_GEOMETRY_READOUTIDMAPPER_H
13 
14 // LArSoft libraries
17 
18 // C/C++ standard libraries
19 #include <vector>
20 #include <array>
21 #include <initializer_list>
22 #include <string>
23 #include <utility> // std::forward()
24 #include <algorithm> // std::fill(), std::for_each()
25 #include <stdexcept> // std::out_of_range
26 #include <cassert>
27 
28 
29 namespace readout {
30 
31  template <typename Index = std::size_t>
33 
34  template <typename Index = std::size_t>
35  class ROPIDmapper;
36 
37 } // namespace readout
38 
39 
40 // --- BEGIN Readout ID mappers ------------------------------------------------
41 /// @name Readout ID mappers
42 /// @ingroup Geometry
43 /// @{
44 
45 /** ****************************************************************************
46  * @brief Mapping for TPC set identifiers.
47  * @tparam Index (default: `std::size_t`) type of flat index
48  * @see `geo::GeoIDmapper`
49  *
50  * A customized version of `geo::GeoIDmapper` offering TPC set ID-specific
51  * interface.
52  */
53 template <typename Index /* = std::size_t */>
55  : public geo::GeoIDmapper<readout::TPCsetID, Index>
56 {
57 
58  /// Base class.
60 
61  public:
62 
63  // import types
64  using ID_t = typename BaseMapper_t::ID_t;
66 
67 
68  // import all constructors from `geo::GeoIDmapper`
69  using BaseMapper_t::BaseMapper_t;
70 
71  /**
72  * @brief Prepares the mapping with the specified sizes.
73  * @param nCryo number of cryostats
74  * @param nTPCsets number of TPCsets per cryostat
75  *
76  * The mapping is sized to map `nCryo` cryostats, each with `nTPCsets` TPC
77  * sets.
78  */
79  TPCsetIDmapper(unsigned int nCryo, unsigned int nTPCsets)
80  : BaseMapper_t({ nCryo, nTPCsets })
81  {}
82 
83 
84  // --- BEGIN Mapping modification --------------------------------------------
85  /// @name Mapping modification
86  /// @{
87 
89 
90  /**
91  * @brief Prepares the mapping for the specified sizes.
92  * @param nCryo number of cryostats
93  * @param nTPCsets number of TPC sets
94  * @see `resizeAs()`
95  *
96  * The mapping is sized to map `nCryo` cryostats, each with `nTPCsets` TPC
97  * sets.
98  */
99  void resize(unsigned int nCryo, unsigned int nTPCsets)
100  { BaseMapper_t::resize({ nCryo, nTPCsets }); }
101 
102  /// @}
103  // --- END Mapping modification ----------------------------------------------
104 
105 
106  // --- BEGIN Mapping status query --------------------------------------------
107  /// @name Mapping status query
108  /// @{
109 
110  /// Returns whether this mapping covers the specified cryostat.
111  bool hasCryostat(geo::CryostatID const& cryoid) const
112  { return BaseMapper_t::hasElement(cryoid); }
113 
114  /// Returns whether this mapping covers the specified TPC set.
115  bool hasTPCset(readout::TPCsetID const& tpcsetid) const
116  { return BaseMapper_t::hasElement(tpcsetid); }
117 
118  /// @}
119  // --- END Mapping status query ----------------------------------------------
120 
121 }; // readout::TPCsetIDmapper<>
122 
123 
124 /** ****************************************************************************
125  * @brief Mapping for readout plane identifiers.
126  * @tparam Index (default: `std::size_t`) type of flat index
127  * @see `geo::GeoIDmapper`
128  *
129  * A customized version of `geo::GeoIDmapper` offering
130  * readout plane ID-specific interface.
131  */
132 template <typename Index /* = std::size_t */>
133 class readout::ROPIDmapper: public geo::GeoIDmapper<readout::ROPID, Index> {
134 
135  /// Base class.
137 
138  public:
139 
140  // import types
141  using ID_t = typename BaseMapper_t::ID_t;
143 
144 
145  // import all constructors from `geo::GeoIDmapper`
146  using BaseMapper_t::BaseMapper_t;
147 
148  /**
149  * @brief Prepares the mapping with the specified sizes.
150  * @param nCryo number of cryostats
151  * @param nTPCsets number of TPC sets per cryostat
152  * @param nROPs number of readout planes per TPC set
153  *
154  * The mapping is sized to map `nCryo` cryostats, each with `nTPCsets` TPC
155  * sets, each one with `nROPs` readout planes.
156  */
157  ROPIDmapper(unsigned int nCryo, unsigned int nTPCsets, unsigned int nROPs)
158  : BaseMapper_t({ nCryo, nTPCsets, nROPs })
159  {}
160 
161 
162  // --- BEGIN Mapping modification --------------------------------------------
163  /// @name Mapping modification
164  /// @{
165 
166  using BaseMapper_t::resize;
167 
168  /**
169  * @brief Prepares the mapping for the specified sizes.
170  * @param nCryo number of cryostats
171  * @param nTPCsets number of TPC sets per cryostat
172  * @param nROPs number of readout planes per TPC set
173  * @see `resizeAs()`
174  *
175  * The mapping is sized to map `nCryo` cryostats, each with `nTPCsets` TPC
176  * sets, each one with `nROPs` readout planes.
177  */
178  void resize(unsigned int nCryo, unsigned int nTPCsets, unsigned int nROPs)
179  { BaseMapper_t::resize({ nCryo, nTPCsets, nROPs }); }
180 
181  /// @}
182  // --- END Mapping modification ----------------------------------------------
183 
184 
185  // --- BEGIN Mapping status query --------------------------------------------
186  /// @name Mapping status query
187  /// @{
188 
189  /// Returns whether this mapping covers the specified cryostat.
190  bool hasCryostat(geo::CryostatID const& cryoid) const
191  { return BaseMapper_t::hasElement(cryoid); }
192 
193  /// Returns whether this mapping covers the specified TPC set.
194  bool hasTPC(readout::TPCsetID const& tpcsetid) const
195  { return BaseMapper_t::hasElement(tpcsetid); }
196 
197  /// Returns whether this mapping covers the specified readout plane.
198  bool hasPlane(readout::ROPID const& ropid) const
199  { return BaseMapper_t::hasElement(ropid); }
200 
201  /// @}
202  // --- END Mapping status query ----------------------------------------------
203 
204 }; // readout::ROPIDmapper<>
205 
206 
207 /// @}
208 // --- END Readout ID mappers --------------------------------------------------
209 //------------------------------------------------------------------------------
210 
211 
212 
213 #endif // LARCOREALG_GEOMETRY_READOUTIDMAPPER_H
bool hasCryostat(geo::CryostatID const &cryoid) const
Returns whether this mapping covers the specified cryostat.
ROPIDmapper(unsigned int nCryo, unsigned int nTPCsets, unsigned int nROPs)
Prepares the mapping with the specified sizes.
Classes identifying readout-related concepts.
bool hasTPC(readout::TPCsetID const &tpcsetid) const
Returns whether this mapping covers the specified TPC set.
Class identifying a set of TPC sharing readout channels.
Definition: readout_types.h:70
Mapping between geometry/readout ID and flat index.
Mapping for readout plane identifiers.
bool hasPlane(readout::ROPID const &ropid) const
Returns whether this mapping covers the specified readout plane.
unsigned int Index
Class identifying a set of planes sharing readout channels.
bool hasElement(GeoID const &id) const
Returns whether this mapping hosts data for the specified ID.
readout::TPCsetID ID_t
Type used as ID for this mapping.
void resize(unsigned int nCryo, unsigned int nTPCsets)
Prepares the mapping for the specified sizes.
bool hasCryostat(geo::CryostatID const &cryoid) const
Returns whether this mapping covers the specified cryostat.
void resize(std::initializer_list< unsigned int > dims)
Resizes the mapping to accommodate the specified dimension sizes.
Mapping for TPC set identifiers.
void resize(unsigned int nCryo, unsigned int nTPCsets, unsigned int nROPs)
Prepares the mapping for the specified sizes.
bool hasTPCset(readout::TPCsetID const &tpcsetid) const
Returns whether this mapping covers the specified TPC set.
The data type to uniquely identify a cryostat.
Definition: geo_types.h:190
TPCsetIDmapper(unsigned int nCryo, unsigned int nTPCsets)
Prepares the mapping with the specified sizes.
Class managing the mapping between geometry/readout ID and flat index.