25 using namespace ROOT::Experimental;
26 namespace REX = ROOT::Experimental;
29 Color_t REveDataCollection::fgDefaultColor = kBlue;
35 REveDataCollection::REveDataCollection(
const std::string& n,
const std::string& t) :
38 fChildClass = TClass::GetClass<REveDataItem>();
40 SetupDefaultColorAndTransparency(fgDefaultColor,
true,
true);
43 _handler_func_ids = 0;
46 void REveDataCollection::AddItem(
void *data_ptr,
const std::string& n,
const std::string& t)
48 auto el =
new REveDataItem(n, t);
50 el->SetMainColor(GetMainColor());
51 fItems.emplace_back(data_ptr, el);
56 void REveDataCollection::SetFilterExpr(
const TString& filter)
58 static const REveException eh(
"REveDataCollection::SetFilterExpr ");
60 if (!fItemClass)
throw eh +
"item class has to be set before the filter expression.";
65 s <<
"*((std::function<bool(" << fItemClass->GetName() <<
"*)>*)" << std::hex << std::showbase << (size_t)&fFilterFoo
66 <<
") = [](" << fItemClass->GetName() <<
"* p){" << fItemClass->GetName() <<
" &i=*p; return ("
67 << fFilterExpr.Data() <<
"); }";
71 gROOT->ProcessLine(s.str().c_str());
75 catch (
const std::exception &exc)
77 std::cerr <<
"EveDataCollection::SetFilterExpr" << exc.what();
82 void REveDataCollection::ApplyFilter()
86 for (
auto &ii : fItems)
88 bool res = fFilterFoo(ii.fDataPtr);
92 ii.fItemPtr->SetFiltered( ! res );
97 if ( _handler_func_ids) _handler_func_ids(
this , ids);
102 Int_t REveDataCollection::WriteCoreJson(nlohmann::json &j, Int_t rnr_offset)
104 Int_t ret = REveElement::WriteCoreJson(j, rnr_offset);
105 j[
"fFilterExpr"] = fFilterExpr.Data();
106 j[
"publicFunction"] = nlohmann::json::array();
108 TIter x( fItemClass->GetListOfAllPublicMethods());
109 while (TObject *obj = x()) {
110 TMethod *method =
dynamic_cast<TMethod *
>(obj);
113 m[
"name"] = method->GetPrototype();
114 j[
"publicFunction"].push_back(m);
122 void REveDataCollection::SetCollectionColorRGB(UChar_t r, UChar_t g, UChar_t b)
124 Color_t oldv = GetMainColor();
125 Color_t newv = TColor::GetColor(r, g, b);
128 for (
auto & chld : fChildren)
131 chld->SetMainColor(newv);
132 printf(
" REveDataCollection::SetCollectionColorRGB going to change color for idx %d --------------------\n", idx);
139 REveElement::SetMainColor(newv);
140 printf(
"REveDataCollection::SetCollectionColorRGB color ched to %d ->%d\n", oldv, GetMainColor());
141 _handler_func_ids(
this , ids);
146 void REveDataCollection::SetCollectionVisible(
bool iRnrSelf)
148 SetRnrSelf(iRnrSelf);
152 for (
int i = 0; i < GetNItems(); ++i ) {
154 GetDataItem(i)->SetRnrSelf(fRnrSelf);
157 _handler_func_ids(
this , ids);
164 void REveDataCollection::ItemChanged(REveDataItem* iItem)
168 for (
auto & chld : fChildren)
172 _handler_func_ids(
this , ids);
183 REveDataItem::REveDataItem(
const std::string& n,
const std::string& t) :
186 SetupDefaultColorAndTransparency(kMagenta,
true,
true);
189 Int_t REveDataItem::WriteCoreJson(nlohmann::json &j, Int_t rnr_offset)
191 Int_t ret = REveElement::WriteCoreJson(j, rnr_offset);
192 j[
"fFiltered"] = fFiltered;
196 void REveDataItem::SetItemColorRGB(UChar_t r, UChar_t g, UChar_t b)
198 Color_t color = TColor::GetColor(r, g, b);
199 REveElement::SetMainColor(color);
200 REveDataCollection* c =
dynamic_cast<REveDataCollection*
>(fMother);
201 c->ItemChanged(
this);
204 void REveDataItem::SetItemRnrSelf(
bool iRnrSelf)
206 REveElement::SetRnrSelf(iRnrSelf);
207 REveDataCollection* c =
dynamic_cast<REveDataCollection*
>(fMother);
208 c->ItemChanged(
this);
211 void REveDataItem::SetFiltered(
bool f)
220 void REveDataItem::FillImpliedSelectedSet(Set_t &impSelSet)
222 for (
auto &n : fNieces)
225 n->FillImpliedSelectedSet(impSelSet);
229 printf(
"REveDataItem::FillImpliedSelectedSet added niece '%s' [%s]\n",
230 n->GetCName(), n->IsA()->GetName());
239 REveDataTable::REveDataTable(
const std::string& n,
const std::string& t) :
242 fChildClass = TClass::GetClass<REveDataColumn>();
245 void REveDataTable::PrintTable()
247 Int_t Nit = fCollection->GetNItems();
249 for (Int_t i = 0; i< Nit; ++i)
251 void *data = fCollection->GetDataPtr(i);
252 REveDataItem *item = fCollection->GetDataItem(i);
254 printf(
"| %-20s |", item->GetCName());
256 for (
auto & chld : fChildren)
258 auto clmn =
dynamic_cast<REveDataColumn*
>(chld);
260 printf(
" %10s |", clmn->EvalExpr(data).c_str());
266 Int_t REveDataTable::WriteCoreJson(nlohmann::json &j, Int_t rnr_offset)
268 int ret = REveElement::WriteCoreJson(j, rnr_offset);
269 Int_t Nit = fCollection->GetNItems();
271 nlohmann::json jarr = nlohmann::json::array();
273 for (Int_t i = 0; i < Nit; ++i) {
274 void *data = fCollection->GetDataPtr(i);
276 for (
auto &chld : fChildren) {
277 auto clmn =
dynamic_cast<REveDataColumn *
>(chld);
278 row[chld->GetCName()] = clmn->EvalExpr(data);
283 j[
"fCollectionId"] = fCollection->GetElementId();
287 void REveDataTable::AddNewColumn(
const std::string& expr,
const std::string& title,
int prec)
289 auto c =
new REX::REveDataColumn(title);
292 c->SetExpressionAndType(expr, REX::REveDataColumn::FT_Double);
293 c->SetPrecision(prec);
302 REveDataColumn::REveDataColumn(
const std::string& n,
const std::string& t) :
307 void REveDataColumn::SetExpressionAndType(
const std::string& expr, FieldType_e type)
309 auto table =
dynamic_cast<REveDataTable*
>(fMother);
310 auto coll = table->GetCollection();
311 auto icls = coll->GetItemClass();
316 const char *rtyp =
nullptr;
317 const void *fooptr =
nullptr;
321 case FT_Double: rtyp =
"double"; fooptr = &fDoubleFoo;
break;
322 case FT_Bool: rtyp =
"bool"; fooptr = &fBoolFoo;
break;
323 case FT_String: rtyp =
"std::string"; fooptr = &fStringFoo;
break;
327 s <<
"*((std::function<" << rtyp <<
"(" << icls->GetName() <<
"*)>*)" << std::hex << std::showbase << (size_t)fooptr
328 <<
") = [](" << icls->GetName() <<
"* p){" << icls->GetName() <<
" &i=*p; return (" << fExpression.Data()
333 gROOT->ProcessLine(s.str().c_str());
335 catch (
const std::exception &exc)
337 std::cerr <<
"REveDataColumn::SetExpressionAndType" << exc.what();
341 void REveDataColumn::SetPrecision(Int_t prec)
346 std::string REveDataColumn::EvalExpr(
void *iptr)
353 ostr.Form(
"%.*f", fPrecision, fDoubleFoo(iptr));
358 return fBoolFoo(iptr) ? fTrue : fFalse;
362 return fStringFoo(iptr);