Writting a script for doing several runs of a root function


to analyze the data of my simulation I have two Root functions:

  • “ReduceData.C”
  • "AnalyseData.C"
    The first one gives a tree as an output, that is read by the second. The second gives then some ASCII and postscript files as output.

My question is: Is is possible to write some script that would run these two functions after each other, taking into account that it also has to rename some files in the middle and at the end? I would like to do this to be able to leave runs working over night in serie, and in this way I could have the result of several analysis on the next day.

If it would be a usual shell script, it would look something like this:

.L ReduceData.C
mv outputTree.root outputTree_1.root
.L AnalyseData.C
mv plots.ps plots_1.ps
mv output.txt output_1.txt

and I could copy paste the same structure several times after each other. But something like this doesn’t work because a normal shell script cannot execute any command inside of Root.

I thought about the possibility of introducing the name of the ouput files as a char variable of my two Root functions, in the brackets, and then write a small Root function that would call them with different variables each time. This would work for the root files, but not for the postscript files that have several canvases on them, like:


Is there a simple way of doing this? Or is it better that I put everything as input of the functions and store the postscript data into several independent files whose name are also given?

Thank you,

(PS: The root version I am using is 5.08, and I am working under linux.)

That is easy to do using gSystem->Exec(“any shell script command”)

root .L ReduceData.C ReduceData("inputTree.root") gSystem->Exec("mv outputTree.root outputTree_1.root "); .L AnalyseData.C AnalyseData("outputTree_1.root") gSystem->Exec("mv plots.ps plots_1.ps"); gSystem->Exec("mv output.txt output_1.txt "); ... .q



thanks a lot. I’ve written a small routine as following:

[code]void runMany()

gSystem->Exec(“mv inputTree.root inputTree_1.root”);
gSystem->Exec(“mv plots.ps plots_1.ps”);
gSystem->Exec("mv output.txt output_1.txt ");

… (repeated a couple of times)

cout << " End of runMany " << endl;


It works perfectly. I just have to compile both routines before running this program. Thank you again. This will save me a lot of time! :slight_smile: