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