CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Namespaces | Classes | Functions | Variables
Utilities Namespace Reference

Namespaces

 ReleaseScripts
 

Classes

class  InputTagLabelSet
 
class  TestModuleCommand
 

Functions

def _build_options
 
def cleanUnscheduled
 
def convertToUnscheduled
 
def getHltConfiguration
 
def ignoreAllFiltersOnPath
 
def loadHltConfiguration
 
def removeModulesNotOnAPathExcluding
 
def traverseInputTags
 

Variables

 __lastCallUnary
 

Function Documentation

def Utilities._build_options (   args)
private

Definition at line 6 of file Utilities.py.

Referenced by getHltConfiguration(), and loadHltConfiguration().

6 
7 def _build_options(**args):
8  options = _options.HLTProcessOptions()
9  for key, val in args.iteritems():
10  setattr(options, key, val)
11  return options
12 
def _build_options
Definition: Utilities.py:6
def Utilities.cleanUnscheduled (   proc)

Definition at line 130 of file Utilities.py.

References cmsPerfStripChart.dict.

Referenced by convertToUnscheduled().

131 def cleanUnscheduled(proc):
132  import FWCore.ParameterSet.Config as cms
133  l = dict(proc.paths)
134  l.update( dict(proc.endpaths) )
135  droppedPaths =[]
136  #have to get them now since switching them after the
137  # paths have been changed gives null labels
138  if proc.schedule:
139  pathNamesInScheduled = [p.label_() for p in proc.schedule]
140  else:
141  pathNamesInScheduled = False
142 
143  def getUnqualifiedName(name):
144  if name[0] in set(['!','-']):
145  return name[1:]
146  return name
147 
148  def getQualifiedModule(name,proc):
149  unqual_name = getUnqualifiedName(name)
150  p=getattr(proc,unqual_name)
151  if unqual_name != name:
152  if name[0] == '!':
153  p = ~p
154  elif name[0] == '-':
155  p = cms.ignore(p)
156  return p
157 
158  # Loop over paths
159  # On each path we drop EDProducers except we
160  # keep the EDProducers that depend on EDFilters
161  for pName,p in l.iteritems():
162  qualified_names = []
163  v = cms.DecoratedNodeNameVisitor(qualified_names)
164  p.visit(v)
165  remaining =[]
166 
167  for n in qualified_names:
168  unqual_name = getUnqualifiedName(n)
169  #remove EDProducer's and EDFilter's which are set to ignore
170  if not (isinstance(getattr(proc,unqual_name), cms.EDProducer) or
171  (n[0] =='-' and isinstance(getattr(proc,unqual_name), cms.EDFilter)) ):
172  remaining.append(n)
173 
174  if remaining:
175  p = getQualifiedModule(remaining[0],proc)
176  for m in remaining[1:]:
177  p+=getQualifiedModule(m,proc)
178  setattr(proc,pName,type(getattr(proc,pName))(p))
179  # drop empty paths
180  else:
181  setattr(proc,pName,type(getattr(proc,pName))())
182 
183  # If there is a schedule then it needs to point at
184  # the new Path objects
185  if proc.schedule:
186  proc.schedule = cms.Schedule([getattr(proc,p) for p in pathNamesInScheduled])
187  return proc
def cleanUnscheduled
Definition: Utilities.py:130
def Utilities.convertToUnscheduled (   proc)

Definition at line 92 of file Utilities.py.

References cleanUnscheduled().

Referenced by Utilities.TestModuleCommand.testNoSchedule(), and Utilities.TestModuleCommand.testWithSchedule().

92 
93 def convertToUnscheduled(proc):
94  import FWCore.ParameterSet.Config as cms
95  """Given a 'Process', convert the python configuration from scheduled execution to unscheduled. This is done by
96  1. Removing all modules not on Paths or EndPaths
97  2. Pulling EDProducers not dependent on EDFilters off of all Paths
98  3. Dropping any Paths which are now empty
99  4. Fixing up the Schedule if needed
100  """
101  # Warning: It is not always possible to convert a configuration
102  # where EDProducers are all run on Paths to an unscheduled
103  # configuration by modifying only the python configuration.
104  # There is more than one kind of pathological condition
105  # that can cause this conversion to produce a configuration
106  # that gives different results than the original configuration
107  # when run under cmsRun. One should view the converted configuration
108  # as a thing which needs to be validated. It is possible for there
109  # to be pathologies that cannot be resolved by modifying only the
110  # python configuration and may require redesign inside the C++ code
111  # of the modules and redesign of the logic. For example,
112  # an EDAnalyzer might try to get a product and check if the
113  # returned handle isValid. Then it could behave differently
114  # depending on whether or not the product was present.
115  # The behavior when the product is not present could
116  # be meaningful and important. In the unscheduled case,
117  # the EDProducer will always run and the product could
118  # always be there.
119 
120  # Remove all modules not on Paths or EndPaths
121  proc.prune()
122 
123  # Turn on unschedule mode
124  if not hasattr(proc,'options'):
125  proc.options = cms.untracked.PSet()
126  proc.options.allowUnscheduled = cms.untracked.bool(True)
127 
128  proc=cleanUnscheduled(proc)
129  return proc
def convertToUnscheduled
Definition: Utilities.py:92
def cleanUnscheduled
Definition: Utilities.py:130
def Utilities.getHltConfiguration (   menu,
  args 
)

Definition at line 13 of file Utilities.py.

References _build_options(), and visualization-live-secondInstance_cfg.dump.

13 
14 def getHltConfiguration(menu, **args):
15  args['menu'] = menu
16  args['fragment'] = False
17  options = _build_options(**args)
18 
19  hlt = _imp.new_module('hlt')
20  exec(_confdb.HLTProcess(options).dump(), globals(), hlt.__dict__)
21  return hlt.process
22 
def getHltConfiguration
Definition: Utilities.py:13
def _build_options
Definition: Utilities.py:6
def Utilities.ignoreAllFiltersOnPath (   path)
Given a 'Path', find all EDFilters and wrap them in 'cms.ignore'

Definition at line 69 of file Utilities.py.

69 
70 def ignoreAllFiltersOnPath(path):
71  """Given a 'Path', find all EDFilters and wrap them in 'cms.ignore'
72  """
73  import FWCore.ParameterSet.Config as cms
74  from FWCore.ParameterSet.SequenceTypes import _MutatingSequenceVisitor, _UnarySequenceOperator
75 
76  class IgnoreFilters(object):
77  def __init__(self):
78  self.__lastCallUnary = False
79  def __call__(self, obj):
80  if isinstance(obj,_UnarySequenceOperator):
81  self.__lastCallUnary = True
82  elif obj.isLeaf() and isinstance(obj, cms.EDFilter) and not self.__lastCallUnary:
83  return cms.ignore(obj)
84  else:
85  self.__lastCallUnary = False
86  return obj
87 
88  mutator = _MutatingSequenceVisitor(IgnoreFilters())
89  path.visit(mutator)
90  path._seq = mutator.result()
91  return path
def ignoreAllFiltersOnPath
Definition: Utilities.py:69
def Utilities.loadHltConfiguration (   process,
  menu,
  args 
)

Definition at line 23 of file Utilities.py.

References _build_options(), and visualization-live-secondInstance_cfg.dump.

23 
24 def loadHltConfiguration(process, menu, **args):
25  args['menu'] = menu
26  args['fragment'] = True
27  options = _build_options(**args)
28 
29  hlt = _imp.new_module('hlt')
30  exec(_confdb.HLTProcess(options).dump(), globals(), hlt.__dict__)
31  process.extend( hlt )
32 
def _build_options
Definition: Utilities.py:6
def loadHltConfiguration
Definition: Utilities.py:23
def Utilities.removeModulesNotOnAPathExcluding (   process,
  keepList = () 
)
Given a 'process', find all modules (EDProducers,EDFilters,EDAnalyzers,OutputModules)
and remove them if they do not appear on a Path or EndPath.  One can optionally pass in
a list of modules which even if they are not on a Path or EndPath you wish to have stay 
in the configuration [useful for unscheduled execution].

Definition at line 1 of file Utilities.py.

Referenced by Utilities.TestModuleCommand.testConfig().

1 def removeModulesNotOnAPathExcluding( process, keepList=() ):
2  """Given a 'process', find all modules (EDProducers,EDFilters,EDAnalyzers,OutputModules)
3  and remove them if they do not appear on a Path or EndPath. One can optionally pass in
4  a list of modules which even if they are not on a Path or EndPath you wish to have stay
5  in the configuration [useful for unscheduled execution].
6  """
7  allMods=set((x for x in process.producers_().iterkeys()))
8  allMods.update((x for x in process.filters_().iterkeys()))
9  allMods.update((x for x in process.analyzers_().iterkeys()))
10  allMods.update((x for x in process.outputModules_().iterkeys()))
11 
12  modulesOnPaths = set()
13  for p in process.paths_():
14  modulesOnPaths.update( (x for x in getattr(process,p).moduleNames()))
15  for p in process.endpaths_():
16  modulesOnPaths.update( (x for x in getattr(process,p).moduleNames()))
17 
18  notOnPaths = allMods.difference(modulesOnPaths)
19 
20  keepModuleNames = set( (x.label_() for x in keepList) )
21 
22  getRidOf = notOnPaths.difference(keepModuleNames)
23 
24  for n in getRidOf:
25  delattr(process,n)
26 
def removeModulesNotOnAPathExcluding
Definition: Utilities.py:1
def Utilities.traverseInputTags (   pset,
  visitor,
  stringInputLabels 
)

Definition at line 44 of file Utilities.py.

References relativeConstraints.keys.

44 
45 def traverseInputTags(pset, visitor, stringInputLabels):
46  from FWCore.ParameterSet.Mixins import _Parameterizable
47  from FWCore.ParameterSet.Types import VPSet, VInputTag, InputTag, string
48 
49  # Loop over parameters in a PSet
50  for name in pset.parameters_().keys() :
51  value = getattr(pset,name)
52  # Recursive calls into a PSet in a PSet
53  if isinstance(value, _Parameterizable) :
54  traverseInputTags(value, visitor, stringInputLabels)
55  # Recursive calls into PSets in a VPSet
56  elif isinstance(value, VPSet) :
57  for (n, psetInVPSet) in enumerate(value):
58  traverseInputTags(psetInVPSet, visitor, stringInputLabels)
59  # Get the labels from a VInputTag
60  elif isinstance(value, VInputTag) :
61  visitor(value)
62  # Get the label from an InputTag
63  elif isinstance(value, InputTag) :
64  visitor(value)
65  # Known module labels in string objects
66  elif stringInputLabels and isinstance(value, string) and name in stringInputLabels and value.value() :
67  visitor.labels.add(value.value())
68  #ignore the rest
def traverseInputTags
Definition: Utilities.py:44

Variable Documentation

Utilities.__lastCallUnary

Definition at line 77 of file Utilities.py.