Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
ntpl008_import.C File Reference

Detailed Description

View in nbviewer Open in SWAN
Example of converting data stored in a TTree into an RNTuple

// NOTE: The RNTuple classes are experimental at this point.
// Functionality, interface, and data format is still subject to changes.
// Do not use for real data!
#include <TFile.h>
#include <TROOT.h>
// Import classes from experimental namespace for the time being.
using RNTupleImporter = ROOT::Experimental::RNTupleImporter;
using RNTupleReader = ROOT::Experimental::RNTupleReader;
// Input and output.
constexpr char const *kTreeFileName = "http://root.cern.ch/files/HiggsTauTauReduced/GluGluToHToTauTau.root";
constexpr char const *kTreeName = "Events";
constexpr char const *kNTupleFileName = "ntpl008_import.root";
void ntpl008_import()
{
// RNTupleImporter appends keys to the output file; make sure a second run of the tutorial does not fail
// with `Key 'Events' already exists in file ntpl008_import.root` by removing the output file.
gSystem->Unlink(kNTupleFileName);
// Use multiple threads to compress RNTuple data.
// Create a new RNTupleImporter object.
auto importer = RNTupleImporter::Create(kTreeFileName, kTreeName, kNTupleFileName);
// Begin importing.
importer->Import();
// Inspect the schema of the written RNTuple.
auto file = std::unique_ptr<TFile>(TFile::Open(kNTupleFileName));
if (!file || file->IsZombie()) {
std::cerr << "cannot open " << kNTupleFileName << std::endl;
return;
}
auto ntpl = file->Get<RNTuple>("Events");
auto reader = RNTupleReader::Open(ntpl);
reader->PrintInfo();
ROOT::RDataFrame df("Events", kNTupleFileName);
df.Histo1D({"Jet_pt", "Jet_pt", 100, 0, 0}, "Jet_pt")->DrawCopy();
}
R__EXTERN TSystem * gSystem
Definition TSystem.h:560
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:4070
virtual int Unlink(const char *name)
Unlink, i.e.
Definition TSystem.cxx:1369
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:537
Date
December 2022
Author
The ROOT Team

Definition in file ntpl008_import.C.