RE: Adding a vector to a tree

From: Philippe Canal <pcanal_at_fnal.gov>
Date: Fri, 19 Oct 2007 10:32:31 -0500


Hi Nicolas,

For compile code you need to use:

   gROOT->ProcessLine("#include <vector>"); so that the vector dlls is loaded into CINT and the ROOT meta data (as opposed to the compiled code itself).  

Cheers,
Philippe


From: Nicolas Busca [mailto:ngbusca_at_gmail.com] Sent: Friday, October 19, 2007 10:26 AM
To: Philippe Canal
Cc: 'Bin Guo'; roottalk_at_root.cern.ch
Subject: Re: [ROOT] Adding a vector to a tree

Hi Philippe,

your macro works ok for me when I run it as a macro (by doing .L ... ). It's when I run it as a compiled program that it gives the error message.

I'm using root 5.13/02 on a mac with the default options for building...

Thanks for your prompt responses,

Nicolas Busca

On Oct 19, 2007, at 5:25 PM, Philippe Canal wrote:

Hi,

I just re-tried the script I gave you:

{
#include <vector>
TFile *f = new TFile("peter.root", "recreate"); TTree * t1 = new TTree("nEmcPhotons", "EMC Photons"); vector<float> *E = new vector<float>;
t1->Branch("E", &E);
}

with ROOT 5.17/04 and it works fine for me. Which version of ROOT are you using? How was it build (in particular are the cintdlls built?).

Philippe


From: Nicolas Busca [mailto:ngbusca_at_gmail.com] Sent: Friday, October 19, 2007 10:16 AM
To: Philippe Canal
Cc: 'Bin Guo'; roottalk_at_root.cern.ch
Subject: Re: [ROOT] Adding a vector to a tree

Absolutely, I include vector.h in the beginning of my program... still I get the same error.

Thanks!

Nicolas.

On Oct 19, 2007, at 5:14 PM, Philippe Canal wrote:

Hi,

Did you try after doing:

> Also you need to make sure the dictionary for vector<float> is loaded (for
example add #include <vector>).

I.e. Try

{
#include <vector>
TFile *f = new TFile("peter.root", "recreate"); TTree * t1 = new TTree("nEmcPhotons", "EMC Photons"); vector<float> *E = new vector<float>;
t1->Branch("E", &E);
}

Philippe.


From: Nicolas Busca [mailto:ngbusca_at_gmail.com] Sent: Friday, October 19, 2007 10:08 AM
To: Philippe Canal
Cc: Bin Guo; roottalk_at_root.cern.ch
Subject: Re: [ROOT] Adding a vector to a tree

I tried to use the macro below in a compiled program, and I get an error at running time:

Error in <TTree::Branch>: The pointer specified for ... is not of a class known to ROOT

Any ideas?

Thanks!

Nicolas

On Oct 18, 2007, at 8:46 PM, Philippe Canal wrote:

Use
{
TFile *f = new TFile("peter.root", "recreate"); TTree * t1 = new TTree("nEmcPhotons", "EMC Photons"); vector<float> *E = new vector<float>;
t1->Branch("E", &E);
}

Also you need to make sure the dictionary for vector<float> is loaded (for example add #include <vector>).

Cheers,
Philippe.

Hi Rooters,

I want to add a vector to a root tree, and make it a branch of that tree. I found the example of adding an array to a tree like below:

{
TFile *f = new TFile("peter.root", "recreate"); Int_t nPhot;
Float_t E[500];
TTree * t1 = new TTree("nEmcPhotons", "EMC Photons"); t1->Branch("nPhot", &nPhot, "nPhot/I"); t1->Branch("E", E, "E[nPhot]/F");
}

Now if I want to change E[500] array above to a vector: "vector<float> E",
how do I change the t1->Branch("E", E, "E[nPhot]/F") line ?

Namely, how do I write the 3rd argument of the "Branch()" method for a
vector?

Thanks for the help!

Best,
Bin


Ils sont fous ces Romains


Ils sont fous ces Romains


Ils sont fous ces Romains Received on Fri Oct 19 2007 - 17:35:11 CEST

This archive was generated by hypermail 2.2.0 : Fri Oct 19 2007 - 23:50:02 CEST