Re: [ROOT] Problems with CINT and STL

From: Rene Brun (Rene.Brun@cern.ch)
Date: Tue Sep 25 2001 - 17:08:50 MEST


Hi Tommaso,

If you declare 
   vector<Track> ve;  // a vector of Track objects
then you should fill with
  ve.push_back(*tr); and not (tr)

if you declare
vector<Track*> ve;  // a vector of Track pointers
you should fill with
  ve.push_back(tr);
  
Note that in your particular example, you use a slow procedure.
Using a TClonesArray of Tracks will be about 3 times faster in I/O.

Rene Brun


Tommaso Chiarusi wrote:
> 
> Dear Rooters,
> 
> I have problems as I try to build STL vector containing objects
> which are related to a compile Classes (libMyClass.so).
> 
> When I was using the not-compiled class, i.e. the include files,
> it worked good!!!!!
> 
> I explain myself better:
> I have my own class Track.h .
> 
> I want to build a STL vector of Track objects,
> so I can do:
> 
> #include <vector>
> #include "Track.h"  // as header of the ROOT macro
> ...
> vector<Track> ve;
> Track *tr=new Track(0.2,23.2);
> ve.push_back(tr);
> 
> THIS PROCEDURE WORKS GOOD!
> 
> But now I need to retrieve tracks stored in a Tree, so I'm forced to use
> the compiled class library: I have produced the libTrack.so.
> Then, omitting the #include "Track.h" , I do:
> 
>     if(!TClassTable::GetDict("Track")){
>      gSystem->Load("mylib/libTrack.so");
>     }
> 
>     vector<Track> ve;
> 
> I make the usual opening of the Tree and addressing of the Track objects
> 
>    TTree *myTree = (TTree*)file_root->Get("t1");
>    TBranch *myBranch = myTree->GetBranch("tracks");
> 
>    Track *tr = new Track();
>    myBranch->SetAddress(&tr);
> 
> and get the entries one by one looping over the
> 
>   Int_t nevent = myTree->GetEntries();
> 
> so:
>   for(Int_t i=0;i<nevent;i++){
>     myBranch->GetEntry(i); // get the track
>     ve.push_back(tr);
>     }
> 
>  THIS FAILS!!!!!
> 
> What can it be?
> Is it something related to some Errors in compiling my class?
> 
> sorry if I disturb you again with a new problem.
> 
> Thanks and Cheers!
> 
> Tommaso



This archive was generated by hypermail 2b29 : Tue Jan 01 2002 - 17:51:00 MET