Problems with TClonesArray

From: Diego Casadei (casadei@bo.infn.it)
Date: Wed May 13 1998 - 21:36:53 MEST


Hello Rooters!

I have some problem using TClonesArray.  In the documentation I found an
interesting note: the use of AddAt & Co. is discouraged, because the
programmer should use the operator [] features.  I tried.  This is the
code:

// in data.h
	class TAMSRun : public TObject {
	private:
	  Int_t Nrun;  // run number
	  Int_t nEvt;  // number of events
	  TClonesArray *events;
	public:
	  TAMSRun();
	  TAMSRun(Int_t r,TAMSEvent ev);
	  ~TAMSRun();
	  Int_t GetRun(){return(Nrun);};
	  Int_t GetEvtN(){return(nEvt);};
	  void SetRun(Int_t r){Nrun=r;return;};
	  TClonesArray* GetEvent();
	  Int_t AddEvent(TAMSEvent ev);
	};

// in data.cxx
	TAMSRun::TAMSRun(Int_t r,TAMSEvent ev){
	  Nrun=r;
	  events=new TClonesArray("TAMSEvent",1);
	  events[0]=new TAMSEvent(ev);
	  nEvt=1;
	  return;
	}


and this is the error I get:

cxx: Error: data.cxx, line 15: In this statement, "events[0]" does not
have an assignment operator.
  events[0]=new TAMSEvent(ev);
--^

OK, it seems that I can use the operator [] for fetching one element, but
not for assignments (at least, this is what I guess).

Then I found in the RootTalk Digest a message from Stephen Eichblatt
in which he says that he used a different syntax:

> In the end, i do it like the Event / Track example, using the 
> 
> TClonesArray &tracks = *fTracks;
> new(tracks[fNtrack++]) Track(random);
> 
> which works. 

I tried, writing:

	TAMSRun::TAMSRun(Int_t run,TAMSEvent ev){
	  Nrun=run;
	  events=new TClonesArray("TAMSEvent",1);
	  new(events[0]) ev;
	  nEvt=1;
	  return;
	}

getting:

cxx: Error: data.cxx, line 15: Missing type specifier or type qualifier.
  new(events[0]) ev;
-----------------^

Now I have no idea: how can I assign the object ev to the j-th element of
a TClonesArray?

PS.  I used   events=new TClonesArray("TAMSEvent",1);
     because I want to expand the array when I add the next element.

        Diego Casadei
                casadei@bo.infn.it
                casadei@cern.ch



This archive was generated by hypermail 2b29 : Tue Jan 04 2000 - 00:34:32 MET