I’m trying to use TMVA::Reader to BookMVA methods and use them in a program built in C++.
The only issue is, I have many different models I am testing with many different variables. I don’t want to have to rebuild each time I use a different model for something. I would like to scan through the xml and see which variables exist and add only those to the reader before booking my model. Is this possible?
I can’t find a good XML reader in root. But I also see the TMVA::MethodBase has a “ReadVariablesFromXML” but I can’t initialise a BookMethod class because is it abstract.
You can use the functions in TMVA to read the XML file. First of all in the Reader when you book a method a pointer to the class is returned. You might need to downcast to MethodBase or to the specific method, if you want to call some of its member functions.
You can also look at reading the XML file directly using the TMVA::Tools::ReadAttr function, and you can look for example at the code used here in MethodBase on how it is used to read the different field of the XML file.
But if I’ve already booked the method then I must have already added the variables.
Can you find a list of classes derived from this class? I couldn’t find one earlier. I am using BDT.
Basically the pseudocode of what I’m looking for would be like this:
xmlreader = new TMVA::XMLReader(); //this class doesnt exist but its the class i would need to use.
reader = new TMVA::Reader();
for(variable: xmlreader.GetVarFromXML("TMVAClassification_BDT.weights.xml")
{
reader->AddVariable("variable",&variable);
}
reader->BookMVA("BDT", "TMVAClassification_BDT.weights.xml");
Hi,
I understand now your problem to get the variable names to add to the Reader before booking the method.
Yes, this is a good solution, using an internal parser function, (see here) of the XML file. Maybe we should make this function public, so it is possible to use without the RReader class.