Re: [ROOT] TChains doesn't read a second file

From: Rene Brun (Rene.Brun@cern.ch)
Date: Tue Feb 05 2002 - 08:38:33 MET


Hi Karl,

When using TChain, the branch address(es) must be set via
   chain.SetBranchAddress(branchname,...
and not via
   TBranch *branch = chain.GetBranch(branchname);
   branch->SetAddress(..);

The second form returns the pointer to the branch of the current Tree in the
chain (typically the first one) and the information is lost when the next Tree
is loaded. I realize that this should be better documented. I do not see an easy
way
to accept the second form in a transparent way.

Suzanne, could you add this remark in the documentation. ?

Rene Brun

K. Hauschild wrote:
> 
> Dear Thomas,
> 
> Did you ever sort out the TChain problem :
> 
> >Hi rooters,
> >
> >I have two identical files (same trees, branches, etc. except the number
> >of stored events and the data which is stored). I use a chain to read
> >both files.
> >This works fine for the first file. But the TChain object doesn't read
> >the last file. It returns the last event of the first file n-times
> >(where n is the number of events in the second file)
> >What can be wrong?
> >
> >Thanks,
> >Thomas.
> 
> I am currently having a similar problem with the following file,
> Version 3.02/07, and Solaris 5.9.
> 
> Is this related to LoadTree() ? or am I not defining addresses
> correctly ?
> 
> Thanks,
> 
> Karl
> **********************************************************************
> #include <stdlib.h>
> #include <stdio.h>
> #include <string.h>
> 
> int ReadTree();
> 
> #ifndef __CINT__
> #include "CintIncludes.h"
> 
> #include "ProtoExoScan.h"
> #include "ProtoExoScan.cxx"
> 
> //______________________________________________________________________
> int main()
> {
>   int n = ReadTree();
>   return n;
> }
> #endif
> 
> #define TRIGGER  1
> #include "hdrs/Define.h"
> 
> #define DATAFILE "/home/crash6/gamma/karl/ScanB.root"
> 
> static int bits[4] = {1,2,4,8};
> 
> //______________________________________________________________________
> //______________________________________________________________________
> 
> int ReadTree()
> {
> #ifdef __CINT__
>   //Load class if needed
>   if (!TClassTable::GetDict("ProtoExoScan")) {
>     gSystem.Load("libProtoExoScan.so");
>   }
> #endif
> 
>   //Compressed Scanning Data event class
>   //ProtoExoScan::Class()->IgnoreTObjectStreamer(); //Remove fUniqueId,
> fBits
> 
>   TChain *chain = new TChain("Crystal B");   //Chain the tree "Crystal
> B"
> 
>   chain->Add("/home/crash6/gamma/karl/ScanB.root");
>   if (chain == 0) return 0;
>   Int_t nevents1 = Int_t(chain->GetEntries());
>   printf("\n %d events",nevents1);
> 
>   chain->Add("/home/crash6/gamma/karl/ScanB2.root");
>   if (chain == 0) return 0;
>   Int_t nevents = Int_t(chain->GetEntries());
>   printf("\n %d events",nevents);
>   chain.Draw("fX");
>   //return 0;
> 
>   //===============================================
>   // Specify address where to read the event object
>   // The event was stored in a branch called "Prototype"
>   //===============================================
> 
>   //object must be created before setting the branch address
>   ProtoExoScan *Data = new ProtoExoScan();
> 
>   //Super branch : CompData
>   TBranch *branch = chain->GetBranch("ProtoType");
>   branch->SetAddress(&Data);
> 
>   //Trigger Energy/Time branch
>   TBranch *bTrigE = chain->GetBranch("fTrigger_E");
> 
>   //Scan Position branches
>   TBranch *bX = chain->GetBranch("fX");
>   TBranch *bY = chain->GetBranch("fY");
> 
> 
>   //Output Root File
>   TFile *hfile = new TFile("tempspec.root","RECREATE","Scanning Crystal
> B");
>   Int_t comp = 3;        // by default all files compressed
>   hfile->SetCompressionLevel(comp);
> 
>   //Data Rates
>   TStopwatch timer;
>   timer.Start();
>   double told  = timer.RealTime();
>   double start = timer.RealTime();
>   timer.Continue();
>   double tnew = 0;
>   int    printev = 1000;
> 
>   //Data Variables
>   unsigned char pulse[4][250];
>   unsigned char **p_pulse;
> 
>   int x, y, Gamma, Sid;
>   int iGamma[4] = {121,344,964,1408};
>   int nCrystals, nSegments;
>   int segE[4], segT[4];
>   int num;
>   int TrigE, TrigT;
>   Int_t  seg, i, j, n;
>   Int_t  ngam = 4;
>   Int_t  nseg = 4;
>   Int_t jentry, ientry;
>   Int_t nbytes = 0;
>   Int_t nb = 0;
> 
> 
> #include "hdrs/HistDefs.h"
> 
>   //Loop over all chained events.....
>   for (jentry=0; jentry<nevents;jentry++) {
> 
>     ientry = chain->LoadTree(jentry);
> 
>     //////////////////////////////////////////////////////
>     //Examine ALL Data
>     nb = chain->GetEntry(jentry); nbytes += nb;
>     Data->GetData(&x, &y, &TrigE, &TrigT, &segE[0], &segT[0],
> &pulse[0][0]);
> 
>     //Read just the Trigger Energy
>     //nb = bTrigE->GetEntry(jentry);
>     //assign trigger energy
>     //TrigE = Data->GetTrigger_E();
>     //hTrigger_E->Fill(TrigE);
> 
> 
>     //Read just the Position
>     //nb = bX->GetEntry(jentry); nbytes += nb;
>     //nb = bY->GetEntry(jentry); nbytes += nb;
> 
>     //assign position...
>     //Data->GetPosition(&x, &y);
>     hPosition->Fill(x,y);
> 
> 
>     // Timing
>     //if ( (jentry%printev == 0) && (jentry != 0) ) {
>     if ( (jentry%15000 == 0) && (jentry != 0) ) {
>       tnew = timer.RealTime();
>       printf("Entry:%d, rtime=%.2f s -> %.2f Events/s [%.2f]\n",
>              jentry,tnew-told,(printev)/(tnew-told),0.001*nbytes/(tnew-told));
>       told=tnew; nbytes = 0;
>       timer.Continue();
>     }
>   }
> 
>   hfile->Write();
>   hfile->Close();
>   //if (f) f->Close();
> 
>   return jentry;
> }
> 
> ==========================================================================
> 
> CEA Saclay, DAPNIA/SPhN                Phone  : (33) 01 69 08 7553
> Bat 703 - l'Orme des Merisiers         Fax    : (33) 01 69 08 7584
> F-91191 Gif-sur-Yvette                 E-mail :  khauschild@cea.fr
> France
> karl_hauschild@yahoo.co.uk
>                                        WWW:
> http://www-dapnia.cea.fr/Sphn



This archive was generated by hypermail 2b29 : Sat Jan 04 2003 - 23:50:40 MET