LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
GeometryDataContainers.h
Go to the documentation of this file.
1 
11 #ifndef LARCOREALG_GEOMETRY_GEOMETRYDATACONTAINERS_H
12 #define LARCOREALG_GEOMETRY_GEOMETRYDATACONTAINERS_H
13 
14 // LArSoft libraries
16 
17 // C/C++ standard libraries
18 #include <vector>
19 #include <stdexcept> // std::out_of_range
20 #include <cassert>
21 
22 
23 namespace geo {
24 
25  // --- BEGIN Geometry data containers ----------------------------------------
29 
64  template <typename T>
66 
67  using Container_t = std::vector<T>;
68 
69  public:
70 
73 
74  // TODO the iterator is not really a random access one
75 
76  using reference = typename Container_t::reference ;
77  using const_reference = typename Container_t::const_reference ;
78  using pointer = typename Container_t::pointer ;
79  using const_pointer = typename Container_t::const_pointer ;
80  using iterator = typename Container_t::iterator ;
82  using reverse_iterator = typename Container_t::reverse_iterator ;
83  using const_reverse_iterator = typename Container_t::const_reverse_iterator;
84  using difference_type = typename Container_t::difference_type ;
85  using size_type = typename Container_t::size_type ;
86 
88 
97  TPCDataContainer(unsigned int nCryo, unsigned int nTPCs)
98  : fNCryo(nCryo)
99  , fNTPCs(nTPCs)
100  , fData(computeSize())
101  { assert(!empty()); }
102 
119  TPCDataContainer(unsigned int nCryo, unsigned int nTPCs, T const& defValue)
120  : fNCryo(nCryo)
121  , fNTPCs(nTPCs)
122  , fData(computeSize(), defValue)
123  { assert(!empty()); }
124 
125 
126  // --- BEGIN Container status query ----------------------------------------
129 
131  size_type size() const { return fData.size(); }
132 
134  size_type capacity() const { return fData.capacity(); }
135 
137  bool empty() const { return fData.empty(); }
138 
140  bool hasCryostat(geo::CryostatID const& cryoid) const
141  { return bounded(cryoid.Cryostat, fNCryo); }
142 
144  bool hasTPC(geo::TPCID const& id) const
145  { return hasCryostat(id) && bounded(id.TPC, fNTPCs); }
146 
148  geo::TPCID firstID() const { return { 0U, 0U }; }
149 
151  geo::TPCID lastID() const { return { fNCryo - 1U, fNTPCs - 1U }; }
152 
154  // --- END Container status query ------------------------------------------
155 
156 
157  // --- BEGIN Element access ------------------------------------------------
160 
163  { return fData[index(id)]; }
164 
167  { return fData[index(id)]; }
168 
172  {
173  if (hasTPC(id)) return operator[](id);
174  throw std::out_of_range("No data for " + std::string(id));
175  }
176 
179  const_reference at (geo::TPCID const& id) const
180  {
181  if (hasTPC(id)) return operator[](id);
182  throw std::out_of_range("No data for " + std::string(id));
183  }
184 
185 
188 
190  const_reference first() const { return operator[](firstID()); }
191 
192 
194  reference last() { return operator[](lastID()); }
195 
197  const_reference last() const { return operator[](lastID()); }
198 
200 
201 
202  private:
205 
208 
210 
213  { return (fNTPCs * cryo) + tpc; }
214 
216  size_type index(geo::TPCID const& id) const
217  { return index(id.Cryostat, id.TPC); }
218 
221  { return { index / fNCryo, index % fNCryo }; }
222 
224  size_type computeSize() const { return computeSize(fNCryo, fNTPCs); }
225 
228  { return nCryo * nTPCs; }
229 
231  template <typename Value, typename Upper>
232  static bool bounded(Value v, Upper upper)
233  { return (v >= 0) && (static_cast<size_type>(v) < upper); }
234 
235  }; // class TPCDataContainer
236 
237 
238 
272  template <typename T>
274 
275  using Container_t = std::vector<T>;
276 
277  public:
278 
281 
282  // TODO the iterator is not really a random access one
283 
284  using reference = typename Container_t::reference ;
285  using const_reference = typename Container_t::const_reference ;
286  using pointer = typename Container_t::pointer ;
287  using const_pointer = typename Container_t::const_pointer ;
288  using iterator = typename Container_t::iterator ;
290  using reverse_iterator = typename Container_t::reverse_iterator ;
291  using const_reverse_iterator = typename Container_t::const_reverse_iterator;
292  using difference_type = typename Container_t::difference_type ;
293  using size_type = typename Container_t::size_type ;
294 
296 
308  (unsigned int nCryo, unsigned int nTPCs, unsigned int nPlanes)
309  : fNCryo(nCryo)
310  , fNTPCs(nTPCs)
311  , fNPlanes(nPlanes)
312  , fData(computeSize())
313  { assert(!empty()); }
314 
332  unsigned int nCryo, unsigned int nTPCs, unsigned int nPlanes,
333  T const& defValue
334  )
335  : fNCryo(nCryo)
336  , fNTPCs(nTPCs)
337  , fNPlanes(nPlanes)
338  , fData(computeSize(), defValue)
339  { assert(!empty()); }
340 
341 
342  // --- BEGIN Container status query ----------------------------------------
345 
347  size_type size() const { return fData.size(); }
348 
350  size_type capacity() const { return fData.capacity(); }
351 
353  bool empty() const { return fData.empty(); }
354 
356  bool hasCryostat(geo::CryostatID const& cryoid) const
357  { return bounded(cryoid.Cryostat, fNCryo); }
358 
360  bool hasTPC(geo::TPCID const& id) const
361  { return hasCryostat(id) && bounded(id.TPC, fNTPCs); }
362 
364  bool hasPlane(geo::PlaneID const& id) const
365  { return hasTPC(id) && bounded(id.Plane, fNPlanes); }
366 
368  geo::PlaneID firstID() const { return { 0U, 0U, 0U }; }
369 
372  { return { fNCryo - 1U, fNTPCs - 1U, fNPlanes - 1U }; }
373 
375  // --- END Container status query ------------------------------------------
376 
377 
378  // --- BEGIN Element access ------------------------------------------------
381 
384  { return fData[index(id)]; }
385 
388  { return fData[index(id)]; }
389 
393  {
394  if (hasPlane(id)) return operator[](id);
395  throw std::out_of_range("No data for " + std::string(id));
396  }
397 
400  const_reference at(geo::PlaneID const& id) const
401  {
402  if (hasPlane(id)) return operator[](id);
403  throw std::out_of_range("No data for " + std::string(id));
404  }
405 
406 
409 
411  const_reference first() const { return operator[](firstID()); }
412 
413 
415  reference last() { return operator[](lastID()); }
416 
418  const_reference last() const { return operator[](lastID()); }
419 
421 
422 
423  private:
427 
431 
433 
435  size_type index(CryostatNo_t cryo, TPCNo_t tpc, PlaneNo_t plane) const
436  { return ((cryo) * fNTPCs + tpc) * fNPlanes + plane; }
437 
439  size_type index(geo::PlaneID const& id) const
440  { return index(id.Cryostat, id.TPC, id.Plane); }
441 
444  {
445  return
446  { index / fNCryo, index % fNCryo / fNPlanes, index % fNPlanes };
447  }
448 
451  { return computeSize(fNCryo, fNTPCs, fNPlanes); }
452 
454  static size_type computeSize
455  (CryostatNo_t nCryo, TPCNo_t nTPCs, PlaneNo_t nPlanes)
456  { return nCryo * nTPCs * nPlanes; }
457 
459  template <typename Value, typename Upper>
460  static bool bounded(Value v, Upper upper)
461  { return (v >= 0) && (static_cast<size_type>(v) < upper); }
462 
463  }; // class PlaneDataContainer
464 
465 
467  // --- END Geometry data containers ------------------------------------------
468 
469 } // namespace geo
470 
471 
472 
473 #endif // LARCOREALG_GEOMETRY_GEOMETRYDATACONTAINERS_H
size_type size() const
Returns the number of elements in the container.
typename Container_t::const_pointer const_pointer
size_type index(geo::PlaneID const &id) const
Returns the internal index of the specified TPC in the storage area.
typename Container_t::const_iterator const_iterator
reference operator[](geo::TPCID const &id)
Returns the element for the specified TPC.
typename Container_t::pointer pointer
reference at(geo::PlaneID const &id)
intermediate_table::iterator iterator
size_type index(CryostatNo_t cryo, TPCNo_t tpc) const
Returns the internal index of the specified TPC in the storage area.
typename Container_t::const_reverse_iterator const_reverse_iterator
geo::PlaneID::PlaneID_t PlaneNo_t
size_type capacity() const
Returns the number of elements the container has memory for.
reference operator[](geo::PlaneID const &id)
Returns the element for the specified wire plane.
unsigned int CryostatID_t
Type for the ID number.
Definition: geo_types.h:121
PlaneNo_t fNPlanes
Number of planes per TPC.
bool hasCryostat(geo::CryostatID const &cryoid) const
Returns whether this container hosts data for the specified cryostat.
typename Container_t::const_reference const_reference
The data type to uniquely identify a Plane.
Definition: geo_types.h:250
bool empty() const
Returns whether the container has no elements (false by assumptions).
TPCDataContainer(unsigned int nCryo, unsigned int nTPCs)
Prepares the container with default-constructed data.
typename Container_t::pointer pointer
CryostatID_t Cryostat
Index of cryostat.
Definition: geo_types.h:130
typename Container_t::size_type size_type
Container with one element per geometry wire plane.
geo::PlaneID firstID() const
Returns the ID of the first TPC.
const_reference at(geo::PlaneID const &id) const
reference last()
Returns the element for the last TPC (unchecked).
geo::TPCID lastID() const
Returns the ID of the last covered TPC.
bool hasTPC(geo::TPCID const &id) const
Returns whether this container hosts data for the specified TPC.
const_reference last() const
Returns the element for the last TPC (unchecked).
unsigned int PlaneID_t
Type for the ID number.
Definition: geo_types.h:251
CryostatNo_t fNCryo
Number of cryostats.
Container with one element per geometry TPC.
bool hasPlane(geo::PlaneID const &id) const
Returns whether this container hosts data for the specified plane.
typename Container_t::size_type size_type
typename Container_t::reference reference
intermediate_table::const_iterator const_iterator
static size_type computeSize(CryostatNo_t nCryo, TPCNo_t nTPCs)
Returns the size of a container with the specified dimensions.
size_type index(geo::TPCID const &id) const
Returns the internal index of the specified TPC in the storage area.
typename Container_t::const_reference const_reference
geo::PlaneID ID(size_type index) const
Returns the ID of the TPC at the specified index (unchecked!)
bool hasCryostat(geo::CryostatID const &cryoid) const
Returns whether this container hosts data for the specified cryostat.
unsigned int TPCID_t
Type for the ID number.
Definition: geo_types.h:196
const_reference operator[](geo::PlaneID const &id) const
Returns the element for the specified wire plane (read-only).
size_type size() const
Returns the number of elements in the container.
const_reference operator[](geo::TPCID const &id) const
Returns the element for the specified TPC (read-only).
static bool bounded(Value v, Upper upper)
Returns whether the specified value is between 0 and the upper limit.
bool empty() const
Returns whether the container has no elements (false by assumptions).
typename Container_t::const_reverse_iterator const_reverse_iterator
geo::TPCID firstID() const
Returns the ID of the first TPC.
TPCNo_t fNTPCs
Number of TPCs.
typename Container_t::iterator iterator
typename Container_t::difference_type difference_type
The data type to uniquely identify a TPC.
Definition: geo_types.h:195
typename Container_t::const_pointer const_pointer
geo::TPCID::TPCID_t TPCNo_t
Container_t fData
Data storage area.
Definition of data types for geometry description.
bool hasTPC(geo::TPCID const &id) const
Returns whether this container hosts data for the specified TPC.
typename Container_t::reverse_iterator reverse_iterator
TPCNo_t fNTPCs
Number of TPCs per cryostat.
typename Container_t::difference_type difference_type
reference last()
Returns the element for the last TPC (unchecked).
reference first()
Returns the element for the first TPC (unchecked).
CryostatNo_t fNCryo
Number of cryostats.
geo::CryostatID::CryostatID_t CryostatNo_t
reference first()
Returns the element for the first TPC (unchecked).
typename Container_t::reverse_iterator reverse_iterator
TPCDataContainer(unsigned int nCryo, unsigned int nTPCs, T const &defValue)
Prepares the container with copies of the specified default value.
const_reference first() const
Returns the element for the first TPC (unchecked).
static bool bounded(Value v, Upper upper)
Returns whether the specified value is between 0 and the upper limit.
size_type capacity() const
Returns the number of elements the container has memory for.
typename Container_t::iterator iterator
geo::CryostatID::CryostatID_t CryostatNo_t
const_reference at(geo::TPCID const &id) const
typename Container_t::const_iterator const_iterator
PlaneDataContainer(unsigned int nCryo, unsigned int nTPCs, unsigned int nPlanes, T const &defValue)
Prepares the container with copies of the specified default value.
const_reference last() const
Returns the element for the last TPC (unchecked).
size_type index(CryostatNo_t cryo, TPCNo_t tpc, PlaneNo_t plane) const
Returns the internal index of the specified TPC in the storage area.
reference at(geo::TPCID const &id)
geo::PlaneID lastID() const
Returns the ID of the last covered TPC.
recob::tracking::Plane Plane
Definition: TrackState.h:17
size_type computeSize() const
Computes the expected size of this container.
Namespace collecting geometry-related classes utilities.
size_type computeSize() const
Computes the expected size of this container.
const_reference first() const
Returns the element for the first TPC (unchecked).
geo::TPCID ID(size_type index) const
Returns the ID of the TPC at the specified index (unchecked!)
Container_t fData
Data storage area.
The data type to uniquely identify a cryostat.
Definition: geo_types.h:120
typename Container_t::reference reference