Problems with changing the name of collectable string class in a root file

Hello everyone,
I get a problem in changing the name of collectabe string class in a root file. My root file, which is called ZJetsToNuNu_HT1200To2500_ext1.root, has the following structure:

I would like to change the name of the the first item named “tag” into “untagged”. When I point to it is says that item is a collectable string class. How can I change the name of it and save into a new root file?

I have tried like,

TFile *f = new TFile("ZJetsToNuNu_HT1200To2500_ext1.root", "update");
TObjString *tag;
f->GetObject("tag", tag)
tag->SetString("untagged");
f->Write();

However, it does not change anything.


ROOT Version (5.34/36):


Best wishes,
Bengy

Hi @bengy,

Can you try adding tag->Write() before f->Write() ?

Cheers,

Enric

Hi @etejedor,
It creates a new TObjString with “untagged” now, but the original “tag” is still there.
Best,
Bengy

Hi @bengy,

Can you try to delete the old “tag” by using TFile::Delete:

Please also check the method documentation here:

https://root.cern.ch/doc/v612/classTFile.html#a1b1c78f1d20439291bb52f2217c382f7

Cheers,

Enric

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