test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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  virtual ~TRandomAdaptor();
24 
25  // Returns a pseudo random number in ]0,1[ (i. e., excluding the end points).
26  double flat() { return trand_->Rndm(); }
27 
28  // Fills an array "vect" of specified size with flat random values.
29  void flatArray(int const size, double* vect) { trand_->RndmArray(size,vect); }
30 
31  // Sets the state of the algorithm according to seed.
32  void setSeed(long seed, int);
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);
37 
38  // Saves the current engine status in the named file
39  void saveStatus(char const filename[] = "TRandom.conf") const { 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" ) { trand_->ReadRandom(filename); }
43 
44  // Dumps the current engine status on the screen.
45  void showStatus() const { trand_->Dump(); }
46 
47  // Returns a float flat ]0,1[
48  operator float() { return (float)(trand_->Rndm()); }
49 
50  // Returns an unsigned int (32-bit) flat
51  operator unsigned int() { return (unsigned int)((trand_->Rndm())*exponent_bit_32()); }
52 
53  virtual std::ostream & put (std::ostream & os) const;
54  virtual std::istream & get (std::istream & is);
55  std::string beginTag ( ) { return std::string(trand_->GetName())+std::string("-begin"); }
56  virtual std::istream & getState ( std::istream & is );
57 
58  // Returns the engine name as a string
59  std::string name() const { 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;
63  bool get (std::vector<unsigned long> const& v);
64  bool getState (std::vector<unsigned long> const& v) { 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 
74 
75  }; // TRandomAdaptor
76 
77 } // namespace edm
78 
79 #endif // IOMC_RandomEngine_TRandomAdaptor_h
void flatArray(int const size, double *vect)
value_ptr< TRandom3 > TRandom3Ptr
std::vector< unsigned long > put() const
void setSeed(long seed, int)
void showStatus() const
virtual std::istream & getState(std::istream &is)
TRandom3 * getRootEngine()
void saveStatus(char const filename[]="TRandom.conf") const
bool getState(std::vector< unsigned long > const &v)
void setSeeds(long const *seeds, int)
std::string name() const
static std::string engineName()
void restoreStatus(char const filename[]="TRandom.conf")
tuple filename
Definition: lut2db_cfg.py:20
void Grumble(std::string const &errortext) const
tuple size
Write out results.
std::string beginTag()