Error from TTree::Draw with forward slash in selection

I am having trouble to get the Draw function of a TTree to work when I am trying to use a forward slash in a string that I am trying to select with.
The situation is a bit complicated because the data set I am using has entries of type string which have quotation marks include, i.e. values are for example
Here is a simple example that fails:

auto t = new TTree("t", "t");
char c[50] = "\"/root\"";
t->Branch("l", c, "l/C");
char id[50] = "\"myId\"";
t->Branch("id", id, "id/C");
t->Draw("id", "l==\"\"/root\"\"");

@couet The last command with trying to select on the entry that is including a slash gives:
Error in TTreeFormula::Compile: Bad numerical expression : “root”""
Info in TSelectorDraw::AbortProcess: Variable compilation failed: {id,l==""/root""}

Am I doing something wrong here, do I have to try to escape the forward slash as well ?
Thanks a lot!

ROOT Version: 6.12/07
from Docker image


t->Draw("id", "l==\"\"/root\"\""); // Why the forward slash?

the code see the string l==""/root"", so technically you need:

t->Draw("id", "l==\"\\\"/root\\\"\""); // Why the forward slash?

but if I remember correctly the TTree::Draw parser does not (is very unlikely to not) parse correctly the embedded quote.

You might actually achieve close to what you need with the strstr function instead.

t->Draw("id", "strstr(l, \"root\") != 0");


The “\\\” doesn’t work at all.
The “strstr” does not compare the given strings (and it actually ignores the surrounding “\"”, of course).
Maybe “strcmp” would work, it one was able to get it working inside of the selection string.

Guys, I am sorry, Philippe’s confusion was of course due to the fact that I messed up my problem description. I am detailing a bit more here (and I also edited the initial post):

I am dealing with data that has forward slashes included ("/root") - that’s why in need to match the / in the selection - and that can have more than one level ("/root/world") - that’s why strstr won’t work for me, I really need exact comparison.

So what you write that the code sees, i.e.


is exactly what I want.
The parsing seems to work absolutely fine for data that has quotes, i.e. to match something like


It is really just the / that throws it off.

How could I try to make strcmp work ? Or do you have any other idea ?

Why do you need these internal quotes?

It would work for:

// ...
char c[50] = "/root";
char id[50] = "myId";
// ...
t->Scan("*", "l==\"/root\"");

The internal quotes are because the data comes with quotes, for example as CSV:


I would just have liked to make it work like this to avoid “cleaning” the quotation marks from the data.
And you know, since this worked fine for the case without slash, it seemed kind of odd that the slash would interfere with it.

@couet For me, this is a bug that TTree::ReadFile does not strip surrounding quotation marks in CSV fields (in a CSV file, any field may be quoted so e.g. 1997 should be fully equivalent to "1997", regardless if the user wants to interpret it as a numerical value or as a character string).
I created: JIRA -> ROOT -> ROOT-10867

@mreinhard I recall I met the same problems some time ago. In one case, the utility which “produced” CSV files had a formatting option which allowed to specify if the exported fields should be quoted or not. In another case, I simply used “sed” to remove all quotation marks from the existing CSV files. Of course, in both cases, I was lucky that all quotation marks were actually “redundant” in these files (which may not always be the case so we really need the TTree::ReadFile parser, and any related one, fixed).

Well, I guess it boils down to editing the data to remove the quotes for now then.
Thanks a lot for your help!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.