CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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  '''
19  def __init__(self, cfg, comp, outdir):
20  fname = '/'.join([outdir, cfg.fname])
21  self.file = TFile(fname, cfg.option)
22 
23  def stop(self):
24  self.file.Write()
25  self.file.Close()
26 
27 if __name__ == '__main__':
28  fileservice = TFileService('test.root', 'recreate')
29  fileservice.start()
30  fileservice.stop()
static std::string join(char **cmd)
Definition: RemoteFile.cc:18