[ROOT] i/o problem in root 3.00/01

From: Eddy Offermann (eddy@rentec.com)
Date: Thu Jan 11 2001 - 00:00:24 MET


Dear Root-ers

I wonder whether I use the ROOT I/O system incorrectly (most likely)
or a hit a problem in ROOT 3.00/01
(SunOS moose 5.7 Generic_106541-12 sun4u sparc SUNW,Ultra-Enterprise) ??

I am trying to add the contents of a class (TTrade) to a tree
This class has only one member , TArrayD fVal, see attachments.

When reading back the contents of the tree, only the first entry
in fVal has the correct value, but the array has the correct
length.

What is wrong ?

Best Regards, 
Eddy


Renaissance Technologies Corp.
Route 25A, East Setauket NY 11733
e-mail: eddy@rentec.com
http://www.rentec.com


#include <TTrade.h>

ClassImp(TTrade)

//______________________________________________________________________________
TTrade::TTrade()
{
  fVal.Set(0);
}

//______________________________________________________________________________
TTrade::TTrade(Int_t nrFills)
{
  fVal.Set(nrFills);
  for (Int_t i = 0; i < nrFills; i++)
    fVal[i] = i+1;
}


//______________________________________________________________________________
TTrade::~TTrade()
{
}




#include <TROOT.h> #include <TFile.h> #include <TTree.h> #include <Rtypes.h> #include <TArrayD.h> #include <TObjArray.h> #include <TTrade.h> void WriteTrades(TString &file,TObjArray *tradeList); void ReadTrades(TString &file); Int_t main(Int_t argc, Char_t **argv) { TROOT doit("doit","make the markets efficient"); TObjArray *tradeList = new TObjArray(); for (Int_t i = 0; i < 10; i++) { printf("%d\n",i); tradeList->Add(new TTrade(i+1)); } TString tradeFile("trades"); WriteTrades(tradeFile,tradeList); ReadTrades(tradeFile); delete tradeList; return 0; } //__________________________________________________________________________________ void WriteTrades( TString &file, TObjArray *tradeList) { TFile *tfile = new TFile(file.Data(),"RECREATE","trades",1); TTree *tree = new TTree("Trades","tree of trades"); Int_t split = 1; Int_t bsize = 64000; TTrade *trade = new TTrade(); TBranch *br = tree->Branch("TTrade","TTrade",&trade,bsize,split); Int_t nrTrades = tradeList->GetEntries(); for (Int_t i = 0; i < nrTrades; i++) { trade = (TTrade *)tradeList->At(i); tree->Fill(); } tfile->Write(); tree->Print(); tfile->Close(); } //__________________________________________________________________________________ void ReadTrades( TString &file) { TFile *tfile = new TFile(file.Data()); TTree *tr = (TTree *)tfile->Get("Trades"); TBranch *br = tr->GetBranch("TTrade"); Int_t nrFills = tr->GetEntries(); TTrade* trade = new TTrade(); tr->SetBranchAddress("TTrade",&trade); Int_t nrBytes = 0; for (Int_t i = 0; i < nrFills; i++) { nrBytes += tr->GetEvent(i); for (Int_t j = 0; j < (trade->fVal).GetSize(); j++) printf("%d.%d: %.3f\n",i,j,(trade->fVal)[j]); } delete trade; delete tfile; }
##### DEPENDENCIES ##### # DO NOT DELETE THIS LINE -- make depend depends on it. statkk3.o: /work/eddy/r300/ROOT/include/TROOT.h statkk3.o: /work/eddy/r300/ROOT/include/TDirectory.h statkk3.o: /work/eddy/r300/ROOT/include/TNamed.h statkk3.o: /work/eddy/r300/ROOT/include/TObject.h statkk3.o: /work/eddy/r300/ROOT/include/Rtypes.h statkk3.o: /work/eddy/r300/ROOT/include/RConfig.h statkk3.o: /work/eddy/r300/ROOT/include/RVersion.h statkk3.o: /work/eddy/r300/ROOT/include/DllImport.h statkk3.o: /work/eddy/r300/ROOT/include/Varargs.h statkk3.o: /work/eddy/r300/ROOT/include/TStorage.h statkk3.o: /work/eddy/r300/ROOT/include/TBuffer.h statkk3.o: /work/eddy/r300/ROOT/include/Bytes.h statkk3.o: /work/eddy/r300/ROOT/include/TList.h statkk3.o: /work/eddy/r300/ROOT/include/TSeqCollection.h statkk3.o: /work/eddy/r300/ROOT/include/TCollection.h statkk3.o: /work/eddy/r300/ROOT/include/TIterator.h statkk3.o: /work/eddy/r300/ROOT/include/TString.h statkk3.o: /work/eddy/r300/ROOT/include/TMath.h statkk3.o: /work/eddy/r300/ROOT/include/TRefCnt.h statkk3.o: /work/eddy/r300/ROOT/include/TDatime.h statkk3.o: /work/eddy/r300/ROOT/include/Htypes.h statkk3.o: /work/eddy/r300/ROOT/include/TFile.h statkk3.o: /work/eddy/r300/ROOT/include/TTree.h statkk3.o: /work/eddy/r300/ROOT/include/TObjArray.h statkk3.o: /work/eddy/r300/ROOT/include/TClonesArray.h statkk3.o: /work/eddy/r300/ROOT/include/TAttLine.h statkk3.o: /work/eddy/r300/ROOT/include/Gtypes.h statkk3.o: /work/eddy/r300/ROOT/include/TAttFill.h statkk3.o: /work/eddy/r300/ROOT/include/TAttMarker.h statkk3.o: /work/eddy/r300/ROOT/include/TBranch.h statkk3.o: /work/eddy/r300/ROOT/include/TStringLong.h statkk3.o: /work/eddy/r300/ROOT/include/TCut.h statkk3.o: /work/eddy/r300/ROOT/include/TArrayD.h statkk3.o: /work/eddy/r300/ROOT/include/TArray.h statkk3.o: /work/eddy/r300/ROOT/include/TArrayI.h statkk3.o: /work/eddy/r300/ROOT/include/TVirtualTreePlayer.h statkk3.o: /work/eddy/r300/ROOT/include/TClass.h statkk3.o: /work/eddy/r300/ROOT/include/TDictionary.h statkk3.o: /work/eddy/r300/ROOT/include/Property.h statkk3.o: /work/eddy/r300/ROOT/include/TSystem.h statkk3.o: /work/eddy/r300/ROOT/include/G__ci.h statkk3.o: /work/eddy/r300/ROOT/include/TInetAddress.h statkk3.o: /work/eddy/r300/ROOT/include/TTimer.h statkk3.o: /work/eddy/r300/ROOT/include/TSysEvtHandler.h statkk3.o: /work/eddy/r300/ROOT/include/TQObject.h statkk3.o: /work/eddy/r300/ROOT/include/TTime.h statkk3.o: /work/eddy/r300/ROOT/include/TObjString.h statkk3.o: /work/eddy/r300/ROOT/include/TError.h statkk3.o: /work/eddy/r300/renroot/src/TSDate.h statkk3.o: /work/eddy/r300/renroot/src/TInfo.h statkk3.o: /usr/local/ren/prod/include/info.h ./TTrade.h statkk3.o: /usr/local/ren/prod/include/opts.h TTrade.o: ./TTrade.h /work/eddy/r300/ROOT/include/TObject.h TTrade.o: /work/eddy/r300/ROOT/include/Rtypes.h TTrade.o: /work/eddy/r300/ROOT/include/RConfig.h TTrade.o: /work/eddy/r300/ROOT/include/RVersion.h TTrade.o: /work/eddy/r300/ROOT/include/DllImport.h TTrade.o: /work/eddy/r300/ROOT/include/Varargs.h TTrade.o: /work/eddy/r300/ROOT/include/TStorage.h TTrade.o: /work/eddy/r300/ROOT/include/TBuffer.h TTrade.o: /work/eddy/r300/ROOT/include/Bytes.h TTrade.o: /work/eddy/r300/ROOT/include/TArrayD.h TTrade.o: /work/eddy/r300/ROOT/include/TArray.h TTrade.o: /work/eddy/r300/ROOT/include/Htypes.h TTrade.o: /work/eddy/r300/ROOT/include/TString.h TTrade.o: /work/eddy/r300/ROOT/include/TMath.h TTrade.o: /work/eddy/r300/ROOT/include/TRefCnt.h tradeSubDict.o: tradeSubDict.h /work/eddy/r300/ROOT/include/G__ci.h tradeSubDict.o: /work/eddy/r300/ROOT/include/TROOT.h tradeSubDict.o: /work/eddy/r300/ROOT/include/TDirectory.h tradeSubDict.o: /work/eddy/r300/ROOT/include/TNamed.h tradeSubDict.o: /work/eddy/r300/ROOT/include/TObject.h tradeSubDict.o: /work/eddy/r300/ROOT/include/Rtypes.h tradeSubDict.o: /work/eddy/r300/ROOT/include/RConfig.h tradeSubDict.o: /work/eddy/r300/ROOT/include/RVersion.h tradeSubDict.o: /work/eddy/r300/ROOT/include/DllImport.h tradeSubDict.o: /work/eddy/r300/ROOT/include/Varargs.h tradeSubDict.o: /work/eddy/r300/ROOT/include/TStorage.h tradeSubDict.o: /work/eddy/r300/ROOT/include/TBuffer.h tradeSubDict.o: /work/eddy/r300/ROOT/include/Bytes.h tradeSubDict.o: /work/eddy/r300/ROOT/include/TList.h tradeSubDict.o: /work/eddy/r300/ROOT/include/TSeqCollection.h tradeSubDict.o: /work/eddy/r300/ROOT/include/TCollection.h tradeSubDict.o: /work/eddy/r300/ROOT/include/TIterator.h tradeSubDict.o: /work/eddy/r300/ROOT/include/TString.h tradeSubDict.o: /work/eddy/r300/ROOT/include/TMath.h tradeSubDict.o: /work/eddy/r300/ROOT/include/TRefCnt.h tradeSubDict.o: /work/eddy/r300/ROOT/include/TDatime.h tradeSubDict.o: /work/eddy/r300/ROOT/include/Htypes.h tradeSubDict.o: /work/eddy/r300/ROOT/include/TMemberInspector.h tradeSubDict.o: /work/eddy/r300/ROOT/include/TClass.h tradeSubDict.o: /work/eddy/r300/ROOT/include/TDictionary.h tradeSubDict.o: /work/eddy/r300/ROOT/include/Property.h tradeSubDict.o: /work/eddy/r300/ROOT/include/TError.h



This archive was generated by hypermail 2b29 : Tue Jan 01 2002 - 17:50:33 MET