Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RHistDrawable.hxx
Go to the documentation of this file.
1/// \file ROOT/RHistDrawable.hxx
2/// \ingroup HistDrawV7
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_RHistDrawable
17#define ROOT7_RHistDrawable
18
19#include <ROOT/RDrawable.hxx>
20#include <ROOT/RAttrLine.hxx>
21#include <ROOT/RAttrText.hxx>
22#include <ROOT/RAttrMarker.hxx>
23#include <ROOT/RAttrFill.hxx>
24#include <ROOT/RAttrValue.hxx>
25#include <ROOT/RHist.hxx>
26#include <ROOT/RHistImpl.hxx>
27
28// TODO: move to separate file
30#include <ROOT/RDisplayItem.hxx>
31
32#include <memory>
33
34namespace ROOT {
35namespace Experimental {
36
38 RAttrValue<std::string> fKind{this, "kind", ""}; ///<! hist draw kind
39 RAttrValue<int> fSub{this, "sub", -1}; ///<! hist draw sub kind
40
41protected:
42
43 bool IsFrameRequired() const final { return true; }
44
45 void PopulateMenu(RMenuItems &) override { }
46
47 void SetDrawKind(const std::string &kind, int sub = -1)
48 {
49 fKind = kind;
50 if (sub >= 0)
51 fSub = sub;
52 else
53 fSub.Clear();
54 }
55
56 std::string GetDrawKind() const { return fKind; }
57
58 virtual std::unique_ptr<RDisplayItem> CreateHistDisplay(const RDisplayContext &) = 0;
59
60 virtual bool Is3D() const { return false; }
61
62 std::unique_ptr<RDisplayItem> Display(const RDisplayContext &ctxt) override
63 {
64 if (optimize)
65 return CreateHistDisplay(ctxt);
66
67 return RDrawable::Display(ctxt);
68 }
69
70public:
71
72 class RReply : public RDrawableReply {
73 public:
74 std::unique_ptr<RDisplayItem> item;
75 };
76
77 class RRequest : public RDrawableRequest {
78 std::unique_ptr<RDrawableReply> Process() override
79 {
80 auto hdraw = dynamic_cast<RHistDrawableBase *>(GetContext().GetDrawable());
81
82 auto reply = std::make_unique<RReply>();
83 if (hdraw)
84 reply->item = hdraw->CreateHistDisplay(GetContext());
85 return reply;
86 }
87 };
88
89 friend class RRequest;
90
91 RAttrLine line{this, "line"}; ///<! hist line attributes
92 RAttrFill fill{this, "fill"}; ///<! hist fill attributes
93 RAttrMarker marker{this, "marker"}; ///<! hist marker attributes
94 RAttrText text{this, "text"}; ///<! hist text attributes
95 RAttrValue<bool> optimize{this, "optimize", false}; ///<! optimize drawing
96
98};
99
100
101template <int DIMENSIONS>
103public:
105
106protected:
107
108 Internal::RIOShared<HistImpl_t> fHistImpl; ///< I/O capable reference on histogram
109
110 void CollectShared(Internal::RIOSharedVector_t &vect) override { vect.emplace_back(&fHistImpl); }
111
112public:
113 RHistDrawable() = default;
114 virtual ~RHistDrawable() = default;
115
116 template <class HIST>
117 RHistDrawable(const std::shared_ptr<HIST> &hist) : RHistDrawableBase()
118 {
119 fHistImpl = std::shared_ptr<HistImpl_t>(hist, hist->GetImpl());
120 }
121
122 std::shared_ptr<HistImpl_t> GetHist() const { return fHistImpl.get_shared(); }
123};
124
125
126class RHist1Drawable final : public RHistDrawable<1> {
127protected:
128 std::unique_ptr<RDisplayItem> CreateHistDisplay(const RDisplayContext &) override;
129
130 bool Is3D() const final { return GetDrawKind() == "lego"; }
131
132public:
133 RAttrValue<bool> drawtext{this, "drawtext", false}; ///<! draw text
134 RAttrValue<bool> secondx{this, "secondx", false}; ///<! is draw second x axis for histogram
135 RAttrValue<bool> secondy{this, "secondy", false}; ///<! is draw second y axis for histogram
136 RAttrValue<double> baroffset{this, "baroffset", 0.}; ///<! bar offset
137 RAttrValue<double> barwidth{this, "barwidth", 1.}; ///<! bar width
138
139 RHist1Drawable() = default;
140
141 template <class HIST>
142 RHist1Drawable(const std::shared_ptr<HIST> &hist) : RHistDrawable<1>(hist) {}
143
144 RHist1Drawable &Bar() { SetDrawKind("bar", 0); return *this; }
145 RHist1Drawable &Bar(double _offset, double _width, bool mode3d = false) { SetDrawKind("bar", mode3d ? 1 : 0); baroffset = _offset; barwidth = _width; return *this; }
146 RHist1Drawable &Error(int kind = 0) { SetDrawKind("err", kind); return *this; }
147 RHist1Drawable &Marker() { SetDrawKind("p"); return *this; }
149 RHist1Drawable &Hist() { SetDrawKind("hist"); return *this; }
150 RHist1Drawable &Line() { SetDrawKind("l"); return *this; }
151 RHist1Drawable &Lego(int kind = 0) { SetDrawKind("lego", kind); return *this; }
152 RHist1Drawable &Text() { drawtext = true; return *this; }
153
154 bool IsBar() const { return GetDrawKind() == "bar"; }
155 bool IsError() const { return GetDrawKind() == "err"; }
156 bool IsMarker() const { return GetDrawKind() == "p"; }
157 bool IsHist() const { return GetDrawKind() == "hist"; }
158 bool IsLine() const { return GetDrawKind() == "l"; }
159 bool IsLego() const { return GetDrawKind() == "lego"; }
160 bool IsText() const { return drawtext; }
161};
162
163
164class RHist2Drawable final : public RHistDrawable<2> {
165protected:
166
167 std::unique_ptr<RDisplayItem> CreateHistDisplay(const RDisplayContext &) override;
168
169 bool Is3D() const final { return (GetDrawKind() == "lego") || (GetDrawKind() == "surf") || (GetDrawKind() == "err"); }
170
171public:
172 RAttrValue<bool> drawtext{this, "drawtext", false}; ///<! draw text
173
174 RHist2Drawable() = default;
175
176 template <class HIST>
177 RHist2Drawable(const std::shared_ptr<HIST> &hist) : RHistDrawable<2>(hist) {}
178
179 RHist2Drawable &Color() { SetDrawKind("col"); return *this; }
180 RHist2Drawable &Box(int kind = 0) { SetDrawKind("box", kind); return *this; }
181 RHist2Drawable &Lego(int kind = 0) { SetDrawKind("lego", kind); return *this; }
182 RHist2Drawable &Surf(int kind = 0) { SetDrawKind("surf", kind); return *this; }
183 RHist2Drawable &Error() { SetDrawKind("err"); return *this; }
184 RHist2Drawable &Contour(int kind = 0) { SetDrawKind("cont", kind); return *this; }
185 RHist2Drawable &Scatter() { SetDrawKind("scat"); return *this; }
186 RHist2Drawable &Arrow() { SetDrawKind("arr"); return *this; }
187 RHist2Drawable &Text() { drawtext = true; return *this; }
188
189 bool IsColor() const { return GetDrawKind() == "col"; }
190 bool IsBox() const { return GetDrawKind() == "box"; }
191 bool IsLego() const { return GetDrawKind() == "lego"; }
192 bool IsSurf() const { return GetDrawKind() == "surf"; }
193 bool IsError() const { return GetDrawKind() == "err"; }
194 bool IsContour() const { return GetDrawKind() == "cont"; }
195 bool IsScatter() const { return GetDrawKind() == "scat"; }
196 bool IsArrow() const { return GetDrawKind() == "arr"; }
197 bool IsText() const { return drawtext; }
198};
199
200
201class RHist3Drawable final : public RHistDrawable<3> {
202protected:
203 std::unique_ptr<RDisplayItem> CreateHistDisplay(const RDisplayContext &) override;
204
205 bool Is3D() const final { return true; }
206
207public:
208 RHist3Drawable() = default;
209
210 template <class HIST>
211 RHist3Drawable(const std::shared_ptr<HIST> &hist) : RHistDrawable<3>(hist) {}
212
213 RHist3Drawable &Color() { SetDrawKind("col"); return *this; }
214 RHist3Drawable &Box(int kind = 0) { SetDrawKind("box", kind); return *this; }
215 RHist3Drawable &Sphere(int kind = 0) { SetDrawKind("sphere", kind); return *this; }
216 RHist3Drawable &Scatter() { SetDrawKind("scat"); return *this; }
217};
218
219
220inline auto GetDrawable(const std::shared_ptr<RH1D> &histimpl)
221{
222 return std::make_shared<RHist1Drawable>(histimpl);
223}
224
225inline auto GetDrawable(const std::shared_ptr<RH1I> &histimpl)
226{
227 return std::make_shared<RHist1Drawable>(histimpl);
228}
229
230inline auto GetDrawable(const std::shared_ptr<RH1C> &histimpl)
231{
232 return std::make_shared<RHist1Drawable>(histimpl);
233}
234
235inline auto GetDrawable(const std::shared_ptr<RH1F> &histimpl)
236{
237 return std::make_shared<RHist1Drawable>(histimpl);
238}
239
240inline auto GetDrawable(const std::shared_ptr<RH2D> &histimpl)
241{
242 return std::make_shared<RHist2Drawable>(histimpl);
243}
244
245inline auto GetDrawable(const std::shared_ptr<RH2I> &histimpl)
246{
247 return std::make_shared<RHist2Drawable>(histimpl);
248}
249
250inline auto GetDrawable(const std::shared_ptr<RH2C> &histimpl)
251{
252 return std::make_shared<RHist2Drawable>(histimpl);
253}
254
255inline auto GetDrawable(const std::shared_ptr<RH2F> &histimpl)
256{
257 return std::make_shared<RHist2Drawable>(histimpl);
258}
259
260inline auto GetDrawable(const std::shared_ptr<RH3D> &histimpl)
261{
262 return std::make_shared<RHist3Drawable>(histimpl);
263}
264
265inline auto GetDrawable(const std::shared_ptr<RH3I> &histimpl)
266{
267 return std::make_shared<RHist3Drawable>(histimpl);
268}
269
270inline auto GetDrawable(const std::shared_ptr<RH3C> &histimpl)
271{
272 return std::make_shared<RHist3Drawable>(histimpl);
273}
274
275inline auto GetDrawable(const std::shared_ptr<RH3F> &histimpl)
276{
277 return std::make_shared<RHist3Drawable>(histimpl);
278}
279
280} // namespace Experimental
281} // namespace ROOT
282
283#endif
Base class for RHistImplBase that abstracts out the histogram's PRECISION.
Definition RHistImpl.hxx:72
Drawing fill attributes for different objects.
Definition RAttrFill.hxx:26
Drawing line attributes for different objects.
Definition RAttrLine.hxx:26
RAttrValue< EStyle > style
! marker style
Template class to access single value from drawable or other attributes.
Base class for replies on RDrawableRequest.
Base class for requests which can be submitted from the clients.
const RDrawable::RDisplayContext & GetContext() const
Base class for drawable entities: objects that can be painted on a RPad.
virtual std::unique_ptr< RDisplayItem > Display(const RDisplayContext &)
Creates display item for drawable By default item contains drawable data itself.
Definition RDrawable.cxx:68
RAttrValue< double > barwidth
! bar width
std::unique_ptr< RDisplayItem > CreateHistDisplay(const RDisplayContext &) override
RHist1Drawable & Lego(int kind=0)
RHist1Drawable(const std::shared_ptr< HIST > &hist)
RAttrValue< bool > secondy
! is draw second y axis for histogram
RHist1Drawable & Bar(double _offset, double _width, bool mode3d=false)
RAttrValue< bool > secondx
! is draw second x axis for histogram
RAttrValue< double > baroffset
! bar offset
RHist1Drawable & Error(int kind=0)
RAttrValue< bool > drawtext
! draw text
RHist2Drawable & Surf(int kind=0)
RHist2Drawable & Contour(int kind=0)
RHist2Drawable & Box(int kind=0)
RHist2Drawable & Lego(int kind=0)
RHist2Drawable(const std::shared_ptr< HIST > &hist)
std::unique_ptr< RDisplayItem > CreateHistDisplay(const RDisplayContext &) override
RAttrValue< bool > drawtext
! draw text
std::unique_ptr< RDisplayItem > CreateHistDisplay(const RDisplayContext &) override
RHist3Drawable & Box(int kind=0)
RHist3Drawable(const std::shared_ptr< HIST > &hist)
RHist3Drawable & Sphere(int kind=0)
std::unique_ptr< RDrawableReply > Process() override
std::unique_ptr< RDisplayItem > Display(const RDisplayContext &ctxt) override
Creates display item for drawable By default item contains drawable data itself.
RAttrText text
! hist text attributes
virtual std::unique_ptr< RDisplayItem > CreateHistDisplay(const RDisplayContext &)=0
RAttrMarker marker
! hist marker attributes
RAttrLine line
! hist line attributes
RAttrFill fill
! hist fill attributes
RAttrValue< bool > optimize
! optimize drawing
void PopulateMenu(RMenuItems &) override
void SetDrawKind(const std::string &kind, int sub=-1)
RAttrValue< std::string > fKind
! hist draw kind
RAttrValue< int > fSub
! hist draw sub kind
Internal::RIOShared< HistImpl_t > fHistImpl
I/O capable reference on histogram.
std::shared_ptr< HistImpl_t > GetHist() const
void CollectShared(Internal::RIOSharedVector_t &vect) override
RHistDrawable(const std::shared_ptr< HIST > &hist)
List of items for object context menu.
std::vector< RIOSharedBase * > RIOSharedVector_t
Definition RDrawable.hxx:52
auto GetDrawable(const std::shared_ptr< DRAWABLE > &drawable)
Central method to insert drawable in list of pad primitives By default drawable placed as is.
This file contains a specialised ROOT message handler to test for diagnostic in unit tests.