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>
20
21#include <TFile.h>
22#include <TROOT.h>
23#include <TSystem.h>
24
25// Import classes from experimental namespace for the time being.
26using RNTuple = ROOT::Experimental::RNTuple;
27using RNTupleImporter = ROOT::Experimental::RNTupleImporter;
28using RNTupleReader = ROOT::Experimental::RNTupleReader;
29
30// Input and output.
31constexpr char const *kTreeFileName = "http://root.cern.ch/files/HiggsTauTauReduced/GluGluToHToTauTau.root";
32constexpr char const *kTreeName = "Events";
33constexpr char const *kNTupleFileName = "ntpl008_import.root";
34
35void ntpl008_import()
36{
37 // RNTupleImporter appends keys to the output file; make sure a second run of the tutorial does not fail
38 // with `Key 'Events' already exists in file ntpl008_import.root` by removing the output file.
39 gSystem->Unlink(kNTupleFileName);
40
41 // Use multiple threads to compress RNTuple data.
43
44 // Create a new RNTupleImporter object.
45 auto importer = RNTupleImporter::Create(kTreeFileName, kTreeName, kNTupleFileName);
46
47 // Begin importing.
48 importer->Import();
49
50 // Inspect the schema of the written RNTuple.
51 auto file = std::unique_ptr<TFile>(TFile::Open(kNTupleFileName));
52 if (!file || file->IsZombie()) {
53 std::cerr << "cannot open " << kNTupleFileName << std::endl;
54 return;
55 }
56 auto ntpl = file->Get<RNTuple>("Events");
57 auto reader = RNTupleReader::Open(ntpl);
58 reader->PrintInfo();
59
60 ROOT::RDataFrame df("Events", kNTupleFileName);
61 df.Histo1D({"Jet_pt", "Jet_pt", 100, 0, 0}, "Jet_pt")->DrawCopy();
62}
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