11 #ifndef LARCOREALG_GEOMETRY_GEOMETRYDATACONTAINERS_H 12 #define LARCOREALG_GEOMETRY_GEOMETRYDATACONTAINERS_H 20 #include <boost/iterator/iterator_adaptor.hpp> 21 #include <boost/iterator/transform_iterator.hpp> 26 #include <initializer_list> 34 template <
typename T,
typename Mapper>
49 template <
typename GeoIDdataContainerClass,
typename BaseIterator>
52 template <
typename GeoIDIteratorClass>
100 template <
typename T,
typename Mapper>
116 template <
typename Obj>
117 decltype(
auto) operator()(Obj&& obj)
const 201 template <std::
size_t Level>
202 unsigned int dimSize()
const;
205 static constexpr
unsigned int dimensions();
208 template <
typename GeoID>
209 bool hasElement(GeoID
const&
id)
const;
212 template <
typename GeoID = ID_t>
213 GeoID firstID()
const;
216 template <
typename GeoID = ID_t>
217 GeoID lastID()
const;
381 template <
typename Op>
397 template <
typename Op>
398 decltype(
auto) apply(Op&& op) const;
420 void resize(
std::initializer_list<
unsigned int> dims);
436 void resize(
std::initializer_list<
unsigned int> dims,
value_type const& defValue);
449 template <typename OT>
464 template <typename OT>
526 template <typename T>
590 void resize(
unsigned int nCryo,
unsigned int nTPCs) { BaseContainer_t::resize({nCryo, nTPCs}); }
610 void resize(
unsigned int nCryo,
unsigned int nTPCs, T
const& defValue)
612 BaseContainer_t::resize({nCryo, nTPCs}, defValue);
625 return BaseContainer_t::hasElement(cryoid);
670 template <
typename T>
719 unsigned int nPlanes,
742 void resize(
unsigned int nCryo,
unsigned int nTPCs,
unsigned int nPlanes)
744 BaseContainer_t::resize({nCryo, nTPCs, nPlanes});
768 void resize(
unsigned int nCryo,
unsigned int nTPCs,
unsigned int nPlanes, T
const& defValue)
770 BaseContainer_t::resize({nCryo, nTPCs, nPlanes}, defValue);
783 return BaseContainer_t::hasElement(cryoid);
805 template <
typename GeoIDmapperClass,
typename BaseIterator>
807 :
public boost::iterator_adaptor<
808 geo::details::GeoIDdataContainerIterator<GeoIDmapperClass, BaseIterator>,
817 using Index_t =
typename Mapper_t::index_type;
833 return GeoIDdataContainerIterator::iterator_adaptor_::base();
851 using ID_t =
typename Mapper_t::ID_t;
864 template <
typename OBaseIterator>
867 std::enable_if_t<std::is_convertible_v<OBaseIterator, BaseIterator_t>> =
nullptr)
872 ID_t ID()
const {
return mapper().ID(index()); }
889 template <
typename GeoIDIteratorClass>
891 :
public boost::iterator_adaptor<geo::details::GeoIDdataContainerItemIterator<GeoIDIteratorClass>,
893 std::pair<typename GeoIDIteratorClass::ID_t,
894 typename GeoIDIteratorClass::reference>
898 std::pair<typename GeoIDIteratorClass::ID_t,
899 typename GeoIDIteratorClass::reference>
921 using ID_t =
typename GeoIDiterator_t::ID_t;
930 template <
typename OGeoIDIteratorClass>
933 std::enable_if_t<std::is_convertible_v<OGeoIDIteratorClass, GeoIDiterator_t>> =
nullptr)
938 friend class boost::iterator_core_access;
940 using iterator_adaptor_::base;
942 typename iterator_adaptor_::reference
dereference()
const {
return {base().ID(), *base()}; }
957 template <
typename T>
970 using pointer =
typename Container_t::pointer;
1008 bool empty()
const {
return fData.empty(); }
1040 template <
typename Op>
1043 for (
auto& data : fData)
1059 template <
typename Op>
1062 for (
auto const& data : fData)
1143 template <
typename Value,
typename Upper>
1146 return (v >= 0) && (
static_cast<size_type>(v) < upper);
1157 template <
typename T,
typename Mapper>
1159 : fMapper(dims), fData(fMapper.
size())
1165 template <
typename T,
typename Mapper>
1174 template <
typename T,
typename Mapper>
1181 template <
typename T,
typename Mapper>
1188 template <
typename T,
typename Mapper>
1195 template <
typename T,
typename Mapper>
1196 template <std::
size_t Level>
1199 return mapper().template dimSize<Level>();
1203 template <
typename T,
typename Mapper>
1206 return Mapper_t::dimensions();
1210 template <
typename T,
typename Mapper>
1211 template <
typename GeoID>
1214 return mapper().template hasElement<GeoID>(id);
1218 template <
typename T,
typename Mapper>
1219 template <
typename GeoID >
1222 return mapper().template firstID<GeoID>();
1226 template <
typename T,
typename Mapper>
1227 template <
typename GeoID >
1230 return mapper().template lastID<GeoID>();
1234 template <
typename T,
typename Mapper>
1241 template <
typename T,
typename Mapper>
1248 template <
typename T,
typename Mapper>
1255 template <
typename T,
typename Mapper>
1259 throw std::out_of_range(
"No data for " + std::string(
id));
1263 template <
typename T,
typename Mapper>
1267 throw std::out_of_range(
"No data for " + std::string(
id));
1271 template <
typename T,
typename Mapper>
1278 template <
typename T,
typename Mapper>
1285 template <
typename T,
typename Mapper>
1292 template <
typename T,
typename Mapper>
1299 template <
typename T,
typename Mapper>
1306 template <
typename T,
typename Mapper>
1313 template <
typename T,
typename Mapper>
1320 template <
typename T,
typename Mapper>
1327 template <
typename T,
typename Mapper>
1334 template <
typename T,
typename Mapper>
1341 template <
typename T,
typename Mapper>
1348 template <
typename T,
typename Mapper>
1355 template <
typename T,
typename Mapper>
1362 template <
typename T,
typename Mapper>
1369 template <
typename T,
typename Mapper>
1376 template <
typename T,
typename Mapper>
1383 template <
typename T,
typename Mapper>
1390 template <
typename T,
typename Mapper>
1397 template <
typename T,
typename Mapper>
1404 template <
typename T,
typename Mapper>
1411 template <
typename T,
typename Mapper>
1412 template <
typename Op>
1419 template <
typename T,
typename Mapper>
1427 template <
typename T,
typename Mapper>
1436 template <
typename T,
typename Mapper>
1437 template <
typename OT>
1446 template <
typename T,
typename Mapper>
1447 template <
typename OT>
1457 template <
typename T,
typename Mapper>
1465 template <
typename T,
typename Mapper>
1466 template <
typename Op>
1473 template <
typename T,
typename Mapper>
1476 return mapper().index(
id);
1480 template <
typename T,
typename Mapper>
1488 #endif // LARCOREALG_GEOMETRY_GEOMETRYDATACONTAINERS_H void reset()
Sets all the elements to a default-constructed value_type.
typename Container_t::iterator iterator
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.
typename Container_t::const_reference const_reference
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'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.
reference at(ID_t const &id)
An object with a begin and end iterator.
const_reverse_iterator crend() const
const_iterator cend() 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.
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
ExtraData_t fData
Data for extended features of this 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.
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.
void reset()
Sets all the elements to a default-constructed value_type.
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
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.
const_iterator end() const
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.
const_iterator begin() const
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 ¤t)
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.
reverse_iterator rbegin()
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.
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.
typename Container_t::pointer pointer
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.
const_iterator cbegin() const
BaseIterator_t const & current() const
Returns the iterator to the current element.
typename Container_t::difference_type difference_type
typename Container_t::const_iterator BaseConstIter_t
Type of constant iterator to the data.
typename Container_t::const_iterator const_iterator
typename Container_t::const_pointer const_pointer
decltype(auto) constexpr cbegin(T &&obj)
ADL-aware version of std::cbegin.
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.
typename Container_t::size_type size_type
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.
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 & current()
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.
typename Container_t::value_type value_type
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.
iterator begin()
Returns an iterator to the beginning of the data.
decltype(auto) constexpr empty(T &&obj)
ADL-aware version of std::empty.
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.
const_reverse_iterator rbegin() const
std::vector< T > Container_t
typename Container_t::reference reference