Skip to content

Commit dd4fcff

Browse files
committed
Some touches to the TFile documentation in the Manual
1 parent d496e13 commit dd4fcff

1 file changed

Lines changed: 27 additions & 9 deletions

File tree

manual/root_files/index.md

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,30 +7,33 @@ toc: true
77
toc_sticky: true
88
---
99

10-
ROOT files contain C++ objects that are stored to disk.
11-
You can open files when starting ROOT
10+
ROOT files contain data, for example in the form of objects that are instances of C++ classes, and executable code, for example through `TExec`, `TMacro`, and `TFormula` instances.
11+
12+
> As for *all* files, do not open ROOT files from an unknown origin!
13+
14+
You can open files when starting ROOT, specifying those as commandline arguments
1215

1316
{% highlight bash %}
1417
$ root file.root
1518
{% endhighlight %}
1619

17-
or within C++
20+
or via the C++ API
1821

1922
{% highlight C++ %}
2023
std::unique_ptr<TFile> myFile( TFile::Open("file.root") );
2124
{% endhighlight %}
2225

23-
or Python code
26+
or in Python
2427

2528
{% highlight Python %}
2629
myFile = ROOT.TFile.Open("file.root")
2730
{% endhighlight %}
2831

2932

30-
In ROOT you can save objects in ROOT files, making these objects "persistent".
33+
Objects can be written in ROOT files, making these objects "persistent".
3134
Later on, you can read these objects back: the object is reconstructed in memory.
3235

33-
ROOT files often contain columnar data, used for instance by all LHC (Large Hadron Collider) experiments.
36+
Not only individual objects can be written, in a so-called "row-wise fashion". ROOT files can contain also columnar data, used for instance by many High Energy Physics Experiments, at LHC and elsewhere. At the end of LHC Run 3, *Exabytes* of data were written in ROOT's columnar format!
3437

3538
## Storing an object in a ROOT file and reading it back
3639

@@ -57,7 +60,7 @@ For the second argument, the following options are available:
5760
### Storing an object in a ROOT file
5861

5962
You can save any object, for instance canvases or histograms, into a ROOT file.
60-
You can even store your own types.
63+
You can even store your own types, provided that you expose to ROOT the information necessary for their serialization.
6164

6265
<!-- For more information, see the → [I/O]({{ '/manual/io' | relative_url }}) section of the manual. -->
6366

@@ -78,7 +81,7 @@ myFile.WriteObject(myObject, "MyObject")
7881
### Closing a ROOT file
7982

8083
ROOT will automatically save and close any ROOT files still open when the session ends.
81-
The ROOT file is also saved and closed when deleting / destructing the `TFile` object.
84+
The ROOT file is also saved and closed when deleting, or more in general destructing, the `TFile` object.
8285

8386
{% highlight C++ %}
8487
void closeAtDestruct(TH1 *hist) {
@@ -102,10 +105,13 @@ def closeAtDestruct(hist):
102105

103106
### Opening and inspecting a ROOT file
104107

108+
ROOT is not needed to inspect ROOT files! For example, those can be opened in your web browser with [JSRoot](https://root.cern/js/latest/){:target="_blank"}: no single C++ line is executed, pure JavaScript code provides all the functionality needed.
109+
110+
Of course, ROOT files can be opened and inspected with ROOT's C++ and Python APIs.
105111
Use [TFile::Open()](https://root.cern/doc/master/classTFile.html#ad8870806a04da2c2f4aa02bee4ec6833){:target="_blank"} to open a ROOT file.
106112
While this operation might return a valid pointer to a `TFile` object,
107113
this object might not be able to access data, for instance because ROOT was unable to open the file in the filesystem.
108-
Use [TObject::IsZombie()](https://root.cern/doc/master/classTObject.html#aaa8418b9b6692a12d8d0e500c51911bf){:target="_blank"} to check whether the ROOT file was successfully opened.
114+
You can use [TObject::IsZombie()](https://root.cern/doc/master/classTObject.html#aaa8418b9b6692a12d8d0e500c51911bf){:target="_blank"} to check whether the ROOT file was successfully opened.
109115

110116
{% highlight C++ %}
111117
std::unique_ptr<TFile> file( TFile::Open("file.root") );
@@ -137,6 +143,14 @@ See also → [Object ownership]({{ '/manual/object_ownership' | relative_url }})
137143

138144
For the particular case of TTree, cycles only store metadata, see [Baskets, clusters and the tree header]({{ '/manual/trees/#baskets-clusters-and-the-tree-header' | relative_url }}).
139145

146+
Something a bit advanced now. The information ROOT relies on for serializing objects is stored in `TStreamerInfo` instances, which are stored themselves in the ROOT file. This feature offers several advantages, for example it can make the ROOT file and its content self descriptive.
147+
If you want to have a look to the list of `TStreamerInfo` instances in a file, you can use the following API:
148+
{% highlight C++ %}
149+
root [] std::unique_ptr<TFile> myFile( TFile::Open("file.root") );
150+
...
151+
root [] myFile->GetStreamerInfoList()->Print();
152+
{% endhighlight %}
153+
140154
### Reading an object from a ROOT file
141155

142156
In C++, use the `Get<T>()` method to retrieve the objects from a ROOT file.<br>
@@ -280,6 +294,10 @@ Double-click the ROOT file to inspect its content.
280294
Double-clicking graphical objects displays them in a canvas tab.
281295
Double-clicking files that end with `.C` displays them in an editor tab.
282296

297+
> Clicking on objects in a `TBrowser` (or `RBrowser`) instance can lead to the execution of code.
298+
> For example, a `TCanvas` instance may rely on `TExec` instances to obtain certain effects, a histogram or a graph may do the same with the `TExec` instances stored in their *list of functions*. The `TFormula` powering function classes such as `TF1` or its multidimensional counterparts, also executes jitted C++ code to obtain maximum runtime performance.
299+
> As explained above, as for *all* files, do not open ROOT files from an unknown origin!
300+
283301
## Accessing a remote ROOT file
284302

285303
You can read and write a remote ROOT file by specifying its URL to [TFile::Open()](https://root.cern/doc/master/classTFile.html#aec5f3fae0774aabfc615ebb4b00fe5e0){:target="_blank"}.

0 commit comments

Comments
 (0)