I am trying to write stl vector to tree :
[code]#include “TTree.h”
#include “TFile.h”
#include “vector”
#include <TBranch.h>
#include <TClass.h>
//using namespace std;
int main()
{
std::vector *a=new std::vector;
a->push_back(3.5);
TFile f(“tree.root”,“RECREATE”);
TTree t(“t”,“t”);
t.Branch(“a”,a);
t.Fill();
f.Write();
f.Close();
delete a;
}
[/code]
While executing , I get following error
Error in TTree::Branch: The pointer specified for a is not of a class or type known to ROOT
What should I do ?
[quote=“brun”]Replace
t.Branch("a",a);
by
Rene[/quote]
It seems , that it doesn’t change anything …
PS . I am using root v. 5.20 . Also I compiling this code (I’am not using CINT )
brun
4
You must generate a dictionary for your vector class (see guide) or simply use ACLIC, it will be automatic
//file V.C
#include "TTree.h"
#include "TFile.h"
#include "vector"
#include <TBranch.h>
#include <TClass.h>
//using namespace std;
int V()
{
std::vector<float> *a=new std::vector<float>;
a->push_back(3.5);
TFile f("tree.root","RECREATE");
TTree t("t","t");
t.Branch("a",&a);
t.Fill();
f.Write();
f.Close();
delete a;
return 0;
}
root > .L V.C+
root > V()
Rene
pcanal
5
Alternatively, you can also make sure to load the pre-generated dictonary for the vector by executing:gROOT->ProcessLine("#include <vector>");
Cheers,
Philippe