Logo ROOT  
Reference Guide
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
13#include "TClass.h"
14#include "TBaseClass.h"
15#include "TROOT.h"
16#include "TInterpreter.h"
17#include "TMethod.h"
18#include "TMethodArg.h"
19
22#include <ROOT/REveManager.hxx>
23
24#include <sstream>
25#include "json.hpp"
26
27using namespace ROOT::Experimental;
28
29REveTableViewInfo::REveTableViewInfo(const std::string &name, const std::string &title) : REveElement(name, title), fConfigChanged(false)
30{
31}
32
34{
35 fDisplayedCollection = collectionId;
36
37 fConfigChanged = true;
38 for (auto &it : fDelegates)
39 it();
40
41 fConfigChanged = false;
43}
44
45void REveTableViewInfo::AddNewColumnToCurrentCollection(const std::string& expr, const std::string& title, int prec)
46{
47 if (!fDisplayedCollection) return;
48
50 if (!col) {
51 printf("REveTableViewInfo::AddNewColumnToCurrentCollection error: collection not found\n");
52 return;
53 }
54
55 const char *rtyp = "void";
56 auto icls = col->GetItemClass();
57 std::function<void(void *)> fooptr;
58 std::stringstream s;
59 s << "*((std::function<" << rtyp << "(" << icls->GetName() << "*)>*)" << std::hex << std::showbase << (size_t)(&fooptr)
60 << ") = [](" << icls->GetName() << "* p){" << icls->GetName() << " &i=*p; return (" << expr
61 << "); }";
62
63 int err;
64 gROOT->ProcessLine(s.str().c_str(), &err);
65 if (err != TInterpreter::kNoError)
66 {
67 std::cout << "REveTableViewInfo::AddNewColumnToCurrentCollection failed." << std::endl;
68 return;
69 }
70
71 fConfigChanged = true;
72 table(col->GetItemClass()->GetName()).column(title, prec, expr);
73
74 for (auto &it : fDelegates)
75 it();
76
77 fConfigChanged = false;
78
80}
81
82
83////////////////////////////////////////////////////////////////////////////////
84/// Find column definitions for given class name.
85// Look for definition also in base classes
87{
88 struct SimpleMethodFill
89 {
91 {
92 TMethod *meth;
93 TIter next(c->GetListOfAllPublicMethods());
94 while ((meth = (TMethod*) next())) {
95 // take only methods without arguments
96 if (!meth->GetListOfMethodArgs()->First())
97 {
98 std::string mn = meth->GetName();
99 std::string exp = "i." + mn + "()";
100
101 TDataType* dt = gROOT->GetType(meth->GetReturnTypeName());
102 if (dt) {
103 int t = dt->GetType();
104 if (
108 t == EDataType::kBool_t )
109 entries.push_back(REveTableEntry(mn, 0, exp));
110 else if (
111 t == EDataType::kFloat_t ||
113 entries.push_back(REveTableEntry(mn, 3, exp));
114 }
115 }
116 }
117
118 // look in the base classes
119 TBaseClass *base;
120 TIter blnext(c->GetListOfBases());
121 while ((base = (TBaseClass*) blnext()))
122 {
123 fill(entries, base->GetClassPointer());
124 }
125
126 }
127 };
128
129 auto search = fSpecs.find(cname);
130 if (search != fSpecs.end())
131 {
132 return search->second;
133 }
134 else {
135 TClass* c = TClass::GetClass(cname.c_str());
136 TBaseClass *base;
137 TIter blnext(c->GetListOfBases());
138 while ((base = (TBaseClass*) blnext()))
139 {
140 auto bs = fSpecs.find(base->GetName());
141 if (bs != fSpecs.end())
142 {
143 return bs->second;
144 }
145 }
146 }
147
148 // create new entry if not existing
149 SimpleMethodFill methodFinder;
150 methodFinder.fill(fSpecs[cname], TClass::GetClass(cname.c_str()));
151 return fSpecs[cname];
152}
153
154////////////////////////////////////////////////////////////////////////////////
155/// Fill core part of JSON representation.
156
158{
159 auto ret = REveElement::WriteCoreJson(j, rnr_offset);
160 j["fDisplayedCollection"] = fDisplayedCollection;
161 return ret;
162}
163
164
#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:109
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*.
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)
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.
Definition: TBaseClass.cxx:63
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:2948
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*".
Definition: TFunction.cxx:140
virtual TObject * First() const
Return the first object in the list. Returns 0 when list is empty.
Definition: TList.cxx:658
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:306
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:47
R__EXTERN REveManager * gEve
void function(const Char_t *name_, T fun, const Char_t *docstring=0)
Definition: RExports.h:151
static constexpr double s
fill
Definition: fit1_py.py:6
basic_json<> json
default JSON class
Definition: REveElement.hxx:88