Re: Create a bash-script that runs C-files in ROOT

From: Ida Häggström <ida.haggstrom_at_radfys.umu.se>
Date: Wed, 7 Apr 2010 08:47:35 +0200


Hi Brett and thanks for your suggestion! I'm really not familiar with C unfortunately and tried implementing your suggestion without success... =(. I do need something similar to this, i.e. be able to call different filenames. To be more specific:

I have a bash-script with a loop ( in this case 40 loops, as many as the number of root files I have).
Each loop I run:



for (j=0;j<=$N,j++)
do

   cd folder$j
   root -q -b myScript1.C myScript2.C
   cd ..
done



Each folder I enter contains one root file, different names however. Now, each loop I want to use a different root-file in the first C-script (rootFile_0.root to rootFile_39.root).
I've searched around and tried this in my first C-script (myScript1.C):

  char Root_File[250];
  void *dirp = gSystem->OpenDirectory(".");   const char *afile;
  Int_t nfiles = 0;

  while(afile = gSystem->GetDirEntry(dirp)) {

      if (strstr(afile,".root")) {
    TChain chain("finalDelayedCoinci");

      sprintf(Root_File,"%s",afile);
      chain.Add(Root_File);
      printf("\n Processing file %s...\n",afile);
        nfiles++;
      }

  }

This seems to find the single root-file in each directory. However, I'm afraid this will cause some problems if I for example add another root-file into a folder or something. Your suggestion would be nicer, if I can just send the filename as an argument into the C-script, something like:

for (j=0;j<=$N,j++)
do

   cd folder$j
   root -q -b myScript1.C("rootFile_$j") myScript2.C    cd ..
done



and then add this file to the chain inside the C-script. I've tried implementing this, but unfortunately I'm really not good at neither C nor root! I really appreciate your help,

Cheers,
Ida

Den 6 april 2010 19.56 skrev Brett Viren <bv_at_bnl.gov>:

> Ida Häggström <ida.haggstrom_at_radfys.umu.se> writes:
>
> > I want to
> > create a bash-script to run from my Linux teminal that calls for ROOT and
> > executes the C-scripts and so on...
>
> One more feature to consider is that you can pass arguments from the
> shell into your C-scripts. You just have to be a little careful to make
> sure that any special characters are escaped so the shell won't
> interpret them.
>
> For example,
>
> shell> cat myscript.C
> void myscript(const char* filename) {
> TFile* f = new TFile(filename);
> //...
> }
>
> You can pass in the file name like:
>
> shell> root -q myscript.C\(\"file1.root\"\)
>
> or wrap the whole thing in single-quotes like:
>
> shell> root -q 'myscript.C("file1.root")'
>
>
> -Brett.
>
>
>
Received on Wed Apr 07 2010 - 08:47:39 CEST

This archive was generated by hypermail 2.2.0 : Wed Apr 07 2010 - 17:50:02 CEST