Saving a string variable in a root file

Hello,

I’d like to automate some things in my analysis. This would require a python script to save a string type variable to a ROOT file (along with other things, those are already implemented), so that later another script can open the ROOT file, and can get the value of this string via TFile.Get()

I’ve seen that we have TString and TObjString, however, if I understand correctly, these just save a string into the ROOT file. Whereas I would need a name-string pair to be saved, so that the saved string has a name I can reference it with, to use with TFile.Get().
For example in pseudocode:

# first python script
hfile = ROOT.TFile( 'output.root', 'RECREATE')
parameter17 = "DtWrtPVMax9999"
---> need a way here to save parameter17 and its stored value into the root file. 


# So that a later python script can then do:
hfile = ROOT.TFile.Open( 'output.root')
parameter17 = hfile.Get("parameter17")

print(parameter17)   ---> gives "DtWrtPVMax9999"

I assume it’s always an option to just use some sort of simple external container file to write/read these string parameters, but if possible, it may be better to have them inside the ROOT files. (Other things are stored in it as well that are written/read alongside the string, so it would be good to have everything in one place).

Is this possible to do somehow, with TObjString or TString? The problem is that I don’t see how, due to them being stored as just the string, and not a name - string pair. Or is there perhaps another way?

Thank you

Try searching for examples on this forum.
E.g. String in a ROOT file

root [0] TNamed n("myname","mystring"); TFile f("junk.root","recreate"); n.Write();
root [1] .ls
TFile**         junk.root
 TFile*         junk.root
  KEY: TNamed   myname;1        mystring
root [2] f.Get("myname")
(TObject *) 0x55c8b4614420
root [3] myname->GetTitle()
(const char *) "mystring"