Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
REveDataClasses.hxx
Go to the documentation of this file.
1 // @(#)root/eve7:$Id$
2 // Authors: Matevz Tadel & Alja Mrak-Tadel: 2006, 2007, 2018
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2019, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 
13 #ifndef ROOT7_REveDataClasses
14 #define ROOT7_REveDataClasses
15 
16 #include <ROOT/REveElement.hxx>
17 
18 #include <functional>
19 #include <vector>
20 #include <iostream>
21 
22 class TClass;
23 
24 namespace ROOT {
25 namespace Experimental {
26 
27 class REveDataItem;
28 
29 //==============================================================================
30 
31 class REveDataCollection : public REveElement
32 {
33 public:
34  typedef std::vector<int> Ids_t;
35 
36 private:
37  std::function<void (REveDataCollection*)> _handler_func;
38  std::function<void (REveDataCollection*, const Ids_t&)> _handler_func_ids;
39 
40 public:
41  static Color_t fgDefaultColor;
42 
43  TClass *fItemClass{nullptr}; // so far only really need class name
44 
45  struct ItemInfo_t
46  {
47  void *fDataPtr{nullptr};
48  REveDataItem *fItemPtr{nullptr};
49 
50  ItemInfo_t() = default;
51  ItemInfo_t(void *dp, REveDataItem *di) : fDataPtr(dp), fItemPtr(di) {}
52  };
53 
54  std::vector<ItemInfo_t> fItems;
55 
56  TString fFilterExpr;
57  std::function<bool(void *)> fFilterFoo = [](void *) { return true; };
58 
59  REveDataCollection(const std::string& n = "REveDataCollection", const std::string& t = "");
60  virtual ~REveDataCollection() {}
61 
62  TClass *GetItemClass() const { return fItemClass; }
63  void SetItemClass(TClass *cls) { fItemClass = cls; }
64 
65  void ReserveItems(Int_t items_size) { fItems.reserve(items_size); }
66  void AddItem(void *data_ptr, const std::string& n, const std::string& t);
67  void ClearItems() { fItems.clear(); }
68 
69  void SetFilterExpr(const TString &filter);
70  void ApplyFilter();
71 
72  Int_t GetNItems() const { return (Int_t)fItems.size(); }
73  void *GetDataPtr(Int_t i) const { return fItems[i].fDataPtr; }
74  REveDataItem *GetDataItem(Int_t i) const { return fItems[i].fItemPtr; }
75 
76  Int_t WriteCoreJson(nlohmann::json &cj, Int_t rnr_offset) override;
77 
78  virtual void SetCollectionColorRGB(UChar_t r, UChar_t g, UChar_t b);
79  virtual void SetCollectionVisible(bool);
80  virtual void ItemChanged(REveDataItem *item);
81 
82  void SetHandlerFunc (std::function<void (REveDataCollection*)> handler_func)
83  {
84  _handler_func = handler_func;
85  }
86  void SetHandlerFuncIds (std::function<void (REveDataCollection*, const Ids_t&)> handler_func)
87  {
88  _handler_func_ids= handler_func;
89  }
90 };
91 
92 //==============================================================================
93 
94 class REveDataItem : public REveElement,
95  public REveAuntAsList
96 {
97 protected:
98  Bool_t fFiltered{false};
99 
100 public:
101  REveDataItem(const std::string& n = "REveDataItem", const std::string& t = "");
102  virtual ~REveDataItem() {}
103 
104  Bool_t GetFiltered() const { return fFiltered; }
105  void SetFiltered(Bool_t f);
106 
107  virtual void SetItemColorRGB(UChar_t r, UChar_t g, UChar_t b);
108  virtual void SetItemRnrSelf(bool);
109 
110  virtual void FillImpliedSelectedSet(Set_t& impSelSet) override;
111 
112  Int_t WriteCoreJson(nlohmann::json &cj, Int_t rnr_offset) override;
113 };
114 
115 //==============================================================================
116 
117 class REveDataTable : public REveElement
118 {
119 protected:
120  const REveDataCollection *fCollection{nullptr};
121 
122 public:
123  REveDataTable(const std::string& n = "REveDataTable", const std::string& t = "");
124  virtual ~REveDataTable() {}
125 
126  void SetCollection(const REveDataCollection *col) { fCollection = col; }
127  const REveDataCollection *GetCollection() const { return fCollection; }
128 
129  void PrintTable();
130  virtual Int_t WriteCoreJson(nlohmann::json &cj, Int_t rnr_offset);
131 
132  void AddNewColumn(const std::string& expr, const std::string& title, int prec = 2);
133 };
134 
135 //==============================================================================
136 
137 class REveDataColumn : public REveElement
138 {
139 public:
140  enum FieldType_e { FT_Double = 0, FT_Bool, FT_String };
141 
142 protected:
143 public:
144  TString fExpression;
145  FieldType_e fType; // can we auto detect this?
146  Int_t fPrecision{2};
147 
148  std::string fTrue{"*"};
149  std::string fFalse{" "};
150 
151  std::function<double(void *)> fDoubleFoo;
152  std::function<bool(void *)> fBoolFoo;
153  std::function<std::string(void *)> fStringFoo;
154 
155 public:
156  REveDataColumn(const std::string& n = "REveDataColumn", const std::string& t = "");
157  virtual ~REveDataColumn() {}
158 
159  void SetExpressionAndType(const std::string &expr, FieldType_e type);
160  void SetPrecision(Int_t prec);
161 
162  std::string EvalExpr(void *iptr);
163 };
164 
165 
166 } // namespace Experimental
167 } // namespace ROOT
168 
169 #endif