[ROOT] Unexpected reading of TH1 objects from a tree

From: Nesterov Stanislav (qleap@pnpi.spb.ru)
Date: Sun Jun 16 2002 - 22:38:21 MEST


Hi All,

I found a strange problem arising when you are trying to read TH1F objects 
from a TTree. We have a tree with several TH1F objects as TBranches (under 
different names). I understand clearly that this kind of object is not 
suitable for keeping inside a tree, but ROOT behavior in getting these 
histograms is very strange. Below I dump simple ROOT session where I opened 
TFile, created new TH1F object, set Branch Address, and then got several 
Entries from opened tree.
>>>>>>>>>>>>>>>>>>>>Session start<<<<<<<<<<<<<<<<<<<<<<<<<<<
 *******************************************
  *                                        *
  *        W E L C O M E  to  R O O T       *
  *                                         *
  *   Version   3.03/05       31 May 2002   *
  *                                         *
  *  You are welcome to visit our Web site  *
  *          http://root.cern.ch            *
  *                                         *
  *******************************************
root [0] TFile fl("res/run06.root")
root [1] fl.cd()                        
(Bool_t)1
root [2] pht = new TH1F;                              
root [3] .ls                                    
TFile**         res/run06.root
 TFile*          res/run06.root
  KEY: TTree    wheel;1 Measurement of TRT Wheel
root [4] wheel->Print()
>>>>>>>>>>>>>>>bla-bla-bla<<<<<<<<<<<<<<<<<<<<<<<<<<
*.........................................................................*
*Br   41 :RBckgr    : RBckg[3]/F                                          *
*Entries :       54 : Total  Size=        714 bytes  File Size  =       0 *
*Baskets :        0 : Basket Size=      32000 bytes  Compression=1.00     *
*.........................................................................*
*Br  42 :Spec      :                                                      *
*Entries :       54 : Total  Size=     323848 bytes  File Size  =   92614 *
*Baskets :       27 : Basket Size=      16000 bytes  Compression=3.50     *
*.........................................................................*
*Br  43 :RSpec     :                                                      *
*Entries :       54 : Total  Size=     324416 bytes  File Size  =  103221 *
*Baskets :       27 : Basket Size=      16000 bytes  Compression= 3.14    *
*.........................................................................*
root [5] wheel->SetBranchAddress("Spec",&pht);
root [6] .ls
TFile**         ../../fedin/wts_offline/res/run06.root
 TFile*         ../../fedin/wts_offline/res/run06.root
  OBJ: TTree    wheel   Measurement of TRT Wheel : 0
  KEY: TTree    wheel;1 Measurement of TRT Wheel
root [7] wheel->GetEntry(13)
(Int_t)12134
root [8] .ls
TFile**         ../../fedin/wts_offline/res/run06.root
 TFile*         ../../fedin/wts_offline/res/run06.root
  OBJ: TTree    wheel   Measurement of TRT Wheel : 0
  OBJ: TH1F     s1_3_2  Spectrum L==1  C==3  R==2 : 0
  OBJ: TH1F     r1_3_2  Reference spectrum L==1  C==3  R==2 : 0
  KEY: TTree    wheel;1 Measurement of TRT Wheel
root [9] wheel->GetEntry(24)
(Int_t)12134
root [10] .ls                
TFile**         ../../fedin/wts_offline/res/run06.root
 TFile*         ../../fedin/wts_offline/res/run06.root
  OBJ: TTree    wheel   Measurement of TRT Wheel : 0
  OBJ: TH1F     s1_5_1  Spectrum L==1  C==5  R==1 : 0
  OBJ: TH1F     r1_5_1  Reference spectrum L==1  C==5  R==1 : 0
  OBJ: TH1F     s1_5_1  Spectrum L==1  C==5  R==1 : 0
  OBJ: TH1F     r1_5_1  Reference spectrum L==1  C==5  R==1 : 0
  KEY: TTree    wheel;1 Measurement of TRT Wheel
root [11] wheel->GetEntry(2) 
(Int_t)12134
root [12] .ls               
TFile**         ../../fedin/wts_offline/res/run06.root
 TFile*         ../../fedin/wts_offline/res/run06.root
  OBJ: TTree    wheel   Measurement of TRT Wheel : 0
  OBJ: TH1F     s1_1_3  Spectrum L==1  C==1  R==3 : 0
  OBJ: TH1F     r1_1_3  Reference spectrum L==1  C==1  R==3 : 0
  OBJ: TH1F     s1_1_3  Spectrum L==1  C==1  R==3 : 0
  OBJ: TH1F     r1_1_3  Reference spectrum L==1  C==1  R==3 : 0
  OBJ: TH1F     s1_1_3  Spectrum L==1  C==1  R==3 : 0
  OBJ: TH1F     r1_1_3  Reference spectrum L==1  C==1  R==3 : 0
  KEY: TTree    wheel;1 Measurement of TRT Wheel
root [13] delete pht
root [14] .ls
TFile**         ../../fedin/wts_offline/res/run06.root
 TFile*         ../../fedin/wts_offline/res/run06.root
  OBJ: TTree    wheel   Measurement of TRT Wheel : 0
  OBJ: TH1F     r1_1_3  Reference spectrum L==1  C==1  R==3 : 0
  OBJ: TObject  TObject Basic ROOT object : 0
  OBJ: TH1F     r1_1_3  Reference spectrum L==1  C==1  R==3 : 0
  OBJ: TObject  TObject Basic ROOT object : 0
  OBJ: TH1F     r1_1_3  Reference spectrum L==1  C==1  R==3 : 0
  KEY: TTree    wheel;1 Measurement of TRT Wheel
root [15] r1_1_3->Delete()
root [16] .ls
TFile**         ../../fedin/wts_offline/res/run06.root
 TFile*         ../../fedin/wts_offline/res/run06.root
  OBJ: TTree    wheel   Measurement of TRT Wheel : 0
  OBJ: TObject  TObject Basic ROOT object : 0
  OBJ: TObject  TObject Basic ROOT object : 0
  OBJ: TObject  TObject Basic ROOT object : 0
  OBJ: TObject  TObject Basic ROOT object : 0
  KEY: TTree    wheel;1 Measurement of TRT Wheel
root [17] .q
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<End of Session>>>>>>>>>>>>>>>>>>
This is getting very odd. I just tried to get ONE histogram, but have got 
ALL of them in memory. And this is not all: histograms are duplicated with 
the same names. Deleting is not good for them: strange object still in 
memory. 

Yes I know: TH1 and TTree objects are reading into a memory by default, but 
for tree branch it is not very good default I think.
			   Best regards,
					Stanislav Nesterov.



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