11 #ifndef LARDATA_RECOBASEPROXY_PROXYBASE_ASSOCIATEDDATA_H 12 #define LARDATA_RECOBASEPROXY_PROXYBASE_ASSOCIATEDDATA_H 32 #include <type_traits> 101 typename ValueType =
typename DataIter::value_type
112 using typename data_iterator_t::difference_type;
114 using pointer = std::add_pointer_t<value_type>;
115 using reference = std::add_lvalue_reference_t<value_type>;
127 { data_iterator_t::operator++();
return asIterator(); }
159 template <
typename Value>
166 {
return std::addressof(value); }
168 template <
typename Value>
170 {
return { std::forward<Value>(
value) }; }
181 template <std::
size_t N,
typename TupleIter>
182 class tuple_element_iterator:
184 tuple_element_iterator<N, TupleIter>,
186 std::tuple_element_t<N, typename TupleIter::value_type>
190 tuple_element_iterator<N, TupleIter>,
192 std::tuple_element_t<N, typename TupleIter::value_type>
196 using base_iterator_t::base_iterator_t;
199 tuple_element_iterator(base_iterator_t
const& from)
200 : base_iterator_t(from) {}
202 static auto transform(TupleIter
const& v) -> decltype(
auto)
203 {
return std::get<N>(*v); }
215 template <
typename ArtAssnsIterValue>
228 using main_t =
typename assns_node_traits_t::left_t;
231 using value_t =
typename assns_node_traits_t::right_t;
234 using data_t =
typename assns_node_traits_t::data_t;
237 using mainptr_t =
typename assns_node_traits_t::leftptr_t;
243 using dataptr_t =
typename assns_node_traits_t::dataptr_t;
278 template <
typename Node = node_t>
280 {
return lar::util::assns_has_metadata_v<Node>; }
283 template <
typename Node = node_t>
292 template <
typename Node = node_t>
297 data()
const {
return *dataPtr(); }
318 auto key()
const -> decltype(auto) {
return valuePtr().key(); }
321 auto id()
const -> decltype(auto) {
return valuePtr().id(); }
332 template <
typename ArtAssnsIterValue>
338 template <
typename ArtAssnsIterValue>
344 template <
typename ArtAssnsIterValue>
350 template <
typename ArtAssnsIterValue>
359 template <
typename ArtAssnsIterValue>
371 template <
typename ArtAssnsIterValue>
385 template <
typename ArtAssnsIter>
396 template <
typename ArtAssnsIter>
399 assns_node_iterator<ArtAssnsIter>,
401 typename AssnsIterTraits<ArtAssnsIter>::node_t
418 using base_iterator_t::base_iterator_t;
435 using main_t =
typename AssnsNode_t::main_t;
436 using value_t =
typename AssnsNode_t::value_t;
437 using data_t =
typename AssnsNode_t::data_t;
456 template <
typename Node = AssnsNode_t>
458 {
return lar::util::assns_has_metadata_v<Node>; }
461 template <
typename ArtNode = ArtAssnsNode_t>
463 {
return info().dataPtr(); }
466 template <
typename ArtNode = ArtAssnsNode_t>
468 hasMetadata<ArtNode>(),
472 {
return info().data(); }
508 template <
typename BoundaryIter>
514 {
return static_cast<BoundaryIter
const&
>(*this); }
523 {
return *(boundaryIter()); }
527 {
return *(std::next(boundaryIter())); }
533 template <
typename BoundaryIter>
573 template <
typename BoundaryIter>
575 (BoundaryIter
const& iBegin)
576 {
return { iBegin }; }
605 template <
typename BoundaryIter>
608 <BoundaryListRangeIterator<BoundaryIter>, BoundaryIter>
621 using pointer = std::add_pointer_t<std::decay_t<value_type>>;
622 using reference = std::add_lvalue_reference_t<std::decay_t<value_type>>;
625 using base_t::base_t;
668 template <
typename Iter>
689 : boundaries(
std::
move(boundaries))
690 { assert(this->boundaries.size() >= 1); }
694 {
return boundaries.size() - 1; }
697 {
return boundaries[
std::min(i, nRanges())]; }
700 {
return rangeBegin(i + 1); }
703 std::size_t
size()
const {
return nRanges(); }
706 {
return { boundaries.begin() }; }
709 {
return { std::prev(boundaries.end()) }; }
725 {
return { std::next(boundaries.begin(), i) }; }
778 typename Main,
typename Aux,
typename Metadata ,
809 {
return fGroups.begin(); }
813 {
return fGroups.end(); }
816 auto getRange(std::size_t i)
const -> decltype(
auto)
817 {
return util::makeTagged<tag>(fGroups.range(i)); }
824 "Inconsistent data types." 826 return getRange(
index);
830 template <
typename TestTag>
831 static constexpr
bool hasTag() {
return std::is_same<TestTag, tag>(); }
876 template <
typename Tag,
typename Assns>
879 template <
typename Assns>
881 {
return makeAssociatedData<typename Assns::right_t>(assns, minSize); }
901 template <
typename Tag,
typename MainColl,
typename Assns>
903 {
return makeAssociatedData<Tag>(assns, mainColl.size()); }
905 template <
typename MainColl,
typename Assns>
907 {
return makeAssociatedData<typename Assns::right_t>(mainColl, assns); }
927 template <std::
size_t GroupKey,
typename Iter>
931 constexpr
auto KeyIndex = GroupKey;
934 = [](
auto const& assn){
return std::get<KeyIndex>(assn).
key(); };
937 boundaries.reserve(expectedSize + 1);
938 boundaries.push_back(begin);
940 for (
auto it = begin; it !=
end; ++it) {
941 auto const key = extractKey(*it);
942 if (
key == current)
continue;
945 throw std::runtime_error(
"associationRanges() got input element #" 953 boundaries.push_back(end);
959 template <std::
size_t GroupKey,
typename Iter>
961 {
return associationRangesImpl<GroupKey, Iter>(
begin,
end); }
965 template <std::
size_t GroupKey,
typename Iter>
967 auto boundaries = associationRangesImpl<GroupKey, Iter>(
begin,
end,
n);
968 if (boundaries.size() <=
n) {
970 (boundaries.end(), n + 1 - boundaries.size(), boundaries.back());
971 assert(boundaries.size() == (n + 1));
1000 template <std::
size_t GroupKey,
typename Iter>
1004 (associationRangeBoundaries<GroupKey>(
begin,
end));
1025 template <std::
size_t GroupKey,
typename Iter>
1029 (associationRangeBoundaries<GroupKey>(
begin,
end,
n));
1039 template <
typename Tag,
typename Assns>
1042 using Main_t =
typename Assns::left_t;
1043 using Aux_t =
typename Assns::right_t;
1045 using AssociatedData_t
1052 auto ranges = details::associationRangeBoundaries<0U>
1053 (
begin(assns),
end(assns), minSize);
1056 using group_ranges_t =
typename AssociatedData_t::group_ranges_t;
1057 return AssociatedData_t(
1059 (
typename group_ranges_t::boundaries_t(
ranges.begin(),
ranges.end()))
1069 #endif // LARDATA_RECOBASEPROXY_PROXYBASE_ASSOCIATEDDATA_H
end
while True: pbar.update(maxval-len(onlies[E][S])) #print iS, "/", len(onlies[E][S]) found = False for...
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.
auto end() const -> decltype(auto)
Returns the end iterator of the range (next to the begin 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.
auto end() const -> decltype(auto)
Returns an iterator pointing past the last associated data range.
range_ref_t rangeRef(std::size_t i) const
Returns the specified range.
typename AssnsNode_t::main_t main_t
BoundaryList< Iter >::boundaries_t associationRangesImpl(Iter begin, Iter end, std::size_t expectedSize)
auto operator[](std::size_t index) const -> decltype(auto)
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.
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::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.
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.
Specializations of STL tuple utilities for art::AssnsNode.
std::add_lvalue_reference_t< std::decay_t< value_type >> reference
typename assns_node_traits_t::rightptr_t valueptr_t
Type of art pointer to the associated (right) object.
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
auto getRange(std::size_t i) const -> decltype(auto)
Returns the range with the specified index (no check performed).
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)
typename AssnsNode_t::valueptr_t valueptr_t
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.
auto begin() const -> decltype(auto)
Returns the begin iterator of the range.
Value box for use with pointer dereference operator->().
Traits for a association iterator.
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.
std::size_t nRanges() const
Returns the number of ranges contained in the list.
ArtAssnsIterValue node_t
Type of the wrapped node.
auto operator*() const -> decltype(auto)
Dereference operator; need to be redefined by derived classes.
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
BoundaryList(boundaries_t &&boundaries)
Constructor: steals the specified boundary list.
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.
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).
Data types for the specified association type (or its node).
IteratorWrapperBase()=default
Default constructor: default-constructs the underlying iterator.
auto begin() const -> decltype(auto)
Returns an iterator pointing to the first associated data range.
double distance(double x1, double y1, double z1, double x2, double y2, double z2)
std::vector< data_iterator_t > boundaries_t
static auto transform(data_iterator_t const &) -> decltype(auto)
Transforms and returns the value at the specified data iterator.
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.
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
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.
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.
auto operator->() const -> decltype(auto)
Dereference operator; need to be redefined by derived classes.
std::forward_iterator_tag iterator_category
AssociatedData(group_ranges_t &&groups)
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.
T min(sqlite3 *const db, std::string const &table_name, std::string const &column_name)
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.
auto operator[](std::size_t i) const -> decltype(auto)
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.
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()).
second_as<> second
Type of time stored in seconds, in double precision.
auto operator->() const -> decltype(auto)
Access the contained value via its pointer.
QuadExpr operator*(double v, const QuadExpr &e)
typename AssnsNode_t::dataptr_t dataptr_t
ArtAssnsIter art_assns_iter_t
std::string to_string(ModuleType const mt)
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.