LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
readout_types.h
Go to the documentation of this file.
1 
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 namespace readout {
18 
19  namespace details {
20 
21  template <typename T>
22  inline std::string writeToString(T const& value)
23  {
24  return geo::details::writeToString(value);
25  }
26 
27  template <std::size_t Index, typename ID>
29 
30  template <std::size_t UpIndex, typename ID>
32 
33  template <std::size_t Index, typename ID>
34  inline constexpr auto getAbsIDindex(ID const& id)
35  {
36  return geo::details::getAbsIDindex<Index, ID>(id);
37  }
38 
39  template <std::size_t Index, typename ID>
40  inline auto& getAbsIDindex(ID& id)
41  {
42  return geo::details::getAbsIDindex<Index, ID>(id);
43  }
44 
45  } // namespace details
46 
49  struct ElementLevel {
50 
52 
53  static constexpr Level_t Cryostat = 0U;
54  static constexpr Level_t TPCset = 1U;
55  static constexpr Level_t ReadoutPlane = 2U;
56  static constexpr Level_t Channel = 3U;
57  static constexpr Level_t NLevels = 4U;
58 
59  }; // struct ElementLevel
60 
61  // We define our own cryostat ID as an alias of the one from geometry
63 
72  struct TPCsetID : public CryostatID {
73  using TPCsetID_t = unsigned short;
74 
75  using ThisID_t = TPCsetID;
77 
79  template <std::size_t L>
81 
83  template <std::size_t A>
85 
87  static constexpr TPCsetID_t InvalidID = std::numeric_limits<TPCsetID_t>::max();
88 
90  TPCsetID_t TPCset = InvalidID;
91 
93  constexpr TPCsetID() = default;
94 
97  constexpr TPCsetID(CryostatID const& cryoid, TPCsetID_t s) : CryostatID(cryoid), TPCset(s) {}
98 
100  constexpr TPCsetID(CryostatID_t c, TPCsetID_t s) : CryostatID(c), TPCset(s) {}
101 
102  // comparison operators are out of class
103 
105  std::string toString() const { return details::writeToString(*this); }
107  explicit operator std::string() const { return toString(); }
109 
110  // the following two methods are useful for (templated) abstraction
112  constexpr auto const& deepestIndex() const { return TPCset; }
114  auto& deepestIndex() { return TPCset; }
116  constexpr ParentID_t const& parentID() const { return *this; }
118  ParentID_t& parentID() { return *this; }
120  template <std::size_t Index = 0U>
121  constexpr auto getIndex() const;
123  template <std::size_t Index = 0U>
124  auto& writeIndex();
126  template <std::size_t Above>
127  constexpr auto getRelIndex() const;
128 
130  constexpr TPCsetID const& asTPCsetID() const { return *this; }
132  TPCsetID& asTPCsetID() { return *this; }
134  constexpr TPCsetID const& asConstTPCsetID() { return *this; }
135 
137  constexpr int cmp(TPCsetID const& other) const
138  {
139  int cmp_res = CryostatID::cmp(other);
140  if (cmp_res == 0) // same cryostat: compare TPC set
141  return ThreeWayComparison(TPCset, other.TPCset);
142  else // return the order of cryostats
143  return cmp_res;
144  } // cmp()
145 
147  static constexpr auto Level = readout::ElementLevel::TPCset;
148 
150  static constexpr TPCsetID_t getInvalidID() { return TPCsetID::InvalidID; }
151 
152  }; // struct TPCsetID
153 
164  struct ROPID : public TPCsetID {
165  using ROPID_t = unsigned int;
166 
167  using ThisID_t = ROPID;
169 
171  template <std::size_t L>
173 
175  template <std::size_t A>
177 
179  static constexpr ROPID_t InvalidID = std::numeric_limits<ROPID_t>::max();
180 
181  ROPID_t ROP = InvalidID;
182 
184  constexpr ROPID() = default;
185 
188  constexpr ROPID(TPCsetID const& tpcsetid, ROPID_t r) : TPCsetID(tpcsetid), ROP(r) {}
189 
192  constexpr ROPID(CryostatID_t c, TPCsetID_t s, ROPID_t r) : TPCsetID(c, s), ROP(r) {}
193 
194  // comparison operators are out of class
195 
197  std::string toString() const { return details::writeToString(*this); }
199  explicit operator std::string() const { return toString(); }
201 
202  // the following two methods are useful for (templated) abstraction
204  constexpr auto const& deepestIndex() const { return ROP; }
206  auto& deepestIndex() { return ROP; }
208  constexpr ParentID_t const& parentID() const { return *this; }
210  ParentID_t& parentID() { return *this; }
212  template <std::size_t Index = 0U>
213  constexpr auto getIndex() const;
215  template <std::size_t Index = 0U>
216  auto& writeIndex();
218  template <std::size_t Above>
219  constexpr auto getRelIndex() const;
220 
222  constexpr ROPID const& asROPID() const { return *this; }
224  ROPID& asROPID() { return *this; }
226  constexpr ROPID const& asConstROPID() { return *this; }
227 
229  constexpr int cmp(ROPID const& other) const
230  {
231  int cmp_res = TPCsetID::cmp(other);
232  if (cmp_res == 0) // same TPC set: compare plane
233  return ThreeWayComparison(ROP, other.ROP);
234  else // return the order of TPC set
235  return cmp_res;
236  } // cmp()
237 
240 
242  static constexpr ROPID_t getInvalidID() { return ROPID::InvalidID; }
243 
244  }; // struct ROPID
245 
246  //----------------------------------------------------------------------------
247  //--- ID comparison operators
248  //---
249 
253 
255  inline constexpr bool operator==(TPCsetID const& a, TPCsetID const& b)
256  {
257  return (a.asCryostatID() == b.asCryostatID()) && (a.TPCset == b.TPCset);
258  } // operator== (TPCsetID, TPCsetID)
259 
261  inline constexpr bool operator!=(TPCsetID const& a, TPCsetID const& b)
262  {
263  return (a.asCryostatID() != b.asCryostatID()) || (a.TPCset != b.TPCset);
264  } // operator!= (TPCsetID, TPCsetID)
265 
267  inline constexpr bool operator<(TPCsetID const& a, TPCsetID const& b)
268  {
269  int cmp_res = a.asCryostatID().cmp(b);
270  if (cmp_res == 0) // same cryostat: compare TPC set
271  return a.TPCset < b.TPCset;
272  else // return the order of cryostats
273  return cmp_res < 0;
274  } // operator< (TPCsetID, TPCsetID)
275 
277  inline constexpr bool operator==(ROPID const& a, ROPID const& b)
278  {
279  return (a.asTPCsetID() == b.asTPCsetID()) && (a.ROP == b.ROP);
280  } // operator== (ROPID, ROPID)
281 
283  inline constexpr bool operator!=(ROPID const& a, ROPID const& b)
284  {
285  return (a.asTPCsetID() != b.asTPCsetID()) || (a.ROP != b.ROP);
286  } // operator!= (ROPID, ROPID)
287 
289  inline constexpr bool operator<(ROPID const& a, ROPID const& b)
290  {
291  int cmp_res = a.asTPCsetID().cmp(b);
292  if (cmp_res == 0) // same TPC set: compare ROP
293  return a.ROP < b.ROP;
294  else // return the order of TPC set
295  return cmp_res < 0;
296  } // operator< (ROPID, ROPID)
297 
299 
300  //----------------------------------------------------------------------------
301  //--- ID output operators
302  //---
304  inline std::ostream& operator<<(std::ostream& out, TPCsetID const& sid)
305  {
306  out << sid.asCryostatID() << " S:" << sid.TPCset;
307  return out;
308  } // operator<< (TPCsetID)
309 
310  inline std::ostream& operator<<(std::ostream& out, ROPID const& rid)
311  {
312  out << rid.asTPCsetID() << " R:" << rid.ROP;
313  return out;
314  } // operator<< (ROPID)
315 
316 } // namespace readout
317 
318 //------------------------------------------------------------------------------
319 //--- template implementation
320 //------------------------------------------------------------------------------
321 template <std::size_t Index /* = 0U */>
322 constexpr auto readout::TPCsetID::getIndex() const
323 {
324  static_assert(Index <= Level, "This ID type does not have the requested Index level.");
325  return details::getAbsIDindex<Index>(*this);
326 } // readout::TPCsetID::getIndex() const
327 
328 template <std::size_t Index /* = 0U */>
330 {
331  static_assert(Index <= Level, "This ID type does not have the requested Index level.");
332  return details::getAbsIDindex<Index>(*this);
333 } // readout::TPCsetID::writeIndex()
334 
335 template <std::size_t Above>
336 constexpr auto readout::TPCsetID::getRelIndex() const
337 {
338  static_assert(Above <= Level, "This ID type does not have the requested Index level.");
339  return getIndex<Level - Above>();
340 } // readout::TPCsetID::getRelIndex()
341 
342 //------------------------------------------------------------------------------
343 template <std::size_t Index /* = 0U */>
344 constexpr auto readout::ROPID::getIndex() const
345 {
346  static_assert(Index <= Level, "This ID type does not have the requested Index level.");
347  return details::getAbsIDindex<Index>(*this);
348 } // readout::ROPID::getIndex() const
349 
350 template <std::size_t Index /* = 0U */>
352 {
353  static_assert(Index <= Level, "This ID type does not have the requested Index level.");
354  return details::getAbsIDindex<Index>(*this);
355 } // readout::ROPID::writeIndex()
356 
357 template <std::size_t Above>
358 constexpr auto readout::ROPID::getRelIndex() const
359 {
360  static_assert(Above <= Level, "This ID type does not have the requested Index level.");
361  return getIndex<Level - Above>();
362 } // readout::ROPID::getRelIndex()
363 
364 //------------------------------------------------------------------------------
365 
366 #endif // LARCOREOBJ_SIMPLETYPESANDCONSTANTS_READOUT_TYPES_H
TRandom r
Definition: spectrum.C:23
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:53
std::ostream & operator<<(std::ostream &out, TPCsetID const &sid)
Generic output of TPCsetID to stream.
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:200
unsigned int ROPID_t
Type for the ID number.
IDparameter< readout::ROPID > ROPID
Member type of validated readout::ROPID parameter.
geo::details::AbsIDtype< Index, ID > AbsIDtype
Definition: readout_types.h:28
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:73
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:72
Level
Definition: Level.h:13
geo::ElementLevel::Level_t Level_t
Definition: readout_types.h:51
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:204
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:31
std::string writeToString(T const &value)
Write the argument into a string.
Definition: geo_types.h:842
ParentID_t & parentID()
Return the parent ID of this one (a TPC set ID).
typename AbsIDtypeStruct< ID, Index >::type AbsIDtype
Definition: geo_types.h:47
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.
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
Definition of data types for geometry description.
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.
double value
Definition: spectrum.C:18
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:193
static constexpr Level_t TPCset
Definition: readout_types.h:54
TPCsetID & asTPCsetID()
Conversion to TPCsetID (for convenience of notation).
constexpr auto getAbsIDindex(ID const &id)
Definition: readout_types.h:34
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).
void ParentID_t
Type of the parent ID (none!).
Definition: geo_types.h:196
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:269
static constexpr ROPID_t InvalidID
Special code for an invalid ID.
std::size_t Level_t
Definition: geo_types.h:174
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:22
static constexpr Level_t ReadoutPlane
Definition: readout_types.h:55
geo::CryostatID CryostatID
Definition: readout_types.h:62
constexpr TPCsetID const & asTPCsetID() const
Conversion to TPCsetID (for convenience of notation).
The data type to uniquely identify a cryostat.
Definition: geo_types.h:192