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 RNTupleImporter class is experimental at this point.
13// Functionality and interface are still subject to changes.
14
15#include <ROOT/RNTupleDS.hxx>
19
20#include <TFile.h>
21#include <TROOT.h>
22#include <TSystem.h>
23
24// Import classes from experimental namespace for the time being.
25using RNTupleImporter = ROOT::Experimental::RNTupleImporter;
26
27// Input and output.
28constexpr char const *kTreeFileName = "http://root.cern.ch/files/HiggsTauTauReduced/GluGluToHToTauTau.root";
29constexpr char const *kTreeName = "Events";
30constexpr char const *kNTupleFileName = "ntpl008_import.root";
31
32void ntpl008_import()
33{
34 // RNTupleImporter appends keys to the output file; make sure a second run of the tutorial does not fail
35 // with `Key 'Events' already exists in file ntpl008_import.root` by removing the output file.
37
38 // Use multiple threads to compress RNTuple data.
40
41 // Create a new RNTupleImporter object.
42 auto importer = RNTupleImporter::Create(kTreeFileName, kTreeName, kNTupleFileName);
43
44 // Begin importing.
45 importer->Import();
46
47 // Inspect the schema of the written RNTuple.
48 auto file = std::unique_ptr<TFile>(TFile::Open(kNTupleFileName));
49 if (!file || file->IsZombie()) {
50 std::cerr << "cannot open " << kNTupleFileName << std::endl;
51 return;
52 }
53 auto ntpl = std::unique_ptr<ROOT::RNTuple>(file->Get<ROOT::RNTuple>("Events"));
55 reader->PrintInfo();
56
58 df.Histo1D({"Jet_pt", "Jet_pt", 100, 0, 0}, "Jet_pt")->DrawCopy();
59}
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
R__EXTERN TSystem * gSystem
Definition TSystem.h:572
Converts a TTree into an RNTuple.
ROOT's RDataFrame offers a modern, high-level interface for analysis of data stored in TTree ,...
static std::unique_ptr< RNTupleReader > Open(std::string_view ntupleName, std::string_view storage, const ROOT::RNTupleReadOptions &options=ROOT::RNTupleReadOptions())
Open an RNTuple for reading.
Representation of an RNTuple data set in a ROOT file.
Definition RNTuple.hxx:65
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:4131
virtual int Unlink(const char *name)
Unlink, i.e.
Definition TSystem.cxx:1393
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