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