Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:54:34

0001 /*
0002  *  indexIntoFile_t.cppunit.cc
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 TestIndexIntoFile1 : public CppUnit::TestFixture {
0020   CPPUNIT_TEST_SUITE(TestIndexIntoFile1);
0021   CPPUNIT_TEST(testRunOrLumiEntry);
0022   CPPUNIT_TEST(testRunOrLumiIndexes);
0023   CPPUNIT_TEST(testEventEntry);
0024   CPPUNIT_TEST(testSortedRunOrLumiItr);
0025   CPPUNIT_TEST(testKeys);
0026   CPPUNIT_TEST(testConstructor);
0027   CPPUNIT_TEST_SUITE_END();
0028 
0029 public:
0030   static const IndexIntoFile::EntryType kRun = IndexIntoFile::kRun;
0031   static const IndexIntoFile::EntryType kLumi = IndexIntoFile::kLumi;
0032   static const IndexIntoFile::EntryType kEvent = IndexIntoFile::kEvent;
0033   static const IndexIntoFile::EntryType kEnd = IndexIntoFile::kEnd;
0034 
0035   void setUp() {
0036     // Make some fake processHistoryID's to work with
0037     nullPHID = ProcessHistoryID();
0038 
0039     ProcessConfiguration pc;
0040     auto processHistory1 = std::make_unique<ProcessHistory>();
0041     ProcessHistory& ph1 = *processHistory1;
0042     processHistory1->push_back(pc);
0043     fakePHID1 = ph1.id();
0044 
0045     auto processHistory2 = std::make_unique<ProcessHistory>();
0046     ProcessHistory& ph2 = *processHistory2;
0047     processHistory2->push_back(pc);
0048     processHistory2->push_back(pc);
0049     fakePHID2 = ph2.id();
0050 
0051     auto processHistory3 = std::make_unique<ProcessHistory>();
0052     ProcessHistory& ph3 = *processHistory3;
0053     processHistory3->push_back(pc);
0054     processHistory3->push_back(pc);
0055     processHistory3->push_back(pc);
0056     fakePHID3 = ph3.id();
0057   }
0058 
0059   void tearDown() {}
0060 
0061   void testRunOrLumiEntry();
0062   void testRunOrLumiIndexes();
0063   void testEventEntry();
0064   void testSortedRunOrLumiItr();
0065   void testKeys();
0066   void testConstructor();
0067 
0068   ProcessHistoryID nullPHID;
0069   ProcessHistoryID fakePHID1;
0070   ProcessHistoryID fakePHID2;
0071   ProcessHistoryID fakePHID3;
0072 };
0073 
0074 ///registration of the test so that the runner can find it
0075 CPPUNIT_TEST_SUITE_REGISTRATION(TestIndexIntoFile1);
0076 
0077 void TestIndexIntoFile1::testRunOrLumiEntry() {
0078   edm::IndexIntoFile::RunOrLumiEntry r1;
0079   CPPUNIT_ASSERT(r1.orderPHIDRun() == edm::IndexIntoFile::invalidEntry);
0080   CPPUNIT_ASSERT(r1.orderPHIDRunLumi() == edm::IndexIntoFile::invalidEntry);
0081   CPPUNIT_ASSERT(r1.entry() == edm::IndexIntoFile::invalidEntry);
0082   CPPUNIT_ASSERT(r1.processHistoryIDIndex() == edm::IndexIntoFile::invalidIndex);
0083   CPPUNIT_ASSERT(r1.run() == edm::IndexIntoFile::invalidRun);
0084   CPPUNIT_ASSERT(r1.lumi() == edm::IndexIntoFile::invalidLumi);
0085   CPPUNIT_ASSERT(r1.beginEvents() == edm::IndexIntoFile::invalidEntry);
0086   CPPUNIT_ASSERT(r1.endEvents() == edm::IndexIntoFile::invalidEntry);
0087 
0088   edm::IndexIntoFile::RunOrLumiEntry r2(1, 2, 3, 4, 5, 6, 7, 8);
0089 
0090   CPPUNIT_ASSERT(r2.orderPHIDRun() == 1);
0091   CPPUNIT_ASSERT(r2.orderPHIDRunLumi() == 2);
0092   CPPUNIT_ASSERT(r2.entry() == 3);
0093   CPPUNIT_ASSERT(r2.processHistoryIDIndex() == 4);
0094   CPPUNIT_ASSERT(r2.run() == 5);
0095   CPPUNIT_ASSERT(r2.lumi() == 6);
0096   CPPUNIT_ASSERT(r2.beginEvents() == 7);
0097   CPPUNIT_ASSERT(r2.endEvents() == 8);
0098 
0099   CPPUNIT_ASSERT(r2.isRun() == false);
0100 
0101   edm::IndexIntoFile::RunOrLumiEntry r3(1, 2, 3, 4, 5, edm::IndexIntoFile::invalidLumi, 7, 8);
0102 
0103   CPPUNIT_ASSERT(r3.isRun() == true);
0104 
0105   r3.setOrderPHIDRun(11);
0106   CPPUNIT_ASSERT(r3.orderPHIDRun() == 11);
0107   r3.setProcessHistoryIDIndex(12);
0108   CPPUNIT_ASSERT(r3.processHistoryIDIndex() == 12);
0109   r3.setOrderPHIDRun(1);
0110 
0111   CPPUNIT_ASSERT(!(r2 < r3));
0112   CPPUNIT_ASSERT(!(r3 < r2));
0113 
0114   edm::IndexIntoFile::RunOrLumiEntry r4(10, 1, 1, 4, 5, 6, 7, 8);
0115   CPPUNIT_ASSERT(r2 < r4);
0116   CPPUNIT_ASSERT(!(r4 < r2));
0117 
0118   edm::IndexIntoFile::RunOrLumiEntry r5(1, 10, 1, 4, 5, 6, 7, 8);
0119   CPPUNIT_ASSERT(r2 < r5);
0120   CPPUNIT_ASSERT(!(r5 < r2));
0121 
0122   edm::IndexIntoFile::RunOrLumiEntry r6(1, 2, 10, 4, 5, 6, 7, 8);
0123   CPPUNIT_ASSERT(r2 < r6);
0124   CPPUNIT_ASSERT(!(r6 < r2));
0125 
0126   r3.setOrderPHIDRunLumi(1001);
0127   CPPUNIT_ASSERT(r3.orderPHIDRunLumi() == 1001);
0128 }
0129 
0130 void TestIndexIntoFile1::testRunOrLumiIndexes() {
0131   edm::IndexIntoFile::RunOrLumiIndexes r1(1, 2, 3, 4);
0132   CPPUNIT_ASSERT(r1.processHistoryIDIndex() == 1);
0133   CPPUNIT_ASSERT(r1.run() == 2);
0134   CPPUNIT_ASSERT(r1.lumi() == 3);
0135   CPPUNIT_ASSERT(r1.indexToGetEntry() == 4);
0136   CPPUNIT_ASSERT(r1.beginEventNumbers() == -1);
0137   CPPUNIT_ASSERT(r1.endEventNumbers() == -1);
0138 
0139   r1.setBeginEventNumbers(11);
0140   r1.setEndEventNumbers(12);
0141   CPPUNIT_ASSERT(r1.beginEventNumbers() == 11);
0142   CPPUNIT_ASSERT(r1.endEventNumbers() == 12);
0143 
0144   CPPUNIT_ASSERT(r1.isRun() == false);
0145 
0146   edm::IndexIntoFile::RunOrLumiIndexes r2(1, 2, edm::IndexIntoFile::invalidLumi, 4);
0147   CPPUNIT_ASSERT(r2.isRun() == true);
0148 
0149   edm::IndexIntoFile::RunOrLumiIndexes r3(1, 2, 3, 4);
0150   CPPUNIT_ASSERT(!(r1 < r3));
0151   CPPUNIT_ASSERT(!(r3 < r1));
0152 
0153   edm::IndexIntoFile::RunOrLumiIndexes r4(11, 2, 3, 4);
0154   CPPUNIT_ASSERT(r1 < r4);
0155   CPPUNIT_ASSERT(!(r4 < r1));
0156 
0157   edm::IndexIntoFile::RunOrLumiIndexes r5(1, 11, 1, 4);
0158   CPPUNIT_ASSERT(r1 < r5);
0159   CPPUNIT_ASSERT(!(r5 < r1));
0160 
0161   edm::IndexIntoFile::RunOrLumiIndexes r6(1, 2, 11, 4);
0162   CPPUNIT_ASSERT(r1 < r6);
0163   CPPUNIT_ASSERT(!(r6 < r1));
0164 
0165   Compare_Index_Run c;
0166   CPPUNIT_ASSERT(!c(r1, r6));
0167   CPPUNIT_ASSERT(!c(r6, r1));
0168   CPPUNIT_ASSERT(c(r1, r5));
0169   CPPUNIT_ASSERT(!c(r5, r1));
0170   CPPUNIT_ASSERT(c(r1, r4));
0171   CPPUNIT_ASSERT(!c(r4, r1));
0172 
0173   Compare_Index c1;
0174   CPPUNIT_ASSERT(!c1(r1, r5));
0175   CPPUNIT_ASSERT(!c1(r5, r1));
0176   CPPUNIT_ASSERT(c1(r1, r4));
0177   CPPUNIT_ASSERT(!c1(r4, r1));
0178 }
0179 
0180 void TestIndexIntoFile1::testEventEntry() {
0181   edm::IndexIntoFile::EventEntry e1;
0182   CPPUNIT_ASSERT(e1.event() == edm::IndexIntoFile::invalidEvent);
0183   CPPUNIT_ASSERT(e1.entry() == edm::IndexIntoFile::invalidEntry);
0184 
0185   edm::IndexIntoFile::EventEntry e2(100, 200);
0186   CPPUNIT_ASSERT(e2.event() == 100);
0187   CPPUNIT_ASSERT(e2.entry() == 200);
0188 
0189   edm::IndexIntoFile::EventEntry e3(100, 300);
0190   edm::IndexIntoFile::EventEntry e4(200, 300);
0191   edm::IndexIntoFile::EventEntry e5(200, 100);
0192 
0193   CPPUNIT_ASSERT(e2 == e3);
0194   CPPUNIT_ASSERT(!(e3 == e4));
0195 
0196   CPPUNIT_ASSERT(e3 < e4);
0197   CPPUNIT_ASSERT(e3 < e5);
0198   CPPUNIT_ASSERT(!(e4 < e5));
0199 }
0200 
0201 void TestIndexIntoFile1::testSortedRunOrLumiItr() {
0202   edm::IndexIntoFile indexIntoFile0;
0203   CPPUNIT_ASSERT(indexIntoFile0.empty());
0204   edm::IndexIntoFile::SortedRunOrLumiItr iter(&indexIntoFile0, 0);
0205   CPPUNIT_ASSERT(iter.indexIntoFile() == &indexIntoFile0);
0206   CPPUNIT_ASSERT(iter.runOrLumi() == 0);
0207   ++iter;
0208   CPPUNIT_ASSERT(iter.runOrLumi() == 0);
0209   CPPUNIT_ASSERT(iter == indexIntoFile0.beginRunOrLumi());
0210   CPPUNIT_ASSERT(iter == indexIntoFile0.endRunOrLumi());
0211 
0212   edm::IndexIntoFile indexIntoFile;
0213   indexIntoFile.addEntry(fakePHID1, 1, 1, 1, 0);  // Event
0214   indexIntoFile.addEntry(fakePHID1, 1, 1, 2, 1);  // Event
0215   indexIntoFile.addEntry(fakePHID1, 1, 1, 0, 0);  // Lumi
0216   indexIntoFile.addEntry(fakePHID1, 1, 2, 1, 2);  // Event
0217   indexIntoFile.addEntry(fakePHID1, 1, 2, 2, 3);  // Event
0218   indexIntoFile.addEntry(fakePHID1, 1, 2, 3, 4);  // Event
0219   indexIntoFile.addEntry(fakePHID1, 1, 2, 0, 1);  // Lumi
0220   indexIntoFile.addEntry(fakePHID1, 1, 1, 3, 5);  // Event
0221   indexIntoFile.addEntry(fakePHID1, 1, 1, 4, 6);  // Event
0222   indexIntoFile.addEntry(fakePHID1, 1, 1, 0, 0);  // Lumi
0223   indexIntoFile.addEntry(fakePHID1, 1, 0, 0, 0);  // Run
0224   indexIntoFile.sortVector_Run_Or_Lumi_Entries();
0225 
0226   CPPUNIT_ASSERT(!indexIntoFile.empty());
0227 
0228   unsigned count = 0;
0229   IndexIntoFile::SortedRunOrLumiItr runOrLumi = indexIntoFile.beginRunOrLumi();
0230   for (IndexIntoFile::SortedRunOrLumiItr endRunOrLumi = indexIntoFile.endRunOrLumi(); runOrLumi != endRunOrLumi;
0231        ++runOrLumi) {
0232     long long beginEventNumbers;
0233     long long endEventNumbers;
0234     IndexIntoFile::EntryNumber_t beginEventEntry;
0235     IndexIntoFile::EntryNumber_t endEventEntry;
0236     runOrLumi.getRange(beginEventNumbers, endEventNumbers, beginEventEntry, endEventEntry);
0237 
0238     if (count == 0) {
0239       CPPUNIT_ASSERT(runOrLumi.isRun());
0240       CPPUNIT_ASSERT(beginEventNumbers == -1);
0241       CPPUNIT_ASSERT(endEventNumbers == -1);
0242       CPPUNIT_ASSERT(beginEventEntry == -1);
0243       CPPUNIT_ASSERT(endEventEntry == -1);
0244     } else if (count == 3) {
0245       CPPUNIT_ASSERT(!runOrLumi.isRun());
0246       CPPUNIT_ASSERT(beginEventNumbers == 4);
0247       CPPUNIT_ASSERT(endEventNumbers == 7);
0248       CPPUNIT_ASSERT(beginEventEntry == 2);
0249       CPPUNIT_ASSERT(endEventEntry == 5);
0250 
0251       IndexIntoFile::RunOrLumiIndexes const& indexes = runOrLumi.runOrLumiIndexes();
0252       CPPUNIT_ASSERT(indexes.processHistoryIDIndex() == 0);
0253       CPPUNIT_ASSERT(indexes.run() == 1U);
0254       CPPUNIT_ASSERT(indexes.lumi() == 2U);
0255       CPPUNIT_ASSERT(indexes.indexToGetEntry() == 3);
0256       CPPUNIT_ASSERT(indexes.beginEventNumbers() == 4);
0257       CPPUNIT_ASSERT(indexes.endEventNumbers() == 7);
0258     }
0259 
0260     CPPUNIT_ASSERT(runOrLumi.runOrLumi() == count);
0261     ++count;
0262   }
0263   CPPUNIT_ASSERT(count == 4U);
0264   CPPUNIT_ASSERT(runOrLumi.runOrLumi() == 4U);
0265   ++runOrLumi;
0266   CPPUNIT_ASSERT(runOrLumi.runOrLumi() == 4U);
0267 
0268   CPPUNIT_ASSERT(runOrLumi == indexIntoFile.endRunOrLumi());
0269   CPPUNIT_ASSERT(!(runOrLumi == indexIntoFile.beginRunOrLumi()));
0270   CPPUNIT_ASSERT(!(iter == indexIntoFile.beginRunOrLumi()));
0271 
0272   CPPUNIT_ASSERT(!(runOrLumi != indexIntoFile.endRunOrLumi()));
0273   CPPUNIT_ASSERT(runOrLumi != indexIntoFile.beginRunOrLumi());
0274   CPPUNIT_ASSERT(iter != indexIntoFile.beginRunOrLumi());
0275 }
0276 
0277 void TestIndexIntoFile1::testKeys() {
0278   IndexIntoFile::IndexRunKey key1(1, 2);
0279   CPPUNIT_ASSERT(key1.processHistoryIDIndex() == 1);
0280   CPPUNIT_ASSERT(key1.run() == 2);
0281 
0282   IndexIntoFile::IndexRunKey key2(1, 2);
0283   CPPUNIT_ASSERT(!(key1 < key2));
0284   CPPUNIT_ASSERT(!(key2 < key1));
0285 
0286   IndexIntoFile::IndexRunKey key3(1, 3);
0287   CPPUNIT_ASSERT(key1 < key3);
0288   CPPUNIT_ASSERT(!(key3 < key1));
0289 
0290   IndexIntoFile::IndexRunKey key4(10, 1);
0291   CPPUNIT_ASSERT(key1 < key4);
0292   CPPUNIT_ASSERT(!(key4 < key1));
0293 
0294   IndexIntoFile::IndexRunLumiKey k1(1, 2, 3);
0295   CPPUNIT_ASSERT(k1.processHistoryIDIndex() == 1);
0296   CPPUNIT_ASSERT(k1.run() == 2);
0297   CPPUNIT_ASSERT(k1.lumi() == 3);
0298 
0299   IndexIntoFile::IndexRunLumiKey k2(1, 2, 3);
0300   CPPUNIT_ASSERT(!(k1 < k2));
0301   CPPUNIT_ASSERT(!(k2 < k1));
0302 
0303   IndexIntoFile::IndexRunLumiKey k3(1, 2, 4);
0304   CPPUNIT_ASSERT(k1 < k3);
0305   CPPUNIT_ASSERT(!(k3 < k1));
0306 
0307   IndexIntoFile::IndexRunLumiKey k4(1, 3, 1);
0308   CPPUNIT_ASSERT(k1 < k4);
0309   CPPUNIT_ASSERT(!(k4 < k1));
0310 
0311   IndexIntoFile::IndexRunLumiKey k5(11, 1, 1);
0312   CPPUNIT_ASSERT(k1 < k5);
0313   CPPUNIT_ASSERT(!(k5 < k1));
0314 
0315   IndexIntoFile::IndexRunLumiEventKey e1(1, 2, 3, 4);
0316   CPPUNIT_ASSERT(e1.processHistoryIDIndex() == 1);
0317   CPPUNIT_ASSERT(e1.run() == 2);
0318   CPPUNIT_ASSERT(e1.lumi() == 3);
0319   CPPUNIT_ASSERT(e1.event() == 4);
0320 
0321   IndexIntoFile::IndexRunLumiEventKey e2(1, 2, 3, 4);
0322   CPPUNIT_ASSERT(!(e1 < e2));
0323   CPPUNIT_ASSERT(!(e2 < e1));
0324 
0325   IndexIntoFile::IndexRunLumiEventKey e3(1, 2, 3, 5);
0326   CPPUNIT_ASSERT(e1 < e3);
0327   CPPUNIT_ASSERT(!(e3 < e1));
0328 
0329   IndexIntoFile::IndexRunLumiEventKey e4(1, 2, 11, 1);
0330   CPPUNIT_ASSERT(e1 < e4);
0331   CPPUNIT_ASSERT(!(e4 < e1));
0332 
0333   IndexIntoFile::IndexRunLumiEventKey e5(1, 11, 1, 1);
0334   CPPUNIT_ASSERT(e1 < e5);
0335   CPPUNIT_ASSERT(!(e5 < e1));
0336 
0337   IndexIntoFile::IndexRunLumiEventKey e6(11, 1, 1, 1);
0338   CPPUNIT_ASSERT(e1 < e6);
0339   CPPUNIT_ASSERT(!(e6 < e1));
0340 }
0341 
0342 void TestIndexIntoFile1::testConstructor() {
0343   edm::IndexIntoFile indexIntoFile;
0344   CPPUNIT_ASSERT(indexIntoFile.runOrLumiEntries().empty());
0345   CPPUNIT_ASSERT(indexIntoFile.processHistoryIDs().empty());
0346   CPPUNIT_ASSERT(indexIntoFile.eventEntries().empty());
0347   CPPUNIT_ASSERT(indexIntoFile.eventNumbers().empty());
0348   CPPUNIT_ASSERT(indexIntoFile.setRunOrLumiEntries().empty());
0349   CPPUNIT_ASSERT(indexIntoFile.setProcessHistoryIDs().empty());
0350 
0351   std::vector<LuminosityBlockNumber_t> lumis;
0352   lumis.push_back(1);
0353   edm::IndexIntoFile::IndexIntoFileItr iter = indexIntoFile.begin(IndexIntoFile::firstAppearanceOrder);
0354   iter.getLumisInRun(lumis);
0355   CPPUNIT_ASSERT(lumis.empty());
0356 }