Re: (2) painting an object derived from TH1

From: Rene Brun (Rene.Brun@cern.ch)
Date: Thu Oct 21 1999 - 23:02:17 MEST


Hi Victor, Damir,
There is no need for TH1::SetPainter
You can directly use the static function
  TVirtualHistPainter::SetPainter(const char* myPainterClassname)
Once this is called (once per job), TH1::Paint will automatically
invoke your painter.
Note that each histogram has its own painter instance in such a way
that the system can work in a multithreaded environment.

Rene Brun

On Thu, 21 Oct 1999, Victor Perevoztchikov wrote:

>   Hi Damir,
> in new TH1 class no method SetPainter(TVirtualHistPainter *userPainter);
> If Rene & Fons will add it, then you can create your painter
> object derived from TVirtualHistPainter and set it to histogram.
> 
> As a temporary solution you can use the following "barbaric" function
> to add your method to histogram. When rene will add SetPainter to TH1
> then you can remove it.
> 
> void SetPainter(TH1 *h,TVirtualHistPainter *p)
> {
>   TVirtualHistPainter **s =   (TVirtualHistPainter **)((int*)h+117);
>   p->SetHistogram(h);
>   *s = p;
> }
> 
> Victor
> 
> "Valeri Fine (Faine)" wrote:
> > 
> > ----- Original Message -----
> > From: Valeri Fine (Faine) <fine@bnl.gov>
> > To: Damir Buskulic <buskulic@lapp.in2p3.fr>; ROOT mailing list <roottalk@hpsalo.cern.ch>
> > Subject: Re: painting an object derived from TH1
> > 
> > ----- Original Message -----
> > From: Damir Buskulic <buskulic@lapp.in2p3.fr>
> > To: ROOT mailing list <roottalk@hpsalo.cern.ch>
> > Subject: painting an object derived from TH1
> > 
> > > Hi,
> > >
> > > with the new library scheme of ROOT, the Painter and Hist are separated.
> > > I have a class that derives from TH1F, but I would like to paint some
> > > parts differently, namely the stat box. Before, I was just overloading
> > > the TH1::PaintStats method.
> > > How can I do it now ? Do I have to specify a completely different
> > > painter that I have to rewrite ? I looked a little bit at the code and
> > > found that the static member fgPainter was holding the class description
> > > of the current Painter. Since it is static, I cannot change it without
> > > changing also the painter for regular TH1.
> > > I suppose I'll just put regular stats off and overlay my own stat box.
> > >
> > > Any other ideas ?
> > 
> > I missed one essential point, one has to add
> >                 fPainter->StHistogram(this) ;
> > statement to get:
> > 
> > 
> > class  TMyHist : public TH1 {
> >   public:
> >     TVirtualHistPainter * Painter(TVirtualHistPainter *myPainter) {
> >       TVirtualHistPainter * old = fPainter;
> >       fPainter  = myPainter;
> >       if (fPainter) fPainter->SetHistogram(this) ;
> >       return old;
> >     }
> > }
> > 
> >   Afterwards you can define your own painter and attach it to your particular
> > histogram. This way you may use either standard or your own Painter with each
> > other Update step or for different TPads.
> > 
> >  Another solution:
> > 
> > class  TMyHist : public TH1 {
> >   public:
> >     TVirtualHistPainter * Painter(TVirtualHistPainter *myPainter) {
> >        delete fPainter; fPainter = 0;
> >       if (myPainter) {
> >         fPainter  = myPainter;
> >         fPainter->SetHistogram(this) ;
> >      }
> >       return fPainter  ;
> >     }
> > }
> > 
> >                          Valery
> 
> -- 
> Victor M. Perevoztchikov   perev@bnl.gov  perev@vxcern.cern.ch       
> Brookhaven National Laboratory MS 510A PO Box 5000 Upton NY 11973-5000
> tel office : 516-344-7894; fax 516-344-4206; home 516-345-2690
> 



This archive was generated by hypermail 2b29 : Tue Jan 04 2000 - 00:43:41 MET