CMS 3D CMS Logo

TRandomAdaptor.h
Go to the documentation of this file.
1 #ifndef IOMC_RandomEngine_TRandomAdaptor_h
2 #define IOMC_RandomEngine_TRandomAdaptor_h
3 
4 #include "CLHEP/Random/RandomEngine.h"
5 
6 #include "TRandom3.h"
7 
8 #include <cmath>
10 
11 namespace edm {
12 
13  class TRandomAdaptor : public CLHEP::HepRandomEngine {
14  public:
16 
17  // Constructors and destructor.
19  TRandomAdaptor(long seed);
20  TRandomAdaptor(int rowIndex, int colIndex);
21  TRandomAdaptor(std::istream& is);
22  ~TRandomAdaptor() override;
23 
24  // Returns a pseudo random number in ]0,1[ (i. e., excluding the end points).
25  double flat() override { return trand_->Rndm(); }
26 
27  // Fills an array "vect" of specified size with flat random values.
28  void flatArray(int const size, double* vect) override { trand_->RndmArray(size, vect); }
29 
30  // Sets the state of the algorithm according to seed.
31  void setSeed(long seed, int) override;
32 
33  // Sets the state of the algorithm according to the zero terminated
34  // array of seeds. It is allowed to ignore one or many seeds in this array.
35  void setSeeds(long const* seeds, int) override;
36 
37  // Saves the current engine status in the named file
38  void saveStatus(char const filename[] = "TRandom.conf") const override { trand_->WriteRandom(filename); }
39 
40  // Reads from named file the the last saved engine status and restores it.
41  void restoreStatus(char const filename[] = "TRandom.conf") override { trand_->ReadRandom(filename); }
42 
43  // Dumps the current engine status on the screen.
44  void showStatus() const override { trand_->Dump(); }
45 
46  // Returns a float flat ]0,1[
47  operator float() override { return (float)(trand_->Rndm()); }
48 
49  // Returns an unsigned int (32-bit) flat
50  operator unsigned int() override { return (unsigned int)((trand_->Rndm()) * exponent_bit_32()); }
51 
52  std::ostream& put(std::ostream& os) const override;
53  std::istream& get(std::istream& is) override;
54  std::string beginTag() { return std::string(trand_->GetName()) + std::string("-begin"); }
55  std::istream& getState(std::istream& is) override;
56 
57  // Returns the engine name as a string
58  std::string name() const override { return std::string("T") + std::string(trand_->GetName()); }
59  static std::string engineName() { return std::string("TRandomAdaptor"); }
60 
61  std::vector<unsigned long> put() const override;
62  bool get(std::vector<unsigned long> const& v) override;
63  bool getState(std::vector<unsigned long> const& v) override { return get(v); }
64 
65  // In case all else fails, let the user talk directly to the engine
66  TRandom3* getRootEngine() { return trand_.operator->(); }
67 
68  private:
69  void Grumble(std::string const& errortext) const;
70 
72 
73  }; // TRandomAdaptor
74 
75 } // namespace edm
76 
77 #endif // IOMC_RandomEngine_TRandomAdaptor_h
value_ptr< TRandom3 > TRandom3Ptr
std::string name() const override
void setSeed(long seed, int) override
std::vector< unsigned long > put() const override
TRandom3 * getRootEngine()
void flatArray(int const size, double *vect) override
void Grumble(std::string const &errortext) const
void showStatus() const override
bool getState(std::vector< unsigned long > const &v) override
static std::string engineName()
void setSeeds(long const *seeds, int) override
double flat() override
~TRandomAdaptor() override
HLT enums.
std::istream & getState(std::istream &is) override
void saveStatus(char const filename[]="TRandom.conf") const override
void restoreStatus(char const filename[]="TRandom.conf") override
std::string beginTag()