def decodeConditions(self, args2): conditions = ConditionBlock() current = conditions nparameter = 0 observable1 = 0 observable2 = 0 operator = 0 value = 0. for item in args: # Opening bracket # if item=="(": # if nparameter!=0: # logging.getLogger('MA5').error("problem with an opening bracket") # return None # block=ConditionBlock() # block.mother=current # current.Add(block,0) # current=block # elif item==")": # if nparameter==3: # logging.getLogger('MA5').error("problem with a closing bracket") # return None # current=current.mother # Observable if nparameter == 0: obs = self.extract_observable(item) if obs == None: return None if not ObservableType.isCuttable(obs[1]): logging.getLogger('MA5').error("a cut applied to the observable '"+\ item+"' is not possible") return None observable1 = obs[0] observable2 = obs[1] nparameter = 1 # Operator elif nparameter == 1: operator = self.extract_operator(item) if operator == OperatorType.UNKNOWN: return None nparameter = 2 # Threshold value elif nparameter == 2: try: value = float(item) except: logging.getLogger('MA5').error("the threshold '"+item+\ "' is not a float value.") return None nparameter = 3 # Connector elif nparameter == 3: if item == "or": connector = ConnectorType.OR elif item == "and": connector = ConnectorType.AND else: logging.getLogger('MA5').error( "'" + item + "' is not a valid connector") return None nparameter = 0 block = ConditionType(observable1, observable2, operator, value) current.Add(block, connector) if nparameter == 3: block = ConditionType(observable1, observable2, operator, value) current.Add(block, ConnectorType.UNKNOWN) return conditions
def extract_condition(self, current, words, partType): # layout condition words = self.layout_condition(words) # checking number of arguments if len(words) < 3: logging.getLogger('MA5').error("condition '" + str(words) + "' is not correct.") return None # looking for observable # determining if doubleCondition case doubleCondition = False if words[0] not in self.main.observables.full_list: if words[2] not in self.main.observables.full_list: logging.getLogger('MA5').error( "no observable found in condition '" + str(words) + "'") return None else: doubleCondition = True # double condition case if doubleCondition: # checking number of arguments if len(words) < 5: logging.getLogger('MA5').error("condition '" + str(words) + "' is not correct.") return None # extracting threshold try: threshold1 = float(words[0]) except: logging.getLogger('MA5').error("'" + words[0] + "' must be a float value.") return None # extracting operator operator1 = self.extract_operator(words[1]) if operator1 == OperatorType.UNKNOWN: logging.getLogger('MA5').error("operator '" + words[1] + "' is unknown.") return None # extracting threshold try: threshold = float(words[-1]) except: logging.getLogger('MA5').error("'" + words[-1] + "' must be a float value.") return None # extracting operator operator = self.extract_operator(words[-2]) if operator == OperatorType.UNKNOWN: logging.getLogger('MA5').error("operator '" + words[-2] + "' is unknown.") return None # extracting observable obsName = words[0] if doubleCondition: obsName = words[2] if partType == None and obsName not in self.main.observables.cut_event_list: logging.getLogger('MA5').error("observable '"+obsName+"' cannot be used for "+\ "rejecting an event.") return None if partType != None and obsName not in self.main.observables.cut_candidate_list: logging.getLogger('MA5').error("observable '"+obsName+"' cannot be used for "+\ "rejecting a candidate.") return None obsRef = self.main.observables.get(obsName) if partType == ArgumentType.COMBINATION and (len( obsRef.args) == 0 or obsRef.args[0] == ArgumentType.PARTICLE): logging.getLogger('MA5').error( "observable '" + obsName + "' can be used on a particle but not a combination of particles" ) return None # Case with arguments arguments = [] if (partType!=None and len(obsRef.args)>1) or \ (partType==None and len(obsRef.args)>0) : # Checking opening-brace if (doubleCondition and words[3]!='(') or \ (not doubleCondition and words[1]!='(') : logging.getLogger('MA5').error("wrong syntax for the condition '" +\ str(words)+"'") return None # Checking closing-brace if words[-3] != ")": logging.getLogger('MA5').error("wrong syntax for the condition '" +\ str(words)+"'") return None # Creating new obsRef if partType == None: obsRef2 = obsRef else: obsRef2 = ObservableBase.Clone(obsRef,\ args=obsRef.args[1:]) # Extracting arguments if doubleCondition: arguments=self.extract_arguments(words[4:-3],\ obsName,\ obsRef2) else: arguments=self.extract_arguments(words[2:-3],\ obsName,\ obsRef2) # Checking arguments if arguments == None: return None # Case with no arguments else: if (doubleCondition and len(words)!=5) or \ (not doubleCondition and len(words)!=3) : logging.getLogger('MA5').error("wrong number of arguments in the condition '"+\ str(words)+"'") return None # Checking operator consistency with double condition if doubleCondition: if not ( ( operator1 in [OperatorType.GREATER,OperatorType.GREATER_EQUAL] ) \ and \ ( operator in [OperatorType.GREATER,OperatorType.GREATER_EQUAL] ) ) \ and \ not ( ( operator1 in [OperatorType.LESS,OperatorType.LESS_EQUAL] ) \ and \ ( operator in [OperatorType.LESS,OperatorType.LESS_EQUAL] ) ): logging.getLogger('MA5').error( 'double conditions allowed are : < obs < , > obs >') return None # Storing condition if doubleCondition: current.sequence.append(ConditionSequence()) if operator1 == OperatorType.LESS: newOperator1 = OperatorType.GREATER elif operator1 == OperatorType.GREATER: newOperator1 = OperatorType.LESS elif operator1 == OperatorType.LESS_EQUAL: newOperator1 = OperatorType.GREATER_EQUAL elif operator1 == OperatorType.GREATER_EQUAL: newOperator1 = OperatorType.LESS_EQUAL condition1 = ConditionType(obsRef, arguments, newOperator1, threshold1) current.sequence[-1].sequence.append(condition1) current.sequence[-1].sequence.append(ConditionConnector('and')) condition2 = ConditionType(obsRef, arguments, operator, threshold) current.sequence[-1].sequence.append(condition2) else: condition = ConditionType(obsRef, arguments, operator, threshold) current.sequence.append(condition) return True