Home | News | Documentation | Download

Add enum parsing in TTreeFormula

Hi there :slight_smile:

I’d like to define TTreeFormula using enum names. With a naive implementation, an error is returned saying the enum name is not recognized. Is there a way we can make TTreeFormula aware of the existence of extra enums?

An example:

enum eventType{
  SubGeV_elike_0dcy = 1,
  SubGeV_elike_1dcy
};

f = new TTreeFormula("f", "type == SubGeV_elike_0dcy", myTree);

Cheers!
Adrien


Please read tips for efficient and successful posting and posting code

ROOT Version: 6.22/08
Platform: macOS
Compiler: clang


f = new TTreeFormula("f", TString::Format("type == %d", SubGeV_elike_0dcy), myTree);

Thanks for the reply,

In fact I’d like to define formula strings in an external .txt file. So this solution would not allow me to do so :confused:
Isn’t a way to define the enum namespace in a LinkDef file for example?

If the enum is a namespace then the correct syntax is:

f = new TTreeFormula("f", "type == name_of_the_namesapce::SubGeV_elike_0dcy", myTree);

In order for TTreeFormula to ‘see’ the enum, the interpreter need to know about it.
There are several ways to automate the process, one is to add to a LinkDef file:

#pragma link C++ namespace name_of_the_namespace;
#pragma link C++ enum eventType;