CMS 3D CMS Logo

Classes | Functions | Variables

Config Namespace Reference

Classes

class  FilteredStream
class  Process
class  SubProcess
class  TestMakePSet
class  TestModuleCommand

Functions

def checkImportPermission
def findProcess

Variables

tuple options = Options()

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

00028                                                              :
00029     """
00030     Raise an exception if called by special config files. This checks
00031     the call or import stack for the importing file. An exception is raised if
00032     the importing module is not in allowedPatterns and if it is called too deeply:
00033     minLevel = 2: inclusion by top lvel cfg only
00034     minLevel = 1: No inclusion allowed
00035     allowedPatterns = ['Module1','Module2/SubModule1'] allows import
00036     by any module in Module1 or Submodule1
00037     """
00038 
00039     import inspect
00040     import os
00041 
00042     ignorePatterns = ['FWCore/ParameterSet/Config.py','<string>']
00043     CMSSWPath = [os.environ['CMSSW_BASE'],os.environ['CMSSW_RELEASE_BASE']]
00044 
00045     # Filter the stack to things in CMSSWPath and not in ignorePatterns
00046     trueStack = []
00047     for item in inspect.stack():
00048         inPath = False
00049         ignore = False
00050 
00051         for pattern in CMSSWPath:
00052             if item[1].find(pattern) != -1:
00053                 inPath = True
00054                 break
00055         if item[1].find('/') == -1: # The base file, no path
00056             inPath = True
00057 
00058         for pattern in ignorePatterns:
00059             if item[1].find(pattern) != -1:
00060                 ignore = True
00061                 break
00062 
00063         if inPath and not ignore:
00064             trueStack.append(item[1])
00065 
00066     importedFile = trueStack[0]
00067     importedBy   = ''
00068     if len(trueStack) > 1:
00069         importedBy = trueStack[1]
00070 
00071     for pattern in allowedPatterns:
00072         if importedBy.find(pattern) > -1:
00073             return True
00074 
00075     if len(trueStack) <= minLevel: # Imported directly
00076         return True
00077 
00078     raise ImportError("Inclusion of %s is allowed only by cfg or specified cfi files."
00079                       % importedFile)

def Config::findProcess (   module)
Look inside the module and find the Processes it contains

Definition at line 80 of file Config.py.

00081                        :
00082     """Look inside the module and find the Processes it contains"""
00083     class Temp(object):
00084         pass
00085     process = None
00086     if isinstance(module,dict):
00087         if 'process' in module:
00088             p = module['process']
00089             module = Temp()
00090             module.process = p
00091     if hasattr(module,'process'):
00092         if isinstance(module.process,Process):
00093             process = module.process
00094         else:
00095             raise RuntimeError("The attribute named 'process' does not inherit from the Process class")
00096     else:
00097         raise RuntimeError("no 'process' attribute found in the module, please add one")
00098     return process
00099 


Variable Documentation

Definition at line 5 of file Config.py.