RE : TTree with user defined class

From: Bob <bob.velghe_at_gmail.com>
Date: Mon, 27 Sep 2010 15:59:34 +0200


Thanks a lot ! After some minor modifications everything run fine "inside" root.

Right now I'll continue to work like this that but my final goal is to be able to run my program as a standalone binary, compiled with standard tools, and linked with the Root libraries.

Any idea to make this happen ?

Bob

2010/9/27 John Idarraga <idarraga_at_cern.ch>:
> Well, if he is compiling with ACLIC
>
> .L Sample.h++
>
> he doesn't need to load the lib ... it is already loaded.
>
> John
>
> Ahmed Ali Abdelalim wrote:
>>
>> Hi Bob,
>>  you compiled and linked now you need to tell ROOT to loaded your library
>> .To do this you have two ways:
>>   1- login to root then do
>>       gSystem->Load("libMyLib.so");
>> before execute your code.
>>  2- make a root map file ( for ex.: myLib.rootmap) to tell root to load
>> your library when it starts. the format is trivial like,
>>  Library.TmyLib:                              libMyLib.so
>>  hth
>>  Cheers,
>>  Ahmed
>>  ##################################################
>> #Ahmed Ali Abdelalim      Phone(Uni):+41223796213
>> #University of Geneva     mobil: +41 78 611 7329 #Physics Section, DPNC
>>                         #
>>  #CERN PH/UAT (ATLAS),     Phone:+412276 74279     #Office: 40-1-D32
>>                        #CH-1211 Geneve 23 Switzerland.
>>  ##################################################
>>
>> ------------------------------------------------------------------------
>> *De:* owner-roottalk_at_root.cern.ch de la part de Bob
>> *Date:* lun. 9/27/2010 12:41
>> *À:* roottalk_at_lxroot01.cern.ch
>> *Objet :* Re: [ROOT] TTree with user defined class
>>
>> 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 - 15:59:40 CEST

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