Logo ROOT   6.12/07
Reference Guide
THistDrawable.hxx
Go to the documentation of this file.
1 /// \file ROOT/THistDrawable.h
2 /// \ingroup HistDraw ROOT7
3 /// \author Axel Naumann <axel@cern.ch>
4 /// \date 2015-07-09
5 /// \warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback
6 /// is welcome!
7 
8 /*************************************************************************
9  * Copyright (C) 1995-2015, Rene Brun and Fons Rademakers. *
10  * All rights reserved. *
11  * *
12  * For the licensing terms see $ROOTSYS/LICENSE. *
13  * For the list of contributors see $ROOTSYS/README/CREDITS. *
14  *************************************************************************/
15 
16 #ifndef ROOT7_THistDrawable
17 #define ROOT7_THistDrawable
18 
19 #include "ROOT/TDrawable.hxx"
21 #include "ROOT/THistImpl.hxx"
22 #include "ROOT/TMenuItem.hxx"
23 
24 #include <memory>
25 
26 class TH1;
27 
28 namespace ROOT {
29 namespace Experimental {
30 
31 class TPadBase;
32 
33 template <int DIMENSIONS, class PRECISION,
34  template <int D_, class P_, template <class P__> class STORAGE> class... STAT>
35 class THist;
36 
37 namespace Detail {
38 template <int DIMENSIONS>
39 class THistImplPrecisionAgnosticBase;
40 }
41 
42 namespace Internal {
43 
45 
46 template <int DIMENSION>
48  static THistPainterBase<DIMENSION> *&GetPainterPtr();
49 
50 protected:
52  virtual ~THistPainterBase();
53 
54 public:
55  static THistPainterBase<DIMENSION> *GetPainter();
56 
57  /// Paint a THist. All we need is access to its GetBinContent()
58  virtual void Paint(TDrawable &obj, const THistDrawingOpts<DIMENSION> &opts, TVirtualCanvasPainter &canv) = 0;
59 };
60 
61 extern template class THistPainterBase<1>;
62 extern template class THistPainterBase<2>;
63 extern template class THistPainterBase<3>;
64 
65 } // namespace Internal
66 
68 protected:
69  std::unique_ptr<TH1> fOldHist;
70 
71 public:
72  TH1 *GetOldHist() const { return fOldHist.get(); }
73 
76  virtual ~THistDrawableBase();
77 
79 
80  void PopulateMenu(TMenuItems &) final;
81 
82  void Execute(const std::string &) final
83  {
84  // should execute menu item
85  }
86 };
87 
88 template <int DIMENSIONS>
89 class THistDrawable final: public THistDrawableBase {
90 public:
92 
93 private:
96 
97  bool UpdateOldHist();
98 
99 public:
100  THistDrawable();
101 
102  template <class HIST>
103  THistDrawable(const std::shared_ptr<HIST> &hist, TPadBase& pad)
104  : fHistImpl(std::shared_ptr<HistImpl_t>(hist, hist->GetImpl())), fOpts(pad)
105  {}
106 
107  template <class HIST>
108  THistDrawable(std::unique_ptr<HIST> &&hist, TPadBase& pad)
109  : fHistImpl(std::unique_ptr<HistImpl_t>(std::move(hist->TakeImpl()))), fOpts(pad)
110  {}
111 
112  /// Paint the histogram
113  void Paint(Internal::TVirtualCanvasPainter &canv) final;
114 
116  const THistDrawingOpts<DIMENSIONS> &GetOptions() const { return fOpts; }
117 };
118 
119 extern template class THistDrawable<1>;
120 extern template class THistDrawable<2>;
121 extern template class THistDrawable<3>;
122 
123 } // namespace Experimental
124 } // namespace ROOT
125 
126 #endif
Base class for drawable entities: objects that can be painted on a TPad.
Definition: TDrawable.hxx:36
Namespace for new ROOT classes and functions.
Definition: StringConv.hxx:21
Internal::TUniWeakPtr< HistImpl_t > fHistImpl
STL namespace.
#define PRECISION
Definition: MnPrint.cxx:26
Base class for graphic containers for TDrawable-s.
Definition: TPad.hxx:41
void Execute(const std::string &) final
const THistDrawingOpts< DIMENSIONS > & GetOptions() const
THistDrawingOpts< DIMENSIONS > fOpts
Abstract interface for painting a canvas.
THistDrawable(const std::shared_ptr< HIST > &hist, TPadBase &pad)
THistDrawable(std::unique_ptr< HIST > &&hist, TPadBase &pad)
The TH1 histogram class.
Definition: TH1.h:56
Base class for THistImplBase that abstracts out the histogram&#39;s PRECISION.
Definition: THistImpl.hxx:71
Binding & operator=(OUT(*fun)(void))
THistDrawingOpts< DIMENSIONS > & GetOptions()