Hi. How can I compare two TTree with hash?
I generate two TTree with simulation which are should be the same.
I would like to compare these equality.
In this question (21204), the function has been discussed and I found that the implemented solutions.
However, they are a little bit much and it is general for all TObject. My target is only TTree.
Can I compare them with handy way for example calculating their hash?
First of all, welcome to the ROOT forum!
Regarding your question, @pcanal might correct me, but I think that there’s no direct way of doing that.
Also, see these two forum topics with more information/suggestions: Comparing ROOT TTrees, and What is the most efficient way to compare the content of two entries in a TTree?.
Hi, thank you for your reply, @jalopezg .
First suggestion is a bit trick. As you know,
TTree::Scan() require user input. I guess I need to execute some ROOT script in the shell script like
yes q | root -l -b -q 'dump.C etc. It isn’t closed in C++. Moreover, it Is hard to Scan all the entry for huge file because of performance issue.
Second one shows nice implementations. As I said, they are a little bit huge thus not match for my small project.
You are very welcome, @mzks!
Actually, I cannot come up with anything else other than manually comparing the TTree schemas and the data stored in each branch. Maybe @pcanal can suggest something else here.
We do not calculate a hash for the content of a TTree (and extracting the non variable information would be more costly that you hope for). One thing you could do is to use the new TFile feature: ROOT: TFile Class Reference
A bit TFile::kReproducible can be enabled specifying the "reproducible" url option when creating the file:
TFile *f = TFile::Open("name.root?reproducible","RECREATE","File title");
Unlike regular TFiles, the content of such file has reproducible binary content when writing exactly same data. This achieved by writing pre-defined values for creation and modification date of TKey/TDirectory objects and null value for TUUID objects inside TFile. As drawback, TRef objects stored in such file cannot be read correctly.
In case the name of the file is not reproducible either (in case of creating temporary filenames) a value can be passed to the reproducible option to replace the name stored in the file.
TFile *f = TFile::Open("tmpname.root?reproducible=fixedname","RECREATE","File title");
Hi @pcanal, @jalopezg thank you very much for your responses.
kReproducible is nice. I’m very happy to know this new feature. I will try to calculate binary hash to.compare two file.
Unfortunately, my files include some parameters not to compare.
Thus, I use these dirty solution.
- make binary to read TTree and TTree::Scan()
- on the shell script,
yes q | ./the_binary
- redirect the shell script to file
./the_script.sh >> dump1.txt
- compare the dumped file
diff dump1.txt dump2.txt
- on cmake (ctest), add_test(diff COMMAND sh -c “diff dump1.txt dump2.txt”)
Then, I could not compare all TTree but at least I could check the initial ~30 lines are the same.
Thank you very much for your help.
root -b -q -l -e 'TTree *t; (TFile::Open("your_file_name.root"))->GetObject("your_tree_name", t); t->SetScanField(0); t->Scan("*");' > scan.out.txt
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.