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
19#include <ROOT/REveManager.hxx>
21#include <ROOT/REveUtil.hxx>
22
23#include <sstream>
24
25#include <nlohmann/json.hpp>
26
27using namespace ROOT::Experimental;
28
29namespace {
30 struct TableDictHelper {
31 void fillPublicMethods(REveTableHandle::Entries_t &entries, TClass *c)
32 {
33 static size_t maxEnt = 3;
34 TMethod *meth;
35 TIter next(c->GetListOfAllPublicMethods());
36 while ((meth = (TMethod *)next()) && entries.size() < maxEnt) {
37 // take only methods without arguments
38 if (!meth->GetListOfMethodArgs()->First()) {
39 std::string mn = meth->GetName();
40 std::string exp = "i." + mn + "()";
41
43 if (dt) {
44 int t = dt->GetType();
48 entries.push_back(REveTableEntry(mn, 0, exp));
50 entries.push_back(REveTableEntry(mn, 3, exp));
51 }
52 }
53 }
54
55 // look in the base classes
56 TBaseClass *base;
57 TIter blnext(c->GetListOfBases());
58 while ((base = (TBaseClass *)blnext())) {
59 fillPublicMethods(entries, base->GetClassPointer());
60 }
61 }
62
63 TClass *searchMatchInBaseClasses(TClass *c, REveTableHandle::Specs_t &specs)
64 {
65 TBaseClass *base;
66 TIter blnext(c->GetListOfBases());
67 while ((base = (TBaseClass *)blnext())) {
68 auto bs = specs.find(base->GetName());
69 if (bs != specs.end()) {
70 return base->GetClassPointer();
71 }
72 return searchMatchInBaseClasses(base->GetClassPointer(), specs);
73 }
74 return nullptr;
75 }
76 };
77
78}
79
80REveTableViewInfo::REveTableViewInfo(const std::string &name, const std::string &title)
81 : REveElement(name, title), fConfigChanged(false)
82{
83}
84
86{
87 fDisplayedCollection = collectionId;
88
89 fConfigChanged = true;
90 for (auto &it : fDelegates)
91 it();
92
93 fConfigChanged = false;
95}
96
97void REveTableViewInfo::AddNewColumnToCurrentCollection(const char* expr, const char* title, int prec)
98{
99 static const REveException eh("REveTableViewInfo::AddNewColumnToCurrentCollection");
100
102 return;
103
105 if (!col) {
106 printf("REveTableViewInfo::AddNewColumnToCurrentCollection error: collection not found\n");
107 return;
108 }
109
111 throw eh + "column-expression verification failed.";
112 }
113
114 const char *rtyp = "void";
115 auto icls = col->GetItemClass();
116 std::function<void(void *)> fooptr;
117 std::stringstream s;
118 s << "*((std::function<" << rtyp << "(" << icls->GetName() << "*)>*)" << std::hex << std::showbase
119 << (size_t)(&fooptr) << ") = [](" << icls->GetName() << "* p){" << icls->GetName()
120 << " &i=*p; return (" << expr << "); }";
121
122 // make ProcessLine() call to check if expr is valid
123 // there may be more efficient check
124 int err;
125 gROOT->ProcessLine(s.str().c_str(), &err);
126 if (err != TInterpreter::kNoError) {
127 throw eh + "column expression compilation check failed.";
128 }
129
130 fConfigChanged = true;
131
132 auto sit = fSpecs.find(icls->GetName());
133 if (sit != fSpecs.end()) {
134 table(icls->GetName()).column(title, prec, expr);
135 } else {
136 TableDictHelper helper;
137 TClass *b = helper.searchMatchInBaseClasses(icls, fSpecs);
138 std::string n = b->GetName();
139 for (REveTableHandle::Entries_t::iterator e = fSpecs[n].begin(); e != fSpecs[n].end(); ++e) {
140 table(col->GetItemClass()->GetName()).column(e->fName, e->fPrecision, e->fExpression);
141 }
142 table(col->GetItemClass()->GetName()).column(title, prec, expr);
143 }
144 for (auto &it : fDelegates)
145 it();
146
147 fConfigChanged = false;
148
150}
151
152////////////////////////////////////////////////////////////////////////////////
153/// Find column definitions for given class name.
154// Look for definition also in base classes
156{
157 TableDictHelper helper;
158 auto search = fSpecs.find(cname);
159 if (search != fSpecs.end()) {
160 return search->second;
161 } else {
162 TClass *b = helper.searchMatchInBaseClasses(TClass::GetClass(cname.c_str()), fSpecs);
163 if (b) {
164 return fSpecs[b->GetName()];
165 }
166 }
167
168 // create new entry if not existing
169 helper.fillPublicMethods(fSpecs[cname], TClass::GetClass(cname.c_str()));
170 return fSpecs[cname];
171}
172
173////////////////////////////////////////////////////////////////////////////////
174/// Fill core part of JSON representation.
175
176Int_t REveTableViewInfo::WriteCoreJson(nlohmann::json &j, Int_t rnr_offset)
177{
178 auto ret = REveElement::WriteCoreJson(j, rnr_offset);
179 j["fDisplayedCollection"] = fDisplayedCollection;
180 return ret;
181}
#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
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char cname
char name[80]
Definition TGX11.cxx:110
#define gROOT
Definition TROOT.h:406
virtual Int_t WriteCoreJson(nlohmann::json &cj, Int_t rnr_offset)
Write core json.
REveException Exception-type thrown by Eve classes.
Definition REveTypes.hxx:43
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.
static bool VerifyObjectFilterOrTableExpression(std::string_view expr)
Input string verification and sanitization.
Definition REveUtil.cxx:117
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:81
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:3037
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*".
TObject * First() const override
Return the first object in the list. Returns 0 when list is empty.
Definition TList.cxx:657
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
const char * GetName() const override
Returns name of object.
Definition TNamed.h:47
RVec< PromoteType< T > > exp(const RVec< T > &v)
Definition RVec.hxx:1837
const Int_t n
Definition legend1.C:16
R__EXTERN REveManager * gEve