Auxiliary data structure to configure random number generator.  
 More...
#include <JRandom.hh>
 | 
|   | JRandom () | 
|   | Default constructor.  
  | 
|   | 
|   | JRandom (const TString &buffer) | 
|   | Constructor.  
  | 
|   | 
|   | JRandom (const ULong_t seed) | 
|   | Constructor.  
  | 
|   | 
| bool  | set (TRandom *&pr) const | 
|   | Configure random number generator.  
  | 
|   | 
 | 
| 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.  
  | 
|   | 
 | 
| 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.  
  | 
|   | 
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.
 
◆ JRandom() [1/3]
  
  
      
        
          | JROOT::JRandom::JRandom  | 
          ( | 
           | ) | 
           | 
         
       
   | 
  
inline   | 
  
 
 
◆ JRandom() [2/3]
  
  
      
        
          | JROOT::JRandom::JRandom  | 
          ( | 
          const TString & |           buffer | ) | 
           | 
         
       
   | 
  
inline   | 
  
 
Constructor. 
- Parameters
 - 
  
  
 
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
 - 
  
  
 
Definition at line 60 of file JROOT/JRandom.hh.
   61    {
   62      static_cast<TString&>(*this) += seed;
   63    }
 
 
 
◆ set()
  
  
      
        
          | bool JROOT::JRandom::set  | 
          ( | 
          TRandom *& |           pr | ) | 
           const | 
         
       
   | 
  
inline   | 
  
 
Configure random number generator. 
- Parameters
 - 
  
    | pr | reference pointer to random number generator  | 
  
   
- Returns
 - true if successful; else false 
 
Definition at line 98 of file JROOT/JRandom.hh.
   99    {
  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_name | file name  | 
    | pr | reference pointer to random number generator  | 
  
   
- Returns
 - true if successful; else false 
 
Definition at line 128 of file JROOT/JRandom.hh.
  129    {
  132 
  133      if (pr != NULL) {
  134 
  135        if        (file_name.EndsWith(".root")) {
  136 
  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_name | file name  | 
    | pr | pointer to random number generator  | 
  
   
- Returns
 - true if successful; else false 
 
Definition at line 174 of file JROOT/JRandom.hh.
  175    {
  178 
  179      if (pr != NULL) {
  180 
  181        if        (file_name.EndsWith(".root")) {
  182 
  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    }
 
 
 
◆ operator>>
  
  
      
        
          | std::istream & operator>>  | 
          ( | 
          std::istream & |           in,  | 
         
        
           | 
           | 
          JRandom & |           object ) | 
         
       
   | 
  
friend   | 
  
 
Read random from input. 
- Parameters
 - 
  
    | in | input stream  | 
    | object | random  | 
  
   
- 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
 - 
  
    | out | output stream  | 
    | object | random  | 
  
   
- 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: