Description
When using rootcp --replace
, objects are only replaced if they are not equal to the existing object by value, which doesn't seem to makes sense to me.
Reproducer
Write some histograms:
// write_histo_files.C
void write_histo_file(double w1, double w2, std::string const &name)
{
std::string filename = name + ".root";
std::unique_ptr<TFile> file{TFile::Open(filename.c_str(), "RECREATE")};
TH1 *histo = new TH1D{"histo", "histo", 20, -4, 4};
histo->Fill(1.0, w1);
histo->Fill(1.0, w2);
histo->Write();
}
void write_histo_files()
{
// Same histograms
write_histo_file(1, 1., "source_same");
write_histo_file(1, 1, "target_same");
// Different histograms
write_histo_file(1.0, 1.0, "source_different");
write_histo_file(0.5, 0.5, "target_different");
}
Now run this script and use rootcp to merge the source with target files, and check the target files:
root -b -q write_histo_files.C
rootcp --replace source_same.root:histo target_same.root:histo
rootcp --replace source_different.root:histo target_different.root:histo
echo "Same histos:"
rootls -t target_same.root
echo "Different histos:"
rootls -t target_different.root
The output will be:
Same histos:
TH1D Jun 13 19:55 2025 histo;2 "histo" [current cycle]
TH1D Jun 13 19:55 2025 histo;1 "histo" [backup cycle]
Different histos:
TH1D Jun 13 19:55 2025 histo;1 "histo"
How does it make sense to write only a backup if the histograms were the same anyway, and otherwise not? This logic needs to be revisited I think:
https://github.com/root-project/root/blob/master/main/python/cmdLineUtils.py#L700
I think with the --replace
option, the object should always be replaced without no backup cycle, and that's actually how it was at some point. It is not clear to me why this behavior was changed in f25b6e5 ten years ago.
@dpiparo, do you maybe have a hint since you merged that commit?
This logical flaw becomes apparent now that histogram classes implement an equality operator via UHI. Before, the equality operator was falling back to pointer comparison, which always failed since the objects in the source and target files are different. Hence, the histogram object was always overwritten with no backup cycle.
Metadata
Metadata
Assignees
Type
Projects
Status