Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2025-02-27 07:20:00

0001 #include "catch.hpp"
0002 #include "DataFormats/Provenance/interface/ProcessHistory.h"
0003 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0004 #include "DataFormats/Provenance/interface/IndexIntoFile.h"
0005 #include "DataFormats/Provenance/interface/ParameterSetID.h"
0006 #include "DataFormats/Provenance/interface/ProcessConfiguration.h"
0007 #include "DataFormats/Provenance/interface/ProcessHistoryID.h"
0008 #include "DataFormats/Provenance/interface/ProcessHistoryRegistry.h"
0009 #include "FWCore/Utilities/interface/Exception.h"
0010 #include "FWCore/Version/interface/GetReleaseVersion.h"
0011 
0012 #include <string>
0013 #include <iostream>
0014 
0015 bool checkRunOrLumiEntry(edm::IndexIntoFile::RunOrLumiEntry const& rl,
0016                          edm::IndexIntoFile::EntryNumber_t orderPHIDRun,
0017                          edm::IndexIntoFile::EntryNumber_t orderPHIDRunLumi,
0018                          edm::IndexIntoFile::EntryNumber_t entry,
0019                          int processHistoryIDIndex,
0020                          edm::RunNumber_t run,
0021                          edm::LuminosityBlockNumber_t lumi,
0022                          edm::IndexIntoFile::EntryNumber_t beginEvents,
0023                          edm::IndexIntoFile::EntryNumber_t endEvents) {
0024   if (rl.orderPHIDRun() != orderPHIDRun)
0025     return false;
0026   if (rl.orderPHIDRunLumi() != orderPHIDRunLumi)
0027     return false;
0028   if (rl.entry() != entry)
0029     return false;
0030   if (rl.processHistoryIDIndex() != processHistoryIDIndex)
0031     return false;
0032   if (rl.run() != run)
0033     return false;
0034   if (rl.lumi() != lumi)
0035     return false;
0036   if (rl.beginEvents() != beginEvents)
0037     return false;
0038   if (rl.endEvents() != endEvents)
0039     return false;
0040   return true;
0041 }
0042 
0043 TEST_CASE("test ProcessHistory", "[ProcessHistory]") {
0044   edm::ProcessHistoryRegistry processHistoryRegistry;
0045   edm::ParameterSet dummyPset;
0046   edm::ParameterSetID psetID;
0047   dummyPset.registerIt();
0048   psetID = dummyPset.id();
0049   SECTION("ProcessHistory") {
0050     edm::ProcessHistory pnl1;
0051     edm::ProcessHistory pnl2;
0052     SECTION("default initialize comparison") {
0053       REQUIRE(pnl1 == pnl1);
0054       REQUIRE(pnl1 == pnl2);
0055     }
0056     edm::ProcessConfiguration iHLT("HLT", psetID, "CMSSW_5_100_40", edm::HardwareResourcesDescription());
0057     edm::ProcessConfiguration iRECO("RECO", psetID, "5_100_42patch100", edm::HardwareResourcesDescription());
0058     pnl2.push_back(iHLT);
0059     edm::ProcessHistory pnl3;
0060     pnl3.push_back(iHLT);
0061     pnl3.push_back(iRECO);
0062 
0063     SECTION("different history comparison") {
0064       REQUIRE(pnl1 != pnl2);
0065       edm::ProcessHistoryID id1 = pnl1.setProcessHistoryID();
0066       edm::ProcessHistoryID id2 = pnl2.setProcessHistoryID();
0067       edm::ProcessHistoryID id3 = pnl3.setProcessHistoryID();
0068 
0069       REQUIRE(id1 != id2);
0070       REQUIRE(id2 != id3);
0071       REQUIRE(id3 != id1);
0072 
0073       edm::ProcessHistory pnl4;
0074       pnl4.push_back(iHLT);
0075       edm::ProcessHistoryID id4 = pnl4.setProcessHistoryID();
0076       REQUIRE(pnl4 == pnl2);
0077       REQUIRE(id4 == id2);
0078 
0079       edm::ProcessHistory pnl5;
0080       pnl5 = pnl3;
0081       REQUIRE(pnl5 == pnl3);
0082       REQUIRE(pnl5.id() == pnl3.id());
0083     }
0084 
0085     SECTION("reduce") {
0086       edm::ProcessConfiguration pc1("HLT", psetID, "", edm::HardwareResourcesDescription());
0087       edm::ProcessConfiguration pc2("HLT", psetID, "a", edm::HardwareResourcesDescription());
0088       edm::ProcessConfiguration pc3("HLT", psetID, "1", edm::HardwareResourcesDescription());
0089       edm::ProcessConfiguration pc4("HLT", psetID, "ccc500yz", edm::HardwareResourcesDescription());
0090       edm::ProcessConfiguration pc5("HLT", psetID, "500yz872", edm::HardwareResourcesDescription());
0091       edm::ProcessConfiguration pc6("HLT", psetID, "500yz872djk999patch10", edm::HardwareResourcesDescription());
0092       edm::ProcessConfiguration pc7("HLT", psetID, "xb500yz872djk999patch10", edm::HardwareResourcesDescription());
0093       edm::ProcessConfiguration pc8("HLT", psetID, "CMSSW_4_4_0_pre5", edm::HardwareResourcesDescription());
0094       edm::HardwareResourcesDescription hrd;
0095       hrd.microarchitecture = "fred";
0096       edm::ProcessConfiguration pc9("HLT", psetID, "CMSSW_4_4_0_pre5", hrd);
0097 
0098       pc1.setProcessConfigurationID();
0099       pc2.setProcessConfigurationID();
0100       pc3.setProcessConfigurationID();
0101       pc4.setProcessConfigurationID();
0102       pc5.setProcessConfigurationID();
0103       pc6.setProcessConfigurationID();
0104       pc7.setProcessConfigurationID();
0105       pc8.setProcessConfigurationID();
0106       pc9.setProcessConfigurationID();
0107 
0108       REQUIRE(pc9.id() != pc8.id());
0109 
0110       pc1.reduce();
0111       pc2.reduce();
0112       pc3.reduce();
0113       pc4.reduce();
0114       pc5.reduce();
0115       pc6.reduce();
0116       pc7.reduce();
0117       pc8.reduce();
0118       pc9.reduce();
0119 
0120       REQUIRE(pc9.id() == pc8.id());
0121 
0122       edm::ProcessConfiguration pc1expected("HLT", psetID, "", edm::HardwareResourcesDescription());
0123       edm::ProcessConfiguration pc2expected("HLT", psetID, "a", edm::HardwareResourcesDescription());
0124       edm::ProcessConfiguration pc3expected("HLT", psetID, "1", edm::HardwareResourcesDescription());
0125       edm::ProcessConfiguration pc4expected("HLT", psetID, "ccc500yz", edm::HardwareResourcesDescription());
0126       edm::ProcessConfiguration pc5expected("HLT", psetID, "500yz872", edm::HardwareResourcesDescription());
0127       edm::ProcessConfiguration pc6expected("HLT", psetID, "500yz872", edm::HardwareResourcesDescription());
0128       edm::ProcessConfiguration pc7expected("HLT", psetID, "xb500yz872", edm::HardwareResourcesDescription());
0129       edm::ProcessConfiguration pc8expected("HLT", psetID, "CMSSW_4_4", edm::HardwareResourcesDescription());
0130       edm::ProcessConfiguration pc9expected = pc8expected;
0131 
0132       REQUIRE(pc1 == pc1expected);
0133       REQUIRE(pc2 == pc2expected);
0134       REQUIRE(pc3 == pc3expected);
0135       REQUIRE(pc4 == pc4expected);
0136       REQUIRE(pc5 == pc5expected);
0137       REQUIRE(pc6 == pc6expected);
0138       REQUIRE(pc7 == pc7expected);
0139       REQUIRE(pc8 == pc8expected);
0140       REQUIRE(pc9 == pc9expected);
0141 
0142       REQUIRE(pc1.id() == pc1expected.id());
0143       REQUIRE(pc2.id() == pc2expected.id());
0144       REQUIRE(pc3.id() == pc3expected.id());
0145       REQUIRE(pc4.id() == pc4expected.id());
0146       REQUIRE(pc5.id() == pc5expected.id());
0147       REQUIRE(pc6.id() == pc6expected.id());
0148       REQUIRE(pc7.id() == pc7expected.id());
0149       REQUIRE(pc8.id() == pc8expected.id());
0150       REQUIRE(pc9.id() == pc9expected.id());
0151 
0152       REQUIRE(pc7.id() != pc8expected.id());
0153     }
0154     SECTION("multi-step history reduce") {
0155       edm::ProcessConfiguration iHLTreduced("HLT", psetID, "CMSSW_5_100", edm::HardwareResourcesDescription());
0156       edm::ProcessConfiguration iRECOreduced("RECO", psetID, "5_100", edm::HardwareResourcesDescription());
0157       edm::ProcessHistory phTestExpected;
0158       phTestExpected.push_back(iHLTreduced);
0159       phTestExpected.push_back(iRECOreduced);
0160 
0161       edm::ProcessHistory phTest = pnl3;
0162       phTest.setProcessHistoryID();
0163       phTest.reduce();
0164       REQUIRE(phTest == phTestExpected);
0165       REQUIRE(phTest.id() == phTestExpected.id());
0166       REQUIRE(phTest.id() != pnl3.id());
0167 
0168       processHistoryRegistry.registerProcessHistory(pnl3);
0169       edm::ProcessHistoryID reducedPHID = processHistoryRegistry.reducedProcessHistoryID(pnl3.id());
0170       REQUIRE(reducedPHID == phTest.id());
0171 
0172       processHistoryRegistry.registerProcessHistory(pnl2);
0173       reducedPHID = processHistoryRegistry.reducedProcessHistoryID(pnl2.id());
0174       pnl2.reduce();
0175       REQUIRE(reducedPHID == pnl2.id());
0176     }
0177   }
0178   SECTION("IndexIntoFile") {
0179     edm::ProcessHistory ph1;
0180     edm::ProcessHistory ph1a;
0181     edm::ProcessHistory ph1b;
0182     edm::ProcessHistory ph2;
0183     edm::ProcessHistory ph2a;
0184     edm::ProcessHistory ph2b;
0185     edm::ProcessHistory ph3;
0186     edm::ProcessHistory ph4;
0187 
0188     edm::ProcessConfiguration pc1("HLT", psetID, "CMSSW_5_1_40", edm::HardwareResourcesDescription());
0189     edm::ProcessConfiguration pc1a("HLT", psetID, "CMSSW_5_1_40patch1", edm::HardwareResourcesDescription());
0190     edm::ProcessConfiguration pc1b("HLT", psetID, "CMSSW_5_1_40patch2", edm::HardwareResourcesDescription());
0191     edm::ProcessConfiguration pc2("HLT", psetID, "CMSSW_5_2_40", edm::HardwareResourcesDescription());
0192     edm::ProcessConfiguration pc2a("HLT", psetID, "CMSSW_5_2_40patch1", edm::HardwareResourcesDescription());
0193     edm::ProcessConfiguration pc2b("HLT", psetID, "CMSSW_5_2_40patch2", edm::HardwareResourcesDescription());
0194     edm::ProcessConfiguration pc3("HLT", psetID, "CMSSW_5_3_40", edm::HardwareResourcesDescription());
0195     edm::ProcessConfiguration pc4("HLT", psetID, "CMSSW_5_4_40", edm::HardwareResourcesDescription());
0196 
0197     ph1.push_back(pc1);
0198     ph1a.push_back(pc1a);
0199     ph1b.push_back(pc1b);
0200     ph2.push_back(pc2);
0201     ph2a.push_back(pc2a);
0202     ph2b.push_back(pc2b);
0203     ph3.push_back(pc3);
0204     ph4.push_back(pc4);
0205 
0206     edm::ProcessHistoryID phid1 = ph1.setProcessHistoryID();
0207     edm::ProcessHistoryID phid1a = ph1a.setProcessHistoryID();
0208     edm::ProcessHistoryID phid1b = ph1b.setProcessHistoryID();
0209     edm::ProcessHistoryID phid2 = ph2.setProcessHistoryID();
0210     edm::ProcessHistoryID phid2a = ph2a.setProcessHistoryID();
0211     edm::ProcessHistoryID phid2b = ph2b.setProcessHistoryID();
0212     edm::ProcessHistoryID phid3 = ph3.setProcessHistoryID();
0213     edm::ProcessHistoryID phid4 = ph4.setProcessHistoryID();
0214 
0215     processHistoryRegistry.registerProcessHistory(ph1);
0216     processHistoryRegistry.registerProcessHistory(ph1a);
0217     processHistoryRegistry.registerProcessHistory(ph1b);
0218     processHistoryRegistry.registerProcessHistory(ph2);
0219     processHistoryRegistry.registerProcessHistory(ph2a);
0220     processHistoryRegistry.registerProcessHistory(ph2b);
0221     processHistoryRegistry.registerProcessHistory(ph3);
0222     processHistoryRegistry.registerProcessHistory(ph4);
0223 
0224     edm::ProcessHistory rph1 = ph1;
0225     edm::ProcessHistory rph1a = ph1a;
0226     edm::ProcessHistory rph1b = ph1b;
0227     edm::ProcessHistory rph2 = ph2;
0228     edm::ProcessHistory rph2a = ph2a;
0229     edm::ProcessHistory rph2b = ph2b;
0230     edm::ProcessHistory rph3 = ph3;
0231     edm::ProcessHistory rph4 = ph4;
0232     rph1.reduce();
0233     rph1a.reduce();
0234     rph1b.reduce();
0235     rph2.reduce();
0236     rph2a.reduce();
0237     rph2b.reduce();
0238     rph3.reduce();
0239     rph4.reduce();
0240 
0241     SECTION("sequential") {
0242       edm::IndexIntoFile indexIntoFile;
0243       indexIntoFile.addEntry(phid1, 1, 0, 0, 0);
0244       indexIntoFile.addEntry(phid2, 2, 0, 0, 1);
0245       indexIntoFile.addEntry(phid3, 3, 0, 0, 2);
0246       indexIntoFile.addEntry(phid4, 4, 0, 0, 3);
0247 
0248       indexIntoFile.sortVector_Run_Or_Lumi_Entries();
0249 
0250       indexIntoFile.reduceProcessHistoryIDs(processHistoryRegistry);
0251 
0252       std::vector<edm::ProcessHistoryID> const& v = indexIntoFile.processHistoryIDs();
0253       REQUIRE(v[0] == rph1.id());
0254       REQUIRE(v[1] == rph2.id());
0255       REQUIRE(v[2] == rph3.id());
0256       REQUIRE(v[3] == rph4.id());
0257     }
0258 
0259     SECTION("non-sequential") {
0260       edm::IndexIntoFile indexIntoFile1;
0261       indexIntoFile1.addEntry(phid1, 1, 11, 0, 0);
0262       indexIntoFile1.addEntry(phid1, 1, 12, 0, 1);
0263       indexIntoFile1.addEntry(phid1, 1, 0, 0, 0);
0264       indexIntoFile1.addEntry(phid2, 2, 11, 0, 2);
0265       indexIntoFile1.addEntry(phid2, 2, 12, 0, 3);
0266       indexIntoFile1.addEntry(phid2, 2, 0, 0, 1);
0267       indexIntoFile1.addEntry(phid1a, 1, 11, 1, 0);
0268       indexIntoFile1.addEntry(phid1a, 1, 11, 2, 1);
0269       indexIntoFile1.addEntry(phid1a, 1, 11, 0, 4);
0270       indexIntoFile1.addEntry(phid1a, 1, 12, 1, 2);
0271       indexIntoFile1.addEntry(phid1a, 1, 12, 2, 3);
0272       indexIntoFile1.addEntry(phid1a, 1, 12, 0, 5);
0273       indexIntoFile1.addEntry(phid1a, 1, 0, 0, 2);
0274       indexIntoFile1.addEntry(phid3, 3, 0, 0, 3);
0275       indexIntoFile1.addEntry(phid2a, 2, 0, 0, 4);
0276       indexIntoFile1.addEntry(phid2b, 2, 0, 0, 5);
0277       indexIntoFile1.addEntry(phid4, 4, 0, 0, 6);
0278       indexIntoFile1.addEntry(phid1b, 1, 0, 0, 7);
0279       indexIntoFile1.addEntry(phid1, 5, 11, 0, 6);
0280       indexIntoFile1.addEntry(phid1, 5, 0, 0, 8);
0281       indexIntoFile1.addEntry(phid4, 1, 11, 0, 7);
0282       indexIntoFile1.addEntry(phid4, 1, 0, 0, 9);
0283 
0284       indexIntoFile1.sortVector_Run_Or_Lumi_Entries();
0285 
0286       std::vector<edm::ProcessHistoryID> const& v1 = indexIntoFile1.processHistoryIDs();
0287       REQUIRE(v1.size() == 8U);
0288 
0289       indexIntoFile1.reduceProcessHistoryIDs(processHistoryRegistry);
0290 
0291       std::vector<edm::ProcessHistoryID> const& rv1 = indexIntoFile1.processHistoryIDs();
0292       REQUIRE(rv1.size() == 4U);
0293       REQUIRE(rv1[0] == rph1.id());
0294       REQUIRE(rv1[1] == rph2.id());
0295       REQUIRE(rv1[2] == rph3.id());
0296       REQUIRE(rv1[3] == rph4.id());
0297 
0298       std::vector<edm::IndexIntoFile::RunOrLumiEntry>& runOrLumiEntries = indexIntoFile1.setRunOrLumiEntries();
0299 
0300       REQUIRE(runOrLumiEntries.size() == 18U);
0301 
0302       /*
0303        std::cout << rv1[0] << "  " << rph1 << "\n";
0304        std::cout << rv1[1] << "  " << rph2 << "\n";
0305        std::cout << rv1[2] << "  " << rph3 << "\n";
0306        std::cout << rv1[3] << "  " << rph4 << "\n";
0307        
0308        for (auto const& item : runOrLumiEntries) {
0309        std::cout << item.orderPHIDRun() << "  "
0310        << item.orderPHIDRunLumi() << "  "
0311        << item.entry() << "  "
0312        << item.processHistoryIDIndex() << "  "
0313        << item.run() << "  "
0314        << item.lumi() << "  "
0315        << item.beginEvents() << "  "
0316        << item.endEvents() << "\n";
0317        
0318        }
0319        */
0320       SECTION("checkRunOrLumiEntry") {
0321         REQUIRE(checkRunOrLumiEntry(runOrLumiEntries.at(0), 0, -1, 0, 0, 1, 0, -1, -1));
0322         REQUIRE(checkRunOrLumiEntry(runOrLumiEntries.at(1), 0, -1, 2, 0, 1, 0, -1, -1));
0323         REQUIRE(checkRunOrLumiEntry(runOrLumiEntries.at(2), 0, -1, 7, 0, 1, 0, -1, -1));
0324         REQUIRE(checkRunOrLumiEntry(runOrLumiEntries.at(3), 0, 0, 0, 0, 1, 11, -1, -1));
0325         REQUIRE(checkRunOrLumiEntry(runOrLumiEntries.at(4), 0, 0, 4, 0, 1, 11, 0, 2));
0326         REQUIRE(checkRunOrLumiEntry(runOrLumiEntries.at(5), 0, 1, 1, 0, 1, 12, -1, -1));
0327         REQUIRE(checkRunOrLumiEntry(runOrLumiEntries.at(6), 0, 1, 5, 0, 1, 12, 2, 4));
0328         REQUIRE(checkRunOrLumiEntry(runOrLumiEntries.at(7), 1, -1, 1, 1, 2, 0, -1, -1));
0329         REQUIRE(checkRunOrLumiEntry(runOrLumiEntries.at(8), 1, -1, 4, 1, 2, 0, -1, -1));
0330         REQUIRE(checkRunOrLumiEntry(runOrLumiEntries.at(9), 1, -1, 5, 1, 2, 0, -1, -1));
0331         REQUIRE(checkRunOrLumiEntry(runOrLumiEntries.at(10), 1, 2, 2, 1, 2, 11, -1, -1));
0332         REQUIRE(checkRunOrLumiEntry(runOrLumiEntries.at(11), 1, 3, 3, 1, 2, 12, -1, -1));
0333         REQUIRE(checkRunOrLumiEntry(runOrLumiEntries.at(12), 3, -1, 3, 2, 3, 0, -1, -1));
0334         REQUIRE(checkRunOrLumiEntry(runOrLumiEntries.at(13), 6, -1, 6, 3, 4, 0, -1, -1));
0335         REQUIRE(checkRunOrLumiEntry(runOrLumiEntries.at(14), 8, -1, 8, 0, 5, 0, -1, -1));
0336         REQUIRE(checkRunOrLumiEntry(runOrLumiEntries.at(15), 8, 6, 6, 0, 5, 11, -1, -1));
0337         REQUIRE(checkRunOrLumiEntry(runOrLumiEntries.at(16), 9, -1, 9, 3, 1, 0, -1, -1));
0338         REQUIRE(checkRunOrLumiEntry(runOrLumiEntries.at(17), 9, 7, 7, 3, 1, 11, -1, -1));
0339       }
0340     }
0341   }
0342 }