I am having trouble in filling a vector of Class in TTree. Following is my code and error.
////////////bar.hxx
#include <vector>
#include "EventLoopFunction.h"
#include "TTree.h"
struct bar{ int id, type, charge;};
class qHit{
public:
int id;
std::vector<bar> qclsthit;
virtual ~qHit(){qclsthit.clear();};
void Print(){return;};
ClassDef(qHit,1)
};
class ReconCluster:public EventLoopFunction{
private:
TTree *fTree;
vector<bar> hit;
vector<qHit> qclst;
public:
ReconCluster(){};
virtual ~ReconCluster() {};
void Clear();
void Initialize();
bool operator()(Event&);
void Finalize();
void GetBarHits(Event&, vector<bar>*);
void GetQHits(vector<bar>&, vector<qHit>*);
};
/////////////////bar.cxx
#include "bar.hxx"
#include "TROOT.h"
ClassImp(qHit)
int main(int argc, char **argv){
gROOT->ProcessLine(".L /Users/analysis/ana/v0r0/include/loader.C+");
ReconCluster myCode;
EventLoop(argc,argv,myCode);
return 0;
}
void ReconCluster::Initialize(){
fTree = new TTree("tr","Cluster Tree");
fTree->Branch("bar","vector<bar>",&hit);
fTree->Branch("qHit","vector<qHit>",&qclst);
}
void ReconCluster::Clear(){
hit.clear();
qclst.clear();
}
bool ReconCluster::operator()(Event& ev){
GetBarHits(ev,&hit);
GetQHits(hit,&qclst);
fTree->Fill();
Clear();
return;
}
....
////////// Loader.C
#include "bar.hxx"
#include <vector>
#ifdef __MAKECINT__
#pragma link C++ class bar+;
#pragma link C++ class vector<bar>+;
#pragma link C++ class qHit+;
//#pragma link C++ class vector<qHit>+; commented for now
#endif
Compilation ERROR: (Macosx)
#CMT---> building application ../Darwin/clst_f.exe
Undefined symbols for architecture x86_64:
"vtable for qHit", referenced from:
qHit::qHit()in bar.o
qHit::~qHit()in bar.o
qHit::qHit(qCluster const&)in bar.o
"ROOT::GenerateInitInstance(qHit const*)", referenced from:
__static_initialization_and_destruction_0(int, int)in bar.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
make[3]: *** [../Darwin/clst_f.exe] Error 1
make[2]: *** [clst_f] Error 2
make[1]: *** [common_target] Error 2
make: *** [check_config] Error 2
Linux ERROR:
#CMT---> building application ../Linux-x86_64/clst_f.exe
../Linux-x86_64/bar.o: In function `__static_initialization_and_destruction_0':
/home/fumi/analysis/ana/v0r0/cmt/../src/bar.cxx:3: undefined reference to `ROOT::GenerateInitInstance(qHit const*)'
../Linux-x86_64/bar.o: In function `qHit':
/home/fumi/analysis/ana/v0r0/cmt/../src/../include/barhit.hxx:5: undefined reference to `vtable for qHit'
/home/fumi/analysis/ana/v0r0/cmt/../src/../include/barhit.hxx:5: undefined reference to `vtable for qHit'
/home/fumi/analysis/ana/v0r0/cmt/../src/../include/barhit.hxx:5: undefined reference to `vtable for qHit'
/home/fumi/analysis/ana/v0r0/cmt/../src/../include/barhit.hxx:5: undefined reference to `vtable for qHit'
/home/fumi/analysis/ana/v0r0/cmt/../src/../include/barhit.hxx:5: undefined reference to `vtable for qHit'
../Linux-x86_64/bar.o:/home/fumi/analysis/ana/v0r0/cmt/../src/../include/barhit.hxx:5: more undefined references to `vtable for qHit' follow
collect2: ld returned 1 exit status
make[3]: *** [../Linux-x86_64/clst_f.exe] Error 1
make[2]: *** [clst_f] Error 2
make[1]: *** [common_target] Error 2
make: *** [check_config] Error 2
The error looks like from virtual table of the class, not sure how to fix this.
Thanks for any help.