LArSoft  v09_90_00
Liquid Argon Software toolkit - https://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
18 
19 // Boost libraries
20 #include <boost/iterator/iterator_adaptor.hpp>
21 #include <boost/iterator/transform_iterator.hpp>
22 
23 // C/C++ standard libraries
24 #include <algorithm> // std::fill(), std::for_each()
25 #include <cassert>
26 #include <initializer_list>
27 #include <stdexcept> // std::out_of_range
28 #include <string>
29 #include <utility> // std::forward()
30 #include <vector>
31 
32 namespace geo {
33 
34  template <typename T, typename Mapper>
36 
37  template <typename T>
39 
40  template <typename T>
42 
43  // ---------------------------------------------------------------------------
44  namespace details {
45 
46  template <typename T>
48 
49  template <typename GeoIDdataContainerClass, typename BaseIterator>
51 
52  template <typename GeoIDIteratorClass>
54 
55  } // namespace details
56  // ---------------------------------------------------------------------------
57 
58 } // namespace geo
59 
60 // --- BEGIN Geometry data containers ----------------------------------------
61 
65 
100 template <typename T, typename Mapper>
102 
104 
107 
110 
113 
115  struct IDextractor {
116  template <typename Obj>
117  decltype(auto) operator()(Obj&& obj) const
118  {
119  return obj.ID();
120  }
121  }; // struct IDextractor
122 
123 public:
125  using Mapper_t = Mapper;
126 
127  using ID_t = typename Mapper_t::ID_t;
128 
131 
135  using pointer = typename Container_t::pointer;
139  // using reverse_iterator = typename Container_t::reverse_iterator ;
140  // using const_reverse_iterator = typename Container_t::const_reverse_iterator;
143 
146 
149 
151 
158  GeoIDdataContainer() = default;
159 
171  GeoIDdataContainer(std::initializer_list<unsigned int> dims);
172 
185  GeoIDdataContainer(std::initializer_list<unsigned int> dims, value_type const& defValue);
186 
187  // --- BEGIN Container status query ----------------------------------------
190 
192  size_type size() const;
193 
195  size_type capacity() const;
196 
198  bool empty() const;
199 
201  template <std::size_t Level>
202  unsigned int dimSize() const;
203 
205  static constexpr unsigned int dimensions();
206 
208  template <typename GeoID>
209  bool hasElement(GeoID const& id) const;
210 
212  template <typename GeoID = ID_t>
213  GeoID firstID() const;
214 
216  template <typename GeoID = ID_t>
217  GeoID lastID() const;
218 
220  Mapper_t const& mapper() const;
221 
223  // --- END Container status query ------------------------------------------
224 
225  // --- BEGIN Element access ------------------------------------------------
228 
230 
231  reference operator[](ID_t const& id);
232 
234  const_reference operator[](ID_t const& id) const;
235 
238  reference at(ID_t const& id);
239 
242  const_reference at(ID_t const& id) const;
243 
245  reference first();
246 
248  const_reference first() const;
249 
251  reference last();
252 
254  const_reference last() const;
255 
257  // --- END Element access --------------------------------------------------
258 
259  // --- BEGIN Iterators -----------------------------------------------------
307 
310  iterator begin();
311 
313  iterator end();
314 
316  const_iterator begin() const;
317 
319  const_iterator end() const;
320 
322  const_iterator cbegin() const;
323 
325  const_iterator cend() const;
326 
328  item_iterator item_begin();
329 
331  item_iterator item_end();
332 
334  item_const_iterator item_begin() const;
335 
337  item_const_iterator item_end() const;
338 
340  item_const_iterator item_cbegin() const;
341 
343  item_const_iterator item_cend() const;
344 
346  auto items();
347 
349  auto items() const;
350 
352  // --- END Iterators -------------------------------------------------------
353 
354  // --- BEGIN Data modification ---------------------------------------------
362 
365  void fill(value_type value);
366 
368  void reset();
369 
381  template <typename Op>
382  Op apply(Op&& op);
383 
397  template <typename Op>
398  decltype(auto) apply(Op&& op) const;
399 
401  // --- END Data modification -------------------------------------------------
402 
403  // --- BEGIN Container modification ------------------------------------------
406 
420  void resize(std::initializer_list<unsigned int> dims);
421 
436  void resize(std::initializer_list<unsigned int> dims, value_type const& defValue);
437 
449  template <typename OT>
450  void resizeAs(geo::GeoIDdataContainer<OT, Mapper_t> const& other);
451 
464  template <typename OT>
465  void resizeAs(geo::GeoIDdataContainer<OT, Mapper_t> const& other, value_type const& defValue);
466 
473  void clear();
474 
476  // --- END Container modification --------------------------------------------
477 
478 private:
479  Mapper_t fMapper;
480 
481  Container_t fData;
482 
484  size_type index(ID_t const& id) const;
485 
487  ID_t ID(size_type const index) const;
488 
489 }; // class geo::GeoIDdataContainer<>
490 
491 //------------------------------------------------------------------------------
526 template <typename T>
527 class geo::TPCDataContainer : public geo::GeoIDdataContainer<T, geo::TPCIDmapper<>> {
528 
530 
531 public:
533 
542  TPCDataContainer() = default;
543 
552  TPCDataContainer(unsigned int nCryo, unsigned int nTPCs) : BaseContainer_t({nCryo, nTPCs}) {}
553 
570  TPCDataContainer(unsigned int nCryo, unsigned int nTPCs, value_type const& defValue)
571  : BaseContainer_t({nCryo, nTPCs}, defValue)
572  {}
573 
574  // --- BEGIN Container modification ------------------------------------------
577 
590  void resize(unsigned int nCryo, unsigned int nTPCs) { BaseContainer_t::resize({nCryo, nTPCs}); }
591 
610  void resize(unsigned int nCryo, unsigned int nTPCs, T const& defValue)
611  {
612  BaseContainer_t::resize({nCryo, nTPCs}, defValue);
613  }
614 
616  // --- END Container modification --------------------------------------------
617 
618  // --- BEGIN Container status query ------------------------------------------
621 
623  bool hasCryostat(geo::CryostatID const& cryoid) const
624  {
625  return BaseContainer_t::hasElement(cryoid);
626  }
627 
629  bool hasTPC(geo::TPCID const& tpcid) const { return BaseContainer_t::hasElement(tpcid); }
630 
632  // --- END Container status query --------------------------------------------
633 
634 }; // class geo::details::TPCDataContainer<>
635 
636 //------------------------------------------------------------------------------
670 template <typename T>
671 class geo::PlaneDataContainer : public geo::GeoIDdataContainer<T, geo::PlaneIDmapper<>> {
672 
675 
676 public:
685  PlaneDataContainer() = default;
686 
697  PlaneDataContainer(unsigned int nCryo, unsigned int nTPCs, unsigned int nPlanes)
698  : BaseContainer_t({nCryo, nTPCs, nPlanes})
699  {}
700 
717  PlaneDataContainer(unsigned int nCryo,
718  unsigned int nTPCs,
719  unsigned int nPlanes,
720  T const& defValue)
721  : BaseContainer_t{{nCryo, nTPCs, nPlanes}, defValue}
722  {}
723 
724  // --- BEGIN Container modification ------------------------------------------
727 
742  void resize(unsigned int nCryo, unsigned int nTPCs, unsigned int nPlanes)
743  {
744  BaseContainer_t::resize({nCryo, nTPCs, nPlanes});
745  }
746 
768  void resize(unsigned int nCryo, unsigned int nTPCs, unsigned int nPlanes, T const& defValue)
769  {
770  BaseContainer_t::resize({nCryo, nTPCs, nPlanes}, defValue);
771  }
772 
774  // --- END Container modification --------------------------------------------
775 
776  // --- BEGIN Container status query ------------------------------------------
779 
781  bool hasCryostat(geo::CryostatID const& cryoid) const
782  {
783  return BaseContainer_t::hasElement(cryoid);
784  }
785 
787  bool hasTPC(geo::TPCID const& tpcid) const { return BaseContainer_t::hasElement(tpcid); }
788 
790  bool hasPlane(geo::PlaneID const& planeid) const { return BaseContainer_t::hasElement(planeid); }
791 
793  // --- END Container status query --------------------------------------------
794 
795 }; // class geo::PlaneDataContainer
796 
797 //------------------------------------------------------------------------------
805 template <typename GeoIDmapperClass, typename BaseIterator>
807  : public boost::iterator_adaptor<
808  geo::details::GeoIDdataContainerIterator<GeoIDmapperClass, BaseIterator>,
809  BaseIterator> {
810 
812  using Mapper_t = GeoIDmapperClass;
813 
814  using BaseIterator_t = BaseIterator;
815 
817  using Index_t = typename Mapper_t::index_type;
818 
819  struct ExtraData_t {
820 
822  Mapper_t const* mapper = nullptr;
823 
825 
826  }; // struct ExtraData_t
827 
829 
831  BaseIterator_t const& current() const
832  {
833  return GeoIDdataContainerIterator::iterator_adaptor_::base();
834  }
835  BaseIterator_t& current() { return GeoIDdataContainerIterator::iterator_adaptor_::base(); }
836 
838  BaseIterator_t const& start() const { return fData.start; }
839 
841  Mapper_t const& mapper() const
842  {
843  assert(fData.mapper);
844  return *(fData.mapper);
845  }
846 
848  Index_t index() const { return static_cast<Index_t>(current() - start()); }
849 
850 public:
851  using ID_t = typename Mapper_t::ID_t;
852 
854  GeoIDdataContainerIterator() = default;
855 
858  BaseIterator_t const& start,
859  BaseIterator_t const& current)
860  : GeoIDdataContainerIterator::iterator_adaptor_(current), fData{&mapper, start}
861  {}
862 
864  template <typename OBaseIterator>
867  std::enable_if_t<std::is_convertible_v<OBaseIterator, BaseIterator_t>> = nullptr)
868  : GeoIDdataContainerIterator::iterator_adaptor_(other.base()), fData(other.fData)
869  {}
870 
872  ID_t ID() const { return mapper().ID(index()); }
873 
874 private:
875  // friend class boost::iterator_core_access;
876 
877  // there might be some need for other interoperability methods (comparison?)
878 
879 }; // geo::details::GeoIDdataContainerIterator
880 
889 template <typename GeoIDIteratorClass>
891  : public boost::iterator_adaptor<geo::details::GeoIDdataContainerItemIterator<GeoIDIteratorClass>,
892  GeoIDIteratorClass,
893  std::pair<typename GeoIDIteratorClass::ID_t,
894  typename GeoIDIteratorClass::reference> // Value
895  ,
896  boost::use_default // Category
897  ,
898  std::pair<typename GeoIDIteratorClass::ID_t,
899  typename GeoIDIteratorClass::reference> // Reference
900  > {
901  /*
902  * Implementation notes:
903  * * boost::transform_iterator can't be used to wrap
904  * `geo::GeoIDdataContainerIterator` because it acts on the value of
905  * the wrapped iterator, while we need to extract information from
906  * the iterator itself (its `ID()` data member)
907  * * we need to specify the type of reference the iterator returns,
908  * because... it's not a reference; this is not really a STL random
909  * access iterator since it dereferences to a temporary value (rvalue)
910  * like an input iterator can; but for the rest it's a full blown random
911  * access iterator (same stuff as the infamous `std::vector<bool>`)
912  *
913  */
914 
915  using GeoIDiterator_t = GeoIDIteratorClass;
916 
918 
919 public:
921  using ID_t = typename GeoIDiterator_t::ID_t;
922 
924  GeoIDdataContainerItemIterator() = default;
925 
928 
930  template <typename OGeoIDIteratorClass>
933  std::enable_if_t<std::is_convertible_v<OGeoIDIteratorClass, GeoIDiterator_t>> = nullptr)
934  : iterator_adaptor_(other.base())
935  {}
936 
937 private:
938  friend class boost::iterator_core_access;
939 
940  using iterator_adaptor_::base;
941 
942  typename iterator_adaptor_::reference dereference() const { return {base().ID(), *base()}; }
943 
944  // there might be some need for other interoperability methods (comparison?)
945 
946 }; // geo::details::GeoIDdataContainerItemIterator
947 
949 // --- END Geometry data containers --------------------------------------------
950 //------------------------------------------------------------------------------
951 
952 //------------------------------------------------------------------------------
953 //--- Template implementation
954 //------------------------------------------------------------------------------
955 //--- geo::details::GeoContainerData
956 //------------------------------------------------------------------------------
957 template <typename T>
959 
960  using Container_t = std::vector<T>;
961 
962 public:
963  // --- BEGIN STL container types ---------------------------------------------
966 
967  using value_type = typename Container_t::value_type;
968  using reference = typename Container_t::reference;
969  using const_reference = typename Container_t::const_reference;
970  using pointer = typename Container_t::pointer;
971  using const_pointer = typename Container_t::const_pointer;
972  using iterator = typename Container_t::iterator;
974  using reverse_iterator = typename Container_t::reverse_iterator;
975  using const_reverse_iterator = typename Container_t::const_reverse_iterator;
976  using difference_type = typename Container_t::difference_type;
977  using size_type = typename Container_t::size_type;
978 
980  // --- END STL container types -----------------------------------------------
981 
983 
984  // --- BEGIN Constructors ----------------------------------------------------
985 
987  GeoContainerData() = default;
988 
990  GeoContainerData(size_type size) : fData(size) {}
991 
992  // Prepares the container with copies of the specified default value.
993  GeoContainerData(size_type size, value_type const& defValue) : fData(size, defValue) {}
994 
995  // --- END Constructors ------------------------------------------------------
996 
997  // --- BEGIN Container status query ------------------------------------------
1000 
1002  size_type size() const { return fData.size(); }
1003 
1005  size_type capacity() const { return fData.capacity(); }
1006 
1008  bool empty() const { return fData.empty(); }
1009 
1011  // --- END Container status query --------------------------------------------
1012 
1013  // --- BEGIN Data modification -----------------------------------------------
1021 
1024  void fill(value_type value) { std::fill(fData.begin(), fData.end(), value); }
1025 
1027  void reset() { fill(value_type{}); }
1028 
1040  template <typename Op>
1041  Op apply(Op&& op)
1042  {
1043  for (auto& data : fData)
1044  op(data);
1045  return op;
1046  }
1047 
1059  template <typename Op>
1060  Op apply(Op&& op) const
1061  {
1062  for (auto const& data : fData)
1063  op(data);
1064  return op;
1065  }
1066 
1068  // --- END Element access ----------------------------------------------------
1069 
1070  // --- BEGIN Container modification ------------------------------------------
1073 
1083  void resize(size_type size) { fData.resize(size); }
1084 
1095  void resize(size_type size, value_type const& defValue) { fData.resize(size, defValue); }
1096 
1103  void clear() { fData.clear(); }
1104 
1106  // --- END Container modification --------------------------------------------
1107 
1108  // --- BEGIN Element access --------------------------------------------------
1111 
1113  reference operator[](index_type index) { return fData[index]; }
1114 
1116  const_reference operator[](index_type index) const { return fData[index]; }
1117 
1119  // --- END Element access ----------------------------------------------------
1120 
1121  // --- BEGIN Iterators -------------------------------------------------------
1124 
1125  iterator begin() { return fData.begin(); }
1126  iterator end() { return fData.end(); }
1127  const_iterator begin() const { return fData.begin(); }
1128  const_iterator end() const { return fData.end(); }
1129  const_iterator cbegin() const { return fData.cbegin(); }
1130  const_iterator cend() const { return fData.cend(); }
1131 
1132  reverse_iterator rbegin() { return fData.rbegin(); }
1133  reverse_iterator rend() { return fData.rend(); }
1134  const_reverse_iterator rbegin() const { return fData.rbegin(); }
1135  const_reverse_iterator rend() const { return fData.rend(); }
1136  const_reverse_iterator crbegin() const { return fData.crbegin(); }
1137  const_reverse_iterator crend() const { return fData.crend(); }
1138 
1140  // --- END Iterators ---------------------------------------------------------
1141 
1143  template <typename Value, typename Upper>
1144  static bool bounded(Value v, Upper upper)
1145  {
1146  return (v >= 0) && (static_cast<size_type>(v) < upper);
1147  }
1148 
1149 private:
1151 
1152 }; // class geo::details::GeoContainerData
1153 
1154 //------------------------------------------------------------------------------
1155 //--- geo::GeoIDdataContainer
1156 //------------------------------------------------------------------------------
1157 template <typename T, typename Mapper>
1158 geo::GeoIDdataContainer<T, Mapper>::GeoIDdataContainer(std::initializer_list<unsigned int> dims)
1159  : fMapper(dims), fData(fMapper.size())
1160 {
1161  assert(!fData.empty());
1162 }
1163 
1164 //------------------------------------------------------------------------------
1165 template <typename T, typename Mapper>
1166 geo::GeoIDdataContainer<T, Mapper>::GeoIDdataContainer(std::initializer_list<unsigned int> dims,
1167  value_type const& defValue)
1168  : fMapper(dims), fData(fMapper.computeSize(), defValue)
1169 {
1170  assert(!fData.empty());
1171 }
1172 
1173 //------------------------------------------------------------------------------
1174 template <typename T, typename Mapper>
1176 {
1177  return fData.size();
1178 }
1179 
1180 //------------------------------------------------------------------------------
1181 template <typename T, typename Mapper>
1183 {
1184  return fData.capacity();
1185 }
1186 
1187 //------------------------------------------------------------------------------
1188 template <typename T, typename Mapper>
1190 {
1191  return fData.empty();
1192 }
1193 
1194 //------------------------------------------------------------------------------
1195 template <typename T, typename Mapper>
1196 template <std::size_t Level>
1198 {
1199  return mapper().template dimSize<Level>();
1200 }
1201 
1202 //------------------------------------------------------------------------------
1203 template <typename T, typename Mapper>
1205 {
1206  return Mapper_t::dimensions();
1207 }
1208 
1209 //------------------------------------------------------------------------------
1210 template <typename T, typename Mapper>
1211 template <typename GeoID>
1213 {
1214  return mapper().template hasElement<GeoID>(id);
1215 }
1216 
1217 //------------------------------------------------------------------------------
1218 template <typename T, typename Mapper>
1219 template <typename GeoID /* = ID_t */>
1221 {
1222  return mapper().template firstID<GeoID>();
1223 }
1224 
1225 //------------------------------------------------------------------------------
1226 template <typename T, typename Mapper>
1227 template <typename GeoID /* = ID_t */>
1229 {
1230  return mapper().template lastID<GeoID>();
1231 }
1232 
1233 //------------------------------------------------------------------------------
1234 template <typename T, typename Mapper>
1236 {
1237  return fMapper;
1238 }
1239 
1240 //------------------------------------------------------------------------------
1241 template <typename T, typename Mapper>
1243 {
1244  return fData[mapper().index(id)];
1245 }
1246 
1247 //------------------------------------------------------------------------------
1248 template <typename T, typename Mapper>
1250 {
1251  return fData[mapper().index(id)];
1252 }
1253 
1254 //------------------------------------------------------------------------------
1255 template <typename T, typename Mapper>
1257 {
1258  if (hasElement(id)) return operator[](id);
1259  throw std::out_of_range("No data for " + std::string(id));
1260 } // geo::GeoIDdataContainer<>::at()
1261 
1262 //------------------------------------------------------------------------------
1263 template <typename T, typename Mapper>
1265 {
1266  if (hasElement(id)) return operator[](id);
1267  throw std::out_of_range("No data for " + std::string(id));
1268 } // geo::GeoIDdataContainer<>::at() const
1269 
1270 //------------------------------------------------------------------------------
1271 template <typename T, typename Mapper>
1273 {
1274  return operator[](firstID());
1275 }
1276 
1277 //------------------------------------------------------------------------------
1278 template <typename T, typename Mapper>
1280 {
1281  return operator[](firstID());
1282 }
1283 
1284 //------------------------------------------------------------------------------
1285 template <typename T, typename Mapper>
1287 {
1288  return operator[](lastID());
1289 }
1290 
1291 //------------------------------------------------------------------------------
1292 template <typename T, typename Mapper>
1294 {
1295  return operator[](lastID());
1296 }
1297 
1298 //------------------------------------------------------------------------------
1299 template <typename T, typename Mapper>
1301 {
1302  return {mapper(), fData.begin(), fData.begin()};
1303 }
1304 
1305 //------------------------------------------------------------------------------
1306 template <typename T, typename Mapper>
1308 {
1309  return {mapper(), fData.begin(), fData.end()};
1310 }
1311 
1312 //------------------------------------------------------------------------------
1313 template <typename T, typename Mapper>
1315 {
1316  return {mapper(), fData.begin(), fData.begin()};
1317 }
1318 
1319 //------------------------------------------------------------------------------
1320 template <typename T, typename Mapper>
1322 {
1323  return {mapper(), fData.begin(), fData.end()};
1324 }
1325 
1326 //------------------------------------------------------------------------------
1327 template <typename T, typename Mapper>
1329 {
1330  return begin();
1331 }
1332 
1333 //------------------------------------------------------------------------------
1334 template <typename T, typename Mapper>
1336 {
1337  return end();
1338 }
1339 
1340 //------------------------------------------------------------------------------
1341 template <typename T, typename Mapper>
1343 {
1344  return {begin()};
1345 }
1346 
1347 //------------------------------------------------------------------------------
1348 template <typename T, typename Mapper>
1350 {
1351  return {end()};
1352 }
1353 
1354 //------------------------------------------------------------------------------
1355 template <typename T, typename Mapper>
1357 {
1358  return {begin()};
1359 }
1360 
1361 //------------------------------------------------------------------------------
1362 template <typename T, typename Mapper>
1364 {
1365  return {end()};
1366 }
1367 
1368 //------------------------------------------------------------------------------
1369 template <typename T, typename Mapper>
1371 {
1372  return item_begin();
1373 }
1374 
1375 //------------------------------------------------------------------------------
1376 template <typename T, typename Mapper>
1378 {
1379  return item_end();
1380 }
1381 
1382 //------------------------------------------------------------------------------
1383 template <typename T, typename Mapper>
1385 {
1386  return util::span{item_begin(), item_end()};
1387 }
1388 
1389 //------------------------------------------------------------------------------
1390 template <typename T, typename Mapper>
1392 {
1393  return util::span{item_begin(), item_end()};
1394 }
1395 
1396 //------------------------------------------------------------------------------
1397 template <typename T, typename Mapper>
1399 {
1400  fData.fill(value);
1401 }
1402 
1403 //------------------------------------------------------------------------------
1404 template <typename T, typename Mapper>
1406 {
1407  fData.reset();
1408 }
1409 
1410 //------------------------------------------------------------------------------
1411 template <typename T, typename Mapper>
1412 template <typename Op>
1414 {
1415  return fData.apply(std::forward<Op>(op));
1416 }
1417 
1418 //------------------------------------------------------------------------------
1419 template <typename T, typename Mapper>
1420 void geo::GeoIDdataContainer<T, Mapper>::resize(std::initializer_list<unsigned int> dims)
1421 {
1422  fMapper.resize(dims);
1423  fData.resize(mapper().size());
1424 } // geo::GeoIDdataContainer<T, Mapper>::resize()
1425 
1426 //------------------------------------------------------------------------------
1427 template <typename T, typename Mapper>
1428 void geo::GeoIDdataContainer<T, Mapper>::resize(std::initializer_list<unsigned int> dims,
1429  value_type const& defValue)
1430 {
1431  fMapper.resize(dims);
1432  fData.resize(mapper().size(), defValue);
1433 } // geo::GeoIDdataContainer<T, Mapper>::resize(value_type)
1434 
1435 //------------------------------------------------------------------------------
1436 template <typename T, typename Mapper>
1437 template <typename OT>
1440 {
1441  fMapper.resizeAs(other.mapper());
1442  fData.resize(mapper().size());
1443 } // geo::GeoIDdataContainer<T, Mapper>::resizeAs()
1444 
1445 //------------------------------------------------------------------------------
1446 template <typename T, typename Mapper>
1447 template <typename OT>
1450  value_type const& defValue)
1451 {
1452  fMapper.resizeAs(other.mapper());
1453  fData.resize(mapper().size(), defValue);
1454 } // geo::GeoIDdataContainer<T, Mapper>::resizeAs(value_type)
1455 
1456 //------------------------------------------------------------------------------
1457 template <typename T, typename Mapper>
1459 {
1460  fMapper.clear();
1461  fData.clear();
1462 } // geo::GeoIDdataContainer<>::clear()
1463 
1464 //------------------------------------------------------------------------------
1465 template <typename T, typename Mapper>
1466 template <typename Op>
1467 decltype(auto) geo::GeoIDdataContainer<T, Mapper>::apply(Op&& op) const
1468 {
1469  return fData.apply(std::forward<Op>(op));
1470 }
1471 
1472 //------------------------------------------------------------------------------
1473 template <typename T, typename Mapper>
1475 {
1476  return mapper().index(id);
1477 }
1478 
1479 //------------------------------------------------------------------------------
1480 template <typename T, typename Mapper>
1482 {
1483  return mapper().ID(index);
1484 }
1485 
1486 //------------------------------------------------------------------------------
1487 
1488 #endif // LARCOREALG_GEOMETRY_GEOMETRYDATACONTAINERS_H
void reset()
Sets all the elements to a default-constructed value_type.
typename Container_t::iterator iterator
intermediate_table::iterator iterator
Functor to extract an ID data member.
static bool bounded(Value v, Upper upper)
Returns whether the specified value is between 0 and the upper limit.
auto items()
Returns an object suitable for a range-for loop with item_iterator.
void resize(unsigned int nCryo, unsigned int nTPCs, T const &defValue)
Prepares the container initializing all its data.
Mapper_t const & mapper() const
Returns the mapper object used to convert ID&#39;s and container positions.
Item iterator for geo::GeoIDdataContainer class.
BaseIterator_t const & start() const
Returns the iterator to the begin element.
GeoID firstID() const
Returns the ID of the first element with GeoID type.
decltype(auto) constexpr cend(T &&obj)
ADL-aware version of std::cend.
Definition: StdUtils.h:93
reference at(ID_t const &id)
An object with a begin and end iterator.
const_reverse_iterator crend() const
const_reverse_iterator crbegin() const
GeoID lastID() const
Returns the ID of the last covered element with GeoID type.
typename Container_t::const_pointer const_pointer
iterator end()
Returns an iterator to past the end of the data.
Iterator for geo::GeoIDdataContainer class.
iterator_adaptor_::reference dereference() const
bool hasCryostat(geo::CryostatID const &cryoid) const
Returns whether this container hosts data for the specified cryostat.
size_type capacity() const
Returns the number of elements the container has memory for.
GeoIDdataContainerItemIterator(GeoIDiterator_t const &iter)
Constructor: points to data pointed by current.
size_type capacity() const
Returns the number of elements the container has memory for.
The data type to uniquely identify a Plane.
Definition: geo_types.h:463
Mapping between geometry/readout ID and flat index.
const_iterator cbegin() const
Returns a constant iterator to the beginning of the data.
TPCDataContainer(unsigned int nCryo, unsigned int nTPCs)
Prepares the container with default-constructed data.
reference last()
Returns the element for the last ID (unchecked).
typename Container_t::reverse_iterator reverse_iterator
STL namespace.
ExtraData_t fData
Data for extended features of this iterator.
intermediate_table::const_iterator const_iterator
ID_t ID() const
Returns the ID corresponding to the current element.
size_type index_type
Type used internally (so far) for indexing.
bool hasPlane(geo::PlaneID const &planeid) const
Returns whether this container hosts data for the specified plane.
Container with one element per geometry wire plane.
typename Container_t::const_reverse_iterator const_reverse_iterator
bool empty() const
Returns whether the container has no elements (false by assumptions).
void resize(size_type size, value_type const &defValue)
Prepares the container with copies of the specified default value.
Simple class with a begin and an end.
Definition: span.h:129
GeoIDdataContainerIterator(GeoIDdataContainerIterator< Mapper_t, OBaseIterator > const &other, std::enable_if_t< std::is_convertible_v< OBaseIterator, BaseIterator_t >>=nullptr)
Generalized copy constructor, only if argument iterator can be converted.
void resize(unsigned int nCryo, unsigned int nTPCs)
Prepares the container with default-constructed data.
GeoIDdataContainerItemIterator(GeoIDdataContainerItemIterator< OGeoIDIteratorClass > const &other, std::enable_if_t< std::is_convertible_v< OGeoIDIteratorClass, GeoIDiterator_t >>=nullptr)
Generalized copy constructor, only if argument iterator can be converted.
BaseIterator BaseIterator_t
Type of iterator to the actual data.
Op apply(Op &&op) const
Applies an operation on all elements.
Container with one element per geometry TPC.
item_const_iterator item_cbegin() const
Returns a item constant iterator to the beginning of the data.
void resize(unsigned int nCryo, unsigned int nTPCs, unsigned int nPlanes, T const &defValue)
Prepares the container initializing all its data.
decltype(auto) constexpr end(T &&obj)
ADL-aware version of std::end.
Definition: StdUtils.h:77
void reset()
Sets all the elements to a default-constructed value_type.
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:101
GeoContainerData(size_type size)
Prepares the container with default-constructed data.
ID_t ID(size_type const index) const
Returns the ID corresponding to a internal index in the storage area.
Container with one element per geometry TPC.
typename Mapper_t::ID_t ID_t
Type used as ID for this container.
size_type size() const
Returns the number of elements in the container.
bool hasCryostat(geo::CryostatID const &cryoid) const
Returns whether this container hosts data for the specified cryostat.
typename Container_t::difference_type difference_type
reference operator[](index_type index)
Returns the element for the specified index.
typename Container_t::size_type size_type
typename Mapper_t::index_type Index_t
Type of index in the container mapping.
typename BaseContainer_t::value_type value_type
typename Container_t::const_reference const_reference
GeoIDdataContainerIterator(Mapper_t const &mapper, BaseIterator_t const &start, BaseIterator_t const &current)
Constructor: points to data pointed by current.
item_iterator item_begin()
Returns an item iterator to the beginning of the data.
void fill(const art::PtrVector< recob::Hit > &hits, int only_plane)
typename Container_t::reference reference
The data type to uniquely identify a TPC.
Definition: geo_types.h:381
Definition of data types for geometry description.
const_reference operator[](index_type index) const
Returns the element for the specified index (read-only).
Mapping for TPC identifiers.
reference first()
Returns the element for the first ID (unchecked).
typename GeoIDiterator_t::ID_t ID_t
Type of the ID in this iterator.
double value
Definition: spectrum.C:18
const_reverse_iterator rend() const
reference operator[](ID_t const &id)
Returns the element for the specified geometry element.
Mapper Mapper_t
Type of mapper between IDs and index.
TPCDataContainer(unsigned int nCryo, unsigned int nTPCs, value_type const &defValue)
Prepares the container with copies of the specified default value.
GeoIDIteratorClass GeoIDiterator_t
Type of wrapped iterator.
bool hasTPC(geo::TPCID const &tpcid) const
Returns whether this container hosts data for the specified TPC.
item_iterator item_end()
Returns an item iterator to past the end of the data.
void clear()
Makes the container empty, with no usable storage space.
Op apply(Op &&op)
Applies an operation on all elements.
static constexpr unsigned int dimensions()
Dimensions of the ID of this container.
void fill(value_type value)
Sets all elements to the specified value (copied).
void resize(unsigned int nCryo, unsigned int nTPCs, unsigned int nPlanes)
Prepares the container with default-constructed data.
GeoContainerData(size_type size, value_type const &defValue)
typename Container_t::value_type value_type
typename Container_t::iterator BaseIter_t
Type of iterator to the data.
BaseIterator_t const & current() const
Returns the iterator to the current element.
typename Container_t::const_iterator BaseConstIter_t
Type of constant iterator to the data.
typename Container_t::const_iterator const_iterator
decltype(auto) constexpr cbegin(T &&obj)
ADL-aware version of std::cbegin.
Definition: StdUtils.h:85
bool hasTPC(geo::TPCID const &tpcid) const
Returns whether this container hosts data for the specified TPC.
typename BaseMapper_t::ID_t ID_t
PlaneDataContainer(unsigned int nCryo, unsigned int nTPCs, unsigned int nPlanes, T const &defValue)
Prepares the container with copies of the specified default value.
Mapper_t const & mapper() const
Returns the mapping of the container being iterated.
size_type index(ID_t const &id) const
Returns the internal index of the specified ID in the storage area.
decltype(auto) constexpr begin(T &&obj)
ADL-aware version of std::begin.
Definition: StdUtils.h:69
Index_t index() const
Returns the index of the current element.
void resize(size_type size)
Prepares the container with default-constructed data.
size_type size() const
Returns the number of elements in the container.
typename Container_t::pointer pointer
bool empty() const
Returns whether the container has no elements (false by assumptions).
PlaneDataContainer(unsigned int nCryo, unsigned int nTPCs, unsigned int nPlanes)
Prepares the container with default-constructed data.
void resizeAs(geo::GeoIDdataContainer< OT, Mapper_t > const &other)
Prepares the container with default-constructed data.
BaseIterator_t start
Iterator to the first element.
Namespace collecting geometry-related classes utilities.
unsigned int dimSize() const
Dimensions of the Level dimension of this container.
typename Mapper_t::ID_t ID_t
Type of the ID in this iterator.
typename GeoIDdataContainerItemIterator::iterator_adaptor_ iterator_adaptor_
void clear()
Makes the container empty, with no usable storage space.
GeoIDdataContainer()=default
Default constructor: container has no room at all.
Mapper_t fMapper
Mapping of IDs to indices.
Container_t fData
Data storage area.
Container_t fData
Data storage.
const_iterator cend() const
Returns a constant iterator to past the end of the data.
Op apply(Op &&op)
Applies an operation on all elements.
GeoIDmapperClass Mapper_t
< Type of mapping of the container this class iterates.
item_const_iterator item_cend() const
Returns a item constant iterator to past the end of the data.
vec_iX clear()
iterator begin()
Returns an iterator to the beginning of the data.
decltype(auto) constexpr empty(T &&obj)
ADL-aware version of std::empty.
Definition: StdUtils.h:109
void resize(std::initializer_list< unsigned int > dims)
Prepares the container with default-constructed data.
void fill(value_type value)
Sets all elements to the specified value (copied).
bool hasElement(GeoID const &id) const
Returns whether this container hosts data for the specified ID.
The data type to uniquely identify a cryostat.
Definition: geo_types.h:192
const_reverse_iterator rbegin() const
Mapper_t const * mapper
Mapping of the container being iterated.