Run a c++ code from a root Macro

Okay, so I need to launch a c++ code from my root macro, but I need to call the code with an argument. Is this something I can do using gROOT->ProcessLine(.x writing.cpp());?

Also I need to specify the file location of the cpp file since I can’t put it in the macros section

Thanks

Chris

// macro.cxx #include <iostream> void macro(double x, double y, double z) { std::cout << x << " " << y << " " << z << std::endl; } root [0] gROOT->Macro("/full/path/to/my/macro.cxx++(1.1, 2.2, 3.3)");

I don’t know if this helps because I want to launch from inside my current .C Macro. When I do try what you suggested, I get a not defined in current scope error.
I call:

root F:\DRS_Projects\c_settles_root\Debug\GuiApp.C <- This is the macro that I wish to run the cpp macro from
When I execute

I get the following error:

root [1] Error: Function c_settles_root(1,"file path") is not defined in current scope (225)

Thanks

Chris

// file macro.cxx #include <iostream> // "function-name" must be the same as the "file-name base" void macro(int i, const char *s) { std::cout << i << " " << s << std::endl; } root [0] gROOT->Macro("/full/path/to/my/macro.cxx++(1, \"file path\")");

[quote=“Pepe Le Pew”]// file macro.cxx #include <iostream> // "function-name" must be the same as the "file-name base" void macro(int i, const char *s) { std::cout << i << " " << s << std::endl; } root [0] gROOT->Macro("/full/path/to/my/macro.cxx++(1, \"file path\")");[/quote]

Would there be any way to pass variables into the argument of the macro, and not just a predefined string literal?

Thanks

Chris

int i = 1; const char *s = "file name"; gROOT->Macro(TString::Format("/full/path/to/my/macro.cxx++(%d, \"%s\")", i, s));

How would I go about passing in the parameters if I was passing in a TFile and not an int or a string?

I currently have this:

[code] TFile f(newrootpath);
TTree* T = NULL;
f.GetObject(“T”, T);
//system(path);

int i = 1;
const char *s = "file name";
//gROOT->Macro(TString::Format("/full/path/to/my/macro.cxx++(%d, \"%s\")", i, s));
gROOT->Macro("F:\\DRS_Projects\\c_settles_root\\Debug\\Integration.C");
gROOT->ProcessLine(TString::("Integration integral(%s,\"F: / DRS_Projects / c_settles_root / Debug / OldDRSTest8.root\", 550, 750, 100, 300)"), T);

[/code]

Thanks

Chris

// file macro.cxx #include "TTree.h" #include <iostream> // "function-name" does NOT need to be the same as the "file-name base" void func(TTree *t, const char *s) { std::cout << t << " " << s << std::endl; } const char *s = "file name"; TTree *t = new TTree("t", "tree"); std::cout << t << " " << s << std::endl; gROOT->LoadMacro("macro.cxx++"); gROOT->ProcessLineSync(TString::Format("func(((TTree *)%p), \"%s\");", ((void *)t), s));

So it’s now changed from running a cpp Macro to running a C macro. I have also moved the macro to the macros folder on the desktop to help with troubleshooting. Here is my entire function:

[code]void MyMainFrame::GenerateClicked()
{
//TString path = "“F:\DRS_Projects\c_settles_root\Debug\c_settles_root.exe” ";
//path += FilePath->GetText();

string rootpath = FilePath->GetText();
rootpath = rootpath.substr(0, rootpath.length() - 4);
rootpath += ".root";
cout << rootpath << endl; // For Debugging

TString newrootpath;
newrootpath = rootpath;

TFile f(newrootpath);
TTree* T = NULL;
f.GetObject("T", T);
cout << "Debug 1" << endl;

gROOT->LoadMacro("Integration.C");
gROOT->ProcessLineSync(TString::Format("Integration integral(((TTree *)%p), \"%s\" , 550, 750, 100, 300 );", ((void *)T), rootpath));

cout << "Got here without breaking" << endl;

}[/code]

The Macro that I’m trying to run has a header that looks like this:

I know that the issue is with how gROOT->LoadMacro("Integration.C"); is being called because Debug 1 will print out on the screen right before that but as soon as the LoadMacro gets ran, root freezes.

I have also tried changing LoadMacro to just Macro.

Thank you so much for your help. I really appreciate it.

Chris

You can try (you will need to “delete f;” somewhere, when “T” is no longer needed): TFile *f = TFile::Open(rootpath.c_str()); if ((!f) || f->IsZombie()) { delete f; return; } // just a precaution TTree *T; f->GetObject("T", T); if (!T) { delete f; return; } // just a precaution In the ProcessLineSync call, you should use: rootpath.c_str()
Also try to precompile your macro using ACLiC (should report most source code bugs): gROOT->LoadMacro("Integration.C++");