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
 
virtual std::istream & get (std::istream &is) override
 
bool get (std::vector< unsigned long > const &v) override
 
TRandom3 * getRootEngine ()
 
virtual 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
 
virtual std::ostream & put (std::ostream &os) const override
 
virtual 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)
 
virtual ~TRandomAdaptor ()
 

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

Definition at line 16 of file TRandomAdaptor.h.

Constructor & Destructor Documentation

edm::TRandomAdaptor::TRandomAdaptor ( )

Definition at line 17 of file TRandomAdaptor.cc.

References trand_.

17  : trand_(new TRandom3()) {
18  theSeed = trand_->GetSeed();
19 }
edm::TRandomAdaptor::TRandomAdaptor ( long  seed)

Definition at line 20 of file TRandomAdaptor.cc.

References trand_.

20  : trand_(new TRandom3(seed)) {
21  theSeed = trand_->GetSeed();
22 }
edm::TRandomAdaptor::TRandomAdaptor ( int  rowIndex,
int  colIndex 
)

Definition at line 23 of file TRandomAdaptor.cc.

References trand_.

23  : trand_(new TRandom3(rowIndex*colIndex-1)) {
24  theSeed = trand_->GetSeed();
25 }
edm::TRandomAdaptor::TRandomAdaptor ( std::istream &  is)

Definition at line 27 of file TRandomAdaptor.cc.

References Grumble(), and AlCaHLTBitMon_QueryRunRegistry::string.

27  {
28  Grumble(std::string("Cannot instantiate a TRandom engine from an istream"));
29 }
void Grumble(std::string const &errortext) const
edm::TRandomAdaptor::~TRandomAdaptor ( )
virtual

Definition at line 31 of file TRandomAdaptor.cc.

31  {
32 }

Member Function Documentation

std::string edm::TRandomAdaptor::beginTag ( )
inline
static std::string edm::TRandomAdaptor::engineName ( )
inlinestatic
double edm::TRandomAdaptor::flat ( void  )
inlineoverride

Definition at line 26 of file TRandomAdaptor.h.

References trand_.

26 { return trand_->Rndm(); }
void edm::TRandomAdaptor::flatArray ( int const  size,
double *  vect 
)
inlineoverride

Definition at line 29 of file TRandomAdaptor.h.

References SurveyInfoScenario_cff::seed, setSeed(), setSeeds(), and trand_.

29 { trand_->RndmArray(size,vect); }
size
Write out results.
std::istream & edm::TRandomAdaptor::get ( std::istream &  is)
overridevirtual
bool edm::TRandomAdaptor::get ( std::vector< unsigned long > const &  v)
override

Definition at line 98 of file TRandomAdaptor.cc.

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

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

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

Definition at line 67 of file TRandomAdaptor.h.

References Grumble(), AlCaHLTBitMon_QueryRunRegistry::string, and trand_.

67 { return trand_.operator->(); }
std::istream & edm::TRandomAdaptor::getState ( std::istream &  is)
overridevirtual

Definition at line 93 of file TRandomAdaptor.cc.

References Grumble(), and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by beginTag(), and get().

93  {
94  Grumble(std::string("getState(std::istream) not available for TRandom engines"));
95  return is;
96 }
void Grumble(std::string const &errortext) const
bool edm::TRandomAdaptor::getState ( std::vector< unsigned long > const &  v)
inlineoverride

Definition at line 64 of file TRandomAdaptor.h.

References findQualityFiles::v.

64 { return get(v); }
void edm::TRandomAdaptor::Grumble ( std::string const &  errortext) const
private

Definition at line 121 of file TRandomAdaptor.cc.

References edm::errors::UnimplementedFeature.

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

121  {
122 
123 // Throw an edm::Exception for unimplemented functions
124  std::ostringstream sstr;
125  sstr << "Unimplemented Feature: " << errortext << '\n';
127  throw except;
128 }
std::string edm::TRandomAdaptor::name ( void  ) const
inlineoverride
edm::TRandomAdaptor::operator float ( )
inlineoverride

Definition at line 48 of file TRandomAdaptor.h.

References trand_.

48 { return (float)(trand_->Rndm()); }
edm::TRandomAdaptor::operator unsigned int ( )
inlineoverride

Definition at line 51 of file TRandomAdaptor.h.

References put(), and trand_.

51 { return (unsigned int)((trand_->Rndm())*exponent_bit_32()); }
std::ostream & edm::TRandomAdaptor::put ( std::ostream &  os) const
overridevirtual

Definition at line 34 of file TRandomAdaptor.cc.

References Grumble(), and AlCaHLTBitMon_QueryRunRegistry::string.

34  {
35  Grumble(std::string("put(std::ostream) not available for TRandom engines"));
36  return os;
37 }
void Grumble(std::string const &errortext) const
std::vector< unsigned long > edm::TRandomAdaptor::put ( ) const
overridevirtual

Definition at line 39 of file TRandomAdaptor.cc.

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

Referenced by engineName(), and operator unsigned int().

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

Definition at line 42 of file TRandomAdaptor.h.

References corrVsCorr::filename, and trand_.

42 { trand_->ReadRandom(filename); }
void edm::TRandomAdaptor::saveStatus ( char const  filename[] = "TRandom.conf") const
inlineoverride

Definition at line 39 of file TRandomAdaptor.h.

References corrVsCorr::filename, and trand_.

39 { trand_->WriteRandom(filename); }
void edm::TRandomAdaptor::setSeed ( long  seed,
int   
)
override

Definition at line 75 of file TRandomAdaptor.cc.

References trand_.

Referenced by flatArray().

75  {
76  trand_->SetSeed(seed);
77  theSeed = trand_->GetSeed();
78 }
void edm::TRandomAdaptor::setSeeds ( long const *  seeds,
int   
)
override

Definition at line 82 of file TRandomAdaptor.cc.

References trand_.

Referenced by flatArray().

82  {
83  trand_->SetSeed(seeds[0]);
84  theSeed = trand_->GetSeed();
85 }
void edm::TRandomAdaptor::showStatus ( ) const
inlineoverride

Definition at line 45 of file TRandomAdaptor.h.

References trand_.

45 { trand_->Dump(); }

Member Data Documentation

TRandom3Ptr edm::TRandomAdaptor::trand_
mutableprivate