Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:22:36

0001 #ifndef Mixing_Base_PileupRandomNumberGenerator_h
0002 #define Mixing_Base_PileupRandomNumberGenerator_h
0003 // -*- C++ -*-
0004 //
0005 // Package:     Mixing/Base
0006 // Class  :     PileupRandomNumberGenerator
0007 //
0008 /**\class PileupRandomNumberGenerator PileupRandomNumberGenerator.h "PileupRandomNumberGenerator.h"
0009 
0010  Description: Handle forwarding random numbers to modules within a mixing module
0011 
0012  Usage:
0013     Internal
0014 
0015 */
0016 //
0017 // Original Author:  Christopher Jones
0018 //         Created:  Wed, 09 Nov 2022 17:53:22 GMT
0019 //
0020 
0021 // system include files
0022 #include <memory>
0023 #include <unordered_map>
0024 
0025 // user include files
0026 #include "FWCore/Utilities/interface/RandomNumberGenerator.h"
0027 #include "SimDataFormats/RandomEngine/interface/RandomEngineState.h"
0028 #include "FWCore/ServiceRegistry/interface/ModuleCallingContext.h"
0029 
0030 // forward declarations
0031 
0032 class PileupRandomNumberGenerator : public edm::RandomNumberGenerator {
0033 public:
0034   PileupRandomNumberGenerator(std::vector<std::string> const& iModuleLabels);
0035 
0036   void setSeed(uint32_t iSeed);
0037   void setEngine(CLHEP::HepRandomEngine const&);
0038 
0039   CLHEP::HepRandomEngine& getEngine(edm::StreamID const&) final;
0040 
0041   CLHEP::HepRandomEngine& getEngine(edm::LuminosityBlockIndex const&) final;
0042 
0043   std::unique_ptr<CLHEP::HepRandomEngine> cloneEngine(edm::LuminosityBlockIndex const&) final;
0044 
0045   std::uint32_t mySeed() const final { return m_seed; }
0046 
0047 private:
0048   void preBeginLumi(edm::LuminosityBlock const& lumi) final;
0049   void postEventRead(edm::Event const& event) final;
0050 
0051   void setLumiCache(edm::LuminosityBlockIndex, std::vector<RandomEngineState> const& iStates) final;
0052   void setEventCache(edm::StreamID, std::vector<RandomEngineState> const& iStates) final;
0053 
0054   std::vector<RandomEngineState> const& getEventCache(edm::StreamID const&) const final;
0055   std::vector<RandomEngineState> const& getLumiCache(edm::LuminosityBlockIndex const&) const final;
0056 
0057   void consumes(edm::ConsumesCollector&& iC) const final;
0058 
0059   /// For debugging purposes only.
0060   void print(std::ostream& os) const final;
0061 
0062   static std::unique_ptr<CLHEP::HepRandomEngine> cloneEngine(CLHEP::HepRandomEngine const& existingEngine);
0063 
0064   const std::string& findPresentModule() const;
0065 
0066   std::unordered_map<std::string, std::unique_ptr<CLHEP::HepRandomEngine>> m_modulesToEngines;
0067   uint32_t m_seed;
0068 };
0069 
0070 #endif