ATLAS Offline Software
SwitchComponentName.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2017 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) < 5:
14  print "Too few arguments. Expected the following:"
15  print " 1. Input file"
16  print " 2. Output file"
17  print " 3. Original name of component"
18  print " 4. New name of component"
19  exit(1)
20 
21 inputFile = TFile.Open(sys.argv[1],"READ")
22 outputFile = TFile.Open(sys.argv[2],"RECREATE")
23 compName = sys.argv[3]
24 newName = sys.argv[4]
25 
26 for histName in inputFile.GetKeyNames():
27  hist = inputFile.Get(histName)
28  if TString(histName).Contains(compName):
29  newHistName = re.sub(compName,newName,histName)
30  print "Renaming component: %s --> %s"%(histName,newHistName)
31  outputFile.cd()
32  hist.Write(newHistName)
33  continue
34  else:
35  outputFile.cd()
36  hist.Write(histName)
37 
38 outputFile.Close()
39 inputFile.Close()
40 
SwitchComponentName.GetKeyNames
def GetKeyNames(self, dir="")
Definition: SwitchComponentName.py:7
calibdata.exit
exit
Definition: calibdata.py:236