Logo ROOT   6.10/09
Reference Guide
THistDrawable.hxx
Go to the documentation of this file.
1 /// \file ROOT/THistDrawable.h
2 /// \ingroup Hist 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 is welcome!
6 
7 /*************************************************************************
8  * Copyright (C) 1995-2015, Rene Brun and Fons Rademakers. *
9  * All rights reserved. *
10  * *
11  * For the licensing terms see $ROOTSYS/LICENSE. *
12  * For the list of contributors see $ROOTSYS/README/CREDITS. *
13  *************************************************************************/
14 
15 #ifndef ROOT7_THistDrawable
16 #define ROOT7_THistDrawable
17 
18 #include "ROOT/TDrawable.hxx"
20 #include "ROOT/TLogger.hxx"
21 
22 #include <memory>
23 
24 class TH1;
25 
26 namespace ROOT {
27 namespace Experimental {
28 
29 template<int DIMENSIONS, class PRECISION,
30  template <int D_, class P_, template <class P__> class STORAGE> class... STAT>
31 class THist;
32 
33 namespace Detail {
34 template <int DIMENSIONS> class THistImplPrecisionAgnosticBase;
35 }
36 
37 namespace Internal {
38 
40 
41 template <int DIMENSION>
44 
45 protected:
46  THistPainterBase() { fgPainter = this; }
47  virtual ~THistPainterBase();
48 
49 public:
51  if (!fgPainter)
53  return fgPainter;
54  }
55 
56  /// Paint a THist. All we need is access to its GetBinContent()
57  virtual void Paint(TDrawable& obj, THistDrawOptions<DIMENSION> opts,
58  TCanvas& canv) = 0;
59 };
60 
61 extern template class THistPainterBase<1>;
62 extern template class THistPainterBase<2>;
63 extern template class THistPainterBase<3>;
64 
66 protected:
67  std::unique_ptr<TH1> fOldHist;
68 
69 public:
70  TH1* GetOldHist() const { return fOldHist.get(); }
71 
74  virtual ~THistDrawableBase();
75 
77 };
78 
79 template <int DIMENSIONS>
80 class THistDrawable final: public THistDrawableBase {
81 public:
83 
84 private:
87 
88  bool UpdateOldHist();
89 public:
90  template<class HIST>
91  THistDrawable(const std::shared_ptr<HIST>& hist, THistDrawOptions<DIMENSIONS> opts):
92  fHistImpl(std::shared_ptr<HistImpl_t>(hist, hist->GetImpl())),
93  fOpts(opts) {}
94 
95  template<class HIST>
96  THistDrawable(std::unique_ptr<HIST>&& hist, THistDrawOptions<DIMENSIONS> opts):
97  fHistImpl(std::unique_ptr<HistImpl_t>(std::move(hist->TakeImpl()))),
98  fOpts(opts) {}
99 
100  /// Paint the histogram
101  void Paint(TCanvas& canv) final {
102  if (UpdateOldHist())
103  THistPainterBase<DIMENSIONS>::GetPainter()->Paint(*this, fOpts, canv);
104  }
105 };
106 
107 extern template class THistDrawable<1>;
108 extern template class THistDrawable<2>;
109 extern template class THistDrawable<3>;
110 
111 } // namespace Internal
112 } // namespace Experimental
113 } // namespace ROOT
114 
115 #endif
Namespace for new ROOT classes and functions.
Definition: StringConv.hxx:21
Graphic container for TDrawable-s.
Definition: TCanvas.hxx:38
STL namespace.
static THistPainterBase< DIMENSION > * GetPainter()
THistDrawable(const std::shared_ptr< HIST > &hist, THistDrawOptions< DIMENSIONS > opts)
#define PRECISION
Definition: MnPrint.cxx:26
virtual void Paint(TDrawable &obj, THistDrawOptions< DIMENSION > opts, TCanvas &canv)=0
Paint a THist. All we need is access to its GetBinContent()
static THistPainterBase< DIMENSION > * fgPainter
THistDrawOptions< DIMENSIONS > fOpts
THistDrawable(std::unique_ptr< HIST > &&hist, THistDrawOptions< DIMENSIONS > opts)
void Paint(TCanvas &canv) final
Paint the histogram.
The TH1 histogram class.
Definition: TH1.h:56
Base class for THistImplBase that abstracts out the histogram&#39;s PRECISION.
Binding & operator=(OUT(*fun)(void))
Base class for drawable entities: objects that can be painted on a TPad.
Definition: TDrawable.hxx:30
Drawing options for a histogram with DIMENSIONS.