Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 
0002 //
0003 // Reads some simple test objects in the event, run, and lumi
0004 // principals.  Then checks to see if the values in these
0005 // objects match what we expect.  Intended to be used to
0006 // test the values in a file that has merged run and lumi
0007 // products.
0008 //
0009 // Original Author: David Dagenhart, Fermilab, February 2008
0010 
0011 #include "DataFormats/Common/interface/Handle.h"
0012 #include "DataFormats/Common/interface/Wrapper.h"
0013 #include "DataFormats/Provenance/interface/BranchDescription.h"
0014 #include "DataFormats/Provenance/interface/BranchID.h"
0015 #include "DataFormats/Provenance/interface/ProcessHistory.h"
0016 #include "DataFormats/Provenance/interface/Provenance.h"
0017 #include "DataFormats/TestObjects/interface/Thing.h"
0018 #include "DataFormats/TestObjects/interface/ThingWithIsEqual.h"
0019 #include "DataFormats/TestObjects/interface/ThingWithMerge.h"
0020 #include "FWCore/Framework/interface/ConstProductRegistry.h"
0021 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0022 #include "FWCore/Framework/interface/Event.h"
0023 #include "FWCore/Framework/interface/FileBlock.h"
0024 #include "FWCore/Framework/interface/LuminosityBlock.h"
0025 #include "FWCore/Framework/interface/MakerMacros.h"
0026 #include "FWCore/Framework/interface/Run.h"
0027 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0028 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0029 #include "FWCore/ServiceRegistry/interface/Service.h"
0030 #include "FWCore/Utilities/interface/InputTag.h"
0031 
0032 #include <cassert>
0033 #include <iostream>
0034 #include <memory>
0035 #include <string>
0036 #include <vector>
0037 
0038 namespace edm {
0039   class EventSetup;
0040 }
0041 
0042 namespace edmtest {
0043 
0044   class TestMergeResults : public edm::one::EDAnalyzer<edm::one::WatchRuns, edm::one::WatchLuminosityBlocks> {
0045   public:
0046     explicit TestMergeResults(edm::ParameterSet const&);
0047 
0048     void analyze(edm::Event const& e, edm::EventSetup const& c) override;
0049     void beginRun(edm::Run const&, edm::EventSetup const&) override;
0050     void endRun(edm::Run const&, edm::EventSetup const&) override;
0051     void beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override;
0052     void endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override;
0053     void endJob() override;
0054 
0055   private:
0056     void checkExpectedLumiProducts(unsigned int index,
0057                                    std::vector<int> const& expectedValues,
0058                                    edm::InputTag const& tag,
0059                                    char const* functionName,
0060                                    edm::LuminosityBlock const& lumi,
0061                                    std::vector<int> const& expectedValueImproperlyMerged);
0062 
0063     void checkExpectedRunProducts(unsigned int index,
0064                                   std::vector<int> const& expectedValues,
0065                                   edm::InputTag const& tag,
0066                                   char const* functionName,
0067                                   edm::Run const& run,
0068                                   std::vector<int> const& expectedValueImproperlyMerged);
0069 
0070     void abortWithMessage(char const* whichFunction,
0071                           char const* type,
0072                           edm::InputTag const& tag,
0073                           int expectedValue,
0074                           int actualValue,
0075                           bool unexpectedImproperlyMergedValue = false) const;
0076 
0077     std::vector<int> default_;
0078     std::vector<std::string> defaultvstring_;
0079 
0080     std::vector<int> expectedBeginRunProd_;
0081     std::vector<int> expectedEndRunProd_;
0082     std::vector<int> expectedBeginLumiProd_;
0083     std::vector<int> expectedEndLumiProd_;
0084 
0085     std::vector<int> expectedBeginRunNew_;
0086     std::vector<int> expectedEndRunNew_;
0087     std::vector<int> expectedBeginLumiNew_;
0088     std::vector<int> expectedEndLumiNew_;
0089 
0090     std::vector<int> expectedEndRunProdImproperlyMerged_;
0091     std::vector<int> expectedEndLumiProdImproperlyMerged_;
0092 
0093     std::vector<std::string> expectedParents_;
0094 
0095     std::vector<std::string> expectedProcessHistoryInRuns_;
0096 
0097     std::vector<int> expectedDroppedEvent_;
0098     std::vector<int> expectedDroppedEvent1_;
0099     std::vector<int> expectedDroppedEvent1NEvents_;
0100 
0101     bool verbose_;
0102 
0103     unsigned int indexRun_;
0104     unsigned int indexLumi_;
0105     unsigned int parentIndex_;
0106     unsigned int droppedIndex1_;
0107     int droppedIndex1EventCount_;
0108     unsigned int processHistoryIndex_;
0109 
0110     edm::Handle<edmtest::Thing> h_thing;
0111     edm::Handle<edmtest::ThingWithMerge> h_thingWithMerge;
0112     edm::Handle<edmtest::ThingWithIsEqual> h_thingWithIsEqual;
0113 
0114     bool testAlias_;
0115   };
0116 
0117   // -----------------------------------------------------------------
0118 
0119   TestMergeResults::TestMergeResults(edm::ParameterSet const& ps)
0120       : default_(),
0121         defaultvstring_(),
0122         expectedBeginRunProd_(ps.getUntrackedParameter<std::vector<int> >("expectedBeginRunProd", default_)),
0123         expectedEndRunProd_(ps.getUntrackedParameter<std::vector<int> >("expectedEndRunProd", default_)),
0124         expectedBeginLumiProd_(ps.getUntrackedParameter<std::vector<int> >("expectedBeginLumiProd", default_)),
0125         expectedEndLumiProd_(ps.getUntrackedParameter<std::vector<int> >("expectedEndLumiProd", default_)),
0126 
0127         expectedBeginRunNew_(ps.getUntrackedParameter<std::vector<int> >("expectedBeginRunNew", default_)),
0128         expectedEndRunNew_(ps.getUntrackedParameter<std::vector<int> >("expectedEndRunNew", default_)),
0129         expectedBeginLumiNew_(ps.getUntrackedParameter<std::vector<int> >("expectedBeginLumiNew", default_)),
0130         expectedEndLumiNew_(ps.getUntrackedParameter<std::vector<int> >("expectedEndLumiNew", default_)),
0131 
0132         expectedEndRunProdImproperlyMerged_(
0133             ps.getUntrackedParameter<std::vector<int> >("expectedEndRunProdImproperlyMerged", default_)),
0134         expectedEndLumiProdImproperlyMerged_(
0135             ps.getUntrackedParameter<std::vector<int> >("expectedEndLumiProdImproperlyMerged", default_)),
0136 
0137         expectedParents_(ps.getUntrackedParameter<std::vector<std::string> >("expectedParents", defaultvstring_)),
0138         expectedProcessHistoryInRuns_(
0139             ps.getUntrackedParameter<std::vector<std::string> >("expectedProcessHistoryInRuns", defaultvstring_)),
0140 
0141         expectedDroppedEvent_(ps.getUntrackedParameter<std::vector<int> >("expectedDroppedEvent", default_)),
0142         expectedDroppedEvent1_(ps.getUntrackedParameter<std::vector<int> >("expectedDroppedEvent1", default_)),
0143         expectedDroppedEvent1NEvents_(
0144             ps.getUntrackedParameter<std::vector<int> >("expectedDroppedEvent1NEvents", default_)),
0145 
0146         verbose_(ps.getUntrackedParameter<bool>("verbose", false)),
0147 
0148         indexRun_(0),
0149         indexLumi_(0),
0150         parentIndex_(0),
0151         droppedIndex1_(0),
0152         droppedIndex1EventCount_(0),
0153         processHistoryIndex_(0),
0154         testAlias_(ps.getUntrackedParameter<bool>("testAlias", false)) {
0155     auto ap_thing = std::make_unique<edmtest::Thing>();
0156     edm::Wrapper<edmtest::Thing> w_thing(std::move(ap_thing));
0157     assert(!w_thing.isMergeable());
0158     assert(!w_thing.hasIsProductEqual());
0159     assert(!w_thing.hasSwap());
0160 
0161     auto ap_thingwithmerge = std::make_unique<edmtest::ThingWithMerge>();
0162     edm::Wrapper<edmtest::ThingWithMerge> w_thingWithMerge(std::move(ap_thingwithmerge));
0163     assert(w_thingWithMerge.isMergeable());
0164     assert(!w_thingWithMerge.hasIsProductEqual());
0165     assert(w_thingWithMerge.hasSwap());
0166 
0167     auto ap_thingwithisequal = std::make_unique<edmtest::ThingWithIsEqual>();
0168     edm::Wrapper<edmtest::ThingWithIsEqual> w_thingWithIsEqual(std::move(ap_thingwithisequal));
0169     assert(!w_thingWithIsEqual.isMergeable());
0170     assert(w_thingWithIsEqual.hasIsProductEqual());
0171     assert(!w_thingWithIsEqual.hasSwap());
0172 
0173     if (expectedDroppedEvent_.size() > 0) {
0174       consumes<edmtest::ThingWithIsEqual>(edm::InputTag{"makeThingToBeDropped", "event", "PROD"});
0175       consumes<edmtest::ThingWithMerge>(edm::InputTag{"makeThingToBeDropped", "event", "PROD"});
0176 
0177       consumes<edmtest::ThingWithIsEqual, edm::InRun>(edm::InputTag{"makeThingToBeDropped", "beginRun", "PROD"});
0178     }
0179     for (auto const& parent : expectedParents_) {
0180       mayConsume<edmtest::Thing>(edm::InputTag{parent, "event", "PROD"});
0181     }
0182     if (expectedDroppedEvent1_.size() > droppedIndex1_) {
0183       assert(expectedDroppedEvent1_.size() == expectedDroppedEvent1NEvents_.size());
0184       consumes<edmtest::ThingWithIsEqual>(edm::InputTag{"makeThingToBeDropped1", "event", "PROD"});
0185     }
0186     consumes<edmtest::Thing>(edm::InputTag{"thingWithMergeProducer", "event", "PROD"});
0187 
0188     if (testAlias_) {
0189       consumes<edmtest::Thing>(edm::InputTag{"aliasForThingToBeDropped2", "instance2"});
0190       consumes<edmtest::Thing>(edm::InputTag{"aliasForThingToBeDropped2", "instance2", "PROD"});
0191     }
0192 
0193     {
0194       edm::InputTag tag("thingWithMergeProducer", "beginRun", "PROD");
0195       consumes<edmtest::Thing, edm::InRun>(tag);
0196       consumes<edmtest::ThingWithMerge, edm::InRun>(tag);
0197       consumes<edmtest::ThingWithIsEqual, edm::InRun>(tag);
0198     }
0199 
0200     {
0201       edm::InputTag tag("thingWithMergeProducer", "beginRun");
0202       consumes<edmtest::Thing, edm::InRun>(tag);
0203       consumes<edmtest::ThingWithMerge, edm::InRun>(tag);
0204       consumes<edmtest::ThingWithIsEqual, edm::InRun>(tag);
0205     }
0206 
0207     {
0208       edm::InputTag tag("thingWithMergeProducer", "endRun", "PROD");
0209       consumes<edmtest::Thing, edm::InRun>(tag);
0210       consumes<edmtest::ThingWithMerge, edm::InRun>(tag);
0211       consumes<edmtest::ThingWithIsEqual, edm::InRun>(tag);
0212     }
0213 
0214     {
0215       edm::InputTag tag("thingWithMergeProducer", "endRun");
0216       consumes<edmtest::Thing, edm::InRun>(tag);
0217       consumes<edmtest::ThingWithMerge, edm::InRun>(tag);
0218       consumes<edmtest::ThingWithIsEqual, edm::InRun>(tag);
0219     }
0220 
0221     if (expectedDroppedEvent_.size() > 2) {
0222       edm::InputTag tag("makeThingToBeDropped", "endRun", "PROD");
0223       consumes<edmtest::ThingWithMerge, edm::InRun>(tag);
0224       consumes<edmtest::ThingWithIsEqual, edm::InRun>(tag);
0225     }
0226 
0227     if (testAlias_) {
0228       consumes<edmtest::Thing, edm::InRun>(edm::InputTag{"aliasForThingToBeDropped2", "endRun2"});
0229       edm::InputTag tag("aliasForThingToBeDropped2", "endRun2", "PROD");
0230       consumes<edmtest::Thing, edm::InRun>(tag);
0231     }
0232 
0233     if (expectedDroppedEvent_.size() > 3) {
0234       edm::InputTag tag("makeThingToBeDropped", "beginLumi", "PROD");
0235       consumes<edmtest::ThingWithIsEqual, edm::InLumi>(tag);
0236     }
0237     {
0238       edm::InputTag tag("thingWithMergeProducer", "endLumi", "PROD");
0239       consumes<edmtest::Thing, edm::InLumi>(tag);
0240       consumes<edmtest::ThingWithMerge, edm::InLumi>(tag);
0241       consumes<edmtest::ThingWithIsEqual, edm::InLumi>(tag);
0242     }
0243 
0244     {
0245       edm::InputTag tag("thingWithMergeProducer", "endLumi");
0246       consumes<edmtest::Thing, edm::InLumi>(tag);
0247       consumes<edmtest::ThingWithMerge, edm::InLumi>(tag);
0248       consumes<edmtest::ThingWithIsEqual, edm::InLumi>(tag);
0249     }
0250 
0251     {
0252       edm::InputTag tag("thingWithMergeProducer", "beginLumi", "PROD");
0253       consumes<edmtest::Thing, edm::InLumi>(tag);
0254       consumes<edmtest::ThingWithMerge, edm::InLumi>(tag);
0255       consumes<edmtest::ThingWithIsEqual, edm::InLumi>(tag);
0256     }
0257 
0258     {
0259       edm::InputTag tag("thingWithMergeProducer", "beginLumi");
0260       consumes<edmtest::Thing, edm::InLumi>(tag);
0261       consumes<edmtest::ThingWithMerge, edm::InLumi>(tag);
0262       consumes<edmtest::ThingWithIsEqual, edm::InLumi>(tag);
0263     }
0264 
0265     if (expectedDroppedEvent_.size() > 4) {
0266       edm::InputTag tag("makeThingToBeDropped", "endLumi", "PROD");
0267       consumes<edmtest::ThingWithIsEqual, edm::InLumi>(tag);
0268       consumes<edmtest::ThingWithMerge, edm::InLumi>(tag);
0269     }
0270 
0271     if (testAlias_) {
0272       consumes<edmtest::Thing, edm::InLumi>(edm::InputTag{"aliasForThingToBeDropped2", "endLumi2"});
0273       edm::InputTag tag("aliasForThingToBeDropped2", "endLumi2", "PROD");
0274       consumes<edmtest::Thing, edm::InLumi>(tag);
0275     }
0276   }
0277 
0278   // -----------------------------------------------------------------
0279 
0280   void TestMergeResults::analyze(edm::Event const& e, edm::EventSetup const&) {
0281     assert(e.processHistory().id() == e.processHistoryID());
0282 
0283     if (verbose_)
0284       edm::LogInfo("TestMergeResults") << "analyze";
0285 
0286     if (expectedDroppedEvent_.size() > 0) {
0287       edm::InputTag tag("makeThingToBeDropped", "event", "PROD");
0288       e.getByLabel(tag, h_thingWithIsEqual);
0289       assert(h_thingWithIsEqual->a == expectedDroppedEvent_[0]);
0290 
0291       e.getByLabel(tag, h_thingWithMerge);
0292       assert(h_thingWithMerge.isValid());
0293     }
0294 
0295     // This one is used to test the merging step when a specific product
0296     // has been dropped or not created in some of the input files.
0297     if (expectedDroppedEvent1_.size() > droppedIndex1_) {
0298       ++droppedIndex1EventCount_;
0299       if (droppedIndex1EventCount_ > expectedDroppedEvent1NEvents_[droppedIndex1_]) {
0300         ++droppedIndex1_;
0301         std::cout << "advance " << droppedIndex1_ << std::endl;
0302         droppedIndex1EventCount_ = 1;
0303       }
0304       assert(droppedIndex1_ < expectedDroppedEvent1_.size());
0305 
0306       edm::InputTag tag("makeThingToBeDropped1", "event", "PROD");
0307       e.getByLabel(tag, h_thingWithIsEqual);
0308       if (expectedDroppedEvent1_[droppedIndex1_] == -1) {
0309         assert(!h_thingWithIsEqual.isValid());
0310       } else {
0311         assert(h_thingWithIsEqual.isValid());
0312         assert(h_thingWithIsEqual->a == expectedDroppedEvent1_[droppedIndex1_]);
0313       }
0314     }
0315 
0316     // I'm not sure this test belongs in this module.  Originally it tested
0317     // merging of parentage for run and lumi products, but at some point the
0318     // parentage for run/lumi products stopped being written at all so there was
0319     // nothing to test.  This was the only real test of the provenance
0320     // parentage, so I just converted to a test of the parentage of products
0321     // in the Event rather than deleting it or writing a complete new test ...
0322     // It is actually convenient here, so maybe it is OK even if the module name
0323     // has nothing to do with this test.
0324     if (parentIndex_ < expectedParents_.size()) {
0325       edm::InputTag tag("thingWithMergeProducer", "event", "PROD");
0326       e.getByLabel(tag, h_thing);
0327       std::string expectedParent = expectedParents_[parentIndex_];
0328       edm::BranchID actualParentBranchID = h_thing.provenance()->productProvenance()->parentage().parents()[0];
0329 
0330       // There ought to be a get that uses the BranchID as an argument, but
0331       // there is not at the moment so we get the Provenance first and use that
0332       // find the actual parent
0333       edm::Provenance prov = e.getProvenance(actualParentBranchID);
0334       assert(expectedParent == prov.moduleLabel());
0335       edm::InputTag tagparent(prov.moduleLabel(), prov.productInstanceName(), prov.processName());
0336       e.getByLabel(tagparent, h_thing);
0337       assert(h_thing->a == 11);
0338       ++parentIndex_;
0339     }
0340 
0341     if (testAlias_) {
0342       e.getByLabel("aliasForThingToBeDropped2", "instance2", h_thing);
0343       assert(h_thing->a == 11);
0344       edm::InputTag inputTag("aliasForThingToBeDropped2", "instance2", "PROD");
0345       e.getByLabel(inputTag, h_thing);
0346       assert(h_thing->a == 11);
0347 
0348       edm::BranchID const& originalBranchID = h_thing.provenance()->branchDescription().originalBranchID();
0349       bool foundOriginalInRegistry = false;
0350       edm::Service<edm::ConstProductRegistry> reg;
0351       // Loop over provenance of products in registry.
0352       for (edm::ProductRegistry::ProductList::const_iterator it = reg->productList().begin();
0353            it != reg->productList().end();
0354            ++it) {
0355         edm::BranchDescription const& desc = it->second;
0356         if (desc.branchID() == originalBranchID) {
0357           foundOriginalInRegistry = true;
0358           break;
0359         }
0360       }
0361       assert(foundOriginalInRegistry);
0362     }
0363   }
0364 
0365   void TestMergeResults::beginRun(edm::Run const& run, edm::EventSetup const&) {
0366     if (verbose_)
0367       edm::LogInfo("TestMergeResults") << "beginRun";
0368 
0369     if (expectedDroppedEvent_.size() > 1) {
0370       edm::InputTag tagd("makeThingToBeDropped", "beginRun", "PROD");
0371       run.getByLabel(tagd, h_thingWithIsEqual);
0372       assert(h_thingWithIsEqual->a == expectedDroppedEvent_[1]);
0373     }
0374   }
0375 
0376   void TestMergeResults::endRun(edm::Run const& run, edm::EventSetup const&) {
0377     assert(run.processHistory().id() == run.processHistoryID());
0378 
0379     edm::ProcessHistory const& ph = run.processHistory();
0380     for (edm::ProcessHistory::const_iterator iter = ph.begin(), iEnd = ph.end(); iter != iEnd; ++iter) {
0381       if (processHistoryIndex_ < expectedProcessHistoryInRuns_.size()) {
0382         assert(expectedProcessHistoryInRuns_[processHistoryIndex_] == iter->processName());
0383         ++processHistoryIndex_;
0384       }
0385     }
0386 
0387     if (verbose_)
0388       edm::LogInfo("TestMergeResults") << "endRun";
0389 
0390     std::vector<int> emptyDummy;
0391 
0392     edm::InputTag tag("thingWithMergeProducer", "endRun", "PROD");
0393     checkExpectedRunProducts(indexRun_, expectedEndRunProd_, tag, "endRun", run, expectedEndRunProdImproperlyMerged_);
0394 
0395     edm::InputTag tagnew("thingWithMergeProducer", "endRun");
0396     checkExpectedRunProducts(indexRun_, expectedEndRunNew_, tagnew, "endRun", run, emptyDummy);
0397 
0398     edm::InputTag tagb("thingWithMergeProducer", "beginRun", "PROD");
0399     checkExpectedRunProducts(indexRun_, expectedBeginRunProd_, tagb, "endRun", run, emptyDummy);
0400 
0401     edm::InputTag tagbnew("thingWithMergeProducer", "beginRun");
0402     checkExpectedRunProducts(indexRun_, expectedBeginRunNew_, tagbnew, "endRun", run, emptyDummy);
0403 
0404     if (expectedDroppedEvent_.size() > 2) {
0405       edm::InputTag tagd("makeThingToBeDropped", "endRun", "PROD");
0406       run.getByLabel(tagd, h_thingWithIsEqual);
0407       assert(h_thingWithIsEqual->a == expectedDroppedEvent_[2]);
0408 
0409       run.getByLabel(tagd, h_thingWithMerge);
0410       assert(!h_thingWithMerge.isValid());
0411     }
0412 
0413     if (testAlias_) {
0414       run.getByLabel("aliasForThingToBeDropped2", "endRun2", h_thing);
0415       assert(h_thing->a == 100001);
0416       edm::InputTag inputTag("aliasForThingToBeDropped2", "endRun2", "PROD");
0417       run.getByLabel(inputTag, h_thing);
0418       assert(h_thing->a == 100001);
0419 
0420       edm::BranchID const& originalBranchID = h_thing.provenance()->branchDescription().originalBranchID();
0421       bool foundOriginalInRegistry = false;
0422       edm::Service<edm::ConstProductRegistry> reg;
0423       // Loop over provenance of products in registry.
0424       for (edm::ProductRegistry::ProductList::const_iterator it = reg->productList().begin();
0425            it != reg->productList().end();
0426            ++it) {
0427         edm::BranchDescription const& desc = it->second;
0428         if (desc.branchID() == originalBranchID) {
0429           foundOriginalInRegistry = true;
0430           break;
0431         }
0432       }
0433       assert(foundOriginalInRegistry);
0434     }
0435 
0436     indexRun_ += 3;
0437   }
0438 
0439   void TestMergeResults::beginLuminosityBlock(edm::LuminosityBlock const& lumi, edm::EventSetup const&) {
0440     if (verbose_)
0441       edm::LogInfo("TestMergeResults") << "beginLuminosityBlock";
0442 
0443     if (expectedDroppedEvent_.size() > 3) {
0444       edm::InputTag tagd("makeThingToBeDropped", "beginLumi", "PROD");
0445       lumi.getByLabel(tagd, h_thingWithIsEqual);
0446       assert(h_thingWithIsEqual->a == expectedDroppedEvent_[3]);
0447     }
0448   }
0449 
0450   void TestMergeResults::endLuminosityBlock(edm::LuminosityBlock const& lumi, edm::EventSetup const&) {
0451     assert(lumi.processHistory().id() == lumi.processHistoryID());
0452 
0453     if (verbose_)
0454       edm::LogInfo("TestMergeResults") << "endLuminosityBlock";
0455 
0456     std::vector<int> emptyDummy;
0457 
0458     edm::InputTag tag("thingWithMergeProducer", "endLumi", "PROD");
0459     checkExpectedLumiProducts(
0460         indexLumi_, expectedEndLumiProd_, tag, "endLumi", lumi, expectedEndLumiProdImproperlyMerged_);
0461 
0462     edm::InputTag tagnew("thingWithMergeProducer", "endLumi");
0463     checkExpectedLumiProducts(indexLumi_, expectedEndLumiNew_, tagnew, "endLumi", lumi, emptyDummy);
0464 
0465     edm::InputTag tagb("thingWithMergeProducer", "beginLumi", "PROD");
0466     checkExpectedLumiProducts(indexLumi_, expectedBeginLumiProd_, tagb, "endLumi", lumi, emptyDummy);
0467 
0468     edm::InputTag tagbnew("thingWithMergeProducer", "beginLumi");
0469     checkExpectedLumiProducts(indexLumi_, expectedBeginLumiNew_, tagbnew, "endLumi", lumi, emptyDummy);
0470 
0471     if (expectedDroppedEvent_.size() > 4) {
0472       edm::InputTag tagd("makeThingToBeDropped", "endLumi", "PROD");
0473       lumi.getByLabel(tagd, h_thingWithIsEqual);
0474       assert(h_thingWithIsEqual->a == expectedDroppedEvent_[4]);
0475 
0476       lumi.getByLabel(tagd, h_thingWithMerge);
0477       assert(!h_thingWithMerge.isValid());
0478     }
0479 
0480     if (testAlias_) {
0481       lumi.getByLabel("aliasForThingToBeDropped2", "endLumi2", h_thing);
0482       assert(h_thing->a == 1001);
0483       edm::InputTag inputTag("aliasForThingToBeDropped2", "endLumi2", "PROD");
0484       lumi.getByLabel(inputTag, h_thing);
0485       assert(h_thing->a == 1001);
0486 
0487       edm::BranchID const& originalBranchID = h_thing.provenance()->branchDescription().originalBranchID();
0488       bool foundOriginalInRegistry = false;
0489       edm::Service<edm::ConstProductRegistry> reg;
0490       // Loop over provenance of products in registry.
0491       for (edm::ProductRegistry::ProductList::const_iterator it = reg->productList().begin();
0492            it != reg->productList().end();
0493            ++it) {
0494         edm::BranchDescription const& desc = it->second;
0495         if (desc.branchID() == originalBranchID) {
0496           foundOriginalInRegistry = true;
0497           break;
0498         }
0499       }
0500       assert(foundOriginalInRegistry);
0501     }
0502     indexLumi_ += 3;
0503   }
0504 
0505   void TestMergeResults::endJob() {
0506     if (verbose_)
0507       edm::LogInfo("TestMergeResults") << "endJob";
0508   }
0509 
0510   void TestMergeResults::checkExpectedRunProducts(unsigned int index,
0511                                                   std::vector<int> const& expectedValues,
0512                                                   edm::InputTag const& tag,
0513                                                   char const* functionName,
0514                                                   edm::Run const& run,
0515                                                   std::vector<int> const& expectedValueImproperlyMerged) {
0516     if ((index + 2) < expectedValues.size()) {
0517       int expected = expectedValues[index];
0518       if (expected != 0) {
0519         run.getByLabel(tag, h_thing);
0520         if (h_thing->a != expected) {
0521           abortWithMessage(functionName, "Thing", tag, expected, h_thing->a);
0522         }
0523         if (index < expectedValueImproperlyMerged.size()) {
0524           if ((expectedValueImproperlyMerged[index] != 0) != h_thing.provenance()->knownImproperlyMerged()) {
0525             abortWithMessage(functionName, "Thing", tag, 0, 0, true);
0526           }
0527         }
0528       }
0529 
0530       expected = expectedValues[index + 1];
0531       if (expected != 0) {
0532         run.getByLabel(tag, h_thingWithMerge);
0533         if (h_thingWithMerge->a != expected) {
0534           abortWithMessage(functionName, "ThingWithMerge", tag, expected, h_thingWithMerge->a);
0535         }
0536         if (index + 1 < expectedValueImproperlyMerged.size()) {
0537           if ((expectedValueImproperlyMerged[index + 1] != 0) !=
0538               h_thingWithMerge.provenance()->knownImproperlyMerged()) {
0539             abortWithMessage(functionName, "ThingWithMerge", tag, 0, 0, true);
0540           }
0541         }
0542         if (!h_thingWithMerge.provenance()->branchDescription().isMergeable()) {
0543           std::cerr << "TestMergeResults::checkExpectedRunProducts isMergeable from BranchDescription returns\n"
0544                     << "unexpected value for ThingWithMerge type." << std::endl;
0545           abort();
0546         }
0547       }
0548 
0549       expected = expectedValues[index + 2];
0550       if (expected != 0) {
0551         run.getByLabel(tag, h_thingWithIsEqual);
0552         if (h_thingWithIsEqual->a != expected) {
0553           abortWithMessage(functionName, "ThingWithIsEqual", tag, expected, h_thingWithIsEqual->a);
0554         }
0555         if (index + 2 < expectedValueImproperlyMerged.size()) {
0556           if ((expectedValueImproperlyMerged[index + 2] != 0) !=
0557               h_thingWithIsEqual.provenance()->knownImproperlyMerged()) {
0558             abortWithMessage(functionName, "ThingWithIsEqual", tag, 0, 0, true);
0559           }
0560         }
0561         if (h_thingWithIsEqual.provenance()->branchDescription().isMergeable()) {
0562           std::cerr << "TestMergeResults::checkExpectedRunProducts isMergeable from BranchDescription returns\n"
0563                     << "unexpected value for ThingWithIsEqual type." << std::endl;
0564           abort();
0565         }
0566       }
0567     }
0568   }
0569 
0570   void TestMergeResults::checkExpectedLumiProducts(unsigned int index,
0571                                                    std::vector<int> const& expectedValues,
0572                                                    edm::InputTag const& tag,
0573                                                    char const* functionName,
0574                                                    edm::LuminosityBlock const& lumi,
0575                                                    std::vector<int> const& expectedValueImproperlyMerged) {
0576     if ((index + 2) < expectedValues.size()) {
0577       int expected = expectedValues[index];
0578       if (expected != 0) {
0579         lumi.getByLabel(tag, h_thing);
0580         if (h_thing->a != expected) {
0581           abortWithMessage(functionName, "Thing", tag, expected, h_thing->a);
0582         }
0583         if (index < expectedValueImproperlyMerged.size()) {
0584           if ((expectedValueImproperlyMerged[index] != 0) != h_thing.provenance()->knownImproperlyMerged()) {
0585             abortWithMessage(functionName, "Thing", tag, 0, 0, true);
0586           }
0587         }
0588       }
0589 
0590       expected = expectedValues[index + 1];
0591       if (expected != 0) {
0592         lumi.getByLabel(tag, h_thingWithMerge);
0593         if (h_thingWithMerge->a != expected) {
0594           abortWithMessage(functionName, "ThingWithMerge", tag, expected, h_thingWithMerge->a);
0595         }
0596         if (index + 1 < expectedValueImproperlyMerged.size()) {
0597           if ((expectedValueImproperlyMerged[index + 1] != 0) !=
0598               h_thingWithMerge.provenance()->knownImproperlyMerged()) {
0599             abortWithMessage(functionName, "ThingWithMerge", tag, 0, 0, true);
0600           }
0601         }
0602         if (!h_thingWithMerge.provenance()->branchDescription().isMergeable()) {
0603           std::cerr << "TestMergeResults::checkExpectedLumiProducts isMergeable from BranchDescription returns\n"
0604                     << "unexpected value for ThingWithMerge type." << std::endl;
0605           abort();
0606         }
0607       }
0608 
0609       expected = expectedValues[index + 2];
0610       if (expected != 0) {
0611         lumi.getByLabel(tag, h_thingWithIsEqual);
0612         if (h_thingWithIsEqual->a != expected) {
0613           abortWithMessage(functionName, "ThingWithIsEqual", tag, expected, h_thingWithIsEqual->a);
0614         }
0615         if (index + 2 < expectedValueImproperlyMerged.size()) {
0616           if ((expectedValueImproperlyMerged[index + 2] != 0) !=
0617               h_thingWithIsEqual.provenance()->knownImproperlyMerged()) {
0618             abortWithMessage(functionName, "ThingWithIsEqual", tag, 0, 0, true);
0619           }
0620         }
0621         if (h_thingWithIsEqual.provenance()->branchDescription().isMergeable()) {
0622           std::cerr << "TestMergeResults::checkExpectedLumiProducts isMergeable from BranchDescription returns\n"
0623                     << "unexpected value for ThingWithIsEqual type." << std::endl;
0624           abort();
0625         }
0626       }
0627     }
0628   }
0629 
0630   void TestMergeResults::abortWithMessage(char const* whichFunction,
0631                                           char const* type,
0632                                           edm::InputTag const& tag,
0633                                           int expectedValue,
0634                                           int actualValue,
0635                                           bool unexpectedImproperlyMergedValue) const {
0636     std::cerr << "Error while testing merging of run/lumi products in TestMergeResults.cc\n"
0637               << "In function " << whichFunction << " looking for product of type " << type << "\n"
0638               << tag << std::endl;
0639     if (unexpectedImproperlyMergedValue) {
0640       std::cerr << "Unexpected value of knownImproperlyMerged from provenance" << std::endl;
0641     } else {
0642       std::cerr << "Expected value = " << expectedValue << " actual value = " << actualValue << std::endl;
0643     }
0644     abort();
0645   }
0646 }  // namespace edmtest
0647 
0648 using edmtest::TestMergeResults;
0649 
0650 DEFINE_FWK_MODULE(TestMergeResults);