Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include "ThingProducer.h"
0002 #include "FWCore/Framework/interface/Event.h"
0003 #include "FWCore/Framework/interface/LuminosityBlock.h"
0004 #include "FWCore/Framework/interface/Run.h"
0005 #include "FWCore/Framework/interface/MakerMacros.h"
0006 
0007 namespace edmtest {
0008   ThingProducer::ThingProducer(edm::ParameterSet const& iConfig)
0009       : alg_(iConfig.getParameter<int>("offsetDelta"),
0010              iConfig.getParameter<int>("nThings"),
0011              iConfig.getParameter<bool>("grow")),
0012         noPut_(iConfig.getUntrackedParameter<bool>("noPut"))  // used for testing with missing products
0013   {
0014     evToken_ = produces<ThingCollection>();
0015     blToken_ = produces<ThingCollection, edm::Transition::BeginLuminosityBlock>("beginLumi");
0016     elToken_ = produces<ThingCollection, edm::Transition::EndLuminosityBlock>("endLumi");
0017     brToken_ = produces<ThingCollection, edm::Transition::BeginRun>("beginRun");
0018     erToken_ = produces<ThingCollection, edm::Transition::EndRun>("endRun");
0019   }
0020 
0021   // Virtual destructor needed.
0022   ThingProducer::~ThingProducer() {}
0023 
0024   // Functions that gets called by framework every event
0025   void ThingProducer::produce(edm::StreamID, edm::Event& e, edm::EventSetup const&) const {
0026     // Step A: Get Inputs
0027 
0028     // Step B: Create empty output
0029     ThingCollection result;  //Empty
0030 
0031     // Step C: Invoke the algorithm, passing in inputs (NONE) and getting back outputs.
0032     alg_.run(result);
0033 
0034     // Step D: Put outputs into event
0035     if (!noPut_)
0036       e.emplace(evToken_, std::move(result));
0037   }
0038 
0039   // Functions that gets called by framework every luminosity block
0040   void ThingProducer::globalBeginLuminosityBlockProduce(edm::LuminosityBlock& lb, edm::EventSetup const&) const {
0041     // Step A: Get Inputs
0042 
0043     // Step B: Create empty output
0044     ThingCollection result;  //Empty
0045 
0046     // Step C: Invoke the algorithm, passing in inputs (NONE) and getting back outputs.
0047     alg_.run(result);
0048 
0049     // Step D: Put outputs into lumi block
0050     if (!noPut_)
0051       lb.emplace(blToken_, std::move(result));
0052   }
0053 
0054   void ThingProducer::globalEndLuminosityBlockProduce(edm::LuminosityBlock& lb, edm::EventSetup const&) const {
0055     // Step A: Get Inputs
0056 
0057     // Step B: Create empty output
0058     ThingCollection result;  //Empty
0059 
0060     // Step C: Invoke the algorithm, passing in inputs (NONE) and getting back outputs.
0061     alg_.run(result);
0062 
0063     // Step D: Put outputs into lumi block
0064     if (!noPut_)
0065       lb.emplace(elToken_, std::move(result));
0066   }
0067 
0068   // Functions that gets called by framework every run
0069   void ThingProducer::globalBeginRunProduce(edm::Run& r, edm::EventSetup const&) const {
0070     // Step A: Get Inputs
0071 
0072     // Step B: Create empty output
0073     ThingCollection result;  //Empty
0074 
0075     // Step C: Invoke the algorithm, passing in inputs (NONE) and getting back outputs.
0076     alg_.run(result);
0077 
0078     // Step D: Put outputs into event
0079     if (!noPut_)
0080       r.emplace(brToken_, std::move(result));
0081   }
0082 
0083   void ThingProducer::globalEndRunProduce(edm::Run& r, edm::EventSetup const&) const {
0084     // Step A: Get Inputs
0085 
0086     // Step B: Create empty output
0087     ThingCollection result;  //Empty
0088 
0089     // Step C: Invoke the algorithm, passing in inputs (NONE) and getting back outputs.
0090     alg_.run(result);
0091 
0092     // Step D: Put outputs into event
0093     if (!noPut_)
0094       r.emplace(erToken_, std::move(result));
0095   }
0096 
0097   void ThingProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0098     edm::ParameterSetDescription desc;
0099     desc.add<int>("offsetDelta", 0)
0100         ->setComment(
0101             "How much extra to increment the value used when creating Things for a new container. E.g. the last value "
0102             "used to create Thing from the previous event is incremented by 'offsetDelta' to compute the value to use "
0103             "of the first Thing created in the next Event.");
0104     desc.add<int>("nThings", 20)->setComment("How many Things to put in each collection.");
0105     desc.add<bool>("grow", false)
0106         ->setComment("If true, multiply 'nThings' by the value of offset for each run of the algorithm.");
0107     desc.addUntracked<bool>("noPut", false)
0108         ->setComment("If true, data is not put into the Principal. This is used to test missing products.");
0109     descriptions.add("thingProd", desc);
0110   }
0111 
0112 }  // namespace edmtest
0113 using edmtest::ThingProducer;
0114 DEFINE_FWK_MODULE(ThingProducer);