Hello and thanks for your input!
You are right about the chain being unnecessary, but I'm working on someone
elses code and haven't dared changing too much! =) I might want to add
different root files later on so I think I will keep the chain for now.
I've continued working on my script and got it to half work...
Running the bash-script:
------------bash-script-----------------
for (j=0;j<=$N,j++)
do
cd folder$j
root -q -b myScript1.C\($j\) myScript2.C
cd ..
done
char Root_File[250];
TChain chain("finalCoinci");
sprintf(Root_File,"rootOutput_%d.root",fileNumber);
chain.Add(Root_File);
printf("\n Processing file rootOutput_t%d.root...\n",fileNumber);
......more stuff.....
}
Total Number of Coincidence Events:= 730
... 0
Warning: wrong member access operator '.'
/home/ida/GATE/ROOT_v5.24/root/share/root/macros/GEAdvance3D_SinogramFinalCoinci_Bin.C:411:
Warning: wrong member access operator '.'
/home/ida/GATE/ROOT_v5.24/root/share/root/macros/GEAdvance3D_SinogramFinalCoinci_Bin.C:414:
Warning: wrong member access operator '.'
/home/ida/GATE/ROOT_v5.24/root/share/root/macros/GEAdvance3D_SinogramFinalCoinci_Bin.C:417:
Warning: wrong member access operator '.'
/home/ida/GATE/ROOT_v5.24/root/share/root/macros/GEAdvance3D_SinogramFinalCoinci_Bin.C:420:
Warning: wrong member access operator '.'
/home/ida/GATE/ROOT_v5.24/root/share/root/macros/GEAdvance3D_SinogramFinalCoinci_Bin.C:423:
---------myScript1.C----------------
char Root_File[250];
TChain chain("finalCoinci");
sprintf(Root_File,"rootOutput_%d.root",fileNumber);
chain.Add(Root_File);
printf("\n Processing file rootOutput_t%d.root...\n",fileNumber);
......more stuff.....
}
Den 7 april 2010 10.00 skrev Axel Naumann <Axel.Naumann_at_cern.ch>:
> Hi Ida,
>
> what about the following:
>
> #include <iostream>
>
> void myScript1(int dir) {
> TString filename = TString::Format("rootFile_%d.root", dir);
> TFile* f = TFile::Open(filename);
> if (!f || f->IsZombie()) {
> std::cerr << filename << " not found!" << std::endl;
> return;
> }
> TTree* tree = 0;
> f->GetObject("finalDelayedCoinci", tree);
> }
>
> With one single tree per run you don't need a TChain, and you can pass the
> dir number to the C++ part by invoking it with:
>
>
> for (j=0;j<=$N,j++)
> do
> cd folder$j
> root -q -b myScript1.C\($j\) myScript2.C
> cd ..
> done
>
> Cheers, Axel.
>
> Ida Häggström wrote on 04/07/2010 08:47 AM:
>
>> 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 <mailto:bv_at_bnl.gov
>> >>:
>>
>>
>> Ida Häggström <ida.haggstrom_at_radfys.umu.se
>> <mailto: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 - 10:37:12 CEST
This archive was generated by hypermail 2.2.0 : Wed Apr 07 2010 - 11:50:01 CEST