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#include "TClass.h"
13#include <ROOT/REveManager.hxx>
14#include "TROOT.h"
15#include "TInterpreter.h"
16
17#include "json.hpp"
18
19using namespace ROOT::Experimental;
20
21REveTableViewInfo::REveTableViewInfo(const std::string &name, const std::string &title) : REveElement(name, title), fConfigChanged(false)
22{
23}
24
26{
27 fDisplayedCollection = collectionId;
28
29 fConfigChanged = true;
30 for (auto &it : fDelegates)
31 it();
32
33 fConfigChanged = false;
35}
36
37void REveTableViewInfo::AddNewColumnToCurrentCollection(const std::string& expr, const std::string& title, int prec)
38{
39 if (!fDisplayedCollection) return;
40
42 if (!col) {
43 printf("REveTableViewInfo::AddNewColumnToCurrentCollection error: collection not found\n");
44 return;
45 }
46
47 const char *rtyp = "void";
48 auto icls = col->GetItemClass();
49 std::function<void(void *)> fooptr;
50 std::stringstream s;
51 s << "*((std::function<" << rtyp << "(" << icls->GetName() << "*)>*)" << std::hex << std::showbase << (size_t)(&fooptr)
52 << ") = [](" << icls->GetName() << "* p){" << icls->GetName() << " &i=*p; return (" << expr
53 << "); }";
54
55 int err;
56 gROOT->ProcessLine(s.str().c_str(), &err);
57 if (err != TInterpreter::kNoError)
58 {
59 std::cout << "REveTableViewInfo::AddNewColumnToCurrentCollection failed." << std::endl;
60 return;
61 }
62
63 fConfigChanged = true;
64 table(col->GetItemClass()->GetName()).column(title, prec, expr);
65
66 for (auto &it : fDelegates)
67 it();
68
69 fConfigChanged = false;
70
72}
73
74////////////////////////////////////////////////////////////////////////////////
75/// Fill core part of JSON representation.
76
78{
79 auto ret = REveElement::WriteCoreJson(j, rnr_offset);
80 j["fDisplayedCollection"] = fDisplayedCollection;
81 return ret;
82}
83
84
int Int_t
Definition: RtypesCore.h:41
char name[80]
Definition: TGX11.cxx:109
#define gROOT
Definition: TROOT.h:415
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)
void AddNewColumnToCurrentCollection(const std::string &expr, const std::string &title, int prec=2)
std::vector< Delegate_t > fDelegates
REveTableHandle table(std::string className)
Int_t WriteCoreJson(nlohmann::json &j, Int_t rnr_offset) override
Fill core part of JSON representation.
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:47
R__EXTERN REveManager * gEve
unsigned int ElementId_t
Definition: REveTypes.hxx:25
void function(const Char_t *name_, T fun, const Char_t *docstring=0)
Definition: RExports.h:151
static constexpr double s