User Tools

Site Tools


root:pyroot_tfile

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Last revisionBoth sides next revision
root:pyroot_tfile [2017/06/13 09:39] iwnroot:pyroot_tfile [2017/09/05 10:35] – [Handling TFile files] iwn
Line 1: Line 1:
-===== Handling TFiles =====+[[root:root|Getting started with ROOT]] -> [[root:pyroot|Useful pyROOT snippets]] → [[root:pyroot_tfile|Handling TFile files]]
  
-==== Adding a directory to a TFile ====+====== Handling TFile files ====== 
 + 
 +Class references for: 
 +  * ''[[https://root.cern.ch/doc/master/classTFile.html|TDirectory]]'', 
 +  * ''[[https://root.cern.ch/doc/master/classTFile.html|TFile]]''
 + 
 +===== Adding a directory to a TFile =====
  
 Here is a basic example creating a file with on directory. If you want to create and save an object in this directory, e.g. a tree or histogram, use ''dir.cd()''. Pay attention to the order of creating an object, changing directory (''cd()'') and writing the object! Here is a basic example creating a file with on directory. If you want to create and save an object in this directory, e.g. a tree or histogram, use ''dir.cd()''. Pay attention to the order of creating an object, changing directory (''cd()'') and writing the object!
Line 26: Line 32:
  
  
-==== gDirectory ====+===== gDirectory =====
  
-Note that ''gDirectory'' is the current directory containing all newly created saved objects, or those saved to this directory. If you just opened a file, this will be your current directory until you close it or use ''cd()''. Test the behavior:+Note that ''gDirectory'' is the current directory containing all newly created saved objects, or those saved to this directory. If you just opened a file, this will be your current directory until you close it or use ''cd()'' on some ''TDirectory'' or other ''TFile''. Test the behavior with this macro:
  
 <file python gDirectory.py> <file python gDirectory.py>
Line 44: Line 50:
 printGDirectory() printGDirectory()
  
-print ">>> creating some file with some contents"+print ">>> creating file with some contents"
 file = TFile("test.root","recreate") file = TFile("test.root","recreate")
 tree = TTree("tree","tree") tree = TTree("tree","tree")
Line 63: Line 69:
 printGDirectory() printGDirectory()
 </file> </file>
- 
  
root/pyroot_tfile.txt · Last modified: 2017/09/05 10:37 by iwn