bengy
April 30, 2018, 1:26am
#1
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
bengy
April 30, 2018, 5:56pm
#3
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
:
[quote]Q2. After closing and reopening the file the ls() changes and no
directory is shown.[/quote] humm … f.Open("test.root", "READ");Does NOT affect the object ‘j’ because TFile::Open is a static function that allocates and return a new object. i.e. TFile *f2 TFile::Open("test.root", "READ");
f2->ls();
f2->Close();will work better.
Cheers,
Philippe.
Please also check the method documentation here:
https://root.cern.ch/doc/v612/classTFile.html#a1b1c78f1d20439291bb52f2217c382f7
Cheers,
Enric
system
closed
May 15, 2018, 6:30pm
#5
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.