32 Raise an exception if called by special config files. This checks 33 the call or import stack for the importing file. An exception is raised if 34 the importing module is not in allowedPatterns and if it is called too deeply: 35 minLevel = 2: inclusion by top lvel cfg only 36 minLevel = 1: No inclusion allowed 37 allowedPatterns = ['Module1','Module2/SubModule1'] allows import 38 by any module in Module1 or Submodule1 44 ignorePatterns = [
'FWCore/ParameterSet/Config.py',
'FWCore/ParameterSet/python/Config.py',
'<string>',
'<frozen ']
45 CMSSWPath = [os.environ[
'CMSSW_BASE'],os.environ[
'CMSSW_RELEASE_BASE']]
49 for item
in inspect.stack():
53 for pattern
in CMSSWPath:
54 if item[1].
find(pattern) != -1:
57 if item[1].
find(
'/') == -1:
60 for pattern
in ignorePatterns:
61 if item[1].
find(pattern) != -1:
65 if inPath
and not ignore:
66 trueStack.append(item[1])
68 importedFile = trueStack[0]
70 if len(trueStack) > 1:
71 importedBy = trueStack[1]
73 for pattern
in allowedPatterns:
74 if importedBy.find(pattern) > -1:
77 if len(trueStack) <= minLevel:
80 raise ImportError(
"Inclusion of %s is allowed only by cfg or specified cfi files." void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
def checkImportPermission(minLevel=2, allowedPatterns=[])