Root v4 and v5 Tree::Branch()

Hello,
In Root 4 (4.00.08 and 4.2), I hooked up branches to trees like this:

   TClonesArray *reconVecTcaPtr =
      new TClonesArray ("TLorentzVector", 6);
   TTree *outputTreePtr = new TTree ("T4Vecs", "Six TLorentz Vectors");
   outputTreePtr->Branch ("recon", &reconVecTcaPtr);

This code doesn’t seem to compile for Root 5.

src/TreeFileInterface.cc: In member function `void TreeFileInterface::_hookupExtraCTBranches()':
src/TreeFileInterface.cc:758: error: invalid conversion from `void*' to `Int_t'
src/TreeFileInterface.cc:758: error:   initializing argument 2 of `virtual Int_t TTree::Branch(const char*, Int_t, Int_t)'

What I need is commands that work both for Root 4 and Root 5 (hopefully without using #ifdefs everywhere). Any ideas?

Cheers,
 Charles

p.s. Are these methods still supported in Root5?

   treePtr->Branch ("numJets ",   &numJets ,   "numJets/I");
   treePtr->Branch ("hepg",   "CLPHEPGCont",  &contPtr);

where CLPHEPGCont is a class with a dictionary?

Hi,

The code snippet you gave compiles correctly (as I would
expect) when I copy/paste it. Actually the error messagesrc/TreeFileInterface.cc:758: error: invalid conversion from `void*' to `Int_t'Indicates that somehow you code is more like (probably indirectly) void *reconVecTcaPtr = new TClonesArray ("TLorentzVector", 6); TTree *outputTreePtr = new TTree ("T4Vecs", "Six TLorentz Vectors"); outputTreePtr->Branch ("recon", (void*)&reconVecTcaPtr);
which defeats the purpose of the new enhanced interface which tries
to detect the type of the pointer being passed to Branch (instead
of assuming it is a TClonesArray).

So as you stated it, the code does indeed compile in ROOT 5.

If, for some reason, you really need to use a void* in the context
above, then you need to specify explictly the type: outputTreePtr->Branch ("recon", "TClonesArray", (void*)&reconVecTcaPtr);

[quote]p.s. Are these methods still supported in Root5?
treePtr->Branch ("numJets ", &numJets , “numJets/I”);
treePtr->Branch (“hepg”, “CLPHEPGCont”, &contPtr);
where CLPHEPGCont is a class with a dictionary?[/quote]

Yes, they are.

Cheers,
Philippe.

PS. Please do not post the same question on several forums …

[quote=“pcanal”]Hi,

The code snippet you gave compiles correctly (as I would
expect) when I copy/paste it. Actually the error messagesrc/TreeFileInterface.cc:758: error: invalid conversion from `void*' to `Int_t'Indicates that somehow you code is more like (probably indirectly) void *reconVecTcaPtr = new TClonesArray ("TLorentzVector", 6); TTree *outputTreePtr = new TTree ("T4Vecs", "Six TLorentz Vectors"); outputTreePtr->Branch ("recon", (void*)&reconVecTcaPtr);
which defeats the purpose of the new enhanced interface which tries
to detect the type of the pointer being passed to Branch (instead
of assuming it is a TClonesArray).
[/quote]

Busted :blush:

I have a std::map < std::string, void* > that contains all of my pointers.

This is exactly what I do when it’s not a TClonesArray. I can use “TClonesArray” in Root 4 as well?

[quote]
PS. Please do not post the same question on several forums …[/quote]

Sorry, we’re getting a little worried about moving to Root 5. I got a little antsy…

[quote]This is exactly what I do when it’s not a TClonesArray. I can use “TClonesArray” in Root 4 as well? [/quote]Yes, it should work.

Cheers,
Philippe

Just for completeness: As you suspected, it works fine under root 4. I do understand how adding the autodetect feature is nice, but it also would have been nice if it could have been implemented without breaking the old API as well (i.e., if it is just a void*, assume TClonesArray since that’s what was done in Root 4).

Thanks again for your help,
Charles