Dear Rene Thank you for your help. Since I am loading the macro first, the macro call mechanism may not be the reason for the problem. Therefore, I am sending you a demo code which also shows this behavior. I apologize that the code is pretty long because I am creating a library first. The steps are the following: 1, load macro 2, initialize library 3, fill tree 4, draw tree This is the output from root: root [0] .L macro4Test.C root [1] Init() root [2] FillTree("/opt/rootdata/test.txt") TestClass::TestClass New file [test.root] is created TestClass::FFillTree ~TestClass::TestClass root [3] DrawTree("/opt/rootcode/test.root","fX") <TCanvas::MakeDefCanvas>: created default TCanvas with name c1 root [4] DrawTree("/opt/rootcode/test.root","log10(fX)") Error: No symbol fX in current scope FILE:macro4Test.C LINE:42 *** Interpreter error recovered *** Error: class,struct,union or type (unknown) not defined FILE:macro4Test.C LINE:42 Error: No symbol fX in current scope FILE:macro4Test.C LINE:42 *** Interpreter error recovered *** Error: class,struct,union or type (unknown) not defined FILE:macro4Test.C LINE:42 Error: No symbol fX in current scope FILE:macro4Test.C LINE:42 *** Interpreter error recovered *** Error: class,struct,union or type (unknown) not defined FILE:macro4Test.C LINE:42 .... etc .... All necessary files are listed below, and the file "test.txt", which contains hundred lines with x and y values, is attached. Thank you in advance for your help. Best regards Christian ---------------------------------- C.h.r.i.s.t.i.a.n S.t.r.a.t.o.w.a V.i.e.n.n.a, A.u.s.t.r.i.a //================================================================== // macro4Test.C //================================================================== #ifndef __CINT__ #include <stdio.h> #include <stdlib.h> #include <iostream.h> #include <iomanip.h> #include <math.h> #include "TFile.h" #include "TTree.h" #include "TBranch.h" #include "Test.h" #endif //----------------------------------------------------------------------// void Init() { gSystem->Load("/opt/rootcode/Test.so"); }//Init //----------------------------------------------------------------------// void FillTree(const char *vData) { TestClass *vTestClass = new TestClass("TestClass","class title","test.root"); vTestClass->FFillTree(vData); delete vTestClass; }//FillTree //----------------------------------------------------------------------// void DrawTree(const char *vRootFile,const char *varexp) { TFile *fFile = new TFile(vRootFile,"READ"); TTree *vTree = (TTree*)fFile->Get("vTree"); TTest *vTest = 0; vTree->SetBranchAddress("vBranch",&vTest); vTree->Draw(varexp); }//DrawTree /////////////////////////// // To run it in root: // > .L macro4Test.C // > Init() //only once per root session // > FillTree("/opt/rootdata/test.txt") // > DrawTree("/opt/rootcode/test.root","fX") // > DrawTree("/opt/rootcode/test.root","log10(fX)") // > DrawTree("/opt/rootcode/test.root","fX:fY") // > DrawTree("/opt/rootcode/test.root","sqrt(fX):sqrt(fY)") // /////////////////////////// //================================================================== // Test.h //================================================================== #ifndef __Test__ #define __Test__ #include <iostream.h> #include "TObject.h" #include "TNamed.h" #include "TFile.h" #include "TString.h" class TestClass: public TNamed { private: TFile *fFile; //! public : TestClass(); TestClass(const char *vName,const char *vTitle,const char *vFileName); ~TestClass(); void FFillTree(const char *vText); ClassDef(TestClass,1) //TestClass }; class TTest: public TObject { private: Float_t fX; Float_t fY; public : TTest(); ~TTest(); void FSetX(Float_t vX) {fX = vX;} void FSetY(Float_t vY) {fY = vY;} Float_t FGetX() const {return fX;} Float_t FGetY() const {return fY;} ClassDef(TTest,1) //Test }; #endif //================================================================== // Test.cxx //================================================================== #include <stdio.h> #include <stdlib.h> #include <iostream.h> #include <fstream.h> #include <math.h> #include "Test.h" #include "TTree.h" #include "TSystem.h" #include "TBranch.h" ClassImp(TestClass); ClassImp(TTest); //----------------------------------------------------------------------// TestClass::TestClass(): TNamed() { cout << "TestClass::TestClass" << endl; fFile = 0; } //----------------------------------------------------------------------// TestClass::TestClass(const char *vName,const char *vTitle,const char *vFileName): TNamed(vName,vTitle) { cout << "TestClass::TestClass" << endl; fFile = new TFile(vFileName,"RECREATE"); cout << "New file [" << vFileName << "] is created" << endl; }//Constructor //----------------------------------------------------------------------// TestClass::~TestClass() { cout << "~TestClass::TestClass" << endl; delete fFile; fFile = 0; }//Destructor //----------------------------------------------------------------------// void TestClass::FFillTree(const char *vText) { cout << "TestClass::FFillTree" << endl; Float_t vX, vY; ifstream vInput(vText, ios::in); TTree *vTree = new TTree("vTree","data from test.txt"); // TTest *vTest = new TTest(); TTest *vTest = 0; TBranch *vBranch = vTree->Branch("vBranch","TTest",&vTest,64000,1); Int_t nlines = 0; while (nlines < 100) { vInput >> vX >> vY; if (!vInput.good()) break; vTest->FSetX(vX); vTest->FSetY(vY); vTree->Fill(); nlines++; } fFile->Write(); vInput.close(); // delete vTest; }//FFillTree //----------------------------------------------------------------------// TTest::TTest(): TObject() { //*-*-*-*-*-*-*-*-*Default TTest constructor*-*-*-*-*-*-*-*-*-*-*-*-*-*-* // ======================== fX = 0; fY = 0; }//Constructor //----------------------------------------------------------------------// TTest::~TTest() { //*-*-*-*-*-*-*-*-*TTest destructor *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* // =============== }//Destructor //================================================================== // TestLinkDef.h //================================================================== #ifdef __CINT__ #pragma link off all globals; #pragma link off all classes; #pragma link off all functions; #pragma link C++ class TestClass+; #pragma link C++ class TTest+; #endif //================================================================== // MakeFile4Test //================================================================== # Makefile for class Test. # shell: gmake -f Makefile4Test ARCH = linuxppcegcs CXX = ObjSuf = o SrcSuf = cxx ExeSuf = DllSuf = so OutPutOpt = -o ROOTCFLAGS := $(shell root-config --cflags) ROOTLIBS := $(shell root-config --libs) ROOTGLIBS := $(shell root-config --glibs) ifeq ($(ARCH),linuxegcs) # Linux with egcs (>= RedHat 5.2) CXX = g++ CXXFLAGS = -O -Wall -fPIC LD = g++ LDFLAGS = -O SOFLAGS = -shared endif ifeq ($(ARCH),linuxppcegcs) # MkLinux with egcs/glibc CXX = g++ CXXFLAGS = -O -Wall -fPIC LD = g++ LDFLAGS = -O SOFLAGS = -shared -Wl,-soname, endif CXXFLAGS += $(ROOTCFLAGS) LIBS = $(ROOTLIBS) $(SYSLIBS) GLIBS = $(ROOTGLIBS) $(SYSLIBS) #------------------------------------------------------------------------------ TESTO = Test.$(ObjSuf) TestDict.$(ObjSuf) TESTS = Test.$(SrcSuf) TestDict.$(SrcSuf) TESTSO = Test.$(DllSuf) OBJS = $(TESTO) PROGRAMS = $(TESTSO) #------------------------------------------------------------------------------ .SUFFIXES: .$(SrcSuf) .$(ObjSuf) .$(DllSuf) all: $(PROGRAMS) $(TESTSO): $(TESTO) $(LD) $(SOFLAGS) $(LDFLAGS) $^ $(OutPutOpt) $@ clean: @rm -f $(OBJS) core .SUFFIXES: .$(SrcSuf) ### Test.$(ObjSuf): Test.h TestDict.$(SrcSuf): Test.h TestLinkDef.h @echo "Generating dictionary TestDict..." @rootcint -f TestDict.$(SrcSuf) -c Test.h TestLinkDef.h .$(SrcSuf).$(ObjSuf): $(CXX) $(CXXFLAGS) -c $< Rene Brun wrote: > Hi Christian, > > The first problem is not connected with Trees. It seems that there is > a problem with the CINT macro call mechanism when an argument > is a string with a ")". This is under investigation. > Instead of doing .x DrawTree.C("... > do > .L DrawTree.C, then > DrawTree(""... > > If this does not solve your problem, please send me a short macro > that I can use to to debug. > > About your second problem. I am aware of some combinations > of viewing angles that give problems. This happens if you make more > than one complete turn with the picture upside down. > > Rene Brun > > On Sat, 19 May 2001 cstrato@EUnet.at wrote: > > > > > Dear Rooters > > > > I have the following function in a macro to draw a tree: > > void DrawTee(const char *vTreeName,const char *varexp) > > { > > gSystem->Load("/opt/rootcode/Mylib.so"); > > > > TFile *fFile = new TFile("/opt/rootcode/test.root","READ"); > > TTree *vTree = (TTree*)fFile->Get(vTreeName); > > // MyClass *vClass = 0; > > // vTree->SetBranchAddress("vBranch",&vClass); > > > > vTree->Draw(varexp); > > } > > > > >From root I call this function: > > root [1] DrawTree("vTree","fX") > > This works fine, however, when I call: > > root [2] DrawTree("vTree","sqrt(fX)") > > I get the following error message printed 13 times: > > Error: No symbol fX in current scope FILE:macro4draw.C LINE:17 > > *** Interpreter error recovered *** > > Error: class,struct,union or type (unknown) not defined > > FILE:macro4draw.C LINE:17 > > > > Interestingly, the histogram is always drawn correctly, when > > I use different functions. > > > > I do understand why the error appears, since fX is a private member > > of class MyClass and cannot be accessed directly, but then this error > > should also appear in the case: DrawTree("vTree","fX"). > > > > What can I do to avoid the error messages? > > > > Thank you in advance for your help. > > My system: PowerBook LinuxPPC 2000, root 3.01/02 > > > > P.S.: When I rotate a 3-dim histogram interactively with the mouse in > > such a way, > > that I turn it upside-down often, then finally the vertical axis is no > > longer > > drawn correctly, and also the content is drawn partly outside of the > > box. > > > > P.P.S.: The function Tree->AddFriend() is really very helpful! > > > > Best regards > > Christian > > ---------------------------------- > > C.h.r.i.s.t.i.a.n S.t.r.a.t.o.w.a > > V.i.e.n.n.a, A.u.s.t.r.i.a > > > > > > 1446.3 284.3 2272.8 426.5 8323.8 1882.8 4655 8951.8 1106 239 1418 225.8 6842.3 1263.5 1789.3 365.4 1281 283.7 1037.8 246 875.8 217.4 1696.5 296.6 706.8 146.1 852.5 151.6 828.3 133.4 1764 399.4 23826.3 4925.6 4155 1382.4 18770.8 6463.9 973 198.5 16253.3 3478.7 2601.3 567.2 1359.3 216.3 993 188.1 1872.5 246.4 10844.3 2369.8 1975.8 289 670 112 3398.5 7574.2 1603.3 407.4 9267.5 2298.3 4615 1704.7 1228.5 207.7 646 102.9 10630.3 10978.5 8122.5 2291 1613.5 710.9 839 140 5560 1081.2 1701.3 344.3 2574.5 582.4 1253.8 215.1 855.3 190.9 852.8 177 1645.5 527.9 1436.3 300.5 155 17.3 982.3 165.5 726.8 224.8 1627.5 308.7 866.5 432.9 2198.3 660.2 805 123.6 907.8 183.8 1340.5 229.5 2290.8 369.8 7134 9458.8 11800.3 11074.7 673.3 120.4 8700.8 2702.7 5845 1609.4 2260.3 345 1867.8 398.9 1181.3 181.9 1115 198.8 6155 5635.9 5896.3 942.7 737.3 140.4 3200.5 729.3 4597.5 982.9 8819.3 1988.5 6934.3 1250.8 843.3 169.9 3785.8 800.2 6836.5 1192.8 760.5 176.4 755.8 267.5 800 130.6 1096.3 208.3 1093.5 172.3 1989.3 313.3 1671.3 397.6 725.3 577 792 135.6 614.8 281.7 2734.3 2446.1 1981 410.5 2344.8 402.7 5418.3 6219.8 7805 8589.6 3388.5 584.7 1134.5 205.7 4640 1111.8 5133.8 9206.7 2612.2 2694.9 859.3 176.4 1282 882.7 777.8 150.4 782.5 172.8 749 136.2
This archive was generated by hypermail 2b29 : Tue Jan 01 2002 - 17:50:46 MET