Generate a file identifier or hash


I want to get a file identifier or hash from a file. I somehow believe I found what I need in TFile::TNamed.

If I do:

TFile *f = new TFile( "myFile.root");
root [2] f->Hash()
(unsigned long) 594636882

I get a value that seems to be the identifier. This number seems to be a 32-bits number. Will this Hash method provide a unique identifier? What is the probability 2 different files will produce the same hash. But worst, in a database with 10,000 files (for example) what will be the probability that any pair of files will share a common hash?

It seems 32-bits depth in this hash will not be enough, since this translates to just 4x10^9 values.

So, can I rely on this hash to get a unique identifier of my file in a file database?

Or, there is a more sophisticated way to do this in ROOT?

What you want is probably the UUID in the file itself. See the documentation for TFile, and look for fUUID there.

1 Like

Thanks, that looks more like what I am looking for.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.