Beispiel #1
0
class CutflowDecision:
    def __init__(self, cutflow):
        if isinstance(cutflow, CutflowDecision):
            self._cutflow = OrderedDict(cutflow._cutflow)
        else:
            self._cutflow = OrderedDict(cutflow)
        #just need functions and flags for this
        for key in self._cutflow.keys():
            self._cutflow[key] = self._cutflow[key][:2] + [False]
        #print self._cutflow

    def __getitem__(self, idx):
        return self._cutflow[idx][-1]

    def __call__(self, event, index=-1):
        #print 'object index:',index
        for item in self._cutflow.itervalues():
            args = []
            for arg in item[1]:
                argv = getattr(event, arg)
                if index > -1 and not isinstance(argv,
                                                 (int, float, bool, long)):
                    args.append(argv[index])
                else:
                    args.append(argv)
            #print index, item[1], args
            #print 'calling %s with values:'%(item[0]),args
            item[-1] = bool(item[0](*tuple(args)))

    def __nonzero__(self):
        for item in self._cutflow.itervalues():
            if not item[-1]:
                return False
        return True

    #take the modulus of the current value of the cut
    def __mod__(self, cuts):
        for key, item in self._cutflow.iteritems():
            if key not in cuts and not item[-1]:
                return False
        return True

    #cuts is a list of names or an ordereddict
    def __sub__(self, cuts):
        cutflow = []
        if isinstance(cuts, (list, OrderedDict)):
            for key in self._cutflow.keys():
                if key not in cuts:
                    cutflow.append([key, [self._cutflow[key]]])
        return CutflowDecision(cutflow)

    #cuts is a list as mentioned in the class comment or an ordered dict
    def __add__(self, cuts):
        cutflow = OrderDict(self._cutflow)
        if isinstance(cuts, (list, OrderedDict)):
            cutflow += OrderedDict(cuts)
        return CutflowDecision(cutflow)
Beispiel #2
0
class CutflowDecision:
    def __init__(self,cutflow):
        if isinstance(cutflow,CutflowDecision):
            self._cutflow = OrderedDict(cutflow._cutflow)
        else:
            self._cutflow = OrderedDict(cutflow)
        #just need functions and flags for this
        for key in self._cutflow.keys():
            self._cutflow[key] =  self._cutflow[key][:2] + [False]
        #print self._cutflow

    def __getitem__(self,idx):
        return self._cutflow[idx][-1]
    
    def __call__(self,event,index=-1):
        #print 'object index:',index
        for item in self._cutflow.itervalues():
            args = []            
            for arg in item[1]:
                argv = getattr(event,arg)
                if index > -1 and not isinstance(argv,(int,float,bool,long)):
                    args.append(argv[index])
                else:
                    args.append(argv)
            #print index, item[1], args
            #print 'calling %s with values:'%(item[0]),args
            item[-1] = bool(item[0](*tuple(args)))
                
    def __nonzero__(self):
        for item in self._cutflow.itervalues():
            if not item[-1]:
                return False
        return True

    #take the modulus of the current value of the cut
    def __mod__(self,cuts):
        for key,item in self._cutflow.iteritems():
            if key not in cuts and not item[-1]:
                return False
        return True

    #cuts is a list of names or an ordereddict
    def __sub__(self,cuts):
        cutflow = []
        if isinstance(cuts,(list,OrderedDict)):            
            for key in self._cutflow.keys():
                if key not in cuts:
                    cutflow.append([key,[self._cutflow[key]]])
        return CutflowDecision(cutflow)

    #cuts is a list as mentioned in the class comment or an ordered dict
    def __add__(self,cuts):
        cutflow = OrderDict(self._cutflow)
        if isinstance(cuts,(list,OrderedDict)):            
            cutflow += OrderedDict(cuts)
        return CutflowDecision(cutflow)