File indexing completed on 2023-03-17 10:51:13
0001
0002
0003
0004
0005 #include "cppunit/extensions/HelperMacros.h"
0006
0007 #include "DataFormats/Provenance/interface/ProcessHistoryID.h"
0008 #include "DataFormats/Provenance/interface/ProcessConfiguration.h"
0009 #include "DataFormats/Provenance/interface/ProcessHistory.h"
0010
0011 #include "DataFormats/Provenance/interface/IndexIntoFile.h"
0012
0013 #include <string>
0014 #include <iostream>
0015 #include <memory>
0016
0017 using namespace edm;
0018
0019 class TestIndexIntoFile5 : public CppUnit::TestFixture {
0020 CPPUNIT_TEST_SUITE(TestIndexIntoFile5);
0021 CPPUNIT_TEST(testDuplicateCheckerFunctions);
0022 CPPUNIT_TEST_SUITE_END();
0023
0024 public:
0025 static const IndexIntoFile::EntryType kRun = IndexIntoFile::kRun;
0026 static const IndexIntoFile::EntryType kLumi = IndexIntoFile::kLumi;
0027 static const IndexIntoFile::EntryType kEvent = IndexIntoFile::kEvent;
0028 static const IndexIntoFile::EntryType kEnd = IndexIntoFile::kEnd;
0029
0030 class Skipped {
0031 public:
0032 Skipped() : phIndexOfSkippedEvent_(0), runOfSkippedEvent_(0), lumiOfSkippedEvent_(0), skippedEventEntry_(0) {}
0033 int phIndexOfSkippedEvent_;
0034 RunNumber_t runOfSkippedEvent_;
0035 LuminosityBlockNumber_t lumiOfSkippedEvent_;
0036 IndexIntoFile::EntryNumber_t skippedEventEntry_;
0037 };
0038
0039 Skipped skipped_;
0040
0041 void setUp() {
0042
0043 nullPHID = ProcessHistoryID();
0044
0045 ProcessConfiguration pc;
0046 auto processHistory1 = std::make_unique<ProcessHistory>();
0047 ProcessHistory& ph1 = *processHistory1;
0048 processHistory1->push_back(pc);
0049 fakePHID1 = ph1.id();
0050
0051 auto processHistory2 = std::make_unique<ProcessHistory>();
0052 ProcessHistory& ph2 = *processHistory2;
0053 processHistory2->push_back(pc);
0054 processHistory2->push_back(pc);
0055 fakePHID2 = ph2.id();
0056
0057 auto processHistory3 = std::make_unique<ProcessHistory>();
0058 ProcessHistory& ph3 = *processHistory3;
0059 processHistory3->push_back(pc);
0060 processHistory3->push_back(pc);
0061 processHistory3->push_back(pc);
0062 fakePHID3 = ph3.id();
0063 }
0064
0065 void tearDown() {}
0066
0067 void testDuplicateCheckerFunctions();
0068
0069 ProcessHistoryID nullPHID;
0070 ProcessHistoryID fakePHID1;
0071 ProcessHistoryID fakePHID2;
0072 ProcessHistoryID fakePHID3;
0073
0074 void check(edm::IndexIntoFile::IndexIntoFileItr const& iter,
0075 IndexIntoFile::EntryType type,
0076 int indexToRun,
0077 int indexToLumi,
0078 int indexToEventRange,
0079 long long indexToEvent,
0080 long long nEvents);
0081
0082
0083 class TestEventFinder : public IndexIntoFile::EventFinder {
0084 public:
0085 explicit TestEventFinder() {}
0086 virtual ~TestEventFinder() {}
0087 virtual EventNumber_t getEventNumberOfEntry(IndexIntoFile::EntryNumber_t entry) const {
0088 return testData_.at(entry);
0089 }
0090 void push_back(EventNumber_t e) { testData_.push_back(e); }
0091
0092 private:
0093 std::vector<EventNumber_t> testData_;
0094 };
0095 };
0096
0097
0098 CPPUNIT_TEST_SUITE_REGISTRATION(TestIndexIntoFile5);
0099
0100 void TestIndexIntoFile5::check(edm::IndexIntoFile::IndexIntoFileItr const& iter,
0101 IndexIntoFile::EntryType type,
0102 int indexToRun,
0103 int indexToLumi,
0104 int indexToEventRange,
0105 long long indexToEvent,
0106 long long nEvents) {
0107 bool theyMatch = iter.getEntryType() == type && iter.type() == type && iter.indexToRun() == indexToRun &&
0108 iter.indexToLumi() == indexToLumi && iter.indexToEventRange() == indexToEventRange &&
0109 iter.indexToEvent() == indexToEvent && iter.nEvents() == nEvents;
0110 if (!theyMatch) {
0111 std::cout << "\nExpected " << type << " " << indexToRun << " " << indexToLumi << " " << indexToEventRange
0112 << " " << indexToEvent << " " << nEvents << "\n";
0113 std::cout << "Iterator values " << iter.type() << " " << iter.indexToRun() << " " << iter.indexToLumi() << " "
0114 << iter.indexToEventRange() << " " << iter.indexToEvent() << " " << iter.nEvents() << "\n";
0115 }
0116 CPPUNIT_ASSERT(theyMatch);
0117 }
0118
0119 void TestIndexIntoFile5::testDuplicateCheckerFunctions() {
0120 std::set<IndexIntoFile::IndexRunLumiEventKey> relevantPreviousEvents;
0121
0122 edm::IndexIntoFile indexIntoFile1;
0123 indexIntoFile1.addEntry(fakePHID1, 6, 1, 0, 0);
0124 indexIntoFile1.addEntry(fakePHID1, 6, 0, 0, 0);
0125 indexIntoFile1.sortVector_Run_Or_Lumi_Entries();
0126
0127
0128 edm::IndexIntoFile indexIntoFile2;
0129 relevantPreviousEvents.clear();
0130 indexIntoFile1.set_intersection(indexIntoFile2, relevantPreviousEvents);
0131 CPPUNIT_ASSERT(relevantPreviousEvents.empty());
0132
0133 relevantPreviousEvents.clear();
0134 indexIntoFile2.set_intersection(indexIntoFile1, relevantPreviousEvents);
0135 CPPUNIT_ASSERT(relevantPreviousEvents.empty());
0136
0137
0138 edm::IndexIntoFile indexIntoFile3;
0139 indexIntoFile3.addEntry(fakePHID1, 7, 0, 0, 0);
0140 indexIntoFile3.sortVector_Run_Or_Lumi_Entries();
0141
0142 relevantPreviousEvents.clear();
0143 indexIntoFile1.set_intersection(indexIntoFile3, relevantPreviousEvents);
0144 CPPUNIT_ASSERT(relevantPreviousEvents.empty());
0145
0146 relevantPreviousEvents.clear();
0147 indexIntoFile3.set_intersection(indexIntoFile1, relevantPreviousEvents);
0148 CPPUNIT_ASSERT(relevantPreviousEvents.empty());
0149
0150
0151 edm::IndexIntoFile indexIntoFile4;
0152 indexIntoFile4.addEntry(fakePHID1, 6, 0, 0, 0);
0153 indexIntoFile4.addEntry(fakePHID1, 7, 0, 0, 0);
0154 indexIntoFile4.sortVector_Run_Or_Lumi_Entries();
0155
0156 relevantPreviousEvents.clear();
0157 indexIntoFile1.set_intersection(indexIntoFile4, relevantPreviousEvents);
0158 CPPUNIT_ASSERT(relevantPreviousEvents.empty());
0159
0160 relevantPreviousEvents.clear();
0161 indexIntoFile4.set_intersection(indexIntoFile1, relevantPreviousEvents);
0162 CPPUNIT_ASSERT(relevantPreviousEvents.empty());
0163
0164
0165 edm::IndexIntoFile indexIntoFile5;
0166 indexIntoFile5.addEntry(fakePHID1, 6, 2, 0, 0);
0167 indexIntoFile5.addEntry(fakePHID1, 6, 0, 0, 0);
0168 indexIntoFile5.addEntry(fakePHID1, 6, 0, 0, 0);
0169 indexIntoFile5.sortVector_Run_Or_Lumi_Entries();
0170
0171 relevantPreviousEvents.clear();
0172 indexIntoFile1.set_intersection(indexIntoFile5, relevantPreviousEvents);
0173 CPPUNIT_ASSERT(relevantPreviousEvents.empty());
0174
0175 relevantPreviousEvents.clear();
0176 indexIntoFile5.set_intersection(indexIntoFile1, relevantPreviousEvents);
0177 CPPUNIT_ASSERT(relevantPreviousEvents.empty());
0178
0179 for (int j = 0; j < 2; ++j) {
0180 edm::IndexIntoFile indexIntoFile11;
0181 indexIntoFile11.addEntry(fakePHID1, 6, 2, 0, 0);
0182 indexIntoFile11.addEntry(fakePHID1, 6, 3, 0, 1);
0183 indexIntoFile11.addEntry(fakePHID1, 6, 3, 0, 2);
0184 indexIntoFile11.addEntry(fakePHID1, 6, 0, 0, 0);
0185 indexIntoFile11.addEntry(fakePHID1, 6, 0, 0, 1);
0186 indexIntoFile11.addEntry(fakePHID1, 7, 1, 1, 0);
0187 indexIntoFile11.addEntry(fakePHID1, 7, 1, 2, 1);
0188 indexIntoFile11.addEntry(fakePHID1, 7, 1, 3, 2);
0189 indexIntoFile11.addEntry(fakePHID1, 7, 1, 4, 3);
0190 indexIntoFile11.addEntry(fakePHID1, 7, 1, 0, 3);
0191 indexIntoFile11.addEntry(fakePHID1, 7, 0, 0, 2);
0192 indexIntoFile11.addEntry(fakePHID1, 8, 1, 1, 4);
0193 indexIntoFile11.addEntry(fakePHID1, 8, 1, 0, 4);
0194 indexIntoFile11.addEntry(fakePHID1, 8, 0, 0, 3);
0195 indexIntoFile11.addEntry(fakePHID1, 8, 1, 2, 5);
0196 indexIntoFile11.addEntry(fakePHID1, 8, 1, 0, 5);
0197 indexIntoFile11.addEntry(fakePHID1, 8, 0, 0, 4);
0198 indexIntoFile11.sortVector_Run_Or_Lumi_Entries();
0199
0200 edm::IndexIntoFile indexIntoFile12;
0201 indexIntoFile12.addEntry(fakePHID1, 6, 1, 0, 0);
0202 indexIntoFile12.addEntry(fakePHID1, 6, 3, 0, 1);
0203 indexIntoFile12.addEntry(fakePHID1, 6, 3, 0, 2);
0204 indexIntoFile12.addEntry(fakePHID1, 6, 0, 0, 0);
0205 indexIntoFile12.addEntry(fakePHID1, 6, 0, 0, 1);
0206 indexIntoFile12.addEntry(fakePHID1, 7, 1, 1, 0);
0207 indexIntoFile12.addEntry(fakePHID1, 7, 1, 7, 1);
0208 indexIntoFile12.addEntry(fakePHID1, 7, 1, 3, 2);
0209 indexIntoFile12.addEntry(fakePHID1, 7, 1, 8, 3);
0210 indexIntoFile12.addEntry(fakePHID1, 7, 1, 0, 3);
0211 indexIntoFile12.addEntry(fakePHID1, 7, 1, 11, 4);
0212 indexIntoFile12.addEntry(fakePHID1, 7, 1, 6, 5);
0213 indexIntoFile12.addEntry(fakePHID1, 7, 1, 1, 6);
0214 indexIntoFile12.addEntry(fakePHID1, 7, 1, 4, 7);
0215 indexIntoFile12.addEntry(fakePHID1, 7, 1, 0, 4);
0216 indexIntoFile12.addEntry(fakePHID1, 7, 0, 0, 2);
0217 indexIntoFile12.sortVector_Run_Or_Lumi_Entries();
0218
0219 edm::IndexIntoFile indexIntoFile22;
0220 indexIntoFile22.addEntry(fakePHID1, 6, 1, 0, 0);
0221 indexIntoFile22.addEntry(fakePHID1, 6, 3, 0, 1);
0222 indexIntoFile22.addEntry(fakePHID1, 6, 3, 0, 2);
0223 indexIntoFile22.addEntry(fakePHID1, 6, 0, 0, 0);
0224 indexIntoFile22.addEntry(fakePHID1, 6, 0, 0, 1);
0225 indexIntoFile22.addEntry(fakePHID1, 7, 1, 11, 0);
0226 indexIntoFile22.addEntry(fakePHID1, 7, 1, 7, 1);
0227 indexIntoFile22.addEntry(fakePHID1, 7, 1, 3, 2);
0228 indexIntoFile22.addEntry(fakePHID1, 7, 1, 8, 3);
0229 indexIntoFile22.addEntry(fakePHID1, 7, 1, 0, 3);
0230 indexIntoFile22.addEntry(fakePHID1, 7, 1, 11, 4);
0231 indexIntoFile22.addEntry(fakePHID1, 7, 1, 6, 5);
0232 indexIntoFile22.addEntry(fakePHID1, 7, 1, 1, 6);
0233 indexIntoFile22.addEntry(fakePHID1, 7, 1, 4, 7);
0234 indexIntoFile22.addEntry(fakePHID1, 7, 1, 0, 4);
0235 indexIntoFile22.addEntry(fakePHID1, 7, 0, 0, 2);
0236 indexIntoFile22.sortVector_Run_Or_Lumi_Entries();
0237
0238 TestEventFinder* ptr11(new TestEventFinder);
0239 ptr11->push_back(1);
0240 ptr11->push_back(2);
0241 ptr11->push_back(3);
0242 ptr11->push_back(4);
0243 ptr11->push_back(1);
0244 ptr11->push_back(2);
0245
0246 std::shared_ptr<IndexIntoFile::EventFinder> shptr11(ptr11);
0247 indexIntoFile11.setEventFinder(shptr11);
0248
0249 TestEventFinder* ptr12(new TestEventFinder);
0250 ptr12->push_back(1);
0251 ptr12->push_back(7);
0252 ptr12->push_back(3);
0253 ptr12->push_back(8);
0254 ptr12->push_back(11);
0255 ptr12->push_back(6);
0256 ptr12->push_back(1);
0257 ptr12->push_back(4);
0258
0259 std::shared_ptr<IndexIntoFile::EventFinder> shptr12(ptr12);
0260 indexIntoFile12.setEventFinder(shptr12);
0261
0262 TestEventFinder* ptr22(new TestEventFinder);
0263 ptr22->push_back(11);
0264 ptr22->push_back(7);
0265 ptr22->push_back(3);
0266 ptr22->push_back(8);
0267 ptr22->push_back(11);
0268 ptr22->push_back(6);
0269 ptr22->push_back(1);
0270 ptr22->push_back(4);
0271
0272 std::shared_ptr<IndexIntoFile::EventFinder> shptr22(ptr22);
0273 indexIntoFile22.setEventFinder(shptr22);
0274
0275 if (j == 0) {
0276 indexIntoFile11.fillEventNumbers();
0277 indexIntoFile12.fillEventNumbers();
0278 indexIntoFile22.fillEventNumbers();
0279 } else {
0280 indexIntoFile11.fillEventEntries();
0281 indexIntoFile12.fillEventEntries();
0282 indexIntoFile22.fillEventEntries();
0283 }
0284
0285 CPPUNIT_ASSERT(!indexIntoFile11.containsDuplicateEvents());
0286 CPPUNIT_ASSERT(indexIntoFile12.containsDuplicateEvents());
0287 CPPUNIT_ASSERT(indexIntoFile22.containsDuplicateEvents());
0288
0289 relevantPreviousEvents.clear();
0290 indexIntoFile11.set_intersection(indexIntoFile12, relevantPreviousEvents);
0291 CPPUNIT_ASSERT(relevantPreviousEvents.size() == 3);
0292 std::set<IndexIntoFile::IndexRunLumiEventKey>::const_iterator iter = relevantPreviousEvents.begin();
0293 CPPUNIT_ASSERT(iter->event() == 1);
0294 CPPUNIT_ASSERT(iter->processHistoryIDIndex() == 0);
0295 CPPUNIT_ASSERT(iter->run() == 7);
0296 CPPUNIT_ASSERT(iter->lumi() == 1);
0297 ++iter;
0298 CPPUNIT_ASSERT(iter->event() == 3);
0299 ++iter;
0300 CPPUNIT_ASSERT(iter->event() == 4);
0301
0302 relevantPreviousEvents.clear();
0303 indexIntoFile12.set_intersection(indexIntoFile11, relevantPreviousEvents);
0304 CPPUNIT_ASSERT(relevantPreviousEvents.size() == 3);
0305 iter = relevantPreviousEvents.begin();
0306 CPPUNIT_ASSERT(iter->event() == 1);
0307 CPPUNIT_ASSERT(iter->processHistoryIDIndex() == 0);
0308 CPPUNIT_ASSERT(iter->run() == 7);
0309 CPPUNIT_ASSERT(iter->lumi() == 1);
0310 ++iter;
0311 CPPUNIT_ASSERT(iter->event() == 3);
0312 ++iter;
0313 CPPUNIT_ASSERT(iter->event() == 4);
0314 }
0315 }