Repeatedly get and save TH2D in TFile

Dear ROOTers,

How can I repeatedly get all the TH2D objects (with known names) from a file, alter them and then append them again in the same file?

I tried many things, but nothing worked out sofar.

for i in indices:
if file.FindObjectAnyFile(“my_object”) == None:
hist = ROOT.TH2F(“my_object”,…)
hist = file.get(“my_object”)



Why does this not work?


is the file opened in “UPDATE”? Otherwise, better to post in the ROOT Support forum, as this question isn’t PyROOT specific (and outside my limited knowledge).



Do you mean to over-ride the old content and add it along side the old content (it is to over-ride, is writting a new file an option?)?

hist.Append("my_object") Why does this not work?How does it fail? … humm actually what do you mean by it (do you really mean to try to append a string to the histogram?) … the closest I can think of that you might mean is :file.Append(hist) which is already implied (any histogram read from a TFile is already Appended/attached to the TFile).