Hi Rooters, I've written a small class to read a file and display plot and another stuff. This class contains a TTree object which is created by the default constructor of MyClass by TTree fList("fList","Test") it has been previously declared in the class definition with TTree *fList. But I can't use this tree in the other functions of the class, e.g. void Print() { fList->Print(); } In a root session [root][1].L MyClass.C [root][2] MyClass t("f72_r1.rep"); [root][3] t->Print(); Error: illegal pointer to class object fList 0x0 17 FILE:MyClass.h LINE:165 *** Interpreter error recovered *** I can understand what is the error I think it is because fList is built afterwards. It works if I declare the ntuple as a main variable TTree tree("fList","Test") in MyClass.C and adding fList = tree in the constructor. I would like to avoid such a solution. Do you see any other ? What I don't understand is that all other declared types work (Int_t Float_t,...). The whole code I used is below. I'm sorry if this has been already asked in roottalk but I didn't manage to find it. I've also two short question : - What is the status of Root GUI use under Windows ? - Is there someone using Root libraries with Labview ? (I've already asked this question some time ago) ------MyClass.h #include <TChain.h> #include <TFile.h> #include <TSelector.h> #include <iostream.h> #include <stdio.h> #include <strstream.h> #include <fstream.h> #include <string.h> class MyClass { public: Char_t name[32]; Int_t nList=0; Int_t nWords; Int_t nAcc; Int_t Accorl[12]; Int_t Accorc[12]; Int_t wFormat; Int_t tCM1; Int_t tCM3; Int_t tT0; Float_t TCres; TTree *fList; Int_t num; char fName[32]; Int_t CM1; Int_t CM3; Int_t T0; Int_t Tout; Int_t Tot; Int_t runtime; Char_t date[32]; Bool_t sel; TBranch *b_num; TBranch *b_fName; TBranch *b_CM1; TBranch *b_CM3; TBranch *b_T0; TBranch *b_Tout; TBranch *b_T0; TBranch *b_runtime; TBranch *b_date ; TBranch *b_sel; // MyClass (char *filename); ~MyClass (); void Print(); Bool_t Select(Int_t idfile); }; //Default constructor MyClass::MyClass (char *filename){ //open the report file and fille all the structure nAcc = 0; ifstream file(filename); if(!file) { cout << "Report File not found " << endl; break; } Int_t nlines = 0; TString line; // skip lines for(int kk=0;kk<3;kk++) { line.ReadLine(file); } line.ReadToDelim(file, '\t'); line.ReadToDelim(file, ' '); // Number of words nWords = atoi(line.Data()); line.ReadToDelim(file, ' '); line.Remove(0,1); // Format of words wFormat = atoi(line.Data()); line.ReadLine(file); line.ReadLine(file); line.ReadToDelim(file,'\t'); // Read accordeon for(int kk=0;kk<12;kk++) { line.ReadToDelim(file, '\t'); Accorl[kk]=atoi(line.Data()); if ( Accorl[kk]!=0) nAcc++; //cout << "nacc = " << nAcc <<" Accorl[kk]=" << Accorl[kk]<<" kk=" <<kk << endl; } line.ReadToDelim(file, '\t'); line.ReadToDelim(file, '\t'); for(int kk=0;kk<12;kk++) { line.ReadToDelim(file, '\t'); if (Accorl[kk]!=0) Accorc[kk]=atoi(line.Data()); //cout << "nacc = " << nAcc <<" Accorc[kk]=" << Accorc[kk]<<" kk=" <<kk << endl; } line.ReadToDelim(file, '='); line.ReadLine(file); // Time-Coder Resolution TCres=atof(line.Data()); // Compute real accordeon compression in ns and Accordeon length in channels for (kk=0;kk<nAcc; kk++) { Accorc[kk] = TMath::Power(2,Accorc[kk]); Accorc[kk] *= TCres; Accorl[kk]*=1024; } // Skip header for (kk=0;kk<6; kk++) { line.ReadLine(file); } // Create Ntuple TTree fList("fList","fList"); fList->Print(); fList->Branch("num",&num,"number"); fList->Branch("fName",&fName,"lst filename"); fList->Branch("CM1",&CM1,"CM1"); fList->Branch("CM3",&CM3,"CM3"); fList->Branch("T0",&T0,"T0"); fList->Branch("Tout",&Tout,"Tout"); fList->Branch("Tot",&Tot,"Tot"); fList->Branch("runtime",&runtime,"runtime"); fList->Branch("date",date,"date"); fList->Branch("sel",&sel,"selected"); // Fill ntuple while (file) { line.ReadToDelim(file,'\t'); num = atoi(line.Data()); line.ReadToDelim(file,'\t'); strcpy(fName,line.Data()); line.ReadToDelim(file,'\t'); strcpy(date,line.Data()); line.ReadToDelim(file,'\t'); line.ReadToDelim(file,'\t'); line.ReadToDelim(file,'\t'); runtime = atoi(line.Data()); line.ReadToDelim(file,'\t'); line.ReadToDelim(file,'\t'); line.ReadToDelim(file,'\t'); line.ReadToDelim(file,'\t'); line.ReadToDelim(file,'\t'); line.ReadToDelim(file,'\t'); line.ReadToDelim(file,'\t'); line.ReadToDelim(file,'\t'); CM1 = atoi(line.Data()); line.ReadToDelim(file,'\t'); CM3 = atoi(line.Data()); line.ReadToDelim(file,'\t'); line.ReadToDelim(file,'\t'); T0 = atoi(line.Data()); line.ReadToDelim(file,'\t'); Tout = atoi(line.Data()); line.ReadToDelim(file,'\t'); Tot = atoi(line.Data()); line.ReadToDelim(file,'\n'); sel = kTRUE; fList->Fill(); tCM1 +=CM1; tCM3 +=CM3; tT0 +=T0; } cout << tT0 << endl; } MyClass::~MyClass() { } MyClass::Print() { fList->Print(); } -----MyClass.C #include "MyClass.h" { }
This archive was generated by hypermail 2b29 : Tue Jan 01 2002 - 17:51:05 MET