extractMaxGeometryElements.h
Go to the documentation of this file.
1 /**
2  * @file larcorealg/Geometry/details/extractMaxGeometryElements.h
3  * @brief Algorithm discovering the number of elements in the geometry.
4  * @author Gianluca Petrillo (petrillo@slac.stanford.edu)
5  * @date October 19, 2019
6  *
7  * This is a header only library.
8  */
9 
10 #ifndef LARCOREALG_GEOMETRY_DETAILS_EXTRACTMAXGEOMETRYELEMENTS_H
11 #define LARCOREALG_GEOMETRY_DETAILS_EXTRACTMAXGEOMETRYELEMENTS_H
12 
13 
14 // LArSoft libraries
19 
20 // C/C++ standard libraries
21 #include <array>
22 #include <cstddef> // std::size_t
23 
24 
25 namespace geo::details {
26 
27  /**
28  * @brief Extracts the maximum number of elements per type.
29  * @tparam Levels the number of detector elements to discover
30  * @param Cryostats the sorted list of cryostats in the detector
31  * @return an array with maximum number of cryostats, TPCs, planes and wires
32  *
33  * The returned array includes:
34  *
35  * * index `[0]`: number of cryostats
36  * * index `[1]`: maximum number of TPCs in any of the cryostats
37  * (enabled only if `Levels` is `2` or higher)
38  * * index `[2]`: maximum number of wire planes in any of the TPCs
39  * (enabled only if `Levels` is `3` or higher)
40  * * index `[3]`: maximum number of wires in any of the wire planes
41  * (enabled only if `Levels` is `4`)
42  *
43  */
44  template <std::size_t Levels = 4U>
45  static std::array<unsigned int, Levels> extractMaxGeometryElements
46  (geo::GeometryData_t::CryostatList_t const& Cryostats);
47 
48 } // namespace geo::details
49 
50 
51 // -----------------------------------------------------------------------------
52 // --- template implementation
53 // -----------------------------------------------------------------------------
54 template <std::size_t Levels /* = 4U */>
55 std::array<unsigned int, Levels>
57  (geo::GeometryData_t::CryostatList_t const& Cryostats)
58 {
59  static_assert(Levels > 0U);
60  static_assert(Levels <= 4U);
61 
62  std::array<unsigned int, Levels> maxElements;
63  maxElements.fill(0U);
64 
65  auto setMax = [&maxElements](std::size_t index, unsigned int value)
66  { if (maxElements[index] < value) maxElements[index] = value; };
67 
68  setMax(0U, Cryostats.size());
69  if constexpr(Levels > 1U) {
70  for (geo::CryostatGeo const& cryo: Cryostats) {
71  setMax(1U, cryo.NTPC());
72  if constexpr(Levels > 2U) {
73  for (geo::TPCGeo const& TPC: cryo.IterateTPCs()) {
74  setMax(2U, TPC.Nplanes());
75  if constexpr(Levels > 3U) {
76  for (geo::PlaneGeo const& plane: TPC.IteratePlanes()) {
77  setMax(3U, plane.Nwires());
78  } // for planes
79  } // if do wires
80  } // for TPCs
81  } // if do planes
82  } // for cryostats
83  } // if do TPCs
84 
85  return maxElements;
86 } // geo::details::extractMaxGeometryElements()
87 
88 
89 // -----------------------------------------------------------------------------
90 
91 
92 #endif // LARCOREALG_GEOMETRY_DETAILS_EXTRACTMAXGEOMETRYELEMENTS_H
Encapsulate the construction of a single cyostat.
Simple data structure holding the data of the geometry.
Geometry information for a single TPC.
Definition: TPCGeo.h:38
static std::array< unsigned int, Levels > extractMaxGeometryElements(geo::GeometryData_t::CryostatList_t const &Cryostats)
Extracts the maximum number of elements per type.
std::vector< geo::CryostatGeo > CryostatList_t
Type of list of cryostats.
Definition: GeometryData.h:34
Geometry information for a single cryostat.
Definition: CryostatGeo.h:43
Geometry information for a single wire plane.The plane is represented in the geometry by a solid whic...
Definition: PlaneGeo.h:82
Encapsulate the construction of a single detector plane.
Encapsulate the construction of a single detector plane.