Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-10-25 09:53:58

0001 #include "JetMETCorrections/InterpolationTables/interface/NpstatException.h"
0002 #include "JetMETCorrections/InterpolationTables/interface/ArrayRange.h"
0003 
0004 namespace npstat {
0005   ArrayRange::ArrayRange(const unsigned* ishape, const unsigned imax) {
0006     if (imax) {
0007       assert(ishape);
0008       this->reserve(imax);
0009       for (unsigned i = 0; i < imax; ++i)
0010         this->push_back(Interval<unsigned>(ishape[i]));
0011     }
0012   }
0013 
0014   bool ArrayRange::isCompatible(const ArrayShape& ishape) const {
0015     const unsigned imax = ishape.size();
0016     return isCompatible(imax ? &ishape[0] : (unsigned*)nullptr, imax);
0017   }
0018 
0019   bool ArrayRange::isCompatible(const unsigned* ishape, const unsigned imax) const {
0020     if (this->size() != imax)
0021       return false;
0022     if (imax) {
0023       assert(ishape);
0024       for (unsigned i = 0; i < imax; ++i)
0025         if ((*this)[i].length() == 0U)
0026           return true;
0027       for (unsigned i = 0; i < imax; ++i)
0028         if ((*this)[i].max() > ishape[i])
0029           return false;
0030     }
0031     return true;
0032   }
0033 
0034   bool ArrayRange::operator<(const ArrayRange& r) const {
0035     const unsigned mysize = this->size();
0036     const unsigned othersize = r.size();
0037     if (mysize < othersize)
0038       return true;
0039     if (mysize > othersize)
0040       return false;
0041     for (unsigned i = 0; i < mysize; ++i) {
0042       const Interval<unsigned>& left((*this)[i]);
0043       const Interval<unsigned>& right(r[i]);
0044       if (left.min() < right.min())
0045         return true;
0046       if (left.min() > right.min())
0047         return false;
0048       if (left.max() < right.max())
0049         return true;
0050       if (left.max() > right.max())
0051         return false;
0052     }
0053     return false;
0054   }
0055 
0056   ArrayRange& ArrayRange::stripOuterLayer() {
0057     const unsigned mysize = this->size();
0058     for (unsigned i = 0; i < mysize; ++i) {
0059       (*this)[i].setMin((*this)[i].min() + 1U);
0060       const unsigned uplim = (*this)[i].max();
0061       if (uplim)
0062         (*this)[i].setMax(uplim - 1U);
0063     }
0064     return *this;
0065   }
0066 
0067   unsigned long ArrayRange::rangeSize() const {
0068     unsigned long result = 0UL;
0069     const unsigned imax = this->size();
0070     if (imax) {
0071       result = 1UL;
0072       for (unsigned i = 0; i < imax; ++i)
0073         result *= (*this)[i].length();
0074     }
0075     return result;
0076   }
0077 
0078   ArrayShape ArrayRange::shape() const {
0079     const unsigned imax = this->size();
0080     ArrayShape oshape(imax);
0081     for (unsigned i = 0; i < imax; ++i)
0082       oshape[i] = (*this)[i].length();
0083     return oshape;
0084   }
0085 
0086   void ArrayRange::lowerLimits(unsigned* limits, const unsigned limitsLen) const {
0087     const unsigned imax = this->size();
0088     if (limitsLen < imax)
0089       throw npstat::NpstatInvalidArgument(
0090           "In npstat::ArrayRange::lowerLimits: "
0091           "insufficient size of the output buffer");
0092     if (imax) {
0093       assert(limits);
0094       const Interval<unsigned>* data = &(*this)[0];
0095       for (unsigned i = 0; i < imax; ++i)
0096         limits[i] = data[i].min();
0097     }
0098   }
0099 
0100   void ArrayRange::upperLimits(unsigned* limits, const unsigned limitsLen) const {
0101     const unsigned imax = this->size();
0102     if (limitsLen < imax)
0103       throw npstat::NpstatInvalidArgument(
0104           "In npstat::ArrayRange::upperLimits: "
0105           "insufficient size of the output buffer");
0106     if (imax) {
0107       assert(limits);
0108       const Interval<unsigned>* data = &(*this)[0];
0109       for (unsigned i = 0; i < imax; ++i)
0110         limits[i] = data[i].max();
0111     }
0112   }
0113 
0114   void ArrayRange::rangeLength(unsigned* limits, const unsigned limitsLen) const {
0115     const unsigned imax = this->size();
0116     if (limitsLen < imax)
0117       throw npstat::NpstatInvalidArgument(
0118           "In npstat::ArrayRange::rangeLength: "
0119           "insufficient size of the output buffer");
0120     if (imax) {
0121       assert(limits);
0122       const Interval<unsigned>* data = &(*this)[0];
0123       for (unsigned i = 0; i < imax; ++i)
0124         limits[i] = data[i].length();
0125     }
0126   }
0127 }  // namespace npstat