test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ArrayNDScanner.cc
Go to the documentation of this file.
2 #include <cassert>
3 
5 
6 namespace npstat {
8  const unsigned* shape, const unsigned lenShape)
9  {
10  // Check argument validity
11  if (lenShape == 0U || lenShape >= CHAR_BIT*sizeof(unsigned long))
13  "In npstat::ArrayNDScanner::initialize: invalid scan shape");
14  assert(shape);
15  for (unsigned j=0; j<lenShape; ++j)
16  if (!shape[j]) throw npstat::NpstatInvalidArgument(
17  "In npstat::ArrayNDScanner::initialize: "
18  "number of scans must be positive in each dimension");
19 
20  // Initialize the scanner data
21  state_ = 0UL;
22  dim_ = lenShape;
23  strides_[dim_ - 1] = 1UL;
24  for (unsigned j=dim_ - 1; j>0; --j)
25  strides_[j - 1] = strides_[j]*shape[j];
26  maxState_ = strides_[0]*shape[0];
27  }
28 
30  unsigned* ix, const unsigned indexBufferLen) const
31  {
32  if (indexBufferLen < dim_) throw npstat::NpstatInvalidArgument(
33  "In npstat::ArrayNDScanner::getIndex: "
34  "insufficient length of the output buffer");
36  "In npstat::ArrayNDScanner::getIndex: invalid scanner state");
37  assert(ix);
38 
39  unsigned long l = state_;
40  for (unsigned i=0; i<dim_; ++i)
41  {
42  unsigned long idx = l / strides_[i];
43  ix[i] = static_cast<unsigned>(idx);
44  l -= (idx * strides_[i]);
45  }
46  }
47 }
int i
Definition: DBlmapReader.cc:9
assert(m_qm.get())
void initialize(const unsigned *shape, unsigned lenShape)
unsigned long maxState_
Exceptions for the npstat namespace.
unsigned long strides_[CHAR_BIT *sizeof(unsigned long)]
int j
Definition: DBlmapReader.cc:9
tuple idx
DEBUGGING if hasattr(process,&quot;trackMonIterativeTracking2012&quot;): print &quot;trackMonIterativeTracking2012 D...
void getIndex(unsigned *index, unsigned indexBufferLen) const
Iteration over indices of a multidimensional array.