Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
ntpl008_import.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_ntuple
3/// \notebook
4/// Example of converting data stored in a TTree into an RNTuple
5///
6/// \macro_image
7/// \macro_code
8///
9/// \date December 2022
10/// \author The ROOT Team
11
12// NOTE: The RNTuple classes are experimental at this point.
13// Functionality, interface, and data format is still subject to changes.
14// Do not use for real data!
15
16#include <ROOT/RNTupleDS.hxx>
19
20#include <TFile.h>
21#include <TROOT.h>
22
23// Import classes from experimental namespace for the time being.
24using RNTuple = ROOT::Experimental::RNTuple;
25using RNTupleImporter = ROOT::Experimental::RNTupleImporter;
26using RNTupleReader = ROOT::Experimental::RNTupleReader;
27
28// Input and output.
29constexpr char const *kTreeFileName = "http://root.cern.ch/files/HiggsTauTauReduced/GluGluToHToTauTau.root";
30constexpr char const *kTreeName = "Events";
31constexpr char const *kNTupleFileName = "ntpl008_import.root";
32
33void ntpl008_import()
34{
35 // RNTupleImporter appends keys to the output file; make sure a second run of the tutorial does not fail
36 // with `Key 'Events' already exists in file ntpl008_import.root` by removing the output file.
37 gSystem->Unlink(kNTupleFileName);
38
39 // Use multiple threads to compress RNTuple data.
41
42 // Create a new RNTupleImporter object.
43 auto importer = RNTupleImporter::Create(kTreeFileName, kTreeName, kNTupleFileName);
44
45 // Begin importing.
46 importer->Import();
47
48 // Inspect the schema of the written RNTuple.
49 auto file = std::unique_ptr<TFile>(TFile::Open(kNTupleFileName));
50 if (!file || file->IsZombie()) {
51 std::cerr << "cannot open " << kNTupleFileName << std::endl;
52 return;
53 }
54 auto ntpl = file->Get<RNTuple>("Events");
55 auto reader = RNTupleReader::Open(ntpl);
56 reader->PrintInfo();
57
58 ROOT::RDataFrame df("Events", kNTupleFileName);
59 df.Histo1D({"Jet_pt", "Jet_pt", 100, 0, 0}, "Jet_pt")->DrawCopy();
60}
R__EXTERN TSystem * gSystem
Definition TSystem.h:555
Converts a TTree into an RNTuple.
An RNTuple that is used to read data from storage.
Representation of an RNTuple data set in a ROOT file.
Definition RNTuple.hxx:61
ROOT's RDataFrame offers a modern, high-level interface for analysis of data stored in TTree ,...
static TFile * Open(const char *name, Option_t *option="", const char *ftitle="", Int_t compress=ROOT::RCompressionSetting::EDefaults::kUseCompiledDefault, Int_t netopt=0)
Create / open a file.
Definition TFile.cxx:4089
virtual int Unlink(const char *name)
Unlink, i.e.
Definition TSystem.cxx:1381
void EnableImplicitMT(UInt_t numthreads=0)
Enable ROOT's implicit multi-threading for all objects and methods that provide an internal paralleli...
Definition TROOT.cxx:539