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
24#include <nlohmann/json.hpp>
25
26using namespace ROOT::Experimental;
27
28namespace {
29 struct TableDictHelper {
30 void fillPublicMethods(REveTableHandle::Entries_t &entries, TClass *c)
31 {
32 static size_t maxEnt = 3;
33 TMethod *meth;
34 TIter next(c->GetListOfAllPublicMethods());
35 while ((meth = (TMethod *)next()) && entries.size() < maxEnt) {
36 // take only methods without arguments
37 if (!meth->GetListOfMethodArgs()->First()) {
38 std::string mn = meth->GetName();
39 std::string exp = "i." + mn + "()";
40
42 if (dt) {
43 int t = dt->GetType();
47 entries.push_back(REveTableEntry(mn, 0, exp));
49 entries.push_back(REveTableEntry(mn, 3, exp));
50 }
51 }
52 }
53
54 // look in the base classes
55 TBaseClass *base;
56 TIter blnext(c->GetListOfBases());
57 while ((base = (TBaseClass *)blnext())) {
58 fillPublicMethods(entries, base->GetClassPointer());
59 }
60 }
61
62 TClass *searchMatchInBaseClasses(TClass *c, REveTableHandle::Specs_t &specs)
63 {
64 TBaseClass *base;
65 TIter blnext(c->GetListOfBases());
66 while ((base = (TBaseClass *)blnext())) {
67 auto bs = specs.find(base->GetName());
68 if (bs != specs.end()) {
69 return base->GetClassPointer();
70 }
71 return searchMatchInBaseClasses(base->GetClassPointer(), specs);
72 }
73 return nullptr;
74 }
75 };
76
77}
78
79REveTableViewInfo::REveTableViewInfo(const std::string &name, const std::string &title)
80 : REveElement(name, title), fConfigChanged(false)
81{
82}
83
85{
86 fDisplayedCollection = collectionId;
87
88 fConfigChanged = true;
89 for (auto &it : fDelegates)
90 it();
91
92 fConfigChanged = false;
94}
95
96void REveTableViewInfo::AddNewColumnToCurrentCollection(const char* expr, const char* title, int prec)
97{
99 return;
100
102 if (!col) {
103 printf("REveTableViewInfo::AddNewColumnToCurrentCollection error: collection not found\n");
104 return;
105 }
106
107 const char *rtyp = "void";
108 auto icls = col->GetItemClass();
109 std::function<void(void *)> fooptr;
110 std::stringstream s;
111 s << "*((std::function<" << rtyp << "(" << icls->GetName() << "*)>*)" << std::hex << std::showbase
112 << (size_t)(&fooptr) << ") = [](" << icls->GetName() << "* p){" << icls->GetName() << " &i=*p; return (" << expr
113 << "); }";
114
115 // make ProcessLine() call to check if expr is valid
116 // there may be more efficient check
117 int err;
118 gROOT->ProcessLine(s.str().c_str(), &err);
119 if (err != TInterpreter::kNoError) {
120 std::cout << "REveTableViewInfo::AddNewColumnToCurrentCollection failed." << std::endl;
121 return;
122 }
123
124 fConfigChanged = true;
125
126 auto sit = fSpecs.find(icls->GetName());
127 if (sit != fSpecs.end()) {
128 table(icls->GetName()).column(title, prec, expr);
129 } else {
130 TableDictHelper helper;
131 TClass *b = helper.searchMatchInBaseClasses(icls, fSpecs);
132 std::string n = b->GetName();
133 for (REveTableHandle::Entries_t::iterator e = fSpecs[n].begin(); e != fSpecs[n].end(); ++e) {
134 table(col->GetItemClass()->GetName()).column(e->fName, e->fPrecision, e->fExpression);
135 }
136 table(col->GetItemClass()->GetName()).column(title, prec, expr);
137 }
138 for (auto &it : fDelegates)
139 it();
140
141 fConfigChanged = false;
142
144}
145
146////////////////////////////////////////////////////////////////////////////////
147/// Find column definitions for given class name.
148// Look for definition also in base classes
150{
151 TableDictHelper helper;
152 auto search = fSpecs.find(cname);
153 if (search != fSpecs.end()) {
154 return search->second;
155 } else {
156 TClass *b = helper.searchMatchInBaseClasses(TClass::GetClass(cname.c_str()), fSpecs);
157 if (b) {
158 return fSpecs[b->GetName()];
159 }
160 }
161
162 // create new entry if not existing
163 helper.fillPublicMethods(fSpecs[cname], TClass::GetClass(cname.c_str()));
164 return fSpecs[cname];
165}
166
167////////////////////////////////////////////////////////////////////////////////
168/// Fill core part of JSON representation.
169
171{
172 auto ret = REveElement::WriteCoreJson(j, rnr_offset);
173 j["fDisplayedCollection"] = fDisplayedCollection;
174 return ret;
175}
typedef void(GLAPIENTRYP _GLUfuncptr)(void)
#define b(i)
Definition RSha256.hxx:100
#define c(i)
Definition RSha256.hxx:101
#define e(i)
Definition RSha256.hxx:103
@ 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
#define gROOT
Definition TROOT.h:404
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
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)
void AddNewColumnToCurrentCollection(const char *expr, const char *title, int prec=2)
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:2966
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:307
virtual const char * GetName() const
Returns name of object.
Definition TNamed.h:47
const Int_t n
Definition legend1.C:16
R__EXTERN REveManager * gEve
basic_json< std::map, std::vector, std::string, bool, std::int64_t, std::uint64_t, double, std::allocator, adl_serializer, std::vector< std::uint8_t > > json