Re: TTree with user defined class

From: Bob <bob.velghe_at_gmail.com>
Date: Mon, 27 Sep 2010 12:41:46 +0200


Thanks John,

First I moved the class definition to Sample.h then I choose the ACLiC option to generate the dictionary (.L Sample.h+). I got two new file Sample_h.so and Sample_h.d

When I try to run the program I have exactly the same error : Error in <TTree::Branch>: The pointer specified for debug is not of a class or type known to ROOT.

I also tried to link ttree_write.o against the library Sample_h.so but without success, should I keep going in this way ? I'm a bit lost !

Thanks,

Bob

2010/9/27 John Idarraga <idarraga_at_cern.ch>:
> Hello Bob,
>
> Yeah, you need a dictionary, a couple of macros in your source file and
> that's it.  Check this out
>
> http://root.cern.ch/drupal/content/interacting-shared-libraries-rootcint
>
> if you have any trouble let me know,
>
> John Idarraga
>
> Bob wrote:
>>
>> 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 -rdynamic
>> ttree_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 - 12:41:51 CEST

This archive was generated by hypermail 2.2.0 : Mon Sep 27 2010 - 17:50:02 CEST