CMS 3D CMS Logo

Public Types | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes

edm::TRandomAdaptor Class Reference

#include <TRandomAdaptor.h>

List of all members.

Public Types

typedef value_ptr< TRandom3 > TRandom3Ptr

Public Member Functions

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

Definition at line 19 of file TRandomAdaptor.h.

: trand_(new TRandom3()) {}
edm::TRandomAdaptor::TRandomAdaptor ( long  seed) [inline]

Definition at line 20 of file TRandomAdaptor.h.

: trand_(new TRandom3(seed)) {}
edm::TRandomAdaptor::TRandomAdaptor ( int  rowIndex,
int  colIndex 
) [inline]

Definition at line 21 of file TRandomAdaptor.h.

: trand_(new TRandom3(rowIndex*colIndex-1)) {}
edm::TRandomAdaptor::TRandomAdaptor ( std::istream &  is)

Definition at line 17 of file TRandomAdaptor.cc.

References Grumble().

                                          {
  Grumble(std::string("Cannot instantiate a TRandom engine from an istream"));
}
edm::TRandomAdaptor::~TRandomAdaptor ( ) [virtual]

Definition at line 21 of file TRandomAdaptor.cc.

                                {
}

Member Function Documentation

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

Definition at line 55 of file TRandomAdaptor.h.

References trand_.

{ return std::string(trand_->GetName())+std::string("-begin"); }
static std::string edm::TRandomAdaptor::engineName ( ) [inline, static]

Definition at line 60 of file TRandomAdaptor.h.

{ return std::string("TRandomAdaptor"); }
double edm::TRandomAdaptor::flat ( void  ) [inline]

Definition at line 26 of file TRandomAdaptor.h.

References trand_.

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

Definition at line 29 of file TRandomAdaptor.h.

References trand_.

{ trand_->RndmArray(size,vect); }
bool edm::TRandomAdaptor::get ( std::vector< unsigned long > const &  v)

Definition at line 75 of file TRandomAdaptor.cc.

References i, and trand_.

                                                          {
  if(v.empty())  return false;
  if(v[0] != CLHEP::engineIDulong<TRandomAdaptor>()) return false;
  int32_t numItems = v.size()-1;

  int32_t itemSize = sizeof(uint32_t);
  TBufferFile buffer(TBuffer::kRead, numItems * itemSize + 1024);
  char* bufferPtr = buffer.Buffer();
  for(int32_t i = 0; i < numItems; ++i) {

    *reinterpret_cast<uint32_t*>(bufferPtr + i * itemSize) = static_cast<uint32_t>(v[i+1] & 0xffffffff);
  }

  // Note that this will fail if the TRandom3 version (specifically the TStreamerInfo)
  // has changed between the time the state was saved and the time the following call
  // is made.  Because we are manually calling the Streamer function, the original
  // TStreamerInfo is not saved anywhere. Normally ROOT saves the TStreamerInfo
  // automatically.
  trand_->Streamer(buffer);

  return true;
}
std::istream & edm::TRandomAdaptor::get ( std::istream &  is) [virtual]

Definition at line 65 of file TRandomAdaptor.cc.

References getState(), and Grumble().

                                              {
  Grumble(std::string("get(std::istream) not available for TRandom engines"));
  return getState(is);
}
TRandom3* edm::TRandomAdaptor::getRootEngine ( ) [inline]

Definition at line 67 of file TRandomAdaptor.h.

References trand_.

{ return trand_.operator->(); }
bool edm::TRandomAdaptor::getState ( std::vector< unsigned long > const &  v) [inline]

Definition at line 64 of file TRandomAdaptor.h.

References v.

{ return get(v); }
std::istream & edm::TRandomAdaptor::getState ( std::istream &  is) [virtual]

Definition at line 70 of file TRandomAdaptor.cc.

References Grumble().

Referenced by get().

                                                   {
  Grumble(std::string("getState(std::istream) not available for TRandom engines"));
  return is;
}
void edm::TRandomAdaptor::Grumble ( std::string const &  errortext) const [private]

Definition at line 98 of file TRandomAdaptor.cc.

References except, and edm::errors::UnimplementedFeature.

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

                                                             {

// Throw an edm::Exception for unimplemented functions
   std::ostringstream sstr;
   sstr << "Unimplemented Feature: " << errortext << '\n';
   edm::Exception except(edm::errors::UnimplementedFeature, sstr.str());
   throw except;
}
std::string edm::TRandomAdaptor::name ( void  ) const [inline]

Definition at line 59 of file TRandomAdaptor.h.

References trand_.

{ return std::string("T")+std::string(trand_->GetName()); }
edm::TRandomAdaptor::operator float ( ) [inline]

Definition at line 48 of file TRandomAdaptor.h.

References trand_.

{ return (float)(trand_->Rndm()); }
edm::TRandomAdaptor::operator unsigned int ( ) [inline]

Definition at line 51 of file TRandomAdaptor.h.

References trand_.

{ return (unsigned int)((trand_->Rndm())*exponent_bit_32); }
std::vector< unsigned long > edm::TRandomAdaptor::put ( ) const

Definition at line 29 of file TRandomAdaptor.cc.

References i, trand_, and v.

                                                   {
  std::vector<unsigned long> v;

  int32_t itemSize = sizeof(uint32_t);
  TBufferFile buffer(TBuffer::kWrite, 2048 * itemSize);
  trand_->Streamer(buffer);
  buffer.SetReadMode();
  char* bufferPtr = buffer.Buffer();
  int32_t numItems = (buffer.Length() + itemSize - 1) / itemSize;
  v.reserve(numItems + 1);
  v.push_back(CLHEP::engineIDulong<TRandomAdaptor>());
  for(int i = 0; i < numItems; ++i) {

    // Here we do some ugly manipulations to the data to match the format
    // of the output of the CLHEP put function (the whole point of this adaptor
    // is to make TRandom3 work through the CLHEP interface as if it were a
    // a CLHEP engine ...).  In CLHEP, the vector returned by put contains
    // unsigned long's, but these always contain only 32 bits of information.
    // In the case of a 64 bit build the top 32 bits is only padding (all 0's).

    // Get the next 32 bits of data from the buffer
    uint32_t value32 = *reinterpret_cast<uint32_t*>(bufferPtr + i * itemSize);

    if(i == numItems - 1) {
      int nBytes = buffer.Length() % itemSize;
      if(nBytes == 1) value32 &= 0xffu;
      else if(nBytes == 2) value32 &= 0xffffu;
      else if(nBytes == 3) value32 &= 0xffffffu;
    }

    // Push it into the vector in an unsigned long which may be 32 or 64 bits
    v.push_back(static_cast<unsigned long>(value32));
  }
  return v;
}
std::ostream & edm::TRandomAdaptor::put ( std::ostream &  os) const [virtual]

Definition at line 24 of file TRandomAdaptor.cc.

References Grumble().

                                                    {
  Grumble(std::string("put(std::ostream) not available for TRandom engines"));
  return os;
}
void edm::TRandomAdaptor::restoreStatus ( char const  filename[] = "TRandom.conf") [inline]

Definition at line 42 of file TRandomAdaptor.h.

References lut2db_cfg::filename, and trand_.

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

Definition at line 39 of file TRandomAdaptor.h.

References lut2db_cfg::filename, and trand_.

{ trand_->WriteRandom(filename); }
void edm::TRandomAdaptor::setSeed ( long  seed,
int   
) [inline]

Definition at line 32 of file TRandomAdaptor.h.

References trand_.

{ trand_->SetSeed(seed); }
void edm::TRandomAdaptor::setSeeds ( long const *  seeds,
int   
) [inline]

Definition at line 36 of file TRandomAdaptor.h.

References trand_.

{ trand_->SetSeed(seeds[0]); }
void edm::TRandomAdaptor::showStatus ( ) const [inline]

Definition at line 45 of file TRandomAdaptor.h.

References trand_.

{ trand_->Dump(); }

Member Data Documentation