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
dqmMemoryStats.float
float
Definition: dqmMemoryStats.py:127
edm::TRandomAdaptor::TRandom3Ptr
value_ptr< TRandom3 > TRandom3Ptr
Definition: TRandomAdaptor.h:15
edm
HLT enums.
Definition: AlignableModifier.h:19
edm::TRandomAdaptor::showStatus
void showStatus() const override
Definition: TRandomAdaptor.h:44
edm::TRandomAdaptor::flat
double flat() override
Definition: TRandomAdaptor.h:25
edm::TRandomAdaptor::name
std::string name() const override
Definition: TRandomAdaptor.h:58
edm::TRandomAdaptor::get
std::istream & get(std::istream &is) override
Definition: TRandomAdaptor.cc:84
findQualityFiles.v
v
Definition: findQualityFiles.py:179
edm::TRandomAdaptor::put
std::vector< unsigned long > put() const override
Definition: TRandomAdaptor.cc:34
edm::TRandomAdaptor::getRootEngine
TRandom3 * getRootEngine()
Definition: TRandomAdaptor.h:66
fileCollector.seed
seed
Definition: fileCollector.py:127
edm::TRandomAdaptor::engineName
static std::string engineName()
Definition: TRandomAdaptor.h:59
edm::TRandomAdaptor::~TRandomAdaptor
~TRandomAdaptor() override
Definition: TRandomAdaptor.cc:27
edm::TRandomAdaptor::TRandomAdaptor
TRandomAdaptor()
Definition: TRandomAdaptor.cc:17
edm::TRandomAdaptor::setSeed
void setSeed(long seed, int) override
Definition: TRandomAdaptor.cc:72
corrVsCorr.filename
filename
Definition: corrVsCorr.py:123
edm::TRandomAdaptor
Definition: TRandomAdaptor.h:13
value_ptr.h
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
InitialStep_cff.seeds
seeds
Definition: InitialStep_cff.py:231
edm::TRandomAdaptor::trand_
TRandom3Ptr trand_
Definition: TRandomAdaptor.h:71
edm::value_ptr< TRandom3 >
createfilelist.int
int
Definition: createfilelist.py:10
edm::TRandomAdaptor::restoreStatus
void restoreStatus(char const filename[]="TRandom.conf") override
Definition: TRandomAdaptor.h:41
edm::TRandomAdaptor::setSeeds
void setSeeds(long const *seeds, int) override
Definition: TRandomAdaptor.cc:79
edm::TRandomAdaptor::Grumble
void Grumble(std::string const &errortext) const
Definition: TRandomAdaptor.cc:118
edm::TRandomAdaptor::saveStatus
void saveStatus(char const filename[]="TRandom.conf") const override
Definition: TRandomAdaptor.h:38
edm::TRandomAdaptor::getState
std::istream & getState(std::istream &is) override
Definition: TRandomAdaptor.cc:89
edm::TRandomAdaptor::flatArray
void flatArray(int const size, double *vect) override
Definition: TRandomAdaptor.h:28
edm::TRandomAdaptor::beginTag
std::string beginTag()
Definition: TRandomAdaptor.h:54
edm::TRandomAdaptor::getState
bool getState(std::vector< unsigned long > const &v) override
Definition: TRandomAdaptor.h:63
findQualityFiles.size
size
Write out results.
Definition: findQualityFiles.py:443