Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
REveDataCollection.cxx
Go to the documentation of this file.
1// @(#)root/eve7:$Id$
2// Authors: Matevz Tadel & Alja Mrak-Tadel: 2006, 2007, 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
13#include <ROOT/REveUtil.hxx>
15#include <ROOT/REveManager.hxx>
16
17#include "TROOT.h"
18#include "TMethod.h"
19#include "TMethodArg.h"
20#include "TColor.h"
21#include "TClass.h"
22#include "TList.h"
23#include "TBaseClass.h"
24
25#include <sstream>
26
27using namespace ROOT::Experimental;
28
29
31
32//==============================================================================
33//==============================================================================
34
35REveDataItemList::REveDataItemList(const std::string& n, const std::string& t):
36 REveElement(n,t)
37{
38 fAlwaysSecSelect = true;
39
42 });
43
45 REveDataItemList::DummyFillImpliedSelected(collection, impSelSet);
46 });
47
49}
50//______________________________________________________________________________
51
53{
54 fItems[idx]->SetRnrSelf(visible);
55 ItemChanged(idx);
57}
58
59//______________________________________________________________________________
60
62{
64 fItems[idx]->SetMainColor(c);
65 ItemChanged(idx);
67}
68//______________________________________________________________________________
69
71{
72 int idx = 0;
73 std::vector<int> ids;
74 for (auto & chld : fItems)
75 {
76 if (chld == iItem) {
77 ids.push_back(idx);
78 fHandlerItemsChange( this , ids);
79 return;
80 }
81 idx++;
82 }
83}
84
85//______________________________________________________________________________
86
88{
89 std::vector<int> ids;
90 ids.push_back(idx);
91 fHandlerItemsChange( this , ids);
92}
93
94//______________________________________________________________________________
95
97{
98 /*
99 printf("REveDataCollection::FillImpliedSelectedSet colecction setsize %zu\n", RefSelectedSet().size());
100 for (auto x : RefSelectedSet())
101 printf("%d \n", x);
102 */
103 fHandlerFillImplied( this , impSelSet);
104}
105
106//______________________________________________________________________________
107
108
109Int_t REveDataItemList::WriteCoreJson(nlohmann::json &j, Int_t rnr_offset)
110{
111 Int_t ret = REveElement::WriteCoreJson(j, rnr_offset);
112 j["items"] = nlohmann::json::array();
113 for (auto & chld : fItems)
114 {
115 nlohmann::json i;
116 i["fFiltered"] = chld->GetFiltered();
117 i["fRnrSelf"] = chld->GetRnrSelf();
118 i["fColor"] = chld->GetMainColor();
119 j["items"].push_back(i);
120 }
121
122 return ret;
123}
124
125//______________________________________________________________________________
126
128{
129 Bool_t ret = REveElement::SetRnrState(iRnrSelf);
130 std::vector<int> ids;
131
132 for (size_t i = 0; i < fItems.size(); ++i ) {
133 ids.push_back(i);
134 fItems[i]->SetRnrSelf(fRnrSelf);
135 }
136
137 fHandlerItemsChange( this , ids);
140
141 return ret;
142}
143
144//______________________________________________________________________________
145void REveDataItemList::ProcessSelection(ElementId_t selectionId, bool multi, bool secondary, const std::set<int>& secondary_idcs)
146{
147 RefSelectedSet() = secondary_idcs;
148 REveSelection* selection = (REveSelection*) ROOT::Experimental::gEve->FindElementById(selectionId);
149 selection->NewElementPicked(GetElementId(), multi, secondary, secondary_idcs);
150}
151
152//______________________________________________________________________________
153std::string REveDataItemList::GetHighlightTooltip(const std::set<int>& secondary_idcs) const
154{
155 if (secondary_idcs.empty()) {
156 return GetName();
157 }
158
159 // print info for first selected index
160 int idx = *secondary_idcs.begin();
161 auto col = dynamic_cast<REveDataCollection*>(fMother);
162 void* data = col->GetDataPtr(idx);
163 std::string name = col->GetName();
164 auto li = name.size();
165 if (li && name[li-1] == 's')
166 {
167 name = name.substr(0, li-1);
168 }
169
170 std::string res;
171 for (auto &z : secondary_idcs)
172 {
173 idx = z;
174 data = col->GetDataPtr(idx);
175 res += Form("%s %d", name.c_str(), idx);
176 for (auto &t : fTooltipExpressions) {
177 std::string eval = t.fTooltipFunction.EvalExpr(data);
178 res += Form("\n %s = %s", t.fTooltipTitle.c_str(), eval.c_str());
179 }
180 res += "\n";
181 }
182 return res;
183}
184
185//______________________________________________________________________________
186void REveDataItemList::AddTooltipExpression(const std::string &title, const std::string &expr)
187{
188 TTip tt;
189 tt.fTooltipTitle = title;
190 tt.fTooltipFunction.SetPrecision(2);
191 auto col = dynamic_cast<REveDataCollection*>(fMother);
192 auto icls = col->GetItemClass();
193 tt.fTooltipFunction.SetExpressionAndType(expr, REveDataColumn::FT_Double, icls);
194 fTooltipExpressions.push_back(tt);
195}
196
197//______________________________________________________________________________
199{
200 fHandlerItemsChange = handler_func;
201}
202
203//______________________________________________________________________________
205{
206 fHandlerFillImplied = handler_func;
207}
208
209//______________________________________________________________________________
211{
212 if (gDebug) {
213 printf("REveDataItemList::DummyItemsCahngeDelegate not implemented\n");
214 }
215}
216
217
218//______________________________________________________________________________
220{
221 if (gDebug) {
222 printf("REveDataItemList::DummyFillImpliedSelectedDelegate not implemented\n");
223 }
224}
225
226//==============================================================================
227// REveDataCollection
228//==============================================================================
229
230REveDataCollection::REveDataCollection(const std::string& n, const std::string& t) :
231 REveElement(n, t)
232{
233 std::string lname = n + "Items";
234 fItemList = new REveDataItemList(lname.c_str());
236
238}
239
240void REveDataCollection::AddItem(void *data_ptr, const std::string& /*n*/, const std::string& /*t*/)
241{
242 auto el = new REveDataItem(data_ptr, GetMainColor());
243 fItemList->fItems.emplace_back(el);
244}
245
246//------------------------------------------------------------------------------
247
249{
250 static const REveException eh("REveDataCollection::SetFilterExpr ");
251
252 if (!fItemClass) throw eh + "item class has to be set before the filter expression.";
253
254 fFilterExpr = filter;
255
256 std::stringstream s;
257 s << "*((std::function<bool(" << fItemClass->GetName() << "*)>*)" << std::hex << std::showbase << (size_t)&fFilterFoo
258 << ") = [](" << fItemClass->GetName() << "* p){" << fItemClass->GetName() << " &i=*p; return ("
259 << fFilterExpr.Data() << "); }";
260
261 // printf("%s\n", s.Data());
262 try {
263 gROOT->ProcessLine(s.str().c_str());
264 // AMT I don't know why ApplyFilter call is separated
265 ApplyFilter();
266 }
267 catch (const std::exception &exc)
268 {
269 std::cerr << "EveDataCollection::SetFilterExpr" << exc.what();
270 }
271}
272
274{
275 Ids_t ids;
276 int idx = 0;
277 for (auto &ii : fItemList->fItems)
278 {
279 bool res = fFilterFoo(ii->GetDataPtr());
280
281 // printf("Item:%s -- filter result = %d\n", ii.fItemPtr->GetElementName(), res);
282
283 ii->SetFiltered( ! res );
284
285 ids.push_back(idx++);
286 }
290}
291
292//______________________________________________________________________________
293
294void REveDataCollection::StreamPublicMethods(nlohmann::json &j) const
295{
296 struct PubMethods
297 {
298 void FillJSON(TClass* c, nlohmann::json & arr)
299 {
300 TString ctor = c->GetName(), dtor = "~";
301 {
302 int i = ctor.Last(':');
303 if (i != kNPOS)
304 {
305 ctor.Replace(0, i + 1, "");
306 }
307 dtor += ctor;
308 }
309
310 TMethod *meth;
311 TIter next(c->GetListOfMethods());
312 while ((meth = (TMethod*) next()))
313 {
314 // Filter out ctor, dtor, some ROOT stuff.
315 {
316 TString m(meth->GetName());
317 if (m == ctor || m == dtor ||
318 m == "Class" || m == "Class_Name" || m == "Class_Version" || m == "Dictionary" || m == "IsA" ||
319 m == "DeclFileName" || m == "ImplFileName" || m == "DeclFileLine" || m == "ImplFileLine" ||
320 m == "Streamer" || m == "StreamerNVirtual" || m == "ShowMembers" ||
321 m == "CheckTObjectHashConsistency")
322 {
323 continue;
324 }
325 }
326
327 TString ms;
328 TMethodArg *ma;
329 TIter next_ma(meth->GetListOfMethodArgs());
330 while ((ma = (TMethodArg*) next_ma()))
331 {
332 if ( ! ms.IsNull()) ms += ", ";
333
334 ms += ma->GetTypeName();
335 ms += " ";
336 ms += ma->GetName();
337 }
338 char* entry = Form("i.%s(%s)",meth->GetName(),ms.Data());
339 nlohmann::json jm ;
340 jm["f"] = entry;
341 jm["r"] = meth->GetReturnTypeName();
342 jm["c"] = c->GetName();
343 arr.push_back(jm);
344 }
345 {
346 TBaseClass *base;
347 TIter blnext(c->GetListOfBases());
348 while ((base = (TBaseClass*) blnext()))
349 {
350 FillJSON(base->GetClassPointer(), arr);
351 }
352 }
353 }
354 };
355 j["fPublicFunctions"] = nlohmann::json::array();
356 PubMethods pm;
357 pm.FillJSON(fItemClass, j["fPublicFunctions"]);
358}
359
360//______________________________________________________________________________
361
363{
364 int idx = 0;
365 Ids_t ids;
366 for (auto & chld : fItemList->fItems)
367 {
368 chld->SetMainColor(newv);
369 ids.push_back(idx);
370 idx++;
371 }
372
374 for (auto & chld : fItemList->fItems)
375 {
376 chld->SetMainColor(newv);
377 }
379 fItemList->SetMainColor(newv);
381}
382
383//______________________________________________________________________________
384
386{
387 Bool_t ret = REveElement::SetRnrState(iRnrSelf);
388 Ids_t ids;
389 for (int i = 0; i < GetNItems(); ++i ) {
390 ids.push_back(i);
391 fItemList->fItems[i]->SetRnrSelf(fRnrSelf);
392 }
393
396
397 return ret;
398}
399
400
401//______________________________________________________________________________
402
403Int_t REveDataCollection::WriteCoreJson(nlohmann::json &j, Int_t rnr_offset)
404{
405 Int_t ret = REveElement::WriteCoreJson(j, rnr_offset);
406 j["fFilterExpr"] = fFilterExpr.Data();
407 return ret;
408}
409
ROOT::R::TRInterface & r
Definition Object.C:4
#define b(i)
Definition RSha256.hxx:100
#define c(i)
Definition RSha256.hxx:101
#define g(i)
Definition RSha256.hxx:105
const Ssiz_t kNPOS
Definition RtypesCore.h:115
unsigned char UChar_t
Definition RtypesCore.h:38
short Color_t
Definition RtypesCore.h:83
@ kBlue
Definition Rtypes.h:66
char name[80]
Definition TGX11.cxx:110
Int_t gDebug
Definition TROOT.cxx:590
#define gROOT
Definition TROOT.h:406
char * Form(const char *fmt,...)
void StreamPublicMethods(nlohmann::json &cj) const
void AddItem(void *data_ptr, const std::string &n, const std::string &t)
Bool_t SetRnrState(Bool_t) override
Set render state of this element and of its children to the same value.
void SetMainColor(Color_t) override
Set main color of the element.
Int_t WriteCoreJson(nlohmann::json &cj, Int_t rnr_offset) override
Write core json.
REveDataCollection(const std::string &n="REveDataCollection", const std::string &t="")
REveDataItemList(const std::string &n="Items", const std::string &t="")
void AddTooltipExpression(const std::string &title, const std::string &expr)
virtual void ItemChanged(REveDataItem *item)
Int_t WriteCoreJson(nlohmann::json &cj, Int_t rnr_offset) override
Write core json.
FillImpliedSelectedFunc_t fHandlerFillImplied
void ProcessSelection(ElementId_t id, bool multi, bool secondary, const std::set< int > &in_secondary_idcs)
void FillImpliedSelectedSet(Set_t &impSelSet) override
Populate set impSelSet with derived / dependant elements.
void SetItemColorRGB(Int_t idx, UChar_t r, UChar_t g, UChar_t b)
Bool_t SetRnrState(Bool_t) override
Set render state of this element and of its children to the same value.
std::string GetHighlightTooltip(const std::set< int > &secondary_idcs) const override
static void DummyFillImpliedSelected(REveDataItemList *, Set_t &impSelSet)
void SetFillImpliedSelectedDelegate(FillImpliedSelectedFunc_t)
std::vector< REveDataItem * > fItems
static void DummyItemsChange(REveDataItemList *, const std::vector< int > &)
std::function< void(REveDataItemList *, Set_t &)> FillImpliedSelectedFunc_t
void SetItemVisible(Int_t idx, Bool_t visible)
std::function< void(REveDataItemList *, const std::vector< int > &)> ItemsChangeFunc_t
const std::string & GetName() const
virtual Int_t WriteCoreJson(nlohmann::json &cj, Int_t rnr_offset)
Write core json.
void SetupDefaultColorAndTransparency(Color_t col, Bool_t can_edit_color, Bool_t can_edit_transparency)
Set up element to use built-in main color and set flags allowing editing of main color and transparen...
virtual void AddElement(REveElement *el)
Add el to the list of children.
virtual Bool_t SetRnrState(Bool_t rnr)
Set render state of this element and of its children to the same value.
std::set< REveElement * > Set_t
ElementId_t GetElementId() const
virtual void SetMainColor(Color_t color)
Set main color of the element.
virtual Color_t GetMainColor() const
REveException Exception-type thrown by Eve classes.
Definition REveTypes.hxx:40
REveSelection Container for selected and highlighted elements.
void NewElementPicked(ElementId_t id, bool multi, bool secondary, const std::set< int > &secondary_idcs={})
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 Int_t GetColor(const char *hexcolor)
Static method returning color number for color specified by hex color string of form: "#rrggbb",...
Definition TColor.cxx:1769
const char * GetReturnTypeName() const
Get full type description of function return type, e,g.: "class TDirectory*".
Each ROOT method (see TMethod) has a linked list of its arguments.
Definition TMethodArg.h:36
const char * GetTypeName() const
Get type of method argument, e.g.: "class TDirectory*" -> "TDirectory" Result needs to be used or cop...
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:308
virtual const char * GetName() const
Returns name of object.
Definition TNamed.h:47
Basic string class.
Definition TString.h:136
TString & Replace(Ssiz_t pos, Ssiz_t n, const char *s)
Definition TString.h:682
const char * Data() const
Definition TString.h:369
Ssiz_t Last(char c) const
Find last occurrence of a character c.
Definition TString.cxx:912
Bool_t IsNull() const
Definition TString.h:407
const Int_t n
Definition legend1.C:16
R__EXTERN REveManager * gEve
auto * m
Definition textangle.C:8
auto * tt
Definition textangle.C:16