Hello,
I have a tree I wrote to disk like this
detectorTree = new TTree ( "Detectors","Detector Tree" );
recordedEvent = new BETAEvent();
detectorTree->Branch ( "aBetaEvent","BETAEvent",&recordedEvent );
// .. adding data and filling etc...
I can open up a TBrowser and everything looks fine (the data is there)
However when I try to read in the tree to do some analysis like this :
gROOT->ProcessLine(".L BETAEvent.C");
BETAEvent * event = new BETAEvent();
TFile * f = new TFile("data/beta.run.10825.root");
TTree *t = (TTree*)f->Get("Detectors");
t->SetBranchAddress("aBetaEvent", &event);
Int_t nevent = t->GetEntries();
for (int i=0;i<nevent;i++)
{
gDebug=2;
t->GetEvent(i); // <- Crashes here
}
I get the infamous *** Break *** segmentation violation
Any ideas why?
Thanks in advance!
-Whitney
pcanal
August 22, 2009, 5:10pm
2
Hi,
You must compile the user object/class. Use gROOT->ProcessLine(".L BETAEvent.C+");
Cheers,
Philippe
Thanks for your response.
I made said changes and now it crashes at setting the branch address! However, I noticed after executing the script and getting :
*** Break *** segmentation violation
if I just run the script again ( .x EventDisplay.cxx)
without leaving the interpreter it appears to run fine!???
Any ideas what to do to fix this?
Thanks
pcanal
August 24, 2009, 3:55pm
4
Hi,
Can you provide a complete running example showing the issue?
Philippe.
In the tar file you will find the output of two sessions one without gDebug and one with gDebug=2.
After executing the script again (up arrow then return) it runs smoothly (as can be seen in the output)
I include the script and the event class code as well. There is also a root file which contains a tree with a few events.
Thanks!
buggy_event.tar (730 KB)
pcanal
August 24, 2009, 4:57pm
6
Hi,
The problem, as shown by valgrind:root [0] .x EventDisplay.cxx
==11080== Conditional jump or move depends on uninitialised value(s)
==11080== at 0x7BAE7A0: BETAEvent::~BETAEvent() (BETAEvent.C:18)
==11080== by 0x4E9F582: TClass::BuildRealData(void*, bool) (TClass.cxx:1333)
is a missing initialization in the constructor of BETAEvent. Use:[code] BETAEvent::BETAEvent() : fChain(0)
{
// if parameter tree is not specified (or zero), connect the file
// used to generate this class and read the Tree.
}[/code]
Cheers,
Philippe
SOLVED. After making the correction to BETAEvent it now works properly.
Thanks for your help!
Cheers,
Whit