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>
25 #include <initializer_list>
35 template <
typename T,
typename Mapper>
50 template <
typename GeoIDdataContainerClass,
typename BaseIterator>
53 template <
typename GeoIDIteratorClass>
102 template <
typename T,
typename Mapper>
118 template <
typename Obj>
119 decltype(
auto) operator()(Obj&& obj)
const {
return obj.ID(); }
186 std::initializer_list<unsigned int> dims,
205 template <std::
size_t Level>
212 template <
typename GeoID>
216 template <
typename GeoID = ID_t>
220 template <
typename GeoID = ID_t>
391 template <
typename Op>
407 template <
typename Op>
431 void resize(
std::initializer_list<
unsigned int> dims);
448 (
std::initializer_list<
unsigned int> dims,
value_type const& defValue);
462 template <typename OT>
477 template <typename OT>
548 template <typename T>
598 (
unsigned int nCryo,
unsigned int nTPCs,
value_type const& defValue)
599 : BaseContainer_t({ nCryo, nTPCs }, defValue)
619 void resize(
unsigned int nCryo,
unsigned int nTPCs)
620 { BaseContainer_t::resize({ nCryo, nTPCs }); }
640 void resize(
unsigned int nCryo,
unsigned int nTPCs, T
const& defValue)
641 { BaseContainer_t::resize({ nCryo, nTPCs }, defValue); }
653 {
return BaseContainer_t::hasElement(cryoid); }
657 {
return BaseContainer_t::hasElement(tpcid); }
700 template <
typename T>
731 (
unsigned int nCryo,
unsigned int nTPCs,
unsigned int nPlanes)
752 unsigned int nCryo,
unsigned int nTPCs,
unsigned int nPlanes,
755 : BaseContainer_t{ { nCryo, nTPCs, nPlanes }, defValue }
777 void resize(
unsigned int nCryo,
unsigned int nTPCs,
unsigned int nPlanes)
778 { BaseContainer_t::resize({ nCryo, nTPCs, nPlanes }); }
802 unsigned int nCryo,
unsigned int nTPCs,
unsigned int nPlanes,
805 { BaseContainer_t::resize({ nCryo, nTPCs, nPlanes }, defValue); }
817 {
return BaseContainer_t::hasElement(cryoid); }
821 {
return BaseContainer_t::hasElement(tpcid); }
825 {
return BaseContainer_t::hasElement(planeid); }
842 template <
typename GeoIDmapperClass,
typename BaseIterator>
844 :
public boost::iterator_adaptor<
845 geo::details::GeoIDdataContainerIterator<GeoIDmapperClass, BaseIterator>
856 using Index_t =
typename Mapper_t::index_type;
871 {
return GeoIDdataContainerIterator::iterator_adaptor_::base(); }
873 {
return GeoIDdataContainerIterator::iterator_adaptor_::base(); }
880 { assert(fData.mapper);
return *(fData.mapper); }
904 template <
typename OBaseIterator>
934 template <
typename GeoIDIteratorClass>
936 :
public boost::iterator_adaptor<
937 geo::details::GeoIDdataContainerItemIterator<GeoIDIteratorClass>
940 typename GeoIDIteratorClass::ID_t,
941 typename GeoIDIteratorClass::reference
945 typename GeoIDIteratorClass::ID_t,
946 typename GeoIDIteratorClass::reference
984 template <
typename OGeoIDIteratorClass>
987 std::enable_if_t<std::is_convertible_v<OGeoIDIteratorClass, GeoIDiterator_t>>
995 friend class boost::iterator_core_access;
997 using iterator_adaptor_::base;
1000 {
return { base().ID(), *base() }; }
1019 template <
typename T>
1058 : fData(size, defValue) {}
1108 template <
typename Op>
1110 {
for (
auto& data: fData) op(data);
return op; }
1123 template <
typename Op>
1125 {
for (
auto const& data: fData) op(data);
return op; }
1158 { fData.
resize(size, defValue); }
1210 template <
typename Value,
typename Upper>
1212 {
return (v >= 0) && (
static_cast<size_type>(v) < upper); }
1224 template <
typename T,
typename Mapper>
1226 (std::initializer_list<unsigned int> dims)
1230 assert(!fData.
empty());
1235 template <
typename T,
typename Mapper>
1237 (std::initializer_list<unsigned int> dims,
value_type const& defValue)
1239 ,
fData(fMapper.computeSize(), defValue)
1241 assert(!fData.
empty());
1246 template <
typename T,
typename Mapper>
1248 {
return fData.
size(); }
1252 template <
typename T,
typename Mapper>
1258 template <
typename T,
typename Mapper>
1260 {
return fData.
empty(); }
1264 template <
typename T,
typename Mapper>
1265 template <std::
size_t Level>
1267 {
return mapper().template dimSize<Level>(); }
1271 template <
typename T,
typename Mapper>
1277 template <
typename T,
typename Mapper>
1278 template <
typename GeoID>
1280 {
return mapper().template hasElement<GeoID>(id); }
1284 template <
typename T,
typename Mapper>
1285 template <
typename GeoID >
1287 {
return mapper().template firstID<GeoID>(); }
1291 template <
typename T,
typename Mapper>
1292 template <
typename GeoID >
1294 {
return mapper().template lastID<GeoID>(); }
1298 template <
typename T,
typename Mapper>
1304 template <
typename T,
typename Mapper>
1306 {
return fData[
mapper().index(
id)]; }
1310 template <
typename T,
typename Mapper>
1313 {
return fData[
mapper().index(
id)]; }
1317 template <
typename T,
typename Mapper>
1320 throw std::out_of_range(
"No data for " + std::string(
id));
1325 template <
typename T,
typename Mapper>
1330 throw std::out_of_range(
"No data for " + std::string(
id));
1335 template <
typename T,
typename Mapper>
1341 template <
typename T,
typename Mapper>
1347 template <
typename T,
typename Mapper>
1353 template <
typename T,
typename Mapper>
1359 template <
typename T,
typename Mapper>
1365 template <
typename T,
typename Mapper>
1371 template <
typename T,
typename Mapper>
1377 template <
typename T,
typename Mapper>
1383 template <
typename T,
typename Mapper>
1389 template <
typename T,
typename Mapper>
1395 template <
typename T,
typename Mapper>
1397 {
return {
begin() }; }
1401 template <
typename T,
typename Mapper>
1403 {
return {
end() }; }
1407 template <
typename T,
typename Mapper>
1410 {
return {
begin() }; }
1414 template <
typename T,
typename Mapper>
1417 {
return {
end() }; }
1421 template <
typename T,
typename Mapper>
1428 template <
typename T,
typename Mapper>
1435 template <
typename T,
typename Mapper>
1441 template <
typename T,
typename Mapper>
1447 template <
typename T,
typename Mapper>
1449 { fData.
fill(value); }
1453 template <
typename T,
typename Mapper>
1459 template <
typename T,
typename Mapper>
1460 template <
typename Op>
1462 {
return fData.
apply(std::forward<Op>(op)); }
1466 template <
typename T,
typename Mapper>
1468 (std::initializer_list<unsigned int> dims)
1476 template <
typename T,
typename Mapper>
1478 (std::initializer_list<unsigned int> dims,
value_type const& defValue)
1486 template <
typename T,
typename Mapper>
1487 template <
typename OT>
1497 template <
typename T,
typename Mapper>
1498 template <
typename OT>
1508 template <
typename T,
typename Mapper>
1516 template <
typename T,
typename Mapper>
1517 template <
typename Op>
1519 {
return fData.
apply(std::forward<Op>(op)); }
1523 template <
typename T,
typename Mapper>
1526 {
return mapper().index(
id); }
1530 template <
typename T,
typename Mapper>
1538 #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
double std(const std::vector< short > &wf, const double ped_mean, size_t start, size_t nsample)
Mapper_t const & mapper() const
Returns the mapper object used to convert ID's and container positions.
BaseIterator_t const & start() const
Returns the iterator to the begin element.
Item iterator for geo::GeoIDdataContainer class.
GeoID firstID() const
Returns the ID of the first element with GeoID type.
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.
index_type size() const
Returns the number of elements in the mapping.
Iterator for geo::GeoIDdataContainer class.
void resizeAs(geo::GeoIDmapper< OIDType, OIndex > const &other)
Resizes the mapping to reflect the one from another mapping.
iterator_adaptor_::reference dereference() const
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.
GeoIDmapperClass Mapper_t
< Type of mapping of the container this class iterates.
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.
void resize(unsigned int nCryo, unsigned int nTPCs, unsigned int nPlanes)
Prepares the mapping for the specified sizes.
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
Mapper_t const & mapper() const
Returns the mapping of the container being iterated.
size_type index_type
Type used internally (so far) for indexing.
Index_t index() const
Returns the index of the current element.
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.
typename Mapper_t::ID_t ID_t
Type of the ID in this iterator.
Simple class with a begin and an end.
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.
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 reset()
Sets all the elements to a default-constructed value_type.
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
typename Container_t::difference_type difference_type
GeoIDdataContainerIterator(Mapper_t const &mapper, BaseIterator_t const &start, BaseIterator_t const ¤t)
Constructor: points to data pointed by current.
reference operator[](index_type index)
Returns the element for the specified index.
const_iterator begin() const
typename Container_t::size_type size_type
typename std::enable_if< B, T >::type enable_if_t
typename Container_t::const_reference const_reference
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.
typename Container_t::pointer pointer
GeoIDIteratorClass GeoIDiterator_t
Type of wrapped iterator.
item_iterator item_end()
Returns an item iterator to past the end of the data.
typename Mapper_t::index_type Index_t
Type of index in the container mapping.
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).
BaseIterator_t const & current() const
Returns the iterator to the current element.
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 & current()
const_iterator cbegin() const
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
BaseIterator BaseIterator_t
Type of iterator to the actual data.
typename Container_t::const_pointer const_pointer
size_t ID_t
Index used to identify Flash_t/QPointCollection_t uniquely in an event.
typename Container_t::size_type size_type
size_type index(ID_t const &id) const
Returns the internal index of the specified ID in the storage area.
void resize(size_type size)
Prepares the container with default-constructed data.
size_type size() const
Returns the number of elements in the container.
ExtraData_t fData
Data for extended features of this iterator.
typename Container_t::pointer pointer
bool empty() const
Returns whether the container has no elements (false by assumptions).
void resizeAs(geo::GeoIDdataContainer< OT, Mapper_t > const &other)
Prepares the container with default-constructed data.
unsigned int dimSize() const
Dimensions of the Level dimension of this container.
typename GeoIDdataContainerItemIterator::iterator_adaptor_ iterator_adaptor_
void clear()
Makes the container empty, with no usable storage space.
typename Container_t::value_type value_type
ID_t ID() const
Returns the ID corresponding to the current element.
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.
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.
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.
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< icarus::ICARUSChannelMapAlg::PlaneInfo_t > Container_t
typename Container_t::reference reference
void clear()
Sets all dimension sizes to 0.