Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
REveTableInfo.cxx
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#include "TClass.h"
13#include "TBaseClass.h"
14#include "TROOT.h"
15#include "TInterpreter.h"
16#include "TMethod.h"
17#include "TMethodArg.h"
18
20#include <ROOT/REveManager.hxx>
21
22#include <sstream>
23
24using namespace ROOT::Experimental;
25
26REveTableViewInfo::REveTableViewInfo(const std::string &name, const std::string &title)
27 : REveElement(name, title), fConfigChanged(false)
28{
29}
30
32{
33 fDisplayedCollection = collectionId;
34
35 fConfigChanged = true;
36 for (auto &it : fDelegates)
37 it();
38
39 fConfigChanged = false;
41}
42
43void REveTableViewInfo::AddNewColumnToCurrentCollection(const std::string &expr, const std::string &title, int prec)
44{
46 return;
47
49 if (!col) {
50 printf("REveTableViewInfo::AddNewColumnToCurrentCollection error: collection not found\n");
51 return;
52 }
53
54 const char *rtyp = "void";
55 auto icls = col->GetItemClass();
56 std::function<void(void *)> fooptr;
57 std::stringstream s;
58 s << "*((std::function<" << rtyp << "(" << icls->GetName() << "*)>*)" << std::hex << std::showbase
59 << (size_t)(&fooptr) << ") = [](" << icls->GetName() << "* p){" << icls->GetName() << " &i=*p; return (" << expr
60 << "); }";
61
62 int err;
63 gROOT->ProcessLine(s.str().c_str(), &err);
64 if (err != TInterpreter::kNoError) {
65 std::cout << "REveTableViewInfo::AddNewColumnToCurrentCollection failed." << std::endl;
66 return;
67 }
68
69 fConfigChanged = true;
70 table(col->GetItemClass()->GetName()).column(title, prec, expr);
71
72 for (auto &it : fDelegates)
73 it();
74
75 fConfigChanged = false;
76
78}
79
80////////////////////////////////////////////////////////////////////////////////
81/// Find column definitions for given class name.
82// Look for definition also in base classes
84{
85 struct TableDictHelper {
86 void fillPublicMethods(REveTableHandle::Entries_t &entries, TClass *c)
87 {
88 static size_t maxEnt = 3;
89 TMethod *meth;
90 TIter next(c->GetListOfAllPublicMethods());
91 while ((meth = (TMethod *)next()) && entries.size() < maxEnt) {
92 // take only methods without arguments
93 if (!meth->GetListOfMethodArgs()->First()) {
94 std::string mn = meth->GetName();
95 std::string exp = "i." + mn + "()";
96
98 if (dt) {
99 int t = dt->GetType();
103 entries.push_back(REveTableEntry(mn, 0, exp));
105 entries.push_back(REveTableEntry(mn, 3, exp));
106 }
107 }
108 }
109
110 // look in the base classes
111 TBaseClass *base;
112 TIter blnext(c->GetListOfBases());
113 while ((base = (TBaseClass *)blnext())) {
114 fillPublicMethods(entries, base->GetClassPointer());
115 }
116 }
117
118 TClass *searchMatchInBaseClasses(TClass *c, REveTableHandle::Specs_t &specs)
119 {
120 TBaseClass *base;
121 TIter blnext(c->GetListOfBases());
122 while ((base = (TBaseClass *)blnext())) {
123 auto bs = specs.find(base->GetName());
124 if (bs != specs.end()) {
125 return base->GetClassPointer();
126 }
127 return searchMatchInBaseClasses(base->GetClassPointer(), specs);
128 }
129 return nullptr;
130 }
131 };
132
133 TableDictHelper helper;
134 auto search = fSpecs.find(cname);
135 if (search != fSpecs.end()) {
136 return search->second;
137 } else {
138 TClass *b = helper.searchMatchInBaseClasses(TClass::GetClass(cname.c_str()), fSpecs);
139 if (b) {
140 return fSpecs[b->GetName()];
141 }
142 }
143
144 // create new entry if not existing
145 helper.fillPublicMethods(fSpecs[cname], TClass::GetClass(cname.c_str()));
146 return fSpecs[cname];
147}
148
149////////////////////////////////////////////////////////////////////////////////
150/// Fill core part of JSON representation.
151
152Int_t REveTableViewInfo::WriteCoreJson(nlohmann::json &j, Int_t rnr_offset)
153{
154 auto ret = REveElement::WriteCoreJson(j, rnr_offset);
155 j["fDisplayedCollection"] = fDisplayedCollection;
156 return ret;
157}
#define b(i)
Definition RSha256.hxx:100
#define c(i)
Definition RSha256.hxx:101
@ kFloat_t
Definition TDataType.h:31
@ kULong64_t
Definition TDataType.h:32
@ kInt_t
Definition TDataType.h:30
@ kLong_t
Definition TDataType.h:30
@ kDouble32_t
Definition TDataType.h:31
@ kBool_t
Definition TDataType.h:32
@ kULong_t
Definition TDataType.h:30
@ kLong64_t
Definition TDataType.h:32
@ kDouble_t
Definition TDataType.h:31
@ kUInt_t
Definition TDataType.h:30
char name[80]
Definition TGX11.cxx:110
double exp(double)
#define gROOT
Definition TROOT.h:406
typedef void((*Func_t)())
virtual Int_t WriteCoreJson(nlohmann::json &cj, Int_t rnr_offset)
Write core json.
REveElement * FindElementById(ElementId_t id) const
Lookup ElementId in element map and return corresponding REveElement*.
std::map< std::string, Entries_t > Specs_t
REveTableHandle & column(const std::string &name, int precision, const std::string &expression)
std::vector< REveTableEntry > Entries_t
void AddNewColumnToCurrentCollection(const std::string &expr, const std::string &title, int prec=2)
REveTableViewInfo(const std::string &name="TableViewManager", const std::string &title="")
std::vector< Delegate_t > fDelegates
REveTableHandle::Entries_t & RefTableEntries(std::string cname)
Find column definitions for given class name.
REveTableHandle table(std::string className)
Int_t WriteCoreJson(nlohmann::json &j, Int_t rnr_offset) override
Fill core part of JSON representation.
Each class (see TClass) has a linked list of its base class(es).
Definition TBaseClass.h:33
TClass * GetClassPointer(Bool_t load=kTRUE)
Get pointer to the base class TClass.
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition TClass.h:80
static TClass * GetClass(const char *name, Bool_t load=kTRUE, Bool_t silent=kFALSE)
Static method returning pointer to TClass of the specified class name.
Definition TClass.cxx:2957
Basic data type descriptor (datatype information is obtained from CINT).
Definition TDataType.h:44
Int_t GetType() const
Definition TDataType.h:68
const char * GetReturnTypeName() const
Get full type description of function return type, e,g.: "class TDirectory*".
virtual TObject * First() const
Return the first object in the list. Returns 0 when list is empty.
Definition TList.cxx:659
Each ROOT class (see TClass) has a linked list of methods.
Definition TMethod.h:38
virtual TList * GetListOfMethodArgs()
Returns methodarg list and additionally updates fDataMember in TMethod by calling FindDataMember();.
Definition TMethod.cxx:308
virtual const char * GetName() const
Returns name of object.
Definition TNamed.h:47
R__EXTERN REveManager * gEve