Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-03-19 09:07:51

0001 // Author: Sergey Linev, 7.10.2022
0002 
0003 /*************************************************************************
0004  * Copyright (C) 1995-2022, Rene Brun and Fons Rademakers.               *
0005  * All rights reserved.                                                  *
0006  *                                                                       *
0007  * For the licensing terms see $ROOTSYS/LICENSE.                         *
0008  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
0009  *************************************************************************/
0010 
0011 #ifndef ROOT7_RTreeViewer
0012 #define ROOT7_RTreeViewer
0013 
0014 #include <ROOT/RWebDisplayArgs.hxx>
0015 
0016 #include "Rtypes.h"
0017 
0018 #include <memory>
0019 #include <vector>
0020 #include <string>
0021 #include <functional>
0022 
0023 class TTree;
0024 class TBranch;
0025 class TLeaf;
0026 class TObjArray;
0027 
0028 namespace ROOT {
0029 
0030 class RWebWindow;
0031 class RTreeDrawMonitoring;
0032 class RTreeDrawInvokeTimer;
0033 
0034 class RTreeViewer {
0035 
0036 friend class RTreeDrawMonitoring;
0037 friend class RTreeDrawInvokeTimer;
0038 
0039 public:
0040 
0041    using PerformDrawCallback_t = std::function<void(const std::string &)>;
0042 
0043    struct RBranchInfo {
0044       std::string fName, fTitle;
0045       RBranchInfo() = default;
0046       RBranchInfo(const std::string &_name, const std::string &_title) : fName(_name), fTitle(_title) {}
0047    };
0048 
0049    struct RConfig {
0050       std::string fTreeName, fExprX, fExprY, fExprZ, fExprCut, fOption;
0051       std::vector<RBranchInfo> fBranches;
0052       Long64_t fNumber{0}, fFirst{0}, fStep{1}, fLargerStep{2}, fTreeEntries{0};
0053    };
0054 
0055    RTreeViewer(TTree *tree = nullptr);
0056    virtual ~RTreeViewer();
0057 
0058    void SetTitle(const std::string &title) { fTitle = title; }
0059    const std::string &GetTitle() const { return fTitle; }
0060 
0061    std::string GetWindowAddr() const;
0062 
0063    std::string GetWindowUrl(bool remote);
0064 
0065    void SetTree(TTree *tree);
0066 
0067    bool SuggestLeaf(const TLeaf *leaf);
0068 
0069    bool SuggestBranch(const TBranch *branch);
0070 
0071    bool SuggestExpression(const std::string &expr);
0072 
0073    void SetCallback(PerformDrawCallback_t func) { fCallback = func; }
0074 
0075    /** Configures default hierarchy browser visibility, only has effect before showing web window */
0076    void SetShowHierarchy(bool on = true) { fShowHierarchy = on; }
0077 
0078    /** Returns default hierarchy browser visibility */
0079    bool GetShowHierarchy() const { return fShowHierarchy; }
0080 
0081    void Show(const RWebDisplayArgs &args = "", bool always_start_new_browser = false);
0082 
0083    void Update();
0084 
0085    static RTreeViewer *NewViewer(TTree *);
0086 
0087 private:
0088 
0089    TTree *fTree{nullptr};                  ///<! TTree to show
0090    std::string fTitle;                     ///<! title of tree viewer
0091    std::shared_ptr<ROOT::RWebWindow> fWebWindow; ///<! web window
0092    bool fShowHierarchy{false};             ///<! show TTree hierarchy
0093    RConfig fCfg;                           ///<! configuration, exchanged between client and server
0094    PerformDrawCallback_t fCallback;        ///<! callback invoked when tree draw performed
0095    std::string fLastSendProgress;          ///<! last send progress to client
0096    std::unique_ptr<RTreeDrawInvokeTimer> fTimer; ///<!  timer to invoke tree draw
0097 
0098    void WebWindowConnect(unsigned connid);
0099    void WebWindowCallback(unsigned connid, const std::string &arg);
0100 
0101    void SendCfg(unsigned connid);
0102 
0103    std::string FormatItemName(const std::string &name);
0104 
0105    void AddBranches(TObjArray *branches);
0106 
0107    void UpdateConfig();
0108 
0109    void SendProgress(Double_t nevent = 0.);
0110 
0111    void InvokeTreeDraw();
0112 };
0113 
0114 } // namespace ROOT
0115 
0116 #endif