Dear experts,
I’m trying to change the name of a TObjString
after it was created:
Just by doing this is not working:
fTObjString->Write("foobar", TObject::kOverwrite);
meaning, by assigning a name during the Writing process
I’ve also tried this:
TObjString* tmp = (TObjString*)fTObjString->Clone("foobar");
delete fTObjString;
fTObjString = tmp;
fTObjString->Write("foobar", TObject::kOverwrite);
but none of the mentioned solutions works.
The object dumped on disk still has the name assigned by default, which is 0
Can you please suggest a workaround?
Mauro.
ROOT Version: 6.24.6
Platform: CENTOS7
Compiler: c++ (GCC) 10.2.1
couet
February 12, 2024, 7:19am
2
Reading the doc it seems that SetString might be what you are looking for.
Hi,
that’s the TString content, not the Object name.
They are two different things
couet
February 12, 2024, 8:50am
4
I know, but TObjString does not inherits from TNamed. And look at the GetName
method here: ROOT: core/base/inc/TObjString.h Source File
It returns fString
OK,
so, if I use SetString
I do set the name of the object and the string content,
which should be two different things.
The other strange thing is that when I save the object in the root file I get the right content and the right name displayed on the TBrowser
:
D_ITEndOfCalib_Board(0)
But when I read the root file with TBrowser
and I Dump the content the TStringObject
has the name = “1”, not the one displayed in the TBrowser
I don’t know if I was clear.
There are two mysteries:
the Object
name and TString
content should be handled differently, they are not the same thing
the TBrowser
somehow seems to read things properly, but if I Dump()
the content of the object the TString
content and the Object
name are the same, and equal to “1”
couet
February 12, 2024, 9:26am
6
As it seems related to IO and TBrowser, may be @pcanal and @bellenot may have an idea about it.
Hi,
do you guys have any news on this subject?
I’ll take a look, but not before Thursday or Friday. But I think the browser get the name from the TKey, not from TObjString
Hi @bellenot , ok many thanks.
Let me make just one further comment: if it is as you say, how can I copy a TObjString
from a TFile
to another TFile
and have the name appear on the TBrowser
?
Right now I’m using this code:
inputDir->cd();
TObject* newO = key->ReadObj();
outputDir->cd();
newO->Write();
delete newO;
Many thanks again.
Mauro.
Since it’s I/O, maybe @pcanal can give more details
I get this from the TFile
in which I copied the TObjString
.
To be compared with what I posted at the beginning which comes from the original TFile
Dear All,
I solved the problem by doing this:
inputDir->cd();
TObject* newO = key->ReadObj();
outputDir->cd();
newO->Write(key->GetName(), TObject::kOverwrite);
delete newO;
Cheers,
Mauro.
system
Closed
February 27, 2024, 1:47pm
13
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.