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  SwitchProducerTest
 
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 29 of file Config.py.

References spr.find().

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

Definition at line 82 of file Config.py.

References resolutioncreator_cfi.object.

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