Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
REveTableInfo.hxx
Go to the documentation of this file.
1 // @(#)root/eve7:$Id$
2 // Authors: Matevz Tadel & Alja Mrak-Tadel: 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 #ifndef ROOT7_REveTableInfo
13 #define ROOT7_REveTableInfo
14 
15 #include <ROOT/REveElement.hxx>
16 #include <ROOT/REveDataClasses.hxx>
17 
18 namespace ROOT {
19 namespace Experimental {
20 
21 ///////////////////////////////////////////////////////////////////////////////
22 /// REveTableEntry
23 ///////////////////////////////////////////////////////////////////////////////
24 
25 class REveTableEntry {
26 public:
27  std::string fName;
28  int fPrecision;
29  std::string fExpression;
30  REveDataColumn::FieldType_e fType;
31 
32  REveTableEntry() : fName("unknown"), fPrecision(2), fType(REveDataColumn::FT_Double) {}
33 
34  REveTableEntry(const std::string &name, int precision, const std::string &expression)
35  : fName(name), fPrecision(precision), fExpression(expression), fType(REveDataColumn::FT_Double)
36  {
37  }
38 
39  void Print() const
40  {
41  printf("TableEntry\n");
42  printf("name: %s expression: %s\n", fName.c_str(), fExpression.c_str());
43  }
44 };
45 
46 ///////////////////////////////////////////////////////////////////////////////
47 /// REveTableHandle
48 ///////////////////////////////////////////////////////////////////////////////
49 
50 class REveTableHandle
51 {
52  friend class REveTableViewInfo;
53 
54 public:
55  typedef std::vector<REveTableEntry> Entries_t;
56  typedef std::map<std::string, Entries_t> Specs_t;
57 
58  // REveTableHandle() {}
59 
60  REveTableHandle&
61  column(const std::string &name, int precision, const std::string &expression)
62  {
63  fSpecs[fClassName].emplace_back(name, precision, expression);
64  return *this;
65  }
66 
67  REveTableHandle &column(const std::string &label, int precision)
68  {
69  return column(label, precision, label);
70  }
71 
72  REveTableHandle(std::string className, Specs_t &specs)
73  :fClassName(className), fSpecs(specs)
74  {
75  }
76 
77 protected:
78  std::string fClassName;
79  Specs_t& fSpecs;
80 };
81 
82 ///////////////////////////////////////////////////////////////////////////////
83 /// REveTableViewInfo
84 ///////////////////////////////////////////////////////////////////////////////
85 
86 class REveTableViewInfo : public REveElement
87 {
88 public:
89  REveTableViewInfo(const std::string &name = "TableViewManager", const std::string &title = "");
90 
91  typedef std::function<void ()> Delegate_t;
92 
93  void SetDisplayedCollection(ElementId_t);
94  ElementId_t GetDisplayedCollection() const { return fDisplayedCollection; }
95 
96  void AddNewColumnToCurrentCollection(const std::string& expr, const std::string& title, int prec = 2);
97 
98  void AddDelegate(Delegate_t d) { fDelegates.push_back(d); }
99 
100  Int_t WriteCoreJson(nlohmann::json &j, Int_t rnr_offset) override;
101 
102  // read
103  REveTableHandle::Entries_t &RefTableEntries(std::string cname) { return fSpecs[cname]; }
104 
105  // filling
106  REveTableHandle table(std::string className)
107  {
108  REveTableHandle handle(className, fSpecs);
109  return handle;
110  }
111 
112  bool GetConfigChanged() const { return fConfigChanged; }
113 
114 
115 private:
116  int fDisplayedCollection{0};
117  std::vector<Delegate_t> fDelegates;
118  REveTableHandle::Specs_t fSpecs;
119  bool fConfigChanged{false};
120 };
121 
122 
123 }
124 }
125 
126 #endif