Hi Alex, CINT has the ability to retrive the ROOT using their "NAME". The name of a ROOT object is usually the first argument of the constructor. In your case this name is the same as the symbol for the variable holding the object (i.e. h1). On the second run of your getH method, CINT noticed that their is no defined variable named 'h1' at this point, so it interogates ROOT and finds that it exist an histogram whose name is h1 (it is at this point stored in h2). As a convenience it automatically declared and set a pointer variable to this histogram (this is for fast prototyping). You should note that object name is ROOT are important, especially for histograms. In you code, when you do h2 = getH(); you might want to consider doing in addition h2.SetName("h2"); (this would remove the symptoms you are seing). Cheers, Philippe. PS. Also you are using the method SetBinContent to enter data in your histogram, you probably know that the method Fill is a high level version which also accumulate statistics (Thus it is the prefered method for filling an histogram). -----Original Message----- From: owner-roottalk@pcroot.cern.ch [mailto:owner-roottalk@pcroot.cern.ch]On Behalf Of Alexander Dietz Sent: Thursday, June 27, 2002 8:53 AM To: root list Subject: [ROOT] ROOT knows the existence of undefined object Hello, in the attachement there is a small program with a function 'getH' that should return a histogram (as a real histogram, not as a pointer). When starting the program (using ROOT Version 3.02/07 on g++-Linux) with 'prog()' two histograms 'h2' and 'h3' are created with the function 'getH'. When trying to create 'h3' the value of 'counter' is 1, so that the adress of 'h1' in 'getH' is printed out. Ths works but 'h1' is not defined yet!! 'h1' will be defined some lines later ('TH1F h1=...'). But why do ROOT know the existence of 'h1' before its creation? Does ROOT not delete 'h1' at the end of 'getH' (as it is the standard procedure for any C++ program)? Is this a bug? Or is this extra property of ROOT? Cheers A. Dietz
This archive was generated by hypermail 2b29 : Sat Jan 04 2003 - 23:50:58 MET