Hi Robert, You have several includes missing and variables initialisation missing. See your files modified in the attachements. Rene Brun Robert Probny wrote: > > Hello, > I am beginner in ROOT. Please help me with this problem: > I have small "MYClass" (see bellow). How create shared library exam.so ? > how write make file and LinkDef.h file ? on my PC is root4.00.01 and gcc > 3.2 > > exam.h > > #ifndef exam_h > #define exam_h > class exam { > private: > TTree *fTree; > static const Text_t *fgPath; > > static const Int_t fgMaxWires=48; > UInt_t fNwires; > UShort_t fWidth[fgMaxWires]; > UShort_t fWire[fgMaxWires]; > public: > exam(TTree *tree=0); > virtual ~exam(); > void SetPath(const Text_t *path) { fgPath = path; } > const Text_t *GetPath() const { return fgPath; } > void SetRun(const UShort_t run); > void Init(TTree *tree); > Int_t GetEntries() const { return fTree->GetEntries(); } > void AnalyzeEntry(const Int_t entry); > }; > #endif > > exam.cxx > > #include "exam.h" > //------------------------------ > exam::exam(TTree *tree) > { > if (tree == 0) return; > Init(tree); > } > //------------------------------ > exam::~exam() > { > cout << "DESTRUCTOR" << endl; > if (!fTree) return; > if (fTree==0) return; > delete fTree->GetCurrentFile(); > } > //------------------------------ > void exam::SetRun(const UShort_t run) > { > Text_t fname[200]; > sprintf(fname,"%s/run%0.3u.root",GetPath(),run); > TFile *f = new TFile(fname); > TTree *mytree = (TTree*)f->Get("mytree"); > Init(mytree); > } > //------------------------------ > void exam::Init(TTree *tree) > { > if (tree == 0) return; > fTree = tree; > fTree->SetBranchAddress("fNwires",&fNwires); > fTree->SetBranchAddress("fWires.fWidth",fWidth); > fTree->SetBranchAddress("fWires.fWire",fWire); > fTree->SetBranchStatus("*",0); > fTree->SetBranchStatus("fNwires",1); > fTree->SetBranchStatus("fWires.fWidth",1); > fTree->SetBranchStatus("fWires.fWire",1); > > cout << "Processing file: "; > cout << fTree->GetCurrentFile()->GetName() << endl; > } > //------------------------------ > void exam::AnalyzeEntry(const Int_t entry) > { > if (fTree==0) return; > fTree->GetEntry(entry); > for (UShort_t i=0; i<fNwires; i++) { > cout << "width = " << fWidth[i] << endl; > cout << "wire = " << fWire[i] << endl; > } > } > > in root all working (for example): > > root [0] .L exam.cxx > root [1] exam *ex1 = new exam > root [2] ex1->SetPath("/mypath") > root [3] ex1->SetRun(999) > root [4] ex1->AnalyzeEntry(99) > width = 1 > wire = 10 > width = 1 > wire = 111 > .... > > I test method .L exam.cxx+ but not working ...(errors, MyClass is wrong) > > Regards Robert > > _________________________________________________________________ > The new MSN 8: smart spam protection and 2 months FREE* > http://join.msn.com/?page=features/junkmail #ifndef exam_h #define exam_h #include "TTree.h" class exam { private: TTree *fTree; static const Text_t *fgPath; static const Int_t fgMaxWires=48; UInt_t fNwires; UShort_t fWidth[fgMaxWires]; UShort_t fWire[fgMaxWires]; public: exam(TTree *tree=0); virtual ~exam(); void SetPath(const Text_t *path) { fgPath = path; } const Text_t *GetPath() const { return fgPath; } void SetRun(const UShort_t run); void Init(TTree *tree); Int_t GetEntries() const { return (Int_t)fTree->GetEntries(); } void AnalyzeEntry(const Int_t entry); }; #endif #include "Riostream.h" #include "TFile.h" #include "exam.h" const Text_t *exam::fgPath="something"; //------------------------------ exam::exam(TTree *tree) { if (tree == 0) return; Init(tree); } //------------------------------ exam::~exam() { cout << "DESTRUCTOR" << endl; if (!fTree) return; if (fTree==0) return; delete fTree->GetCurrentFile(); } //------------------------------ void exam::SetRun(const UShort_t run) { Text_t fname[200]; sprintf(fname,"%s/run%3u.root",GetPath(),run); TFile *f = new TFile(fname); TTree *mytree = (TTree*)f->Get("mytree"); Init(mytree); } //------------------------------ void exam::Init(TTree *tree) { if (tree == 0) return; fTree = tree; fTree->SetBranchAddress("fNwires",&fNwires); fTree->SetBranchAddress("fWires.fWidth",fWidth); fTree->SetBranchAddress("fWires.fWire",fWire); fTree->SetBranchStatus("*",0); fTree->SetBranchStatus("fNwires",1); fTree->SetBranchStatus("fWires.fWidth",1); fTree->SetBranchStatus("fWires.fWire",1); cout << "Processing file: "; cout << fTree->GetCurrentFile()->GetName() << endl; } //------------------------------ void exam::AnalyzeEntry(const Int_t entry) { if (fTree==0) return; fTree->GetEntry(entry); for (UShort_t i=0; i<fNwires; i++) { cout << "width = " << fWidth[i] << endl; cout << "wire = " << fWire[i] << endl; } }
This archive was generated by hypermail 2b29 : Sun Jan 02 2005 - 05:50:06 MET