Set preprocessor #define values before compilation

Dear experts,

I have a runAnalysis.C macro that I use to compile my custom classes using ROOT5 like


In the ClassA definition, I have a preprocessor macro that determines the definition of the class, something like:

#define TYPE 1
#if TYPE == 1
typedef EventA Event;
#if TYPE == 2
typedef EventB Event;

Is there a way to pass the TYPE value as a parameter for the compilator in my runAnalysis.C macro instead, so that I don’t have to rewrite it manually in the source file?
ROOT5 as well as ROOT6 solutions are welcome :slight_smile:
Thanks a lot!

Please read tips for efficient and successful posting and posting code

ROOT Version: Not Provided
Platform: Not Provided
Compiler: Not Provided

The simplest I can think of would be to add right in the beginning of your “ClassA.cxx”:

#if !defined(TYPE)
#include "ClassA_TYPE.hxx" /* get it from this file */

and then use:

gSystem->Exec("echo '#define TYPE 1' > ClassA_TYPE.hxx");

Thanks Wile, that’s a smart workaround.
Sadly it isn’t platform universal but that shouldn’t matter for me.

Thanks a lot!

{ std::ofstream f("ClassA_TYPE.hxx", std::ios::trunc); f << "#define TYPE 1" << std::endl; f.close(); }

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