Loading macro not working

Dear all,

I am trying to use a .C macro to load another .C with the gROOT->LoadMacro command but it doesn’t seem to be working.

The code is the following:

#include <iostream>
#include "TROOT.h"
#include "TSystem.h"
#include "TApplication.h"

using namespace std; 

void BDTScore()
{
	gROOT->LoadMacro("TMVAClassification_BDT.C");

	vector<string> inputVars;
	inputVars.push_back( "Size" );
	inputVars.push_back( "Width" );
	inputVars.push_back( "Distance" );
	inputVars.push_back("Alpha");

	IClassifierReader* BDTResponse = new ReadBDT( inputVars );
}

The macro I am trying to load contains classes, IClassifierReader being one of them. However, if I purposefully make a mistake in the name of this macro, nothing changes and I still get the following error:

error: unknown type name 'IClassifierReader'
        IClassifierReader* BDTResponse = new ReadBDT( inputVars );

Anyone knows what the issue might be? I am using ROOT 6.12.

Thank you in advance for your help :slight_smile:

Cheers,
Kevin

Macros loading macros is the stuff nightmares are made from. So I would strongly recommend turning this into a compiled executable.

Otherwise, try

gROOT->LoadMacro("TMVAClassification_BDT.C+");

This other macro macro only contains classes. Is it the one you’re telling me to turn into an executable? How would you do this?

Adding “+” hasn’t changed anything unfortunately.

Sorry, I was a bit harsh in my first answer.

It’s generally a good idea, for a number of reason, to compile your code into one executable, so both your macro and MVAClassification_BDT.C. The command to do that looks like this

g++ yourmainmacro.C  TMVAClassification_BDT.C -o myprogram $(root-config --cflags --glibs) 

and produces a binary executable called “myprogram”.

Thanks again for your answer. Unfortunately, the compilation does not work properly, I get the same error:

$ g++ BDTScore.C TMVAClassification_BDT.C -o BDTScore $(root-config --cflags --glibs)

BDTScore.C: In function ‘void BDTScore()’:
BDTScore.C:18:2: error: ‘IClassifierReader’ was not declared in this scope
  IClassifierReader* BDTResponse = new ReadBDT( inputVars );
  ^
BDTScore.C:18:21: error: ‘BDTResponse’ was not declared in this scope
  IClassifierReader* BDTResponse = new ReadBDT( inputVars );
                     ^
BDTScore.C:18:39: error: expected type-specifier before ‘ReadBDT’
  IClassifierReader* BDTResponse = new ReadBDT( inputVars );
                                       ^
BDTScore.C:18:39: error: expected ‘;’ before ‘ReadBDT’

It really looks like it is unable to link the macro TMVAClassification_BDT.C where the IClassifierReader class is located.

Can you please post the full code of both files, I’ll have a look.

Alternatively, simply #include the macro instead of gSystem->LoadMacro()ing it.

Thank you very much for your help, I attached the files here :slight_smile: files.tar (54.5 KB)

It seems to work this way indeed, thank you very much :slight_smile: I didn’t know it was possible to include a .C macro without having to create a .h header first.

Cheers,
Kévin

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