CMS 3D CMS Logo

Public Member Functions

npstat::ArrayRange Struct Reference

#include <ArrayRange.h>

Inheritance diagram for npstat::ArrayRange:
npstat::BoxND< unsigned > vector

List of all members.

Public Member Functions

 ArrayRange ()
 ArrayRange (unsigned dim)
 ArrayRange (unsigned dim, const Interval< unsigned > &r1)
void lowerLimits (unsigned *limits, unsigned limitsLen) const
bool operator< (const ArrayRange &) const
void rangeLength (unsigned *range, unsigned rangeLen) const
unsigned long rangeSize () const
ArrayShape shape () const
ArrayRangestripOuterLayer ()
void upperLimits (unsigned *limits, unsigned limitsLen) const
 ArrayRange (const ArrayShape &shape)
 ArrayRange (const unsigned *shape, unsigned shapeLen)
bool isCompatible (const ArrayShape &shape) const
bool isCompatible (const unsigned *shape, unsigned shapeLen) const

Detailed Description

Utility class for use in certain array iterations

Definition at line 21 of file ArrayRange.h.


Constructor & Destructor Documentation

npstat::ArrayRange::ArrayRange ( ) [inline]

Definition at line 23 of file ArrayRange.h.

{}
npstat::ArrayRange::ArrayRange ( unsigned  dim) [inline]

Constructor from a given number of dimensions

Definition at line 26 of file ArrayRange.h.

: BoxND<unsigned>(dim) {}
npstat::ArrayRange::ArrayRange ( unsigned  dim,
const Interval< unsigned > &  r1 
) [inline]

The given interval is repeated for every dimension

Definition at line 29 of file ArrayRange.h.

            : BoxND<unsigned>(dim, r1) {}
npstat::ArrayRange::ArrayRange ( const ArrayShape shape) [inline]

Constructor which creates a range out of a shape which is used to represent the upper limit. The lower limit in each dimension is set to 0.

Definition at line 38 of file ArrayRange.h.

: BoxND<unsigned>(shape) {}
npstat::ArrayRange::ArrayRange ( const unsigned *  shape,
unsigned  shapeLen 
)

Definition at line 5 of file ArrayRange.cc.

References i.

    {
        if (imax)
        {
            assert(ishape);
            this->reserve(imax);
            for (unsigned i=0; i<imax; ++i)
                this->push_back(Interval<unsigned>(ishape[i]));
        }
    }

Member Function Documentation

bool npstat::ArrayRange::isCompatible ( const ArrayShape shape) const

Check for compatibility with a shape

Definition at line 16 of file ArrayRange.cc.

Referenced by npstat::ArrayND< Numeric, StackLen, StackDim >::ArrayND().

    {
        const unsigned imax = ishape.size();
        return isCompatible(imax ? &ishape[0] : (unsigned*)0, imax);
    }
bool npstat::ArrayRange::isCompatible ( const unsigned *  shape,
unsigned  shapeLen 
) const

Definition at line 22 of file ArrayRange.cc.

References i, max(), and findQualityFiles::size.

    {
        if (this->size() != imax)
            return false;
        if (imax)
        {
            assert(ishape);
            for (unsigned i=0; i<imax; ++i)
                if ((*this)[i].length() == 0U)
                    return true;
            for (unsigned i=0; i<imax; ++i)
                if ((*this)[i].max() > ishape[i])
                    return false;
        }
        return true;
    }
void npstat::ArrayRange::lowerLimits ( unsigned *  limits,
unsigned  limitsLen 
) const

Get the lower range limits into an array. The length of the limit array should be at least equal to the dimensionality.

Definition at line 99 of file ArrayRange.cc.

References data, i, min, and findQualityFiles::size.

Referenced by npstat::ArrayND< Numeric, StackLen, StackDim >::ArrayND().

    {
        const unsigned imax = this->size();
        if (limitsLen < imax) throw npstat::NpstatInvalidArgument(
            "In npstat::ArrayRange::lowerLimits: "
            "insufficient size of the output buffer");
        if (imax)
        {
            assert(limits);
            const Interval<unsigned>* data = &(*this)[0];
            for (unsigned i=0; i<imax; ++i)
                limits[i] = data[i].min();
        }
    }
bool npstat::ArrayRange::operator< ( const ArrayRange r) const

Operator for use with maps

Definition at line 40 of file ArrayRange.cc.

References i, npstat::Interval< Numeric >::max(), npstat::Interval< Numeric >::min(), and findQualityFiles::size.

    {
        const unsigned mysize = this->size();
        const unsigned othersize = r.size();
        if (mysize < othersize)
            return true;
        if (mysize > othersize)
            return false;
        for (unsigned i=0; i<mysize; ++i)
        {
            const Interval<unsigned>& left((*this)[i]);
            const Interval<unsigned>& right(r[i]);
            if (left.min() < right.min())
                return true;
            if (left.min() > right.min())
                return false;
            if (left.max() < right.max())
                return true;
            if (left.max() > right.max())
                return false;
        }
        return false;
    }
void npstat::ArrayRange::rangeLength ( unsigned *  range,
unsigned  rangeLen 
) const

Get the range into an array

Definition at line 131 of file ArrayRange.cc.

References data, i, and findQualityFiles::size.

Referenced by npstat::ArrayND< Numeric, StackLen, StackDim >::ArrayND().

    {
        const unsigned imax = this->size();
        if (limitsLen < imax) throw npstat::NpstatInvalidArgument(
            "In npstat::ArrayRange::rangeLength: "
            "insufficient size of the output buffer");
        if (imax)
        {
            assert(limits);
            const Interval<unsigned>* data = &(*this)[0];
            for (unsigned i=0; i<imax; ++i)
                limits[i] = data[i].length();
        }
    }
unsigned long npstat::ArrayRange::rangeSize ( ) const

How many elements will be iterated over?

Definition at line 77 of file ArrayRange.cc.

References i, query::result, and findQualityFiles::size.

Referenced by npstat::ArrayND< Numeric, StackLen, StackDim >::ArrayND().

    {
        unsigned long result = 0UL;
        const unsigned imax = this->size();
        if (imax)
        {
            result = 1UL;
            for (unsigned i=0; i<imax; ++i)
                result *= (*this)[i].length();
        }
        return result;
    }
ArrayShape npstat::ArrayRange::shape ( void  ) const

The shape which corresponds to this range (i.e., max - min in all dimensions)

Definition at line 90 of file ArrayRange.cc.

References i, and findQualityFiles::size.

    {
        const unsigned imax = this->size();
        ArrayShape oshape(imax);
        for (unsigned i=0; i<imax; ++i)
            oshape[i] = (*this)[i].length();
        return oshape;
    }
ArrayRange & npstat::ArrayRange::stripOuterLayer ( )

This method changes the range of this object so that for each dimension the minimum becomes larger by 1 and the maximum smaller by 1.

Definition at line 64 of file ArrayRange.cc.

References i, min, and findQualityFiles::size.

    {
        const unsigned mysize = this->size();
        for (unsigned i=0; i<mysize; ++i)
        {
            (*this)[i].setMin((*this)[i].min() + 1U);
            const unsigned uplim = (*this)[i].max();
            if (uplim)
                (*this)[i].setMax(uplim - 1U);
        }
        return *this;
    }
void npstat::ArrayRange::upperLimits ( unsigned *  limits,
unsigned  limitsLen 
) const

Get the upper range limits into an array

Definition at line 115 of file ArrayRange.cc.

References data, i, max(), and findQualityFiles::size.

    {
        const unsigned imax = this->size();
        if (limitsLen < imax) throw npstat::NpstatInvalidArgument(
            "In npstat::ArrayRange::upperLimits: "
            "insufficient size of the output buffer");
        if (imax)
        {
            assert(limits);
            const Interval<unsigned>* data = &(*this)[0];
            for (unsigned i=0; i<imax; ++i)
                limits[i] = data[i].max();
        }
    }