Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include "FWCore/Framework/interface/one/EDProducer.h"
0002 #include "FWCore/Framework/interface/MakerMacros.h"
0003 #include "FWCore/Framework/interface/Event.h"
0004 #include "FWCore/Framework/interface/LuminosityBlock.h"
0005 
0006 #include "FWCore/Utilities/interface/RandomNumberGenerator.h"
0007 #include "FWCore/Utilities/interface/EDPutToken.h"
0008 #include "FWCore/Utilities/interface/Transition.h"
0009 #include "FWCore/ServiceRegistry/interface/Service.h"
0010 
0011 #include "DataFormats/TestObjects/interface/ToyProducts.h"
0012 
0013 #include "CLHEP/Random/RandFlat.h"
0014 
0015 namespace edmtest {
0016   class RandomIntProducer : public edm::one::EDProducer<edm::BeginLuminosityBlockProducer> {
0017   public:
0018     RandomIntProducer(edm::ParameterSet const& iPSet);
0019 
0020     void produce(edm::Event&, edm::EventSetup const&) final;
0021 
0022     void beginLuminosityBlockProduce(edm::LuminosityBlock&, edm::EventSetup const&) final;
0023 
0024   private:
0025     edm::EDPutTokenT<IntProduct> const evToken_;
0026     edm::EDPutTokenT<IntProduct> const lumiToken_;
0027   };
0028   RandomIntProducer::RandomIntProducer(edm::ParameterSet const&)
0029       : evToken_{produces<IntProduct>()},
0030         lumiToken_{produces<IntProduct, edm::Transition::BeginLuminosityBlock>("lumi")} {}
0031 
0032   void RandomIntProducer::produce(edm::Event& iEvent, edm::EventSetup const&) {
0033     edm::Service<edm::RandomNumberGenerator> gen;
0034     iEvent.emplace(evToken_, CLHEP::RandFlat::shootInt(&gen->getEngine(iEvent.streamID()), 10));
0035   }
0036 
0037   void RandomIntProducer::beginLuminosityBlockProduce(edm::LuminosityBlock& iLumi, edm::EventSetup const&) {
0038     edm::Service<edm::RandomNumberGenerator> gen;
0039     iLumi.emplace(lumiToken_, CLHEP::RandFlat::shootInt(&gen->getEngine(iLumi.index()), 10));
0040   }
0041 
0042 }  // namespace edmtest
0043 
0044 using namespace edmtest;
0045 DEFINE_FWK_MODULE(RandomIntProducer);