CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes
npstat::BoxNDScanner< Numeric > Class Template Reference

#include <BoxNDScanner.h>

Public Member Functions

 BoxNDScanner (const BoxND< Numeric > &box, const std::vector< unsigned > &shape)
 
 BoxNDScanner (const BoxND< Numeric > &box, const unsigned *shape, const unsigned lenShape)
 
unsigned dim () const
 
void getCoords (Numeric *x, unsigned nx) const
 
void getIndex (unsigned *index, unsigned indexBufferLen) const
 
bool isValid () const
 
unsigned long maxState () const
 
BoxNDScanneroperator++ ()
 
void operator++ (int)
 
void reset ()
 
void setState (const unsigned long state)
 
unsigned long state () const
 

Private Member Functions

 BoxNDScanner ()
 
void initialize (const unsigned *shape, unsigned lenShape)
 

Private Attributes

BoxND< Numeric > box_
 
std::vector< double > bw_
 
unsigned long maxState_
 
unsigned long state_
 
std::vector< unsigned long > strides_
 

Detailed Description

template<typename Numeric>
class npstat::BoxNDScanner< Numeric >

A class for iterating over all coordinates in a multidimensional box (but not a full-fledeged iterator). The expected usage pattern is as follows:

double* coords = ... (the buffer size should be at least box.dim())
for (BoxNDScanner<double> scan(box,shape); scan.isValid(); ++scan)
{
scan.getCoords(coords, coordsBufferSize);
.... Do what is necessary with coordinates ....
.... Extract linear bin number: ..............
scan.state();
}

The coordinates will be in the middle of the bins (imagine a multivariate histogram with boundaries defined by the given box).

Definition at line 38 of file BoxNDScanner.h.

Constructor & Destructor Documentation

◆ BoxNDScanner() [1/3]

template<typename Numeric >
npstat::BoxNDScanner< Numeric >::BoxNDScanner ( const BoxND< Numeric > &  box,
const std::vector< unsigned > &  shape 
)
inline

Constructor from a bounding box and a multidimensional array shape

Definition at line 46 of file BoxNDScanner.h.

48  : box_(box), state_(0UL)
49  {initialize(shape.empty() ? static_cast<unsigned*>(0) :
50  &shape[0], shape.size());}

References npstat::BoxNDScanner< Numeric >::initialize().

◆ BoxNDScanner() [2/3]

template<typename Numeric >
npstat::BoxNDScanner< Numeric >::BoxNDScanner ( const BoxND< Numeric > &  box,
const unsigned *  shape,
const unsigned  lenShape 
)
inline

Definition at line 52 of file BoxNDScanner.h.

54  : box_(box), state_(0UL) {initialize(shape, lenShape);}

References npstat::BoxNDScanner< Numeric >::initialize().

◆ BoxNDScanner() [3/3]

template<typename Numeric >
npstat::BoxNDScanner< Numeric >::BoxNDScanner ( )
private

Member Function Documentation

◆ dim()

template<typename Numeric >
unsigned npstat::BoxNDScanner< Numeric >::dim ( ) const
inline

Dimensionality of the scan

Definition at line 58 of file BoxNDScanner.h.

58 {return box_.dim();}

References npstat::BoxNDScanner< Numeric >::box_.

◆ getCoords()

template<typename Numeric >
void npstat::BoxNDScanner< Numeric >::getCoords ( Numeric *  x,
unsigned  nx 
) const

Retrieve current coordinates inside the box

Definition at line 130 of file BoxNDScanner.h.

131  {
132  const unsigned dim = strides_.size();
133  if (nx < dim) throw npstat::NpstatInvalidArgument(
134  "In npstat::BoxNDScanner::getCoords: "
135  "insufficient length of the output buffer");
137  "In npstat::BoxNDScanner::getCoords: invalid scanner state");
138  assert(x);
139 
140  unsigned long l = state_;
141  for (unsigned i=0; i<dim; ++i)
142  {
143  unsigned long idx = l / strides_[i];
144  x[i] = box_[i].min() + (idx + 0.5)*bw_[i];
145  l -= (idx * strides_[i]);
146  }
147  }

References cms::cuda::assert(), mps_fire::i, heavyIonCSV_trainingSettings::idx, and cmsLHEtoEOSManager::l.

◆ getIndex()

template<typename Numeric >
void npstat::BoxNDScanner< Numeric >::getIndex ( unsigned *  index,
unsigned  indexBufferLen 
) const

Retrieve current multidimensional index

Definition at line 150 of file BoxNDScanner.h.

151  {
152  const unsigned dim = strides_.size();
153  if (nx < dim) throw npstat::NpstatInvalidArgument(
154  "In npstat::BoxNDScanner::getIndex: "
155  "insufficient length of the output buffer");
157  "In npstat::BoxNDScanner::getIndex: invalid scanner state");
158  assert(ix);
159 
160  unsigned long l = state_;
161  for (unsigned i=0; i<dim; ++i)
162  {
163  unsigned long idx = l / strides_[i];
164  ix[i] = static_cast<unsigned>(idx);
165  l -= (idx * strides_[i]);
166  }
167  }

References cms::cuda::assert(), mps_fire::i, heavyIonCSV_trainingSettings::idx, and cmsLHEtoEOSManager::l.

◆ initialize()

template<typename Numeric >
void npstat::BoxNDScanner< Numeric >::initialize ( const unsigned *  shape,
unsigned  lenShape 
)
private

Definition at line 107 of file BoxNDScanner.h.

109  {
110  if (!(dim && box_.dim() == dim)) throw npstat::NpstatInvalidArgument(
111  "In npstat::BoxNDScanner::initialize: incompatible scan shape");
112  assert(shape);
113  for (unsigned j=0; j<dim; ++j)
114  if (!shape[j]) throw npstat::NpstatInvalidArgument(
115  "In npstat::BoxNDScanner::initialize: "
116  "number of scans must be positive in each dimension");
117 
118  strides_.resize(dim);
119  strides_[dim - 1] = 1UL;
120  for (unsigned j=dim - 1; j>0; --j)
121  strides_[j - 1] = strides_[j]*shape[j];
122  maxState_ = strides_[0]*shape[0];
123 
124  bw_.reserve(dim);
125  for (unsigned j=0; j<dim; ++j)
126  bw_.push_back(box_[j].length()*1.0/shape[j]);
127  }

References cms::cuda::assert(), and dqmiolumiharvest::j.

Referenced by npstat::BoxNDScanner< Numeric >::BoxNDScanner().

◆ isValid()

template<typename Numeric >
bool npstat::BoxNDScanner< Numeric >::isValid ( void  ) const
inline

Returns false when iteration is complete

Definition at line 67 of file BoxNDScanner.h.

67 {return state_ < maxState_;}

References npstat::BoxNDScanner< Numeric >::maxState_, and npstat::BoxNDScanner< Numeric >::state_.

Referenced by ntupleDataFormat._Object::_checkIsValid(), and core.AutoHandle.AutoHandle::ReallyLoad().

◆ maxState()

template<typename Numeric >
unsigned long npstat::BoxNDScanner< Numeric >::maxState ( ) const
inline

Maximum possible state (i.e., linear index of the scan)

Definition at line 64 of file BoxNDScanner.h.

64 {return maxState_;}

References npstat::BoxNDScanner< Numeric >::maxState_.

◆ operator++() [1/2]

template<typename Numeric >
BoxNDScanner& npstat::BoxNDScanner< Numeric >::operator++ ( void  )
inline

Prefix increment

Definition at line 79 of file BoxNDScanner.h.

80  {if (state_ < maxState_) ++state_; return *this;}

References npstat::BoxNDScanner< Numeric >::maxState_, and npstat::BoxNDScanner< Numeric >::state_.

◆ operator++() [2/2]

template<typename Numeric >
void npstat::BoxNDScanner< Numeric >::operator++ ( int  )
inline

Postfix increment (distinguished by the dummy "int" parameter)

Definition at line 83 of file BoxNDScanner.h.

83 {if (state_ < maxState_) ++state_;}

References npstat::BoxNDScanner< Numeric >::maxState_, and npstat::BoxNDScanner< Numeric >::state_.

◆ reset()

template<typename Numeric >
void npstat::BoxNDScanner< Numeric >::reset ( void  )
inline

Reset the state (as if the object has just been constructed)

Definition at line 76 of file BoxNDScanner.h.

76 {state_ = 0UL;}

References npstat::BoxNDScanner< Numeric >::state_.

◆ setState()

template<typename Numeric >
void npstat::BoxNDScanner< Numeric >::setState ( const unsigned long  state)
inline

◆ state()

template<typename Numeric >
unsigned long npstat::BoxNDScanner< Numeric >::state ( ) const
inline

Retrieve current state (i.e., linear index of the scan)

Definition at line 61 of file BoxNDScanner.h.

61 {return state_;}

References npstat::BoxNDScanner< Numeric >::state_.

Referenced by npstat::BoxNDScanner< Numeric >::setState().

Member Data Documentation

◆ box_

template<typename Numeric >
BoxND<Numeric> npstat::BoxNDScanner< Numeric >::box_
private

Definition at line 94 of file BoxNDScanner.h.

Referenced by npstat::BoxNDScanner< Numeric >::dim().

◆ bw_

template<typename Numeric >
std::vector<double> npstat::BoxNDScanner< Numeric >::bw_
private

Definition at line 96 of file BoxNDScanner.h.

◆ maxState_

template<typename Numeric >
unsigned long npstat::BoxNDScanner< Numeric >::maxState_
private

◆ state_

template<typename Numeric >
unsigned long npstat::BoxNDScanner< Numeric >::state_
private

◆ strides_

template<typename Numeric >
std::vector<unsigned long> npstat::BoxNDScanner< Numeric >::strides_
private

Definition at line 95 of file BoxNDScanner.h.

npstat::BoxNDScanner::box_
BoxND< Numeric > box_
Definition: BoxNDScanner.h:94
npstat::BoxNDScanner::strides_
std::vector< unsigned long > strides_
Definition: BoxNDScanner.h:95
mps_fire.i
i
Definition: mps_fire.py:428
npstat::BoxNDScanner::state_
unsigned long state_
Definition: BoxNDScanner.h:97
cms::cuda::assert
assert(be >=bs)
DDAxes::x
npstat::BoxNDScanner::dim
unsigned dim() const
Definition: BoxNDScanner.h:58
heavyIonCSV_trainingSettings.idx
idx
Definition: heavyIonCSV_trainingSettings.py:5
edmScanValgrind.buffer
buffer
Definition: edmScanValgrind.py:171
npstat::BoxNDScanner::bw_
std::vector< double > bw_
Definition: BoxNDScanner.h:96
npstat::NpstatRuntimeError
Definition: NpstatException.h:46
contentValuesFiles.number
number
Definition: contentValuesFiles.py:53
npstat::BoxNDScanner::initialize
void initialize(const unsigned *shape, unsigned lenShape)
Definition: BoxNDScanner.h:107
npstat::NpstatInvalidArgument
Definition: NpstatException.h:38
npstat::BoxNDScanner::state
unsigned long state() const
Definition: BoxNDScanner.h:61
cmsLHEtoEOSManager.l
l
Definition: cmsLHEtoEOSManager.py:204
newFWLiteAna.bin
bin
Definition: newFWLiteAna.py:161
linear
float linear(float x)
Definition: OccupancyPlotMacros.cc:26
npstat::BoxNDScanner::maxState_
unsigned long maxState_
Definition: BoxNDScanner.h:98
cms::cuda::be
int be
Definition: HistoContainer.h:126
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
findQualityFiles.size
size
Write out results.
Definition: findQualityFiles.py:443