4 #include "CLHEP/Random/engineIDulong.h"
6 #include "TBufferFile.h"
18 Grumble(std::string(
"Cannot instantiate a TRandom engine from an istream"));
25 Grumble(std::string(
"put(std::ostream) not available for TRandom engines"));
30 std::vector<unsigned long>
v;
32 int32_t itemSize =
sizeof(uint32_t);
33 TBufferFile buffer(TBuffer::kWrite, 2048 * itemSize);
36 char* bufferPtr = buffer.Buffer();
37 int32_t numItems = (buffer.Length() + itemSize - 1) / itemSize;
38 v.reserve(numItems + 1);
39 v.push_back (CLHEP::engineIDulong<TRandomAdaptor>());
40 for(
int i = 0;
i < numItems; ++
i) {
50 uint32_t value32 = *
reinterpret_cast<uint32_t *
>(bufferPtr +
i * itemSize);
52 if (
i == numItems - 1) {
53 int nBytes = buffer.Length() % itemSize;
54 if (nBytes == 1) value32 &= 0xffu;
55 else if (nBytes == 2) value32 &= 0xffffu;
56 else if (nBytes == 3) value32 &= 0xffffffu;
60 v.push_back(static_cast<unsigned long>(value32));
66 Grumble(std::string(
"get(std::istream) not available for TRandom engines"));
71 Grumble(std::string(
"getState(std::istream) not available for TRandom engines"));
76 if(v.empty())
return false;
77 if(v[0] != CLHEP::engineIDulong<TRandomAdaptor>())
return false;
78 int32_t numItems = v.size()-1;
80 int32_t itemSize =
sizeof(uint32_t);
81 TBufferFile buffer(TBuffer::kRead, numItems * itemSize + 1024);
82 char* bufferPtr = buffer.Buffer();
83 for(int32_t
i = 0;
i < numItems; ++
i) {
85 *
reinterpret_cast<uint32_t *
>(bufferPtr +
i * itemSize) = static_cast<uint32_t>(v[
i+1] & 0xffffffff);
101 std::ostringstream sstr;
102 sstr <<
"Unimplemented Feature: " << errortext <<
'\n';
std::vector< unsigned long > put() const
virtual std::istream & getState(std::istream &is)
virtual std::istream & get(std::istream &is)
virtual ~TRandomAdaptor()
void Grumble(std::string const &errortext) const