00001 #include <cassert> 00002 #include "JetMETCorrections/InterpolationTables/interface/NpstatException.h" 00003 00004 #include "JetMETCorrections/InterpolationTables/interface/ArrayShape.h" 00005 00006 namespace npstat { 00007 ArrayShape makeShape() 00008 { 00009 return ArrayShape(); 00010 } 00011 00012 ArrayShape makeShape(unsigned i0) 00013 { 00014 return ArrayShape(1, i0); 00015 } 00016 00017 ArrayShape makeShape(unsigned i0, unsigned i1) 00018 { 00019 ArrayShape s; 00020 s.reserve(2); 00021 s.push_back(i0); 00022 s.push_back(i1); 00023 return s; 00024 } 00025 00026 ArrayShape makeShape(unsigned i0, unsigned i1, unsigned i2) 00027 { 00028 ArrayShape s; 00029 s.reserve(3); 00030 s.push_back(i0); 00031 s.push_back(i1); 00032 s.push_back(i2); 00033 return s; 00034 } 00035 00036 ArrayShape makeShape(unsigned i0, unsigned i1, unsigned i2, unsigned i3) 00037 { 00038 ArrayShape s; 00039 s.reserve(4); 00040 s.push_back(i0); 00041 s.push_back(i1); 00042 s.push_back(i2); 00043 s.push_back(i3); 00044 return s; 00045 } 00046 00047 ArrayShape makeShape(unsigned i0, unsigned i1, unsigned i2, unsigned i3, 00048 unsigned i4) 00049 { 00050 ArrayShape s; 00051 s.reserve(5); 00052 s.push_back(i0); 00053 s.push_back(i1); 00054 s.push_back(i2); 00055 s.push_back(i3); 00056 s.push_back(i4); 00057 return s; 00058 } 00059 00060 ArrayShape makeShape(unsigned i0, unsigned i1, unsigned i2, unsigned i3, 00061 unsigned i4, unsigned i5) 00062 { 00063 ArrayShape s; 00064 s.reserve(6); 00065 s.push_back(i0); 00066 s.push_back(i1); 00067 s.push_back(i2); 00068 s.push_back(i3); 00069 s.push_back(i4); 00070 s.push_back(i5); 00071 return s; 00072 } 00073 00074 ArrayShape makeShape(unsigned i0, unsigned i1, unsigned i2, unsigned i3, 00075 unsigned i4, unsigned i5, unsigned i6) 00076 { 00077 ArrayShape s; 00078 s.reserve(7); 00079 s.push_back(i0); 00080 s.push_back(i1); 00081 s.push_back(i2); 00082 s.push_back(i3); 00083 s.push_back(i4); 00084 s.push_back(i5); 00085 s.push_back(i6); 00086 return s; 00087 } 00088 00089 ArrayShape makeShape(unsigned i0, unsigned i1, unsigned i2, unsigned i3, 00090 unsigned i4, unsigned i5, unsigned i6, unsigned i7) 00091 { 00092 ArrayShape s; 00093 s.reserve(8); 00094 s.push_back(i0); 00095 s.push_back(i1); 00096 s.push_back(i2); 00097 s.push_back(i3); 00098 s.push_back(i4); 00099 s.push_back(i5); 00100 s.push_back(i6); 00101 s.push_back(i7); 00102 return s; 00103 } 00104 00105 ArrayShape makeShape(unsigned i0, unsigned i1, unsigned i2, unsigned i3, 00106 unsigned i4, unsigned i5, unsigned i6, unsigned i7, 00107 unsigned i8) 00108 { 00109 ArrayShape s; 00110 s.reserve(9); 00111 s.push_back(i0); 00112 s.push_back(i1); 00113 s.push_back(i2); 00114 s.push_back(i3); 00115 s.push_back(i4); 00116 s.push_back(i5); 00117 s.push_back(i6); 00118 s.push_back(i7); 00119 s.push_back(i8); 00120 return s; 00121 } 00122 00123 ArrayShape makeShape(unsigned i0, unsigned i1, unsigned i2, unsigned i3, 00124 unsigned i4, unsigned i5, unsigned i6, unsigned i7, 00125 unsigned i8, unsigned i9) 00126 { 00127 ArrayShape s; 00128 s.reserve(10); 00129 s.push_back(i0); 00130 s.push_back(i1); 00131 s.push_back(i2); 00132 s.push_back(i3); 00133 s.push_back(i4); 00134 s.push_back(i5); 00135 s.push_back(i6); 00136 s.push_back(i7); 00137 s.push_back(i8); 00138 s.push_back(i9); 00139 return s; 00140 } 00141 00142 ArrayShape makeShape(const unsigned* indices, const unsigned nIndices) 00143 { 00144 ArrayShape s; 00145 if (nIndices) 00146 { 00147 assert(indices); 00148 s.reserve(nIndices); 00149 for (unsigned i=0; i<nIndices; ++i) 00150 s.push_back(indices[i]); 00151 } 00152 return s; 00153 } 00154 00155 ArrayShape doubleShape(const ArrayShape& inputShape) 00156 { 00157 ArrayShape s(inputShape); 00158 const unsigned len = s.size(); 00159 for (unsigned i=0; i<len; ++i) 00160 s[i] *= 2U; 00161 return s; 00162 } 00163 00164 ArrayShape halfShape(const ArrayShape& inputShape) 00165 { 00166 ArrayShape s(inputShape); 00167 const unsigned len = s.size(); 00168 for (unsigned i=0; i<len; ++i) 00169 { 00170 if (!(s[i] % 2U == 0)) throw npstat::NpstatInvalidArgument( 00171 "In npstat::halfShape: array span must be " 00172 "even in each dimension"); 00173 s[i] /= 2U; 00174 } 00175 return s; 00176 } 00177 00178 bool isSubShape(const ArrayShape& sh1, const ArrayShape& sh2) 00179 { 00180 const unsigned len = sh1.size(); 00181 if (len != sh2.size()) 00182 return false; 00183 for (unsigned i=0; i<len; ++i) 00184 if (sh1[i] > sh2[i]) 00185 return false; 00186 return true; 00187 } 00188 }