test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Member Functions | Private Attributes
npstat::BoxNDScanner< Numeric > Class Template Reference

#include <BoxNDScanner.h>

Public Member Functions

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
 
 BoxNDScanner (const BoxND< Numeric > &box, const std::vector< unsigned > &shape)
 
 BoxNDScanner (const BoxND< Numeric > &box, const unsigned *shape, const unsigned lenShape)
 

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

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.

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

48  : box_(box), state_(0UL)
49  {initialize(shape.empty() ? static_cast<unsigned*>(0) :
50  &shape[0], shape.size());}
void initialize(const unsigned *shape, unsigned lenShape)
Definition: BoxNDScanner.h:107
BoxND< Numeric > box_
Definition: BoxNDScanner.h:94
unsigned long state_
Definition: BoxNDScanner.h:97
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.

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

54  : box_(box), state_(0UL) {initialize(shape, lenShape);}
void initialize(const unsigned *shape, unsigned lenShape)
Definition: BoxNDScanner.h:107
BoxND< Numeric > box_
Definition: BoxNDScanner.h:94
unsigned long state_
Definition: BoxNDScanner.h:97
template<typename Numeric >
npstat::BoxNDScanner< Numeric >::BoxNDScanner ( )
private

Member Function Documentation

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

Dimensionality of the scan

Definition at line 58 of file BoxNDScanner.h.

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

58 {return box_.dim();}
BoxND< Numeric > box_
Definition: BoxNDScanner.h:94
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.

References assert(), i, customizeTrackingMonitorSeedNumber::idx, and cmsLHEtoEOSManager::l.

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  }
int i
Definition: DBlmapReader.cc:9
unsigned long maxState_
Definition: BoxNDScanner.h:98
assert(m_qm.get())
BoxND< Numeric > box_
Definition: BoxNDScanner.h:94
unsigned long state_
Definition: BoxNDScanner.h:97
std::vector< unsigned long > strides_
Definition: BoxNDScanner.h:95
tuple idx
DEBUGGING if hasattr(process,&quot;trackMonIterativeTracking2012&quot;): print &quot;trackMonIterativeTracking2012 D...
unsigned dim() const
Definition: BoxNDScanner.h:58
std::vector< double > bw_
Definition: BoxNDScanner.h:96
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.

References assert(), i, customizeTrackingMonitorSeedNumber::idx, and cmsLHEtoEOSManager::l.

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  }
int i
Definition: DBlmapReader.cc:9
unsigned long maxState_
Definition: BoxNDScanner.h:98
assert(m_qm.get())
unsigned long state_
Definition: BoxNDScanner.h:97
std::vector< unsigned long > strides_
Definition: BoxNDScanner.h:95
tuple idx
DEBUGGING if hasattr(process,&quot;trackMonIterativeTracking2012&quot;): print &quot;trackMonIterativeTracking2012 D...
unsigned dim() const
Definition: BoxNDScanner.h:58
template<typename Numeric >
void npstat::BoxNDScanner< Numeric >::initialize ( const unsigned *  shape,
unsigned  lenShape 
)
private

Definition at line 107 of file BoxNDScanner.h.

References assert(), and j.

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

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  }
unsigned long maxState_
Definition: BoxNDScanner.h:98
assert(m_qm.get())
int j
Definition: DBlmapReader.cc:9
BoxND< Numeric > box_
Definition: BoxNDScanner.h:94
std::vector< unsigned long > strides_
Definition: BoxNDScanner.h:95
unsigned dim() const
Definition: BoxNDScanner.h:58
std::vector< double > bw_
Definition: BoxNDScanner.h:96
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.

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

Referenced by core.AutoHandle.AutoHandle::ReallyLoad().

67 {return state_ < maxState_;}
unsigned long maxState_
Definition: BoxNDScanner.h:98
unsigned long state_
Definition: BoxNDScanner.h:97
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.

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

64 {return maxState_;}
unsigned long maxState_
Definition: BoxNDScanner.h:98
template<typename Numeric >
BoxNDScanner& npstat::BoxNDScanner< Numeric >::operator++ ( void  )
inline

Prefix increment

Definition at line 79 of file BoxNDScanner.h.

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

80  {if (state_ < maxState_) ++state_; return *this;}
unsigned long maxState_
Definition: BoxNDScanner.h:98
unsigned long state_
Definition: BoxNDScanner.h:97
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.

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

83 {if (state_ < maxState_) ++state_;}
unsigned long maxState_
Definition: BoxNDScanner.h:98
unsigned long state_
Definition: BoxNDScanner.h:97
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.

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

76 {state_ = 0UL;}
unsigned long state_
Definition: BoxNDScanner.h:97
template<typename Numeric >
void npstat::BoxNDScanner< Numeric >::setState ( const unsigned long  state)
inline

Set the state directly

Definition at line 86 of file BoxNDScanner.h.

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

unsigned long maxState_
Definition: BoxNDScanner.h:98
unsigned long state_
Definition: BoxNDScanner.h:97
unsigned long state() const
Definition: BoxNDScanner.h:61
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.

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

61 {return state_;}
unsigned long state_
Definition: BoxNDScanner.h:97

Member Data Documentation

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

Definition at line 94 of file BoxNDScanner.h.

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

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

Definition at line 96 of file BoxNDScanner.h.

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

Definition at line 95 of file BoxNDScanner.h.