I was not very successful in saving trees with vectors in my own program, so I started picking apart hvector.C example hoping to understand what I’m doing wrong. Instead, I found that I can;t run that one as a standalone program either.
I changed it in such away that only the write() routine and some other essential stuff is left:
//
// This tutorials demonstrate how to store and restore simple vectors
// in a TTree
//
#include <vector>
#include "TFile.h"
#include "TTree.h"
#include "TCanvas.h"
#include "TFrame.h"
#include "TH1F.h"
#include "TBenchmark.h"
#include "TRandom.h"
#include "TSystem.h"
#ifdef __MAKECINT__
#pragma link C++ class vector<float>+;
#endif
void write()
{
TFile *f = TFile::Open("hvector.root","RECREATE");
if (!f) { return; }
std::vector<float> vpx;
std::vector<float> vpy;
std::vector<float> vpz;
std::vector<float> vrand;
// Create a TTree
TTree *t = new TTree("tvec","Tree with vectors");
t->Branch("vpx",&vpx);
t->Branch("vpy",&vpy);
t->Branch("vpz",&vpz);
t->Branch("vrand",&vrand);
gRandom->SetSeed();
for (Int_t i = 0; i < 25000; i++) {
Int_t npx = (Int_t)(gRandom->Rndm(1)*15);
vpx.clear();
vpy.clear();
vpz.clear();
vrand.clear();
for (Int_t j = 0; j < npx; ++j) {
Float_t px,py,pz;
gRandom->Rannor(px,py);
pz = px*px + py*py;
Float_t random = gRandom->Rndm(1);
vpx.push_back(px);
vpy.push_back(py);
vpz.push_back(pz);
vrand.push_back(random);
}
t->Fill();
}
f->Write();
delete f;
}
//void hvector()
int main()
{
// gBenchmark->Start("hvector");
write();
// read();
// gBenchmark->Show("hvector");
return 0;
}
When I compile (this part is fine) and run it, I get the following output:
Error in TTree::Branch: The pointer specified for vpx is not of a class or type known to ROOT
Error in TTree::Branch: The pointer specified for vpy is not of a class or type known to ROOT
Error in TTree::Branch: The pointer specified for vpz is not of a class or type known to ROOT
Error in TTree::Branch: The pointer specified for vrand is not of a class or type known to ROOT
and the root file is empty. Could you, please, tell me what my blunder is. I am using root v5.20, gcc version 4.1.3
I was not very successful in saving trees with vectors in my own program, so I started picking apart hvector.C example hoping to understand what I’m doing wrong. Instead, I found that I can;t run that one as a standalone program either.
I changed it in such away that only the write() routine and some other essential stuff is left:
//
// This tutorials demonstrate how to store and restore simple vectors
// in a TTree
//
#include <vector>
#include "TFile.h"
#include "TTree.h"
#include "TCanvas.h"
#include "TFrame.h"
#include "TH1F.h"
#include "TBenchmark.h"
#include "TRandom.h"
#include "TSystem.h"
#ifdef __MAKECINT__
#pragma link C++ class vector<float>+;
#endif
void write()
{
TFile *f = TFile::Open("hvector.root","RECREATE");
if (!f) { return; }
std::vector<float> vpx;
std::vector<float> vpy;
std::vector<float> vpz;
std::vector<float> vrand;
// Create a TTree
TTree *t = new TTree("tvec","Tree with vectors");
t->Branch("vpx",&vpx);
t->Branch("vpy",&vpy);
t->Branch("vpz",&vpz);
t->Branch("vrand",&vrand);
gRandom->SetSeed();
for (Int_t i = 0; i < 25000; i++) {
Int_t npx = (Int_t)(gRandom->Rndm(1)*15);
vpx.clear();
vpy.clear();
vpz.clear();
vrand.clear();
for (Int_t j = 0; j < npx; ++j) {
Float_t px,py,pz;
gRandom->Rannor(px,py);
pz = px*px + py*py;
Float_t random = gRandom->Rndm(1);
vpx.push_back(px);
vpy.push_back(py);
vpz.push_back(pz);
vrand.push_back(random);
}
t->Fill();
}
f->Write();
delete f;
}
//void hvector()
int main()
{
// gBenchmark->Start("hvector");
write();
// read();
// gBenchmark->Show("hvector");
return 0;
}
When I compile (this part is fine) and run it, I get the following output:
Error in TTree::Branch: The pointer specified for vpx is not of a class or type known to ROOT
Error in TTree::Branch: The pointer specified for vpy is not of a class or type known to ROOT
Error in TTree::Branch: The pointer specified for vpz is not of a class or type known to ROOT
Error in TTree::Branch: The pointer specified for vrand is not of a class or type known to ROOT
and the root file is empty. Could you, please, tell me what my blunder is. I am using root v5.20, gcc version 4.1.3
[quote]When I compile (this part is fine) and run it, I get the following output:
Error in TTree::Branch: The pointer specified for vpx is not of a class or type known to ROOT
Error in TTree::Branch: The pointer specified for vpy is not of a class or type known to ROOT
Error in TTree::Branch: The pointer specified for vpz is not of a class or type known to ROOT
Error in TTree::Branch: The pointer specified for vrand is not of a class or type known to ROOT
[/quote]As the message tries to hint, you are missing the dictionary for the class being used. In your case this is the class ‘vector’. You must either generate generate a dictionary with rootcint, compile and link the result, or you can use the provided dictionary for vector by adding the line#include "TROOT.h"[code]and add to your main function the line:[code]gROOT->ProcessLine("#include <vector>");.
[quote=“pcanal”][quote]When I compile (this part is fine) and run it, I get the following output:
Error in TTree::Branch: The pointer specified for vpx is not of a class or type known to ROOT
Error in TTree::Branch: The pointer specified for vpy is not of a class or type known to ROOT
Error in TTree::Branch: The pointer specified for vpz is not of a class or type known to ROOT
Error in TTree::Branch: The pointer specified for vrand is not of a class or type known to ROOT
[/quote]As the message tries to hint, you are missing the dictionary for the class being used. In your case this is the class ‘vector’. You must either generate generate a dictionary with rootcint, compile and link the result, or you can use the provided dictionary for vector by adding the line#include "TROOT.h"[code]and add to your main function the line:[code]gROOT->ProcessLine("#include <vector>");.