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"},
182 {typeid(unsigned char), "unsigned char"},
183 {typeid(signed char), "signed char"},
184 {typeid(int), "int"},
185 {typeid(unsigned int), "unsigned int"},
186 {typeid(short), "short"},
187 {typeid(unsigned short), "unsigned short"},
188 {typeid(long), "long"},
189 {typeid(unsigned long), "unsigned long"},
190 {typeid(double), "double"},
191 {typeid(float), "float"},
192 {typeid(Long64_t), "Long64_t"},
193 {typeid(ULong64_t), "ULong64_t"},
194 {typeid(bool), "bool"}};
195
196 if (auto it = typeID2TypeNameMap.find(id); it != typeID2TypeNameMap.end())
197 return it->second;
198
199 if (auto c = TClass::GetClass(id)) {
200 return c->GetName();
201 }
202
203 return "";
204}
205
206char TypeID2ROOTTypeName(const std::type_info &tid)
207{
208 const static std::unordered_map<TypeInfoRef, char, TypeInfoRefHash, TypeInfoRefEqualComp> typeID2ROOTTypeNameMap{
209 {typeid(char), 'B'}, {typeid(Char_t), 'B'}, {typeid(unsigned char), 'b'}, {typeid(UChar_t), 'b'},
210 {typeid(int), 'I'}, {typeid(Int_t), 'I'}, {typeid(unsigned int), 'i'}, {typeid(UInt_t), 'i'},
211 {typeid(short), 'S'}, {typeid(Short_t), 'S'}, {typeid(unsigned short), 's'}, {typeid(UShort_t), 's'},
212 {typeid(long), 'G'}, {typeid(Long_t), 'G'}, {typeid(unsigned long), 'g'}, {typeid(ULong_t), 'g'},
213 {typeid(long long), 'L'}, {typeid(Long64_t), 'L'}, {typeid(unsigned long long), 'l'}, {typeid(ULong64_t), 'l'},
214 {typeid(float), 'F'}, {typeid(Float_t), 'F'}, {typeid(Double_t), 'D'}, {typeid(double), 'D'},
215 {typeid(bool), 'O'}, {typeid(Bool_t), 'O'}};
216
217 if (auto it = typeID2ROOTTypeNameMap.find(tid); it != typeID2ROOTTypeNameMap.end())
218 return it->second;
219
220 return ' ';
221}
222
223std::string ComposeRVecTypeName(const std::string &valueType)
224{
225 return "ROOT::VecOps::RVec<" + valueType + ">";
226}
227
228std::string GetLeafTypeName(TLeaf *leaf, const std::string &colName)
229{
230 const char *colTypeCStr = leaf->GetTypeName();
231 std::string colType = colTypeCStr == nullptr ? "" : colTypeCStr;
232 if (colType.empty())
233 throw std::runtime_error("Could not deduce type of leaf " + colName);
234 if (leaf->GetLeafCount() != nullptr && leaf->GetLenStatic() == 1) {
235 // this is a variable-sized array
237 } else if (leaf->GetLeafCount() == nullptr && leaf->GetLenStatic() > 1) {
238 // this is a fixed-sized array (we do not differentiate between variable- and fixed-sized arrays)
240 } else if (leaf->GetLeafCount() != nullptr && leaf->GetLenStatic() > 1) {
241 // we do not know how to deal with this branch
242 throw std::runtime_error("TTree leaf " + colName +
243 " has both a leaf count and a static length. This is not supported.");
244 }
245
246 return colType;
247}
248
249/// Return the typename of object colName stored in t, if any. Return an empty string if colName is not in t.
250/// Supported cases:
251/// - leaves corresponding to single values, variable- and fixed-length arrays, with following syntax:
252/// - "leafname", as long as TTree::GetLeaf resolves it
253/// - "b1.b2...leafname", as long as TTree::GetLeaf("b1.b2....", "leafname") resolves it
254/// - TBranchElements, as long as TTree::GetBranch resolves their names
255std::string GetBranchOrLeafTypeName(TTree &t, const std::string &colName)
256{
257 // look for TLeaf either with GetLeaf(colName) or with GetLeaf(branchName, leafName) (splitting on last dot)
258 auto *leaf = t.GetLeaf(colName.c_str());
259 if (!leaf)
260 leaf = t.FindLeaf(colName.c_str()); // try harder
261 if (!leaf) {
262 // try splitting branchname and leafname
263 const auto dotPos = colName.find_last_of('.');
264 const auto hasDot = dotPos != std::string::npos;
265 if (hasDot) {
266 const auto branchName = colName.substr(0, dotPos);
267 const auto leafName = colName.substr(dotPos + 1);
268 leaf = t.GetLeaf(branchName.c_str(), leafName.c_str());
269 }
270 }
271 if (leaf)
272 return GetLeafTypeName(leaf, std::string(leaf->GetFullName()));
273
274 // we could not find a leaf named colName, so we look for a branch called like this
275 auto branch = t.GetBranch(colName.c_str());
276 if (!branch)
277 branch = t.FindBranch(colName.c_str()); // try harder
278 if (branch) {
279 static const TClassRef tbranchelement("TBranchElement");
280 if (branch->InheritsFrom(tbranchelement)) {
281 auto be = static_cast<TBranchElement *>(branch);
282 if (auto currentClass = be->GetCurrentClass())
283 return currentClass->GetName();
284 else {
285 // Here we have a special case for getting right the type of data members
286 // of classes sorted in TClonesArrays: ROOT-9674
287 auto mother = be->GetMother();
288 if (mother && mother->InheritsFrom(tbranchelement) && mother != be) {
289 auto beMom = static_cast<TBranchElement *>(mother);
290 auto beMomClass = beMom->GetClass();
291 if (beMomClass && 0 == std::strcmp("TClonesArray", beMomClass->GetName()))
292 return be->GetTypeName();
293 }
294 return be->GetClassName();
295 }
296 } else if (branch->IsA() == TBranch::Class() && branch->GetListOfLeaves()->GetEntriesUnsafe() == 1) {
297 // normal branch (not a TBranchElement): if it has only one leaf, we pick the type of the leaf:
298 // RDF and TTreeReader allow referring to branch.leaf as just branch if branch has only one leaf
299 leaf = static_cast<TLeaf *>(branch->GetListOfLeaves()->UncheckedAt(0));
300 return GetLeafTypeName(leaf, std::string(leaf->GetFullName()));
301 }
302 }
303
304 // we could not find a branch or a leaf called colName
305 return std::string();
306}
307
308/// Return a string containing the type of the given branch. Works both with real TTree branches and with temporary
309/// column created by Define. Throws if type name deduction fails.
310/// Note that for fixed- or variable-sized c-style arrays the returned type name will be RVec<T>.
311/// vector2RVec specifies whether typename 'std::vector<T>' should be converted to 'RVec<T>' or returned as is
312std::string ColumnName2ColumnTypeName(const std::string &colName, TTree *tree, RDataSource *ds, RDefineBase *define,
313 bool vector2RVec)
314{
315 std::string colType;
316
317 // must check defines first: we want Redefines to have precedence over everything else
318 if (define) {
319 colType = define->GetTypeName();
320 } else if (ds && ds->HasColumn(colName)) {
322 } else if (tree) {
325 std::vector<std::string> split;
326 int dummy;
327 TClassEdit::GetSplit(colType.c_str(), split, dummy);
328 auto &valueType = split[1];
330 }
331 }
332
333 if (colType.empty())
334 throw std::runtime_error("Column \"" + colName +
335 "\" is not in a dataset and is not a custom column been defined.");
336
337 return colType;
338}
339
340/// Convert type name (e.g. "Float_t") to ROOT type code (e.g. 'F') -- see TBranch documentation.
341/// Return a space ' ' in case no match was found.
342char TypeName2ROOTTypeName(const std::string &b)
343{
344 const static std::unordered_map<std::string, char> typeName2ROOTTypeNameMap{{"char", 'B'},
345 {"Char_t", 'B'},
346 {"unsigned char", 'b'},
347 {"UChar_t", 'b'},
348 {"int", 'I'},
349 {"Int_t", 'I'},
350 {"unsigned", 'i'},
351 {"unsigned int", 'i'},
352 {"UInt_t", 'i'},
353 {"short", 'S'},
354 {"short int", 'S'},
355 {"Short_t", 'S'},
356 {"unsigned short", 's'},
357 {"unsigned short int", 's'},
358 {"UShort_t", 's'},
359 {"long", 'G'},
360 {"long int", 'G'},
361 {"Long_t", 'G'},
362 {"unsigned long", 'g'},
363 {"unsigned long int", 'g'},
364 {"ULong_t", 'g'},
365 {"double", 'D'},
366 {"Double_t", 'D'},
367 {"float", 'F'},
368 {"Float_t", 'F'},
369 {"long long", 'L'},
370 {"long long int", 'L'},
371 {"Long64_t", 'L'},
372 {"unsigned long long", 'l'},
373 {"unsigned long long int", 'l'},
374 {"ULong64_t", 'l'},
375 {"bool", 'O'},
376 {"Bool_t", 'O'}};
377
378 if (auto it = typeName2ROOTTypeNameMap.find(b); it != typeName2ROOTTypeNameMap.end())
379 return it->second;
380
381 return ' ';
382}
383
384unsigned int GetNSlots()
385{
386 unsigned int nSlots = 1;
387#ifdef R__USE_IMT
390#endif // R__USE_IMT
391 return nSlots;
392}
393
394/// Replace occurrences of '.' with '_' in each string passed as argument.
395/// An Info message is printed when this happens. Dots at the end of the string are not replaced.
396/// An exception is thrown in case the resulting set of strings would contain duplicates.
397std::vector<std::string> ReplaceDotWithUnderscore(const std::vector<std::string> &columnNames)
398{
400 for (auto &col : newColNames) {
401 const auto dotPos = col.find('.');
402 if (dotPos != std::string::npos && dotPos != col.size() - 1 && dotPos != 0u) {
403 auto oldName = col;
404 std::replace(col.begin(), col.end(), '.', '_');
405 if (std::find(columnNames.begin(), columnNames.end(), col) != columnNames.end())
406 throw std::runtime_error("Column " + oldName + " would be written as " + col +
407 " but this column already exists. Please use Alias to select a new name for " +
408 oldName);
409 Info("Snapshot", "Column %s will be saved as %s", oldName.c_str(), col.c_str());
410 }
411 }
412
413 return newColNames;
414}
415
416void InterpreterDeclare(const std::string &code)
417{
418 R__LOG_DEBUG(10, RDFLogChannel()) << "Declaring the following code to cling:\n\n" << code << '\n';
419
420 if (!gInterpreter->Declare(code.c_str())) {
421 const auto msg =
422 "\nRDataFrame: An error occurred during just-in-time compilation. The lines above might indicate the cause of "
423 "the crash\n All RDF objects that have not run an event loop yet should be considered in an invalid state.\n";
424 throw std::runtime_error(msg);
425 }
426}
427
428void InterpreterCalc(const std::string &code, const std::string &context)
429{
430 if (code.empty())
431 return;
432
433 R__LOG_DEBUG(10, RDFLogChannel()) << "Jitting and executing the following code:\n\n" << code << '\n';
434
435 TInterpreter::EErrorCode errorCode(TInterpreter::kNoError); // storage for cling errors
436
437 auto callCalc = [&errorCode, &context](const std::string &codeSlice) {
438 gInterpreter->Calc(codeSlice.c_str(), &errorCode);
440 std::string msg = "\nAn error occurred during just-in-time compilation";
441 if (!context.empty())
442 msg += " in " + context;
443 msg +=
444 ". The lines above might indicate the cause of the crash\nAll RDF objects that have not run their event "
445 "loop yet should be considered in an invalid state.\n";
446 throw std::runtime_error(msg);
447 }
448 };
449
450 // Call Calc every 1000 newlines in order to avoid jitting a very large function body, which is slow:
451 // see https://github.com/root-project/root/issues/9312 and https://github.com/root-project/root/issues/7604
452 std::size_t substr_start = 0;
453 std::size_t substr_end = 0;
454 while (substr_end != std::string::npos && substr_start != code.size() - 1) {
455 for (std::size_t i = 0u; i < 1000u && substr_end != std::string::npos; ++i) {
456 substr_end = code.find('\n', substr_end + 1);
457 }
458 const std::string subs = code.substr(substr_start, substr_end - substr_start);
460
461 callCalc(subs);
462 }
463}
464
465bool IsInternalColumn(std::string_view colName)
466{
467 const auto str = colName.data();
468 const auto goodPrefix = colName.size() > 3 && // has at least more characters than {r,t}df
469 ('r' == str[0] || 't' == str[0]) && // starts with r or t
470 0 == strncmp("df", str + 1, 2); // 2nd and 3rd letters are df
471 return goodPrefix && '_' == colName.back(); // also ends with '_'
472}
473
474unsigned int GetColumnWidth(const std::vector<std::string>& names, const unsigned int minColumnSpace)
475{
476 auto columnWidth = 0u;
477 for (const auto& name : names) {
478 const auto length = name.length();
479 if (length > columnWidth)
481 }
483 return columnWidth;
484}
485
486void CheckReaderTypeMatches(const std::type_info &colType, const std::type_info &requestedType,
487 const std::string &colName)
488{
489 // We want to explicitly support the reading of bools as unsigned char, as
490 // this is quite common to circumvent the std::vector<bool> specialization.
491 const bool explicitlySupported = (colType == typeid(bool) && requestedType == typeid(unsigned char)) ? true : false;
492
493 // Here we compare names and not typeinfos since they may come from two different contexts: a compiled
494 // and a jitted one.
495 const auto diffTypes = (0 != std::strcmp(colType.name(), requestedType.name()));
496 auto inheritedType = [&]() {
498 return colTClass && colTClass->InheritsFrom(TClass::GetClass(requestedType));
499 };
500
502 const auto tName = TypeID2TypeName(requestedType);
503 const auto colTypeName = TypeID2TypeName(colType);
504 std::string errMsg = "RDataFrame: type mismatch: column \"" + colName + "\" is being used as ";
505 if (tName.empty()) {
506 errMsg += requestedType.name();
507 errMsg += " (extracted from type info)";
508 } else {
509 errMsg += tName;
510 }
511 errMsg += " but the Define or Vary node advertises it as ";
512 if (colTypeName.empty()) {
513 auto &id = colType;
514 errMsg += id.name();
515 errMsg += " (extracted from type info)";
516 } else {
518 }
519 throw std::runtime_error(errMsg);
520 }
521}
522
523bool IsStrInVec(const std::string &str, const std::vector<std::string> &vec)
524{
525 return std::find(vec.cbegin(), vec.cend(), str) != vec.cend();
526}
527
528auto RStringCache::Insert(const std::string &string) -> decltype(fStrings)::const_iterator
529{
530 {
531 std::shared_lock l{fMutex};
532 if (auto it = fStrings.find(string); it != fStrings.end())
533 return it;
534 }
535
536 // TODO: Would be nicer to use a lock upgrade strategy a-la TVirtualRWMutex
537 // but that is unfortunately not usable outside the already available ROOT mutexes
538 std::unique_lock l{fMutex};
539 if (auto it = fStrings.find(string); it != fStrings.end())
540 return it;
541
542 return fStrings.insert(string).first;
543}
544
546{
547 const nlohmann::ordered_json fullData = nlohmann::ordered_json::parse(std::ifstream(jsonFile));
548 if (!fullData.contains("samples") || fullData["samples"].empty()) {
549 throw std::runtime_error(
550 R"(The input specification does not contain any samples. Please provide the samples in the specification like:
551{
552 "samples": {
553 "sampleA": {
554 "trees": ["tree1", "tree2"],
555 "files": ["file1.root", "file2.root"],
556 "metadata": {"lumi": 1.0, }
557 },
558 "sampleB": {
559 "trees": ["tree3", "tree4"],
560 "files": ["file3.root", "file4.root"],
561 "metadata": {"lumi": 0.5, }
562 },
563 ...
564 },
565})");
566 }
567
569 for (const auto &keyValue : fullData["samples"].items()) {
570 const std::string &sampleName = keyValue.key();
571 const auto &sample = keyValue.value();
572 // TODO: if requested in https://github.com/root-project/root/issues/11624
573 // allow union-like types for trees and files, see: https://github.com/nlohmann/json/discussions/3815
574 if (!sample.contains("trees")) {
575 throw std::runtime_error("A list of tree names must be provided for sample " + sampleName + ".");
576 }
577 std::vector<std::string> trees = sample["trees"];
578 if (!sample.contains("files")) {
579 throw std::runtime_error("A list of files must be provided for sample " + sampleName + ".");
580 }
581 std::vector<std::string> files = sample["files"];
582 if (!sample.contains("metadata")) {
584 } else {
586 for (const auto &metadata : sample["metadata"].items()) {
587 const auto &val = metadata.value();
588 if (val.is_string())
589 m.Add(metadata.key(), val.get<std::string>());
590 else if (val.is_number_integer())
591 m.Add(metadata.key(), val.get<int>());
592 else if (val.is_number_float())
593 m.Add(metadata.key(), val.get<double>());
594 else
595 throw std::logic_error("The metadata keys can only be of type [string|int|double].");
596 }
598 }
599 }
600 if (fullData.contains("friends")) {
601 for (const auto &friends : fullData["friends"].items()) {
602 std::string alias = friends.key();
603 std::vector<std::string> trees = friends.value()["trees"];
604 std::vector<std::string> files = friends.value()["files"];
605 if (files.size() != trees.size() && trees.size() > 1)
606 throw std::runtime_error("Mismatch between trees and files in a friend.");
607 spec.WithGlobalFriends(trees, files, alias);
608 }
609 }
610
611 if (fullData.contains("range")) {
612 std::vector<int> range = fullData["range"];
613
614 if (range.size() == 1)
615 spec.WithGlobalRange({range[0]});
616 else if (range.size() == 2)
617 spec.WithGlobalRange({range[0], range[1]});
618 }
619 return spec;
620};
621
622} // end NS RDF
623} // end NS Internal
624} // end NS ROOT
625
626std::string
628{
629 return df.GetTypeNameWithOpts(colName, vector2RVec);
630}
631
633{
634 return df.GetTopLevelFieldNames();
635}
636
638{
639 return df.GetColumnNamesNoDuplicates();
640}
641
647
649{
650 return ds.DescribeDataset();
651}
652
654 const ROOT::RDF::RDataSource &ds, unsigned int slot,
655 const std::unordered_map<std::string, ROOT::RDF::Experimental::RSample *> &sampleMap)
656{
657 return ds.CreateSampleInfo(slot, sampleMap);
658}
659
664
669
670std::unique_ptr<ROOT::Detail::RDF::RColumnReaderBase>
672 const std::type_info &tid, TTreeReader *treeReader)
673{
674 return ds.CreateColumnReader(slot, col, tid, treeReader);
675}
676
678{
679 return std::move(spec.fSamples);
680}
#define R__LOG_DEBUG(DEBUGLEVEL,...)
Definition RLogger.hxx:360
#define b(i)
Definition RSha256.hxx:100
#define c(i)
Definition RSha256.hxx:101
Basic types used by ROOT and required by TInterpreter.
bool Bool_t
Boolean (0=false, 1=true) (bool)
Definition RtypesCore.h:77
unsigned short UShort_t
Unsigned Short integer 2 bytes (unsigned short)
Definition RtypesCore.h:54
int Int_t
Signed integer 4 bytes (int)
Definition RtypesCore.h:59
unsigned char UChar_t
Unsigned Character 1 byte (unsigned char)
Definition RtypesCore.h:52
char Char_t
Character 1 byte (char)
Definition RtypesCore.h:51
unsigned long ULong_t
Unsigned long integer 4 bytes (unsigned long). Size depends on architecture.
Definition RtypesCore.h:69
long Long_t
Signed long integer 4 bytes (long). Size depends on architecture.
Definition RtypesCore.h:68
unsigned int UInt_t
Unsigned integer 4 bytes (unsigned int)
Definition RtypesCore.h:60
float Float_t
Float 4 bytes (float)
Definition RtypesCore.h:71
short Short_t
Signed Short integer 2 bytes (short)
Definition RtypesCore.h:53
double Double_t
Double 8 bytes.
Definition RtypesCore.h:73
long long Long64_t
Portable signed long integer 8 bytes.
Definition RtypesCore.h:83
unsigned long long ULong64_t
Portable unsigned long integer 8 bytes.
Definition RtypesCore.h:84
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
void Info(const char *location, const char *msgfmt,...)
Use this function for informational messages.
Definition TError.cxx:241
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:528
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:2974
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:4891
virtual TBranch * GetBranch(const char *name)
Return pointer to the branch with the given name in this tree or its friends.
Definition TTree.cxx:5431
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:6277
virtual TLeaf * FindLeaf(const char *name)
Find first leaf containing searchname.
Definition TTree.cxx:4966
ROOT::RLogChannel & RDFLogChannel()
Definition RDFUtils.cxx:42
void RunFinalChecks(const ROOT::RDF::RDataSource &ds, bool nodesLeftNotRun)
Definition RDFUtils.cxx:660
std::vector< std::string > ReplaceDotWithUnderscore(const std::vector< std::string > &columnNames)
Replace occurrences of '.
Definition RDFUtils.cxx:397
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:653
ROOT::RDF::Experimental::RDatasetSpec RetrieveSpecFromJson(const std::string &jsonFile)
Function to retrieve RDatasetSpec from JSON file provided.
Definition RDFUtils.cxx:545
unsigned int GetNSlots()
Definition RDFUtils.cxx:384
std::string ComposeRVecTypeName(const std::string &valueType)
Definition RDFUtils.cxx:223
void CallInitializeWithOpts(ROOT::RDF::RDataSource &ds, const std::set< std::string > &suppressErrorsForMissingColumns)
Definition RDFUtils.cxx:642
std::string GetLeafTypeName(TLeaf *leaf, const std::string &colName)
Definition RDFUtils.cxx:228
const std::vector< std::string > & GetTopLevelFieldNames(const ROOT::RDF::RDataSource &ds)
Definition RDFUtils.cxx:632
char TypeName2ROOTTypeName(const std::string &b)
Convert type name (e.g.
Definition RDFUtils.cxx:342
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:523
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:474
std::string GetBranchOrLeafTypeName(TTree &t, const std::string &colName)
Return the typename of object colName stored in t, if any.
Definition RDFUtils.cxx:255
std::string DescribeDataset(ROOT::RDF::RDataSource &ds)
Definition RDFUtils.cxx:648
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:671
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:312
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:428
void CheckReaderTypeMatches(const std::type_info &colType, const std::type_info &requestedType, const std::string &colName)
Definition RDFUtils.cxx:486
bool IsInternalColumn(std::string_view colName)
Whether custom column with name colName is an "internal" column such as rdfentry_ or rdfslot_.
Definition RDFUtils.cxx:465
std::vector< ROOT::RDF::Experimental::RSample > MoveOutSamples(ROOT::RDF::Experimental::RDatasetSpec &spec)
Definition RDFUtils.cxx:677
void ProcessMT(ROOT::RDF::RDataSource &ds, ROOT::Detail::RDF::RLoopManager &lm)
Definition RDFUtils.cxx:665
std::string GetTypeNameWithOpts(const ROOT::RDF::RDataSource &ds, std::string_view colName, bool vector2RVec)
Definition RDFUtils.cxx:627
void InterpreterDeclare(const std::string &code)
Declare code in the interpreter via the TInterpreter::Declare method, throw in case of errors.
Definition RDFUtils.cxx:416
const std::vector< std::string > & GetColumnNamesNoDuplicates(const ROOT::RDF::RDataSource &ds)
Definition RDFUtils.cxx:637
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:206
Namespace for new ROOT classes and functions.
Bool_t IsImplicitMTEnabled()
Returns true if the implicit multi-threading in ROOT is enabled.
Definition TROOT.cxx:600
UInt_t GetThreadPoolSize()
Returns the size of ROOT's thread pool.
Definition TROOT.cxx:607
@ 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