Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:13:03

0001 #ifndef FWCore_Services_ExternalRandomNumberGeneratorService_h
0002 #define FWCore_Services_ExternalRandomNumberGeneratorService_h
0003 
0004 /** \class edm::ExternalRandomNumberGenerator
0005 
0006   Description: Interface for obtaining random number engines.
0007 
0008   Usage:
0009 */
0010 
0011 #include <cstdint>
0012 #include <iosfwd>
0013 #include <memory>
0014 #include <vector>
0015 
0016 #include "FWCore/Utilities/interface/RandomNumberGenerator.h"
0017 
0018 namespace edm {
0019 
0020   class ExternalRandomNumberGeneratorService : public RandomNumberGenerator {
0021   public:
0022     ExternalRandomNumberGeneratorService();
0023     ExternalRandomNumberGeneratorService(ExternalRandomNumberGeneratorService const&) = delete;
0024     ExternalRandomNumberGeneratorService const& operator=(ExternalRandomNumberGeneratorService const&) = delete;
0025 
0026     void setState(std::vector<unsigned long> const&, long seed);
0027     std::vector<unsigned long> getState() const;
0028 
0029     CLHEP::HepRandomEngine& getEngine(StreamID const&) final;
0030     CLHEP::HepRandomEngine& getEngine(LuminosityBlockIndex const&) final;
0031     std::unique_ptr<CLHEP::HepRandomEngine> cloneEngine(LuminosityBlockIndex const&) final;
0032     std::uint32_t mySeed() const final;
0033 
0034     // The following functions should not be used by general users.  They
0035     // should only be called by Framework code designed to work with the
0036     // service while it is saving the engine states or restoring them.
0037     // The first two are called by the EventProcessor at special times.
0038     // The next two are called by a dedicated producer module (RandomEngineStateProducer).
0039 
0040     void preBeginLumi(LuminosityBlock const& lumi) final;
0041     void postEventRead(Event const& event) final;
0042 
0043     void setLumiCache(LuminosityBlockIndex, std::vector<RandomEngineState> const& iStates) final;
0044     void setEventCache(StreamID, std::vector<RandomEngineState> const& iStates) final;
0045 
0046     std::vector<RandomEngineState> const& getEventCache(StreamID const&) const final;
0047     std::vector<RandomEngineState> const& getLumiCache(LuminosityBlockIndex const&) const final;
0048 
0049     void consumes(ConsumesCollector&& iC) const final;
0050 
0051     /// For debugging purposes only.
0052     void print(std::ostream& os) const final;
0053 
0054   private:
0055     std::unique_ptr<CLHEP::HepRandomEngine> createFromState(std::vector<unsigned long> const&, long seed) const;
0056 
0057     std::unique_ptr<CLHEP::HepRandomEngine> engine_;
0058   };
0059 }  // namespace edm
0060 #endif