Dear experts,TObjString  after it was created:
Just by doing this is not working:fTObjString->Write("foobar", TObject::kOverwrite); 
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.0
Can you please suggest a workaround?
ROOT Version:  6.24.6Platform:  CENTOS7Compiler:   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,
             
            
              
            
           
          
            
              
                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 fString
             
            
              
            
           
          
            
            
              OK,SetString I do set the name of the object and the string content,
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)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,
             
            
              
            
           
          
            
            
              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?
inputDir->cd();
TObject* newO = key->ReadObj();
outputDir->cd();
newO->Write();
delete newO;
Many thanks again.
             
            
              
            
           
          
            
            
              Since it’s I/O, maybe @pcanal  can give more details
             
            
              
            
           
          
            
            
              I get this from the TFile in which I copied the TObjString.TFile
             
            
              
            
           
          
            
            
              Dear All,
inputDir->cd();
TObject* newO = key->ReadObj();
outputDir->cd();
newO->Write(key->GetName(), TObject::kOverwrite);
delete newO;
Cheers,
             
            
              
            
           
          
            
              
                system  
              
                  
                    February 27, 2024,  1:47pm
                   
                  13 
               
             
            
              This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.