Namespaces | |
namespace | ReleaseScripts |
Classes | |
class | InputTagLabelSet |
class | TestModuleCommand |
Functions | |
def | _build_options |
def | convertToUnscheduled |
def | getHltConfiguration |
def | loadHltConfiguration |
def | removeModulesNotOnAPathExcluding |
def | traverseInputTags |
def Utilities::_build_options | ( | args | ) | [private] |
Definition at line 6 of file Utilities.py.
def Utilities::convertToUnscheduled | ( | proc | ) |
Definition at line 69 of file Utilities.py.
00070 : 00071 import FWCore.ParameterSet.Config as cms 00072 """Given a 'Process', convert the python configuration from scheduled execution to unscheduled. This is done by 00073 1. Removing all modules not on Paths or EndPaths 00074 2. Pulling EDProducers not dependent on EDFilters off of all Paths 00075 3. Dropping any Paths which are now empty 00076 4. Fixing up the Schedule if needed 00077 """ 00078 # Warning: It is not always possible to convert a configuration 00079 # where EDProducers are all run on Paths to an unscheduled 00080 # configuration by modifying only the python configuration. 00081 # There is more than one kind of pathological condition 00082 # that can cause this conversion to produce a configuration 00083 # that gives different results than the original configuration 00084 # when run under cmsRun. One should view the converted configuration 00085 # as a thing which needs to be validated. It is possible for there 00086 # to be pathologies that cannot be resolved by modifying only the 00087 # python configuration and may require redesign inside the C++ code 00088 # of the modules and redesign of the logic. For example, 00089 # an EDAnalyzer might try to get a product and check if the 00090 # returned handle isValid. Then it could behave differently 00091 # depending on whether or not the product was present. 00092 # The behavior when the product is not present could 00093 # be meaningful and important. In the unscheduled case, 00094 # the EDProducer will always run and the product could 00095 # always be there. 00096 00097 # Remove all modules not on Paths or EndPaths 00098 proc.prune() 00099 00100 # Turn on unschedule mode 00101 if not hasattr(proc,'options'): 00102 proc.options = cms.untracked.PSet() 00103 proc.options.allowUnscheduled = cms.untracked.bool(True) 00104 00105 l = proc.paths 00106 droppedPaths =[] 00107 #have to get them now since switching them after the 00108 # paths have been changed gives null labels 00109 if proc.schedule: 00110 pathNamesInScheduled = [p.label_() for p in proc.schedule] 00111 else: 00112 pathNamesInScheduled = False 00113 00114 # Look for EDProducers that depend on an EDFilter, either 00115 # directly or indirectly through another EDProducer. These 00116 # EDProducers must stay in a path and run scheduled. The 00117 # first loop will find all the direct dependencies, but then 00118 # the loop must be repeated until no more dependencies 00119 # are found in order to find the indirect dependencies. 00120 # Note that here we are assuming that if a module 00121 # has a configuration parameter that is an InputTag, then 00122 # it depends on the module with the same module label as in 00123 # the InputTag. In addition, there are a number of special 00124 # cases where we have identified specific types of modules 00125 # which use particular string parameters like InputTag 00126 # module labels. And so we have some special code to 00127 # handle those cases also. If there are other cases where 00128 # the module gets things without using InputTags, then this 00129 # conversion script can fail, which might result in ProductNotFound 00130 # exceptions or other problems when the converted configuration is run. 00131 00132 # The dictionary keys are are the types of the EDProducers 00133 # The dictionary values are lists of parameter names that are strings 00134 # used like InputTags. 00135 knownStringInputLabels = {} 00136 knownStringInputLabels['KProd'] = ['xSrc'] # a fake entry for a unit test below 00137 knownStringInputLabels['SeedGeneratorFromRegionHitsEDProducer'] = ['vertexSrc'] 00138 knownStringInputLabels['PixelTrackProducer'] = ['vertexSrc'] 00139 knownStringInputLabels['SimpleTrackListMerger'] = ['TrackProducer1', 'TrackProducer2'] 00140 00141 allEDFilters = set(proc.filters_().keys()) 00142 allEDProducers = set(proc.producers_().keys()) 00143 00144 dependentProducers = set() 00145 firstPass = True 00146 00147 while True : 00148 00149 dependentsFoundThisPass = False 00150 00151 for producer in allEDProducers : 00152 if producer not in dependentProducers : 00153 iModule = getattr(proc,producer) 00154 00155 stringInputLabels = [] 00156 moduleType = iModule.type_() 00157 if moduleType in knownStringInputLabels : 00158 stringInputLabels = knownStringInputLabels[moduleType] 00159 00160 inputTagLabels = InputTagLabelSet() 00161 traverseInputTags(getattr(proc,producer), inputTagLabels, stringInputLabels) 00162 00163 if firstPass : 00164 if not inputTagLabels.labels.isdisjoint(allEDFilters) : 00165 dependentProducers.add(producer) 00166 dependentsFoundThisPass = True 00167 00168 if not inputTagLabels.labels.isdisjoint(dependentProducers) : 00169 dependentProducers.add(producer) 00170 dependentsFoundThisPass = True 00171 00172 if not dependentsFoundThisPass : 00173 break 00174 firstPass = False 00175 00176 # Loop over paths 00177 # On each path we drop EDProducers except we 00178 # keep the EDProducers that depend on EDFilters 00179 for pName,p in l.iteritems(): 00180 nodes = [] 00181 v = cms.ModuleNodeVisitor(nodes) 00182 p.visit(v) 00183 names = [node.label_() for node in nodes] 00184 remaining =[] 00185 00186 for n in names: 00187 if not isinstance(getattr(proc,n), cms.EDProducer): 00188 remaining.append(n) 00189 else : 00190 if n in dependentProducers : 00191 remaining.append(n) 00192 00193 if remaining: 00194 p=getattr(proc,remaining[0]) 00195 for m in remaining[1:]: 00196 p+=getattr(proc,m) 00197 setattr(proc,pName,cms.Path(p)) 00198 # drop empty paths 00199 else: 00200 setattr(proc,pName,cms.Path()) 00201 00202 # If there is a schedule then it needs to point at 00203 # the new Path objects 00204 if proc.schedule: 00205 proc.schedule = cms.Schedule([getattr(proc,p) for p in pathNamesInScheduled]) 00206 return proc
def Utilities::getHltConfiguration | ( | menu, | |
args | |||
) |
Definition at line 13 of file Utilities.py.
def Utilities::loadHltConfiguration | ( | process, | |
menu, | |||
args | |||
) |
Definition at line 23 of file Utilities.py.
def Utilities::removeModulesNotOnAPathExcluding | ( | process, | |
keepList = () |
|||
) |
Given a 'process', find all modules (EDProducers,EDFilters,EDAnalyzers,OutputModules) and remove them if they do not appear on a Path or EndPath. One can optionally pass in a list of modules which even if they are not on a Path or EndPath you wish to have stay in the configuration [useful for unscheduled execution].
Definition at line 1 of file Utilities.py.
00002 : 00003 """Given a 'process', find all modules (EDProducers,EDFilters,EDAnalyzers,OutputModules) 00004 and remove them if they do not appear on a Path or EndPath. One can optionally pass in 00005 a list of modules which even if they are not on a Path or EndPath you wish to have stay 00006 in the configuration [useful for unscheduled execution]. 00007 """ 00008 allMods=set((x for x in process.producers_().iterkeys())) 00009 allMods.update((x for x in process.filters_().iterkeys())) 00010 allMods.update((x for x in process.analyzers_().iterkeys())) 00011 allMods.update((x for x in process.outputModules_().iterkeys())) 00012 00013 modulesOnPaths = set() 00014 for p in process.paths_(): 00015 modulesOnPaths.update( (x for x in getattr(process,p).moduleNames())) 00016 for p in process.endpaths_(): 00017 modulesOnPaths.update( (x for x in getattr(process,p).moduleNames())) 00018 00019 notOnPaths = allMods.difference(modulesOnPaths) 00020 00021 keepModuleNames = set( (x.label_() for x in keepList) ) 00022 00023 getRidOf = notOnPaths.difference(keepModuleNames) 00024 00025 for n in getRidOf: 00026 delattr(process,n)
def Utilities::traverseInputTags | ( | pset, | |
visitor, | |||
stringInputLabels | |||
) |
Definition at line 44 of file Utilities.py.
00045 : 00046 from FWCore.ParameterSet.Mixins import _Parameterizable 00047 from FWCore.ParameterSet.Types import VPSet, VInputTag, InputTag, string 00048 00049 # Loop over parameters in a PSet 00050 for name in pset.parameters_().keys() : 00051 value = getattr(pset,name) 00052 # Recursive calls into a PSet in a PSet 00053 if isinstance(value, _Parameterizable) : 00054 traverseInputTags(value, visitor, stringInputLabels) 00055 # Recursive calls into PSets in a VPSet 00056 elif isinstance(value, VPSet) : 00057 for (n, psetInVPSet) in enumerate(value): 00058 traverseInputTags(psetInVPSet, visitor, stringInputLabels) 00059 # Get the labels from a VInputTag 00060 elif isinstance(value, VInputTag) : 00061 visitor(value) 00062 # Get the label from an InputTag 00063 elif isinstance(value, InputTag) : 00064 visitor(value) 00065 # Known module labels in string objects 00066 elif stringInputLabels and isinstance(value, string) and name in stringInputLabels and value.value() : 00067 visitor.labels.add(value.value()) 00068 #ignore the rest