Generating hash using the object content

Hi, I like to store object in a file and associate to them an hash. The hash should depends from the object content, just to have a fast check to know if two objects are equivalent or not.

The idea I thought is this:

class MyObj : public TObject {
ULong_t _id;
double val1;
double val2;

void genHash() {
_id = TString::Hash(&val1,sizeof(double)*2);

MyObj() : val1(0), val2(0) {

void set1(double v) { val1 = v; genHash(); }
void set2(double v) { val2 = v; genHash(); }
double get1() { return val1; }
double get2() { return val2; }

ULong_t getID() const{ return _id; }


But I like to know if there is an automatic way to produce hashes in ROOT in the way I like or other ideas.

many thanks, Guido[/code]


I would calculate the hash on a buffer filled by ROOT’s I/O facility, instead of an object’s memory address. That way you can be sure to

  • be platform independent,
  • do a deep comparison (if two objects contain a pointer to different addresses, but all objects are identical it will still result in identical IDs)
  • not compare “irrelevant” memory, like the possibly uninitialized padding between an object’s members.

Cheers, Axel.