Parameters in gROOT->ProcessLine() in named macros

Hi all,

I have the following code in a macro run.cxx

[code]TChain * LQ_1200Chain = new TChain("","");
LQ_1200Chain->Add("…/…/D5PDs/LQ_1200.root/physics");

string LQ_1200histName = “LQ_1200”;

gROOT->ProcessLine(".L LQ_Analysis.C++");
gROOT->ProcessLine(“LQ_Analysis t(LQ_1200chain)”);
gROOT->ProcessLine(“t->Loop(LQ_1200histName);”);[/code]

which runs fine if the macro is unnamed, but as soon as I change the macro to a named one (adding void run() before the first {), then root complains that

Error: Symbol LQ_1200chain is not defined in current scope (tmpfile):1: *** Interpreter error recovered *** Error: Symbol t is not defined in current scope (tmpfile):1: Error: Failed to evaluate t->Loop(LQ_1200histName)

Any ideas for a work around?

[quote]which runs fine if the macro is unnamed, but as soon as I change the macro to a named one [/quote]This is the expected behavior since LQ_1200Chain is now defined in the scope of the function rather than the global scope (where the content of ProcessLine is evaluated).

Note that the following should work in both case:[code]TChain * LQ_1200Chain = new TChain("","");
LQ_1200Chain->Add("…/…/D5PDs/LQ_1200.root/physics");

string LQ_1200histName = “LQ_1200”;

gROOT->ProcessLine(".L LQ_Analysis.C+");
LQ_Analysis t(LQ_1200chain);
t->Loop(LQ_1200histName);[/code]and the following will work in all cases (i.e. including when compiled):[code]
#include
#include "TChain.h
#if defined(CINT) && !defined(MAKECINT)
#include “Q_Analysis.C+”
#else
#include “Q_Analysis.C”
#endif

void run() {
TChain * LQ_1200Chain = new TChain("","");
LQ_1200Chain->Add("…/…/D5PDs/LQ_1200.root/physics");

string LQ_1200histName = “LQ_1200”;
LQ_Analysis t(LQ_1200chain);
t->Loop(LQ_1200histName);
}[/code]

Cheers,
Philippe.

I have a section of code very similar to this and don’t understand why it is not working:
{
gROOT->ProcessLine(".L /uscms/home/wclarida/MajCode/CMSSW_3_9_9/test/ntupleReader/src/Analizer.cc+");
gROOT->ProcessLine(".L /uscms/home/wclarida/MajCode/CMSSW_3_9_9/test/ntupleReader/src/ChainMaker.C+");
gROOT->ProcessLine(".L /uscms/home/wclarida/MajCode/CMSSW_3_9_9/test/ntupleReader/src/ChainAdd.C+");

TChain* chain = ChainMaker(“MajMC_Mass30.txt”);
Analizer Pippo;
Pippo.Init(chain);
Pippo.SetName(“Maj30”, 1);
Pippo.SetWeight(98.4, 14600);
std::cout << “Maj30” << std::endl;
Pippo.Loop();
}

The three shared libraries are created successfully and then the code fails with the error:
Error: Symbol AnalizerPippo is not defined in current scope runbackground.C:7

Hi,

What does:gROOT->ProcessLine(".L /uscms/home/wclarida/MajCode/CMSSW_3_9_9/test/ntupleReader/src/Analizer.cc+"); TClass::GetClass("Analizer")->Print();return? What are the last few lines of:gROOT->ProcessLine(".L /uscms/home/wclarida/MajCode/CMSSW_3_9_9/test/ntupleReader/src/Analizer.cc+"); gROOT->ProcessLine(".class");

Philippe.

Hi pcanal,

Sorry I have not looked at your proposed solutions until now. Thanks and the first solution worked perfectly! (Didn’t bother with the second solution since there was not much point)

Jason