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