Hi Mike, TClonesArray in version 3.00/06 accept variable length items or pointers. However, the TTree::Branch system cannot create branches for such data types in the class in the TClonesArray. With the development version 3.01 in CVS, this is now possible and I have checked that your example works correctly with 3.01 when using the new branch mechanism TTree::Bronch. Rene Brun Mike Beddo wrote: > > Hi all, > > I am trying to construct two classes for analyzing items in shopping > baskets (non-physics application - but I used to be a physicist, > really!) These are below (I'm not a native C++ programmer, my world > revolves around C): > > class TLogItem : public TObject { > > private: > TObjString *fUPC; > Int_t fSales; > > public: > TLogItem(); > TLogItem(char *upc, Int_t sales); > virtual ~TLogItem(); > > const char *Upc() const {return fUPC->GetName();} > Int_t Sales() const {return fSales;} > > ClassDef(TLogItem,1) //TLogItem structure > }; > > class TLog : public TObject { > > private: > Int_t fKey; > Int_t fDateTime; > Bool_t fValid; > Int_t fGrossPos; > Int_t fGrossNeg; > Int_t fNitem; > TClonesArray *fItems; > > static TClonesArray *fgItems; > > public: > TLog(); > virtual ~TLog(); > void SetHeader(Int_t key, Int_t time, Int_t gross_pos, Int_t > gross_neg); > void AddItem(char *upc, Int_t sales); > void Clear(Option_t *option = ""); > Bool_t IsValid() const {return fValid;} > TClonesArray *Items() const {return fItems;} > > Int_t TLogId() const {return fKey;} > Int_t DateTime() const {return fDateTime;} > > ClassDef(TLog,1) //TLog structure > }; > > Notice the use of TObjArray in the first class, and TClonesArray in the > second class. The constructor for TLogItem initializes member fUPC, if > it doesn't exist. > > The problem is when I write to a root file (after defining a tree, ...) > I get the following error message after the first bucket is written to > disk: > > Warning in <TBranchClones::BranchClones>: Cannot process: TLogItem::fUPC > > When I read back from the root file, the member fSales is correct, but > fUPC is always ''. I think this has something to do with being unable to > stream the TObjString to file. What am I doing wrong? > > - Mike Beddo
This archive was generated by hypermail 2b29 : Tue Jan 01 2002 - 17:50:43 MET