ATLAS Offline Software
ExtractComponent.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
2 
3 import sys
4 import re
5 from ROOT import *
6 
7 def GetKeyNames(self,dir=""):
8  self.cd(dir)
9  return [key.GetName() for key in gDirectory.GetListOfKeys()]
10 TFile.GetKeyNames = GetKeyNames
11 
12 
13 if len(sys.argv) < 4:
14  print "Too few arguments. Expected the following:"
15  print " 1. Input file"
16  print " 2. Output file"
17  print " 3+ Name(s) of components to extract"
18  exit(1)
19 
20 inputFile = TFile.Open(sys.argv[1],"READ")
21 outputFile = TFile.Open(sys.argv[2],"RECREATE")
22 compNames = sys.argv[3:]
23 
24 # Check that the request is possible
25 for compName in compNames:
26  if compName not in inputFile.GetKeyNames():
27  print "Unable to continue - input file does not contain the requested component:",compName
28  exit(2)
29 
30 # Now do what the user asked
31 for compName in compNames:
32  hist = inputFile.Get(compName)
33  outputFile.cd()
34  hist.Write(compName)
35 
36 outputFile.Close()
37 inputFile.Close()
38 
ExtractComponent.GetKeyNames
def GetKeyNames(self, dir="")
Definition: ExtractComponent.py:7
calibdata.exit
exit
Definition: calibdata.py:236