Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
_tfile.pyzdoc
Go to the documentation of this file.
2
6
10
11In order to write objects into a TFile, the `WriteObject` Python method can
13
17
18This class can also be used as a context manager, with the goal of opening a
19file and doing some quick manipulations of the objects inside it. The
20TFile::Close method will be automatically called at the end of the context. For
22\code{.py}
23from ROOT import TFile
24with TFile("file1.root", "recreate") as outfile:
25 hout = ROOT.TH1F(...)
26 outfile.WriteObject(hout, "myhisto")
28
29Since the file is closed at the end of the context, all objects created or read
30from the file inside the context are not accessible anymore in the application
32like histograms can be detached from a file with the SetDirectory method. This
34context:
35\code{.py}
36import ROOT
37from ROOT import TFile
38with TFile("file1.root", "read") as infile:
39 hin = infile.Get("myhisto")
40 hin.SetDirectory(ROOT.nullptr)
41
43print(hin.GetName())
45
46\note The TFile::Close method automatically sets the current directory in
48current directory to some other file that was opened prior to the `with`
50
#define a(i)
Definition RSha256.hxx:99
#define e(i)
Definition RSha256.hxx:103
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void on
#define gROOT
Definition TROOT.h:411
A ROOT file is structured in Directories (like a file system).
Describe directory structure in memory.
Definition TDirectory.h:45
A ROOT file is an on-disk file, usually with extension .root, that stores objects in a file-system-li...
Definition TFile.h:131
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:3764
1-D histogram with a float per channel (see TH1 documentation)
Definition TH1.h:878
constexpr std::array< decltype(std::declval< F >()(std::declval< int >())), N > make(F f)
CoordSystem::Scalar get(DisplacementVector2D< CoordSystem, Tag > const &p)
TString as(SEXP s)
Definition RExports.h:86