Problem reading class tree branch

From: James Jackson <james.jackson_at_cern.ch>
Date: Fri, 29 Aug 2008 10:05:00 +0100


Hi,

Following on from previous problems with "a/D:b/I:c/D" branch ordering, I have re-written my code to store a C++ class. I again have the same problem: I can read the data just fine in a TBrowser (including plotting the result of class member functions, namely one which calls TClonesArray::GetLast() ), however when I try and read the data in a script I just get jargon.

Compile libraries / dictionaries:

james-jacksons-macbook-pro:RootLibs jamesjackson$ root -l root [0] .L Process.cc+
Info in <TUnixSystem::ACLiC>: creating shared library /Users/ jamesjackson/Documents/Development/TracklessQuickTest/RootLibs/./ Process_cc.so
root [1] .L JJSuperCluster.cc+
Info in <TUnixSystem::ACLiC>: creating shared library /Users/ jamesjackson/Documents/Development/TracklessQuickTest/RootLibs/./ JJSuperCluster_cc.so
root [2] .L JJEvent.cc+
Info in <TUnixSystem::ACLiC>: creating shared library /Users/ jamesjackson/Documents/Development/TracklessQuickTest/RootLibs/./ JJEvent_cc.so
/Users/jamesjackson/Documents/Development/TracklessQuickTest/ RootLibs/./JJEvent.cc:42: warning: unused parameter ‘sc’ /Users/jamesjackson/Documents/Development/TracklessQuickTest/ RootLibs/./JJEvent.cc:42: warning: unused parameter ‘cutResults’

Attempt to read data:

<code>
#include "JJEvent.h"
#include "Process.h"

#include <iostream>

void test()
{

    // Load data libraries

    gSystem->Load("Process_cc.so");
    gSystem->Load("JJSuperCluster_cc.so");
    gSystem->Load("JJEvent_cc.so");

    // Open file and get trees
    TFile f("clusterHistos.root");
    TDirectory *d = (TDirectory*)f.Get("diEmAnalysis");     TTree *eventTree = (TTree*)d->Get("Events");     TTree *processTree = (TTree*)d->Get("Process");

    // Attach data members
    JJEvent *event = 0;
    Process *process = 0;
    eventTree->SetBranchAddress("Events", &event);     processTree->SetBranchAddress("Process", &process);

    // Read event tree
    UInt_t numEvents = eventTree->GetEntries();     for(UInt_t i = 0; i < numEvents; ++i)     {

       // Get current event
       eventTree->GetEntry(i);

       // Print the number of superclusters
       std::cout << event->EventNumber << std::endl;
       std::cout << "  " << event->GetNumberOfSuperClusters() <<  
std::endl;

    }
}
</code>

This just spits out garbage:

<output>
0

   44717842
1

   44717842
2

   44717842
0

   44717842
3

   44717842
</output>

where clearly the event number should be monotonically increasing (confirmed by plotting from TBrowser), and the count is clearly wrong.

I would appreciate any advice on how to solve this, I am (still) very confused. An example root file, the class definitions and the above test script are available from:

/afs/cern.ch/user/j/jacksonj/public/RootTest-29082008.tgz

Running this code on a different machine results in a segmentation violation and a stack trace:

Regards,
James. Received on Fri Aug 29 2008 - 11:05:10 CEST

This archive was generated by hypermail 2.2.0 : Tue Sep 02 2008 - 11:50:02 CEST