Hi Patrick,
You forgot the declaration of SubEventSTL in your myLinkDef.h.
This file should be:
//------------------file myLinkDef.h
#ifdef __CINT__
#pragma link off all globals;
#pragma link off all classes;
#pragma link off all functions;
#pragma link C++ class EventSTL+;
#pragma link C++ class SubEventSTL+;
#endif
Also note that you can remove the declaration of the obsolete TROOT
constructor in your main program.
Rene Brun
On Mon, 21
Apr 2003, Patrick Murray wrote:
> If I have a class made of a hierarchy of classes in pure C++ (ie no
> ClassDef stuff) and I want to put this class into a root tree without
> changing the orginal class, can it be done the with inheritance into a
> root class (ie with ClassDef). Something like:
>
> #include "TObject.h"
> #include <vector>
> #include "MyC++Class.h"
>
> class RootClass : public MyC++Class
> {
> public:
> RootClas();
> virtual ~RootClass();
> ClassDef(RootClass,1)
> };
>
> also how deep into the hierarchy must I go. I tried tried to modofy one of
> the examples by adding a pure C++ class SubEventSTL and adding a data
> member SEVector which is a vector of SubEventSTL objects. It compiled but
> gave the following errors:
>
> [pmurray@ccc04 sample]$ ./STL
> UNKNOW type, sopen=SubEventSTL
> Size: 0 - Contents :
> 0 1 2 3 4 5 6 7 8 9here 1:0
>
> *** Break *** segmentation violation
> Generating stack trace...
> 0x401cd7d7 in TUnixSystem::StackTrace(void) + 0x25b from
> /usr/local/lib/root/libCore.so.3.05
> 0x401cc3ce in TUnixSystem::DispatchSignals(ESignals) + 0xb2 from
> /usr/local/lib/root/libCore.so.3.05
> 0x401cb59b in <unknown> from /usr/local/lib/root/libCore.so.3.05
> 0x401cf099 in <unknown> from /usr/local/lib/root/libCore.so.3.05
> 0x40881848 in <unknown> from /lib/i686/libc.so.6
> 0x4019287d in TClass::Streamer(void *, TBuffer &) + 0x21 from
> /usr/local/lib/root/libCore.so.3.05
> 0x401263d4 in TBuffer::StreamObject(void *, TClass *) + 0x24 from
> /usr/local/lib/root/libCore.so.3.05
> 0x40021945 in R__EventSTL_SEVector__FR7TBufferPvi at
> /home/pmurray/sample/STLcint.cxx:154 from EventSTL.so
> 0x401b9f79 in TStreamerInfo::WriteBuffer(TBuffer &, char *, int) + 0x1bc1
> from /usr/local/lib/root/libCore.so.3.05
> 0x407300fb in TBranchElement::FillLeaves(TBuffer &) + 0x34b from
> /usr/local/lib/root/libTree.so.3.05
> 0x4072a92c in TBranch::Fill(void) + 0x214 from
> /usr/local/lib/root/libTree.so.3.05
> 0x4072fd3b in TBranchElement::Fill(void) + 0x117 from
> /usr/local/lib/root/libTree.so.3.05
> 0x40744644 in TTree::Fill(void) + 0x80 from
> /usr/local/lib/root/libTree.so.3.05
> 0x08048cb9 in main + 0x179 from ./STL
> 0x4086f507 in __libc_start_main at
> /usr/src/build/40457-i686/BUILD/glibc-2.2.4/csu/../sysdeps/generic/libc-start.c:129
> from /lib/i686/libc.so.6
> 0x08048a61 in EventSTL::EventSTL(void) + 0x3d from ./STL
> Aborted
> [pmurray@ccc04 sample]$
>
> Here is the code:
>
> Thank you for your help,
>
> Pat Murray
>
> //....goSTL
> rootcint -f STLcint.cxx -c EventSTL.h myLinkDef.h
> g++ -g -fPIC -I/usr/local/include/root -c STLcint.cxx EventSTL.cxx
> MainSTL.cxx SubEventSTL.cxx
> g++ -g -Wl,-soname,EventSTL.so -shared STLcint.o EventSTL.o SubEventSTL.o
> -o EventSTL.so
> g++ -g -o STL MainSTL.o EventSTL.so -L/usr/local/lib/root \
> -lCore -lCint -lTree -lm -ldl -rdynamic
>
> //------------------file SubEventSTL.h
>
> #include <vector>
>
> class SubEventSTL
> {
> public:
> SubEventSTL();
> virtual ~SubEventSTL();
> void Add(int x);
> void VI();
> void Clear();
> vector<int> B;
>
> };
>
>
> //------------------file SubEventSTL.cxx
> #include "SubEventSTL.h"
>
>
> SubEventSTL::SubEventSTL() {
> for (int i=0;i<10;i++)
> {
> Add(i);
> cout << " " << B[i];
> }
>
> }
> SubEventSTL::~SubEventSTL() {}
> void SubEventSTL::Add(int x)
> {
> B.push_back(x);
> }
>
> void SubEventSTL::Clear()
> {
> B.clear();
> }
>
> void SubEventSTL::VI()
> {
> cout << "Size: " << B.size() << " - Contents : " ;
> for (int i=0;i<B.size();i++)
> {
> cout << " " << B[i];
> }
> cout << endl;
> }
>
> //------------------file EventSTL.h
> #include "TObject.h"
> #include <vector>
> #include "SubEventSTL.h"
>
> class EventSTL : public TObject
> {
> public:
> EventSTL();
> virtual ~EventSTL();
> void Electron(Double_t x);
> void VI();
> void Clear();
> vector<Double_t> A;
> vector<SubEventSTL> SEVector;
> ClassDef(EventSTL,1)
> };
>
> //------------------file EventSTL.cxx
> #include "EventSTL.h"
>
> ClassImp(EventSTL)
>
> EventSTL::EventSTL() {}
> EventSTL::~EventSTL() {}
> void EventSTL::Electron(Double_t x)
> {
> A.push_back(x);
> SubEventSTL se;
> SEVector.push_back(se);
> }
>
> void EventSTL::Clear()
> {
> A.clear();
> }
>
> void EventSTL::VI()
> {
> cout << "Size: " << A.size() << " - Contents : " ;
> for (Int_t i=0;i<A.size();i++)
> {
> cout << " " << A[i];
> }
> cout << endl;
> }
>
> //------------------file myLinkDef.h
> #ifdef __CINT__
>
> #pragma link off all globals;
> #pragma link off all classes;
> #pragma link off all functions;
>
> #pragma link C++ class EventSTL+;
> #endif
>
>
>
> //-----------------file MainSTL.cxx
> #include <iostream>
>
> #include "TROOT.h"
> #include "TFile.h"
> #include "TTree.h"
> #include "EventSTL.h"
>
>
> EventSTL *CC = new EventSTL;
>
> TROOT Mauri("Bos_to_Root","Bos Banks to Root file conversion");
>
> main()
> {
>
> TFile *myfile;
> myfile = new TFile("STL.root","RECREATE","TTree Dynamic ROOT file");
>
> TTree *mytree = new TTree("T","My tree");
> mytree->Branch("abc","EventSTL",&CC,16000,0);
>
> for (Int_t i=0;i<10;++i)
> {
> for (Int_t j=0;j<i;++j)
> {
> CC->Electron(i);
> cout<<"here "<<i<<":"<<j<<endl;
> }
> mytree->Fill();
> CC->VI();
> CC->Clear();
> }
>
> mytree->Write();
> mytree->Print();
>
> return 0;
>
> }
>
>
>
>
This archive was generated by hypermail 2b29 : Thu Jan 01 2004 - 17:50:11 MET