Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:21:10

0001 
0002 #include "IOMC/RandomEngine/src/RandomEngineStateProducer.h"
0003 
0004 #include "FWCore/Framework/interface/Event.h"
0005 #include "FWCore/Framework/interface/LuminosityBlock.h"
0006 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0007 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0008 #include "FWCore/ServiceRegistry/interface/Service.h"
0009 #include "FWCore/Utilities/interface/RandomNumberGenerator.h"
0010 #include "SimDataFormats/RandomEngine/interface/RandomEngineStates.h"
0011 
0012 #include <memory>
0013 
0014 RandomEngineStateProducer::RandomEngineStateProducer(edm::ParameterSet const&) {
0015   produces<edm::RandomEngineStates, edm::Transition::BeginLuminosityBlock>("beginLumi");
0016   produces<edm::RandomEngineStates>();
0017 }
0018 
0019 RandomEngineStateProducer::~RandomEngineStateProducer() {}
0020 
0021 void RandomEngineStateProducer::produce(edm::StreamID iID, edm::Event& ev, edm::EventSetup const&) const {
0022   edm::Service<edm::RandomNumberGenerator> randomService;
0023   if (randomService.isAvailable()) {
0024     auto states = std::make_unique<edm::RandomEngineStates>();
0025     states->setRandomEngineStates(randomService->getEventCache(ev.streamID()));
0026     ev.put(std::move(states));
0027   }
0028 }
0029 
0030 void RandomEngineStateProducer::globalBeginLuminosityBlockProduce(edm::LuminosityBlock& lb,
0031                                                                   edm::EventSetup const&) const {
0032   edm::Service<edm::RandomNumberGenerator> randomService;
0033   if (randomService.isAvailable()) {
0034     auto states = std::make_unique<edm::RandomEngineStates>();
0035     states->setRandomEngineStates(randomService->getLumiCache(lb.index()));
0036     lb.put(std::move(states), "beginLumi");
0037   }
0038 }
0039 
0040 void RandomEngineStateProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0041   edm::ParameterSetDescription desc;
0042   descriptions.add("randomEngineStateProducer", desc);
0043 }