Back to home page

Project CMSSW displayed by LXR

 
 

    


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

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     ItemTypeInfo 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     ProductDescription thingDesc_;
0042     ProductDescription thingWithMergeDesc_;
0043     ProductDescription thingWithEqualDesc_;
0044     ProcessHistoryID historyID_;
0045   };
0046 }  // namespace edmtest
0047 
0048 using namespace edmtest;
0049 
0050 PutOrMergeTestSource::PutOrMergeTestSource(ParameterSet const& iPS, InputSourceDescription const& iISD)
0051     : InputSource(iPS, iISD),
0052       stage_(0),
0053       thingDesc_(InRun,
0054                  "thingWithMergeProducer",
0055                  "PROD",
0056                  "edmtest::Thing",
0057                  "edmtestThing",
0058                  "endRun",
0059                  edm::TypeWithDict(typeid(edmtest::Thing)),
0060                  false,
0061                  true),
0062       thingWithMergeDesc_(InRun,
0063                           "thingWithMergeProducer",
0064                           "PROD",
0065                           "edmtest::ThingWithMerge",
0066                           "edmtestThingWithMerge",
0067                           "endRun",
0068                           edm::TypeWithDict(typeid(edmtest::ThingWithMerge)),
0069                           false,
0070                           true),
0071       thingWithEqualDesc_(InRun,
0072                           "thingWithMergeProducer",
0073                           "PROD",
0074                           "edmtest::ThingWithIsEqual",
0075                           "edmtestThingWithIsEqual",
0076                           "endRun",
0077                           edm::TypeWithDict(typeid(edmtest::ThingWithIsEqual)),
0078                           false,
0079                           true) {
0080   edm::ParameterSet dummyPset;
0081   dummyPset.registerIt();
0082 
0083   ProcessHistory history;
0084   history.emplace_back("PROD", dummyPset.id(), "RELVERSION", HardwareResourcesDescription());
0085   processHistoryRegistry().registerProcessHistory(history);
0086   historyID_ = history.id();
0087 }
0088 
0089 void PutOrMergeTestSource::registerProducts() {
0090   edm::ParameterSet dummyPset;
0091   dummyPset.registerIt();
0092 
0093   thingDesc_.setIsProvenanceSetOnRead();
0094   thingWithMergeDesc_.setIsProvenanceSetOnRead();
0095   productRegistryUpdate().copyProduct(thingDesc_);
0096   productRegistryUpdate().copyProduct(thingWithMergeDesc_);
0097   productRegistryUpdate().copyProduct(thingWithEqualDesc_);
0098 }
0099 
0100 InputSource::ItemTypeInfo PutOrMergeTestSource::getNextItemType() {
0101   switch (stage_) {
0102     case 0: {
0103       return ItemType::IsFile;
0104     }
0105     case 1: {
0106       return ItemType::IsRun;
0107     }
0108     case 2: {
0109       return ItemType::IsRun;
0110     }
0111     default:
0112       return ItemType::IsStop;
0113   }
0114   return ItemType::IsInvalid;
0115 }
0116 
0117 std::shared_ptr<RunAuxiliary> PutOrMergeTestSource::readRunAuxiliary_() {
0118   auto id = std::make_shared<RunAuxiliary>(1, Timestamp::beginOfTime(), Timestamp::endOfTime());
0119   id->setProcessHistoryID(historyID_);
0120   return id;
0121 }
0122 std::shared_ptr<LuminosityBlockAuxiliary> PutOrMergeTestSource::readLuminosityBlockAuxiliary_() { return {}; }
0123 std::shared_ptr<FileBlock> PutOrMergeTestSource::readFile_() {
0124   ++stage_;
0125   return std::make_shared<FileBlock>();
0126 }
0127 void PutOrMergeTestSource::readRun_(RunPrincipal& runPrincipal) {
0128   runAuxiliary()->setProcessHistoryID(historyID_);
0129   runPrincipal.fillRunPrincipal(processHistoryRegistry());
0130   ++stage_;
0131   runPrincipal.putOrMerge(thingDesc_, std::make_unique<Wrapper<edmtest::Thing>>(WrapperBase::Emplace{}, 100001));
0132   runPrincipal.putOrMerge(thingWithMergeDesc_,
0133                           std::make_unique<Wrapper<edmtest::ThingWithMerge>>(WrapperBase::Emplace{}, 100002));
0134   runPrincipal.putOrMerge(thingWithEqualDesc_,
0135                           std::make_unique<Wrapper<edmtest::ThingWithIsEqual>>(WrapperBase::Emplace{}, 100003));
0136 }
0137 void PutOrMergeTestSource::readEvent_(EventPrincipal& eventPrincipal) { assert(false); }
0138 
0139 DEFINE_FWK_INPUT_SOURCE(PutOrMergeTestSource);