Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 
0002 //
0003 // Puts some simple test objects in the event, run, and lumi
0004 // principals.  The values put into these objects are just
0005 // arbitrary and meaningless.  Later we check that what get
0006 // out when reading the file after merging is what is expected.
0007 //
0008 // Original Author: David Dagenhart, Fermilab, February 2008
0009 
0010 #include "ThingWithMergeProducer.h"
0011 #include "FWCore/Framework/interface/Event.h"
0012 #include "FWCore/Framework/interface/LuminosityBlock.h"
0013 #include "FWCore/Framework/interface/Run.h"
0014 #include "FWCore/Framework/interface/MakerMacros.h"
0015 #include "DataFormats/TestObjects/interface/Thing.h"
0016 #include "DataFormats/TestObjects/interface/ThingWithMerge.h"
0017 #include "DataFormats/TestObjects/interface/ThingWithIsEqual.h"
0018 #include "DataFormats/Common/interface/Handle.h"
0019 #include "FWCore/Utilities/interface/InputTag.h"
0020 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0021 
0022 namespace edmtest {
0023   ThingWithMergeProducer::ThingWithMergeProducer(edm::ParameterSet const& pset)
0024       : changeIsEqualValue_(pset.getUntrackedParameter<bool>("changeIsEqualValue", false)),
0025         labelsToGet_(pset.getUntrackedParameter<std::vector<std::string>>("labelsToGet", std::vector<std::string>())),
0026         noPut_(pset.getUntrackedParameter<bool>("noPut", false)) {
0027     produces<Thing>("event");
0028     produces<Thing, edm::Transition::BeginLuminosityBlock>("beginLumi");
0029     produces<Thing, edm::Transition::EndLuminosityBlock>("endLumi");
0030     produces<Thing, edm::Transition::BeginRun>("beginRun");
0031     produces<Thing, edm::Transition::EndRun>("endRun");
0032 
0033     produces<ThingWithMerge>("event");
0034     produces<ThingWithMerge, edm::Transition::BeginLuminosityBlock>("beginLumi");
0035     produces<ThingWithMerge, edm::Transition::EndLuminosityBlock>("endLumi");
0036     produces<ThingWithMerge, edm::Transition::BeginRun>("beginRun");
0037     produces<ThingWithMerge, edm::Transition::EndRun>("endRun");
0038 
0039     produces<ThingWithIsEqual>("event");
0040     produces<ThingWithIsEqual, edm::Transition::BeginLuminosityBlock>("beginLumi");
0041     produces<ThingWithIsEqual, edm::Transition::EndLuminosityBlock>("endLumi");
0042     produces<ThingWithIsEqual, edm::Transition::BeginRun>("beginRun");
0043     produces<ThingWithIsEqual, edm::Transition::EndRun>("endRun");
0044 
0045     const std::string s_prod("PROD");
0046     for (auto const& label : labelsToGet_) {
0047       consumes<Thing>(edm::InputTag(label, "event", s_prod));
0048       consumes<Thing, edm::InLumi>(edm::InputTag(label, "beginLumi", s_prod));
0049       consumes<Thing, edm::InLumi>(edm::InputTag(label, "endLumi", s_prod));
0050       consumes<Thing, edm::InRun>(edm::InputTag(label, "beginRun", s_prod));
0051       consumes<Thing, edm::InRun>(edm::InputTag(label, "endRun", s_prod));
0052     }
0053   }
0054 
0055   ThingWithMergeProducer::~ThingWithMergeProducer() {}
0056 
0057   void ThingWithMergeProducer::produce(edm::Event& e, edm::EventSetup const&) {
0058     // The purpose of this first getByLabel call is to cause the products
0059     // that are "put" below to have a parent so we can do tests with the
0060     // parentage provenance.
0061     for (Iter iter = labelsToGet_.begin(), ie = labelsToGet_.end(); iter != ie; ++iter) {
0062       edm::Handle<Thing> h;
0063       edm::InputTag tag(*iter, "event", "PROD");
0064       e.getByLabel(tag, h);
0065     }
0066 
0067     auto result = std::make_unique<Thing>();
0068     result->a = 11;
0069     if (!noPut_)
0070       e.put(std::move(result), std::string("event"));
0071 
0072     auto result2 = std::make_unique<ThingWithMerge>();
0073     result2->a = 12;
0074     if (!noPut_)
0075       e.put(std::move(result2), std::string("event"));
0076 
0077     auto result3 = std::make_unique<ThingWithIsEqual>();
0078     result3->a = 13;
0079     if (changeIsEqualValue_)
0080       result3->a = 14;
0081     if (!noPut_)
0082       e.put(std::move(result3), std::string("event"));
0083   }
0084 
0085   void ThingWithMergeProducer::beginLuminosityBlockProduce(edm::LuminosityBlock& lb, edm::EventSetup const&) {
0086     auto result = std::make_unique<Thing>();
0087     result->a = 101;
0088     if (!noPut_)
0089       lb.put(std::move(result), "beginLumi");
0090 
0091     auto result2 = std::make_unique<ThingWithMerge>();
0092     result2->a = 102;
0093     if (!noPut_)
0094       lb.put(std::move(result2), "beginLumi");
0095 
0096     auto result3 = std::make_unique<ThingWithIsEqual>();
0097     result3->a = 103;
0098     if (changeIsEqualValue_)
0099       result3->a = 104;
0100     if (!noPut_)
0101       lb.put(std::move(result3), "beginLumi");
0102   }
0103 
0104   void ThingWithMergeProducer::endLuminosityBlockProduce(edm::LuminosityBlock& lb, edm::EventSetup const&) {
0105     auto result = std::make_unique<Thing>();
0106     result->a = 1001;
0107     if (!noPut_)
0108       lb.put(std::move(result), "endLumi");
0109 
0110     auto result2 = std::make_unique<ThingWithMerge>();
0111     result2->a = 1002;
0112     if (!noPut_)
0113       lb.put(std::move(result2), "endLumi");
0114 
0115     auto result3 = std::make_unique<ThingWithIsEqual>();
0116     result3->a = 1003;
0117     if (changeIsEqualValue_)
0118       result3->a = 1004;
0119     if (!noPut_)
0120       lb.put(std::move(result3), "endLumi");
0121   }
0122 
0123   // Functions that gets called by framework every run
0124   void ThingWithMergeProducer::beginRunProduce(edm::Run& r, edm::EventSetup const&) {
0125     auto result = std::make_unique<Thing>();
0126     result->a = 10001;
0127     if (!noPut_)
0128       r.put(std::move(result), "beginRun");
0129 
0130     auto result2 = std::make_unique<ThingWithMerge>();
0131     result2->a = 10002;
0132     if (!noPut_)
0133       r.put(std::move(result2), "beginRun");
0134 
0135     auto result3 = std::make_unique<ThingWithIsEqual>();
0136     result3->a = 10003;
0137     if (changeIsEqualValue_)
0138       result3->a = 10004;
0139     if (!noPut_)
0140       r.put(std::move(result3), "beginRun");
0141   }
0142 
0143   void ThingWithMergeProducer::endRunProduce(edm::Run& r, edm::EventSetup const&) {
0144     auto result = std::make_unique<Thing>();
0145     result->a = 100001;
0146     if (!noPut_)
0147       r.put(std::move(result), "endRun");
0148 
0149     auto result2 = std::make_unique<ThingWithMerge>();
0150     result2->a = 100002;
0151     if (!noPut_)
0152       r.put(std::move(result2), "endRun");
0153 
0154     auto result3 = std::make_unique<ThingWithIsEqual>();
0155     result3->a = 100003;
0156     if (changeIsEqualValue_)
0157       result3->a = 100004;
0158     if (!noPut_)
0159       r.put(std::move(result3), "endRun");
0160   }
0161 
0162   void ThingWithMergeProducer::beginLuminosityBlock(edm::LuminosityBlock const& lb, edm::EventSetup const&) {
0163     for (Iter iter = labelsToGet_.begin(), ie = labelsToGet_.end(); iter != ie; ++iter) {
0164       edm::Handle<Thing> h;
0165       edm::InputTag tag(*iter, "beginLumi", "PROD");
0166       lb.getByLabel(tag, h);
0167     }
0168   }
0169 
0170   void ThingWithMergeProducer::endLuminosityBlock(edm::LuminosityBlock const& lb, edm::EventSetup const&) {
0171     for (Iter iter = labelsToGet_.begin(), ie = labelsToGet_.end(); iter != ie; ++iter) {
0172       edm::Handle<Thing> h;
0173       edm::InputTag tag(*iter, "endLumi", "PROD");
0174       lb.getByLabel(tag, h);
0175     }
0176   }
0177 
0178   // Functions that gets called by framework every run
0179   void ThingWithMergeProducer::beginRun(edm::Run const& r, edm::EventSetup const&) {
0180     for (Iter iter = labelsToGet_.begin(), ie = labelsToGet_.end(); iter != ie; ++iter) {
0181       edm::Handle<Thing> h;
0182       edm::InputTag tag(*iter, "beginRun", "PROD");
0183       r.getByLabel(tag, h);
0184     }
0185   }
0186 
0187   void ThingWithMergeProducer::endRun(edm::Run const& r, edm::EventSetup const&) {
0188     for (Iter iter = labelsToGet_.begin(), ie = labelsToGet_.end(); iter != ie; ++iter) {
0189       edm::Handle<Thing> h;
0190       edm::InputTag tag(*iter, "endRun", "PROD");
0191       r.getByLabel(tag, h);
0192     }
0193   }
0194 
0195   void ThingWithMergeProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0196     edm::ParameterSetDescription desc;
0197     desc.addUntracked<bool>("changeIsEqualValue", false);
0198     desc.addUntracked<std::vector<std::string>>("labelsToGet", std::vector<std::string>());
0199     desc.addUntracked<bool>("noPut", false);
0200     descriptions.add("thingWithMergeProducer", desc);
0201   }
0202 
0203 }  // namespace edmtest
0204 using edmtest::ThingWithMergeProducer;
0205 DEFINE_FWK_MODULE(ThingWithMergeProducer);