3In the same way
as for TDirectory, it is possible to get the content of
a
4TFile object with the familiar item-getting syntax.
5For more information, please refer to the
TDirectory documentation.
7In addition,
TFile instances can be inspected via the `Get` method,
a feature
8that is inherited from
TDirectoryFile (please see the documentation of
11In order to write objects into
a TFile, the `WriteObject` Python method can
15behave in
a more pythonic way. In particular, they both
throw an `OSError`
if
16there was
a problem accessing the file (
e.g. non-existent or corrupted file).
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
24with
TFile(
"file1.root",
"recreate") as outfile:
26 outfile.WriteObject(hout, "myhisto")
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
31(but they will be stored in the file if they were written to it).
ROOT objects
32like histograms can be detached from
a file with the SetDirectory method. This
33will leave the
object untouched so that it can be accessed after the end of the
38with
TFile(
"file1.root",
"read") as infile:
39 hin = infile.Get("myhisto")
40 hin.SetDirectory(
ROOT.
nullptr)
42# Use the histogram afterwards
46\note The
TFile::Close method automatically sets the current directory in
47the program to the
gROOT object. If you want to restore the status of the
48current directory to some other file that was opened prior to the `with`
49statement, you can use the context manager functionality offered by TContext.
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void on
A ROOT file is structured in Directories (like a file system).
Describe directory structure in memory.
A ROOT file is an on-disk file, usually with extension .root, that stores objects in a file-system-li...
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.
void Close(Option_t *option="") override
Close a file.
1-D histogram with a float per channel (see TH1 documentation)
constexpr std::array< decltype(std::declval< F >()(std::declval< int >())), N > make(F f)
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...