All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Types | Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
geo::part::GridPartition< Data > Class Template Reference

A container of partitions organised in a width/depth rectangular grid. More...

#include <Partitions.h>

Inheritance diagram for geo::part::GridPartition< Data >:
geo::part::PartitionContainer< Data > geo::part::PartitionWithData< Data > geo::part::Partition< Data > geo::part::PartitionBase geo::part::AreaOwner

Public Types

using Partition_t = Partition< Data >
 Base type of the partition. More...
 
using Base_t = PartitionContainer< Data >
 Base class. More...
 
using Data_t = typename Partition_t::Data_t
 Type of contained data. More...
 
using Area_t = typename Partition_t::Area_t
 Type of covered area. More...
 
using Subpartitions_t = typename Base_t::Subpartitions_t
 
- Public Types inherited from geo::part::PartitionContainer< Data >
using Base_t = PartitionWithData< Data >
 Base class. More...
 
using Partition_t = Partition< Data >
 Base type of the partition. More...
 
using Data_t = typename Partition_t::Data_t
 
using Area_t = typename Partition_t::Area_t
 
using Subpartitions_t = typename Partition_t::Subpartitions_t
 
- Public Types inherited from geo::part::PartitionWithData< Data >
using Base_t = Partition< Data >
 Base class. More...
 
using Partition_t = Partition< Data >
 Base type of the partition. More...
 
using Data_t = typename Partition_t::Data_t
 Type of contained data. More...
 
using Area_t = typename Partition_t::Area_t
 Type of covered area. More...
 
- Public Types inherited from geo::part::Partition< Data >
using Data_t = Data
 Type of data stored in the partition. More...
 
using Partition_t = Partition< Data >
 This type. More...
 
using Area_t = PartitionBase::Area_t
 Type of area. More...
 
using Subpartitions_t = std::vector< std::unique_ptr< Partition_t const >>
 Type of list of subpartitions. It needs to preserve polymorphism. More...
 
- Public Types inherited from geo::part::PartitionBase
using Area_t = AreaOwner::Area_t
 
using AreaRangeMember_t = AreaOwner::AreaRangeMember_t
 
- Public Types inherited from geo::part::AreaOwner
using Area_t = lar::util::simple_geo::Rectangle< double >
 Type of area covered by the partition. More...
 
using AreaRangeMember_t = Area_t::Range_t(Area_t::*)
 Type of pointer to Area_t data member of type Range_t. More...
 

Public Member Functions

 GridPartition (Area_t const &area, Subpartitions_t &&subpartitions, unsigned int nDepthPartitions, unsigned int nWidthPartitions, Data_t *defData=nullptr)
 Creates a partition with a grid of subpartitions. More...
 
 GridPartition (Area_t const &area, Subpartitions_t &&subpartitions, unsigned int nDepthPartitions, Data_t *defData=nullptr)
 
- Public Member Functions inherited from geo::part::PartitionContainer< Data >
virtual Data_tatPoint (double w, double d) const override
 Returns stored datum only if point is covered, nullptr otherwise. More...
 
- Public Member Functions inherited from geo::part::PartitionWithData< Data >
 PartitionWithData (Area_t const &area, Data_t *myData)
 Constructor: sets the covered area and the contained datum. More...
 
virtual Data_tdata () const override
 Returns the datum directly stored (nullptr if none). More...
 
- Public Member Functions inherited from geo::part::Partition< Data >
 Partition (Area_t const &area)
 Constructor: sets the covered area and no subpartitions. More...
 
virtual ~Partition ()=default
 Destructor (default, virtual). 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...
 
- Public Member Functions inherited from geo::part::PartitionBase
 PartitionBase (Area_t const &area)
 Constructor: sets the covered area and no subpartitions. More...
 
- Public Member Functions inherited from geo::part::AreaOwner
 AreaOwner (Area_t const &area)
 Constructor: sets the covered area and no subpartitions. 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...
 

Private Member Functions

std::size_t nWidthParts () const
 Number of partitions on width direction. More...
 
std::size_t nDepthParts () const
 
auto part (std::size_t iDepth, std::size_t iWidth) -> decltype(auto)
 
auto part (std::size_t iDepth, std::size_t iWidth) const -> decltype(auto)
 
virtual Partition_t const * findPart (double w, double d) const override
 Returns the only partition which could contain the specified depth. More...
 
std::vector< double > computeWidthSeps (unsigned int nD, unsigned int nW) const
 Computes and returns width separation levels proper for widthSeps. More...
 
std::vector< double > computeDepthSeps (unsigned int nD, unsigned int nW) const
 Computes and returns width separation levels proper for depthSeps. More...
 
virtual std::string doDescribe (std::string indent, std::string firstIndent) const override
 Prints the information about the partition grid. More...
 

Static Private Member Functions

template<PartitionBase::AreaRangeMember_t Range, typename BeginIter , typename EndIter >
static std::vector< double > detectSeparators (BeginIter b, EndIter e, std::size_t const nGroups, std::size_t const startDelta, std::size_t const stride)
 

Private Attributes

std::vector< double > widthSeps
 Separators for width dimension. More...
 
std::vector< double > depthSeps
 Separators for depth dimension. More...
 

Additional Inherited Members

- Protected Member Functions inherited from geo::part::PartitionContainer< Data >
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...
 
 PartitionContainer (Area_t const &area, Subpartitions_t &&subpartitions, Data_t *defData=nullptr)
 Constructor: sets the partition. More...
 
virtual std::string describeIntro () const
 Introduction to the description of the subpartitions. More...
 
- Protected Member Functions inherited from geo::part::PartitionBase
std::string describeArea (std::string indent, std::string firstIndent) const
 Returns a description of the partition area. More...
 
- Static Protected Member Functions inherited from geo::part::Partition< Data >
template<typename Pred >
static void walk (Partition_t const *start, Pred &&pred)
 
- Protected Attributes inherited from geo::part::PartitionContainer< Data >
Subpartitions_t myParts
 List of subpartitions. More...
 
- Static Protected Attributes inherited from geo::part::Partition< Data >
static Subpartitions_t const NoSubparts
 Subpartitions (if any). More...
 

Detailed Description

template<typename Data>
class geo::part::GridPartition< Data >

A container of partitions organised in a width/depth rectangular grid.

Definition at line 514 of file Partitions.h.

Member Typedef Documentation

template<typename Data >
using geo::part::GridPartition< Data >::Area_t = typename Partition_t::Area_t

Type of covered area.

Definition at line 521 of file Partitions.h.

template<typename Data >
using geo::part::GridPartition< Data >::Base_t = PartitionContainer<Data>

Base class.

Definition at line 517 of file Partitions.h.

template<typename Data >
using geo::part::GridPartition< Data >::Data_t = typename Partition_t::Data_t

Type of contained data.

Definition at line 520 of file Partitions.h.

template<typename Data >
using geo::part::GridPartition< Data >::Partition_t = Partition<Data>

Base type of the partition.

Definition at line 516 of file Partitions.h.

template<typename Data >
using geo::part::GridPartition< Data >::Subpartitions_t = typename Base_t::Subpartitions_t

Definition at line 522 of file Partitions.h.

Constructor & Destructor Documentation

template<typename Data >
geo::part::GridPartition< Data >::GridPartition ( Area_t const &  area,
Subpartitions_t &&  subpartitions,
unsigned int  nDepthPartitions,
unsigned int  nWidthPartitions,
Data_t defData = nullptr 
)

Creates a partition with a grid of subpartitions.

Parameters
areatotal area covered by this partition
subpartitionsall subpartitions, row by row
nDepthPartitionsnumber of partitions on depth direction ("rows")
nWidthPartitionsnumber of partitions on width direction ("columns")
defDatapartition data for areas not covered by subpartitions

The content of the collection of subpartitions is stolen. The subpartitions in that collection are expected to be organized by row: (0;0), (0,1), (0,2)... where the first index spans nDepthPartitions values and the second one spans nWidthPartitions values.

Definition at line 934 of file Partitions.h.

940  : Base_t(area, std::move(subpartitions), defData)
941  , widthSeps(computeWidthSeps(nDepthPartitions, nWidthPartitions))
942  , depthSeps(computeDepthSeps(nDepthPartitions, nWidthPartitions))
943 {
944  assert(nWidthPartitions * nDepthPartitions == Base_t::size());
945 } // geo::part::GridPartition<Data>::GridPartition()
std::vector< double > computeDepthSeps(unsigned int nD, unsigned int nW) const
Computes and returns width separation levels proper for depthSeps.
Definition: Partitions.h:1013
std::vector< double > depthSeps
Separators for depth dimension.
Definition: Partitions.h:556
std::vector< double > widthSeps
Separators for width dimension.
Definition: Partitions.h:555
std::vector< double > computeWidthSeps(unsigned int nD, unsigned int nW) const
Computes and returns width separation levels proper for widthSeps.
Definition: Partitions.h:1004
PartitionContainer< Data > Base_t
Base class.
Definition: Partitions.h:517
Area_t const & area() const
Returns the covered area.
Definition: Partitions.h:56
std::size_t size() const
Returns the number of contained subpartitions.
Definition: Partitions.h:340
template<typename Data >
geo::part::GridPartition< Data >::GridPartition ( Area_t const &  area,
Subpartitions_t &&  subpartitions,
unsigned int  nDepthPartitions,
Data_t defData = nullptr 
)

Constructor: autodetects nWidthPartitions from number of subpartitions.

Definition at line 949 of file Partitions.h.

954  : GridPartition(
955  area, std::move(subpartitions), nDepthPartitions,
956  (nDepthPartitions? subpartitions.size()/nDepthPartitions: 0),
957  defData
958  )
959  {}
Area_t const & area() const
Returns the covered area.
Definition: Partitions.h:56
GridPartition(Area_t const &area, Subpartitions_t &&subpartitions, unsigned int nDepthPartitions, unsigned int nWidthPartitions, Data_t *defData=nullptr)
Creates a partition with a grid of subpartitions.
Definition: Partitions.h:934

Member Function Documentation

template<typename Data >
std::vector< double > geo::part::GridPartition< Data >::computeDepthSeps ( unsigned int  nD,
unsigned int  nW 
) const
private

Computes and returns width separation levels proper for depthSeps.

Definition at line 1013 of file Partitions.h.

1014 {
1015  return detectSeparators<&Area_t::depth>
1016  (Base_t::parts().cbegin(), Base_t::parts().cend(), nD, nW, 1U);
1017 } // geo::part::GridPartition<Data>::computeDepthSeps()
virtual Subpartitions_t const & parts() const override
Returns a list of the subpartitions owned.
Definition: Partitions.h:343
template<typename Data >
std::vector< double > geo::part::GridPartition< Data >::computeWidthSeps ( unsigned int  nD,
unsigned int  nW 
) const
private

Computes and returns width separation levels proper for widthSeps.

Definition at line 1004 of file Partitions.h.

1005 {
1006  return detectSeparators<&Area_t::width>
1007  (Base_t::parts().cbegin(), Base_t::parts().cend(), nW, 1U, nW);
1008 } // geo::part::GridPartition<Data>::computeWidthSeps()
virtual Subpartitions_t const & parts() const override
Returns a list of the subpartitions owned.
Definition: Partitions.h:343
template<typename Data >
template<geo::part::AreaOwner::AreaRangeMember_t Range, typename BeginIter , typename EndIter >
std::vector< double > geo::part::GridPartition< Data >::detectSeparators ( BeginIter  b,
EndIter  e,
std::size_t const  nGroups,
std::size_t const  startDelta,
std::size_t const  stride 
)
staticprivate

Definition at line 1025 of file Partitions.h.

1030  {
1031  /*
1032  * The iterators are better be random access.
1033  * The range [b,e[ is considered to be a 2D table stored row after row.
1034  * This function can operate on rows or columns, given the proper arguments.
1035  *
1036  * The full range is split in nGroups "groups" (e.g. rows or columns).
1037  * Each group g starts at the element g x startDelta.
1038  * All members of that group are stride elements far from each other.
1039  *
1040  * Be the table of size (d x w).
1041  * To process data row by row:
1042  * - the group is a row
1043  * - the number of groups is the number of rows: nGroups = d
1044  * - each group will have (d x w)/nGroups = w elements
1045  * - the start offset is the number of group times the size of it:
1046  * startDelta = w
1047  * - the elements are contiguous: stride = 1
1048  *
1049  * To process data column by column:
1050  * - the group is a column
1051  * - the number of groups is the number of columns: nGroups = w
1052  * - each group will have (d x w)/nGroups = d elements
1053  * - the start offset matches the number of group: startDelta = 1
1054  * - the elements are separated by a full row: stride = w
1055  *
1056  */
1057  // the separator is on the lower bound of selected range of the partition area
1058 
1059  static_assert(details::is_partition_ptr_iterator<BeginIter>(),
1060  "Begin iterator does not point to a pointer to partition type");
1061 
1062  details::PartitionRangeLowerBoundExtractor<Range> lowerBound;
1063 
1064  std::size_t const nParts = std::distance(b, e);
1065  std::size_t const nPartsInGroup = nParts / nGroups;
1066 
1067  auto const part
1068  = [b](std::size_t index){ return std::next(b, index)->get(); };
1069 
1070  std::vector<double> seps(nGroups);
1071  for (size_t g = 0; g < nGroups; ++g) {
1072 
1073  double& sep = seps[g];
1074 
1075  // indices of an element in the previous and next group, respectively
1076  std::size_t index = g * startDelta;
1077  sep = lowerBound(part(index));
1078 
1079  std::size_t const iend = index + nPartsInGroup * stride;
1080  while ((index += stride) < iend) {
1081  double const l = lowerBound(part(index));
1082  if (sep > l) sep = l;
1083  } // while (element)
1084 
1085  } // while (groups)
1086  return seps;
1087 } // geo::part::GridPartition<Data>::detectSeparators()
BEGIN_PROLOG g
auto part(std::size_t iDepth, std::size_t iWidth) -> decltype(auto)
Definition: Partitions.h:563
double distance(geo::Point_t const &point, CathodeDesc_t const &cathode)
Returns the distance of a point from the cathode.
do i e
std::size_t nParts() const
Returns the number of subparts in the partition (0 if simple element).
Definition: Partitions.h:249
template<typename Data >
std::string geo::part::GridPartition< Data >::doDescribe ( std::string  indent,
std::string  firstIndent 
) const
overrideprivatevirtual

Prints the information about the partition grid.

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

Definition at line 965 of file Partitions.h.

966 {
967  std::ostringstream sstr;
968  sstr << firstIndent << Base_t::describeIntro()
969  << " in a (WxD) = " << nWidthParts() << " x " << nDepthParts() << " grid";
970  if (Base_t::data()) {
971  sstr << ", and ";
972  describePartitionData(sstr, Base_t::data(), indent, "");
973  }
974  for (std::size_t iDepth = 0; iDepth < nDepthParts(); ++iDepth) {
975  for (std::size_t iWidth = 0; iWidth < nWidthParts(); ++iWidth) {
976  sstr << "\n" << indent << " [" << iDepth << "][" << iWidth << "] "
977  << part(iDepth, iWidth)->describe(indent + " ", "");
978  } // for width
979  } // for depth
980 
981  return sstr.str();
982 } // geo::part::GridPartition<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:784
auto part(std::size_t iDepth, std::size_t iWidth) -> decltype(auto)
Definition: Partitions.h:563
virtual Data_t * data() const override
Returns the datum directly stored (nullptr if none).
Definition: Partitions.h:289
std::size_t nWidthParts() const
Number of partitions on width direction.
Definition: Partitions.h:559
virtual std::string describeIntro() const
Introduction to the description of the subpartitions.
Definition: Partitions.h:875
std::size_t nDepthParts() const
Definition: Partitions.h:561
template<typename Data >
auto geo::part::GridPartition< Data >::findPart ( double  w,
double  d 
) const
overrideprivatevirtual

Returns the only partition which could contain the specified depth.

Implements geo::part::PartitionContainer< Data >.

Definition at line 987 of file Partitions.h.

989 {
990  auto const iWidth = std::upper_bound(widthSeps.cbegin(), widthSeps.cend(), w);
991  if (iWidth == widthSeps.cbegin()) return nullptr;
992  auto const iDepth = std::upper_bound(depthSeps.cbegin(), depthSeps.cend(), d);
993  if (iDepth == depthSeps.cbegin()) return nullptr;
994  return part(
995  std::distance(depthSeps.cbegin(), iDepth) - 1U,
996  std::distance(widthSeps.cbegin(), iWidth) - 1U
997  ).get();
998 } // geo::part::GridPartition<Data>::findPart()
std::vector< double > depthSeps
Separators for depth dimension.
Definition: Partitions.h:556
auto part(std::size_t iDepth, std::size_t iWidth) -> decltype(auto)
Definition: Partitions.h:563
std::vector< double > widthSeps
Separators for width dimension.
Definition: Partitions.h:555
double distance(geo::Point_t const &point, CathodeDesc_t const &cathode)
Returns the distance of a point from the cathode.
template<typename Data >
std::size_t geo::part::GridPartition< Data >::nDepthParts ( ) const
inlineprivate

Definition at line 561 of file Partitions.h.

561 { return depthSeps.size(); }
std::vector< double > depthSeps
Separators for depth dimension.
Definition: Partitions.h:556
template<typename Data >
std::size_t geo::part::GridPartition< Data >::nWidthParts ( ) const
inlineprivate

Number of partitions on width direction.

Number of partitions on depth direction.

Definition at line 559 of file Partitions.h.

template<typename Data >
auto geo::part::GridPartition< Data >::part ( std::size_t  iDepth,
std::size_t  iWidth 
) -> decltype(auto)
inlineprivate

Definition at line 563 of file Partitions.h.

564  { return Base_t::parts()[iDepth * nWidthParts() + iWidth]; }
std::size_t nWidthParts() const
Number of partitions on width direction.
Definition: Partitions.h:559
virtual Subpartitions_t const & parts() const override
Returns a list of the subpartitions owned.
Definition: Partitions.h:343
template<typename Data >
auto geo::part::GridPartition< Data >::part ( std::size_t  iDepth,
std::size_t  iWidth 
) const -> decltype(auto)
inlineprivate

Definition at line 565 of file Partitions.h.

566  { return Base_t::parts()[iDepth * nWidthParts() + iWidth]; }
std::size_t nWidthParts() const
Number of partitions on width direction.
Definition: Partitions.h:559
virtual Subpartitions_t const & parts() const override
Returns a list of the subpartitions owned.
Definition: Partitions.h:343

Member Data Documentation

template<typename Data >
std::vector<double> geo::part::GridPartition< Data >::depthSeps
private

Separators for depth dimension.

Definition at line 556 of file Partitions.h.

template<typename Data >
std::vector<double> geo::part::GridPartition< Data >::widthSeps
private

Separators for width dimension.

Definition at line 555 of file Partitions.h.


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