RE: [ROOT] TClonesArray

From: Philippe Canal (pcanal@fnal.gov)
Date: Fri Dec 17 2004 - 17:52:29 MET


Hi Tommaso,

>From your description it is not clear what is going wrong.
The first thing you should try is to replace v->UncheckedAt by v->At to make
sure you are really reading allocated memory.

Now there is no technical different between (strictly speaking):
	TClonesArray *v =  p.GettArray();
And
	TClonesArray *v;
        v =  p.GettArray();
The difference I guess in that between the last 2 lines you have many other
thing going-on that may or may not affect the result (like going
out-of-scope, other unrelated memory over-write, etc.).

The simpliest is for you to send a very small, complete example that
reproduces the problem.

Cheers,
Philippe.

-----Original Message-----
From: owner-roottalk@pcroot.cern.ch [mailto:owner-roottalk@pcroot.cern.ch]
On Behalf Of tommaso chiarusi
Sent: Friday, December 17, 2004 7:42 AM
To: Root Newsgroup
Subject: [ROOT] TClonesArray

Dear Rooters,
Should it be stange the following?

You have a member function GetArray() which yields a pointer to
TClonesArray.

so, in the scope of some methods:

	TClonesArray *v =  p.GettArray();
	Evento &te = *((Evento*) v->UncheckedAt(cont));


It's Ok and the Evento-memory segment does exist and it is filled with right
things. While...

	TClonesArray *v;
	v =  p.GettArray();
	Evento &te = *((Evento*) v->UncheckedAt(cont));

It ISN'T ok, and the Evento-memory segment is completely random.



What's happening?

I need to use the second case, since the TClonesArray pointer v should be a
private data member of a class.
In particular I should organize such stuff as the following:

	TClonesArray *v;  -> IN THE PRIVATE DATA MEMBER DECLARATION SCOPE

	v =  p.GettArray(); -> IN THE CLASS CONSTRUCTOR DEFINITION

	Evento &te = *((Evento*) v->UncheckedAt(cont)); IN A MEMBER FUNCTION
 

Maybe I'm forgetting some stupid rule.... 
Thanks a lot,

Tommaso.

P.S.

System

ROOT:  Version   4.00/08       9 July 2004
OS: Linux RH-9
gcc version 3.2.2 20030222 (Red Hat Linux 3.2.2-5)



--
-----------------------

Dr. Tommaso Chiarusi 

Dipartimento di Fisica
Universita' di Bologna
INFN. Sez. Bologna

Tel +39.051.209.5234
Fax +39.051.209.5269

-----------------------



This archive was generated by hypermail 2b29 : Sun Jan 02 2005 - 05:50:10 MET