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>
206 unsigned int dimSize()
const;
212 template <
typename GeoID>
213 bool hasElement(GeoID
const&
id)
const;
216 template <
typename GeoID = ID_t>
217 GeoID firstID()
const;
220 template <
typename GeoID = ID_t>
221 GeoID lastID()
const;
391 template <
typename Op>
407 template <
typename Op>
408 decltype(
auto) apply(Op&& op)
const;
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)
619 void resize(
unsigned int nCryo,
unsigned int nTPCs)
640 void resize(
unsigned int nCryo,
unsigned int nTPCs, T
const& 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,
777 void resize(
unsigned int nCryo,
unsigned int nTPCs,
unsigned int nPlanes)
802 unsigned int nCryo,
unsigned int nTPCs,
unsigned int nPlanes,
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(); }
887 using ID_t =
typename Mapper_t::ID_t;
900 , fData{ &mapper, start }
904 template <
typename OBaseIterator>
907 std::enable_if_t<std::is_convertible_v<OBaseIterator, BaseIterator_t>>
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
972 using ID_t =
typename GeoIDiterator_t::ID_t;
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)
1228 , fData(fMapper.
size())
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>
1319 if (hasElement(
id))
return operator[](
id);
1320 throw std::out_of_range(
"No data for " +
std::string(
id));
1325 template <
typename T,
typename Mapper>
1329 if (hasElement(
id))
return operator[](
id);
1330 throw std::out_of_range(
"No data for " +
std::string(
id));
1335 template <
typename T,
typename Mapper>
1337 {
return operator[](firstID()); }
1341 template <
typename T,
typename Mapper>
1343 {
return operator[](firstID()); }
1347 template <
typename T,
typename Mapper>
1349 {
return operator[](lastID()); }
1353 template <
typename T,
typename Mapper>
1355 {
return operator[](lastID()); }
1359 template <
typename T,
typename Mapper>
1361 {
return { mapper(), fData.
begin(), fData.
begin() }; }
1365 template <
typename T,
typename Mapper>
1367 {
return { mapper(), fData.
begin(), fData.
end() }; }
1371 template <
typename T,
typename Mapper>
1373 {
return { mapper(), fData.
begin(), fData.
begin() }; }
1377 template <
typename T,
typename Mapper>
1379 {
return { mapper(), fData.
begin(), fData.
end() }; }
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>
1424 {
return item_begin(); }
1428 template <
typename T,
typename Mapper>
1431 {
return item_end(); }
1435 template <
typename T,
typename Mapper>
1437 {
return util::span{ item_begin(), item_end() }; }
1441 template <
typename T,
typename Mapper>
1443 {
return util::span{ item_begin(), item_end() }; }
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>
1532 {
return mapper().ID(
index); }
1538 #endif // LARCOREALG_GEOMETRY_GEOMETRYDATACONTAINERS_H void reset()
Sets all the elements to a default-constructed value_type.
end
while True: pbar.update(maxval-len(onlies[E][S])) #print iS, "/", len(onlies[E][S]) found = False for...
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.
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
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(Vector< T > &vec1, Index n1, const V &val)
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.
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.
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.
QTextStream & reset(QTextStream &s)
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 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.
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.
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.
void resize(unsigned int nCryo, unsigned int nTPCsets)
Prepares the mapping for the specified sizes.
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.
vector< vector< double > > clear
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).
void resizeAs(geo::GeoIDdataContainer< OT, Mapper_t > const &other)
Prepares the container with default-constructed data.
BaseIterator_t & current()
LArSoft geometry interface.
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.
Container_t fData
Data storage area.
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< PlaneColl_t > Container_t
typename Container_t::reference reference
void clear()
Sets all dimension sizes to 0.