Rewriting macro as c++ application

I have a macro which has the task of reading in several files of a TNT2 card and make with these data a new histogram.
I know want to transfer this macro to a executable file.

That worked quite well since I got that I have to include TROOT and TApplication somewhere. But at the moment this is only working as long as I give only one filename as a argument.
I don’t know how to hand over more since the call of TApplication deletes the number of arguments:

int main(int argc, char** argv) { [...] TApplication theApp("App", &argc, argv);
After this call argc is set back to 1 and something happens to argv as well, but I don not exactly know what.

I need the information of argc and argv to implement a for loop which runs my algorithms as long as there are arguments/files but do I really have to make copies of the mentioned vectors?

Another problem with converting the script to a executable is that the canvas which is drawn as a final result just flashes on the monitor and then vanishes immediatly since the application closes immediatly:

[...]
  TGraph *tofhisto = new TGraph(channels,channel_x,channel_y);
  TCanvas tofcan;
  tofhisto->Draw("ab");
  
  return(0);
}

I added a theApp.Run(); to be able to access the canvas (resize, etc.), but than when I close the canvas I get the error message

and I have to use ctrl+c to finally close the app - how can I avoid that?

I hope that I described my problems detailed enough; if you need more information please ask, if you think I missed an important part of the manual somewhere please also point it out, and I will try to solve bymyself first.

liquidat

Hi,

if you don’t want your users to be able to use the default ROOT arguments you can do int main(int argc, char** argv) { [...] int argcROOT = 1; char* argvROOT = argv[0]; TApplication theApp("App", &argcROOT, &argvROOT); (TApplication just needs the app’s name). Use TPad::WaitPrimitive to leave the canvas hanging around until the user clicks somewhere.

Cheers, Axel.

Hej,

thanks for the answer, I’m now able to process as many files as I want to :slight_smile:

But I did not got the part about WaitPrimitive: I understood the examples on the calls description page of TPad that it should be enough to call it like

[...]
TCanvas tofcan;
tofhisto->Draw("ab");
tofcan.WaitPrimitive();
theApp.Run();
return 0;

But that didn’t work, it didn’t change the behaviour of the application window at all - to eb more clear:
If I press ctrl+c in the command line or close the window by the file menu it closes as it is exected, without any error, but when I press the X button of the window than there is the invalid pointer error.
The windowmanager I’m using is KWM (KDE) on a Mandriva 10.1 system with KDE 3.2.3

liquidat

You do not need to call gPad->WaitPrimitive if you run a TApplication.
See examples of main program in $ROOTSYS/test programs like hworld, hworld2, etc.

Rene

Hm, do I get this right that there is no possibility of closing the application through the X of the window manager?

quit->SetLabel("Select File/Quit again to exit app");

But at least this version does not produce the mentioned error; but I still have to press ctrl+c to get back to the command line.

TCanvas tofcan; tofhisto->Draw("ab"); tofcan.Update(); theApp.Run(); return 0;

Btw., I work remote (ssh -X) on the machine which has root installed, but that shouldn’t make any difference…

liquidat

Again, you do not send enough information to solve your problem.

Note that in general IT IS A VERY BAD IDEA to implement your main program, if you do not understand how the Application event loop works.
Simply write a script that you execute from the ROOT prompt via
root > .x myscript.C
or
root > .x myscript.C+ (use the native compiler via ACLIC)

Rene

Thanks for the fast answer already at the same night very much, Rene!
About the missing information: if I would exactly know what is missing I wouldn’t need any help. And I know that there is the command line and the scripts, but you have to start somewhen when you want to explore new fileds (applications in this case)
Looks like I was to early. I will get back then to the manuals to try it by myself. If I find any solution I will post it here (in case others stumble over this thread).

liquidat

I have the same problem. After runnin the Run() command I have to press ctrl-C to return to the command line…and nobody seems to know the answer!!
I have to compile my code. Running it from the root console is slower…

Hi,[quote=“moriei”]I have to compile my code. Running it from the root console is slower…[/quote]You do know you can use ROOT’s built-in build system to compile your code, don’t you? It’s called ACLiC, and it plays a major role in the Users Guide. You can simply run “.x mycode.cxx+”, and ROOT will compile, link, and load your code, and then call mycode(). On all platforms.
Axel.