Back to home page

EIC code displayed by LXR

 
 

    


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

0001 // @(#)root/eve7:$Id$
0002 // Authors: Matevz Tadel and Alja Mrak Tadel: 2006, 2007, 2018
0003 //
0004 // Based of initial implementation of generic collection access interface
0005 // for CMS framework and Fireworks event display by Christopher D. Jones.
0006 
0007 /*************************************************************************
0008  * Copyright (C) 1995-2019, Rene Brun and Fons Rademakers.               *
0009  * All rights reserved.                                                  *
0010  *                                                                       *
0011  * For the licensing terms see $ROOTSYS/LICENSE.                         *
0012  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
0013  *************************************************************************/
0014 
0015 
0016 #ifndef ROOT7_REveDataCollection
0017 #define ROOT7_REveDataCollection
0018 
0019 #include <ROOT/REveElement.hxx>
0020 #include <ROOT/REveCompound.hxx>
0021 #include <ROOT/REveSecondarySelectable.hxx>
0022 #include <ROOT/REveDataTable.hxx>
0023 
0024 #include <functional>
0025 #include <vector>
0026 #include <iostream>
0027 
0028 class TClass;
0029 
0030 namespace ROOT {
0031 namespace Experimental {
0032 
0033 //==============================================================================
0034 class REveDataItem
0035 {
0036 private:
0037    void*    fDataPtr{nullptr};
0038 
0039    Bool_t   fRnrSelf{true};
0040    Color_t  fColor{0};
0041    Bool_t   fFiltered{false};
0042 
0043 public:
0044 
0045    REveDataItem(void* d, Color_t c): fDataPtr(d), fColor(c){}
0046 
0047    Bool_t  GetRnrSelf() const { return fRnrSelf; }
0048    Color_t GetMainColor()   const { return fColor; }
0049    Bool_t  GetFiltered() const { return fFiltered; }
0050    Bool_t  GetVisible() const { return (!fFiltered) && fRnrSelf; }
0051 
0052    void*  GetDataPtr() { return fDataPtr; } 
0053 
0054    void SetFiltered(Bool_t i) { fFiltered = i; }
0055    void SetMainColor(Color_t i) { fColor = i; }
0056    void SetRnrSelf(Bool_t i) { fRnrSelf = i; }
0057 };
0058 
0059 //==============================================================================
0060 class REveDataItemList: public REveElement,
0061                         public REveSecondarySelectable
0062 {
0063    friend class REveDataCollection;
0064 
0065 public:
0066    typedef  std::function<void (REveDataItemList*, const std::vector<int>&)> ItemsChangeFunc_t;
0067    typedef  std::function<void (REveDataItemList*, Set_t&, const std::set<int>&)> FillImpliedSelectedFunc_t;
0068 
0069    struct TTip {
0070       std::string    fTooltipTitle;
0071       REveDataColumn fTooltipFunction;
0072    };
0073 
0074 private:
0075    std::vector<REveDataItem*> fItems;
0076    ItemsChangeFunc_t fHandlerItemsChange;
0077    FillImpliedSelectedFunc_t fHandlerFillImplied;
0078 
0079    std::vector< std::unique_ptr<TTip> > fTooltipExpressions;
0080 
0081 public:
0082    REveDataItemList(const std::string& n = "Items", const std::string& t = "");
0083    ~REveDataItemList() override {}
0084    Int_t WriteCoreJson(nlohmann::json &cj, Int_t rnr_offset) override;
0085 
0086    virtual void ItemChanged(REveDataItem *item);
0087    virtual void ItemChanged(Int_t idx);
0088    void FillImpliedSelectedSet(Set_t &impSelSet, const std::set<int>& sec_idcs) override;
0089 
0090    void SetItemVisible(Int_t idx, Bool_t visible);
0091    void SetItemColorRGB(Int_t idx, UChar_t r, UChar_t g, UChar_t b);
0092 
0093    Bool_t SingleRnrState() const override { return kTRUE; }
0094    Bool_t SetRnrState(Bool_t) override;
0095 
0096    void ProcessSelectionStr(ElementId_t id, bool multi, bool secondary, const char* in_secondary_idcs);
0097    void ProcessSelection(ElementId_t id, bool multi, bool secondary, const std::set<int>& in_secondary_idcs);
0098 
0099    void AddTooltipExpression(const std::string &title, const std::string &expr, bool init = true);
0100 
0101    using REveElement::GetHighlightTooltip;
0102    std::string GetHighlightTooltip(const std::set<int>& secondary_idcs) const override;
0103 
0104    void SetItemsChangeDelegate (ItemsChangeFunc_t);
0105    void SetFillImpliedSelectedDelegate (FillImpliedSelectedFunc_t);
0106 
0107    static void DummyItemsChange(REveDataItemList*, const std::vector<int>&);
0108    static void DummyFillImpliedSelected(REveDataItemList*, Set_t& impSelSet, const std::set<int>& sec_idcs);
0109 
0110    std::vector< std::unique_ptr<TTip> >& RefToolTipExpressions() {return fTooltipExpressions;}
0111 };
0112 
0113 //==============================================================================
0114 
0115 class REveDataCollection : public REveElement
0116 {
0117 private:
0118    REveDataItemList* fItemList{nullptr};
0119    int      fLayer{0};
0120 
0121 public:
0122    typedef std::vector<int> Ids_t;
0123    static Color_t fgDefaultColor;
0124 
0125    TClass *fItemClass{nullptr}; // so far only really need class name
0126 
0127    TString fFilterExpr;
0128    std::function<bool(void *)> fFilterFoo = [](void *) { return true; };
0129 
0130    REveDataCollection(const std::string& n = "REveDataCollection", const std::string& t = "");
0131    ~REveDataCollection() override {}
0132 
0133    void ReserveItems(Int_t items_size) { fItemList->fItems.reserve(items_size); }
0134    void AddItem(void *data_ptr, const std::string& n, const std::string& t);
0135    void ClearItems() { fItemList->fItems.clear(); }
0136 
0137    Bool_t SingleRnrState() const override { return kTRUE; }
0138    Bool_t SetRnrState(Bool_t) override;
0139 
0140 
0141    TClass *GetItemClass() const { return fItemClass; }
0142    void SetItemClass(TClass *cls) { fItemClass = cls;}
0143 
0144    int GetLayer() const { return fLayer; }
0145    void SetLayer(int i) { fLayer = i; }
0146 
0147    REveDataItemList* GetItemList() {return fItemList;}
0148 
0149    void SetFilterExpr(const char* filter);
0150    void ApplyFilter();
0151 
0152    const char* GetFilterExpr(){return fFilterExpr.Data();}
0153 
0154    Int_t GetNItems() const { return (Int_t) fItemList->fItems.size(); }
0155    void *GetDataPtr(Int_t i) const { return  fItemList->fItems[i]->GetDataPtr(); }
0156    const REveDataItem* GetDataItem(Int_t i) const { return  fItemList->fItems[i]; }
0157 
0158    void  StreamPublicMethods(nlohmann::json &cj) const;
0159    Int_t WriteCoreJson(nlohmann::json &cj, Int_t rnr_offset) override;
0160 
0161    void SetMainColor(Color_t) override;
0162 
0163 };
0164 
0165 } // namespace Experimental
0166 } // namespace ROOT
0167 
0168 #endif