File indexing completed on 2024-04-06 12:04:21
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #include <Utilities/Testing/interface/CppUnit_testdriver.icpp>
0015 #include <cppunit/extensions/HelperMacros.h>
0016
0017
0018 #include "DataFormats/Histograms/interface/MEtoEDMFormat.h"
0019 #include "TAxis.h"
0020
0021 class TestMEtoEDMFormat : public CppUnit::TestFixture {
0022 CPPUNIT_TEST_SUITE(TestMEtoEDMFormat);
0023 CPPUNIT_TEST(testMergeInt64);
0024 CPPUNIT_TEST(testMergeDouble);
0025 CPPUNIT_TEST(testMergeTString);
0026 CPPUNIT_TEST(testMergeT);
0027 CPPUNIT_TEST_SUITE_END();
0028
0029 public:
0030 void testMergeInt64();
0031 void testMergeDouble();
0032 void testMergeTString();
0033 void testMergeT();
0034 void setUp() override {}
0035 void tearDown() override {}
0036 };
0037
0038
0039 CPPUNIT_TEST_SUITE_REGISTRATION(TestMEtoEDMFormat);
0040
0041 template <typename T>
0042 bool areEquivalent(const MEtoEDM<T>& iLHS, const MEtoEDM<T>& iRHS) {
0043 if (iLHS.getMEtoEdmObject().size() != iRHS.getMEtoEdmObject().size()) {
0044 std::cout << "areEquivalent failure: sizes are different" << std::endl;
0045 return false;
0046 }
0047 typedef typename MEtoEDM<T>::MEtoEdmObjectVector Vec;
0048 typename Vec::const_iterator itRHS = iRHS.getMEtoEdmObject().begin();
0049 for (typename Vec::const_iterator itLHS = iLHS.getMEtoEdmObject().begin(), itLHSEnd = iLHS.getMEtoEdmObject().end();
0050 itLHS != itLHSEnd;
0051 ++itLHS, ++itRHS) {
0052 if (itLHS->name != itRHS->name || itLHS->tags != itRHS->tags || itLHS->object != itRHS->object) {
0053 std::cout << "areEquivalent failure: elements '" << (itLHS->name) << "' " << (itLHS->object) << " and '"
0054 << (itRHS->name) << "' " << (itRHS->object) << " are different" << std::endl;
0055 return false;
0056 }
0057 }
0058 return true;
0059 }
0060
0061 void TestMEtoEDMFormat::testMergeInt64() {
0062 MEtoEDM<long long> empty(0);
0063
0064 MEtoEDM<long long> full(3);
0065 full.putMEtoEdmObject("a", 1);
0066 full.putMEtoEdmObject("b", 2);
0067 full.putMEtoEdmObject("c", 3);
0068
0069 MEtoEDM<long long> fullReordered(3);
0070 fullReordered.putMEtoEdmObject("b", 2);
0071 fullReordered.putMEtoEdmObject("a", 1);
0072 fullReordered.putMEtoEdmObject("c", 3);
0073
0074 MEtoEDM<long long> toMerge(full);
0075
0076
0077 CPPUNIT_ASSERT(areEquivalent(toMerge, full));
0078
0079 toMerge.mergeProduct(empty);
0080 CPPUNIT_ASSERT(areEquivalent(toMerge, full));
0081
0082 MEtoEDM<long long> toMerge2(empty);
0083 toMerge2.mergeProduct(full);
0084 CPPUNIT_ASSERT(areEquivalent(toMerge2, full));
0085
0086 MEtoEDM<long long> toMerge3(full);
0087 toMerge3.mergeProduct(fullReordered);
0088 CPPUNIT_ASSERT(areEquivalent(toMerge3, full));
0089
0090 MEtoEDM<long long> part1(2);
0091 part1.putMEtoEdmObject("a", 1);
0092 part1.putMEtoEdmObject("b", 2);
0093 MEtoEDM<long long> part2(1);
0094 part2.putMEtoEdmObject("c", 3);
0095 part1.mergeProduct(part2);
0096 CPPUNIT_ASSERT(areEquivalent(part1, full));
0097
0098 MEtoEDM<long long> specials1(3);
0099 specials1.putMEtoEdmObject("EventInfo/processedEvents", 1);
0100 specials1.putMEtoEdmObject("EventInfo/iEvent", 2);
0101 specials1.putMEtoEdmObject("EventInfo/iLumiSection", 3);
0102
0103 MEtoEDM<long long> specials2(3);
0104 specials2.putMEtoEdmObject("EventInfo/processedEvents", 1);
0105 specials2.putMEtoEdmObject("EventInfo/iEvent", 3);
0106 specials2.putMEtoEdmObject("EventInfo/iLumiSection", 2);
0107
0108 MEtoEDM<long long> specialsTotal(3);
0109 specialsTotal.putMEtoEdmObject("EventInfo/processedEvents", 2);
0110 specialsTotal.putMEtoEdmObject("EventInfo/iEvent", 3);
0111 specialsTotal.putMEtoEdmObject("EventInfo/iLumiSection", 3);
0112 specials1.mergeProduct(specials2);
0113 CPPUNIT_ASSERT(areEquivalent(specials1, specialsTotal));
0114 }
0115
0116 void TestMEtoEDMFormat::testMergeDouble() {
0117 MEtoEDM<double> empty(0);
0118
0119 MEtoEDM<double> full(3);
0120 full.putMEtoEdmObject("a", 1);
0121 full.putMEtoEdmObject("b", 2);
0122 full.putMEtoEdmObject("c", 3);
0123
0124 MEtoEDM<double> fullReordered(3);
0125 fullReordered.putMEtoEdmObject("b", 2);
0126 fullReordered.putMEtoEdmObject("a", 1);
0127 fullReordered.putMEtoEdmObject("c", 3);
0128
0129 MEtoEDM<double> toMerge(full);
0130
0131
0132 CPPUNIT_ASSERT(areEquivalent(toMerge, full));
0133
0134 toMerge.mergeProduct(empty);
0135 CPPUNIT_ASSERT(areEquivalent(toMerge, full));
0136
0137 MEtoEDM<double> toMerge2(empty);
0138 toMerge2.mergeProduct(full);
0139 CPPUNIT_ASSERT(areEquivalent(toMerge2, full));
0140
0141 MEtoEDM<double> toMerge3(full);
0142 toMerge3.mergeProduct(fullReordered);
0143 CPPUNIT_ASSERT(areEquivalent(toMerge3, full));
0144
0145 MEtoEDM<double> part1(2);
0146 part1.putMEtoEdmObject("a", 1);
0147 part1.putMEtoEdmObject("b", 2);
0148 MEtoEDM<double> part2(1);
0149 part2.putMEtoEdmObject("c", 3);
0150 part1.mergeProduct(part2);
0151 CPPUNIT_ASSERT(areEquivalent(part1, full));
0152 }
0153
0154
0155
0156
0157
0158
0159
0160
0161 void TestMEtoEDMFormat::testMergeTString() {
0162 MEtoEDM<TString> empty(0);
0163
0164 MEtoEDM<TString> full(3);
0165 full.putMEtoEdmObject("a", "1");
0166 full.putMEtoEdmObject("b", "2");
0167 full.putMEtoEdmObject("c", "3");
0168
0169 MEtoEDM<TString> fullReordered(3);
0170 fullReordered.putMEtoEdmObject("b", "2");
0171 fullReordered.putMEtoEdmObject("a", "1");
0172 fullReordered.putMEtoEdmObject("c", "3");
0173
0174 MEtoEDM<TString> toMerge(full);
0175
0176
0177 CPPUNIT_ASSERT(areEquivalent(toMerge, full));
0178
0179 toMerge.mergeProduct(empty);
0180 CPPUNIT_ASSERT(areEquivalent(toMerge, full));
0181
0182 MEtoEDM<TString> toMerge2(empty);
0183 toMerge2.mergeProduct(full);
0184 CPPUNIT_ASSERT(areEquivalent(toMerge2, full));
0185
0186 MEtoEDM<TString> toMerge3(full);
0187 toMerge3.mergeProduct(fullReordered);
0188 CPPUNIT_ASSERT(areEquivalent(toMerge3, full));
0189
0190 MEtoEDM<TString> part1(2);
0191 part1.putMEtoEdmObject("a", "1");
0192 part1.putMEtoEdmObject("b", "2");
0193 MEtoEDM<TString> part2(1);
0194 part2.putMEtoEdmObject("c", "3");
0195 part1.mergeProduct(part2);
0196 CPPUNIT_ASSERT(areEquivalent(part1, full));
0197 }
0198
0199 namespace {
0200 const TAxis dummy(1.0, 0.0, 1.0);
0201
0202 struct Dummy {
0203 Dummy(int i) : m_i(i) {}
0204 Dummy() : m_i(0) {}
0205 void Add(const Dummy* iOther) {
0206 m_i += iOther->m_i;
0207
0208 }
0209
0210 bool operator!=(const Dummy& iOther) const { return m_i != iOther.m_i; }
0211
0212 int GetNbinsX() const { return 1; }
0213 int GetNbinsY() const { return 1; }
0214 int GetNbinsZ() const { return 1; }
0215
0216 const TAxis* GetXaxis() const { return &dummy; }
0217 const TAxis* GetYaxis() const { return &dummy; }
0218 const TAxis* GetZaxis() const { return &dummy; }
0219
0220 bool CanExtendAllAxes() const { return false; }
0221 long long Merge(void*) { return -1; }
0222
0223 int m_i;
0224 };
0225
0226 std::ostream& operator<<(std::ostream& os, const Dummy& iDummy) {
0227 os << iDummy.m_i;
0228 return os;
0229 }
0230
0231 }
0232
0233 void TestMEtoEDMFormat::testMergeT() {
0234 MEtoEDM<Dummy> empty(0);
0235
0236 MEtoEDM<Dummy> full(3);
0237 full.putMEtoEdmObject("a", 1);
0238 full.putMEtoEdmObject("b", 2);
0239 full.putMEtoEdmObject("c", 3);
0240
0241 MEtoEDM<Dummy> fullReordered(3);
0242 fullReordered.putMEtoEdmObject("b", 2);
0243 fullReordered.putMEtoEdmObject("a", 1);
0244 fullReordered.putMEtoEdmObject("c", 3);
0245
0246 MEtoEDM<Dummy> doubleFull(3);
0247 doubleFull.putMEtoEdmObject("a", 2 * 1);
0248 doubleFull.putMEtoEdmObject("b", 2 * 2);
0249 doubleFull.putMEtoEdmObject("c", 2 * 3);
0250
0251 MEtoEDM<Dummy> toMerge(full);
0252
0253
0254 CPPUNIT_ASSERT(areEquivalent(toMerge, full));
0255
0256 toMerge.mergeProduct(empty);
0257 CPPUNIT_ASSERT(areEquivalent(toMerge, full));
0258
0259 MEtoEDM<Dummy> toMerge2(empty);
0260 toMerge2.mergeProduct(full);
0261 CPPUNIT_ASSERT(areEquivalent(toMerge2, full));
0262
0263 MEtoEDM<Dummy> toMerge3(full);
0264 toMerge3.mergeProduct(fullReordered);
0265 CPPUNIT_ASSERT(areEquivalent(toMerge3, doubleFull));
0266
0267 MEtoEDM<Dummy> part1(2);
0268 part1.putMEtoEdmObject("a", 1);
0269 part1.putMEtoEdmObject("b", 2);
0270 MEtoEDM<Dummy> part2(1);
0271 part2.putMEtoEdmObject("c", 3);
0272 part1.mergeProduct(part2);
0273 CPPUNIT_ASSERT(areEquivalent(part1, full));
0274 }