Re: shellscript executing a root macro with variables

From: Adrian Sevcenco <Adrian.Sevcenco_at_cern.ch>
Date: Sat, 10 Mar 2007 17:13:10 +0200


Axel Naumann wrote:
> Hi,
>
> an alternative is e.g. this test.sh (a bash script)
> root -l -b -q "$@"
> which you run as
> ./test.sh 'test.cxx+("c d", "e f")'
> The "$@" takes care of args with spaces, and it works with ACLiC, too.
>
> Cheers, Axel.
>
> Tom Roberts wrote:

>> John Zoidberg wrote:
>>> I would like to create a shellscript which can take any ROOT macro
>>> (with 0,1 or more variables) as argument, launch root, execute the
>>> macro with the given arguments and write the output into a .out file
>>> and the errors into a .err file.
>> Here's how I pass arguments to my Root macro (this is a bash script):
>> ARGS="$*" $ROOTSYS/bin/root -n -l macro.C
>>
>> The ARGS are names of Root files to read:
>>         // open files given in environment variable ARGS
>>         const char *args = gSystem->Getenv("ARGS");
>>         if(!args) args = "";
>>         TObjArray *files = TString(args).Tokenize(" \t");
>>         for(int i=0; i<files->GetEntries(); ++i) {
>>                 TObjString *s = files->At(i);
>>                 if(!s || *s->String().Data() == '\0') continue;
>>                 TFile *f = new TFile(s->String().Data(),"READ");
>>                 if(f->IsZombie())
>>                         new TGMsgBox(gClient->GetRoot(),window,"Error",
>>                           "File could not be opened!"); //self-deleting
>>         }
>>         files->Delete();
>>         delete files;
>>
>> Yes, this fails if any filename contains a space....
>>
>>
>> Tom Roberts

It is possible to use from bash something like this: root -b -q -l
`macro.C(arg0,"'$arg1_1'","'$arg1_2'","'$arg2_1'","'$arg2_2'")' 1>$output_f 2>$error_f
where arg0 is just real argument and the rest (everything with $) are some variables defined before the root call (you could want to have some loops over some files and pass those files as an argument to root macro) It helped me to automatically create hundreds of qsub jobs :D each with their file argument :D Received on Sat Mar 10 2007 - 16:10:58 CET

This archive was generated by hypermail 2.2.0 : Sun Mar 11 2007 - 11:50:01 CET