File indexing completed on 2025-01-18 10:10:44
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef ROOT7_RHistStatBox
0010 #define ROOT7_RHistStatBox
0011
0012 #include <ROOT/RPave.hxx>
0013 #include <ROOT/RDrawableRequest.hxx>
0014 #include <ROOT/RPadBase.hxx>
0015 #include <ROOT/RDisplayItem.hxx>
0016 #include <ROOT/RHist.hxx>
0017 #include <ROOT/RHistImpl.hxx>
0018 #include <ROOT/RFrame.hxx>
0019
0020 #include <memory>
0021 #include <string>
0022 #include <vector>
0023
0024 namespace ROOT {
0025 namespace Experimental {
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035 class RDisplayHistStat : public RIndirectDisplayItem {
0036 unsigned fShowMask{0};
0037 std::vector<std::string> fEntries;
0038 std::vector<std::string> fLines;
0039 public:
0040 RDisplayHistStat() = default;
0041 RDisplayHistStat(const RDrawable &dr, unsigned mask, const std::vector<std::string> &entries, const std::vector<std::string> &lines) :
0042 RIndirectDisplayItem(dr), fShowMask(mask), fEntries(entries), fLines(lines) {}
0043 ~RDisplayHistStat() override = default;
0044
0045 unsigned GetShowMask() const { return fShowMask; }
0046 const std::vector<std::string> &GetEntries() const { return fEntries; }
0047 };
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058 class RHistStatBoxBase : public RPave {
0059
0060 std::string fTitle;
0061 unsigned fShowMask{0xff};
0062
0063 protected:
0064
0065 enum EShowBits { kShowTitle = 0x1, kShowEntries = 0x2, kShowMean = 0x4, kShowDev = 0x8, kShowRange = 0x10 };
0066
0067 virtual void FillStatistic(unsigned, const RFrame::RUserRanges &, std::vector<std::string> &) const {}
0068
0069 virtual const std::vector<std::string> &GetEntriesNames() const;
0070
0071 std::unique_ptr<RDisplayItem> Display(const RDisplayContext &) override;
0072
0073 public:
0074
0075 class RReply : public RDrawableReply {
0076 unsigned mask{0};
0077 std::vector<std::string> lines;
0078 public:
0079 std::vector<std::string> &GetLines() { return lines; }
0080 void SetMask(unsigned _mask) { mask = _mask; }
0081
0082 ~RReply() override = default;
0083 };
0084
0085 class RRequest : public RDrawableRequest {
0086 unsigned mask{0xff};
0087 public:
0088 RRequest() = default;
0089 unsigned GetMask() const { return mask; }
0090 std::unique_ptr<RDrawableReply> Process() override
0091 {
0092 auto stat = dynamic_cast<RHistStatBoxBase *>(GetContext().GetDrawable());
0093
0094 auto frame = GetContext().GetPad()->GetFrame();
0095 RFrame::RUserRanges ranges;
0096 if (frame) frame->GetClientRanges(GetContext().GetConnId(), ranges);
0097
0098 auto reply = std::make_unique<RReply>();
0099
0100 if (stat) {
0101 stat->fShowMask = GetMask();
0102
0103 reply->SetMask(GetMask());
0104
0105 if (GetMask() & RHistStatBoxBase::kShowTitle)
0106 reply->GetLines().emplace_back(stat->GetTitle());
0107
0108 stat->FillStatistic(GetMask(), ranges, reply->GetLines());
0109 }
0110 return reply;
0111 }
0112 };
0113
0114 RHistStatBoxBase() : RPave("stats") {}
0115
0116 void SetTitle(const std::string &title) { fTitle = title; }
0117 const std::string &GetTitle() const { return fTitle; }
0118 };
0119
0120
0121
0122
0123
0124
0125
0126
0127
0128
0129
0130
0131 template <int DIMENSIONS>
0132 class RHistStatBox : public RHistStatBoxBase {
0133 public:
0134 using HistImpl_t = Detail::RHistImplPrecisionAgnosticBase<DIMENSIONS>;
0135
0136 private:
0137 Internal::RIOShared<HistImpl_t> fHistImpl;
0138
0139 protected:
0140
0141 void CollectShared(Internal::RIOSharedVector_t &vect) override { vect.emplace_back(&fHistImpl); }
0142
0143 public:
0144
0145 template <class HIST>
0146 RHistStatBox(const std::shared_ptr<HIST> &hist, const std::string &title = "")
0147 {
0148 fHistImpl = std::shared_ptr<HistImpl_t>(hist, hist->GetImpl());
0149 SetTitle(title);
0150 }
0151
0152 std::shared_ptr<HistImpl_t> GetHist() const { return fHistImpl.get_shared(); }
0153 };
0154
0155
0156 class RHist1StatBox final : public RHistStatBox<1> {
0157 protected:
0158 void FillStatistic(unsigned, const RFrame::RUserRanges &, std::vector<std::string> &) const override;
0159 public:
0160 template <class HIST>
0161 RHist1StatBox(const std::shared_ptr<HIST> &hist, const std::string &title = "") : RHistStatBox<1>(hist, title) {}
0162 };
0163
0164 class RHist2StatBox final : public RHistStatBox<2> {
0165 protected:
0166 void FillStatistic(unsigned, const RFrame::RUserRanges &, std::vector<std::string> &) const override;
0167 public:
0168 template <class HIST>
0169 RHist2StatBox(const std::shared_ptr<HIST> &hist, const std::string &title = "") : RHistStatBox<2>(hist, title) {}
0170 };
0171
0172 class RHist3StatBox final : public RHistStatBox<3> {
0173 protected:
0174 void FillStatistic(unsigned, const RFrame::RUserRanges &, std::vector<std::string> &) const override;
0175 public:
0176 template <class HIST>
0177 RHist3StatBox(const std::shared_ptr<HIST> &hist, const std::string &title = "") : RHistStatBox<3>(hist, title) {}
0178 };
0179
0180 }
0181 }
0182
0183 #endif