System ()

Hi,
I try to explain my problem…

I have a C++ program, I’m compiling with MinGW and running under windows XP professional.

From this program, I would like to run a ROOT Macro.

The Macro is:
C:\root\tutorials\SFHped_plot_v0.C.

From a ROOT terminal, the macro properly works if I write:

.L .\tutorials\SFHped_plot_v0.C (enter) Main() (enter).

From my c++ program, if I do:

#include <stdlib.h> .... system ("C:\\root\\bin\\root.exe");

it opens a ROOT terminal. That’s fine.

Now I would like to be able to run the macro automatically and not only to open the terminal.
So I tried something like:

but nothing works.

What should I do?

thanks in advance!
anna

Anna, not sure whether this is useful, however maybe you could do something along these lines?

//in the includes
#include "TROOT.h"

//instead of the system() call
gROOT->Macro(".\tutorials\SFHped_plot_v0.C(enter)");

Hi,

rename Main() to SFHped_plot_v0() and run system (“C:\root\bin\root.exe C:\root\tutorials\SFHped_plot_v0.C”);

Cheers, Axel.

my compiler (MinGW) doesn’t recognize “TROOT.h” library…

Hi,

What do you run, what is the error you see?

Cheers, Axel.

[quote=“Axel”]Hi,

rename Main() to SFHped_plot_v0() and run system (“C:\root\bin\root.exe C:\root\tutorials\SFHped_plot_v0.C”);

Cheers, Axel.[/quote]

Hi Axel,
if I do as you say, I get the folowing error:

"C:\root\SFHped_output_v1.txt file written


  •                                     *
    
  •    W E L C O M E  to  R O O T       *
    
  •                                     *
    
  • Version 5.20/00 24 June 2008 *
  •                                     *
    
  • You are welcome to visit our Web site *
  •      [root.cern.ch](http://root.cern.ch)            *
    
  •                                     *
    

ROOT 5.20/00 (trunk@24524, Jun 25 2008, 12:08:00 on win32)

CINT/ROOT C/C++ Interpreter version 5.16.29, Jan 08, 2008
Type ? for help. Commands must be C++ statements.
Enclose multiple statements between { }.
root [0]
Processing C:\root\tutorials\SFHped_plot_v0.C…
Error: Function SFHped_plot_v0() is not defined in current scope (0)
*** Interpreter error recovered ***
root [1]"

should I add custome libraries in the c++ code?
when you say to replace script name, do you mean simply replace Main() with file name, or also suppress the curl brackets including the ROOT code?

many thanks!
anna

Hi,

your function called Main() should instead be called SFHped_plot_v0(). “.x MyFile.C” means “load MyFile.C and call MyFile()”.

Cheers, Axel.

[quote=“Axel”]Hi,

your function called Main() should instead be called SFHped_plot_v0(). “.x MyFile.C” means “load MyFile.C and call MyFile()”.

Cheers, Axel.[/quote]

thanks, it helps me!
But then, when you say
"system (“C:\root\bin\root.exe C:\root\tutorials\SFHped_plot_v0.C”);"

where do I write “.x”? is it automatically understood by the ROOT terminal?

Hi,

sorry, that step was missing :slight_smile: $ root file.C gets translated to

$ root
root [0] .x file.C

Cheers, Axel.

[quote=“Axel”]Hi,

sorry, that step was missing :slight_smile: $ root file.C gets translated to

$ root
root [0] .x file.C

Cheers, Axel.[/quote]

Hi,
sorry for my (stupid) questions…
I changed the script replacing Main() with the file name.
Now, if I write:

.x .\tutorials\SFHped_plot_v0.C

in a root terminal (I get double-clicking on the ROOT.exe icon) it works properly.

If I open a prompt command terminal of windows, I go in C:\root directory and I wrote:

C:\root.\tutorials\SFHped_plot_v0.C

it opens the script list with notepad but doesn’t run the script itself, whule I was expecting.
Whan am I wrong?

cheers & thanks,
anna

Hi,

check what you wrote in system(): You need to call root with the filename as argument, i.e.

root C:\root\.\tutorials\SFHped_plot_v0.C

Cheers, Axel.

[quote=“Axel”]Hi,

check what you wrote in system(): You need to call root with the filename as argument, i.e.

root C:\root\.\tutorials\SFHped_plot_v0.C

Cheers, Axel.[/quote]

sorry, I still don’t succeed.
Before testing witjh the c++ code, I was doing some tests with the cmd.exe of windows.
I suppose it acts the commands as system() does. Am I right?
From the cmd.exe terminal, if I go to

path and then I write

the SFHped_plot_v0.C script is opend with Notepad and it is not executed.
Is it right like that?

thanks very much for the time you are spending to answer my questions!
regards
anna

Hi,

when I say

root myCode.C

I mean you start root (aka root.exe) and pass myCode.C as argument. I don’t know where you installed ROOT. Suppose it’s in C:\root\bin, you could do (from cmd.exe):

C:\root\bin\root.exe C:\root\.\tutorials\SFHped_plot_v0.C

Cheers, Axel.

Hi Axel,
so, something is working, but I still have some bugs…

Yes, I have root installed in C:\root\bin.

If, from cmd.exe, I go in the C:\root directory and I write:

it works perfectly (i.e., ROOT is opened and my script succesfully run).

But I cannot do it if I stay in the C:\ directory. namely, if I write:

it doesn’t work. Root is properly run but then it says:

root [0] Processing .\root\tutorials\SFHped_plot_v0.C... Exception: invalid string position Error: Symbol G__exception is not defined in current scope C:\root\tutorials\SF Hped_plot_v0.C(57) Error: type G__exception not defined FILE:C:\root\tutorials\SFHped_plot_v0.C LIN E:57 *** Interpreter error recovered ***

Since I’m not able to give 2 consecutive instructions [i.e., change directory (to go in C:\root) first, and then run root and my code] to the system() function, I don’t succeed in my goal.

can you still help me?
thanks!

cheers,
anna

Hi Anna,

can you post the code around line 57 of SFHped_plot_v0.C?

Cheers, Axel.

[code]int SFHped_plot_v0(){
Int_t Nfibres=128; //fibers number (64 hor + 64 vert fibers)
Float_t fiber[128]; //fiber numbering (1 to 64 for H fibers, 65 to 128 for V fibers) //int?
Float_t ped[128];//array da riempire con pedestal average values, per each fiber
Float_t rms[128]; //array da riempire con pedestal rms values, per each fiber
Float_t F=0; //int?
Float_t P=0;
Float_t R=0;

string detector;
string measurementlabel;
string date;
string exposure;
string gain;
string Nmeas;
string valuemean;
string rmsmean;
string basket;

// read the time the ROOT script is executed at	
time_t rawtime;
time ( &rawtime );
date=ctime(&rawtime); //this string ends with a "newline" character

//let's read the input file and fill the strings:
// for each ">>", it reads until the first space
// i.e., a word at a time
ifstream infile("SFHped_output_v1.txt");
    infile>>detector;
detector=detector.substr(1);  #### LINE 57###
infile>>measurementlabel;
measurementlabel=measurementlabel.substr(1);
infile>>gain;
gain=gain.substr(1);
infile>>exposure;
exposure=exposure.substr(1);

…[/code]

thanks!

Hi,

I assume your code can’t find the file called SFHped_output_v1.txt

Cheers, Axel.

but then, why does it work if I run it directly from a ROOT terminal or from a prompt command going in the C:\ROOT directory first and then writing the command “.\bin\root.exe .\tutorials\SFHped_plot_v0.C”?

I fear it is difficult to debug it in this way; I don’t want to disturb you too much.
I think I’ll do it “by hand” (i.e., not with an automatic call of ROOT from the c++ program).

thanks!
anna

Hi,

I don’t know where that file SFHped_output_v1.txt is located. It should help if you specify the full path, or if you gSystem->cd() to a fixed location before accessing that file.

Cheers, Axel.

great, it works now!

many thanks!
anna