Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:21:29

0001 #ifndef NPSTAT_ARRAYRANGE_HH_
0002 #define NPSTAT_ARRAYRANGE_HH_
0003 
0004 /*!
0005 // \file ArrayRange.h
0006 //
0007 // \brief Multidimensional range of array indices
0008 //
0009 // Author: I. Volobouev
0010 //
0011 // October 2009
0012 */
0013 
0014 #include "JetMETCorrections/InterpolationTables/interface/ArrayShape.h"
0015 #include "JetMETCorrections/InterpolationTables/interface/BoxND.h"
0016 
0017 namespace npstat {
0018   /**
0019     // Utility class for use in certain array iterations
0020     */
0021   struct ArrayRange : public BoxND<unsigned> {
0022     inline ArrayRange() {}
0023 
0024     /** Constructor from a given number of dimensions */
0025     inline explicit ArrayRange(unsigned dim) : BoxND<unsigned>(dim) {}
0026 
0027     /** The given interval is repeated for every dimension */
0028     inline ArrayRange(unsigned dim, const Interval<unsigned>& r1) : BoxND<unsigned>(dim, r1) {}
0029 
0030     //@{
0031     /**
0032         // Constructor which creates a range out of a shape
0033         // which is used to represent the upper limit. The
0034         // lower limit in each dimension is set to 0.
0035         */
0036     inline explicit ArrayRange(const ArrayShape& shape) : BoxND<unsigned>(shape) {}
0037     ArrayRange(const unsigned* shape, unsigned shapeLen);
0038     //@}
0039 
0040     /**
0041         // The shape which corresponds to this range
0042         // (i.e., max - min in all dimensions)
0043         */
0044     ArrayShape shape() const;
0045 
0046     //@{
0047     /** Check for compatibility with a shape */
0048     bool isCompatible(const ArrayShape& shape) const;
0049     bool isCompatible(const unsigned* shape, unsigned shapeLen) const;
0050     //@}
0051 
0052     /** How many elements will be iterated over? */
0053     unsigned long rangeSize() const;
0054 
0055     /** Operator for use with maps */
0056     bool operator<(const ArrayRange&) const;
0057 
0058     /**
0059         // This method changes the range of this object so that
0060         // for each dimension the minimum becomes larger by 1 and the
0061         // maximum smaller by 1.
0062         */
0063     ArrayRange& stripOuterLayer();
0064 
0065     /**
0066         // Get the lower range limits into an array. The length of
0067         // the limit array should be at least equal to the dimensionality.
0068         */
0069     void lowerLimits(unsigned* limits, unsigned limitsLen) const;
0070 
0071     /** Get the upper range limits into an array */
0072     void upperLimits(unsigned* limits, unsigned limitsLen) const;
0073 
0074     /** Get the range into an array */
0075     void rangeLength(unsigned* range, unsigned rangeLen) const;
0076   };
0077 }  // namespace npstat
0078 
0079 #endif  // NPSTAT_ARRAYRANGE_HH_