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::ostream & put (std::ostream &os) const override
 
std::vector< unsigned long > put () 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 (long seed)
 
 TRandomAdaptor (int rowIndex, int colIndex)
 
 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.

References trand_.

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

◆ TRandomAdaptor() [2/4]

edm::TRandomAdaptor::TRandomAdaptor ( long  seed)

Definition at line 18 of file TRandomAdaptor.cc.

References trand_.

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

◆ TRandomAdaptor() [3/4]

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

Definition at line 19 of file TRandomAdaptor.cc.

References trand_.

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

◆ TRandomAdaptor() [4/4]

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

Definition at line 23 of file TRandomAdaptor.cc.

References Grumble(), and AlCaHLTBitMon_QueryRunRegistry::string.

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

◆ ~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.

References AlCaHLTBitMon_QueryRunRegistry::string, and trand_.

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

◆ engineName()

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

Definition at line 59 of file TRandomAdaptor.h.

References AlCaHLTBitMon_QueryRunRegistry::string.

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

◆ flat()

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

Definition at line 25 of file TRandomAdaptor.h.

References trand_.

25 { return trand_->Rndm(); }

◆ flatArray()

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

Definition at line 28 of file TRandomAdaptor.h.

References trand_.

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

◆ 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.

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().

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  }

◆ getRootEngine()

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

Definition at line 66 of file TRandomAdaptor.h.

References trand_.

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

◆ getState() [1/2]

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

Definition at line 89 of file TRandomAdaptor.cc.

References Grumble(), and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by get().

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

◆ getState() [2/2]

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

Definition at line 63 of file TRandomAdaptor.h.

References findQualityFiles::v.

63 { return get(v); }

◆ Grumble()

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

Definition at line 118 of file TRandomAdaptor.cc.

References edm::errors::UnimplementedFeature.

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

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

◆ name()

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

◆ operator float()

edm::TRandomAdaptor::operator float ( )
inlineoverride

Definition at line 47 of file TRandomAdaptor.h.

References trand_.

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

◆ operator unsigned int()

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

Definition at line 50 of file TRandomAdaptor.h.

References trand_.

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

◆ put() [1/2]

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

Definition at line 29 of file TRandomAdaptor.cc.

References Grumble(), and AlCaHLTBitMon_QueryRunRegistry::string.

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

◆ put() [2/2]

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

Definition at line 34 of file TRandomAdaptor.cc.

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

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  }

◆ restoreStatus()

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

Definition at line 41 of file TRandomAdaptor.h.

References corrVsCorr::filename, and trand_.

41 { trand_->ReadRandom(filename); }

◆ saveStatus()

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

Definition at line 38 of file TRandomAdaptor.h.

References corrVsCorr::filename, and trand_.

38 { trand_->WriteRandom(filename); }

◆ setSeed()

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

Definition at line 72 of file TRandomAdaptor.cc.

References fileCollector::seed, and trand_.

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

◆ setSeeds()

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

Definition at line 79 of file TRandomAdaptor.cc.

References HLT_2024v12_cff::seeds, and trand_.

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

◆ showStatus()

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

Definition at line 44 of file TRandomAdaptor.h.

References trand_.

44 { trand_->Dump(); }

Member Data Documentation

◆ trand_

TRandom3Ptr edm::TRandomAdaptor::trand_
mutableprivate