CMS 3D CMS Logo

Functions
common Namespace Reference

Functions

def analyzers_by_type (process, types)
 
def esproducers_by_type (process, types)
 
def filters_by_type (process, types)
 
def insert_modules_after (process, target, modules)
 
def insert_modules_before (process, target, modules)
 
def modules_by_type (process, types)
 
def producers_by_type (process, types)
 
def replace_with (fromObj, toObj)
 
def set_prescale (process, path, prescale)
 

Function Documentation

◆ analyzers_by_type()

def common.analyzers_by_type (   process,
  types 
)

Definition at line 17 of file common.py.

17 def analyzers_by_type(process, *types):
18  "Find all EDAnalyzers in the Process that are instances of the given C++ type."
19  return (analyzer for analyzer in process._Process__analyzers.values() if analyzer._TypedParameterizable__type in types)
20 
def analyzers_by_type(process, types)
Definition: common.py:17

◆ esproducers_by_type()

def common.esproducers_by_type (   process,
  types 
)

Definition at line 21 of file common.py.

Referenced by customizeHLTforCMSSW.customiseBeamSpotFor2018Input(), customizeHLTforCMSSW.customiseForOffline(), and customizeHLTforCMSSW.customizeHLTfor42514().

21 def esproducers_by_type(process, *types):
22  "Find all ESProducers in the Process that are instances of the given C++ type."
23  return (module for module in process._Process__esproducers.values() if module._TypedParameterizable__type in types)
24 
def esproducers_by_type(process, types)
Definition: common.py:21

◆ filters_by_type()

def common.filters_by_type (   process,
  types 
)

Definition at line 13 of file common.py.

13 def filters_by_type(process, *types):
14  "Find all EDFilters in the Process that are instances of the given C++ type."
15  return (filter for filter in process._Process__filters.values() if filter._TypedParameterizable__type in types)
16 
def filters_by_type(process, types)
Definition: common.py:13

◆ insert_modules_after()

def common.insert_modules_after (   process,
  target,
  modules 
)

Definition at line 50 of file common.py.

50 def insert_modules_after(process, target, *modules):
51  "Add the `modules` after the `target` in any Sequence, Paths or EndPath that contains the latter."
52  for sequence in itertools.chain(
53  process._Process__sequences.values(),
54  process._Process__paths.values(),
55  process._Process__endpaths.values()
56  ):
57  try:
58  position = sequence.index(target)
59  except ValueError:
60  continue
61  else:
62  for module in reversed(modules):
63  sequence.insert(position+1, module)
64 
65 
66 # logic from Modifier.toModify from FWCore/ParameterSet/python/Config.py
def insert_modules_after(process, target, modules)
Definition: common.py:50

◆ insert_modules_before()

def common.insert_modules_before (   process,
  target,
  modules 
)

Definition at line 34 of file common.py.

34 def insert_modules_before(process, target, *modules):
35  "Add the `modules` before the `target` in any Sequence, Paths or EndPath that contains the latter."
36  for sequence in itertools.chain(
37  process._Process__sequences.values(),
38  process._Process__paths.values(),
39  process._Process__endpaths.values()
40  ):
41  try:
42  position = sequence.index(target)
43  except ValueError:
44  continue
45  else:
46  for module in reversed(modules):
47  sequence.insert(position, module)
48 
49 
def insert_modules_before(process, target, modules)
Definition: common.py:34

◆ modules_by_type()

def common.modules_by_type (   process,
  types 
)

Definition at line 25 of file common.py.

25 def modules_by_type(process, *types):
26  "Find all modiles or other components in the Process that are instances of the given C++ type."
27  switches = (module for module in (getattr(switchproducer, case) \
28  for switchproducer in process._Process__switchproducers.values() \
29  for case in switchproducer.parameterNames_()))
30  return (module for module in itertools.chain(process.__dict__.values(), switches) \
31  if hasattr(module, '_TypedParameterizable__type') and module._TypedParameterizable__type in types)
32 
33 
def modules_by_type(process, types)
Definition: common.py:25

◆ producers_by_type()

def common.producers_by_type (   process,
  types 
)

Definition at line 4 of file common.py.

Referenced by customizeHLTforCMSSW.customiseBeamSpotFor2018Input(), customizeHLTforCMSSW.customiseCTPPSFor2018Input(), customizeHLTforCMSSW.customiseEGammaRecoFor2018Input(), customizeHLTforCMSSW.customiseHCALFor2018Input(), CustomConfigs.customiseHLTforHIonRepackedRAWPrime(), customizeHLTforCMSSW.customisePixelGainForRun2Input(), customizeHLTforCMSSW.customisePixelL1ClusterThresholdForRun2Input(), and customizePixelTracksForTriplets.customizePixelTracksForTriplets().

4 def producers_by_type(process, *types):
5  "Find all EDProducers in the Process that are instances of the given C++ type."
6  switches = (module for module in (getattr(switchproducer, case) \
7  for switchproducer in process._Process__switchproducers.values() \
8  for case in switchproducer.parameterNames_()) \
9  if isinstance(module, cms.EDProducer))
10  return (module for module in itertools.chain(process._Process__producers.values(), switches) \
11  if module._TypedParameterizable__type in types)
12 
def producers_by_type(process, types)
Definition: common.py:4

◆ replace_with()

def common.replace_with (   fromObj,
  toObj 
)
Replace one object with a different one of the same type.

This function replaces the contents of `fromObj` object with those of `toObj`,
so all references ot it remain valid.

Definition at line 67 of file common.py.

References str.

67 def replace_with(fromObj, toObj):
68  """Replace one object with a different one of the same type.
69 
70  This function replaces the contents of `fromObj` object with those of `toObj`,
71  so all references ot it remain valid.
72  """
73 
74  if not isinstance(toObj, type(fromObj)):
75  raise TypeError('replaceWith requires both arguments to be the same type')
76 
77  if isinstance(toObj, cms._ModuleSequenceType):
78  fromObj._seq = toObj._seq
79 
80  elif isinstance(toObj, cms._Parameterizable):
81  # delete the old items, in case `toObj` is not a complete superset of `fromObj`
82  for p in fromObj.parameterNames_():
83  delattr(fromObj, p)
84  for p in toObj.parameterNames_():
85  setattr(fromObj, p, getattr(toObj, p))
86  if isinstance(toObj, cms._TypedParameterizable):
87  fromObj._TypedParameterizable__type = toObj._TypedParameterizable__type
88 
89  else:
90  raise TypeError('replaceWith does not work with "%s" objects' % str(type(fromObj)))
91 
92 
93 # update or set the HLT prescale for the given path to the given value, in all the prescale columns
def replace_with(fromObj, toObj)
Definition: common.py:67
#define str(s)

◆ set_prescale()

def common.set_prescale (   process,
  path,
  prescale 
)

Definition at line 94 of file common.py.

94 def set_prescale(process, path, prescale):
95  columns = len(process.PrescaleService.lvl1Labels.value())
96  prescales = cms.vuint32([prescale] * columns)
97 
98  for pset in process.PrescaleService.prescaleTable:
99  if pset.pathName.value() == path:
100  pset.prescales = prescales
101  break
102  else:
103  process.PrescaleService.prescaleTable.append(cms.PSet(
104  pathName = cms.string(path),
105  prescales = prescales
106  ))
107 
108 
def set_prescale(process, path, prescale)
Definition: common.py:94