Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:10:44

0001 /*************************************************************************
0002  * Copyright (C) 1995-2020, Rene Brun and Fons Rademakers.               *
0003  * All rights reserved.                                                  *
0004  *                                                                       *
0005  * For the licensing terms see $ROOTSYS/LICENSE.                         *
0006  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
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 /** \class ROOT::Experimental::RDisplayHistStat
0028 \ingroup GrafROOT7
0029 \brief Object send to client for display of RHistStat, required to avoid sending histogram to the client
0030 \author Sergey Linev <s.linev@gsi.de>
0031 \date 2020-04-17
0032 \warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback is welcome!
0033 */
0034 
0035 class RDisplayHistStat : public RIndirectDisplayItem {
0036    unsigned fShowMask{0};   ///< initial show mask
0037    std::vector<std::string> fEntries; ///< names of entries for context menu
0038    std::vector<std::string> fLines;   ///< filled lines to show in stat box
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 /** \class ROOT::Experimental::RHistStatBoxBase
0051 \ingroup GrafROOT7
0052 \brief Base class for histogram statistic box, provides graphics attributes and virtual method for fill statistic
0053 \author Sergey Linev <s.linev@gsi.de>
0054 \date 2020-04-01
0055 \warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback is welcome!
0056 */
0057 
0058 class RHistStatBoxBase : public RPave {
0059 
0060    std::string fTitle;                       ///< stat box title
0061    unsigned fShowMask{0xff};                 ///< show stat box lines
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};                 ///< mask used to create lines
0077       std::vector<std::string> lines;   ///< text lines displayed in the stat box
0078    public:
0079       std::vector<std::string> &GetLines() { return lines; }
0080       void SetMask(unsigned _mask) { mask = _mask; }
0081       // virtual destructor - required to pin vtable
0082       ~RReply() override = default;
0083    };
0084 
0085    class RRequest : public RDrawableRequest {
0086       unsigned mask{0xff};      // mask of items to show
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 /** \class ROOT::Experimental::RHistStatBox
0123 \ingroup GrafROOT7
0124 \brief Template class for statistic box for RHist class
0125 \author Sergey Linev <s.linev@gsi.de>
0126 \date 2020-04-01
0127 \warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback is welcome!
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;  ///< I/O capable reference on histogram
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 } // namespace Experimental
0181 } // namespace ROOT
0182 
0183 #endif