Logo ROOT   6.12/07
Reference Guide
TDataFrame.hxx
Go to the documentation of this file.
1 // Author: Enrico Guiraud, Danilo Piparo CERN 12/2016
2 
3 /*************************************************************************
4  * Copyright (C) 1995-2016, 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 /**
12  \defgroup dataframe DataFrame
13 ROOT's TDataFrame allows to analyse data stored in TTrees with a high level interface.
14 */
15 
16 #ifndef ROOT_TDATAFRAME
17 #define ROOT_TDATAFRAME
18 
19 #include "ROOT/TypeTraits.hxx"
20 #include "ROOT/TDataSource.hxx"
21 #include "ROOT/TDFInterface.hxx"
22 #include "ROOT/TDFNodes.hxx"
23 #include "ROOT/TDFUtils.hxx"
24 #include "TChain.h"
25 
26 #include <memory>
27 #include <iosfwd> // std::ostringstream
28 #include <stdexcept>
29 #include <string>
30 class TDirectory;
31 class TTree;
32 
33 namespace ROOT {
34 namespace Experimental {
35 namespace TDFDetail = ROOT::Detail::TDF;
37 namespace TTraits = ROOT::TypeTraits;
38 
39 class TDataFrame : public TDF::TInterface<TDFDetail::TLoopManager> {
40  using ColumnNames_t = TDFDetail::ColumnNames_t;
42 public:
43  TDataFrame(std::string_view treeName, std::string_view filenameglob, const ColumnNames_t &defaultBranches = {});
44  TDataFrame(std::string_view treename, const std::vector<std::string> &filenames,
45  const ColumnNames_t &defaultBranches = {});
46  TDataFrame(std::string_view treeName, ::TDirectory *dirPtr, const ColumnNames_t &defaultBranches = {});
47  TDataFrame(TTree &tree, const ColumnNames_t &defaultBranches = {});
48  TDataFrame(ULong64_t numEntries);
49  TDataFrame(std::unique_ptr<TDataSource>, const ColumnNames_t &defaultBranches = {});
50 };
51 
52 } // end NS Experimental
53 } // end NS ROOT
54 
55 ////////////////////////////////////////////////////////////////////////////////
56 /// Print a TDataFrame at the prompt:
57 namespace cling {
59 {
60  auto df = tdf->GetDataFrameChecked();
61  auto *tree = df->GetTree();
62  auto defBranches = df->GetDefaultColumnNames();
63 
64  std::ostringstream ret;
65  if (tree) {
66  ret << "A data frame built on top of the " << tree->GetName() << " dataset.";
67  if (!defBranches.empty()) {
68  if (defBranches.size() == 1)
69  ret << "\nDefault branch: " << defBranches[0];
70  else {
71  ret << "\nDefault branches:\n";
72  for (auto &&branch : defBranches) {
73  ret << " - " << branch << "\n";
74  }
75  }
76  }
77  } else {
78  ret << "A data frame that will create " << df->GetNEmptyEntries() << " entries\n";
79  }
80 
81  return ret.str();
82 }
83 } // namespace cling
84 
85 #endif // ROOT_TDATAFRAME
TDataFrame(std::string_view treeName, std::string_view filenameglob, const ColumnNames_t &defaultBranches={})
Build the dataframe.
Definition: TDataFrame.cxx:682
basic_string_view< char > string_view
Definition: RStringView.h:35
Namespace for new ROOT classes and functions.
Definition: StringConv.hxx:21
TDFDetail::ColumnNames_t ColumnNames_t
Definition: TDataFrame.hxx:40
TDataSource defines an API that TDataFrame can use to read arbitrary data formats.
Definition: TDataSource.hxx:51
std::shared_ptr< TLoopManager > GetDataFrameChecked()
Get the TLoopManager if reachable. If not, throw.
std::string printValue(ROOT::Experimental::TDataFrame *tdf)
Definition: TDataFrame.hxx:58
Describe directory structure in memory.
Definition: TDirectory.h:34
unsigned long long ULong64_t
Definition: RtypesCore.h:70
Print a TSeq at the prompt:
Definition: TDatime.h:115
ROOT type_traits extensions.
Definition: TypeTraits.hxx:23
Key/value store of objects.
Definition: TDirectory.hxx:70
ROOT&#39;s TDataFrame offers a high level interface for analyses of data stored in TTrees.
Definition: TDataFrame.hxx:39
Definition: tree.py:1
A TTree object has a header with a name and a title.
Definition: TTree.h:70
The public interface to the TDataFrame federation of classes.