CMS 3D CMS Logo

Classes | Functions | Variables
Utilities Namespace Reference

Classes

class  TestModuleCommand
 

Functions

def _build_options (**args)
 
def convertToSingleModuleEndPaths (process)
 
def convertToUnscheduled (proc)
 
def createTaskWithAllProducersAndFilters (process)
 
def getHltConfiguration (menu, **args)
 
def ignoreAllFiltersOnPath (path)
 
def loadHltConfiguration (process, menu, **args)
 
def moduleLabelsInSequences (*sequences)
 
def modulesInSequences (*sequences)
 

Variables

 __lastCallUnary
 
 _levelInTasks
 
 loadHltConfiguration
 
 onTask
 
 operator
 

Function Documentation

◆ _build_options()

def Utilities._build_options ( **  args)
private

Definition at line 7 of file Utilities.py.

7 def _build_options(**args):
8  options = _options.HLTProcessOptions()
9  for key, val in six.iteritems(args):
10  setattr(options, key, val)
11  return options
12 
13 

Referenced by getHltConfiguration(), and loadHltConfiguration().

◆ convertToSingleModuleEndPaths()

def Utilities.convertToSingleModuleEndPaths (   process)
Remove the EndPaths in the Process with more than one module
and replace with new EndPaths each with only one module.

Definition at line 70 of file Utilities.py.

71  """Remove the EndPaths in the Process with more than one module
72  and replace with new EndPaths each with only one module.
73  """
74  import FWCore.ParameterSet.Config as cms
75  import six
76  toRemove =[]
77  added = []
78  for n,ep in six.iteritems(process.endpaths_()):
79  tsks = []
80  ep.visit(cms.TaskVisitor(tsks))
81 
82  names = ep.moduleNames()
83  if 1 == len(names):
84  continue
85  toRemove.append(n)
86  for m in names:
87  epName = m+"_endpath"
88  setattr(process,epName,cms.EndPath(getattr(process,m),*tsks))
89  added.append(epName)
90 
91  s = process.schedule_()
92  if s:
93  pathNames = [p.label_() for p in s]
94  for rName in toRemove:
95  pathNames.remove(rName)
96  for n in added:
97  pathNames.append(n)
98  newS = cms.Schedule(*[getattr(process,n) for n in pathNames])
99  if s._tasks:
100  newS.associate(*s._tasks)
101  process.setSchedule_(newS)
102 
103  for r in toRemove:
104  delattr(process,r)
105 
106 

Referenced by Utilities.TestModuleCommand.testConvertToSingleModuleEndPaths().

◆ convertToUnscheduled()

def Utilities.convertToUnscheduled (   proc)

Definition at line 46 of file Utilities.py.

46 def convertToUnscheduled(proc):
47  print("covertToUnscheduled is deprecated and no longer needed, and will be removed soon. Please update your configuration.")
48  return proc
49 
50 

References print().

◆ createTaskWithAllProducersAndFilters()

def Utilities.createTaskWithAllProducersAndFilters (   process)

Definition at line 62 of file Utilities.py.

63  from FWCore.ParameterSet.Config import Task
64  import six
65 
66  l = [ p for p in six.itervalues(process.producers)]
67  l.extend( (f for f in six.itervalues(process.filters)) )
68  return Task(*l)
69 

Referenced by Utilities.TestModuleCommand.testCreateTaskWithAllProducersAndFilters().

◆ getHltConfiguration()

def Utilities.getHltConfiguration (   menu,
**  args 
)

Definition at line 14 of file Utilities.py.

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 
23 

References _build_options(), and FrontierConditions_GlobalTag_cff.dump.

◆ ignoreAllFiltersOnPath()

def Utilities.ignoreAllFiltersOnPath (   path)
Given a 'Path', find all EDFilters and wrap them in 'cms.ignore'

Definition at line 2 of file Utilities.py.

2 def ignoreAllFiltersOnPath(path):
3  """Given a 'Path', find all EDFilters and wrap them in 'cms.ignore'
4  """
5  import FWCore.ParameterSet.Config as cms
6  from FWCore.ParameterSet.SequenceTypes import _MutatingSequenceVisitor, _UnarySequenceOperator
7 
8  class IgnoreFilters(object):
9  def __init__(self):
10  self.__lastCallUnary = False
11  self.onTask = False
12  def __call__(self, obj):
13  if self.onTask:
14  return obj
15  elif isinstance(obj,_UnarySequenceOperator):
16  self.__lastCallUnary = True
17  elif obj.isLeaf() and isinstance(obj, cms.EDFilter) and not self.__lastCallUnary:
18  return cms.ignore(obj)
19  else:
20  self.__lastCallUnary = False
21  return obj
22  class IgnoreFiltersVisitor(_MutatingSequenceVisitor):
23  def __init__(self):
24  self.operator = IgnoreFilters()
25  self._levelInTasks = 0
26  super(type(self),self).__init__(self.operator)
27  def enter(self,visitee):
28  if isinstance(visitee, cms.Task):
29  self._levelInTasks += 1
30  self.operator.onTask = (self._levelInTasks > 0)
31  super(IgnoreFiltersVisitor,self).enter(visitee)
32  def leave(self,visitee):
33  if self._levelInTasks > 0:
34  if isinstance(visitee, cms.Task):
35  self._levelInTasks -= 1
36  super(IgnoreFiltersVisitor,self).leave(visitee)
37 
38  mutator = IgnoreFiltersVisitor()
39  path.visit(mutator)
40  if mutator._didApply():
41  path._seq = mutator.result(path)[0]
42  path._tasks.clear()
43  path.associate(*mutator.result(path)[1])
44  return path
45 

References resolutioncreator_cfi.object.

◆ loadHltConfiguration()

def Utilities.loadHltConfiguration (   process,
  menu,
**  args 
)

Definition at line 24 of file Utilities.py.

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 
33 

References _build_options(), FrontierConditions_GlobalTag_cff.dump, and loadHltConfiguration.

◆ moduleLabelsInSequences()

def Utilities.moduleLabelsInSequences ( sequences)

Definition at line 59 of file Utilities.py.

59 def moduleLabelsInSequences(* sequences):
60  return [module.label_() for module in modulesInSequences(* sequences)]
61 

References modulesInSequences().

◆ modulesInSequences()

def Utilities.modulesInSequences ( sequences)

Definition at line 51 of file Utilities.py.

51 def modulesInSequences(* sequences):
52  from FWCore.ParameterSet.SequenceTypes import ModuleNodeVisitor
53  modules = []
54  for sequence in sequences:
55  sequence.visit(ModuleNodeVisitor(modules))
56  return modules
57 
58 

Referenced by moduleLabelsInSequences().

Variable Documentation

◆ __lastCallUnary

Utilities.__lastCallUnary
private

Definition at line 10 of file Utilities.py.

◆ _levelInTasks

Utilities._levelInTasks
private

Definition at line 25 of file Utilities.py.

◆ loadHltConfiguration

Utilities.loadHltConfiguration

Definition at line 35 of file Utilities.py.

Referenced by loadHltConfiguration().

◆ onTask

Utilities.onTask

Definition at line 11 of file Utilities.py.

◆ operator

Utilities.operator
resolutioncreator_cfi.object
object
Definition: resolutioncreator_cfi.py:4
Utilities.convertToUnscheduled
def convertToUnscheduled(proc)
Definition: Utilities.py:46
Utilities.ignoreAllFiltersOnPath
def ignoreAllFiltersOnPath(path)
Definition: Utilities.py:2
Utilities._build_options
def _build_options(**args)
Definition: Utilities.py:7
Utilities.createTaskWithAllProducersAndFilters
def createTaskWithAllProducersAndFilters(process)
Definition: Utilities.py:62
Utilities.moduleLabelsInSequences
def moduleLabelsInSequences(*sequences)
Definition: Utilities.py:59
Utilities.modulesInSequences
def modulesInSequences(*sequences)
Definition: Utilities.py:51
Utilities.getHltConfiguration
def getHltConfiguration(menu, **args)
Definition: Utilities.py:14
print
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:46
FrontierConditions_GlobalTag_cff.dump
dump
Definition: FrontierConditions_GlobalTag_cff.py:12
Utilities.convertToSingleModuleEndPaths
def convertToSingleModuleEndPaths(process)
Definition: Utilities.py:70
Utilities.loadHltConfiguration
def loadHltConfiguration(process, menu, **args)
Definition: Utilities.py:24
SequenceTypes