Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
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"
12 #include <ROOT/REveTableInfo.hxx>
13 #include <ROOT/REveManager.hxx>
14 #include "TROOT.h"
15 #include "TInterpreter.h"
16 
17 #include "json.hpp"
18 
19 using namespace ROOT::Experimental;
20 
21 REveTableViewInfo::REveTableViewInfo(const std::string &name, const std::string &title) : REveElement(name, title), fConfigChanged(false)
22 {
23 }
24 
25 void REveTableViewInfo::SetDisplayedCollection(ElementId_t collectionId)
26 {
27  fDisplayedCollection = collectionId;
28 
29  fConfigChanged = true;
30  for (auto &it : fDelegates)
31  it();
32 
33  fConfigChanged = false;
34  StampObjProps();
35 }
36 
37 void REveTableViewInfo::AddNewColumnToCurrentCollection(const std::string& expr, const std::string& title, int prec)
38 {
39  if (!fDisplayedCollection) return;
40 
41  REveDataCollection* col = dynamic_cast<REveDataCollection*>(gEve->FindElementById(fDisplayedCollection));
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 
71  StampObjProps();
72 }
73 
74 ////////////////////////////////////////////////////////////////////////////////
75 /// Fill core part of JSON representation.
76 
77 Int_t REveTableViewInfo::WriteCoreJson(nlohmann::json &j, Int_t rnr_offset)
78 {
79  auto ret = REveElement::WriteCoreJson(j, rnr_offset);
80  j["fDisplayedCollection"] = fDisplayedCollection;
81  return ret;
82 }
83 
84