Re: [ROOT] Problem w/ TTree::MakeSelector code used stand-alone

From: Rene Brun (Rene.Brun@cern.ch)
Date: Thu Oct 18 2001 - 09:25:21 MEST


Hi Chris,

I do not see a problem with this basic example. Using your generator
example, I created the two files testSel.h and testSel.C (in attachment).
I modified testSel.C in ProcessCut, adding the two statements:
   b_p->GetEntry(entry);
   printf("p=%f\n",p);

then, from an interactive ROOT session, I did
 
root [0]   TFile *f= new TFile("test.root");
root [1]   TTree *t= (TTree*)f->Get("test");
root [2]  .L testSel.C++
root [3]   testSel selector;
root [4]   t->Process(&selector);

This gives:

p=3.200000
p=2.100000
p=2.400000


Rene Brun

Chris Roat wrote:
> 
> Hi ROOTers,
> 
> I am having a problem using the code generated by TTree::MakeSelector in a
> standalone application.  Below I show how I create a very basic tree with
> one branch, "p", that is filled with three entries.  I then run
> MakeSelector to generate an analysis skeleton.  I add ClassDef(test,1) and
> ClassImp(testSel) macros to the resulting skeleton files.
> 
> Making an appropriate LinkDef file, I compile and run the simple main
> program, also shown below.  It runs fine, but at this point the skeleton
> is still empty - a sterile application.  I add the following simple line
> to testSel::ProcessCut(),
> 
> b_p->GetEntry(entry);
> 
> which is, I think, supposed to fill the branch with the entry - based on
> my experience on the command line.  The code compiles without hassle, but
> then I get a seg fault when the new line runs.  The traceback is shown
> below.
> 
> I am running on a linux box with g++-2.95.2, ROOT version 3.01/06.
> 
> Can someone point me to what I am doing wrong?  Thanks much,
> Chris
> 
> // create a basic tree
> 
> hfile = new TFile("test.root","RECREATE");
> tree = new TTree("test","A Tree");
> Float_t p;
> b = tree->Branch("p", &p, "p/F" );
> p= 3.2; tree->Fill();
> p= 2.1; tree->Fill();
> p= 2.4; tree->Fill();
> hfile->Write();
> tree->MakeSelector("testSel")
> 
> // main program
> 
> #include <TTree.h>
> #include <TFile.h>
> #include "testSel.h"
> 
> int main() {
> 
>   TROOT myroot("myroot","Required TROOT object");
>   TFile *f= new TFile("test.root");
>   TTree *t= (TTree*)f->Get("test");
>   testSel selector;
>   t->Process(&selector);
>   return 0;
> 
> }
> 
> // traceback
> 
> (gdb) where
> #0  0x400d8204 in TBuffer::ReadFastArray () from
> /afs/slac.stanford.edu/g/babar/package/root/3.01-06/Linux2/lib/libCore.so
> #1  0x40a6d3b6 in TLeafF::ReadBasketExport () from
> /afs/slac.stanford.edu/g/babar/package/root/3.01-06/Linux2/lib/libTree.so
> #2  0x40a5c397 in TBranch::GetEntryExport () from
> /afs/slac.stanford.edu/g/babar/package/root/3.01-06/Linux2/lib/libTree.so
> #3  0x804b5e3 in testSel::ProcessCut (this=0xbfffeec0, entry=0) at
> testSel.C:49
> #4  0x40dafd4d in TTreePlayer::Process () from
> /afs/slac.stanford.edu/g/babar/package/root/3.01-06/Linux2/lib/libTreePlayer.so
> #5  0x40a766ab in TTree::Process () from
> /afs/slac.stanford.edu/g/babar/package/root/3.01-06/Linux2/lib/libTree.so
> #6  0x804b33f in main () at pid.C:11

//////////////////////////////////////////////////////////
//   This class has been automatically generated 
//     (Thu Oct 18 09:00:54 2001 by ROOT version3.02/01)
//   from TTree test/A Tree
//   found on file: test.root
//////////////////////////////////////////////////////////


#ifndef testSel_h
#define testSel_h

#include <TROOT.h>
#include <TChain.h>
#include <TFile.h>
#include <TSelector.h>

class testSel : public TSelector {
   public :
   TTree          *fChain;   //!pointer to the analyzed TTree or TChain
//Declaration of leaves types
   Float_t         p;

//List of branches
   TBranch        *b_p;   //!

   testSel(TTree *tree=0) {;}
   ~testSel() {;}
   void    Begin(TTree *tree);
   void    Init(TTree *tree);
   Bool_t  Notify();
   Bool_t  ProcessCut(Int_t entry);
   void    ProcessFill(Int_t entry);
   void    Terminate();
};

#endif

#ifdef testSel_cxx
void testSel::Init(TTree *tree)
{
//   Set branch addresses
   if (tree == 0) return;
   fChain    = tree;
   fChain->SetMakeClass(1);

   fChain->SetBranchAddress("p",&p);
}

Bool_t testSel::Notify()
{
//   called when loading a new file
//   get branch pointers
   b_p = fChain->GetBranch("p");
   return kTRUE;
}

#endif // #ifdef testSel_cxx






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