jgomez2
September 1, 2016, 6:01pm
1
I know I goofed up, never put semicolon in histogram names.
What I did:
char histname[128];
char newname[128];
sprintf(histname,"SomeName;1");
TH2 *myHist = (TH2*) gDirectory->FindObjectAny(histname);
sprintf(newname,"SomeNewName;1");
myHist->SetName(newname);
myHist->Write(newname,TObject::kWriteDelete);
gDirectory->Delete(histname);
the problem is i accidentally forgot the “;1” in the newname, and now it is not letting me access the histograms from the command line so I can change them back. Can anyone help?
couet
September 2, 2016, 4:32am
2
jgomez2
September 2, 2016, 1:15pm
3
Hi couet,
Regrettably this did not work. The key was returned as null
jgomez2
September 2, 2016, 3:10pm
4
Hi all,
It was kind of like that tutorial, he had to make some tweaks but this is how one of my colleagues fixed the issue.
TFile* f = TFile::Open( fName, "update");
if (!f->cd( dirName)) continue;
TIter nextKey (gDirectory->GetListOfKeys());
TKey* key;
while (key = (TKey*)nextKey(), key) {
string oldName = key->GetName();
size_t oldLocation = oldName.find( oldPattern);
if (oldLocation == string::npos) continue;
string newName (oldName);
newName.replace( oldLocation, oldPatternLength, newPattern);
cout << setw(38) << oldName << " "
<< setw(38) << newName << " "
<< endl;
TObject* oldObj = key->ReadObj();
oldObj->Clone( newName.c_str());
gDirectory->Delete( (oldName+";*").c_str());
}
f->Write();
f->Close();