Jpp 19.3.0-rc.2
the software that should make you happy
Loading...
Searching...
No Matches
JROOT::JRandom Struct Reference

Auxiliary data structure to configure random number generator. More...

#include <JRandom.hh>

Inheritance diagram for JROOT::JRandom:

Public Member Functions

 JRandom ()
 Default constructor.
 
 JRandom (const TString &buffer)
 Constructor.
 
 JRandom (const ULong_t seed)
 Constructor.
 
bool set (TRandom *&pr) const
 Configure random number generator.
 

Static Public Member Functions

static bool read (const TString &file_name, TRandom *&pr)
 Read random number generator from file.
 
static bool write (const TString &file_name, TRandom *pr)
 Write random number generator to file.
 

Friends

std::istream & operator>> (std::istream &in, JRandom &object)
 Read random from input.
 
std::ostream & operator<< (std::ostream &out, const JRandom &object)
 Write random to output.
 

Detailed Description

Auxiliary data structure to configure random number generator.

The internal TString can hold any of the following data.

  • decimal value corresponding to seed;
  • name of ROOT formatted binary file; or
  • name of JSON formatted ASCII file.

Definition at line 34 of file JROOT/JRandom.hh.

Constructor & Destructor Documentation

◆ JRandom() [1/3]

JROOT::JRandom::JRandom ( )
inline

Default constructor.

Definition at line 40 of file JROOT/JRandom.hh.

41 {}

◆ JRandom() [2/3]

JROOT::JRandom::JRandom ( const TString & buffer)
inline

Constructor.

Parameters
bufferbuffer

Definition at line 49 of file JROOT/JRandom.hh.

50 {
51 static_cast<TString&>(*this) = buffer;
52 }

◆ JRandom() [3/3]

JROOT::JRandom::JRandom ( const ULong_t seed)
inline

Constructor.

Parameters
seedseed

Definition at line 60 of file JROOT/JRandom.hh.

61 {
62 static_cast<TString&>(*this) += seed;
63 }

Member Function Documentation

◆ set()

bool JROOT::JRandom::set ( TRandom *& pr) const
inline

Configure random number generator.

Parameters
prreference pointer to random number generator
Returns
true if successful; else false

Definition at line 98 of file JROOT/JRandom.hh.

99 {
100 using namespace std;
101 using namespace JPP;
102
103 if (pr != NULL) {
104
105 if (this->IsDec()) {
106
107 pr->SetSeed(this->Atoll());
108
109 return true;
110
111 } else {
112
113 return JRandom::read(static_cast<const TString&>(*this), pr);
114 }
115 }
116
117 return false;
118 }
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
static bool read(const TString &file_name, TRandom *&pr)
Read random number generator from file.

◆ read()

static bool JROOT::JRandom::read ( const TString & file_name,
TRandom *& pr )
inlinestatic

Read random number generator from file.

Parameters
file_namefile name
prreference pointer to random number generator
Returns
true if successful; else false

Definition at line 128 of file JROOT/JRandom.hh.

129 {
130 using namespace std;
131 using namespace JPP;
132
133 if (pr != NULL) {
134
135 if (file_name.EndsWith(".root")) {
136
137 JRootFileReader<TRandom> in(file_name.Data(), pr->GetName());
138
139 if (in.hasNext()) {
140
141 TRandom* p = in.next();
142
143 pr = (TRandom*) p->Clone();
144
145 return true;
146 }
147
148 } else if (file_name.EndsWith(".txt")) {
149
150 fstream in(file_name.Data());
151
152 stringstream io;
153
154 if (io << in.rdbuf()) {
155
156 pr = (TRandom*) TBufferJSON::ConvertFromJSON(io.str().c_str());
157
158 return true;
159 }
160 }
161 }
162
163 return false;
164 }

◆ write()

static bool JROOT::JRandom::write ( const TString & file_name,
TRandom * pr )
inlinestatic

Write random number generator to file.

Parameters
file_namefile name
prpointer to random number generator
Returns
true if successful; else false

Definition at line 174 of file JROOT/JRandom.hh.

175 {
176 using namespace std;
177 using namespace JPP;
178
179 if (pr != NULL) {
180
181 if (file_name.EndsWith(".root")) {
182
183 JRootFileWriter<TRandom> out(file_name.Data());
184
185 out.put(*gRandom);
186
187 out.close();
188
189 return true;
190
191 } else if (file_name.EndsWith(".txt")) {
192
193 ofstream out(file_name.Data());
194
195 out << TBufferJSON::ConvertToJSON(gRandom).Data();
196
197 out.close();
198
199 return true;
200 }
201 }
202
203 return false;
204 }
ROOT file object output.

Friends And Related Symbol Documentation

◆ operator>>

std::istream & operator>> ( std::istream & in,
JRandom & object )
friend

Read random from input.

Parameters
ininput stream
objectrandom
Returns
input stream

Definition at line 73 of file JROOT/JRandom.hh.

74 {
75 return in >> static_cast<TString&>(object);
76 }

◆ operator<<

std::ostream & operator<< ( std::ostream & out,
const JRandom & object )
friend

Write random to output.

Parameters
outoutput stream
objectrandom
Returns
output stream

Definition at line 86 of file JROOT/JRandom.hh.

87 {
88 return out << object.Data();
89 }

The documentation for this struct was generated from the following file: