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