RE: problems retrieving <vector> object in ROOT

From: Philippe Canal <pcanal_at_fnal.gov>
Date: Fri, 17 Mar 2006 08:57:46 -0600


Hi Fab,

> First, I noticed that all objects of type vector<Type*> have been
> automatically commented out in the header file (macro.h):
> What is the reason for this ?

This is by design of the current implementation of MakeSelector. It reduces all the objects in the TTree down to their elementary types. When this is not possible it bails out (hence the commented lines). In this implementation MakeSelector assumes that you do not have a proper library for your object (even if you do). In addition it puts the TTree in mode that (by default) make it unable to use real objects.

By the look of your code fMCpart is itself containing a collection (either TClonesArray or vector) of MCPart.

As you can see the collection is deprecated to a series of dis-jointed c-style array of Double and Char_t.

  MCpart* mcp = fMCpart_Parents[j];
  Error: Incorrect assignment to mcp, wrong type 'vector<MCpart*>' FILE:muSel.C LINE:289

Technically this is the correct error message since fMCpart_Parents is defined as:

  vector<MCpart*> fMCpart_Parents[kMaxfMCpart];

i.e. a c-style array of vector and the following would compile

  MCpart* mcp = fMCpart_Parents[i][j];

would compile ... but is unlikely to result is something valid.

Instead you need to either use MakeProxy or to hand code your own TSelector so that it uses your objects (most importantly do no use SetMakeClass(1) and set the higher level object addresses:

  TClonesArray *fMCPart; // or vector<MCPart> whichever is correct   ...
  fChain->SetBranchAddress("fMCPart",&fMCpart):   ...   

Cheers,
Philippe.

-----Original Message-----
From: owner-roottalk_at_pcroot.cern.ch [mailto:owner-roottalk_at_pcroot.cern.ch] On Behalf Of Fabrizio Salvatore
Sent: Friday, March 17, 2006 6:51 AM
To: roottalk_at_pcroot.cern.ch
Subject: [ROOT] problems retrieving <vector> object in ROOT

Hi,

I'm running on some ROOT-tuples that have been produced using some non-native ROOT classes. I've loaded the appropriate library in ROOT where all those classes are defined and I've used the MakeSelector to create my macro.

First, I noticed that all objects of type vector<Type*> have been automatically commented out in the header file (macro.h):

//vector<float> fPFlow_PID_parameters[kMaxfPFlow];

Double_t        fMCpart_NumberofDaughters[kMaxfMCpart];  //[fMCpart_]
Double_t        fMCpart_NumberofParents[kMaxfMCpart];   //[fMCpart_]
UChar_t         fMCpart_InteractCal[kMaxfMCpart];   //[fMCpart_]
UChar_t         fMCpart_InteractTrk[kMaxfMCpart];   //[fMCpart_]
//vector<MCpart*> fMCpart_Parents[kMaxfMCpart]; //vector<MCpart*> fMCpart_Daughters[kMaxfMCpart];

What is the reason for this ?

I now need to access the info of objects of type MCpart* stored in the ROOT-tuple as vectors of MCpart objects and so I've commented out the above lines, and define for these types the branch, branch address, branch pointers:

    TBranch *b_fMCpart_Parents; //!     ...

    fChain->SetBranchAddress("fMCpart.Parents",fMCpart_Parents);     ....

    b_fMCpart_Parents = fChain->GetBranch("fMCpart.Parents");     .....

However, when in my macro I do the following command:

for(Int_t j=0; j<fNMCpart; j++) {

	MCpart* mcp = fMCpart_Parents[j];
	.....

}

my program crashes with the following error:

Error: Incorrect assignment to mcp, wrong type 'vector<MCpart*>' FILE:muSel.C LINE:289

What am I doing wrong ?

As far as I can see, ROOT does know about the vector<MCpart*> type, since if, from the ROOT prompt, I do:

root[0]vector<MCpart*> test;
root[1]test
(vector<MCpart*>)192369456

so the object of that type is defined. Or am I mis-interpreting everything ?

Thanks for any help !

                                Fab

-- 
#############################################################
Dr P-Fabrizio Salvatore            | Department of Physics
Phone: +44 (0)1784 44 3479         | Royal Holloway College
Fax: +44 (0)1784 47 2794           | University of London
e-mail: P.Salvatore_at_rhul.ac.uk     | Egham, Surrey, TW20 0EX
http://www.pp.rhul.ac.uk/~salvator | United Kingdom (UK)
#############################################################
Received on Fri Mar 17 2006 - 16:06:04 MET

This archive was generated by hypermail 2.2.0 : Mon Jan 01 2007 - 16:31:57 MET