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