RE: [ROOT] dynamically allocating histograms

From: Philippe Canal (pcanal@fnal.gov)
Date: Thu Jul 26 2001 - 16:01:18 MEST


Hi,

The short extract of code that you gave should be working as you
expect (i.e. keep the bin value beyond the creating method).
Something else must be going on.  Could you send me more information
of what you code is doing?

Cheers,
Philippe.

PS. the 624 bytes that you see are only the bytes directly 
allocated for the TH2D object.  In its constructors the object
(specifically its TArrayD part) in turn call the operator new
to create an array of double to hold the bin values.  This
has not reason to disappear at the end of your method. 

-----Original Message-----
From: owner-roottalk@pcroot.cern.ch
[mailto:owner-roottalk@pcroot.cern.ch]On Behalf Of
jcfree@socrates.Berkeley.EDU
Sent: Wednesday, July 25, 2001 7:50 PM
To: Rene Brun
Cc: roottalk@pcroot.cern.ch
Subject: [ROOT] dynamically allocating histograms



Hi everyone, 

	I'm currently writing a simple standalone executable for MSVC++ 6
using ROOT 3.01/05. In the program I've designed a class which contains a
pointer to a TH2D histo, set to NULL in the constructor. During
the execution of the program, a user can request that this histogram data
member be dynamically allocated, i.e., my class contains a member function
w/ the
code

fMyClassHisto = new
TH2D("histo","histo",userXbins,0,userXbins,userYbins,0,userYbins);

Then, in the same function, data is read in to the histogram via
"fMyClassHisto->SetBinContent(x,y, userData)"

Here's where the problem comes in: I want other member functions of my
class to use the information in the (now initialized) histogram. Normally,
the "new" operator is supposed to make an object persistent until "delete"
is called; however, using TStorage I discovered that what "new" does in
this case is NOT set aside a chunk of heap memory large enough to preserve
the binned values, but only 624 bytes, apparently the size of an
unfilled TH2D histogram. So, when I exit the member function in which
fMyClassHisto is filled, the bin contents get written over. My question
is: is there
some way to make the entire histogram -- not just the 624 bytes but also
all the bin values -- persistent in memory until delete is called?



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