Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-12-06 02:04:04

0001 // -*- C++ -*-
0002 //
0003 // Package:     Mixing/Base
0004 // Class  :     PileupRandomNumberGenerator
0005 //
0006 // Implementation:
0007 //     [Notes on implementation]
0008 //
0009 // Original Author:  Christopher Jones
0010 //         Created:  Wed, 09 Nov 2022 17:53:24 GMT
0011 //
0012 
0013 // system include files
0014 
0015 // user include files
0016 #include "PileupRandomNumberGenerator.h"
0017 #include "FWCore/ServiceRegistry/interface/CurrentModuleOnThread.h"
0018 #include "FWCore/Utilities/interface/EDMException.h"
0019 #include "FWCore/Utilities/interface/LuminosityBlockIndex.h"
0020 #include "FWCore/Utilities/interface/StreamID.h"
0021 #include "DataFormats/Provenance/interface/ModuleDescription.h"
0022 
0023 #include "IOMC/RandomEngine/interface/cloneEngine.h"
0024 
0025 #include "CLHEP/Random/RandomEngine.h"
0026 
0027 PileupRandomNumberGenerator::PileupRandomNumberGenerator(std::vector<std::string> const& iModuleLabels) : m_seed(0) {
0028   for (auto const& name : iModuleLabels) {
0029     m_modulesToEngines.emplace(name, std::unique_ptr<CLHEP::HepRandomEngine>{});
0030   }
0031 }
0032 
0033 CLHEP::HepRandomEngine& PileupRandomNumberGenerator::getEngine(edm::StreamID const&) {
0034   return *m_modulesToEngines[findPresentModule()];
0035 }
0036 
0037 CLHEP::HepRandomEngine& PileupRandomNumberGenerator::getEngine(edm::LuminosityBlockIndex const&) {
0038   return *m_modulesToEngines[findPresentModule()];
0039 }
0040 
0041 std::unique_ptr<CLHEP::HepRandomEngine> PileupRandomNumberGenerator::cloneEngine(edm::LuminosityBlockIndex const&) {
0042   auto& engine = m_modulesToEngines[findPresentModule()];
0043   return edm::cloneEngine(*engine);
0044 }
0045 
0046 void PileupRandomNumberGenerator::setSeed(uint32_t iSeed) { m_seed = iSeed; }
0047 
0048 void PileupRandomNumberGenerator::setEngine(CLHEP::HepRandomEngine const& iEngine) {
0049   for (auto& v : m_modulesToEngines) {
0050     v.second = edm::cloneEngine(iEngine);
0051   }
0052 }
0053 
0054 void PileupRandomNumberGenerator::preBeginLumi(edm::LuminosityBlock const& lumi) {}
0055 void PileupRandomNumberGenerator::postEventRead(edm::Event const& event) {}
0056 
0057 void PileupRandomNumberGenerator::setLumiCache(edm::LuminosityBlockIndex,
0058                                                std::vector<RandomEngineState> const& iStates) {}
0059 void PileupRandomNumberGenerator::setEventCache(edm::StreamID, std::vector<RandomEngineState> const& iStates) {}
0060 
0061 std::vector<RandomEngineState> const& PileupRandomNumberGenerator::getEventCache(edm::StreamID const&) const {
0062   static const std::vector<RandomEngineState> s_dummy;
0063   return s_dummy;
0064 }
0065 std::vector<RandomEngineState> const& PileupRandomNumberGenerator::getLumiCache(edm::LuminosityBlockIndex const&) const {
0066   static const std::vector<RandomEngineState> s_dummy;
0067   return s_dummy;
0068 }
0069 
0070 void PileupRandomNumberGenerator::consumes(edm::ConsumesCollector&& iC) const {}
0071 
0072 void PileupRandomNumberGenerator::print(std::ostream& os) const {}
0073 
0074 const std::string& PileupRandomNumberGenerator::findPresentModule() const {
0075   edm::ModuleCallingContext const* mcc = edm::CurrentModuleOnThread::getCurrentModuleOnThread();
0076   if (mcc == nullptr) {
0077     throw edm::Exception(edm::errors::LogicError)
0078         << "PileupRandomNumberGenerator::getEngine()\n"
0079            "Requested a random number engine from the RandomNumberGeneratorService\n"
0080            "from an unallowed transition. ModuleCallingContext is null\n";
0081   }
0082   return mcc->moduleDescription()->moduleLabel();
0083 }