Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-03-17 11:02:54

0001 //
0002 //  PutOrMergeTestSource.cc
0003 //  CMSSW
0004 //
0005 //  Created by Chris Jones on 3/23/21.
0006 //
0007 
0008 #include "FWCore/Framework/interface/InputSource.h"
0009 #include "FWCore/Framework/interface/InputSourceMacros.h"
0010 #include "FWCore/Framework/interface/FileBlock.h"
0011 #include "FWCore/Framework/interface/RunPrincipal.h"
0012 
0013 #include "DataFormats/Provenance/interface/ProductRegistry.h"
0014 #include "DataFormats/Provenance/interface/ProcessHistory.h"
0015 #include "DataFormats/Provenance/interface/ProcessHistoryRegistry.h"
0016 
0017 #include "DataFormats/TestObjects/interface/Thing.h"
0018 #include "DataFormats/TestObjects/interface/ThingWithMerge.h"
0019 #include "DataFormats/TestObjects/interface/ThingWithIsEqual.h"
0020 
0021 #include <cassert>
0022 using namespace edm;
0023 
0024 namespace edmtest {
0025   class PutOrMergeTestSource : public InputSource {
0026   public:
0027     PutOrMergeTestSource(ParameterSet const&, InputSourceDescription const&);
0028 
0029     /// Register any produced products
0030     void registerProducts() final;
0031 
0032   private:
0033     ItemType getNextItemType() final;
0034     std::shared_ptr<RunAuxiliary> readRunAuxiliary_() final;
0035     std::shared_ptr<LuminosityBlockAuxiliary> readLuminosityBlockAuxiliary_() final;
0036     std::shared_ptr<FileBlock> readFile_() final;
0037     void readRun_(RunPrincipal& runPrincipal) final;
0038     void readEvent_(EventPrincipal& eventPrincipal) final;
0039 
0040     int stage_;
0041     ParameterSet const dummyPSet_;
0042     BranchDescription thingDesc_;
0043     BranchDescription thingWithMergeDesc_;
0044     BranchDescription thingWithEqualDesc_;
0045     ProcessHistoryID historyID_;
0046   };
0047 }  // namespace edmtest
0048 
0049 using namespace edmtest;
0050 
0051 PutOrMergeTestSource::PutOrMergeTestSource(ParameterSet const& iPS, InputSourceDescription const& iISD)
0052     : InputSource(iPS, iISD),
0053       stage_(0),
0054       dummyPSet_([]() {
0055         ParameterSet dummy;
0056         dummy.registerIt();
0057         return dummy;
0058       }()),
0059       thingDesc_(InRun,
0060                  "thingWithMergeProducer",
0061                  "PROD",
0062                  "edmtest::Thing",
0063                  "edmtestThing",
0064                  "endRun",
0065                  "PutOrMergeTestSource",
0066                  dummyPSet_.id(),
0067                  edm::TypeWithDict(typeid(edmtest::Thing)),
0068                  false,
0069                  true),
0070       thingWithMergeDesc_(InRun,
0071                           "thingWithMergeProducer",
0072                           "PROD",
0073                           "edmtest::ThingWithMerge",
0074                           "edmtestThingWithMerge",
0075                           "endRun",
0076                           "PutOrMergeTestSource",
0077                           dummyPSet_.id(),
0078                           edm::TypeWithDict(typeid(edmtest::ThingWithMerge)),
0079                           false,
0080                           true),
0081       thingWithEqualDesc_(InRun,
0082                           "thingWithMergeProducer",
0083                           "PROD",
0084                           "edmtest::ThingWithIsEqual",
0085                           "edmtestThingWithIsEqual",
0086                           "endRun",
0087                           "PutOrMergeTestSource",
0088                           dummyPSet_.id(),
0089                           edm::TypeWithDict(typeid(edmtest::ThingWithIsEqual)),
0090                           false,
0091                           true) {
0092   edm::ParameterSet dummyPset;
0093   dummyPset.registerIt();
0094 
0095   ProcessHistory history;
0096   history.emplace_back("PROD", dummyPset.id(), "RELVERSION", "PASSID");
0097   processHistoryRegistry().registerProcessHistory(history);
0098   historyID_ = history.id();
0099 }
0100 
0101 void PutOrMergeTestSource::registerProducts() {
0102   edm::ParameterSet dummyPset;
0103   dummyPset.registerIt();
0104 
0105   thingDesc_.setIsProvenanceSetOnRead();
0106   thingWithMergeDesc_.setIsProvenanceSetOnRead();
0107   productRegistryUpdate().copyProduct(thingDesc_);
0108   productRegistryUpdate().copyProduct(thingWithMergeDesc_);
0109   productRegistryUpdate().copyProduct(thingWithEqualDesc_);
0110 }
0111 
0112 InputSource::ItemType PutOrMergeTestSource::getNextItemType() {
0113   switch (stage_) {
0114     case 0: {
0115       return IsFile;
0116     }
0117     case 1: {
0118       return IsRun;
0119     }
0120     case 2: {
0121       return IsRun;
0122     }
0123     default:
0124       return IsStop;
0125   }
0126   return IsInvalid;
0127 }
0128 
0129 std::shared_ptr<RunAuxiliary> PutOrMergeTestSource::readRunAuxiliary_() {
0130   auto id = std::make_shared<RunAuxiliary>(1, Timestamp::beginOfTime(), Timestamp::endOfTime());
0131   id->setProcessHistoryID(historyID_);
0132   return id;
0133 }
0134 std::shared_ptr<LuminosityBlockAuxiliary> PutOrMergeTestSource::readLuminosityBlockAuxiliary_() { return {}; }
0135 std::shared_ptr<FileBlock> PutOrMergeTestSource::readFile_() {
0136   ++stage_;
0137   return std::make_shared<FileBlock>();
0138 }
0139 void PutOrMergeTestSource::readRun_(RunPrincipal& runPrincipal) {
0140   runAuxiliary()->setProcessHistoryID(historyID_);
0141   runPrincipal.fillRunPrincipal(processHistoryRegistry());
0142   ++stage_;
0143   runPrincipal.putOrMerge(thingDesc_, std::make_unique<Wrapper<edmtest::Thing>>(WrapperBase::Emplace{}, 100001));
0144   runPrincipal.putOrMerge(thingWithMergeDesc_,
0145                           std::make_unique<Wrapper<edmtest::ThingWithMerge>>(WrapperBase::Emplace{}, 100002));
0146   runPrincipal.putOrMerge(thingWithEqualDesc_,
0147                           std::make_unique<Wrapper<edmtest::ThingWithIsEqual>>(WrapperBase::Emplace{}, 100003));
0148 }
0149 void PutOrMergeTestSource::readEvent_(EventPrincipal& eventPrincipal) { assert(false); }
0150 
0151 DEFINE_FWK_INPUT_SOURCE(PutOrMergeTestSource);