RE: Problem reading TTree in script

From: Philippe Canal <pcanal_at_fnal.gov>
Date: Thu, 21 Aug 2008 14:41:57 -0500


> ProcessId/I:XSec/D:NumEvents/I

This ordering of variable (int, double, int) has several know problem. In particular TTree, CINT and the compiler can (and do) pad them differently (hence the random value for XSec (and likely NumEvent too).

You must either put those variable in 3 different branches (recommended) or sort them in decreaseing size order (i.e: XSec/D:ProcessId/I:NumEvents/I)

> For information, sometimes when using a
> TBrowser, trees just vanish from the left hand heirarchical view - I
> wonder if this build is actually unstable?

Under what circunstances? The TTree object is associated with the TFile object and thus if the TFile is deleted the TTree will also be deleted.

Cheers,
Philippe.

-----Original Message-----
From: owner-roottalk_at_root.cern.ch [mailto:owner-roottalk_at_root.cern.ch] On Behalf Of James Jackson
Sent: Thursday, August 21, 2008 2:35 PM
To: roottalk_at_root.cern.ch
Subject: [ROOT] Problem reading TTree in script

Hi,

I have a very simple tree, with one branch, and one entry:



**
*Tree :Process : Process
information                                    *
*Entries :        1 : Total =            1206 bytes  File  Size  
=        492 *
*        :          : Tree compression factor =    
1.00                       *
****************************************************************************
**
*Br 0 :Process : ProcessId/I:XSec/D:NumEvents/
I                         *
*Entries :        1 : Total  Size=        862 bytes  One basket in  
memory    *
*Baskets :        0 : Basket Size=      32000 bytes  Compression=    
1.00     *
*...........................................................................
.*

Looking at this with a TBrowser, I can plot each leaf and read off the correct value. Attempting to do this in a script doesn't work:

<code>
struct Process
{

   Int_t procId;
   Double_t xSec;
   Int_t numEvents;
};

Process process;

void test()
{

   TChain proc("Process");
   proc.Add("PhotonJets_120_170/clusterHistos_1.root/diEmAnalysis/ Process");

   proc.SetBranchAddress("Process", &process.procId);    proc.GetEvent(0);

   std::cout << "   ID: " << process.procId << std::endl;
   std::cout << "   XS: " << process.xSec << " (pb)" << std::endl;
   std::cout << "   Number of events: " << process.numEvents <<  
std::endl;
}
</code>

When run:

Processing test.c...

   ID: 125
   XS: 4.24404e-310 (pb)
   Number of events: 0

Process ID is correct, but XS and Number of events are wrong (should be 275 and 20,000). This is using ROOT version 5.20/00, built from source on an Intel Mac running Mac OS X 10.5.4. I would be grateful if anyone could help with this. For information, sometimes when using a TBrowser, trees just vanish from the left hand heirarchical view - I wonder if this build is actually unstable?

Regards,
James Jackson. Received on Thu Aug 21 2008 - 21:42:02 CEST

This archive was generated by hypermail 2.2.0 : Thu Aug 21 2008 - 23:50:01 CEST