Hello,
I'm a Root beginner, I'm trying to save a class to a TTree. Until now I managed to store and read "simple" type like int and STL objects, but not homemade objects.
I'm made a short example :
Code snippet :
#include <TFile.h>
#include <TTree.h>
#include <vector>
#include <iostream>
class Sample {
public: int i; std::vector<int> hits;
int main() {
Sample *s = new Sample();
TFile *f1 = new TFile("debug.root","RECREATE");
if (f1->IsZombie()) {
std::cerr << "! Unable to create debug.root" << std::endl;
return -1;
}
TTree *tree = new TTree("T","Debug");
//Case C
// MyClass object;
// TBranch *branch = tree->Branch(branchname, &object,
bufsize, splitlevel)
//
tree->Branch("debug",s);
for(int j=0;j<10;j++) {
s->hits.empty();
for(int i=0;i<100;i++) {
s->hits.push_back(42+i);
}
tree->Fill();
}
f1->Write();
delete s;
delete tree;
delete f1;
return 0;
I compile with
g++ -Wall -pedantic -pthread -m32
-I/home/bob/root/root-5.26.00d/include -c ttree_write.cxx -o
ttree_write.o
and I link with
g++ -L/home/bob/root/root-5.26.00d/lib -lNew -lCore -lCint -lRIO
-lNet -lHist -lGraf -lGraf3d -lGpad -lTree -lRint -lPostscript -lMatrix -lPhysics -lMathCore -lThread -pthread -lm -ldl -rdynamic -L/home/bob/root/root-5.26.00d/lib -lNew -lCore -lCint -lRIO -lNet -lHist -lGraf -lGraf3d -lGpad -lTree -lRint -lPostscript -lMatrix -lPhysics -lMathCore -lThread -lGui -pthread -lm -ldl -rdynamicttree_write.o -o ttree_write
When I run the program I got
Error in <TTree::Branch>: The pointer specified for debug is not of a
class known to ROOT
I'm sure that I miss an important step but I'm out of ideas ! Any tips ? Received on Mon Sep 27 2010 - 11:30:10 CEST
This archive was generated by hypermail 2.2.0 : Mon Sep 27 2010 - 11:50:01 CEST