Template:ROOT/Exercises/A Simple Stand-Alone Application

Exercise
Once again, consider the code you should have previously written to compute the mean of an array of random numbers. Now, last but not least, make it a stand-alone application and run it independently of any ROOT session. Make sure that passing parameters will still work. Check the performance of your application. Take also care that your modifications don't disturb interpretation or on-the-fly compilation by CINT or ACLiC.

Solution
What we have to do is to add an  function. But this will bother CINT. So we hide it by putting a preprocessor command around it that will ignore it if the variable  is defined.

This works. But it doesn't allow us to pass command line arguments yet. So to make it complete, we add a check if any parameters are given and if so, we convert the second (the first is&mdash;as always&mdash;the name of the application) to an integer and call  with it. The conversation may be done with the  method that can be found in the.

The final code should look like this:

Now we can compile the code using an external compiler

and also execute it without starting ROOT. With or without a parameter. Check out how fast it is!

Note that is is still possible to interpret or compile your macro on-the-fly.

So after a long journey, we have finally made the ultimate ROOT source file. I also recommend this strategy when developing something new. First try it interactively. If you know what to do, start writing your macro and test it on the interpreter. If it is more or less finished, make sure the code is clean and test it on larger amounts of data as compiled code. And finally make it a stand.alone application (if needed). It is wonderful that ROOT supports all these possibilities.

One more thing to note: This was a basic example. To build a stand-alone application with a ROOT GUI a slightly more difficult setup is needed.

/Exercises