Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-03-17 11:03:01

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