11 #ifndef LARDATA_RECOBASEPROXY_PROXYBASE_ASSOCIATEDDATA_H 12 #define LARDATA_RECOBASEPROXY_PROXYBASE_ASSOCIATEDDATA_H 33 #include <type_traits> 96 template <
typename Iter,
typename DataIter,
typename ValueType =
typename DataIter::value_type>
106 using typename data_iterator_t::difference_type;
108 using pointer = std::add_pointer_t<value_type>;
109 using reference = std::add_lvalue_reference_t<value_type>;
122 data_iterator_t::operator++();
157 template <
typename Value>
163 auto operator->() const -> decltype(auto) {
return std::addressof(value); }
165 template <
typename Value>
168 return {std::forward<Value>(
value)};
179 template <std::
size_t N,
typename TupleIter>
180 class tuple_element_iterator:
182 tuple_element_iterator<N, TupleIter>,
184 std::tuple_element_t<N, typename TupleIter::value_type>
188 tuple_element_iterator<N, TupleIter>,
190 std::tuple_element_t<N, typename TupleIter::value_type>
194 using base_iterator_t::base_iterator_t;
197 tuple_element_iterator(base_iterator_t
const& from)
198 : base_iterator_t(from) {}
200 static auto transform(TupleIter
const& v) -> decltype(
auto)
201 {
return std::get<N>(*v); }
213 template <
typename ArtAssnsIterValue>
225 using main_t =
typename assns_node_traits_t::left_t;
228 using value_t =
typename assns_node_traits_t::right_t;
231 using data_t =
typename assns_node_traits_t::data_t;
234 using mainptr_t =
typename assns_node_traits_t::leftptr_t;
240 using dataptr_t =
typename assns_node_traits_t::dataptr_t;
275 template <
typename Node = node_t>
278 return lar::util::assns_has_metadata_v<Node>;
282 template <
typename Node = node_t>
293 template <
typename Node = node_t>
318 auto key() const -> decltype(auto) {
return valuePtr().key(); }
321 auto id() const -> decltype(auto) {
return valuePtr().id(); }
329 template <
typename ArtAssnsIterValue>
335 template <
typename ArtAssnsIterValue>
341 template <
typename ArtAssnsIterValue>
347 template <
typename ArtAssnsIterValue>
355 template <
typename ArtAssnsIterValue>
369 template <
typename ArtAssnsIterValue>
382 template <
typename ArtAssnsIter>
390 template <
typename ArtAssnsIter>
394 typename AssnsIterTraits<ArtAssnsIter>::node_t> {
407 using base_iterator_t::base_iterator_t;
423 using main_t =
typename AssnsNode_t::main_t;
424 using value_t =
typename AssnsNode_t::value_t;
425 using data_t =
typename AssnsNode_t::data_t;
444 template <
typename Node = AssnsNode_t>
447 return lar::util::assns_has_metadata_v<Node>;
451 template <
typename ArtNode = ArtAssnsNode_t>
454 return info().dataPtr();
458 template <
typename ArtNode = ArtAssnsNode_t>
459 std::enable_if_t<hasMetadata<ArtNode>(),
463 return info().data();
498 template <
typename BoundaryIter>
503 auto boundaryIter()
const {
return static_cast<BoundaryIter const&
>(*this); }
510 auto begin() const -> decltype(auto) {
return *(boundaryIter()); }
513 auto end() const -> decltype(auto) {
return *(std::next(boundaryIter())); }
518 template <
typename BoundaryIter>
554 template <
typename BoundaryIter>
586 template <
typename BoundaryIter>
598 using pointer = std::add_pointer_t<std::decay_t<value_type>>;
599 using reference = std::add_lvalue_reference_t<std::decay_t<value_type>>;
601 using base_t::base_t;
642 template <
typename Iter>
663 assert(this->boundaries.size() >= 1);
667 std::size_t
nRanges()
const {
return boundaries.size() - 1; }
671 return boundaries[std::min(i, nRanges())];
677 std::size_t
size()
const {
return nRanges(); }
717 auto operator[](std::size_t i)
const -> decltype(
auto) {
return range(i); }
748 template <
typename Main,
typename Aux,
typename Metadata ,
typename Tag
773 auto begin() const -> decltype(auto) {
return fGroups.begin(); }
776 auto end() const -> decltype(auto) {
return fGroups.end(); }
779 auto getRange(std::size_t i)
const -> decltype(
auto)
781 return util::makeTagged<tag>(fGroups.range(i));
787 static_assert(std::is_convertible<decltype(getRange(index)),
auxiliary_data_t>(),
788 "Inconsistent data types.");
789 return getRange(index);
793 template <
typename TestTag>
796 return std::is_same<TestTag, tag>();
841 template <
typename Tag,
typename Assns>
844 template <
typename Assns>
847 return makeAssociatedData<typename Assns::right_t>(assns, minSize);
867 template <
typename Tag,
typename MainColl,
typename Assns>
870 return makeAssociatedData<Tag>(assns, mainColl.size());
873 template <
typename MainColl,
typename Assns>
876 return makeAssociatedData<typename Assns::right_t>(mainColl, assns);
894 template <std::
size_t GroupKey,
typename Iter>
898 constexpr
auto KeyIndex = GroupKey;
900 auto extractKey = [](
auto const& assn) {
return std::get<KeyIndex>(assn).key(); };
903 boundaries.reserve(expectedSize + 1);
904 boundaries.push_back(begin);
905 std::size_t current = 0;
906 for (
auto it = begin; it !=
end; ++it) {
907 auto const key = extractKey(*it);
908 if (key == current)
continue;
910 auto index = std::distance(begin, it);
911 throw std::runtime_error(
912 "associationRanges() got input element #" +
std::to_string(index - 1) +
" with key " +
915 boundaries.insert(boundaries.
end(), key - current, it);
918 boundaries.push_back(end);
923 template <std::
size_t GroupKey,
typename Iter>
926 return associationRangesImpl<GroupKey, Iter>(
begin,
end);
930 template <std::
size_t GroupKey,
typename Iter>
933 auto boundaries = associationRangesImpl<GroupKey, Iter>(
begin,
end,
n);
934 if (boundaries.size() <=
n) {
935 boundaries.insert(boundaries.end(), n + 1 - boundaries.size(), boundaries.back());
936 assert(boundaries.size() == (n + 1));
964 template <std::
size_t GroupKey,
typename Iter>
988 template <std::
size_t GroupKey,
typename Iter>
999 template <
typename Tag,
typename Assns>
1002 using Main_t =
typename Assns::left_t;
1003 using Aux_t =
typename Assns::right_t;
1011 auto ranges = details::associationRangeBoundaries<0U>(
begin(assns),
end(assns), minSize);
1014 using group_ranges_t =
typename AssociatedData_t::group_ranges_t;
1015 return AssociatedData_t(
1016 group_ranges_t(
typename group_ranges_t::boundaries_t(
ranges.begin(),
ranges.end())));
1024 #endif // LARDATA_RECOBASEPROXY_PROXYBASE_ASSOCIATEDDATA_H
boundaries_t boundaries
Begin iterator of each range, plus end iterator of whole sequence.
IteratorWrapperBase(data_iterator_t const &from)
Copy-from-base constructor.
BoundaryIter boundary_iterator_t
Type of boundary iterator.
Provides features of a collections, from begin and end iterators.
Namespace for general, non-LArSoft-specific utilities.
decltype(makeBoundaryListRange(std::declval< boundary_iterator_t >())) rangeview_t
Type of range returned when dereferencing.
static AssnsNode_t const & transform(art_assns_iter_t const &v)
value_t const & value() const
Returns a reference to the associated value.
Builds and keeps track of internal boundaries in a sequence.
range_ref_t rangeRef(std::size_t i) const
Returns the specified range.
typename AssnsNode_t::main_t main_t
Returns the art pointer to the associated value.
BoundaryList< Iter >::boundaries_t associationRangesImpl(Iter begin, Iter end, std::size_t expectedSize)
auto operator*() const -> decltype(auto)
Dereference operator; need to be redefined by derived classes.
ArtAssnsIter data_iterator_t
main_t const & main() const
Returns the main value, key of the association.
AssnsNode< ArtAssnsIterValue > const & makeAssnsNode(ArtAssnsIterValue const &from)
Reinterprets the specified association node as a AssnsNode.
BoundaryIter boundary_iterator_t
bool operator==(AssnsNode< ArtAssnsIterValue > const &A, typename AssnsNode< ArtAssnsIterValue >::valueptr_t const &B)
data_iterator_t const & asDataIterator() const
BoundaryListRange(boundary_iterator_t const &iBegin)
Constructor: from an iterator to the begin iterator.
BoundaryListRange< BoundaryIter > makeBoundaryListRange(BoundaryIter const &iBegin)
Reinterprets a iterator to boundaries list as a range collection.
typename assns_node_traits_t::leftptr_t mainptr_t
Type of art pointer to the main (left) object in the association.
auto boundaryIter() const
Returns the iterator to the begin iterator.
auto begin() const -> decltype(auto)
Returns an iterator pointing to the first associated data range.
auto getRange(std::size_t i) const -> decltype(auto)
Returns the range with the specified index (no check performed).
std::add_pointer_t< value_type > pointer
typename assns_node_traits_t::right_t value_t
Type of the associated (right) object.
iterator const & asIterator() const
std::add_lvalue_reference_t< value_type > reference
typename range_iterator_t::value_type range_ref_t
Structure holding begin and end iterator for a single range.
valueptr_t operator->() const
Returns the associated value (alias of valuePtr()).
Specializations of STL tuple utilities for art::AssnsNode.
std::add_lvalue_reference_t< std::decay_t< value_type >> reference
decltype(makeCollectionView(std::declval< BeginIter >(), std::declval< EndIter >())) RangeAsCollection_t
Type of collection view owning the two range boundary iterators.
typename assns_node_traits_t::rightptr_t valueptr_t
Type of art pointer to the associated (right) object.
std::enable_if_t< hasMetadata< ArtNode >), typename lar::util::assns_traits< ArtNode >::data_t const & > data() const
Returns a reference to the metadata on this association node.
data_iterator_t const & rangeBegin(std::size_t i) const
Returns the begin iterator of the i-th range (end if overflow).
BoundaryListRangeBase(boundary_iterator_t const &it)
Constructor: copies the specified base iterator.
typename AssnsNode_t::value_t value_t
Returns the art pointer to the associated value.
range_iterator_t begin() const
Returns the begin iterator of the first range.
ValuePtr(Value const &value)
static this_t const & makeFrom(node_t const &from)
Reinterprets the specified association node as a AssnsNode.
auto associationRangeBoundaries(Iter begin, Iter end)
decltype(auto) constexpr end(T &&obj)
ADL-aware version of std::end.
typename AssnsNode_t::valueptr_t valueptr_t
Returns the art pointer to the associated value.
valueptr_t const & valuePtr() const
Returns the art pointer to the associated value.
Object to draft associated data interface.
A BoundaryListRangeBase with a full container interface.
std::size_t size() const
Returns the number of ranges contained in the list.
static constexpr bool hasMetadata()
Returns whether this node type supports metadata.
Value box for use with pointer dereference operator->().
Tag tag
Tag of this association proxy.
Traits for a association iterator.
auto end() const -> decltype(auto)
Returns the end iterator of the range (next to the begin iterator).
std::size_t nRanges() const
Returns the number of ranges contained in the list.
decltype(auto) constexpr to_string(T &&obj)
ADL-aware version of std::to_string.
ArtAssnsIterValue node_t
Type of the wrapped node.
auto operator[](std::size_t i) const -> decltype(auto)
auto operator[](std::size_t index) const -> decltype(auto)
Returns the range with the specified index (no check performed).
main_t const & main() const
Returns the main value, key of the association.
AssnsNode_t const & info() const
Returns the full information the iterator points to.
typename ArtAssnsIter::value_type art_node_t
std::add_pointer_t< std::decay_t< value_type >> pointer
typename AssnsNode_t::mainptr_t mainptr_t
Returns the art pointer to the associated value.
BoundaryList(boundaries_t &&boundaries)
Constructor: steals the specified boundary list.
Encloses LArSoft data product proxy objects and utilities.See this doxygen module for an introduction...
Simple iterator wrapper for manipulation of dereferenced result.
mainptr_t mainPtr() const
Returns the art pointer to the main value, key of the association.
assns_node_iterator(base_iterator_t const &from)
Constructor from a base iterator (explicitly allowed).
auto id() const -> decltype(auto)
Returns the product ID of the art pointer to the value.
util::add_tag_t< typename group_ranges_t::range_t, tag > auxiliary_data_t
Type of collection of auxiliary data associated with a main item.
Value value
Value to return the address of (may be reference).
auto end() const -> decltype(auto)
Returns an iterator pointing past the last associated data range.
Data types for the specified association type (or its node).
IteratorWrapperBase()=default
Default constructor: default-constructs the underlying iterator.
std::vector< data_iterator_t > boundaries_t
BoundaryIter boundary_iterator_t
valueptr_t valuePtr() const
Returns the art pointer to the associated value.
typename assns_node_traits_t::left_t main_t
Type of the main (left) object in the association.
lar::RangeAsCollection_t< data_iterator_t > range_t
Range object directly containing the boundary iterators.
auto operator->() const -> decltype(auto)
Access the contained value via its pointer.
mainptr_t const & mainPtr() const
Returns the art pointer to the main value, key of the association.
iterator & operator++()
Prefix increment operator.
std::enable_if_t< hasMetadata< Node >), dataptr_t > dataPtr() const
Returns the pointer to the metadata on this association node.
Provides the features of a collections, from begin and end iterators.
static constexpr bool hasMetadata()
Returns whether this node type supports metadata.
auto makeCollectionView(BeginIter const &b, EndIter const &e)
Creates a CollectionView from the specified iterators.
typename AssnsNode_t::data_t data_t
Returns the art pointer to the associated value.
static ValuePtr< Value > makeValuePointer(Value &&value)
std::enable_if_t< hasMetadata< ArtNode >), dataptr_t > dataPtr() const
Returns the pointer to the metadata on this association node.
std::enable_if_t< hasMetadata< Node >), typename lar::util::assns_traits< Node >::data_t const & > data() const
Returns a reference to the metadata on this association node.
typename traits_t::node_t AssnsNode_t
Type of node for this association iterator.
bool operator!=(iterator const &other) const
Comparison with another iterator.
This type extends the interface of the art pointer to Assns right side.
value_t const & value() const
Returns the art pointer to the associated value.
AssnsNode_t const & operator()() const
Returns the full information the iterator points to.
std::forward_iterator_tag iterator_category
AssociatedData(group_ranges_t &&groups)
static auto transform(data_iterator_t const &) -> decltype(auto)
Transforms and returns the value at the specified data iterator.
range_iterator_t end() const
Returns the end iterator of the last range.
typename assns_node_traits_t::data_t data_t
Type of the associated additional data (void if none).
typename assns_node_traits_t::dataptr_t dataptr_t
Type of the pointer to associated additional data.
LArSoft-specific namespace.
range_t range(std::size_t i) const
Returns the specified range in an object holding the iterators.
bool operator!=(data_iterator_t const &other) const
Comparison with a data iterator (makes unnecessary to wrap end iterators).
Iterator exposing elements of a boundary list as ranges.
Utilities to address elements of a tuple-like class by tag.
auto makeAssociatedData(Assns const &assns, std::size_t minSize=0)
Processes and returns an associated data object.
typename traits_t::art_node_t ArtAssnsNode_t
Traits for art associations.
static constexpr bool hasTag()
Returns whether this data is labeled with the specified tag.
data_iterator_t const & rangeEnd(std::size_t i) const
Returns the end iterator of the i-th range (end if overflow).
decltype(auto) constexpr begin(T &&obj)
ADL-aware version of std::begin.
auto operator->() const -> decltype(auto)
Dereference operator; need to be redefined by derived classes.
ArtAssnsIterValue base_t
Base class type.
associated_data_iterator_t data_iterator_t
value_t const & operator*() const
Returns a reference to the associated value (alias of value()).
auto operator[](std::size_t index) const -> decltype(auto)
second_as<> second
Type of time stored in seconds, in double precision.
QuadExpr operator*(double v, const QuadExpr &e)
typename AssnsNode_t::dataptr_t dataptr_t
Returns the art pointer to the associated value.
ArtAssnsIter art_assns_iter_t
static auto transform(BoundaryIter const &iter)
Returns the pointed range.
BoundaryList< Iter > associationRanges(Iter begin, Iter end)
Groups associations by the first key.
auto key() const -> decltype(auto)
Returns the key of the art pointer to the value.
auto begin() const -> decltype(auto)
Returns the begin iterator of the range.