CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
egammaGainSwitchFixTools.py
Go to the documentation of this file.
1 import FWCore.ParameterSet.Config as cms
2 
3 
4 def replaceInputTagModuleLabel(tag,names_dict):
5  if tag.getModuleLabel() in names_dict:
6  # print "replacing",tag.getModuleLabel(),"with ",names_dict[tag.getModuleLabel()]
7  tag.setModuleLabel(names_dict[tag.getModuleLabel()])
8 
9 def checkTag(tag,names_dict):
10  new_names=[names_dict[key] for key in names_dict]
11  if tag.getModuleLabel() in new_names and tag.getProcessName()!="@skipCurrentProcess":
12  return False
13  return True
14 
15 def replaceInputTags(process,modname,pset,names_dict):
16  for paraname in pset.parameterNames_():
17  para = pset.getParameter(paraname)
18  if para.pythonTypeName()=="cms.PSet":
19  replaceInputTags(process,modname,para,names_dict)
20  elif para.pythonTypeName()=="cms.VPSet":
21  for newpset in para:
22  replaceInputTags(process,modname,newpset,names_dict)
23  elif para.pythonTypeName()=="cms.InputTag":
24  if not checkTag(para,names_dict):
25  print "WARNING: {0}.{1} : {2} does not properly ignore the current process".format(modname,paraname,para.getModuleLabel())
26  replaceInputTagModuleLabel(para,names_dict)
27 
28  elif para.pythonTypeName()=="cms.VInputTag":
29  for tag in para:
30  if not checkTag(tag,names_dict):
31  print "WARNING: {0}.{1} does not properly ignore the current process".format(modname,paraname,tag.getModuleLabel())
32  if tag.getModuleLabel() in names_dict:
33  replaceInputTagModuleLabel(tag,names_dict)
34 
35 def replaceModulesInSeq(process,seq,names_dict):
36  for org_name in names_dict.keys():
37  seq.replace(getattr(process,org_name),getattr(process,names_dict[org_name]))
38 
39 
40 
41 def customiseForAODGainSwitchFix(process,newNameSuffex=""):
42  process.load("RecoEgamma.EgammaTools.egammaGainSwitchFix_cff")
43  names_dict = {"ecalMultiAndGSGlobalRecHitEB" : "reducedEcalRecHitsEB" + newNameSuffex,
44  "particleFlowRecHitECALGSFixed" : "particleFlowRecHitECAL" + newNameSuffex,
45  "particleFlowRecHitPSGSFixed" : "particleFlowRecHitPS" + newNameSuffex,
46  "particleFlowClusterPSGSFixed" : "particleFlowClusterPS" + newNameSuffex,
47  "particleFlowClusterECALUncorrectedGSFixed" : "particleFlowClusterECALUncorrected" + newNameSuffex,
48  "particleFlowClusterECALGSFixed" : "particleFlowClusterECAL" + newNameSuffex,
49  "particleFlowSuperClusterECALGSFixed" : "particleFlowSuperClusterECAL" + newNameSuffex,
50  "gsFixedRefinedSuperClusters" : "particleFlowEGamma" + newNameSuffex,
51  "gsFixedGsfElectronCores" : "gedGsfElectronCores" + newNameSuffex,
52  "gsFixedGsfElectrons" : "gedGsfElectrons" + newNameSuffex,
53  "gsFixedGedPhotonCores" : "gedPhotonCore" + newNameSuffex,
54  "gsFixedGedPhotons" : "gedPhotons" + newNameSuffex}
55 
56 
57 
58 
59  for org_name in names_dict.keys():
60  setattr(process,names_dict[org_name],getattr(process,org_name).clone())
61 
62 
63  for seqname in process.sequences:
64  seq = getattr(process,seqname)
65  replaceModulesInSeq(process,seq,names_dict)
66 
67  mods_done=[] #keeps track of which modules we have done
68  #useful as module might be in multiple paths
69  for pathname in process.pathNames() :
70  try:
71  path = getattr(process,pathname)
72  for modulename in path.moduleNames():
73  if modulename not in mods_done:
74  mod = getattr(process,modulename)
75  replaceInputTags(process,modulename,mod,names_dict)
76  mods_done.append(modulename)
77  except AttributeError:
78  pass
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)
Definition: eve_macros.cc:135