CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/JetMETCorrections/InterpolationTables/src/ArrayRange.cc

Go to the documentation of this file.
00001 #include "JetMETCorrections/InterpolationTables/interface/NpstatException.h"
00002 #include "JetMETCorrections/InterpolationTables/interface/ArrayRange.h"
00003 
00004 namespace npstat {
00005     ArrayRange::ArrayRange(const unsigned* ishape, const unsigned imax)
00006     {
00007         if (imax)
00008         {
00009             assert(ishape);
00010             this->reserve(imax);
00011             for (unsigned i=0; i<imax; ++i)
00012                 this->push_back(Interval<unsigned>(ishape[i]));
00013         }
00014     }
00015 
00016     bool ArrayRange::isCompatible(const ArrayShape& ishape) const
00017     {
00018         const unsigned imax = ishape.size();
00019         return isCompatible(imax ? &ishape[0] : (unsigned*)0, imax);
00020     }
00021 
00022     bool ArrayRange::isCompatible(const unsigned* ishape,
00023                                   const unsigned imax) const
00024     {
00025         if (this->size() != imax)
00026             return false;
00027         if (imax)
00028         {
00029             assert(ishape);
00030             for (unsigned i=0; i<imax; ++i)
00031                 if ((*this)[i].length() == 0U)
00032                     return true;
00033             for (unsigned i=0; i<imax; ++i)
00034                 if ((*this)[i].max() > ishape[i])
00035                     return false;
00036         }
00037         return true;
00038     }
00039 
00040     bool ArrayRange::operator<(const ArrayRange& r) const
00041     {
00042         const unsigned mysize = this->size();
00043         const unsigned othersize = r.size();
00044         if (mysize < othersize)
00045             return true;
00046         if (mysize > othersize)
00047             return false;
00048         for (unsigned i=0; i<mysize; ++i)
00049         {
00050             const Interval<unsigned>& left((*this)[i]);
00051             const Interval<unsigned>& right(r[i]);
00052             if (left.min() < right.min())
00053                 return true;
00054             if (left.min() > right.min())
00055                 return false;
00056             if (left.max() < right.max())
00057                 return true;
00058             if (left.max() > right.max())
00059                 return false;
00060         }
00061         return false;
00062     }
00063 
00064     ArrayRange& ArrayRange::stripOuterLayer()
00065     {
00066         const unsigned mysize = this->size();
00067         for (unsigned i=0; i<mysize; ++i)
00068         {
00069             (*this)[i].setMin((*this)[i].min() + 1U);
00070             const unsigned uplim = (*this)[i].max();
00071             if (uplim)
00072                 (*this)[i].setMax(uplim - 1U);
00073         }
00074         return *this;
00075     }
00076 
00077     unsigned long ArrayRange::rangeSize() const
00078     {
00079         unsigned long result = 0UL;
00080         const unsigned imax = this->size();
00081         if (imax)
00082         {
00083             result = 1UL;
00084             for (unsigned i=0; i<imax; ++i)
00085                 result *= (*this)[i].length();
00086         }
00087         return result;
00088     }
00089 
00090     ArrayShape ArrayRange::shape() const
00091     {
00092         const unsigned imax = this->size();
00093         ArrayShape oshape(imax);
00094         for (unsigned i=0; i<imax; ++i)
00095             oshape[i] = (*this)[i].length();
00096         return oshape;
00097     }
00098 
00099     void ArrayRange::lowerLimits(unsigned* limits,
00100                                  const unsigned limitsLen) const
00101     {
00102         const unsigned imax = this->size();
00103         if (limitsLen < imax) throw npstat::NpstatInvalidArgument(
00104             "In npstat::ArrayRange::lowerLimits: "
00105             "insufficient size of the output buffer");
00106         if (imax)
00107         {
00108             assert(limits);
00109             const Interval<unsigned>* data = &(*this)[0];
00110             for (unsigned i=0; i<imax; ++i)
00111                 limits[i] = data[i].min();
00112         }
00113     }
00114 
00115     void ArrayRange::upperLimits(unsigned* limits,
00116                                  const unsigned limitsLen) const
00117     {
00118         const unsigned imax = this->size();
00119         if (limitsLen < imax) throw npstat::NpstatInvalidArgument(
00120             "In npstat::ArrayRange::upperLimits: "
00121             "insufficient size of the output buffer");
00122         if (imax)
00123         {
00124             assert(limits);
00125             const Interval<unsigned>* data = &(*this)[0];
00126             for (unsigned i=0; i<imax; ++i)
00127                 limits[i] = data[i].max();
00128         }
00129     }
00130 
00131     void ArrayRange::rangeLength(unsigned* limits,
00132                                  const unsigned limitsLen) const
00133     {
00134         const unsigned imax = this->size();
00135         if (limitsLen < imax) throw npstat::NpstatInvalidArgument(
00136             "In npstat::ArrayRange::rangeLength: "
00137             "insufficient size of the output buffer");
00138         if (imax)
00139         {
00140             assert(limits);
00141             const Interval<unsigned>* data = &(*this)[0];
00142             for (unsigned i=0; i<imax; ++i)
00143                 limits[i] = data[i].length();
00144         }
00145     }
00146 }