def __init__(self, configurableType): if not isConfigurable(configurableType): raise TypeError('SaneConfigurable only works for Configurables!') configurableType.clone = _saneClone self.configurableType = configurableType self.name = type(configurableType).__name__ self.__name__ = self.name
def __init__(self, line, algos): self._members = [] self._outputloc = None self._selection = None for alg in algos: # dispatch according to the type of alg... if isConfigurable(alg): self._handle_Configurable(line, alg) else: x = '_handle_' + type(alg).__name__ handle = getattr( self, x if hasattr(self, x) else '_default_handler_') handle(line, alg)
def selectionWrapper(selType, name, *args, **kwargs): """ Construct a selection of type selType with construction arguments. Checks if name already belongs to an existing Configurable. Checks whether input is Configurable and if so, extracts its non-default parameters and passes them as a configurableGenerator. """ checkName(name) algorithm = kwargs.pop('Algorithm') if isConfigurable(algorithm): checkConfigurable(algorithm) algGen = CloneCallable(algorithm) kwargs['ConfGenerator'] = algGen else: kwargs['ConfGenerator'] = algorithm return selType(name, *args, **kwargs)
def processAlgs(self, algs): for alg in algs: print 'Bringing sanity to', alg if inspect.ismodule(alg): 'Deal with module' self.processAlgs(getConfigurablesFromModule(alg)) else: 'not module', alg if alg in memoized_sanitise._cache or issubclass( type(alg), SaneConfigurable): pass else: memoized_sanitise._cache += [alg] crazyAlg = alg if type(alg) == str: crazyAlg = self._source.__getattr__(alg) elif isConfigurable(alg): alg = alg.__name__ saneAlg = SaneConfigurable(crazyAlg) self._target.__setattr__(alg, saneAlg)
def test_isConfigurable(): assert isConfigurable(5.0) == False assert isConfigurable("bob") == False assert isConfigurable(Dummy()) == False assert isConfigurable(DummyConfigurable("TestConf")) == True
def __init__( self, name, # the base name for the Line prescale=1, # prescale factor ODIN=None, # ODIN predicate L0DU=None, # L0DU predicate HLT=None, # HltDecReports predicate -> Deprecated since 2015 HLT1=None, # Hlt1DecReports predicate HLT2=None, # Hlt2DecReports predicate FILTER=None, # 'VOID'-predicate, e.g. Global Event Cut checkPV=True, # Check PV before running algos algos=None, # the list of stripping members selection=None, postscale=1, # postscale factor MaxCandidates="Override", # Maxumum number of candidates for CombineParticles MaxCombinations="Override", # Maxumum number of combinations for CombineParticles HDRLocation=None, # if None, defined by stream name EnableFlavourTagging=False, # If True, run FlavourTaggingTool to store FT info ExtraInfoTools=None, # Configuration of ExtraInfo tools, as a list of dictionaries (or None) ExtraInfoSelections=None, # Input selections for ExtraInfo tools. If None, use the top-level selection of the line ExtraInfoDaughters=None, # Daughter selections for which store ExtraInfo. If None, use only the top selection. ExtraInfoRecursionLevel=1, # Maximum depth in the decay tree to calculate ExtraInfo # Only used is ExtraInfoDaughters are given, otherwise is 0 RelatedInfoTools=None, # Configuration of Related Info tools, as a list of dictionaries (or None) RelatedInfoFilter=None, # Optional filter which can use RelatedInfo, added to the line sequence # after RelatedInfoTools RequiredRawEvents=None, # Possible list of RawEvent banks required by this line MDSTFlag=False, # Flag to ask the line to be written to MDST.DST stream **args): # other configuration parameters if algos and selection: raise Exception( 'only algos or selection can be set. You have set both.') if selection: if isConfigurable(selection): raise TypeError( 'StrippingLine selection cannot be Configurable type.') algos = [selection] if not algos: algos = [] ## 1) clone all arguments name = deepcopy(name) ODIN = deepcopy(ODIN) L0DU = deepcopy(L0DU) HLT = deepcopy(HLT) HLT1 = deepcopy(HLT1) HLT2 = deepcopy(HLT2) FILTER = deepcopy(FILTER) algos = deepcopy(algos) args = deepcopy(args) # 2) save all parameters (needed for the proper cloning) self._name = name if callable(prescale): prescale = prescale(self.name()) self._prescale = prescale self._ODIN = ODIN self._L0DU = L0DU self._HLT = HLT self._HLT1 = HLT1 self._HLT2 = HLT2 self._FILTER = FILTER self._checkPV = checkPV self._HDRLocation = HDRLocation self._EnableFlavourTagging = EnableFlavourTagging if callable(postscale): postscale = postscale(self.name()) self._postscale = postscale self._algos = algos self._args = args self.MaxCandidates = MaxCandidates self.MaxCombinations = MaxCombinations self.ExtraInfoTools = ExtraInfoTools self.ExtraInfoSelections = ExtraInfoSelections self.ExtraInfoDaughters = ExtraInfoDaughters self.ExtraInfoRecursionLevel = ExtraInfoRecursionLevel self.RelatedInfoTools = RelatedInfoTools self.RelatedInfoFilter = RelatedInfoFilter self._initialSelection = selection validRawBanks = [ "Trigger", "Muon", "Calo", "Rich", "Velo", "Tracker", "HC" ] # hard coded list, should really come from elsewhere.... if RequiredRawEvents != None: for bank in RequiredRawEvents: if bank not in validRawBanks: raise Exception("RawBank " + bank + " is not a known type") self.RequiredRawEvents = RequiredRawEvents self.MDSTFlag = MDSTFlag line = self.subname() self._appended = False # Configurable is not yet created self._configurable = None #start to contruct the sequence self._members = [] self._selection = None self.fullHDRLocation = None # if needed, check Primary Vertex before running all algos from Configurables import CheckPV if checkPV == True: check = CheckPV("checkPVmin1") check.MinPVs = 1 self._members.insert(0, check) elif isinstance(checkPV, int): check = CheckPV("checkPVmin%d" % checkPV) check.MinPVs = checkPV self._members.insert(0, check) elif isinstance(checkPV, tuple): if len(checkPV) == 2: check = CheckPV("checkPVmin%dmax%d" % checkPV) check.MinPVs = checkPV[0] check.MaxPVs = checkPV[1] self._members.insert(0, check) else: raise TypeError, "Wrong checkPV tuple length %d, should be 2" % len( checkPV) elif checkPV != False: raise TypeError, "Wrong checkPV argument type '%s'" % type( checkPV).__name__ # if needed, apply filter before running all algos if FILTER: if isinstance(FILTER, str): fltr = VOIDFilter(voidentryName(line), Code=FILTER) self._members.insert(0, fltr) elif isinstance(FILTER, (tuple, list)) and 2 == len(FILTER): fltr = VOIDFilter(voidentryName(line), Code=FILTER[0], Preambulo=FILTER[1]) self._members.insert(0, fltr) elif isinstance(FILTER, dict): fltr = VOIDFilter(voidentryName(line), **FILTER) self._members.insert(0, fltr) else: raise TypeError, "Wrong FILTER attribute: %s " % FILTER # bind members to line _boundMembers = bindMembers(line, algos) self._members += _boundMembers.members() self._outputloc = _boundMembers.outputLocation() self._selection = _boundMembers.selection() # register into the local storage of all created Lines _add_to_stripping_lines_(self)