readout_types.h
Go to the documentation of this file.
1 /**
2  * @file readout_types.h
3  * @brief Classes identifying readout-related concepts
4  * @author Gianluca Petrillo (petrillo@fnal.gov)
5  * @date June 19th, 2015
6  */
7 
8 #ifndef LARCOREOBJ_SIMPLETYPESANDCONSTANTS_READOUT_TYPES_H
9 #define LARCOREOBJ_SIMPLETYPESANDCONSTANTS_READOUT_TYPES_H
10 
11 // LArSoft libraries
13 
14 // C/C++ standard libraries
15 #include <iosfwd> // std::ostream
16 
17 
18 namespace readout {
19 
20  namespace details {
21 
22  template <typename T>
24  { return geo::details::writeToString(value); }
25 
26  template <std::size_t Index, typename ID>
28 
29  template <std::size_t UpIndex, typename ID>
31 
32  template <std::size_t Index, typename ID>
33  inline constexpr auto getAbsIDindex(ID const& id)
34  { return geo::details::getAbsIDindex<Index, ID>(id); }
35 
36  template <std::size_t Index, typename ID>
37  inline auto& getAbsIDindex(ID& id)
38  { return geo::details::getAbsIDindex<Index, ID>(id); }
39 
40  } // namespace details
41 
42 
43  /// Numerical description of geometry element "level".
44  /// The "detector" level is noticeably missing.
45  struct ElementLevel {
46 
48 
49  static constexpr Level_t Cryostat = 0U;
50  static constexpr Level_t TPCset = 1U;
51  static constexpr Level_t ReadoutPlane = 2U;
52  static constexpr Level_t Channel = 3U;
53  static constexpr Level_t NLevels = 4U;
54 
55  }; // struct ElementLevel
56 
57 
58  // We define our own cryostat ID as an alias of the one from geometry
60 
61 
62  /**
63  * @brief Class identifying a set of TPC sharing readout channels.
64  *
65  * This identifier provides the cryostat location and a number representing
66  * the set of TPCs.
67  * This set is defined by not sharing readout channels with any other TPC
68  * outside the set.
69  */
70  struct TPCsetID: public CryostatID {
71  using TPCsetID_t = unsigned short; ///< Type for the ID number.
72 
73  using ThisID_t = TPCsetID; ///< Type of this ID.
74  using ParentID_t = CryostatID; ///< Type of the parent ID.
75 
76  /// Type of the ID with the specified level `L`.
77  template <std::size_t L>
79 
80  /// Type of the ID `A` levels above this one.
81  template <std::size_t A>
83 
84 
85  /// Special code for an invalid ID.
86  static constexpr TPCsetID_t InvalidID
88 
89  /// Index of the TPC set within its cryostat.
90  TPCsetID_t TPCset = InvalidID;
91 
92  /// Default constructor: an invalid TPC set ID.
93  constexpr TPCsetID() = default;
94 
95  /// Constructor: TPC set with index `s` in the cryostat identified by
96  /// `cryoid`.
97  constexpr TPCsetID(CryostatID const& cryoid, TPCsetID_t s):
98  CryostatID(cryoid), TPCset(s) {}
99 
100  /// Constructor: TPC set with index `s` in the cryostat index `c`.
102  : CryostatID(c), TPCset(s) {}
103 
104  // comparison operators are out of class
105 
106  //@{
107  /// Human-readable representation of the TPC set ID.
108  std::string toString() const { return details::writeToString(*this); }
109  explicit operator std::string() const { return toString(); }
110  //@}
111 
112  // the following two methods are useful for (templated) abstraction
113  /// Returns the value of the deepest ID available (TPC set's).
114  constexpr auto const& deepestIndex() const { return TPCset; }
115  /// Returns the deepest ID available (TPC set's).
116  auto& deepestIndex() { return TPCset; }
117  /// Return the parent ID of this one (a cryostat ID).
118  constexpr ParentID_t const& parentID() const { return *this; }
119  /// Return the parent ID of this one (a cryostat ID).
120  ParentID_t& parentID() { return *this; }
121  /// Returns the index level `Index` of this type.
122  template <std::size_t Index = 0U>
123  constexpr auto getIndex() const;
124  /// Returns the index level `Index` of this type.
125  template <std::size_t Index = 0U>
126  auto& writeIndex();
127  /// Returns the index `Above` levels higher than `Level`.
128  template <std::size_t Above>
129  constexpr auto getRelIndex() const;
130 
131  /// Conversion to TPCsetID (for convenience of notation).
132  constexpr TPCsetID const& asTPCsetID() const { return *this; }
133  /// Conversion to TPCsetID (for convenience of notation).
134  TPCsetID& asTPCsetID() { return *this; }
135  /// Conversion to TPCsetID (for convenience of notation).
136  constexpr TPCsetID const& asConstTPCsetID() { return *this; }
137 
138  /// Returns < 0 if this is smaller than other, 0 if equal, > 0 if larger.
139  constexpr int cmp(TPCsetID const& other) const
140  {
141  int cmp_res = CryostatID::cmp(other);
142  if (cmp_res == 0) // same cryostat: compare TPC set
143  return ThreeWayComparison(TPCset, other.TPCset);
144  else // return the order of cryostats
145  return cmp_res;
146  } // cmp()
147 
148  /// Level of this element.
149  static constexpr auto Level = readout::ElementLevel::TPCset;
150 
151  /// Return the value of the invalid TPC ID as a r-value.
152  static constexpr TPCsetID_t getInvalidID() { return TPCsetID::InvalidID; }
153 
154  }; // struct TPCsetID
155 
156 
157 
158  /**
159  * @brief Class identifying a set of planes sharing readout channels
160  *
161  * This identifier provides the TPC set location and a number representing
162  * the set of planes.
163  * This set is defined by not sharing readout channels with any other plane
164  * outside the set.
165  *
166  * The name stands for "readout plane".
167  */
168  struct ROPID: public TPCsetID {
169  using ROPID_t = unsigned int; ///< Type for the ID number.
170 
171  using ThisID_t = ROPID; ///< Type of this ID.
172  using ParentID_t = TPCsetID; ///< Type of the parent ID.
173 
174  /// Type of the ID with the specified level `L`.
175  template <std::size_t L>
177 
178  /// Type of the ID `A` levels above this one.
179  template <std::size_t A>
181 
182  /// Special code for an invalid ID.
183  static constexpr ROPID_t InvalidID = std::numeric_limits<ROPID_t>::max();
184 
185  ROPID_t ROP = InvalidID; ///< Index of the readout plane within its TPC set.
186 
187  /// Default constructor: an invalid plane ID.
188  constexpr ROPID() = default;
189 
190  /// Constructor: readout plane with index `r` in the TPC set identified by
191  /// `tpcsetid`.
192  constexpr ROPID(TPCsetID const& tpcsetid, ROPID_t r)
193  : TPCsetID(tpcsetid), ROP(r) {}
194 
195  /// Constructor: readout plane with index `r` in the cryostat index `c`,
196  /// TPC set index `s`.
198  : TPCsetID(c, s), ROP(r) {}
199 
200  // comparison operators are out of class
201 
202  //@{
203  /// Human-readable representation of the ROP ID.
204  std::string toString() const { return details::writeToString(*this); }
205  explicit operator std::string() const { return toString(); }
206  //@}
207 
208  // the following two methods are useful for (templated) abstraction
209  /// Returns the value of the deepest ID available (readout plane's).
210  constexpr auto const& deepestIndex() const { return ROP; }
211  /// Returns the deepest ID available (readout plane's).
212  auto& deepestIndex() { return ROP; }
213  /// Return the parent ID of this one (a TPC set ID).
214  constexpr ParentID_t const& parentID() const { return *this; }
215  /// Return the parent ID of this one (a TPC set ID).
216  ParentID_t& parentID() { return *this; }
217  /// Returns the index level `Index` of this type.
218  template <std::size_t Index = 0U>
219  constexpr auto getIndex() const;
220  /// Returns the index level `Index` of this type.
221  template <std::size_t Index = 0U>
222  auto& writeIndex();
223  /// Returns the index `Above` levels higher than `Level`.
224  template <std::size_t Above>
225  constexpr auto getRelIndex() const;
226 
227  /// Conversion to ROPID (for convenience of notation).
228  constexpr ROPID const& asROPID() const { return *this; }
229  /// Conversion to ROPID (for convenience of notation).
230  ROPID& asROPID() { return *this; }
231  /// Conversion to ROPID (for convenience of notation).
232  constexpr ROPID const& asConstROPID() { return *this; }
233 
234  /// Returns < 0 if this is smaller than other, 0 if equal, > 0 if larger.
235  constexpr int cmp(ROPID const& other) const
236  {
237  int cmp_res = TPCsetID::cmp(other);
238  if (cmp_res == 0) // same TPC set: compare plane
239  return ThreeWayComparison(ROP, other.ROP);
240  else // return the order of TPC set
241  return cmp_res;
242  } // cmp()
243 
244  /// Level of this element.
246 
247  /// Return the value of the invalid ROP ID as a r-value.
248  static constexpr ROPID_t getInvalidID() { return ROPID::InvalidID; }
249 
250  }; // struct ROPID
251 
252 
253 
254  //----------------------------------------------------------------------------
255  //--- ID comparison operators
256  //---
257 
258  /// @name Readout ID comparison operators
259  /// @{
260  /// @details The result of comparison with invalid IDs is undefined.
261 
262  /// Comparison: the IDs point to the same TPC set (validity is ignored)
263  inline constexpr bool operator== (TPCsetID const& a, TPCsetID const& b) {
264  return (a.asCryostatID() == b.asCryostatID()) && (a.TPCset == b.TPCset);
265  } // operator== (TPCsetID, TPCsetID)
266 
267  /// Comparison: the IDs point to different TPC sets (validity is ignored)
268  inline constexpr bool operator!= (TPCsetID const& a, TPCsetID const& b) {
269  return (a.asCryostatID() != b.asCryostatID()) || (a.TPCset != b.TPCset);
270  } // operator!= (TPCsetID, TPCsetID)
271 
272  /// Order TPCsetID in increasing Cryo, then TPC set
273  inline constexpr bool operator< (TPCsetID const& a, TPCsetID const& b) {
274  int cmp_res = a.asCryostatID().cmp(b);
275  if (cmp_res == 0) // same cryostat: compare TPC set
276  return a.TPCset < b.TPCset;
277  else // return the order of cryostats
278  return cmp_res < 0;
279  } // operator< (TPCsetID, TPCsetID)
280 
281 
282  /// Comparison: the IDs point to the same ROP (validity is ignored)
283  inline constexpr bool operator== (ROPID const& a, ROPID const& b) {
284  return (a.asTPCsetID() == b.asTPCsetID()) && (a.ROP == b.ROP);
285  } // operator== (ROPID, ROPID)
286 
287  /// Comparison: the IDs point to different ROPs (validity is ignored)
288  inline constexpr bool operator!= (ROPID const& a, ROPID const& b) {
289  return (a.asTPCsetID() != b.asTPCsetID()) || (a.ROP != b.ROP);
290  } // operator!= (ROPID, ROPID)
291 
292  /// Order ROPID in increasing Cryo, then TPC set, then ROP
293  inline constexpr bool operator< (ROPID const& a, ROPID const& b) {
294  int cmp_res = a.asTPCsetID().cmp(b);
295  if (cmp_res == 0) // same TPC set: compare ROP
296  return a.ROP < b.ROP;
297  else // return the order of TPC set
298  return cmp_res < 0;
299  } // operator< (ROPID, ROPID)
300 
301  /// @}
302 
303 
304  //----------------------------------------------------------------------------
305  //--- ID output operators
306  //---
307  /// Generic output of TPCsetID to stream
308  inline std::ostream& operator<< (std::ostream& out, TPCsetID const& sid) {
309  out << sid.asCryostatID() << " S:" << sid.TPCset;
310  return out;
311  } // operator<< (TPCsetID)
312 
313  inline std::ostream& operator<< (std::ostream& out, ROPID const& rid) {
314  out << rid.asTPCsetID() << " R:" << rid.ROP;
315  return out;
316  } // operator<< (ROPID)
317 
318 
319 } // namespace readout
320 
321 
322 //------------------------------------------------------------------------------
323 //--- template implementation
324 //------------------------------------------------------------------------------
325 template <std::size_t Index /* = 0U */>
326 constexpr auto readout::TPCsetID::getIndex() const {
327  static_assert
328  (Index <= Level, "This ID type does not have the requested Index level.");
329  return details::getAbsIDindex<Index>(*this);
330 } // readout::TPCsetID::getIndex() const
331 
332 template <std::size_t Index /* = 0U */>
334  static_assert
335  (Index <= Level, "This ID type does not have the requested Index level.");
336  return details::getAbsIDindex<Index>(*this);
337 } // readout::TPCsetID::writeIndex()
338 
339 template <std::size_t Above>
340 constexpr auto readout::TPCsetID::getRelIndex() const {
341  static_assert
342  (Above <= Level, "This ID type does not have the requested Index level.");
343  return getIndex<Level - Above>();
344 } // readout::TPCsetID::getRelIndex()
345 
346 
347 //------------------------------------------------------------------------------
348 template <std::size_t Index /* = 0U */>
349 constexpr auto readout::ROPID::getIndex() const {
350  static_assert
351  (Index <= Level, "This ID type does not have the requested Index level.");
352  return details::getAbsIDindex<Index>(*this);
353 } // readout::ROPID::getIndex() const
354 
355 template <std::size_t Index /* = 0U */>
357  static_assert
358  (Index <= Level, "This ID type does not have the requested Index level.");
359  return details::getAbsIDindex<Index>(*this);
360 } // readout::ROPID::writeIndex()
361 
362 template <std::size_t Above>
363 constexpr auto readout::ROPID::getRelIndex() const {
364  static_assert
365  (Above <= Level, "This ID type does not have the requested Index level.");
366  return getIndex<Level - Above>();
367 } // readout::ROPID::getRelIndex()
368 
369 
370 //------------------------------------------------------------------------------
371 
372 #endif // LARCOREOBJ_SIMPLETYPESANDCONSTANTS_READOUT_TYPES_H
373 
constexpr int cmp(TPCsetID const &other) const
Returns < 0 if this is smaller than other, 0 if equal, > 0 if larger.
constexpr bool operator<(TPCsetID const &a, TPCsetID const &b)
Order TPCsetID in increasing Cryo, then TPC set.
typename RelIDtypeStruct< ID, UpIndex >::type RelIDtype
Definition: geo_types.h:52
std::ostream & operator<<(std::ostream &out, TPCsetID const &sid)
Generic output of TPCsetID to stream.
static void writeIndex(OutputList &ol)
Definition: index.cpp:3761
auto & deepestIndex()
Returns the deepest ID available (readout plane&#39;s).
static constexpr ROPID_t getInvalidID()
Return the value of the invalid ROP ID as a r-value.
constexpr TPCsetID(CryostatID const &cryoid, TPCsetID_t s)
Definition: readout_types.h:97
constexpr auto getRelIndex() const
Returns the index Above levels higher than Level.
details::AbsIDtype< L, ThisID_t > ID_t
Type of the ID with the specified level L.
Definition: geo_types.h:198
std::string string
Definition: nybbler.cc:12
unsigned int ID
unsigned int ROPID_t
Type for the ID number.
geo::details::AbsIDtype< Index, ID > AbsIDtype
Definition: readout_types.h:27
constexpr auto const & deepestIndex() const
Returns the value of the deepest ID available (TPC set&#39;s).
constexpr int cmp(ROPID const &other) const
Returns < 0 if this is smaller than other, 0 if equal, > 0 if larger.
unsigned short TPCsetID_t
Type for the ID number.
Definition: readout_types.h:71
constexpr auto getIndex() const
Returns the index level Index of this type.
Class identifying a set of TPC sharing readout channels.
Definition: readout_types.h:70
Level
Definition: Level.h:13
unsigned int Index
geo::ElementLevel::Level_t Level_t
Definition: readout_types.h:47
auto & writeIndex()
Returns the index level Index of this type.
details::RelIDtype< A, ThisID_t > UpperID_t
Type of the ID A levels above this one.
Definition: geo_types.h:202
ROPID & asROPID()
Conversion to ROPID (for convenience of notation).
constexpr auto getIndex() const
Returns the index level Index of this type.
static constexpr TPCsetID_t InvalidID
Special code for an invalid ID.
Definition: readout_types.h:87
geo::details::RelIDtype< UpIndex, ID > RelIDtype
Definition: readout_types.h:30
std::string writeToString(T const &value)
Write the argument into a string.
Definition: geo_types.h:864
ParentID_t & parentID()
Return the parent ID of this one (a TPC set ID).
typename AbsIDtypeStruct< ID, Index >::type AbsIDtype
Definition: geo_types.h:46
readout::ROPID ROPID
auto & deepestIndex()
Returns the deepest ID available (TPC set&#39;s).
constexpr ParentID_t const & parentID() const
Return the parent ID of this one (a TPC set ID).
constexpr ROPID(TPCsetID const &tpcsetid, ROPID_t r)
ParentID_t & parentID()
Return the parent ID of this one (a cryostat ID).
ROPID_t ROP
Index of the readout plane within its TPC set.
IDparameter< readout::TPCsetID > TPCsetID
Member type of validated readout::TPCsetID parameter.
const double a
constexpr ROPID const & asROPID() const
Conversion to ROPID (for convenience of notation).
constexpr CryostatID const & asCryostatID() const
Conversion to CryostatID (for convenience of notation).
Definition: geo_types.h:275
static int max(int a, int b)
std::string toString() const
Human-readable representation of the ROP ID.
Definition of data types for geometry description.
string toString(const TVector3 &xyz, int w=9)
constexpr bool operator==(TPCsetID const &a, TPCsetID const &b)
Comparison: the IDs point to the same TPC set (validity is ignored)
constexpr auto getRelIndex() const
Returns the index Above levels higher than Level.
Class identifying a set of planes sharing readout channels.
TPCsetID_t TPCset
Index of the TPC set within its cryostat.
Definition: readout_types.h:90
constexpr TPCsetID(CryostatID_t c, TPCsetID_t s)
Constructor: TPC set with index s in the cryostat index c.
constexpr TPCsetID const & asConstTPCsetID()
Conversion to TPCsetID (for convenience of notation).
unsigned int CryostatID_t
Type for the ID number.
Definition: geo_types.h:191
static constexpr Level_t TPCset
Definition: readout_types.h:50
TPCsetID & asTPCsetID()
Conversion to TPCsetID (for convenience of notation).
constexpr auto getAbsIDindex(ID const &id)
Definition: readout_types.h:33
constexpr ParentID_t const & parentID() const
Return the parent ID of this one (a cryostat ID).
constexpr ROPID const & asConstROPID()
Conversion to ROPID (for convenience of notation).
static constexpr TPCsetID_t getInvalidID()
Return the value of the invalid TPC ID as a r-value.
constexpr auto const & deepestIndex() const
Returns the value of the deepest ID available (readout plane&#39;s).
static bool * b
Definition: config.cpp:1043
void ParentID_t
Type of the parent ID (none!).
Definition: geo_types.h:194
std::string toString() const
Human-readable representation of the TPC set ID.
constexpr ROPID(CryostatID_t c, TPCsetID_t s, ROPID_t r)
auto & writeIndex()
Returns the index level Index of this type.
constexpr int cmp(CryostatID const &other) const
Returns < 0 if this is smaller than other, 0 if equal, > 0 if larger.
Definition: geo_types.h:271
static constexpr ROPID_t InvalidID
Special code for an invalid ID.
std::size_t Level_t
Definition: geo_types.h:170
constexpr bool operator!=(TPCsetID const &a, TPCsetID const &b)
Comparison: the IDs point to different TPC sets (validity is ignored)
std::string writeToString(T const &value)
Definition: readout_types.h:23
static QCString * s
Definition: config.cpp:1042
static constexpr Level_t ReadoutPlane
Definition: readout_types.h:51
geo::CryostatID CryostatID
Definition: readout_types.h:59
constexpr TPCsetID const & asTPCsetID() const
Conversion to TPCsetID (for convenience of notation).
The data type to uniquely identify a cryostat.
Definition: geo_types.h:190