File indexing completed on 2024-04-06 12:19:22
0001 #include <cassert>
0002 #include "JetMETCorrections/InterpolationTables/interface/NpstatException.h"
0003
0004 #include "JetMETCorrections/InterpolationTables/interface/ArrayShape.h"
0005
0006 namespace npstat {
0007 ArrayShape makeShape() { return ArrayShape(); }
0008
0009 ArrayShape makeShape(unsigned i0) { return ArrayShape(1, i0); }
0010
0011 ArrayShape makeShape(unsigned i0, unsigned i1) {
0012 ArrayShape s;
0013 s.reserve(2);
0014 s.push_back(i0);
0015 s.push_back(i1);
0016 return s;
0017 }
0018
0019 ArrayShape makeShape(unsigned i0, unsigned i1, unsigned i2) {
0020 ArrayShape s;
0021 s.reserve(3);
0022 s.push_back(i0);
0023 s.push_back(i1);
0024 s.push_back(i2);
0025 return s;
0026 }
0027
0028 ArrayShape makeShape(unsigned i0, unsigned i1, unsigned i2, unsigned i3) {
0029 ArrayShape s;
0030 s.reserve(4);
0031 s.push_back(i0);
0032 s.push_back(i1);
0033 s.push_back(i2);
0034 s.push_back(i3);
0035 return s;
0036 }
0037
0038 ArrayShape makeShape(unsigned i0, unsigned i1, unsigned i2, unsigned i3, unsigned i4) {
0039 ArrayShape s;
0040 s.reserve(5);
0041 s.push_back(i0);
0042 s.push_back(i1);
0043 s.push_back(i2);
0044 s.push_back(i3);
0045 s.push_back(i4);
0046 return s;
0047 }
0048
0049 ArrayShape makeShape(unsigned i0, unsigned i1, unsigned i2, unsigned i3, unsigned i4, unsigned i5) {
0050 ArrayShape s;
0051 s.reserve(6);
0052 s.push_back(i0);
0053 s.push_back(i1);
0054 s.push_back(i2);
0055 s.push_back(i3);
0056 s.push_back(i4);
0057 s.push_back(i5);
0058 return s;
0059 }
0060
0061 ArrayShape makeShape(unsigned i0, unsigned i1, unsigned i2, unsigned i3, unsigned i4, unsigned i5, unsigned i6) {
0062 ArrayShape s;
0063 s.reserve(7);
0064 s.push_back(i0);
0065 s.push_back(i1);
0066 s.push_back(i2);
0067 s.push_back(i3);
0068 s.push_back(i4);
0069 s.push_back(i5);
0070 s.push_back(i6);
0071 return s;
0072 }
0073
0074 ArrayShape makeShape(
0075 unsigned i0, unsigned i1, unsigned i2, unsigned i3, unsigned i4, unsigned i5, unsigned i6, unsigned i7) {
0076 ArrayShape s;
0077 s.reserve(8);
0078 s.push_back(i0);
0079 s.push_back(i1);
0080 s.push_back(i2);
0081 s.push_back(i3);
0082 s.push_back(i4);
0083 s.push_back(i5);
0084 s.push_back(i6);
0085 s.push_back(i7);
0086 return s;
0087 }
0088
0089 ArrayShape makeShape(unsigned i0,
0090 unsigned i1,
0091 unsigned i2,
0092 unsigned i3,
0093 unsigned i4,
0094 unsigned i5,
0095 unsigned i6,
0096 unsigned i7,
0097 unsigned i8) {
0098 ArrayShape s;
0099 s.reserve(9);
0100 s.push_back(i0);
0101 s.push_back(i1);
0102 s.push_back(i2);
0103 s.push_back(i3);
0104 s.push_back(i4);
0105 s.push_back(i5);
0106 s.push_back(i6);
0107 s.push_back(i7);
0108 s.push_back(i8);
0109 return s;
0110 }
0111
0112 ArrayShape makeShape(unsigned i0,
0113 unsigned i1,
0114 unsigned i2,
0115 unsigned i3,
0116 unsigned i4,
0117 unsigned i5,
0118 unsigned i6,
0119 unsigned i7,
0120 unsigned i8,
0121 unsigned i9) {
0122 ArrayShape s;
0123 s.reserve(10);
0124 s.push_back(i0);
0125 s.push_back(i1);
0126 s.push_back(i2);
0127 s.push_back(i3);
0128 s.push_back(i4);
0129 s.push_back(i5);
0130 s.push_back(i6);
0131 s.push_back(i7);
0132 s.push_back(i8);
0133 s.push_back(i9);
0134 return s;
0135 }
0136
0137 ArrayShape makeShape(const unsigned* indices, const unsigned nIndices) {
0138 ArrayShape s;
0139 if (nIndices) {
0140 assert(indices);
0141 s.reserve(nIndices);
0142 for (unsigned i = 0; i < nIndices; ++i)
0143 s.push_back(indices[i]);
0144 }
0145 return s;
0146 }
0147
0148 ArrayShape doubleShape(const ArrayShape& inputShape) {
0149 ArrayShape s(inputShape);
0150 const unsigned len = s.size();
0151 for (unsigned i = 0; i < len; ++i)
0152 s[i] *= 2U;
0153 return s;
0154 }
0155
0156 ArrayShape halfShape(const ArrayShape& inputShape) {
0157 ArrayShape s(inputShape);
0158 const unsigned len = s.size();
0159 for (unsigned i = 0; i < len; ++i) {
0160 if (!(s[i] % 2U == 0))
0161 throw npstat::NpstatInvalidArgument(
0162 "In npstat::halfShape: array span must be "
0163 "even in each dimension");
0164 s[i] /= 2U;
0165 }
0166 return s;
0167 }
0168
0169 bool isSubShape(const ArrayShape& sh1, const ArrayShape& sh2) {
0170 const unsigned len = sh1.size();
0171 if (len != sh2.size())
0172 return false;
0173 for (unsigned i = 0; i < len; ++i)
0174 if (sh1[i] > sh2[i])
0175 return false;
0176 return true;
0177 }
0178 }