Re: [ROOT] Problems accessing protected data members of root classes

From: Rene Brun (Rene.Brun@cern.ch)
Date: Tue May 30 2000 - 16:38:26 MEST


Hi Birger,
In theory, CINT does not work when a class defined in the interpreter
derives from a compiled class. In practice, you can do it if you call non
virtual functions of the base classes (or if these functions are not redefined
in the interpreted class).
Using the protected members directly seems to be a bit more tricky.

The solution is to use the script compiler as illustrated below.
In attachment, I have a slightly modified version of your class (file band.C)
You can do:

Root > .L band.C++   (this will invoke the compiler and dynamic linker)
Root > TBand b(hist)

Rene Brun


Birger Koblitz wrote:
> 
> Hi Rene,
> 
> thanks for your help. The solution you proposed seems to work. Anyway, the
> problem remains that I was not able to write into the protected data
> members of a class I derived from. This is a bug in CINT in case that I
> did not do a stupid error and it seems I didnt!
> If you have another look at the following lines, you can see that clearly
> fX should have the value of fx in the second printout, which it does not
> have.
> -----------------------------------------------
>   fx=(Float_t *)new Float_t[fN];
>   fy=(Float_t *)new Float_t[fN];
>   cout << "1.  " << fx << " " << fX << endl;
>   fX=(Float_t *)fx; fY=(Float_t *)fy;
>   cout << "2.  " << fx << " " << fX << endl;
> -----------------------------------------------
> Printout:
> 1.  0x209895b8 0xc8
> 2.  0x209895b8 0x209898e8   ??????????????????
> -----------------------------------------------
> My idea of the class was a polyline which automatically expands when
> one adds a histo in a way that it is allways the convex hull of all the
> histograms passed to it. The reason for implementing it in this way is,
> that there is no TGraph with asymetric errors which can be drawn as a
> filled area. At least this is what I found in 2.24/02 and in some
> statement on the rootlist quite some time ago.
> 
> Again thanks for your quick help,
>   Birger
> 
> /------------------------------------------------------------\
> | Birger Koblitz                    koblitz@mail.desy.de     |
> | Max-Planck-Institut fuer Physik                            |
> | (Werner Heisenberg-Institut)                               |
> | DESY-FH1K                         Tel. (40) 8998-3971      |
> | Notkestr. 85                                               |
> | D-22603  HAMBURG                                           |
> \------------------------------------------------------------/

#ifndef TBAND_H
#define TBAND_H

//#if !defined(__CINT__) || defined(__MAKECINT__)
#include <TPolyLine.h>
#include "TH1.h"
#include "iostream.h"
//#endif
class TBand : public TPolyLine{
  Int_t fND;            // Number of default Points
  Float_t *fXD;
  Float_t *fYD;

 public:
  TBand();
  TBand(TH1F *H);
  ~TBand();
  void AddHisto(TH1F *H){;}
  void DefaultHisto(TH1F *H);
};

#endif

// A constructor
TBand::TBand(){
  fND=0;
  fXD=0;
  fYD=0;
}
TBand::~TBand(){
printf ("TBand destructor called\n");
  fND=0;
  if (fXD) delete [] fXD;
  if (fYD) delete [] fYD;
}

TBand::TBand(TH1F *H){
  Float_t *fx,*fy;
  int i;

  DefaultHisto(H);
  
#ifdef NEVER
  int N=2*fND;
  fx=(Float_t *)new Float_t[N];
  fy=(Float_t *)new Float_t[N];
  for(i=1; i<= fND ; i++){
    fx[i-1] =H->GetBinCenter(i);
    fx[N-i] = H->GetBinCenter(i);
    fy[i-1] = fy[N-i] = H->GetBin(i);
  }
  SetPolyLine(N,fx,fy);
#endif
  fN=2*fND;
  fx=(Float_t *)new Float_t[fN];
  fy=(Float_t *)new Float_t[fN];
  cout << "2.  " << fx << " " << fX << endl;
  fX=(Float_t *)fx; fY=(Float_t *)fy;
  cout << "1.  " << fx << " " << fX << endl;
  for(i=1; i<= fND ; i++){
    fx[i-1] =H->GetBinCenter(i);
    fx[fN-i] = H->GetBinCenter(i);
    fY[i-1] = fY[fN-i] = H->GetBin(i);
  }
}

void TBand::DefaultHisto(TH1F *H){

  fND=H->GetNbinsX();
  if(!fND) return;
  
  fXD=(Float_t *)new Float_t[fND];
  fYD=(Float_t *)new Float_t[fND];

  for(int i=1; i<= fND ; i++){
    fXD[i]=H->GetBinCenter(i);
    fYD[i]=H->GetBin(i);
  }
}



This archive was generated by hypermail 2b29 : Tue Jan 02 2001 - 11:50:26 MET