[ROOT] Problems accessing protected data members of root classes

From: Birger Koblitz (koblitz@mail.desy.de)
Date: Tue May 30 2000 - 12:08:26 MEST


Hi,

I am trying to make a class to show the band defined by a MC using
different of the tuning parameters. I do this via inheriting from
TPolyLine:

---------- TBand.h ----------------
#ifndef TBAND_H
#define TBAND_H

#if !defined(__CINT__) || defined(__MAKECINT__)
#include <TPolyLine.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();
};

#endif

// A constructor
TBand::TBand(){
  fND=0;
  fXD=0;
  fYD=0;
}

------------ TBand.C ------------------
#include "TBand.h"

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

  DefaultHisto(H);
  
  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);
  }
}
-----------------------------------------------

Now starting the code and looking what is written into the protected data
member fX one sees:
root [0] .L TBand.C                    
root [1] TFile f("gen/qcdins_new.root")
root [2] h133->Draw("bsph >> hi")  // Make some histo
root [5] TBand tb(hi)              // Init Band
1.  0x209895b8 0xc8
2.  0x209895b8 0x209898e8          ????????????????????/

which gives a nice segmentation violation some lines later. Obviously the
class can not overwrite the protected data member!
Could someone help me, please?

Cheers,
  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                                           |
\------------------------------------------------------------/



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