Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RDFUtils.cxx
Go to the documentation of this file.
1// Author: Enrico Guiraud, Danilo Piparo CERN 03/2017
2
3/*************************************************************************
4 * Copyright (C) 1995-2018, Rene Brun and Fons Rademakers. *
5 * All rights reserved. *
6 * *
7 * For the licensing terms see $ROOTSYS/LICENSE. *
8 * For the list of contributors see $ROOTSYS/README/CREDITS. *
9 *************************************************************************/
10
11#include "RConfigure.h" // R__USE_IMT
12#include "ROOT/RDataSource.hxx"
15#include "ROOT/RDF/RSample.hxx"
17#include "ROOT/RDF/Utils.hxx"
18#include "ROOT/RLogger.hxx"
19#include "RtypesCore.h"
20#include "TBranch.h"
21#include "TBranchElement.h"
22#include "TClass.h"
23#include "TClassEdit.h"
24#include "TClassRef.h"
25#include "TError.h" // Info
26#include "TInterpreter.h"
27#include "TLeaf.h"
28#include "TROOT.h" // IsImplicitMTEnabled, GetThreadPoolSize
29#include "TTree.h"
30
31#include <fstream>
32#include <nlohmann/json.hpp> // nlohmann::json::parse
33#include <stdexcept>
34#include <string>
35#include <cstring>
36#include <typeinfo>
37#include <cstdint>
38
39using namespace ROOT::Detail::RDF;
40using namespace ROOT::RDF;
41
43{
44 static RLogChannel c("ROOT.RDF");
45 return c;
46}
47
48namespace {
49using TypeInfoRef = std::reference_wrapper<const std::type_info>;
50struct TypeInfoRefHash {
51 std::size_t operator()(TypeInfoRef id) const { return id.get().hash_code(); }
52};
53
54struct TypeInfoRefEqualComp {
55 bool operator()(TypeInfoRef left, TypeInfoRef right) const { return left.get() == right.get(); }
56};
57} // namespace
58
59namespace ROOT {
60namespace Internal {
61namespace RDF {
62
63unsigned int &NThreadPerTH3()
64{
65 static unsigned int nThread = 1;
66 return nThread;
67}
68
69/// Return the type_info associated to a name. If the association fails, an
70/// exception is thrown.
71/// References and pointers are not supported since those cannot be stored in
72/// columns.
73const std::type_info &TypeName2TypeID(const std::string &name)
74{
75 // This map includes all relevant C++ fundamental types found at
76 // https://en.cppreference.com/w/cpp/language/types.html and the associated
77 // ROOT portable types when available.
78 const static std::unordered_map<std::string, TypeInfoRef> typeName2TypeIDMap{
79 // Integral types
80 // Standard integer types
81 {"short", typeid(short)},
82 {"short int", typeid(short int)},
83 {"signed short", typeid(signed short)},
84 {"signed short int", typeid(signed short int)},
85 {"unsigned short", typeid(unsigned short)},
86 {"unsigned short int", typeid(unsigned short int)},
87 {"int", typeid(int)},
88 {"signed", typeid(signed)},
89 {"signed int", typeid(signed int)},
90 {"unsigned", typeid(unsigned)},
91 {"unsigned int", typeid(unsigned int)},
92 {"long", typeid(long)},
93 {"long int", typeid(long int)},
94 {"signed long", typeid(signed long)},
95 {"signed long int", typeid(signed long int)},
96 {"unsigned long", typeid(unsigned long)},
97 {"unsigned long int", typeid(unsigned long int)},
98 {"long long", typeid(long long)},
99 {"long long int", typeid(long long int)},
100 {"signed long long", typeid(signed long long)},
101 {"signed long long int", typeid(signed long long int)},
102 {"unsigned long long", typeid(unsigned long long)},
103 {"unsigned long long int", typeid(unsigned long long int)},
104 {"std::size_t", typeid(std::size_t)},
105 // Extended standard integer types
106#ifdef INT8_MAX
107 {"std::int8_t", typeid(std::int8_t)},
108#endif
109#ifdef INT16_MAX
110 {"std::int16_t", typeid(std::int16_t)},
111#endif
112#ifdef INT32_MAX
113 {"std::int32_t", typeid(std::int32_t)},
114#endif
115#ifdef INT64_MAX
116 {"std::int64_t", typeid(std::int64_t)},
117#endif
118#ifdef UINT8_MAX
119 {"std::uint8_t", typeid(std::uint8_t)},
120#endif
121#ifdef UINT16_MAX
122 {"std::uint16_t", typeid(std::uint16_t)},
123#endif
124#ifdef UINT32_MAX
125 {"std::uint32_t", typeid(std::uint32_t)},
126#endif
127#ifdef UINT64_MAX
128 {"std::uint64_t", typeid(std::uint64_t)},
129#endif
130 // ROOT integer types
131 {"Int_t", typeid(Int_t)},
132 {"UInt_t", typeid(UInt_t)},
133 {"Short_t", typeid(Short_t)},
134 {"UShort_t", typeid(UShort_t)},
135 {"Long_t", typeid(Long_t)},
136 {"ULong_t", typeid(ULong_t)},
137 {"Long64_t", typeid(Long64_t)},
138 {"ULong64_t", typeid(ULong64_t)},
139 // Boolean type
140 {"bool", typeid(bool)},
141 {"Bool_t", typeid(bool)},
142 // Character types
143 {"char", typeid(char)},
144 {"Char_t", typeid(char)},
145 {"signed char", typeid(signed char)},
146 {"unsigned char", typeid(unsigned char)},
147 {"UChar_t", typeid(unsigned char)},
148 {"char16_t", typeid(char16_t)},
149 {"char32_t", typeid(char32_t)},
150 // Floating-point types
151 // Standard floating-point types
152 {"float", typeid(float)},
153 {"double", typeid(double)},
154 {"long double", typeid(long double)},
155 // ROOT floating-point types
156 {"Float_t", typeid(float)},
157 {"Double_t", typeid(double)}};
158
159 if (auto it = typeName2TypeIDMap.find(name); it != typeName2TypeIDMap.end())
160 return it->second.get();
161
162 if (auto c = TClass::GetClass(name.c_str())) {
163 if (!c->GetTypeInfo()) {
164 throw std::runtime_error("Cannot extract type_info of type " + name + ".");
165 }
166 return *c->GetTypeInfo();
167 }
168
169 throw std::runtime_error("Cannot extract type_info of type " + name + ".");
170}
171
172/// Returns the name of a type starting from its type_info
173/// An empty string is returned in case of failure
174/// References and pointers are not supported since those cannot be stored in
175/// columns.
176/// Note that this function will take a lock and may be a potential source of
177/// contention in multithreaded execution.
178std::string TypeID2TypeName(const std::type_info &id)
179{
180 const static std::unordered_map<TypeInfoRef, std::string, TypeInfoRefHash, TypeInfoRefEqualComp> typeID2TypeNameMap{
181 {typeid(char), "char"}, {typeid(unsigned char), "unsigned char"},
182 {typeid(int), "int"}, {typeid(unsigned int), "unsigned int"},
183 {typeid(short), "short"}, {typeid(unsigned short), "unsigned short"},
184 {typeid(long), "long"}, {typeid(unsigned long), "unsigned long"},
185 {typeid(double), "double"}, {typeid(float), "float"},
186 {typeid(Long64_t), "Long64_t"}, {typeid(ULong64_t), "ULong64_t"},
187 {typeid(bool), "bool"}};
188
189 if (auto it = typeID2TypeNameMap.find(id); it != typeID2TypeNameMap.end())
190 return it->second;
191
192 if (auto c = TClass::GetClass(id)) {
193 return c->GetName();
194 }
195
196 return "";
197}
198
199char TypeID2ROOTTypeName(const std::type_info &tid)
200{
201 const static std::unordered_map<TypeInfoRef, char, TypeInfoRefHash, TypeInfoRefEqualComp> typeID2ROOTTypeNameMap{
202 {typeid(char), 'B'}, {typeid(Char_t), 'B'}, {typeid(unsigned char), 'b'}, {typeid(UChar_t), 'b'},
203 {typeid(int), 'I'}, {typeid(Int_t), 'I'}, {typeid(unsigned int), 'i'}, {typeid(UInt_t), 'i'},
204 {typeid(short), 'S'}, {typeid(Short_t), 'S'}, {typeid(unsigned short), 's'}, {typeid(UShort_t), 's'},
205 {typeid(long), 'G'}, {typeid(Long_t), 'G'}, {typeid(unsigned long), 'g'}, {typeid(ULong_t), 'g'},
206 {typeid(long long), 'L'}, {typeid(Long64_t), 'L'}, {typeid(unsigned long long), 'l'}, {typeid(ULong64_t), 'l'},
207 {typeid(float), 'F'}, {typeid(Float_t), 'F'}, {typeid(Double_t), 'D'}, {typeid(double), 'D'},
208 {typeid(bool), 'O'}, {typeid(Bool_t), 'O'}};
209
210 if (auto it = typeID2ROOTTypeNameMap.find(tid); it != typeID2ROOTTypeNameMap.end())
211 return it->second;
212
213 return ' ';
214}
215
216std::string ComposeRVecTypeName(const std::string &valueType)
217{
218 return "ROOT::VecOps::RVec<" + valueType + ">";
219}
220
221std::string GetLeafTypeName(TLeaf *leaf, const std::string &colName)
222{
223 const char *colTypeCStr = leaf->GetTypeName();
224 std::string colType = colTypeCStr == nullptr ? "" : colTypeCStr;
225 if (colType.empty())
226 throw std::runtime_error("Could not deduce type of leaf " + colName);
227 if (leaf->GetLeafCount() != nullptr && leaf->GetLenStatic() == 1) {
228 // this is a variable-sized array
230 } else if (leaf->GetLeafCount() == nullptr && leaf->GetLenStatic() > 1) {
231 // this is a fixed-sized array (we do not differentiate between variable- and fixed-sized arrays)
233 } else if (leaf->GetLeafCount() != nullptr && leaf->GetLenStatic() > 1) {
234 // we do not know how to deal with this branch
235 throw std::runtime_error("TTree leaf " + colName +
236 " has both a leaf count and a static length. This is not supported.");
237 }
238
239 return colType;
240}
241
242/// Return the typename of object colName stored in t, if any. Return an empty string if colName is not in t.
243/// Supported cases:
244/// - leaves corresponding to single values, variable- and fixed-length arrays, with following syntax:
245/// - "leafname", as long as TTree::GetLeaf resolves it
246/// - "b1.b2...leafname", as long as TTree::GetLeaf("b1.b2....", "leafname") resolves it
247/// - TBranchElements, as long as TTree::GetBranch resolves their names
248std::string GetBranchOrLeafTypeName(TTree &t, const std::string &colName)
249{
250 // look for TLeaf either with GetLeaf(colName) or with GetLeaf(branchName, leafName) (splitting on last dot)
251 auto *leaf = t.GetLeaf(colName.c_str());
252 if (!leaf)
253 leaf = t.FindLeaf(colName.c_str()); // try harder
254 if (!leaf) {
255 // try splitting branchname and leafname
256 const auto dotPos = colName.find_last_of('.');
257 const auto hasDot = dotPos != std::string::npos;
258 if (hasDot) {
259 const auto branchName = colName.substr(0, dotPos);
260 const auto leafName = colName.substr(dotPos + 1);
261 leaf = t.GetLeaf(branchName.c_str(), leafName.c_str());
262 }
263 }
264 if (leaf)
265 return GetLeafTypeName(leaf, std::string(leaf->GetFullName()));
266
267 // we could not find a leaf named colName, so we look for a branch called like this
268 auto branch = t.GetBranch(colName.c_str());
269 if (!branch)
270 branch = t.FindBranch(colName.c_str()); // try harder
271 if (branch) {
272 static const TClassRef tbranchelement("TBranchElement");
273 if (branch->InheritsFrom(tbranchelement)) {
274 auto be = static_cast<TBranchElement *>(branch);
275 if (auto currentClass = be->GetCurrentClass())
276 return currentClass->GetName();
277 else {
278 // Here we have a special case for getting right the type of data members
279 // of classes sorted in TClonesArrays: ROOT-9674
280 auto mother = be->GetMother();
281 if (mother && mother->InheritsFrom(tbranchelement) && mother != be) {
282 auto beMom = static_cast<TBranchElement *>(mother);
283 auto beMomClass = beMom->GetClass();
284 if (beMomClass && 0 == std::strcmp("TClonesArray", beMomClass->GetName()))
285 return be->GetTypeName();
286 }
287 return be->GetClassName();
288 }
289 } else if (branch->IsA() == TBranch::Class() && branch->GetListOfLeaves()->GetEntriesUnsafe() == 1) {
290 // normal branch (not a TBranchElement): if it has only one leaf, we pick the type of the leaf:
291 // RDF and TTreeReader allow referring to branch.leaf as just branch if branch has only one leaf
292 leaf = static_cast<TLeaf *>(branch->GetListOfLeaves()->UncheckedAt(0));
293 return GetLeafTypeName(leaf, std::string(leaf->GetFullName()));
294 }
295 }
296
297 // we could not find a branch or a leaf called colName
298 return std::string();
299}
300
301/// Return a string containing the type of the given branch. Works both with real TTree branches and with temporary
302/// column created by Define. Throws if type name deduction fails.
303/// Note that for fixed- or variable-sized c-style arrays the returned type name will be RVec<T>.
304/// vector2RVec specifies whether typename 'std::vector<T>' should be converted to 'RVec<T>' or returned as is
305std::string ColumnName2ColumnTypeName(const std::string &colName, TTree *tree, RDataSource *ds, RDefineBase *define,
306 bool vector2RVec)
307{
308 std::string colType;
309
310 // must check defines first: we want Redefines to have precedence over everything else
311 if (define) {
312 colType = define->GetTypeName();
313 } else if (ds && ds->HasColumn(colName)) {
315 } else if (tree) {
318 std::vector<std::string> split;
319 int dummy;
320 TClassEdit::GetSplit(colType.c_str(), split, dummy);
321 auto &valueType = split[1];
323 }
324 }
325
326 if (colType.empty())
327 throw std::runtime_error("Column \"" + colName +
328 "\" is not in a dataset and is not a custom column been defined.");
329
330 return colType;
331}
332
333/// Convert type name (e.g. "Float_t") to ROOT type code (e.g. 'F') -- see TBranch documentation.
334/// Return a space ' ' in case no match was found.
335char TypeName2ROOTTypeName(const std::string &b)
336{
337 const static std::unordered_map<std::string, char> typeName2ROOTTypeNameMap{{"char", 'B'},
338 {"Char_t", 'B'},
339 {"unsigned char", 'b'},
340 {"UChar_t", 'b'},
341 {"int", 'I'},
342 {"Int_t", 'I'},
343 {"unsigned", 'i'},
344 {"unsigned int", 'i'},
345 {"UInt_t", 'i'},
346 {"short", 'S'},
347 {"short int", 'S'},
348 {"Short_t", 'S'},
349 {"unsigned short", 's'},
350 {"unsigned short int", 's'},
351 {"UShort_t", 's'},
352 {"long", 'G'},
353 {"long int", 'G'},
354 {"Long_t", 'G'},
355 {"unsigned long", 'g'},
356 {"unsigned long int", 'g'},
357 {"ULong_t", 'g'},
358 {"double", 'D'},
359 {"Double_t", 'D'},
360 {"float", 'F'},
361 {"Float_t", 'F'},
362 {"long long", 'L'},
363 {"long long int", 'L'},
364 {"Long64_t", 'L'},
365 {"unsigned long long", 'l'},
366 {"unsigned long long int", 'l'},
367 {"ULong64_t", 'l'},
368 {"bool", 'O'},
369 {"Bool_t", 'O'}};
370
371 if (auto it = typeName2ROOTTypeNameMap.find(b); it != typeName2ROOTTypeNameMap.end())
372 return it->second;
373
374 return ' ';
375}
376
377unsigned int GetNSlots()
378{
379 unsigned int nSlots = 1;
380#ifdef R__USE_IMT
383#endif // R__USE_IMT
384 return nSlots;
385}
386
387/// Replace occurrences of '.' with '_' in each string passed as argument.
388/// An Info message is printed when this happens. Dots at the end of the string are not replaced.
389/// An exception is thrown in case the resulting set of strings would contain duplicates.
390std::vector<std::string> ReplaceDotWithUnderscore(const std::vector<std::string> &columnNames)
391{
393 for (auto &col : newColNames) {
394 const auto dotPos = col.find('.');
395 if (dotPos != std::string::npos && dotPos != col.size() - 1 && dotPos != 0u) {
396 auto oldName = col;
397 std::replace(col.begin(), col.end(), '.', '_');
398 if (std::find(columnNames.begin(), columnNames.end(), col) != columnNames.end())
399 throw std::runtime_error("Column " + oldName + " would be written as " + col +
400 " but this column already exists. Please use Alias to select a new name for " +
401 oldName);
402 Info("Snapshot", "Column %s will be saved as %s", oldName.c_str(), col.c_str());
403 }
404 }
405
406 return newColNames;
407}
408
409void InterpreterDeclare(const std::string &code)
410{
411 R__LOG_DEBUG(10, RDFLogChannel()) << "Declaring the following code to cling:\n\n" << code << '\n';
412
413 if (!gInterpreter->Declare(code.c_str())) {
414 const auto msg =
415 "\nRDataFrame: An error occurred during just-in-time compilation. The lines above might indicate the cause of "
416 "the crash\n All RDF objects that have not run an event loop yet should be considered in an invalid state.\n";
417 throw std::runtime_error(msg);
418 }
419}
420
421void InterpreterCalc(const std::string &code, const std::string &context)
422{
423 if (code.empty())
424 return;
425
426 R__LOG_DEBUG(10, RDFLogChannel()) << "Jitting and executing the following code:\n\n" << code << '\n';
427
428 TInterpreter::EErrorCode errorCode(TInterpreter::kNoError); // storage for cling errors
429
430 auto callCalc = [&errorCode, &context](const std::string &codeSlice) {
431 gInterpreter->Calc(codeSlice.c_str(), &errorCode);
433 std::string msg = "\nAn error occurred during just-in-time compilation";
434 if (!context.empty())
435 msg += " in " + context;
436 msg +=
437 ". The lines above might indicate the cause of the crash\nAll RDF objects that have not run their event "
438 "loop yet should be considered in an invalid state.\n";
439 throw std::runtime_error(msg);
440 }
441 };
442
443 // Call Calc every 1000 newlines in order to avoid jitting a very large function body, which is slow:
444 // see https://github.com/root-project/root/issues/9312 and https://github.com/root-project/root/issues/7604
445 std::size_t substr_start = 0;
446 std::size_t substr_end = 0;
447 while (substr_end != std::string::npos && substr_start != code.size() - 1) {
448 for (std::size_t i = 0u; i < 1000u && substr_end != std::string::npos; ++i) {
449 substr_end = code.find('\n', substr_end + 1);
450 }
451 const std::string subs = code.substr(substr_start, substr_end - substr_start);
453
454 callCalc(subs);
455 }
456}
457
458bool IsInternalColumn(std::string_view colName)
459{
460 const auto str = colName.data();
461 const auto goodPrefix = colName.size() > 3 && // has at least more characters than {r,t}df
462 ('r' == str[0] || 't' == str[0]) && // starts with r or t
463 0 == strncmp("df", str + 1, 2); // 2nd and 3rd letters are df
464 return goodPrefix && '_' == colName.back(); // also ends with '_'
465}
466
467unsigned int GetColumnWidth(const std::vector<std::string>& names, const unsigned int minColumnSpace)
468{
469 auto columnWidth = 0u;
470 for (const auto& name : names) {
471 const auto length = name.length();
472 if (length > columnWidth)
474 }
476 return columnWidth;
477}
478
479void CheckReaderTypeMatches(const std::type_info &colType, const std::type_info &requestedType,
480 const std::string &colName)
481{
482 // We want to explicitly support the reading of bools as unsigned char, as
483 // this is quite common to circumvent the std::vector<bool> specialization.
484 const bool explicitlySupported = (colType == typeid(bool) && requestedType == typeid(unsigned char)) ? true : false;
485
486 // Here we compare names and not typeinfos since they may come from two different contexts: a compiled
487 // and a jitted one.
488 const auto diffTypes = (0 != std::strcmp(colType.name(), requestedType.name()));
489 auto inheritedType = [&]() {
491 return colTClass && colTClass->InheritsFrom(TClass::GetClass(requestedType));
492 };
493
495 const auto tName = TypeID2TypeName(requestedType);
496 const auto colTypeName = TypeID2TypeName(colType);
497 std::string errMsg = "RDataFrame: type mismatch: column \"" + colName + "\" is being used as ";
498 if (tName.empty()) {
499 errMsg += requestedType.name();
500 errMsg += " (extracted from type info)";
501 } else {
502 errMsg += tName;
503 }
504 errMsg += " but the Define or Vary node advertises it as ";
505 if (colTypeName.empty()) {
506 auto &id = colType;
507 errMsg += id.name();
508 errMsg += " (extracted from type info)";
509 } else {
511 }
512 throw std::runtime_error(errMsg);
513 }
514}
515
516bool IsStrInVec(const std::string &str, const std::vector<std::string> &vec)
517{
518 return std::find(vec.cbegin(), vec.cend(), str) != vec.cend();
519}
520
521auto RStringCache::Insert(const std::string &string) -> decltype(fStrings)::const_iterator
522{
523 {
524 std::shared_lock l{fMutex};
525 if (auto it = fStrings.find(string); it != fStrings.end())
526 return it;
527 }
528
529 // TODO: Would be nicer to use a lock upgrade strategy a-la TVirtualRWMutex
530 // but that is unfortunately not usable outside the already available ROOT mutexes
531 std::unique_lock l{fMutex};
532 if (auto it = fStrings.find(string); it != fStrings.end())
533 return it;
534
535 return fStrings.insert(string).first;
536}
537
539{
540 const nlohmann::ordered_json fullData = nlohmann::ordered_json::parse(std::ifstream(jsonFile));
541 if (!fullData.contains("samples") || fullData["samples"].empty()) {
542 throw std::runtime_error(
543 R"(The input specification does not contain any samples. Please provide the samples in the specification like:
544{
545 "samples": {
546 "sampleA": {
547 "trees": ["tree1", "tree2"],
548 "files": ["file1.root", "file2.root"],
549 "metadata": {"lumi": 1.0, }
550 },
551 "sampleB": {
552 "trees": ["tree3", "tree4"],
553 "files": ["file3.root", "file4.root"],
554 "metadata": {"lumi": 0.5, }
555 },
556 ...
557 },
558})");
559 }
560
562 for (const auto &keyValue : fullData["samples"].items()) {
563 const std::string &sampleName = keyValue.key();
564 const auto &sample = keyValue.value();
565 // TODO: if requested in https://github.com/root-project/root/issues/11624
566 // allow union-like types for trees and files, see: https://github.com/nlohmann/json/discussions/3815
567 if (!sample.contains("trees")) {
568 throw std::runtime_error("A list of tree names must be provided for sample " + sampleName + ".");
569 }
570 std::vector<std::string> trees = sample["trees"];
571 if (!sample.contains("files")) {
572 throw std::runtime_error("A list of files must be provided for sample " + sampleName + ".");
573 }
574 std::vector<std::string> files = sample["files"];
575 if (!sample.contains("metadata")) {
577 } else {
579 for (const auto &metadata : sample["metadata"].items()) {
580 const auto &val = metadata.value();
581 if (val.is_string())
582 m.Add(metadata.key(), val.get<std::string>());
583 else if (val.is_number_integer())
584 m.Add(metadata.key(), val.get<int>());
585 else if (val.is_number_float())
586 m.Add(metadata.key(), val.get<double>());
587 else
588 throw std::logic_error("The metadata keys can only be of type [string|int|double].");
589 }
591 }
592 }
593 if (fullData.contains("friends")) {
594 for (const auto &friends : fullData["friends"].items()) {
595 std::string alias = friends.key();
596 std::vector<std::string> trees = friends.value()["trees"];
597 std::vector<std::string> files = friends.value()["files"];
598 if (files.size() != trees.size() && trees.size() > 1)
599 throw std::runtime_error("Mismatch between trees and files in a friend.");
600 spec.WithGlobalFriends(trees, files, alias);
601 }
602 }
603
604 if (fullData.contains("range")) {
605 std::vector<int> range = fullData["range"];
606
607 if (range.size() == 1)
608 spec.WithGlobalRange({range[0]});
609 else if (range.size() == 2)
610 spec.WithGlobalRange({range[0], range[1]});
611 }
612 return spec;
613};
614
615} // end NS RDF
616} // end NS Internal
617} // end NS ROOT
618
619std::string
621{
622 return df.GetTypeNameWithOpts(colName, vector2RVec);
623}
624
626{
627 return df.GetTopLevelFieldNames();
628}
629
631{
632 return df.GetColumnNamesNoDuplicates();
633}
634
640
642{
643 return ds.DescribeDataset();
644}
645
647 const ROOT::RDF::RDataSource &ds, unsigned int slot,
648 const std::unordered_map<std::string, ROOT::RDF::Experimental::RSample *> &sampleMap)
649{
650 return ds.CreateSampleInfo(slot, sampleMap);
651}
652
657
662
663std::unique_ptr<ROOT::Detail::RDF::RColumnReaderBase>
665 const std::type_info &tid, TTreeReader *treeReader)
666{
667 return ds.CreateColumnReader(slot, col, tid, treeReader);
668}
669
671{
672 return std::move(spec.fSamples);
673}
#define R__LOG_DEBUG(DEBUGLEVEL,...)
Definition RLogger.hxx:360
#define b(i)
Definition RSha256.hxx:100
#define c(i)
Definition RSha256.hxx:101
bool Bool_t
Definition RtypesCore.h:63
unsigned short UShort_t
Definition RtypesCore.h:40
int Int_t
Definition RtypesCore.h:45
unsigned char UChar_t
Definition RtypesCore.h:38
char Char_t
Definition RtypesCore.h:37
unsigned long ULong_t
Definition RtypesCore.h:55
long Long_t
Definition RtypesCore.h:54
unsigned int UInt_t
Definition RtypesCore.h:46
float Float_t
Definition RtypesCore.h:57
short Short_t
Definition RtypesCore.h:39
double Double_t
Definition RtypesCore.h:59
long long Long64_t
Definition RtypesCore.h:69
unsigned long long ULong64_t
Definition RtypesCore.h:70
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h length
char name[80]
Definition TGX11.cxx:110
#define gInterpreter
TRObject operator()(const T1 &t1) const
std::string GetTypeName() const
The head node of a RDF computation graph.
auto Insert(const std::string &string) -> decltype(fStrings)::const_iterator
Inserts the input string in the cache and returns an iterator to the cached string.
Definition RDFUtils.cxx:521
The dataset specification for RDataFrame.
Class behaving as a heterogenuous dictionary to store the metadata of a dataset.
Definition RMetaData.hxx:57
Class representing a sample which is a grouping of trees and their fileglobs, and,...
Definition RSample.hxx:39
RDataSource defines an API that RDataFrame can use to read arbitrary data formats.
This type represents a sample identifier, to be used in conjunction with RDataFrame features such as ...
A log configuration for a channel, e.g.
Definition RLogger.hxx:98
const_iterator begin() const
const_iterator end() const
A Branch for the case of an object.
static TClass * Class()
TClassRef is used to implement a permanent reference to a TClass object.
Definition TClassRef.h:29
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:3074
A TLeaf describes individual elements of a TBranch See TBranch structure in TTree.
Definition TLeaf.h:57
A simple, robust and fast interface to read values from ROOT columnar datasets such as TTree,...
Definition TTreeReader.h:46
A TTree represents a columnar dataset.
Definition TTree.h:89
virtual TBranch * FindBranch(const char *name)
Return the branch that correspond to the path 'branchname', which can include the name of the tree or...
Definition TTree.cxx:4890
virtual TBranch * GetBranch(const char *name)
Return pointer to the branch with the given name in this tree or its friends.
Definition TTree.cxx:5429
virtual TLeaf * GetLeaf(const char *branchname, const char *leafname)
Return pointer to the 1st Leaf named name in any Branch of this Tree or any branch in the list of fri...
Definition TTree.cxx:6274
virtual TLeaf * FindLeaf(const char *name)
Find leaf..
Definition TTree.cxx:4965
std::ostream & Info()
Definition hadd.cxx:177
ROOT::RLogChannel & RDFLogChannel()
Definition RDFUtils.cxx:42
void RunFinalChecks(const ROOT::RDF::RDataSource &ds, bool nodesLeftNotRun)
Definition RDFUtils.cxx:653
std::vector< std::string > ReplaceDotWithUnderscore(const std::vector< std::string > &columnNames)
Replace occurrences of '.
Definition RDFUtils.cxx:390
const std::type_info & TypeName2TypeID(const std::string &name)
Return the type_info associated to a name.
Definition RDFUtils.cxx:73
ROOT::RDF::RSampleInfo CreateSampleInfo(const ROOT::RDF::RDataSource &ds, unsigned int slot, const std::unordered_map< std::string, ROOT::RDF::Experimental::RSample * > &sampleMap)
Definition RDFUtils.cxx:646
ROOT::RDF::Experimental::RDatasetSpec RetrieveSpecFromJson(const std::string &jsonFile)
Function to retrieve RDatasetSpec from JSON file provided.
Definition RDFUtils.cxx:538
unsigned int GetNSlots()
Definition RDFUtils.cxx:377
std::string ComposeRVecTypeName(const std::string &valueType)
Definition RDFUtils.cxx:216
void CallInitializeWithOpts(ROOT::RDF::RDataSource &ds, const std::set< std::string > &suppressErrorsForMissingColumns)
Definition RDFUtils.cxx:635
std::string GetLeafTypeName(TLeaf *leaf, const std::string &colName)
Definition RDFUtils.cxx:221
const std::vector< std::string > & GetTopLevelFieldNames(const ROOT::RDF::RDataSource &ds)
Definition RDFUtils.cxx:625
char TypeName2ROOTTypeName(const std::string &b)
Convert type name (e.g.
Definition RDFUtils.cxx:335
std::string TypeID2TypeName(const std::type_info &id)
Returns the name of a type starting from its type_info An empty string is returned in case of failure...
Definition RDFUtils.cxx:178
bool IsStrInVec(const std::string &str, const std::vector< std::string > &vec)
Definition RDFUtils.cxx:516
unsigned int GetColumnWidth(const std::vector< std::string > &names, const unsigned int minColumnSpace=8u)
Get optimal column width for printing a table given the names and the desired minimal space between c...
Definition RDFUtils.cxx:467
std::string GetBranchOrLeafTypeName(TTree &t, const std::string &colName)
Return the typename of object colName stored in t, if any.
Definition RDFUtils.cxx:248
std::string DescribeDataset(ROOT::RDF::RDataSource &ds)
Definition RDFUtils.cxx:641
std::unique_ptr< ROOT::Detail::RDF::RColumnReaderBase > CreateColumnReader(ROOT::RDF::RDataSource &ds, unsigned int slot, std::string_view col, const std::type_info &tid, TTreeReader *treeReader)
Definition RDFUtils.cxx:664
std::string ColumnName2ColumnTypeName(const std::string &colName, TTree *, RDataSource *, RDefineBase *, bool vector2RVec=true)
Return a string containing the type of the given branch.
Definition RDFUtils.cxx:305
void InterpreterCalc(const std::string &code, const std::string &context="")
Jit code in the interpreter with TInterpreter::Calc, throw in case of errors.
Definition RDFUtils.cxx:421
void CheckReaderTypeMatches(const std::type_info &colType, const std::type_info &requestedType, const std::string &colName)
Definition RDFUtils.cxx:479
bool IsInternalColumn(std::string_view colName)
Whether custom column with name colName is an "internal" column such as rdfentry_ or rdfslot_.
Definition RDFUtils.cxx:458
std::vector< ROOT::RDF::Experimental::RSample > MoveOutSamples(ROOT::RDF::Experimental::RDatasetSpec &spec)
Definition RDFUtils.cxx:670
void ProcessMT(ROOT::RDF::RDataSource &ds, ROOT::Detail::RDF::RLoopManager &lm)
Definition RDFUtils.cxx:658
std::string GetTypeNameWithOpts(const ROOT::RDF::RDataSource &ds, std::string_view colName, bool vector2RVec)
Definition RDFUtils.cxx:620
void InterpreterDeclare(const std::string &code)
Declare code in the interpreter via the TInterpreter::Declare method, throw in case of errors.
Definition RDFUtils.cxx:409
const std::vector< std::string > & GetColumnNamesNoDuplicates(const ROOT::RDF::RDataSource &ds)
Definition RDFUtils.cxx:630
unsigned int & NThreadPerTH3()
Obtain or set the number of threads that will share a clone of a thread-safe 3D histogram.
Definition RDFUtils.cxx:63
char TypeID2ROOTTypeName(const std::type_info &tid)
Definition RDFUtils.cxx:199
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
Bool_t IsImplicitMTEnabled()
Returns true if the implicit multi-threading in ROOT is enabled.
Definition TROOT.cxx:595
UInt_t GetThreadPoolSize()
Returns the size of ROOT's thread pool.
Definition TROOT.cxx:602
@ kSTLvector
Definition ESTLType.h:30
ROOT::ESTLType IsSTLCont(std::string_view type)
type : type name: vector<list<classA,allocator>,allocator> result: 0 : not stl container code of cont...
int GetSplit(const char *type, std::vector< std::string > &output, int &nestedLoc, EModType mode=TClassEdit::kNone)
Stores in output (after emptying it) the split type.
TMarker m
Definition textangle.C:8
TLine l
Definition textangle.C:4