Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:12:30

0001 #include "catch.hpp"
0002 
0003 #include "DataFormats/Provenance/interface/BranchDescription.h"
0004 #include "DataFormats/Provenance/interface/IndexIntoFile.h"
0005 #include "DataFormats/Provenance/interface/ParameterSetID.h"
0006 #include "DataFormats/Provenance/interface/ParameterSetID.h"
0007 #include "DataFormats/Provenance/interface/ProcessConfiguration.h"
0008 #include "DataFormats/Provenance/interface/ProcessHistory.h"
0009 #include "DataFormats/Provenance/interface/ProcessHistoryID.h"
0010 #include "DataFormats/Provenance/interface/ProductRegistry.h"
0011 #include "DataFormats/Provenance/interface/RunLumiEventNumber.h"
0012 #include "DataFormats/Provenance/interface/StoredMergeableRunProductMetadata.h"
0013 #include "DataFormats/TestObjects/interface/Thing.h"
0014 #include "DataFormats/TestObjects/interface/ThingWithMerge.h"
0015 #include "FWCore/Framework/interface/MergeableRunProductMetadata.h"
0016 #include "FWCore/Framework/interface/MergeableRunProductProcesses.h"
0017 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0018 #include "FWCore/Utilities/interface/BranchType.h"
0019 #include "FWCore/Reflection/interface/TypeWithDict.h"
0020 
0021 #include <memory>
0022 #include <string>
0023 #include <vector>
0024 
0025 TEST_CASE("test MergeableRunProductMetadata", "[MergeableRunProductMetadata]") {
0026   SECTION("test nested class MetadataForProcess") {
0027     edm::MergeableRunProductMetadata::MetadataForProcess metaDataForProcess;
0028     REQUIRE(metaDataForProcess.lumis().empty());
0029     REQUIRE(metaDataForProcess.valid());
0030     REQUIRE(!metaDataForProcess.useIndexIntoFile());
0031     REQUIRE(!metaDataForProcess.allLumisProcessed());
0032     REQUIRE(metaDataForProcess.mergeDecision() == edm::MergeableRunProductMetadata::MERGE);
0033 
0034     std::vector<edm::LuminosityBlockNumber_t>& lumis = metaDataForProcess.lumis();
0035     lumis.push_back(11);
0036     edm::MergeableRunProductMetadata::MetadataForProcess const& acref(metaDataForProcess);
0037     REQUIRE(acref.lumis().at(0) == 11);
0038 
0039     metaDataForProcess.setMergeDecision(edm::MergeableRunProductMetadata::IGNORE);
0040     metaDataForProcess.setValid(false);
0041     metaDataForProcess.setUseIndexIntoFile(true);
0042     metaDataForProcess.setAllLumisProcessed(true);
0043 
0044     REQUIRE(!metaDataForProcess.valid());
0045     REQUIRE(metaDataForProcess.useIndexIntoFile());
0046     REQUIRE(metaDataForProcess.allLumisProcessed());
0047     REQUIRE(metaDataForProcess.mergeDecision() == edm::MergeableRunProductMetadata::IGNORE);
0048 
0049     metaDataForProcess.reset();
0050     REQUIRE(metaDataForProcess.lumis().empty());
0051     REQUIRE(metaDataForProcess.valid());
0052     REQUIRE(!metaDataForProcess.useIndexIntoFile());
0053     REQUIRE(!metaDataForProcess.allLumisProcessed());
0054     REQUIRE(metaDataForProcess.mergeDecision() == edm::MergeableRunProductMetadata::MERGE);
0055   }
0056 
0057   SECTION("test constructor") {
0058     // edm::MergeableRunProductMetadata mergeableRunProductMetadata(nullptr);
0059     // REQUIRE(mergeableRunProductMetadata.metadataForProcesses().empty());
0060 
0061     edm::MergeableRunProductProcesses mergeableRunProductProcesses;
0062     edm::MergeableRunProductMetadata mergeableRunProductMetadata2(mergeableRunProductProcesses);
0063     REQUIRE(mergeableRunProductMetadata2.metadataForProcesses().empty());
0064   }
0065 
0066   SECTION("test main functions") {
0067     edm::ProductRegistry productRegistry;
0068     edm::ParameterSet dummyPset;
0069     dummyPset.registerIt();
0070 
0071     // not mergeable
0072     edm::BranchDescription prod1(edm::InRun,
0073                                  "label",
0074                                  "PROD",
0075                                  "edmtest::Thing",
0076                                  "edmtestThing",
0077                                  "instance",
0078                                  "aModule",
0079                                  dummyPset.id(),
0080                                  edm::TypeWithDict::byName("edmtest::Thing"),
0081                                  false);
0082     productRegistry.copyProduct(prod1);
0083 
0084     // This one should be used
0085     edm::BranchDescription prod2(edm::InRun,
0086                                  "aLabel",
0087                                  "APROD",
0088                                  "edmtest::ThingWithMerge",
0089                                  "edmtestThingWithMerge",
0090                                  "instance",
0091                                  "aModule",
0092                                  dummyPset.id(),
0093                                  edm::TypeWithDict::byName("edmtest::ThingWithMerge"),
0094                                  false);
0095     productRegistry.copyProduct(prod2);
0096 
0097     //not in a Run
0098     edm::BranchDescription prod3(edm::InLumi,
0099                                  "bLabel",
0100                                  "BPROD",
0101                                  "edmtest::ThingWithMerge",
0102                                  "edmtestThingWithMerge",
0103                                  "instance",
0104                                  "aModule",
0105                                  dummyPset.id(),
0106                                  edm::TypeWithDict::byName("edmtest::ThingWithMerge"),
0107                                  false);
0108     productRegistry.copyProduct(prod3);
0109 
0110     // produced
0111     edm::BranchDescription prod4(edm::InRun,
0112                                  "cLabel",
0113                                  "CPROD",
0114                                  "edmtest::ThingWithMerge",
0115                                  "edmtestThingWithMerge",
0116                                  "instance",
0117                                  "aModule",
0118                                  dummyPset.id(),
0119                                  edm::TypeWithDict::byName("edmtest::ThingWithMerge"),
0120                                  true);
0121     productRegistry.addProduct(prod4);
0122 
0123     // dropped
0124     edm::BranchDescription prod5(edm::InRun,
0125                                  "dLabel",
0126                                  "DPROD",
0127                                  "edmtest::ThingWithMerge",
0128                                  "edmtestThingWithMerge",
0129                                  "instance",
0130                                  "aModule",
0131                                  dummyPset.id(),
0132                                  edm::TypeWithDict::byName("edmtest::ThingWithMerge"),
0133                                  false);
0134     prod5.setDropped(true);
0135     productRegistry.copyProduct(prod5);
0136 
0137     // Should be used but the same process name
0138     edm::BranchDescription prod6(edm::InRun,
0139                                  "eLabel",
0140                                  "APROD",
0141                                  "edmtest::ThingWithMerge",
0142                                  "edmtestThingWithMerge",
0143                                  "instance",
0144                                  "aModule",
0145                                  dummyPset.id(),
0146                                  edm::TypeWithDict::byName("edmtest::ThingWithMerge"),
0147                                  false);
0148     productRegistry.copyProduct(prod6);
0149 
0150     // Should be used
0151     edm::BranchDescription prod7(edm::InRun,
0152                                  "fLabel",
0153                                  "AAPROD",
0154                                  "edmtest::ThingWithMerge",
0155                                  "edmtestThingWithMerge",
0156                                  "instance",
0157                                  "aModule",
0158                                  dummyPset.id(),
0159                                  edm::TypeWithDict::byName("edmtest::ThingWithMerge"),
0160                                  false);
0161     productRegistry.copyProduct(prod7);
0162 
0163     edm::MergeableRunProductProcesses mergeableRunProductProcesses;
0164 
0165     REQUIRE(mergeableRunProductProcesses.size() == 0);
0166 
0167     mergeableRunProductProcesses.setProcessesWithMergeableRunProducts(productRegistry);
0168 
0169     REQUIRE(mergeableRunProductProcesses.size() == 2);
0170 
0171     {
0172       std::vector<std::string> expected{"AAPROD", "APROD"};
0173       REQUIRE(mergeableRunProductProcesses.processesWithMergeableRunProducts() == expected);
0174     }
0175     std::vector<std::string> storedProcesses{"AAAPROD", "AAPROD", "APROD", "ZPROD"};
0176     edm::StoredMergeableRunProductMetadata storedMetadata(storedProcesses);
0177     REQUIRE(storedMetadata.processesWithMergeableRunProducts() == storedProcesses);
0178     REQUIRE(storedMetadata.allValidAndUseIndexIntoFile());
0179 
0180     unsigned long long iBeginProcess{100};
0181     unsigned long long iEndProcess{101};
0182     edm::StoredMergeableRunProductMetadata::SingleRunEntry singleRunEntry(iBeginProcess, iEndProcess);
0183     REQUIRE(singleRunEntry.beginProcess() == 100);
0184     REQUIRE(singleRunEntry.endProcess() == 101);
0185 
0186     unsigned long long iBeginLumi{200};
0187     unsigned long long iEndLumi{201};
0188     unsigned int iProcess{202};
0189     bool iValid{true};
0190     bool iUseIndexIntoFile{false};
0191     edm::StoredMergeableRunProductMetadata::SingleRunEntryAndProcess singleRunEntryAndProcess(
0192         iBeginLumi, iEndLumi, iProcess, iValid, iUseIndexIntoFile);
0193     REQUIRE(singleRunEntryAndProcess.beginLumi() == 200);
0194     REQUIRE(singleRunEntryAndProcess.endLumi() == 201);
0195     REQUIRE(singleRunEntryAndProcess.process() == 202);
0196     REQUIRE(singleRunEntryAndProcess.valid() == true);
0197     REQUIRE(singleRunEntryAndProcess.useIndexIntoFile() == false);
0198 
0199     // Fill storedMetadata with fake data
0200     // 9 run entries
0201     // Let AAPROD be not present for all run entries
0202     // Let APROD be there with a vector
0203     //              not there at all (no entries for any process)
0204     //              there invalid with no vector
0205     //              not there at all
0206     //              there with a vector and invalid
0207     // Let AAAPROD and ZPROD be there for all entries 0, 2, 3, 4
0208     {
0209       std::vector<edm::StoredMergeableRunProductMetadata::SingleRunEntry>& singleRunEntries =
0210           storedMetadata.singleRunEntries();
0211       singleRunEntries.emplace_back(0, 3);
0212       singleRunEntries.emplace_back(3, 3);
0213       singleRunEntries.emplace_back(3, 6);
0214       singleRunEntries.emplace_back(6, 8);
0215       singleRunEntries.emplace_back(8, 11);
0216       singleRunEntries.emplace_back(11, 12);
0217       singleRunEntries.emplace_back(12, 13);
0218       singleRunEntries.emplace_back(13, 14);
0219       singleRunEntries.emplace_back(14, 15);
0220 
0221       std::vector<edm::StoredMergeableRunProductMetadata::SingleRunEntryAndProcess>& singleRunEntryAndProcesses =
0222           storedMetadata.singleRunEntryAndProcesses();
0223       std::vector<edm::LuminosityBlockNumber_t>& lumis = storedMetadata.lumis();
0224 
0225       // arguments: beginLumi, endLumi, process Index, valid, useIndexIntoFile
0226       unsigned int iAAAPROD{0};
0227       // unsigned int iAAPROD { 1 };
0228       unsigned int iAPROD{2};
0229       unsigned int iZPROD{3};
0230 
0231       // 0th run entry
0232       iBeginLumi = lumis.size();
0233       lumis.emplace_back(1);
0234       lumis.emplace_back(2);
0235       iEndLumi = lumis.size();
0236       singleRunEntryAndProcesses.emplace_back(iBeginLumi, iEndLumi, iAAAPROD, true, false);
0237 
0238       iBeginLumi = lumis.size();
0239       lumis.emplace_back(101);
0240       lumis.emplace_back(102);
0241       iEndLumi = lumis.size();
0242       singleRunEntryAndProcesses.emplace_back(iBeginLumi, iEndLumi, iAPROD, true, false);
0243 
0244       iBeginLumi = lumis.size();
0245       lumis.emplace_back(1);
0246       lumis.emplace_back(2);
0247       iEndLumi = lumis.size();
0248       singleRunEntryAndProcesses.emplace_back(iBeginLumi, iEndLumi, iZPROD, true, false);
0249 
0250       // nothing in the 1st entry
0251 
0252       // 2nd run entry
0253       iBeginLumi = lumis.size();
0254       lumis.emplace_back(1);
0255       lumis.emplace_back(2);
0256       iEndLumi = lumis.size();
0257       singleRunEntryAndProcesses.emplace_back(iBeginLumi, iEndLumi, iAAAPROD, true, false);
0258 
0259       iBeginLumi = lumis.size();
0260       iEndLumi = lumis.size();
0261       singleRunEntryAndProcesses.emplace_back(iBeginLumi, iEndLumi, iAPROD, false, true);
0262 
0263       iBeginLumi = lumis.size();
0264       lumis.emplace_back(1);
0265       lumis.emplace_back(2);
0266       iEndLumi = lumis.size();
0267       singleRunEntryAndProcesses.emplace_back(iBeginLumi, iEndLumi, iZPROD, true, false);
0268 
0269       // 3rd run entry
0270       iBeginLumi = lumis.size();
0271       lumis.emplace_back(1);
0272       lumis.emplace_back(2);
0273       iEndLumi = lumis.size();
0274       singleRunEntryAndProcesses.emplace_back(iBeginLumi, iEndLumi, iAAAPROD, true, false);
0275 
0276       iBeginLumi = lumis.size();
0277       lumis.emplace_back(1);
0278       lumis.emplace_back(2);
0279       iEndLumi = lumis.size();
0280       singleRunEntryAndProcesses.emplace_back(iBeginLumi, iEndLumi, iZPROD, true, false);
0281 
0282       // 4th run entry
0283       iBeginLumi = lumis.size();
0284       lumis.emplace_back(1);
0285       lumis.emplace_back(2);
0286       iEndLumi = lumis.size();
0287       singleRunEntryAndProcesses.emplace_back(iBeginLumi, iEndLumi, iAAAPROD, true, false);
0288 
0289       iBeginLumi = lumis.size();
0290       lumis.emplace_back(111);
0291       lumis.emplace_back(112);
0292       iEndLumi = lumis.size();
0293       singleRunEntryAndProcesses.emplace_back(iBeginLumi, iEndLumi, iAPROD, false, false);
0294 
0295       iBeginLumi = lumis.size();
0296       lumis.emplace_back(1);
0297       lumis.emplace_back(2);
0298       iEndLumi = lumis.size();
0299       singleRunEntryAndProcesses.emplace_back(iBeginLumi, iEndLumi, iZPROD, true, false);
0300 
0301       // 5th entry
0302       iBeginLumi = lumis.size();
0303       lumis.emplace_back(91);
0304       lumis.emplace_back(92);
0305       iEndLumi = lumis.size();
0306       singleRunEntryAndProcesses.emplace_back(iBeginLumi, iEndLumi, iAPROD, true, false);
0307 
0308       // 6th entry
0309       iBeginLumi = lumis.size();
0310       lumis.emplace_back(121);
0311       lumis.emplace_back(122);
0312       iEndLumi = lumis.size();
0313       singleRunEntryAndProcesses.emplace_back(iBeginLumi, iEndLumi, iAPROD, true, false);
0314 
0315       // 7th entry
0316       iBeginLumi = lumis.size();
0317       lumis.emplace_back(95);
0318       lumis.emplace_back(101);
0319       lumis.emplace_back(105);
0320       iEndLumi = lumis.size();
0321       singleRunEntryAndProcesses.emplace_back(iBeginLumi, iEndLumi, iAPROD, true, false);
0322 
0323       // 8th entry
0324       iBeginLumi = lumis.size();
0325       lumis.emplace_back(1000);
0326       lumis.emplace_back(1002);
0327       lumis.emplace_back(1003);
0328       lumis.emplace_back(1004);
0329       iEndLumi = lumis.size();
0330       singleRunEntryAndProcesses.emplace_back(iBeginLumi, iEndLumi, iAPROD, true, false);
0331     }
0332 
0333     storedMetadata.allValidAndUseIndexIntoFile() = false;
0334 
0335     bool valid;
0336     std::vector<edm::LuminosityBlockNumber_t>::const_iterator lumisBegin;
0337     std::vector<edm::LuminosityBlockNumber_t>::const_iterator lumisEnd;
0338     REQUIRE(storedMetadata.getLumiContent(0, std::string("APROD"), valid, lumisBegin, lumisEnd));
0339     {
0340       std::vector<edm::LuminosityBlockNumber_t> test(lumisBegin, lumisEnd);
0341       std::vector<edm::LuminosityBlockNumber_t> expected{101, 102};
0342       REQUIRE(test == expected);
0343       REQUIRE(valid);
0344     }
0345     REQUIRE(!storedMetadata.getLumiContent(1, std::string("APROD"), valid, lumisBegin, lumisEnd));
0346     REQUIRE(valid);
0347     REQUIRE(!storedMetadata.getLumiContent(2, std::string("APROD"), valid, lumisBegin, lumisEnd));
0348     REQUIRE(!valid);
0349     REQUIRE(!storedMetadata.getLumiContent(3, std::string("APROD"), valid, lumisBegin, lumisEnd));
0350     REQUIRE(valid);
0351     REQUIRE(storedMetadata.getLumiContent(4, std::string("APROD"), valid, lumisBegin, lumisEnd));
0352     {
0353       std::vector<edm::LuminosityBlockNumber_t> test(lumisBegin, lumisEnd);
0354       std::vector<edm::LuminosityBlockNumber_t> expected{111, 112};
0355       REQUIRE(test == expected);
0356       REQUIRE(!valid);
0357     }
0358 
0359     edm::IndexIntoFile indexIntoFile;
0360 
0361     edm::ProcessHistoryID fakePHID1;
0362     edm::ProcessConfiguration pc;
0363     auto processHistory1 = std::make_unique<edm::ProcessHistory>();
0364     edm::ProcessHistory& ph1 = *processHistory1;
0365     processHistory1->push_back(pc);
0366     fakePHID1 = ph1.id();
0367 
0368     edm::ProcessHistoryID fakePHID2;
0369     auto processHistory2 = std::make_unique<edm::ProcessHistory>();
0370     edm::ProcessHistory& ph2 = *processHistory2;
0371     processHistory2->push_back(pc);
0372     processHistory2->push_back(pc);
0373     fakePHID2 = ph2.id();
0374 
0375     indexIntoFile.addEntry(fakePHID1, 11, 1001, 7, 0);  // Event
0376     indexIntoFile.addEntry(fakePHID1, 11, 1001, 6, 1);  // Event
0377     indexIntoFile.addEntry(fakePHID1, 11, 1001, 0, 0);  // Lumi
0378     indexIntoFile.addEntry(fakePHID1, 11, 1001, 0, 1);  // Lumi
0379     indexIntoFile.addEntry(fakePHID1, 11, 1001, 5, 2);  // Event
0380     indexIntoFile.addEntry(fakePHID1, 11, 1001, 4, 3);  // Event
0381     indexIntoFile.addEntry(fakePHID1, 11, 1001, 0, 2);  // Lumi
0382     indexIntoFile.addEntry(fakePHID1, 11, 1003, 5, 4);  // Event
0383     indexIntoFile.addEntry(fakePHID1, 11, 1003, 4, 5);  // Event
0384     indexIntoFile.addEntry(fakePHID1, 11, 1003, 0, 3);  // Lumi
0385     indexIntoFile.addEntry(fakePHID1, 11, 0, 0, 0);     // Run
0386     indexIntoFile.addEntry(fakePHID2, 11, 0, 0, 1);     // Run
0387     indexIntoFile.addEntry(fakePHID2, 11, 1001, 0, 4);  // Lumi
0388     indexIntoFile.addEntry(fakePHID2, 11, 1003, 0, 5);  // Lumi
0389     indexIntoFile.addEntry(fakePHID2, 11, 1003, 4, 6);  // Event
0390     indexIntoFile.addEntry(fakePHID2, 11, 1003, 0, 6);  // Lumi
0391     indexIntoFile.addEntry(fakePHID2, 11, 0, 0, 2);     // Run
0392     indexIntoFile.sortVector_Run_Or_Lumi_Entries();
0393     edm::IndexIntoFile::IndexIntoFileItr iter = indexIntoFile.begin(edm::IndexIntoFile::firstAppearanceOrder);
0394 
0395     edm::MergeableRunProductMetadata mergeableRunProductMetadata(mergeableRunProductProcesses);
0396 
0397     edm::MergeableRunProductMetadata::MetadataForProcess const* APRODMetadataForProcess =
0398         mergeableRunProductMetadata.metadataForOneProcess("APROD");
0399     REQUIRE(APRODMetadataForProcess);
0400 
0401     edm::MergeableRunProductMetadata::MetadataForProcess const* NullMetadataForProcess =
0402         mergeableRunProductMetadata.metadataForOneProcess("DOESNOTEXIST");
0403     REQUIRE(NullMetadataForProcess == nullptr);
0404 
0405     mergeableRunProductMetadata.readRun(0, storedMetadata, edm::IndexIntoFileItrHolder(iter));
0406     {
0407       std::vector<edm::LuminosityBlockNumber_t> expected{101, 102};
0408       REQUIRE(APRODMetadataForProcess->lumis() == expected);
0409       REQUIRE(APRODMetadataForProcess->mergeDecision() == edm::MergeableRunProductMetadata::REPLACE);
0410       REQUIRE(mergeableRunProductMetadata.getMergeDecision("APROD") == edm::MergeableRunProductMetadata::REPLACE);
0411       REQUIRE(APRODMetadataForProcess->valid());
0412       REQUIRE(!mergeableRunProductMetadata.knownImproperlyMerged("APROD"));
0413       REQUIRE(!APRODMetadataForProcess->useIndexIntoFile());
0414       REQUIRE(!APRODMetadataForProcess->allLumisProcessed());
0415     }
0416     // Same one again for test purposes
0417     mergeableRunProductMetadata.readRun(0, storedMetadata, edm::IndexIntoFileItrHolder(iter));
0418     {
0419       std::vector<edm::LuminosityBlockNumber_t> expected{101, 102};
0420       REQUIRE(APRODMetadataForProcess->lumis() == expected);
0421       REQUIRE(APRODMetadataForProcess->mergeDecision() == edm::MergeableRunProductMetadata::IGNORE);
0422       REQUIRE(mergeableRunProductMetadata.getMergeDecision("APROD") == edm::MergeableRunProductMetadata::IGNORE);
0423       REQUIRE(APRODMetadataForProcess->valid());
0424       REQUIRE(!APRODMetadataForProcess->useIndexIntoFile());
0425       REQUIRE(!APRODMetadataForProcess->allLumisProcessed());
0426     }
0427     // disjoint with newly read ones coming first
0428     mergeableRunProductMetadata.readRun(5, storedMetadata, edm::IndexIntoFileItrHolder(iter));
0429     {
0430       std::vector<edm::LuminosityBlockNumber_t> expected{91, 92, 101, 102};
0431       REQUIRE(APRODMetadataForProcess->lumis() == expected);
0432       REQUIRE(APRODMetadataForProcess->mergeDecision() == edm::MergeableRunProductMetadata::MERGE);
0433       REQUIRE(mergeableRunProductMetadata.getMergeDecision("APROD") == edm::MergeableRunProductMetadata::MERGE);
0434       REQUIRE(APRODMetadataForProcess->valid());
0435       REQUIRE(!APRODMetadataForProcess->useIndexIntoFile());
0436       REQUIRE(!APRODMetadataForProcess->allLumisProcessed());
0437     }
0438     // disjoint with newly read ones coming last
0439     mergeableRunProductMetadata.readRun(6, storedMetadata, edm::IndexIntoFileItrHolder(iter));
0440     {
0441       std::vector<edm::LuminosityBlockNumber_t> expected{91, 92, 101, 102, 121, 122};
0442       REQUIRE(APRODMetadataForProcess->lumis() == expected);
0443       REQUIRE(APRODMetadataForProcess->mergeDecision() == edm::MergeableRunProductMetadata::MERGE);
0444       REQUIRE(APRODMetadataForProcess->valid());
0445       REQUIRE(!APRODMetadataForProcess->useIndexIntoFile());
0446       REQUIRE(!APRODMetadataForProcess->allLumisProcessed());
0447     }
0448     // impossible to merge case, shared elements and both also have at least one non-shared element
0449     mergeableRunProductMetadata.readRun(7, storedMetadata, edm::IndexIntoFileItrHolder(iter));
0450     {
0451       std::vector<edm::LuminosityBlockNumber_t> expected{91, 92, 95, 101, 102, 105, 121, 122};
0452       REQUIRE(APRODMetadataForProcess->lumis() == expected);
0453       REQUIRE(APRODMetadataForProcess->mergeDecision() == edm::MergeableRunProductMetadata::MERGE);
0454       REQUIRE(!APRODMetadataForProcess->valid());
0455       REQUIRE(!APRODMetadataForProcess->useIndexIntoFile());
0456       REQUIRE(!APRODMetadataForProcess->allLumisProcessed());
0457     }
0458     mergeableRunProductMetadata.preReadFile();
0459     {
0460       std::vector<edm::LuminosityBlockNumber_t> expected{91, 92, 95, 101, 102, 105, 121, 122};
0461       REQUIRE(APRODMetadataForProcess->lumis() == expected);
0462       REQUIRE(!APRODMetadataForProcess->useIndexIntoFile());
0463     }
0464     mergeableRunProductMetadata.readRun(3, storedMetadata, edm::IndexIntoFileItrHolder(iter));
0465     {
0466       std::vector<edm::LuminosityBlockNumber_t> expected{91, 92, 95, 101, 102, 105, 121, 122};
0467       REQUIRE(APRODMetadataForProcess->lumis() == expected);
0468       REQUIRE(APRODMetadataForProcess->mergeDecision() == edm::MergeableRunProductMetadata::MERGE);
0469       REQUIRE(!APRODMetadataForProcess->valid());
0470       REQUIRE(APRODMetadataForProcess->useIndexIntoFile());
0471       REQUIRE(!APRODMetadataForProcess->allLumisProcessed());
0472     }
0473     mergeableRunProductMetadata.preReadFile();
0474     {
0475       std::vector<edm::LuminosityBlockNumber_t> expected{91, 92, 95, 101, 102, 105, 121, 122, 1001, 1003};
0476       REQUIRE(APRODMetadataForProcess->lumis() == expected);
0477       REQUIRE(!APRODMetadataForProcess->useIndexIntoFile());
0478     }
0479 
0480     mergeableRunProductMetadata.postWriteRun();
0481     {
0482       std::vector<edm::LuminosityBlockNumber_t> expected;
0483       REQUIRE(APRODMetadataForProcess->lumis() == expected);
0484       REQUIRE(APRODMetadataForProcess->mergeDecision() == edm::MergeableRunProductMetadata::MERGE);
0485       REQUIRE(APRODMetadataForProcess->valid());
0486       REQUIRE(!APRODMetadataForProcess->useIndexIntoFile());
0487       REQUIRE(!APRODMetadataForProcess->allLumisProcessed());
0488     }
0489     mergeableRunProductMetadata.readRun(0, storedMetadata, edm::IndexIntoFileItrHolder(iter));
0490     {
0491       std::vector<edm::LuminosityBlockNumber_t> expected{101, 102};
0492       REQUIRE(APRODMetadataForProcess->lumis() == expected);
0493       REQUIRE(APRODMetadataForProcess->mergeDecision() == edm::MergeableRunProductMetadata::REPLACE);
0494       REQUIRE(APRODMetadataForProcess->valid());
0495       REQUIRE(!APRODMetadataForProcess->useIndexIntoFile());
0496       REQUIRE(!APRODMetadataForProcess->allLumisProcessed());
0497     }
0498     mergeableRunProductMetadata.readRun(4, storedMetadata, edm::IndexIntoFileItrHolder(iter));
0499     {
0500       std::vector<edm::LuminosityBlockNumber_t> expected{101, 102, 111, 112};
0501       REQUIRE(APRODMetadataForProcess->lumis() == expected);
0502       REQUIRE(APRODMetadataForProcess->mergeDecision() == edm::MergeableRunProductMetadata::MERGE);
0503       REQUIRE(!APRODMetadataForProcess->valid());
0504       REQUIRE(mergeableRunProductMetadata.knownImproperlyMerged("APROD"));
0505       REQUIRE(!APRODMetadataForProcess->useIndexIntoFile());
0506       REQUIRE(!APRODMetadataForProcess->allLumisProcessed());
0507     }
0508     mergeableRunProductMetadata.preReadFile();
0509     mergeableRunProductMetadata.postWriteRun();
0510     {
0511       std::vector<edm::LuminosityBlockNumber_t> expected;
0512       REQUIRE(expected == mergeableRunProductMetadata.lumisFromIndexIntoFile());
0513       REQUIRE(!mergeableRunProductMetadata.gotLumisFromIndexIntoFile());
0514 
0515       mergeableRunProductMetadata.readRun(1, storedMetadata, edm::IndexIntoFileItrHolder(iter));
0516 
0517       REQUIRE(APRODMetadataForProcess->lumis() == expected);
0518       REQUIRE(APRODMetadataForProcess->mergeDecision() == edm::MergeableRunProductMetadata::MERGE);
0519       REQUIRE(APRODMetadataForProcess->valid());
0520       REQUIRE(APRODMetadataForProcess->useIndexIntoFile());
0521       REQUIRE(!APRODMetadataForProcess->allLumisProcessed());
0522 
0523       expected = std::vector<edm::LuminosityBlockNumber_t>{1001, 1003};
0524       REQUIRE(expected == mergeableRunProductMetadata.lumisFromIndexIntoFile());
0525       REQUIRE(mergeableRunProductMetadata.gotLumisFromIndexIntoFile());
0526     }
0527     mergeableRunProductMetadata.preReadFile();
0528     {
0529       std::vector<edm::LuminosityBlockNumber_t> expected;
0530       REQUIRE(expected == mergeableRunProductMetadata.lumisFromIndexIntoFile());
0531       REQUIRE(!mergeableRunProductMetadata.gotLumisFromIndexIntoFile());
0532 
0533       expected = std::vector<edm::LuminosityBlockNumber_t>{1001, 1003};
0534       REQUIRE(APRODMetadataForProcess->lumis() == expected);
0535       REQUIRE(!APRODMetadataForProcess->useIndexIntoFile());
0536       REQUIRE(!APRODMetadataForProcess->allLumisProcessed());
0537     }
0538 
0539     mergeableRunProductMetadata.postWriteRun();
0540     {
0541       mergeableRunProductMetadata.readRun(2, storedMetadata, edm::IndexIntoFileItrHolder(iter));
0542 
0543       std::vector<edm::LuminosityBlockNumber_t> expected;
0544       REQUIRE(APRODMetadataForProcess->lumis() == expected);
0545       REQUIRE(APRODMetadataForProcess->mergeDecision() == edm::MergeableRunProductMetadata::MERGE);
0546       REQUIRE(!APRODMetadataForProcess->valid());
0547       REQUIRE(APRODMetadataForProcess->useIndexIntoFile());
0548       REQUIRE(!APRODMetadataForProcess->allLumisProcessed());
0549 
0550       expected = std::vector<edm::LuminosityBlockNumber_t>{1001, 1003};
0551       REQUIRE(expected == mergeableRunProductMetadata.lumisFromIndexIntoFile());
0552       REQUIRE(mergeableRunProductMetadata.gotLumisFromIndexIntoFile());
0553     }
0554     {
0555       mergeableRunProductMetadata.readRun(8, storedMetadata, edm::IndexIntoFileItrHolder(iter));
0556       std::vector<edm::LuminosityBlockNumber_t> expected{1000, 1002, 1003, 1004};
0557       REQUIRE(APRODMetadataForProcess->lumis() == expected);
0558       mergeableRunProductMetadata.readRun(2, storedMetadata, edm::IndexIntoFileItrHolder(iter));
0559       REQUIRE(APRODMetadataForProcess->lumis() == expected);
0560       mergeableRunProductMetadata.preReadFile();
0561       expected = std::vector<edm::LuminosityBlockNumber_t>{1000, 1001, 1002, 1003, 1004};
0562       REQUIRE(APRODMetadataForProcess->lumis() == expected);
0563     }
0564     mergeableRunProductMetadata.postWriteRun();
0565 
0566     {
0567       mergeableRunProductMetadata.readRun(2, storedMetadata, edm::IndexIntoFileItrHolder(iter));
0568       mergeableRunProductMetadata.readRun(8, storedMetadata, edm::IndexIntoFileItrHolder(iter));
0569 
0570       std::vector<edm::LuminosityBlockNumber_t> expected{1001, 1003};
0571       REQUIRE(expected == mergeableRunProductMetadata.lumisFromIndexIntoFile());
0572       REQUIRE(mergeableRunProductMetadata.gotLumisFromIndexIntoFile());
0573 
0574       expected = std::vector<edm::LuminosityBlockNumber_t>{1000, 1002, 1003, 1004};
0575       REQUIRE(APRODMetadataForProcess->lumis() == expected);
0576 
0577       mergeableRunProductMetadata.writeLumi(1004);
0578       mergeableRunProductMetadata.writeLumi(1002);
0579       mergeableRunProductMetadata.writeLumi(1002);
0580       mergeableRunProductMetadata.preWriteRun();
0581 
0582       expected.clear();
0583       REQUIRE(expected == mergeableRunProductMetadata.lumisFromIndexIntoFile());
0584       REQUIRE(!mergeableRunProductMetadata.gotLumisFromIndexIntoFile());
0585       REQUIRE(!APRODMetadataForProcess->allLumisProcessed());
0586 
0587       expected = std::vector<edm::LuminosityBlockNumber_t>{1000, 1001, 1002, 1003, 1004};
0588       REQUIRE(APRODMetadataForProcess->lumis() == expected);
0589     }
0590     mergeableRunProductMetadata.postWriteRun();
0591     REQUIRE(mergeableRunProductMetadata.lumisProcessed().empty());
0592     {
0593       // ----------------------------------------------------
0594 
0595       std::vector<std::string> storedProcessesOutput{"AAAPROD", "AAPROD", "APROD", "ZPROD"};
0596       edm::StoredMergeableRunProductMetadata storedMetadataOutput(storedProcesses);
0597 
0598       mergeableRunProductMetadata.readRun(1, storedMetadata, edm::IndexIntoFileItrHolder(iter));
0599       mergeableRunProductMetadata.writeLumi(1003);
0600       mergeableRunProductMetadata.writeLumi(1001);
0601       mergeableRunProductMetadata.preWriteRun();
0602       mergeableRunProductMetadata.addEntryToStoredMetadata(storedMetadataOutput);
0603       mergeableRunProductMetadata.postWriteRun();
0604 
0605       REQUIRE(storedMetadataOutput.allValidAndUseIndexIntoFile());
0606 
0607       // ---------------------------------------------------
0608 
0609       mergeableRunProductMetadata.readRun(2, storedMetadata, edm::IndexIntoFileItrHolder(iter));
0610       mergeableRunProductMetadata.readRun(8, storedMetadata, edm::IndexIntoFileItrHolder(iter));
0611 
0612       std::vector<edm::LuminosityBlockNumber_t> expected{1001, 1003};
0613       REQUIRE(expected == mergeableRunProductMetadata.lumisFromIndexIntoFile());
0614       REQUIRE(mergeableRunProductMetadata.gotLumisFromIndexIntoFile());
0615 
0616       expected = std::vector<edm::LuminosityBlockNumber_t>{1000, 1002, 1003, 1004};
0617       REQUIRE(APRODMetadataForProcess->lumis() == expected);
0618 
0619       mergeableRunProductMetadata.writeLumi(1004);
0620       mergeableRunProductMetadata.writeLumi(1002);
0621       mergeableRunProductMetadata.writeLumi(1002);
0622       mergeableRunProductMetadata.writeLumi(1000);
0623       mergeableRunProductMetadata.writeLumi(1001);
0624       mergeableRunProductMetadata.writeLumi(1003);
0625       mergeableRunProductMetadata.preWriteRun();
0626 
0627       expected.clear();
0628       REQUIRE(expected == mergeableRunProductMetadata.lumisFromIndexIntoFile());
0629       REQUIRE(!mergeableRunProductMetadata.gotLumisFromIndexIntoFile());
0630       REQUIRE(APRODMetadataForProcess->allLumisProcessed());
0631 
0632       expected = std::vector<edm::LuminosityBlockNumber_t>{1000, 1001, 1002, 1003, 1004};
0633       REQUIRE(APRODMetadataForProcess->lumis() == expected);
0634 
0635       mergeableRunProductMetadata.addEntryToStoredMetadata(storedMetadataOutput);
0636 
0637       // ----------------------------------------------------
0638 
0639       mergeableRunProductMetadata.postWriteRun();
0640       mergeableRunProductMetadata.readRun(2, storedMetadata, edm::IndexIntoFileItrHolder(iter));
0641       mergeableRunProductMetadata.preWriteRun();
0642       mergeableRunProductMetadata.addEntryToStoredMetadata(storedMetadataOutput);
0643 
0644       // ----------------------------------------------------
0645 
0646       mergeableRunProductMetadata.readRun(2, storedMetadata, edm::IndexIntoFileItrHolder(iter));
0647       mergeableRunProductMetadata.readRun(8, storedMetadata, edm::IndexIntoFileItrHolder(iter));
0648       mergeableRunProductMetadata.writeLumi(1004);
0649       mergeableRunProductMetadata.writeLumi(1002);
0650       mergeableRunProductMetadata.writeLumi(1002);
0651       mergeableRunProductMetadata.writeLumi(1000);
0652       mergeableRunProductMetadata.writeLumi(1001);
0653       mergeableRunProductMetadata.preWriteRun();
0654       mergeableRunProductMetadata.addEntryToStoredMetadata(storedMetadataOutput);
0655       mergeableRunProductMetadata.postWriteRun();
0656 
0657       // ---------------------------------------------------
0658       {
0659         std::vector<edm::StoredMergeableRunProductMetadata::SingleRunEntry>& singleRunEntries =
0660             storedMetadataOutput.singleRunEntries();
0661         REQUIRE(singleRunEntries.size() == 4);
0662         REQUIRE(singleRunEntries[0].beginProcess() == 0);
0663         REQUIRE(singleRunEntries[0].endProcess() == 0);
0664         REQUIRE(singleRunEntries[1].beginProcess() == 0);
0665         REQUIRE(singleRunEntries[1].endProcess() == 1);
0666         REQUIRE(singleRunEntries[2].beginProcess() == 1);
0667         REQUIRE(singleRunEntries[2].endProcess() == 3);
0668         REQUIRE(singleRunEntries[3].beginProcess() == 3);
0669         REQUIRE(singleRunEntries[3].endProcess() == 5);
0670 
0671         std::vector<edm::StoredMergeableRunProductMetadata::SingleRunEntryAndProcess>& singleRunEntryAndProcesses =
0672             storedMetadataOutput.singleRunEntryAndProcesses();
0673         REQUIRE(singleRunEntryAndProcesses.size() == 5);
0674 
0675         REQUIRE(singleRunEntryAndProcesses[0].beginLumi() == 0);
0676         REQUIRE(singleRunEntryAndProcesses[0].endLumi() == 0);
0677         REQUIRE(singleRunEntryAndProcesses[0].process() == 2);
0678         REQUIRE(!singleRunEntryAndProcesses[0].valid());
0679         REQUIRE(singleRunEntryAndProcesses[0].useIndexIntoFile());
0680 
0681         REQUIRE(singleRunEntryAndProcesses[1].beginLumi() == 0);
0682         REQUIRE(singleRunEntryAndProcesses[1].endLumi() == 2);
0683         REQUIRE(singleRunEntryAndProcesses[1].process() == 1);
0684         REQUIRE(singleRunEntryAndProcesses[1].valid());
0685         REQUIRE(!singleRunEntryAndProcesses[1].useIndexIntoFile());
0686 
0687         REQUIRE(singleRunEntryAndProcesses[2].beginLumi() == 0);
0688         REQUIRE(singleRunEntryAndProcesses[2].endLumi() == 2);
0689         REQUIRE(singleRunEntryAndProcesses[2].process() == 2);
0690         REQUIRE(!singleRunEntryAndProcesses[2].valid());
0691         REQUIRE(!singleRunEntryAndProcesses[2].useIndexIntoFile());
0692 
0693         REQUIRE(singleRunEntryAndProcesses[3].beginLumi() == 2);
0694         REQUIRE(singleRunEntryAndProcesses[3].endLumi() == 4);
0695         REQUIRE(singleRunEntryAndProcesses[3].process() == 1);
0696         REQUIRE(singleRunEntryAndProcesses[3].valid());
0697         REQUIRE(!singleRunEntryAndProcesses[3].useIndexIntoFile());
0698 
0699         REQUIRE(singleRunEntryAndProcesses[4].beginLumi() == 4);
0700         REQUIRE(singleRunEntryAndProcesses[4].endLumi() == 9);
0701         REQUIRE(singleRunEntryAndProcesses[4].process() == 2);
0702         REQUIRE(!singleRunEntryAndProcesses[4].valid());
0703         REQUIRE(!singleRunEntryAndProcesses[4].useIndexIntoFile());
0704 
0705         std::vector<edm::LuminosityBlockNumber_t>& lumis = storedMetadataOutput.lumis();
0706         REQUIRE(lumis.size() == 9);
0707         REQUIRE(lumis[0] == 1001);
0708         REQUIRE(lumis[1] == 1003);
0709         REQUIRE(lumis[2] == 1001);
0710         REQUIRE(lumis[3] == 1003);
0711         REQUIRE(lumis[4] == 1000);
0712         REQUIRE(lumis[5] == 1001);
0713         REQUIRE(lumis[6] == 1002);
0714         REQUIRE(lumis[7] == 1003);
0715         REQUIRE(lumis[8] == 1004);
0716       }
0717       REQUIRE(!storedMetadataOutput.allValidAndUseIndexIntoFile());
0718     }
0719   }
0720 }