CMS 3D CMS Logo

Classes | Functions
Config Namespace Reference

Classes

class  _AndModifier
 
class  _BoolModifierBase
 
class  _InvertModifier
 
class  _OrModifier
 
class  _ParameterModifier
 
class  FilteredStream
 
class  Modifier
 
class  ModifierChain
 
class  Process
 
class  ProcessFragment
 
class  ProcessModifier
 
class  SubProcess
 
class  TestMakePSet
 
class  TestModuleCommand
 

Functions

def checkImportPermission (minLevel=2, allowedPatterns=[])
 
def findProcess (module)
 

Function Documentation

def Config.checkImportPermission (   minLevel = 2,
  allowedPatterns = [] 
)
Raise an exception if called by special config files. This checks
the call or import stack for the importing file. An exception is raised if
the importing module is not in allowedPatterns and if it is called too deeply:
minLevel = 2: inclusion by top lvel cfg only
minLevel = 1: No inclusion allowed
allowedPatterns = ['Module1','Module2/SubModule1'] allows import
by any module in Module1 or Submodule1

Definition at line 26 of file Config.py.

References spr.find().

26 def checkImportPermission(minLevel = 2, allowedPatterns = []):
27  """
28  Raise an exception if called by special config files. This checks
29  the call or import stack for the importing file. An exception is raised if
30  the importing module is not in allowedPatterns and if it is called too deeply:
31  minLevel = 2: inclusion by top lvel cfg only
32  minLevel = 1: No inclusion allowed
33  allowedPatterns = ['Module1','Module2/SubModule1'] allows import
34  by any module in Module1 or Submodule1
35  """
36 
37  import inspect
38  import os
39 
40  ignorePatterns = ['FWCore/ParameterSet/Config.py','<string>']
41  CMSSWPath = [os.environ['CMSSW_BASE'],os.environ['CMSSW_RELEASE_BASE']]
42 
43  # Filter the stack to things in CMSSWPath and not in ignorePatterns
44  trueStack = []
45  for item in inspect.stack():
46  inPath = False
47  ignore = False
48 
49  for pattern in CMSSWPath:
50  if item[1].find(pattern) != -1:
51  inPath = True
52  break
53  if item[1].find('/') == -1: # The base file, no path
54  inPath = True
55 
56  for pattern in ignorePatterns:
57  if item[1].find(pattern) != -1:
58  ignore = True
59  break
60 
61  if inPath and not ignore:
62  trueStack.append(item[1])
63 
64  importedFile = trueStack[0]
65  importedBy = ''
66  if len(trueStack) > 1:
67  importedBy = trueStack[1]
68 
69  for pattern in allowedPatterns:
70  if importedBy.find(pattern) > -1:
71  return True
72 
73  if len(trueStack) <= minLevel: # Imported directly
74  return True
75 
76  raise ImportError("Inclusion of %s is allowed only by cfg or specified cfi files."
77  % importedFile)
78 
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:20
def checkImportPermission(minLevel=2, allowedPatterns=[])
Definition: Config.py:26
def Config.findProcess (   module)
Look inside the module and find the Processes it contains

Definition at line 79 of file Config.py.

References resolutioncreator_cfi.object.

79 def findProcess(module):
80  """Look inside the module and find the Processes it contains"""
81  class Temp(object):
82  pass
83  process = None
84  if isinstance(module,dict):
85  if 'process' in module:
86  p = module['process']
87  module = Temp()
88  module.process = p
89  if hasattr(module,'process'):
90  if isinstance(module.process,Process):
91  process = module.process
92  else:
93  raise RuntimeError("The attribute named 'process' does not inherit from the Process class")
94  else:
95  raise RuntimeError("no 'process' attribute found in the module, please add one")
96  return process
97 
def findProcess(module)
Definition: Config.py:79