Hi,
I want to create a branch in a tree with a TVector. I was however
unable to do so, since my simple macro crashes all the time. The macro
looks like:
-----
#include "TFile.h"
#include "TTree.h"
#include "TBranch.h"
#include "TVector3.h"
#include "TRandom.h"
#include <iostream>
using namespace std;
int createTreeTest2()
{
TFile hfile("Event.root","RECREATE");
// Create a ROOT Tree
TTree *tree = new TTree("T","An example of a ROOT tree");
TVector3* vp = new TVector3;
// Create one branch. If splitlevel is set, event is a superbranch
// creating a sub branch for each data member of the Event object.
cout << "Creating vp branch" << endl;
tree->Branch("vp","TVector3",vp);
cout << "Iterating over events" << endl;
// Fill event, header and tracks with some random numbers
for (Int_t ev = 0; ev < 50; ev++) {
Npa = 3;
for (int i = 0; i < Npa; i++) {
Double_t px = gRandom->Rndm(1);
Double_t py = gRandom->Rndm(1);
Double_t pz = gRandom->Rndm(1);
vp->SetXYZ(px,py,pz);
}
// Serialize single branch of event into one single basket
cout << "Filling tree" << endl;
tree->Fill();
}
tree->Print();
hfile.Write();
hfile.Close();
return 0;
}
-----
When I execute the macro I get the following message:
root [0] .x createTreeTest2.C
Creating vp branch
*** Break *** segmentation violation
Generating stack trace...
0x406c437a in G__CallFunc::Exec(void*) + 0x6e from
/home/iglez/root/lib/libCint.so
0x4017cf82 in TClass::BuildRealData(void*) + 0x2fa from
/home/iglez/root/lib/libCore.so
0x40c9fdbd in TTree::BuildStreamerInfo(TClass*, void*) + 0x31 from
/home/iglez/root/lib/libTree.so
0x40c9f7d2 in TTree::Bronch(char const*, char const*, void*, int, int) +
0x55e from /home/iglez/root/lib/libTree.so
0x40c9e5b5 in TTree::Branch(char const*, char const*, void*, int, int) +
0x41 from /home/iglez/root/lib/libTree.so
0x40cb7cae in <unknown> from /home/iglez/root/lib/libTree.so
0x40655f5e in G__call_cppfunc + 0x263 from
/home/iglez/root/lib/libCint.so
0x40645abe in G__interpret_func + 0x6ee from
/home/iglez/root/lib/libCint.so
0x4062d923 in G__getfunction + 0x12a2 from
/home/iglez/root/lib/libCint.so
0x406b119a in G__getstructmem + 0x82a from
/home/iglez/root/lib/libCint.so
0x406ab2b3 in G__getvariable + 0x4bc from /home/iglez/root/lib/libCint.so
0x40625006 in G__getitem + 0x5c1 from /home/iglez/root/lib/libCint.so
0x40623c4e in G__getexpr + 0x75ce from /home/iglez/root/lib/libCint.so
0x4066ad18 in G__exec_function + 0x1d5 from
/home/iglez/root/lib/libCint.so
0x4067188a in G__exec_statement + 0x23eb from
/home/iglez/root/lib/libCint.so
0x40647211 in G__interpret_func + 0x1e41 from
/home/iglez/root/lib/libCint.so
0x4062df8a in G__getfunction + 0x1909 from
/home/iglez/root/lib/libCint.so
0x40625036 in G__getitem + 0x5f1 from /home/iglez/root/lib/libCint.so
0x40623c4e in G__getexpr + 0x75ce from /home/iglez/root/lib/libCint.so
0x4061c32e in G__calc_internal + 0x2a4 from
/home/iglez/root/lib/libCint.so
0x4067738e in G__process_cmd + 0x2032 from
/home/iglez/root/lib/libCint.so
0x40176215 in TCint::ProcessLine(char const*, TInterpreter::EErrorCode*)
+ 0xa9 from /home/iglez/root/lib/libCore.so
0x40176322 in TCint::ProcessLineSynch(char const*,
TInterpreter::EErrorCode*) + 0x46 from /home/iglez/root/lib/libCore.so
0x400f3879 in TApplication::ProcessFile(char const*, int*) + 0x849 from
/home/iglez/root/lib/libCore.so
0x400f2fb5 in TApplication::ProcessLine(char const*, bool, int*) + 0x523
from /home/iglez/root/lib/libCore.so
0x40e77d4f in TRint::HandleTermInput() + 0x1dd from
/home/iglez/root/lib/libRint.so
0x40e76b92 in TTermInputHandler::Notify() + 0x24 from
/home/iglez/root/lib/libRint.so
0x40e78650 in TTermInputHandler::ReadNotify() + 0x12 from
/home/iglez/root/lib/libRint.so
0x401d98da in TUnixSystem::CheckDescriptors() + 0xea from
/home/iglez/root/lib/libCore.so
0x401d90b6 in TUnixSystem::DispatchOneEvent(bool) + 0xfe from
/home/iglez/root/lib/libCore.so
0x401465e8 in TSystem::InnerLoop() + 0x18 from
/home/iglez/root/lib/libCore.so
0x4014658d in TSystem::Run() + 0x6f from /home/iglez/root/lib/libCore.so
0x400f3a97 in TApplication::Run(bool) + 0x2d from
/home/iglez/root/lib/libCore.so
0x40e7784a in TRint::Run(bool) + 0x30c from
/home/iglez/root/lib/libRint.so
0x08048861 in main + 0x71 from /home/iglez/root/bin/root.exe
0x42015704 in __libc_start_main + 0xe4 from /lib/tls/libc.so.6
0x08048761 in _Unwind_Resume + 0x31 from /home/iglez/root/bin/root.exe
Root > Function createTreeTest2() busy flag cleared
Function () busy flag cleared
Function () busy flag cleared
and my terminal session blocks!... I am using Root 4.00/04 in a PC box
running Linux RH 9 (kernel 2.4.20-31.9).
Am I missing something?... Eventually I would like to store an array
of TVector3. I could not figure how to do this except using
the branch constructor for TClonesArray (which I did not manage to work
either).
Thanks for your help,
Isidro
--
+---------------------------+--------------------------------+
| Isidro González Caballero | mailto:Isidro.Gonzalez@cern.ch |
| IFCA (U. Cantabria/CSIC) | http://home.cern.ch/iglez/ |
| Avda. Los Castros s/n | -o- |
| Santander (Espańa) | Tel: +34 942201343 / 699413841 |
+---------------------------+--------------------------------+
This archive was generated by hypermail 2b29 : Sun Jan 02 2005 - 05:50:08 MET