Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:28:36

0001 #include "FWCore/Integration/test/ThingExtSource.h"
0002 #include "DataFormats/TestObjects/interface/ThingCollection.h"
0003 #include "FWCore/Framework/interface/Event.h"
0004 #include "FWCore/Framework/interface/LuminosityBlock.h"
0005 #include "FWCore/Framework/interface/Run.h"
0006 #include "FWCore/Framework/interface/InputSourceMacros.h"
0007 
0008 namespace edmtest {
0009   ThingExtSource::ThingExtSource(edm::ParameterSet const& pset, edm::InputSourceDescription const& desc)
0010       : ProducerSourceFromFiles(pset, desc, true), alg_() {
0011     produces<ThingCollection>();
0012     produces<ThingCollection, edm::Transition::BeginLuminosityBlock>("beginLumi");
0013     produces<ThingCollection, edm::Transition::BeginLuminosityBlock>("endLumi");
0014     produces<ThingCollection, edm::Transition::BeginRun>("beginRun");
0015     produces<ThingCollection, edm::Transition::BeginRun>("endRun");
0016   }
0017 
0018   // Virtual destructor needed.
0019   ThingExtSource::~ThingExtSource() {}
0020 
0021   // Functions that gets called by framework every event
0022   bool ThingExtSource::setRunAndEventInfo(edm::EventID&, edm::TimeValue_t&, edm::EventAuxiliary::ExperimentType&) {
0023     // Fake running out of data.
0024     if (event() > 2)
0025       return false;
0026     return true;
0027   }
0028 
0029   void ThingExtSource::produce(edm::Event& e) {
0030     // Step A: Get Inputs
0031 
0032     // Step B: Create empty output
0033     auto result = std::make_unique<ThingCollection>();  //Empty
0034 
0035     // Step C: Invoke the algorithm, passing in inputs (NONE) and getting back outputs.
0036     alg_.run(*result);
0037 
0038     // Step D: Put outputs into event
0039     e.put(std::move(result));
0040   }
0041 
0042   // Functions that gets called by framework every luminosity block
0043   void ThingExtSource::beginLuminosityBlock(edm::LuminosityBlock& lb) {
0044     // Step A: Get Inputs
0045 
0046     // Step B: Create empty output
0047     auto result = std::make_unique<ThingCollection>();  //Empty
0048 
0049     // Step C: Invoke the algorithm, passing in inputs (NONE) and getting back outputs.
0050     alg_.run(*result);
0051 
0052     // Step D: Put outputs into lumi block
0053     lb.put(std::move(result), "beginLumi");
0054 
0055     endLuminosityBlock(lb);
0056   }
0057 
0058   void ThingExtSource::endLuminosityBlock(edm::LuminosityBlock& lb) {
0059     // Step A: Get Inputs
0060 
0061     // Step B: Create empty output
0062     auto result = std::make_unique<ThingCollection>();  //Empty
0063 
0064     // Step C: Invoke the algorithm, passing in inputs (NONE) and getting back outputs.
0065     alg_.run(*result);
0066 
0067     // Step D: Put outputs into lumi block
0068     lb.put(std::move(result), "endLumi");
0069   }
0070 
0071   // Functions that gets called by framework every run
0072   void ThingExtSource::beginRun(edm::Run& r) {
0073     // Step A: Get Inputs
0074 
0075     // Step B: Create empty output
0076     auto result = std::make_unique<ThingCollection>();  //Empty
0077 
0078     // Step C: Invoke the algorithm, passing in inputs (NONE) and getting back outputs.
0079     alg_.run(*result);
0080 
0081     // Step D: Put outputs into event
0082     r.put(std::move(result), "beginRun");
0083 
0084     endRun(r);
0085   }
0086 
0087   void ThingExtSource::endRun(edm::Run& r) {
0088     // Step A: Get Inputs
0089 
0090     // Step B: Create empty output
0091     auto result = std::make_unique<ThingCollection>();  //Empty
0092 
0093     // Step C: Invoke the algorithm, passing in inputs (NONE) and getting back outputs.
0094     alg_.run(*result);
0095 
0096     // Step D: Put outputs into event
0097     r.put(std::move(result), "endRun");
0098   }
0099 
0100   void ThingExtSource::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0101     edm::ParameterSetDescription desc;
0102     desc.setComment("Creates ThingCollections from a file for testing.");
0103     edm::ProducerSourceFromFiles::fillDescription(desc);
0104     descriptions.add("source", desc);
0105   }
0106 
0107 }  // namespace edmtest
0108 using edmtest::ThingExtSource;
0109 DEFINE_FWK_INPUT_SOURCE(ThingExtSource);