CMS 3D CMS Logo

List of all members | Public Types | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes
edm::TRandomAdaptor Class Reference

#include <TRandomAdaptor.h>

Inheritance diagram for edm::TRandomAdaptor:

Public Types

typedef value_ptr< TRandom3 > TRandom3Ptr
 

Public Member Functions

std::string beginTag ()
 
double flat () override
 
void flatArray (int const size, double *vect) override
 
std::istream & get (std::istream &is) override
 
bool get (std::vector< unsigned long > const &v) override
 
TRandom3 * getRootEngine ()
 
std::istream & getState (std::istream &is) override
 
bool getState (std::vector< unsigned long > const &v) override
 
std::string name () const override
 
 operator float () override
 
 operator unsigned int () override
 
std::vector< unsigned long > put () const override
 
std::ostream & put (std::ostream &os) const override
 
void restoreStatus (char const filename[]="TRandom.conf") override
 
void saveStatus (char const filename[]="TRandom.conf") const override
 
void setSeed (long seed, int) override
 
void setSeeds (long const *seeds, int) override
 
void showStatus () const override
 
 TRandomAdaptor ()
 
 TRandomAdaptor (int rowIndex, int colIndex)
 
 TRandomAdaptor (long seed)
 
 TRandomAdaptor (std::istream &is)
 
 ~TRandomAdaptor () override
 

Static Public Member Functions

static std::string engineName ()
 

Private Member Functions

void Grumble (std::string const &errortext) const
 

Private Attributes

TRandom3Ptr trand_
 

Detailed Description

Definition at line 13 of file TRandomAdaptor.h.

Member Typedef Documentation

◆ TRandom3Ptr

Definition at line 15 of file TRandomAdaptor.h.

Constructor & Destructor Documentation

◆ TRandomAdaptor() [1/4]

edm::TRandomAdaptor::TRandomAdaptor ( )

Definition at line 17 of file TRandomAdaptor.cc.

17 : trand_(new TRandom3()) { theSeed = trand_->GetSeed(); }

References trand_.

◆ TRandomAdaptor() [2/4]

edm::TRandomAdaptor::TRandomAdaptor ( long  seed)

Definition at line 18 of file TRandomAdaptor.cc.

18 : trand_(new TRandom3(seed)) { theSeed = trand_->GetSeed(); }

References trand_.

◆ TRandomAdaptor() [3/4]

edm::TRandomAdaptor::TRandomAdaptor ( int  rowIndex,
int  colIndex 
)

Definition at line 19 of file TRandomAdaptor.cc.

19  : trand_(new TRandom3(rowIndex * colIndex - 1)) {
20  theSeed = trand_->GetSeed();
21  }

References trand_.

◆ TRandomAdaptor() [4/4]

edm::TRandomAdaptor::TRandomAdaptor ( std::istream &  is)

Definition at line 23 of file TRandomAdaptor.cc.

23  {
24  Grumble(std::string("Cannot instantiate a TRandom engine from an istream"));
25  }

References Grumble(), and AlCaHLTBitMon_QueryRunRegistry::string.

◆ ~TRandomAdaptor()

edm::TRandomAdaptor::~TRandomAdaptor ( )
override

Definition at line 27 of file TRandomAdaptor.cc.

27 {}

Member Function Documentation

◆ beginTag()

std::string edm::TRandomAdaptor::beginTag ( )
inline

Definition at line 54 of file TRandomAdaptor.h.

54 { return std::string(trand_->GetName()) + std::string("-begin"); }

References AlCaHLTBitMon_QueryRunRegistry::string, and trand_.

◆ engineName()

static std::string edm::TRandomAdaptor::engineName ( )
inlinestatic

Definition at line 59 of file TRandomAdaptor.h.

59 { return std::string("TRandomAdaptor"); }

References AlCaHLTBitMon_QueryRunRegistry::string.

◆ flat()

double edm::TRandomAdaptor::flat ( void  )
inlineoverride

Definition at line 25 of file TRandomAdaptor.h.

25 { return trand_->Rndm(); }

References trand_.

◆ flatArray()

void edm::TRandomAdaptor::flatArray ( int const  size,
double *  vect 
)
inlineoverride

Definition at line 28 of file TRandomAdaptor.h.

28 { trand_->RndmArray(size, vect); }

References findQualityFiles::size, and trand_.

◆ get() [1/2]

std::istream & edm::TRandomAdaptor::get ( std::istream &  is)
override

◆ get() [2/2]

bool edm::TRandomAdaptor::get ( std::vector< unsigned long > const &  v)
override

Definition at line 94 of file TRandomAdaptor.cc.

94  {
95  if (v.empty())
96  return false;
97  if (v[0] != CLHEP::engineIDulong<TRandomAdaptor>())
98  return false;
99  int32_t numItems = v.size() - 1;
100 
101  int32_t itemSize = sizeof(uint32_t);
102  TBufferFile buffer(TBuffer::kRead, numItems * itemSize + 1024);
103  char* bufferPtr = buffer.Buffer();
104  for (int32_t i = 0; i < numItems; ++i) {
105  *reinterpret_cast<uint32_t*>(bufferPtr + i * itemSize) = static_cast<uint32_t>(v[i + 1] & 0xffffffff);
106  }
107 
108  // Note that this will fail if the TRandom3 version (specifically the TStreamerInfo)
109  // has changed between the time the state was saved and the time the following call
110  // is made. Because we are manually calling the Streamer function, the original
111  // TStreamerInfo is not saved anywhere. Normally ROOT saves the TStreamerInfo
112  // automatically.
113  trand_->Streamer(buffer);
114 
115  return true;
116  }

References edmScanValgrind::buffer, mps_fire::i, trand_, and findQualityFiles::v.

Referenced by Options.Options::__getitem__(), betterConfigParser.BetterConfigParser::__updateDict(), submitPVValidationJobs.BetterConfigParser::__updateDict(), betterConfigParser.BetterConfigParser::getCompares(), betterConfigParser.BetterConfigParser::getGeneral(), betterConfigParser.BetterConfigParser::getResultingSection(), and submitPVValidationJobs.BetterConfigParser::getResultingSection().

◆ getRootEngine()

TRandom3* edm::TRandomAdaptor::getRootEngine ( )
inline

Definition at line 66 of file TRandomAdaptor.h.

66 { return trand_.operator->(); }

References trand_.

◆ getState() [1/2]

std::istream & edm::TRandomAdaptor::getState ( std::istream &  is)
override

Definition at line 89 of file TRandomAdaptor.cc.

89  {
90  Grumble(std::string("getState(std::istream) not available for TRandom engines"));
91  return is;
92  }

References Grumble(), and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by get().

◆ getState() [2/2]

bool edm::TRandomAdaptor::getState ( std::vector< unsigned long > const &  v)
inlineoverride

Definition at line 63 of file TRandomAdaptor.h.

63 { return get(v); }

References get(), and findQualityFiles::v.

◆ Grumble()

void edm::TRandomAdaptor::Grumble ( std::string const &  errortext) const
private

Definition at line 118 of file TRandomAdaptor.cc.

118  {
119  // Throw an edm::Exception for unimplemented functions
120  std::ostringstream sstr;
121  sstr << "Unimplemented Feature: " << errortext << '\n';
123  throw except;
124  }

References edm::errors::UnimplementedFeature.

Referenced by get(), getState(), put(), and TRandomAdaptor().

◆ name()

std::string edm::TRandomAdaptor::name ( void  ) const
inlineoverride

◆ operator float()

edm::TRandomAdaptor::operator float ( )
inlineoverride

Definition at line 47 of file TRandomAdaptor.h.

47 { return (float)(trand_->Rndm()); }

References trand_.

◆ operator unsigned int()

edm::TRandomAdaptor::operator unsigned int ( )
inlineoverride

Definition at line 50 of file TRandomAdaptor.h.

50 { return (unsigned int)((trand_->Rndm()) * exponent_bit_32()); }

References trand_.

◆ put() [1/2]

std::vector< unsigned long > edm::TRandomAdaptor::put ( ) const
override

Definition at line 34 of file TRandomAdaptor.cc.

34  {
35  std::vector<unsigned long> v;
36 
37  int32_t itemSize = sizeof(uint32_t);
38  TBufferFile buffer(TBuffer::kWrite, 2048 * itemSize);
39  trand_->Streamer(buffer);
40  buffer.SetReadMode();
41  char* bufferPtr = buffer.Buffer();
42  int32_t numItems = (buffer.Length() + itemSize - 1) / itemSize;
43  v.reserve(numItems + 1);
44  v.push_back(CLHEP::engineIDulong<TRandomAdaptor>());
45  for (int i = 0; i < numItems; ++i) {
46  // Here we do some ugly manipulations to the data to match the format
47  // of the output of the CLHEP put function (the whole point of this adaptor
48  // is to make TRandom3 work through the CLHEP interface as if it were a
49  // a CLHEP engine ...). In CLHEP, the vector returned by put contains
50  // unsigned long's, but these always contain only 32 bits of information.
51  // In the case of a 64 bit build the top 32 bits is only padding (all 0's).
52 
53  // Get the next 32 bits of data from the buffer
54  uint32_t value32 = *reinterpret_cast<uint32_t*>(bufferPtr + i * itemSize);
55 
56  if (i == numItems - 1) {
57  int nBytes = buffer.Length() % itemSize;
58  if (nBytes == 1)
59  value32 &= 0xffu;
60  else if (nBytes == 2)
61  value32 &= 0xffffu;
62  else if (nBytes == 3)
63  value32 &= 0xffffffu;
64  }
65 
66  // Push it into the vector in an unsigned long which may be 32 or 64 bits
67  v.push_back(static_cast<unsigned long>(value32));
68  }
69  return v;
70  }

References edmScanValgrind::buffer, mps_fire::i, trand_, and findQualityFiles::v.

◆ put() [2/2]

std::ostream & edm::TRandomAdaptor::put ( std::ostream &  os) const
override

Definition at line 29 of file TRandomAdaptor.cc.

29  {
30  Grumble(std::string("put(std::ostream) not available for TRandom engines"));
31  return os;
32  }

References Grumble(), and AlCaHLTBitMon_QueryRunRegistry::string.

◆ restoreStatus()

void edm::TRandomAdaptor::restoreStatus ( char const  filename[] = "TRandom.conf")
inlineoverride

Definition at line 41 of file TRandomAdaptor.h.

41 { trand_->ReadRandom(filename); }

References corrVsCorr::filename, and trand_.

◆ saveStatus()

void edm::TRandomAdaptor::saveStatus ( char const  filename[] = "TRandom.conf") const
inlineoverride

Definition at line 38 of file TRandomAdaptor.h.

38 { trand_->WriteRandom(filename); }

References corrVsCorr::filename, and trand_.

◆ setSeed()

void edm::TRandomAdaptor::setSeed ( long  seed,
int   
)
override

Definition at line 72 of file TRandomAdaptor.cc.

72  {
73  trand_->SetSeed(seed);
74  theSeed = trand_->GetSeed();
75  }

References fileCollector::seed, and trand_.

◆ setSeeds()

void edm::TRandomAdaptor::setSeeds ( long const *  seeds,
int   
)
override

Definition at line 79 of file TRandomAdaptor.cc.

79  {
80  trand_->SetSeed(seeds[0]);
81  theSeed = trand_->GetSeed();
82  }

References InitialStep_cff::seeds, and trand_.

◆ showStatus()

void edm::TRandomAdaptor::showStatus ( ) const
inlineoverride

Definition at line 44 of file TRandomAdaptor.h.

44 { trand_->Dump(); }

References trand_.

Member Data Documentation

◆ trand_

TRandom3Ptr edm::TRandomAdaptor::trand_
mutableprivate
mps_fire.i
i
Definition: mps_fire.py:428
edm::TRandomAdaptor::get
std::istream & get(std::istream &is) override
Definition: TRandomAdaptor.cc:84
findQualityFiles.v
v
Definition: findQualityFiles.py:179
edm::Exception
Definition: EDMException.h:77
edmScanValgrind.buffer
buffer
Definition: edmScanValgrind.py:171
fileCollector.seed
seed
Definition: fileCollector.py:127
corrVsCorr.filename
filename
Definition: corrVsCorr.py:123
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::TRandomAdaptor::Grumble
void Grumble(std::string const &errortext) const
Definition: TRandomAdaptor.cc:118
edm::TRandomAdaptor::getState
std::istream & getState(std::istream &is) override
Definition: TRandomAdaptor.cc:89
edm::errors::UnimplementedFeature
Definition: EDMException.h:38
findQualityFiles.size
size
Write out results.
Definition: findQualityFiles.py:443