Re: [ROOT] Looping over ntuple files to execute selection

From: Rene Brun (Rene.Brun@cern.ch)
Date: Mon Oct 15 2001 - 15:38:06 MEST


Hi Dario,

{
 Int_t i;
 TFile * f ;
 TTree *h2; //<===
 TString file;
 gROOt->ProcessLine(".L myselect.C"); //<====
 for (i=1; i<3; i++ ) {
  file = "/vtx4/menasce/k4pi_" ;
  file += i ;
  file += ".root" ;
  f=TFile::Open(file.Data()) ;
  h2 = (TTree*)f->Get("h2"); //<===
  h2.Print();
  h2->Process("myselect()") ;
  f->Close() ;
 }
}

You can ignore the warning printed by CINT. In principle, an interpreted class
cannot derive from a comnpiled class. However, if the derived class does not
redefine virtual functions of the base class, it is OK.
You can also use ACLIC, replacing the gROOT line with
 gROOT->ProcessLine(".L myselect.C++");

Rene Brun

Dario Menasce wrote:
> 
> Dear Rooters,
>         I have two ntuple files converted by h2root from PAW to Root format,
> k4pi_1.root and k4pi_2.root. The idea is to loop over the two files and
> fill
> histograms based upon cuts.
> 
> If I do the following interactively it works just fine:
> 
> root[] f = TFile::Open("/vtx4/menasce/k4pi_1.root");
> root[] h2.Print();
> root[] h2->Process("myselect.C") ;
> root[] f->Close() ;
> root[] f = TFile::Open("/vtx4/menasce/k4pi_2.root");
> root[] h2.Print();
> root[] h2->Process("myselect.C") ;
> root[] f->Close() ;
> 
> This is cumbersome, so I try something fancier, like the following,
> which
> crashes the interpreter:
> 
> {
>  Int_t i;
>  TFile * f ;
>  TString file;
>  for (i=1; i<3; i++ ) {
>   file = "/vtx4/menasce/k4pi_" ;
>   file += i ;
>   file += ".root" ;
>   f=TFile::Open(file.Data()) ;
>   h2.Print();
>   h2->Process("myselect.C") ;
>   f->Close() ;
>  }
> }
> 
> What happens is that, after the expected display of h2.Print() I get the
> following message on screen:
> 
> root[] .x example.cc
> 
>        ... output from the first iteration, which works fine...
>        ... output from the second iteration is just the result of
> h2.Print();
>        ... after that, I get:
> 
> reloading /vtx4/menasce/./myselect.C  0
> Warning: Interpreted class myselect derived from precompiled class
> TSelector FILE:myselect.h LINE:17
> !!!There are some limitations regarding compiled/interpreted class
> inheritance
> reloading myselect.h  0
> 
>  *** Break *** segmentation violation
> 
> During these attempts I never changed myselect.C which is just the
> skeleton
> provided by MakeSelector (I just removed comments for readability):
> 
> #define myselect_cxx 1
> #include "myselect.h"
> #include "TH2.h"
> #include "TStyle.h"
> #include "TCanvas.h"
> 
> void myselect::Begin(TTree *tree)
> {
>    Init(tree);
>    cout << "Init" << endl;
> }
> 
> Bool_t myselect::ProcessCut(Int_t entry)
> {
>      fChain->GetTree()->GetEntry(entry);
>      return kTRUE;
> }
> 
> void myselect::ProcessFill(Int_t entry)
> {
> }
> 
> void myselect::Terminate()
> {
>    cout << "Terminate" << endl;
> }
> 
>         Any suggestion? By the way, does a template exist on how to proceed
> in a general case, where one has a set of large ntuples files (derived
> by
> old data in paw) and one needs to loop over them, apply cuts, fill
> histograms
> and save those histograms for fitting?
> 
>                                 Thanks in advance
> 
> --
> +------------------------------------------------------------------------+
> | Dario Menasce, INFN Milano, via Celoria 16, Italy Tel: +39 02 58357322
> |
> |
> |
> |      WEB home page: http://sgimida.mi.infn.it/~menasce/home.html
> |
> |
> |
> |   In a world without fences and walls, who needs Windows and Gates?
> |
> +------------------------------------------------------------------------+
> 
>   --------------------------------------------------------------------------------
> 
>                               Name: Dario.Menasce.vcf
>    Dario.Menasce.vcf          Type: VCard (text/x-vcard)
>                           Encoding: 7bit
>                        Description: Card for Dario Menasce



This archive was generated by hypermail 2b29 : Tue Jan 01 2002 - 17:51:02 MET