CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/JetMETCorrections/InterpolationTables/interface/ArrayNDScanner.h

Go to the documentation of this file.
00001 #ifndef NPSTAT_ARRAYNDSCANNER_HH_
00002 #define NPSTAT_ARRAYNDSCANNER_HH_
00003 
00014 #include <vector>
00015 #include <climits>
00016 
00017 namespace npstat {
00036     class ArrayNDScanner
00037     {
00038     public:
00040 
00041         inline ArrayNDScanner(const unsigned* shape, const unsigned lenShape)
00042             {initialize(shape, lenShape);}
00043 
00044         inline ArrayNDScanner(const std::vector<unsigned>& shape)
00045             {initialize(shape.empty() ? static_cast<unsigned*>(0) : 
00046                         &shape[0], shape.size());}
00048 
00050         inline unsigned dim() const {return dim_;}
00051 
00053         inline unsigned long state() const {return state_;}
00054 
00056         inline unsigned long maxState() const {return maxState_;}
00057 
00059         inline bool isValid() const {return state_ < maxState_;}
00060 
00062         void getIndex(unsigned* index, unsigned indexBufferLen) const;
00063 
00065         inline void reset() {state_ = 0UL;}
00066 
00068         inline ArrayNDScanner& operator++()
00069             {if (state_ < maxState_) ++state_; return *this;}
00070 
00072         inline void operator++(int) {if (state_ < maxState_) ++state_;}
00073 
00075         inline void setState(const unsigned long state)
00076             {state_ = state <= maxState_ ? state : maxState_;}
00077 
00078     private:
00079         ArrayNDScanner();
00080         
00081         void initialize(const unsigned* shape, unsigned lenShape);
00082 
00083         unsigned long strides_[CHAR_BIT*sizeof(unsigned long)];
00084         unsigned long state_;
00085         unsigned long maxState_;
00086         unsigned dim_;
00087     };
00088 }
00089 
00090 #endif // NPSTAT_ARRAYSCANNER_HH_
00091