TParameter(str) doesn't exist

Hi,

I’m using ROOT v. 5.34.02. I can create TParameters from numeric types with no problems. However, if I attempt to make one for a string, I get an error:

$ python
>>> import ROOT
>>> p = ROOT.TParameter(str)("p", "paramval")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "ROOT.py", line 179, in __call__
    result = _root.MakeRootTemplateClass( *newargs )
AttributeError: type object 'ROOT' has no attribute 'TParameter<std::string>'

Apparently the translation str -> std::stringis happening correctly, but it points to nowhere. Is there a known solution for this?

Thanks!

Hi,

normally I’d say that you’ll need to generate a dictionary for it, as the standard set in core/base contains only these:LinkDef3.h:#pragma link C++ class TParameter<Bool_t>+; LinkDef3.h:#pragma link C++ class TParameter<Float_t>+; LinkDef3.h:#pragma link C++ class TParameter<Double_t>+; LinkDef3.h:#pragma link C++ class TParameter<Int_t>+; LinkDef3.h:#pragma link C++ class TParameter<Long_t>+; LinkDef3.h:#pragma link C++ class TParameter<Long64_t>+;
However, as it happens, TParameterstd::string can not be instantiated b/c this snippet in TParameter.h:fVal *= c->GetVal(); will fail to compile for std::string, as std::string can not be used with ‘*=’.

Cheers,
Wim

Okay, that’s fair enough. But is there some alternative? What about using a TString instead of std::string? I don’t know how to generate the necessary dictionary – but would that work? (And if so, how would I get the dictionary?)

Thanks!

Hi,

well, you’re going to need some way of defining ‘=’ for your string class of choice, and TString does not either. You could derive your own custom class from TString, implement '=’ for it and then use that, or define a global overload for TString or std::string with some definition. Alternatively, you could specialize TParameter where you leave out that one method. But at some point, is TParameter the right choice for the use that you have in mind?

To generate a dictionary, see here for rootcint, or use the equivalent of:ROOT.gInterpreter.GenerateDictionary('TParameter<std::string>', 'TParameter.h;string')
Cheers,
Wim

Hi Wim,

Thanks for the details.

It might not be. I’m open to suggestions. Basically, I just want a simple “TNamed”-type object that contains a string where the name and the contained string can be different (TString uses the string content as its name as well). Any ideas would be helpful!

Hi,

looking at the data members of TNamed, then AFAICS, TParameter and TNamed have the same level of complexity (two TString data members, both derived from TObject, many of the public methods are the same). What part is missing in TNamed for your use?

Cheers,
Wim