LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
geo::part::SortedPartition< Data, Sorter > Class Template Referenceabstract

Partition of area sorted across a dimension. More...

#include "Partitions.h"

Inheritance diagram for geo::part::SortedPartition< Data, Sorter >:
geo::part::PartitionContainer< Data > geo::part::PartitionWithData< Data > geo::part::Partition< Data > geo::part::PartitionBase geo::part::AreaOwner

Public Types

using Base_t = PartitionContainer< Data >
 Base class. More...
 
using Partition_t = Partition< Data >
 Base type of the partition. More...
 
using Sorter_t = Sorter
 Type of sorter being used. More...
 
using Data_t = typename Partition_t::Data_t
 
using Area_t = typename Partition_t::Area_t
 
using Subpartitions_t = typename Base_t::Subpartitions_t
 
using AreaRangeMember_t = AreaOwner::AreaRangeMember_t
 

Public Member Functions

 SortedPartition (Area_t const &area, Subpartitions_t &&subpartitions, Data_t *defData=nullptr, Sorter_t sorter={})
 Constructor: sets the partition. More...
 
virtual Data_tatPoint (double w, double d) const override
 Returns stored datum only if point is covered, nullptr otherwise. More...
 
virtual Data_tdata () const override
 Returns the datum directly stored (nullptr if none). More...
 
std::string describe (std::string indent, std::string firstIndent) const
 Returns a description of the partition. More...
 
std::string describe (std::string indent="") const
 Returns a description of the partition. More...
 
template<typename Pred >
void walk (Pred &&pred) const
 Applies pred to all partitions. More...
 
std::size_t nParts () const
 Returns the number of subparts in the partition (0 if simple element). More...
 
bool contains (double w, double d) const
 Returns whether the specified point is covered by this object. More...
 
Area_t const & area () const
 Returns the covered area. More...
 
template<typename Stream >
void dumpArea (Stream &&out) const
 Output the owned area into an output stream. More...
 

Protected Member Functions

Partition_t const * findPartWithKey (double key) const
 Returns the only partition which could contain the specified key. More...
 
void initParts ()
 Performs initialization on the specified subpartition list. More...
 
std::size_t size () const
 Returns the number of contained subpartitions. More...
 
virtual Subpartitions_t const & parts () const override
 Returns a list of the subpartitions owned. More...
 
virtual Partition_t const * findPart (double w, double d) const =0
 Returns the only partition which could contain the specified width. More...
 
virtual std::string doDescribe (std::string indent, std::string firstIndent) const override
 Describes this and each of the subpartitions. More...
 
virtual std::string describeIntro () const
 Introduction to the description of the subpartitions. More...
 
std::string describeArea (std::string indent, std::string firstIndent) const
 Returns a description of the partition area. More...
 

Static Protected Member Functions

template<typename Pred >
static void walk (Partition_t const *start, Pred &&pred)
 

Protected Attributes

Sorter_t sorter
 Object used for sorting and binary search. More...
 
Subpartitions_t myParts
 List of subpartitions. More...
 

Static Protected Attributes

static Subpartitions_t const NoSubparts
 Subpartitions (if any). More...
 

Detailed Description

template<typename Data, typename Sorter>
class geo::part::SortedPartition< Data, Sorter >

Partition of area sorted across a dimension.

Template Parameters
Datatype of data contained in the partition
Sortertype of functor providing comparison of partitions

The sorter is a functor containing comparison functions. It must be compatible with both std::sort() and std::lower_bound() functions. The former requirement implies that the sorter can compare two constant pointers to partitions. The latter also implies that the sorter can compare a constant pointer to partition to a "key" (a real number), and vice versa. The meaning of this comparison is not prescribed; existing implementations interpret that value as a width or depth coordinate.

A copy of the sorter is kept in this partition.

Definition at line 387 of file Partitions.h.

Member Typedef Documentation

template<typename Data, typename Sorter>
using geo::part::SortedPartition< Data, Sorter >::Area_t = typename Partition_t::Area_t

Definition at line 396 of file Partitions.h.

template<typename Data, typename Sorter>
using geo::part::SortedPartition< Data, Sorter >::Base_t = PartitionContainer<Data>

Base class.

Definition at line 390 of file Partitions.h.

template<typename Data, typename Sorter>
using geo::part::SortedPartition< Data, Sorter >::Data_t = typename Partition_t::Data_t

Definition at line 395 of file Partitions.h.

template<typename Data, typename Sorter>
using geo::part::SortedPartition< Data, Sorter >::Partition_t = Partition<Data>

Base type of the partition.

Definition at line 391 of file Partitions.h.

template<typename Data, typename Sorter>
using geo::part::SortedPartition< Data, Sorter >::Sorter_t = Sorter

Type of sorter being used.

Definition at line 392 of file Partitions.h.

template<typename Data, typename Sorter>
using geo::part::SortedPartition< Data, Sorter >::Subpartitions_t = typename Base_t::Subpartitions_t

Definition at line 397 of file Partitions.h.

Constructor & Destructor Documentation

template<typename Data, typename Sorter>
geo::part::SortedPartition< Data, Sorter >::SortedPartition ( Area_t const &  area,
Subpartitions_t &&  subpartitions,
Data_t defData = nullptr,
Sorter_t  sorter = {} 
)
inline

Constructor: sets the partition.

Parameters
areaoverall area covered
subpartitionslist of subpartitions (pointers)
defDatadatum to be returned for points not covered by subpartitions
sorterinstance of the sorter to be used

The subpartitions will be moved from the argument and will be sorted using the comparison contained in the sorter. Note that this will invalidate existing pointers to the sub-partitions.

It is required and assumed that the subpartitions do not overlap and that the points covered by them are a subset of area. Neither of theses requirements is checked.

Definition at line 415 of file Partitions.h.

418  {})
419  : Base_t(area, std::move(subpartitions), defData), sorter(sorter)
420  {
421  initParts();
422  }
void initParts()
Performs initialization on the specified subpartition list.
Definition: Partitions.h:834
Area_t const & area() const
Returns the covered area.
Definition: Partitions.h:53
Sorter_t sorter
Object used for sorting and binary search.
Definition: Partitions.h:425
PartitionContainer< Data > Base_t
Base class.
Definition: Partitions.h:390

Member Function Documentation

template<typename Data >
auto geo::part::PartitionContainer< Data >::atPoint ( double  w,
double  d 
) const
overridevirtualinherited

Returns stored datum only if point is covered, nullptr otherwise.

Reimplemented from geo::part::PartitionWithData< Data >.

Definition at line 784 of file Partitions.h.

References d, part, and w.

785 {
786  if (!Base_t::contains(w, d)) return nullptr; // not our point at all
787  // it's ours; see if it belongs to a subpart
788  auto part = findPart(w, d);
789  return part ? part->atPoint(w, d) : Base_t::data();
790 } // geo::part::PartitionContainer<Data>::atPoint()
bool contains(double w, double d) const
Returns whether the specified point is covered by this object.
Definition: Partitions.h:50
TString part[npart]
Definition: Style.C:32
Float_t d
Definition: plot.C:235
virtual Partition_t const * findPart(double w, double d) const =0
Returns the only partition which could contain the specified width.
virtual Data_t * data() const override
Returns the datum directly stored (nullptr if none).
Definition: Partitions.h:285
Float_t w
Definition: plot.C:20
bool geo::part::AreaOwner::contains ( double  w,
double  d 
) const
inlineinherited

Returns whether the specified point is covered by this object.

Definition at line 50 of file Partitions.h.

References geo::part::AreaOwner::area(), and lar::util::simple_geo::Rectangle< Data >::contains().

50 { return area().contains(w, d); }
bool contains(Data_t w, Data_t d) const
Returns whether the specified point is in the area.
Definition: SimpleGeo.h:442
Float_t d
Definition: plot.C:235
Area_t const & area() const
Returns the covered area.
Definition: Partitions.h:53
Float_t w
Definition: plot.C:20
template<typename Data >
virtual Data_t* geo::part::PartitionWithData< Data >::data ( ) const
inlineoverridevirtualinherited

Returns the datum directly stored (nullptr if none).

Reimplemented from geo::part::Partition< Data >.

Definition at line 285 of file Partitions.h.

Referenced by geo::part::GridPartition< Data >::doDescribe().

285 { return myData; }
Data_t * myData
The contained datum.
Definition: Partitions.h:294
template<typename Data>
std::string geo::part::Partition< Data >::describe ( std::string  indent,
std::string  firstIndent 
) const
inlineinherited

Returns a description of the partition.

Definition at line 215 of file Partitions.h.

216  {
217  return doDescribe(indent, firstIndent);
218  }
virtual std::string doDescribe(std::string indent, std::string firstIndent) const
Returns a description of the partition.
Definition: Partitions.h:256
std::string indent(std::size_t const i)
template<typename Data>
std::string geo::part::Partition< Data >::describe ( std::string  indent = "") const
inlineinherited

Returns a description of the partition.

Definition at line 221 of file Partitions.h.

References geo::part::Partition< Data >::describe(), and art::detail::indent().

Referenced by geo::part::Partition< Data >::describe().

221 { return describe(indent, indent); }
std::string indent(std::size_t const i)
std::string describe(std::string indent, std::string firstIndent) const
Returns a description of the partition.
Definition: Partitions.h:215
std::string geo::part::PartitionBase::describeArea ( std::string  indent,
std::string  firstIndent 
) const
inlineprotectedinherited

Returns a description of the partition area.

Definition at line 575 of file Partitions.h.

References geo::part::AreaOwner::dumpArea(), and part.

Referenced by geo::part::Partition< Data >::doDescribe().

577 {
578  std::ostringstream sstr;
579  sstr << firstIndent << "partition covers ";
580  dumpArea(sstr);
581  return sstr.str();
582 } // geo::part::PartitionBase::describeArea()
void dumpArea(Stream &&out) const
Output the owned area into an output stream.
Definition: Partitions.h:57
template<typename Data >
std::string geo::part::PartitionContainer< Data >::describeIntro ( ) const
protectedvirtualinherited

Introduction to the description of the subpartitions.

Reimplemented in geo::part::WidthPartition< Data >, and geo::part::DepthPartition< Data >.

Definition at line 815 of file Partitions.h.

References util::size(), and util::to_string().

Referenced by geo::part::GridPartition< Data >::doDescribe().

816 {
817  return std::to_string(parts().size()) + " subpartitions";
818 } // geo::part::PartitionContainer<Data>::describeIntro()
decltype(auto) constexpr to_string(T &&obj)
ADL-aware version of std::to_string.
std::size_t size() const
Returns the number of contained subpartitions.
Definition: Partitions.h:335
virtual Subpartitions_t const & parts() const override
Returns a list of the subpartitions owned.
Definition: Partitions.h:338
template<typename Data >
std::string geo::part::PartitionContainer< Data >::doDescribe ( std::string  indent,
std::string  firstIndent 
) const
overrideprotectedvirtualinherited

Describes this and each of the subpartitions.

Reimplemented from geo::part::PartitionWithData< Data >.

Reimplemented in geo::part::GridPartition< Data >.

Definition at line 794 of file Partitions.h.

References geo::part::describePartitionData(), and part.

796 {
797  std::string msg = firstIndent + describeIntro();
798  if (Base_t::data()) {
799  std::ostringstream sstr;
800  sstr << ", and ";
802  msg += sstr.str();
803  }
804 
805  for (auto const& part : parts()) {
806  msg += "\n" + indent + " * ";
807  msg += part->describe(indent + " ", "");
808  }
809 
810  return msg;
811 } // geo::part::PartitionContainer<Data>::doDescribe()
void describePartitionData(Stream &&out, Data const *data, std::string indent="", std::string firstIndent="")
Describes a data object for Partition::describe() method.
Definition: Partitions.h:730
TString part[npart]
Definition: Style.C:32
std::string indent(std::size_t const i)
virtual Subpartitions_t const & parts() const override
Returns a list of the subpartitions owned.
Definition: Partitions.h:338
virtual Data_t * data() const override
Returns the datum directly stored (nullptr if none).
Definition: Partitions.h:285
virtual std::string describeIntro() const
Introduction to the description of the subpartitions.
Definition: Partitions.h:815
template<typename Stream >
void geo::part::AreaOwner::dumpArea ( Stream &&  out) const
inlineinherited

Output the owned area into an output stream.

Definition at line 57 of file Partitions.h.

References geo::part::AreaOwner::area().

Referenced by geo::part::PartitionBase::describeArea().

58  {
59  std::forward<Stream>(out) << area();
60  }
Area_t const & area() const
Returns the covered area.
Definition: Partitions.h:53
template<typename Data >
virtual Partition_t const* geo::part::PartitionContainer< Data >::findPart ( double  w,
double  d 
) const
protectedpure virtualinherited

Returns the only partition which could contain the specified width.

Implemented in geo::part::GridPartition< Data >, geo::part::WidthPartition< Data >, and geo::part::DepthPartition< Data >.

template<typename Data , typename Sorter >
auto geo::part::SortedPartition< Data, Sorter >::findPartWithKey ( double  key) const
protected

Returns the only partition which could contain the specified key.

Definition at line 824 of file Partitions.h.

References util::cend().

826 {
827  auto pbegin = Base_t::parts().cbegin();
828  auto iPart = std::upper_bound(pbegin, Base_t::parts().cend(), key, sorter);
829  return (iPart == pbegin) ? nullptr : (--iPart)->get();
830 } // geo::part::SortedPartition<>::findPartWithKey()
decltype(auto) constexpr cend(T &&obj)
ADL-aware version of std::cend.
Definition: StdUtils.h:93
virtual Subpartitions_t const & parts() const override
Returns a list of the subpartitions owned.
Definition: Partitions.h:338
Sorter_t sorter
Object used for sorting and binary search.
Definition: Partitions.h:425
template<typename Data , typename Sorter >
void geo::part::SortedPartition< Data, Sorter >::initParts ( )
protected

Performs initialization on the specified subpartition list.

Definition at line 834 of file Partitions.h.

References util::begin(), and util::end().

835 {
836  /*
837  * Initialization tasks:
838  * - ensure that the parts are sorted by increasing depth
839  *
840  */
842 
843 } // geo::part::SortedPartition<>::initParts()
decltype(auto) constexpr end(T &&obj)
ADL-aware version of std::end.
Definition: StdUtils.h:77
Subpartitions_t myParts
List of subpartitions.
Definition: Partitions.h:332
Sorter_t sorter
Object used for sorting and binary search.
Definition: Partitions.h:425
decltype(auto) constexpr begin(T &&obj)
ADL-aware version of std::begin.
Definition: StdUtils.h:69
template<typename Data>
std::size_t geo::part::Partition< Data >::nParts ( ) const
inlineinherited

Returns the number of subparts in the partition (0 if simple element).

Definition at line 247 of file Partitions.h.

Referenced by geo::part::GridPartition< Data >::detectSeparators().

247 { return parts().size(); }
virtual Subpartitions_t const & parts() const
Returns a list of all subpartitions.
Definition: Partitions.h:253
template<typename Data >
virtual Subpartitions_t const& geo::part::PartitionContainer< Data >::parts ( ) const
inlineoverrideprotectedvirtualinherited

Returns a list of the subpartitions owned.

Reimplemented from geo::part::Partition< Data >.

Definition at line 338 of file Partitions.h.

Referenced by geo::part::GridPartition< Data >::computeDepthSeps(), and geo::part::GridPartition< Data >::computeWidthSeps().

338 { return myParts; }
Subpartitions_t myParts
List of subpartitions.
Definition: Partitions.h:332
template<typename Data >
std::size_t geo::part::PartitionContainer< Data >::size ( ) const
inlineprotectedinherited

Returns the number of contained subpartitions.

Definition at line 335 of file Partitions.h.

Referenced by geo::part::GridPartition< Data >::GridPartition().

335 { return parts().size(); }
virtual Subpartitions_t const & parts() const override
Returns a list of the subpartitions owned.
Definition: Partitions.h:338
template<typename Data>
template<typename Pred >
void geo::part::Partition< Data >::walk ( Pred &&  pred) const
inlineinherited

Applies pred to all partitions.

Template Parameters
Preda predicate type
Parameters
predthe predicate to be applied

The predicate pred is applied to this partition first, and then to all subpartitions in no specified order.

The predicate is any object behaving like a unary function of signature:

void predicate(Partition<Data> const& part);

If the predicate returns a value, that value is ignored. The predicate is forwarded while "walking" through the partitions.

Definition at line 241 of file Partitions.h.

242  {
243  walk(this, pred);
244  }
void walk(Pred &&pred) const
Applies pred to all partitions.
Definition: Partitions.h:241
template<typename Data >
template<typename Pred >
void geo::part::Partition< Data >::walk ( Partition_t const *  start,
Pred &&  pred 
)
staticprotectedinherited

Applies pred to start partition first, and then to all subpartitions.

Definition at line 748 of file Partitions.h.

References geo::part::Partition< Data >::parts().

749 {
750  if (!start) return;
751  pred(*start);
752 
753  // recursive implementation
754  for (auto const& subPart : start->parts())
755  subPart->walk(std::forward<Pred>(pred));
756 
757 } // geo::part::Partition<Data>::walk()

Member Data Documentation

template<typename Data >
Subpartitions_t geo::part::PartitionContainer< Data >::myParts
protectedinherited

List of subpartitions.

Definition at line 332 of file Partitions.h.

template<typename Data>
geo::part::Partition< Data >::Subpartitions_t const geo::part::Partition< Data >::NoSubparts
staticprotectedinherited

Subpartitions (if any).

Definition at line 250 of file Partitions.h.

template<typename Data, typename Sorter>
Sorter_t geo::part::SortedPartition< Data, Sorter >::sorter
protected

Object used for sorting and binary search.

Definition at line 425 of file Partitions.h.


The documentation for this class was generated from the following file: