File indexing completed on 2025-01-18 10:10:44
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016 #ifndef ROOT7_RHistDrawable
0017 #define ROOT7_RHistDrawable
0018
0019 #include <ROOT/RDrawable.hxx>
0020 #include <ROOT/RAttrLine.hxx>
0021 #include <ROOT/RAttrText.hxx>
0022 #include <ROOT/RAttrMarker.hxx>
0023 #include <ROOT/RAttrFill.hxx>
0024 #include <ROOT/RAttrValue.hxx>
0025 #include <ROOT/RHist.hxx>
0026 #include <ROOT/RHistImpl.hxx>
0027
0028
0029 #include <ROOT/RDrawableRequest.hxx>
0030 #include <ROOT/RDisplayItem.hxx>
0031
0032 #include <memory>
0033
0034 namespace ROOT {
0035 namespace Experimental {
0036
0037 class RHistDrawableBase : public RDrawable {
0038 RAttrValue<std::string> fKind{this, "kind", ""};
0039 RAttrValue<int> fSub{this, "sub", -1};
0040
0041 protected:
0042
0043 bool IsFrameRequired() const final { return true; }
0044
0045 void PopulateMenu(RMenuItems &) override { }
0046
0047 void SetDrawKind(const std::string &kind, int sub = -1)
0048 {
0049 fKind = kind;
0050 if (sub >= 0)
0051 fSub = sub;
0052 else
0053 fSub.Clear();
0054 }
0055
0056 std::string GetDrawKind() const { return fKind; }
0057
0058 virtual std::unique_ptr<RDisplayItem> CreateHistDisplay(const RDisplayContext &) = 0;
0059
0060 virtual bool Is3D() const { return false; }
0061
0062 std::unique_ptr<RDisplayItem> Display(const RDisplayContext &ctxt) override
0063 {
0064 if (optimize)
0065 return CreateHistDisplay(ctxt);
0066
0067 return RDrawable::Display(ctxt);
0068 }
0069
0070 public:
0071
0072 class RReply : public RDrawableReply {
0073 public:
0074 std::unique_ptr<RDisplayItem> item;
0075 };
0076
0077 class RRequest : public RDrawableRequest {
0078 std::unique_ptr<RDrawableReply> Process() override
0079 {
0080 auto hdraw = dynamic_cast<RHistDrawableBase *>(GetContext().GetDrawable());
0081
0082 auto reply = std::make_unique<RReply>();
0083 if (hdraw)
0084 reply->item = hdraw->CreateHistDisplay(GetContext());
0085 return reply;
0086 }
0087 };
0088
0089 friend class RRequest;
0090
0091 RAttrLine line{this, "line"};
0092 RAttrFill fill{this, "fill"};
0093 RAttrMarker marker{this, "marker"};
0094 RAttrText text{this, "text"};
0095 RAttrValue<bool> optimize{this, "optimize", false};
0096
0097 RHistDrawableBase() : RDrawable("hist") {}
0098 };
0099
0100
0101 template <int DIMENSIONS>
0102 class RHistDrawable : public RHistDrawableBase {
0103 public:
0104 using HistImpl_t = Detail::RHistImplPrecisionAgnosticBase<DIMENSIONS>;
0105
0106 protected:
0107
0108 Internal::RIOShared<HistImpl_t> fHistImpl;
0109
0110 void CollectShared(Internal::RIOSharedVector_t &vect) override { vect.emplace_back(&fHistImpl); }
0111
0112 public:
0113 RHistDrawable() = default;
0114 ~RHistDrawable() override = default;
0115
0116 template <class HIST>
0117 RHistDrawable(const std::shared_ptr<HIST> &hist) : RHistDrawableBase()
0118 {
0119 fHistImpl = std::shared_ptr<HistImpl_t>(hist, hist->GetImpl());
0120 }
0121
0122 std::shared_ptr<HistImpl_t> GetHist() const { return fHistImpl.get_shared(); }
0123 };
0124
0125
0126 class RHist1Drawable final : public RHistDrawable<1> {
0127 protected:
0128 std::unique_ptr<RDisplayItem> CreateHistDisplay(const RDisplayContext &) override;
0129
0130 bool Is3D() const final { return GetDrawKind() == "lego"; }
0131
0132 public:
0133 RAttrValue<bool> drawtext{this, "drawtext", false};
0134 RAttrValue<bool> secondx{this, "secondx", false};
0135 RAttrValue<bool> secondy{this, "secondy", false};
0136 RAttrValue<double> baroffset{this, "baroffset", 0.};
0137 RAttrValue<double> barwidth{this, "barwidth", 1.};
0138
0139 RHist1Drawable() = default;
0140
0141 template <class HIST>
0142 RHist1Drawable(const std::shared_ptr<HIST> &hist) : RHistDrawable<1>(hist) {}
0143
0144 RHist1Drawable &Bar() { SetDrawKind("bar", 0); return *this; }
0145 RHist1Drawable &Bar(double _offset, double _width, bool mode3d = false) { SetDrawKind("bar", mode3d ? 1 : 0); baroffset = _offset; barwidth = _width; return *this; }
0146 RHist1Drawable &Error(int kind = 0) { SetDrawKind("err", kind); return *this; }
0147 RHist1Drawable &Marker() { SetDrawKind("p"); return *this; }
0148 RHist1Drawable &Star() { marker.style = RAttrMarker::kStar; return Marker(); }
0149 RHist1Drawable &Hist() { SetDrawKind("hist"); return *this; }
0150 RHist1Drawable &Line() { SetDrawKind("l"); return *this; }
0151 RHist1Drawable &Lego(int kind = 0) { SetDrawKind("lego", kind); return *this; }
0152 RHist1Drawable &Text() { drawtext = true; return *this; }
0153
0154 bool IsBar() const { return GetDrawKind() == "bar"; }
0155 bool IsError() const { return GetDrawKind() == "err"; }
0156 bool IsMarker() const { return GetDrawKind() == "p"; }
0157 bool IsHist() const { return GetDrawKind() == "hist"; }
0158 bool IsLine() const { return GetDrawKind() == "l"; }
0159 bool IsLego() const { return GetDrawKind() == "lego"; }
0160 bool IsText() const { return drawtext; }
0161 };
0162
0163
0164 class RHist2Drawable final : public RHistDrawable<2> {
0165 protected:
0166
0167 std::unique_ptr<RDisplayItem> CreateHistDisplay(const RDisplayContext &) override;
0168
0169 bool Is3D() const final { return (GetDrawKind() == "lego") || (GetDrawKind() == "surf") || (GetDrawKind() == "err"); }
0170
0171 public:
0172 RAttrValue<bool> drawtext{this, "drawtext", false};
0173
0174 RHist2Drawable() = default;
0175
0176 template <class HIST>
0177 RHist2Drawable(const std::shared_ptr<HIST> &hist) : RHistDrawable<2>(hist) {}
0178
0179 RHist2Drawable &Color() { SetDrawKind("col"); return *this; }
0180 RHist2Drawable &Box(int kind = 0) { SetDrawKind("box", kind); return *this; }
0181 RHist2Drawable &Lego(int kind = 0) { SetDrawKind("lego", kind); return *this; }
0182 RHist2Drawable &Surf(int kind = 0) { SetDrawKind("surf", kind); return *this; }
0183 RHist2Drawable &Error() { SetDrawKind("err"); return *this; }
0184 RHist2Drawable &Contour(int kind = 0) { SetDrawKind("cont", kind); return *this; }
0185 RHist2Drawable &Scatter() { SetDrawKind("scat"); return *this; }
0186 RHist2Drawable &Arrow() { SetDrawKind("arr"); return *this; }
0187 RHist2Drawable &Text() { drawtext = true; return *this; }
0188
0189 bool IsColor() const { return GetDrawKind() == "col"; }
0190 bool IsBox() const { return GetDrawKind() == "box"; }
0191 bool IsLego() const { return GetDrawKind() == "lego"; }
0192 bool IsSurf() const { return GetDrawKind() == "surf"; }
0193 bool IsError() const { return GetDrawKind() == "err"; }
0194 bool IsContour() const { return GetDrawKind() == "cont"; }
0195 bool IsScatter() const { return GetDrawKind() == "scat"; }
0196 bool IsArrow() const { return GetDrawKind() == "arr"; }
0197 bool IsText() const { return drawtext; }
0198 };
0199
0200
0201 class RHist3Drawable final : public RHistDrawable<3> {
0202 protected:
0203 std::unique_ptr<RDisplayItem> CreateHistDisplay(const RDisplayContext &) override;
0204
0205 bool Is3D() const final { return true; }
0206
0207 public:
0208 RHist3Drawable() = default;
0209
0210 template <class HIST>
0211 RHist3Drawable(const std::shared_ptr<HIST> &hist) : RHistDrawable<3>(hist) {}
0212
0213 RHist3Drawable &Color() { SetDrawKind("col"); return *this; }
0214 RHist3Drawable &Box(int kind = 0) { SetDrawKind("box", kind); return *this; }
0215 RHist3Drawable &Sphere(int kind = 0) { SetDrawKind("sphere", kind); return *this; }
0216 RHist3Drawable &Scatter() { SetDrawKind("scat"); return *this; }
0217 };
0218
0219
0220 inline auto GetDrawable(const std::shared_ptr<RH1D> &histimpl)
0221 {
0222 return std::make_shared<RHist1Drawable>(histimpl);
0223 }
0224
0225 inline auto GetDrawable(const std::shared_ptr<RH1I> &histimpl)
0226 {
0227 return std::make_shared<RHist1Drawable>(histimpl);
0228 }
0229
0230 inline auto GetDrawable(const std::shared_ptr<RH1C> &histimpl)
0231 {
0232 return std::make_shared<RHist1Drawable>(histimpl);
0233 }
0234
0235 inline auto GetDrawable(const std::shared_ptr<RH1F> &histimpl)
0236 {
0237 return std::make_shared<RHist1Drawable>(histimpl);
0238 }
0239
0240 inline auto GetDrawable(const std::shared_ptr<RH2D> &histimpl)
0241 {
0242 return std::make_shared<RHist2Drawable>(histimpl);
0243 }
0244
0245 inline auto GetDrawable(const std::shared_ptr<RH2I> &histimpl)
0246 {
0247 return std::make_shared<RHist2Drawable>(histimpl);
0248 }
0249
0250 inline auto GetDrawable(const std::shared_ptr<RH2C> &histimpl)
0251 {
0252 return std::make_shared<RHist2Drawable>(histimpl);
0253 }
0254
0255 inline auto GetDrawable(const std::shared_ptr<RH2F> &histimpl)
0256 {
0257 return std::make_shared<RHist2Drawable>(histimpl);
0258 }
0259
0260 inline auto GetDrawable(const std::shared_ptr<RH3D> &histimpl)
0261 {
0262 return std::make_shared<RHist3Drawable>(histimpl);
0263 }
0264
0265 inline auto GetDrawable(const std::shared_ptr<RH3I> &histimpl)
0266 {
0267 return std::make_shared<RHist3Drawable>(histimpl);
0268 }
0269
0270 inline auto GetDrawable(const std::shared_ptr<RH3C> &histimpl)
0271 {
0272 return std::make_shared<RHist3Drawable>(histimpl);
0273 }
0274
0275 inline auto GetDrawable(const std::shared_ptr<RH3F> &histimpl)
0276 {
0277 return std::make_shared<RHist3Drawable>(histimpl);
0278 }
0279
0280 }
0281 }
0282
0283 #endif