LArSoft  v10_04_05
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 Index, typename ID>
31  inline constexpr auto getAbsIDindex(ID const& id)
32  {
33  return geo::details::getAbsIDindex<Index, ID>(id);
34  }
35 
36  template <std::size_t Index, typename ID>
37  inline auto& getAbsIDindex(ID& id)
38  {
39  return geo::details::getAbsIDindex<Index, ID>(id);
40  }
41 
42  } // namespace details
43 
44  // We define our own cryostat ID as an alias of the one from geometry
46 
54  struct TPCsetID : public CryostatID {
55  using TPCsetID_t = unsigned short;
56 
58 
60  static constexpr TPCsetID_t InvalidID = std::numeric_limits<TPCsetID_t>::max();
61 
63  TPCsetID_t TPCset = InvalidID;
64 
66  constexpr TPCsetID() = default;
67 
69  constexpr TPCsetID(CryostatID const& cryoid, TPCsetID_t s) : CryostatID(cryoid), TPCset(s) {}
70 
72  constexpr TPCsetID(CryostatID_t c, TPCsetID_t s) : CryostatID(c), TPCset(s) {}
73 
74  static constexpr auto first() { return TPCsetID{CryostatID::first(), 0}; }
75  static constexpr auto first(CryostatID const& id) { return TPCsetID{id, 0}; }
76 
77  // comparison operators are out of class
78 
80  std::string toString() const { return details::writeToString(*this); }
82  explicit operator std::string() const { return toString(); }
84 
85  // the following two methods are useful for (templated) abstraction
87  constexpr auto const& deepestIndex() const { return TPCset; }
89  auto& deepestIndex() { return TPCset; }
91  constexpr ParentID_t const& parentID() const { return *this; }
92  constexpr ParentID_t& parentID() { return *this; }
94  template <std::size_t Index>
95  constexpr auto getIndex() const;
96 
98  constexpr CryostatID const& asCryostatID() const { return parentID(); }
99  constexpr CryostatID& asCryostatID() { return parentID(); }
100 
102  static constexpr auto Level = geo::details::index_for<TPCsetID>();
103 
105  static constexpr TPCsetID_t getInvalidID() { return TPCsetID::InvalidID; }
106 
107  }; // struct TPCsetID
108 
118  struct ROPID : public TPCsetID {
119  using ROPID_t = unsigned int;
120 
122 
124  static constexpr ROPID_t InvalidID = std::numeric_limits<ROPID_t>::max();
125 
126  ROPID_t ROP = InvalidID;
127 
129  constexpr ROPID() = default;
130 
132  constexpr ROPID(TPCsetID const& tpcsetid, ROPID_t r) : TPCsetID(tpcsetid), ROP(r) {}
133 
136  constexpr ROPID(CryostatID_t c, TPCsetID_t s, ROPID_t r) : TPCsetID(c, s), ROP(r) {}
137 
138  static constexpr auto first() { return ROPID{TPCsetID::first(), 0}; }
139  static constexpr auto first(CryostatID const& id) { return ROPID{TPCsetID::first(id), 0}; }
140  static constexpr auto first(TPCsetID const& id) { return ROPID{id, 0}; }
141 
142  // comparison operators are out of class
143 
145  std::string toString() const { return details::writeToString(*this); }
147  explicit operator std::string() const { return toString(); }
149 
150  // the following two methods are useful for (templated) abstraction
152  constexpr auto const& deepestIndex() const { return ROP; }
154  auto& deepestIndex() { return ROP; }
156  constexpr ParentID_t const& parentID() const { return *this; }
157  constexpr ParentID_t& parentID() { return *this; }
159  template <std::size_t Index>
160  constexpr auto getIndex() const;
161 
163  constexpr TPCsetID const& asTPCsetID() const { return parentID(); }
164  constexpr TPCsetID& asTPCsetID() { return parentID(); }
165 
167  static constexpr auto Level = geo::details::index_for<ROPID>();
168 
170  static constexpr ROPID_t getInvalidID() { return ROPID::InvalidID; }
171 
172  }; // struct ROPID
173 
174  //----------------------------------------------------------------------------
175  //--- ID output operators
176  //---
178  inline std::ostream& operator<<(std::ostream& out, TPCsetID const& sid)
179  {
180  out << sid.asCryostatID() << " S:" << sid.TPCset;
181  return out;
182  }
183 
184  inline std::ostream& operator<<(std::ostream& out, ROPID const& rid)
185  {
186  out << rid.asTPCsetID() << " R:" << rid.ROP;
187  return out;
188  }
189 
190 } // namespace readout
191 
192 //------------------------------------------------------------------------------
193 //--- template implementation
194 //------------------------------------------------------------------------------
195 template <std::size_t Index>
196 constexpr auto readout::TPCsetID::getIndex() const
197 {
198  static_assert(Index <= Level, "This ID type does not have the requested Index level.");
199  return details::getAbsIDindex<Index>(*this);
200 }
201 
202 //------------------------------------------------------------------------------
203 template <std::size_t Index>
204 constexpr auto readout::ROPID::getIndex() const
205 {
206  static_assert(Index <= Level, "This ID type does not have the requested Index level.");
207  return details::getAbsIDindex<Index>(*this);
208 }
209 
210 //------------------------------------------------------------------------------
211 
212 #endif // LARCOREOBJ_SIMPLETYPESANDCONSTANTS_READOUT_TYPES_H
constexpr CryostatID & asCryostatID()
Definition: readout_types.h:99
TRandom r
Definition: spectrum.C:23
constexpr TPCsetID & asTPCsetID()
constexpr ParentID_t & parentID()
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)
Constructor: TPC set with index s in the cryostat identified by cryoid.
Definition: readout_types.h:69
static constexpr auto first()
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).
Definition: readout_types.h:87
unsigned short TPCsetID_t
Type for the ID number.
Definition: readout_types.h:55
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:54
Level
Definition: Level.h:13
constexpr CryostatID const & asCryostatID() const
Conversion to TPCsetID (for convenience of notation).
Definition: readout_types.h:98
static constexpr auto first()
Definition: readout_types.h:74
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:60
std::string writeToString(T const &value)
Write the argument into a string.
Definition: geo_types.h:627
typename AbsIDtypeStruct< ID, Index >::type AbsIDtype
Definition: geo_types.h:59
auto & deepestIndex()
Returns the deepest ID available (TPC set&#39;s).
Definition: readout_types.h:89
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)
Constructor: readout plane with index r in the TPC set identified by tpcsetid.
ROPID_t ROP
Index of the readout plane within its TPC set.
constexpr TPCsetID const & asTPCsetID() const
Conversion to ROPID (for convenience of notation).
IDparameter< readout::TPCsetID > TPCsetID
Member type of validated readout::TPCsetID parameter.
static constexpr auto first(CryostatID const &id)
Definition: readout_types.h:75
static constexpr auto first(TPCsetID const &id)
Definition of data types for geometry description.
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:63
constexpr TPCsetID(CryostatID_t c, TPCsetID_t s)
Constructor: TPC set with index s in the cryostat index c.
Definition: readout_types.h:72
unsigned int CryostatID_t
Type for the ID number.
Definition: geo_types.h:188
constexpr auto getAbsIDindex(ID const &id)
Definition: readout_types.h:31
constexpr ParentID_t const & parentID() const
Return the parent ID of this one (a cryostat ID).
Definition: readout_types.h:91
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).
constexpr ParentID_t & parentID()
Definition: readout_types.h:92
static constexpr auto first()
Definition: geo_types.h:206
constexpr ROPID(CryostatID_t c, TPCsetID_t s, ROPID_t r)
static constexpr auto first(CryostatID const &id)
static constexpr ROPID_t InvalidID
Special code for an invalid ID.
std::string writeToString(T const &value)
Definition: readout_types.h:22
geo::CryostatID CryostatID
Definition: readout_types.h:45
The data type to uniquely identify a cryostat.
Definition: geo_types.h:187