I imagine to sooner or later end up in trouble when I have +-/*()#[]<>% in a branch name.
I see that the following does not crash, raise exceptions, …
TTree* t = new TTree("mytree","treetitle")
float thefloat
t->Branch("foo+baz/bar",&thefloat)
Whether this behaviour is good or bad is not so much of what I’m concerned, I’m interested if there is a sanity checker existing already which validates if a TString (or std::string or const char*) is “safe for branch name usage”?
Or at least a list of things which I should check against (at programming time I don’t know what branch names I will encounter. In my program the name will come from argv)?
Spontaneously, I would check against the above list, a leading digit, and whitespaces.
The name of branch can ‘technically’ contains any ascii characters … however, as you point out, many of those characters can lead to problem when using most of the tools based on TTree (for example TTree::Draw).
The easiest definition is that one should restrict the name of the branch to be a valid C++ variable name, hence including the characters you mention and at least “.:” (and of course quotes). However, some experiment manage to successfull use a single “:” or “.” in the name in some circumstances.
for now I think I’ll allow only valid c++ variable names. We also have some “standard branches” with periods but I’ll not allow creating more of these in the app. So from cplusplus.com/reference/regex/regex_match/ I took as first check
On top of that I’ll black list a few keywords. I think I want to ensure that MakeClass creates more or less valid code and that Draw will not end up in a mess: TMath, cos, float, int, sin, abs, acos, atan, tan, asin, exp, log, double, class, static, inline, const, auto, Notify, Loop, max, min, new, delete, … github.com/pseyfert/tmva-branch … lacklist.h