CMS 3D CMS Logo

tfile.py
Go to the documentation of this file.
1 from PhysicsTools.HeppyCore.framework.services.service import Service
2 from ROOT import TFile
3 
4 class TFileService(Service):
5  """TFile service.
6  The file attribute is a TFile that can be used in several analyzers.
7  The file is closed when the service stops.
8 
9  Example configuration:
10 
11  output_rootfile = cfg.Service(
12  TFileService,
13  'myhists',
14  fname='histograms.root',
15  option='recreate'
16  )
17  """
18  def __init__(self, cfg, comp, outdir):
19  """
20  cfg must contain:
21  - fname: file name
22  - option: TFile options, e.g. recreate
23 
24  outdir is the output directory for the TFile
25 
26  comp is a dummy parameter here.
27  It is needed because the looper creates services and analyzers
28  in the same way, providing the configuration (cfg),
29  the component currently processed (comp),
30  and the output directory.
31 
32  Other implementations of the TFileService could
33  make use of the component information, eg. the component name.
34  """
35  fname = '/'.join([outdir, cfg.fname])
36  self.file = TFile(fname, cfg.option)
37 
38  def stop(self):
39  self.file.Write()
40  self.file.Close()
41 
def __init__(self, cfg, comp, outdir)
Definition: tfile.py:18
static std::string join(char **cmd)
Definition: RemoteFile.cc:19
def stop(self)
Definition: tfile.py:38