#!/usr/bin/env python
###################################################################################
##
## This is a module for *triggernames tables related functions for the
## web interface to the trigger database using the trigger dbserver
## E.Gallas/R.Wellner May 2001
##
## These routines apply specifically to Trigger Names table
## Report, Insert, Update, and Delete
##
## We try to add notes about changes below. See cvs for complete list of changes.
##
## Modified: 02/18/05 by M.Vittone:
## Change ._v. syntax to ._v. due to omniorb conversion of the server.
##
## Modified: Dec 2005, April 2006 by M.Vittone/E.Gallas
## Append '_NOLUM' to Trigger Name if any NEOTERM.X_RELATED=nolum neoterms found
## Recognize and correct zero_bias% and xrel_bias% trigger names.
## Remove L2_global_crate and _exe from the form (never used)
##
###############################################
## Standard/built-in modules.
import sys, os, string, time, cgi, whrandom, re
## I need this for FormContent
from cgi import *
## import my local modules to help report other import errors
from trigdb_aux import *
## I need the trigdb_scripts.py function scripts_report to report
## the scripts in a trigger
from trigdb_scripts import *
## ###############################################################################
def triggernames_menu():
"This routine generates the menu for Run II trigger database triggernames"
display_header('Trigger Names','triggernames_readmenu')
print '
'
print '
'
print '
'
print 'Choose the action to perform:
'
print '
'
form = FormContent()
## get the user
if form.has_key("dbname"):
dbname = form["dbname"][0]
## display actions specific to this user for this element type
error_list = display_sec_menu('TRIGGERNAMES',dbname)
if error_list!=[]:
display_error(error_list)
print '
'
display_footer()
return
print ''
print """
Enter the reference TRIGGER NAME and/or Version here
(the "%" symbol for a wildcard may work):
Trigger Name:
Version:
"""
print '
With STATUS:
'
print '
'
display_statcurr_menu(['all'])
print '
'
print '
'
print """
Report_Format:
"""
htopic = 'entername'
helpme = """Click here for additional help with: """ + \
TDB_Report_Link('helpme',[htopic],HELPDICT_HEADERS[htopic])
print """
Definition:
Each Trigger definition (uniquely identified by a
TRIGGER NAME and VERSION) is a unique set of
one Level 1, one Level 2, and one Level 3 trigger SCRIPT.
Triggers are defined (via INSERT), modified (UPDATE),
deleted (DELETE) and reported (REPORT) via this menu.
If the reference TRIGGER NAME is incomplete,
a list of candidate TriggerNames will be presented
which have a status among the STATUS boxes selected.
UPDATE means modifying an existing TRIGGER NAME,
INSERT means making a new version of an TRIGGER NAME
(copying the reference TRIGGER NAME as a starting point).
""" + helpme + """
"""
display_footer()
return
## ###############################################################################
def triggernames_report(one_triggername,elefmt='long'):
"This routine prints the trigger name (one_triggername) and its scripts"
## get/print the element information
try:
name = one_triggername.name
version = one_triggername.version
statCurr = one_triggername.statCurr
statUsed = one_triggername.statUsed
l1sName = one_triggername.l1sName
l1sVersion = one_triggername.l1sVersion
l2sName = one_triggername.l2sName
l2sVersion = one_triggername.l2sVersion
l3sName = one_triggername.l3sName
l3sVersion = one_triggername.l3sVersion
history = one_triggername.history
l2GlobalCrate = one_triggername.l2GlobalCrate
l2GlobalExe = one_triggername.l2GlobalExe
cdate = one_triggername.createDate
cuser = one_triggername.createUser
mdate = one_triggername.modifyDate
muser = one_triggername.modifyUser
except:
emsg = 'Error reporting on trigger name '
display_exc(emsg,sys.exc_info())
return
##!! triggernames_print(one_triggername)
## compose direct link to the tdb_report_element interface for this element
linktn = TDB_Report_Link('triggername',[name,version])
print '
' % \
('%',get_stat_color(statCurr))
## print the 'list' elefmt result, then exit:
if elefmt=='list':
print_data('tn_name',linktn)
print '
'
return
## print the element identification
print 'TRIGGER Name/Version='; print_data('name',linktn)
print ', Use_Status='; print_data('stat_used',statUsed)
print ', Current_Status='; print_data('stat_curr',statCurr)
##!! if elefmt!='brief':
print 'Created'
if muser: print '(Modified)'
print ' by '; print_data('cuser',string.capitalize(cuser))
if muser:
if muser!=cuser:
print_data('muser','('+string.capitalize(muser)+')');
print ' on '; print_data('user',cdate[:16])
if mdate: print_data('user','('+mdate[:16]+')');
if elefmt!='brief' and history:
print ' Description: '; print_data('history',history);
##?? if l2GlobalCrate!='global_crate':
##?? print ' L2 Global Crate: ';print_data('l2_global_crate',l2GlobalCrate);
##?? if l2GlobalExe!='global_exe':
##?? print 'L2 Global Exe: '; print_data('l2_global_exe',l2GlobalExe);
print ''
if elefmt=='brief':
return
#------------------------------------------------------------------------------------------
## print ' This trigger executes the following SCRIPTS:'
print '
'
return
## ###############################################################################
def triggernames_readmenu():
"""This routine reads the user input from the triggernames_menu"""
## Connect to the CORBA service.
server,servant = connect_server()
## initialize the uid
tnName = ''; tnVersion = 0;
## get form content
form = FormContent()
try:
taction = form["taction"][0]
except:
display_error('triggernames_readmenu: incomplete input',sys.exc_info())
## get the list of input status
instatCurr,instatForm = read_statcurr_menu(form)
## the elefmt determines the length of the triggername report
if form.has_key("elefmt"):
elefmt = form["elefmt"][0]
else:
elefmt = 'short'
try:
if form.has_key("tnName"):
tnName = spacestripfirst(form["tnName"][0])
if form.has_key("tnVersion"):
tnVersion = int(form["tnVersion"][0])
except:
display_error('triggernames_readmenu: invalid input',sys.exc_info())
##obs## remove all spaces from sName
##obs tnName = re.sub(" ","",tnName)
## check all information on the input form for double quotes
emsg = ''
for aString in [taction,tnName]:
if string.find(aString,'"')!=-1:
emsg = "Double quotes not allowed in the input string '%s'" % \
(aString)
display_error(emsg)
display_footer()
return
## initialize the UID input and some other things
## num_objs = number of objects found matching the input criteria
triggername_uids = [tnName,str(tnVersion)]
trig_triggernames = []
num_elements = 0
## if no input element, then insert a new trigger.
if taction=='INSERT' and triggername_uids==['','0']:
triggernames_change(taction,[])
return
printit = '(' + tnName + ',' + str(tnVersion) + ')'
## get the triggernames matching the input criteria
try:
trig_triggernames = servant.GetTTriggerNames(tnName,tnVersion,instatCurr)
except:
display_header('GetTTriggerNames ERROR','Main_Menu')
emsg = "triggernames_readmenu: error on servant.GetTTriggerNames"
emsg = emsg + printit + ' '
display_exc(emsg,sys.exc_info())
display_footer()
return
## get the number of triggernames returned
num_elements = len(trig_triggernames)
## if REPORT, then report the results then exit
if taction=='REPORT':
title = 'Trigger Names REPORT (%s)' % elefmt
display_header(title,'Main_Menu')
if num_elements==0:
print 'No '
print ' TRIGGERNAME(s) matched the input criteria: ' + printit
else:
print 'The following %d TriggerNames matched the input criteria %s ' % \
(num_elements,printit)
if instatCurr!=[]:
print 'You selected elements with Current Status among: %s. ' % \
str(instatCurr)
if form.has_key("elefmt"):
print 'Report format = %s ' % elefmt
for triggernames in trig_triggernames:
print '
'
display_colormap()
display_footer()
return
## if DELETE and no element found - display error message and return
if taction=='DELETE' and num_elements==0:
emsg = 'No Trigger Name(s) '
emsg = emsg + ' matched the input criteria: '
display_error(emsg)
return
## if no element found and UPDATE/INSERT - set taction to INSERT and INSERT a new element
if num_elements==0 and (taction=='UPDATE' or taction=='INSERT'):
taction = 'INSERT'
triggernames_change(taction,[])
return
## if one element found
## UPDATE/INSERT using found term
if num_elements==1 and (taction=='UPDATE' or taction=='INSERT'):
one_triggername = trig_triggernames[0]
triggernames_change(taction,one_triggername)
return
## what we should have left is
## more than one triggernames found for insert, update or delete or
#################################################### list of action / objects
## if DELETE, a checkbox menu is presented
## if INSERT or UPDATE - a menu of submit buttons
if taction=='DELETE': input_type=''
print ''
print ''
## if DELETE or more than one matching elements found (INSERT/UPDATE),
## present a radio/checkbox menu of matching items from which the user can choose
## Allow DELETE or UPDATE only for TRIGGERNAMES with stat_used=='unused'
print 'The following %d Trigger Name(s) \
matched the input criteria. ' % num_elements
## print some instructions
if taction=='DELETE':
print '
All Trigger Names with the DELETE box checked will be deleted.'
print '
Do not click on the SUBMIT button (below) if you are unsure.'
elif taction=='INSERT':
print '
Click on the INSERT button corresponding to the TRIGGER NAME'
print 'you wish to use (copy) to create a new TRIGGER NAME.
'
else:
print '
Click on the UPDATE button corresponding to the TRIGGER NAME '
print 'you wish to modify.'
if taction!='INSERT':
print '
A Status = KEEP '
print 'indicates the TRIGGER NAME is not a candidate for '
if taction=='DELETE': print 'deletion.
'
if taction=='UPDATE': print 'modification.'
## start the table
print '
'
print 'Check here to ' + taction + '
TRIGGER Description
'
ielement = 0
printsubmit = 'no'
for triggernames in trig_triggernames:
ielement = ielement + 1
print '
'
if ((taction=='UPDATE' or taction=='DELETE') \
and triggernames.statUsed=='unused') or taction=='INSERT':
print input_type + ' name="'+ taction + str(ielement) + '" '
print 'value="' + taction + '">'
if taction=='DELETE':
printsubmit = 'yes'
print 'DELETE'
else:
print 'KEEP'
print '
'
## a SUBMIT button is needed for DELETE if there are one/more candidates
if taction=='DELETE' and printsubmit=='yes':
print '
'
print '
'
print '
All Trigger Names with the DELETE '
print 'box checked will be deleted.'
print '
Do not SUBMIT if you are unsure.'
print '
A Status = KEEP '
print 'indicates the TRIGGER NAME is not a candidate for deletion.'
print '
'
print '
'
display_colormap()
display_footer()
return
## ###############################################################################
def triggernames_change(action='dummy',one_triggername=[]):
"""execute the action (INSERT, UPDATE, or DELETE) on the input triggername(s)
or read the radio menu to execute the delete
or use the right reference triggername for INSERT or UPDATE"""
## Connect to the CORBA service.
server,servant = connect_server()
## initialize the uid
tnName = ''; tnVersion = 0;
## no matter what, I still need the instatCurr
form = FormContent()
instatCurr,instatForm = read_statcurr_menu(form)
## see it there is a non-dummy action (input from form, not from another function):
if action=='dummy':
## get form content from the INSERT, UPDATE or DELETE element menu
if form.has_key("taction") and form.has_key("num_elements"):
taction = form["taction"][0]
num_elements = int(form["num_elements"][0])
else:
display_error('triggernames_change: incomplete input',sys.exc_info())
## the form tells you to dowhatelement to whichelement
dowhatelement = {}
whichelement = {}
for ielement in range(1,num_elements+1):
try:
key = taction + str(ielement)
if form.has_key(key): dowhatelement[key] = form[key][0]
else: dowhatelement[key] = 'keep'
ktnName = 'tnName' + str(ielement)
if form.has_key(ktnName): whichelement[ktnName] = form[ktnName][0]
ktnVersion = 'tnVersion' + str(ielement)
if form.has_key(ktnVersion): whichelement[ktnVersion] = form[ktnVersion][0]
except:
display_error('triggernames_change: incomplete Trigger Name input',sys.exc_info())
## take care of DELETE's right here
if taction=="DELETE":
display_header('Trigger Name Deletion Report','Main_Menu')
## get the dbname
dbname = 'anonymous'
if form.has_key("dbname"):
dbname = form["dbname"][0]
if dbname=='anonymous':
display_fatal('Improper identification')
return
## loop over number of triggernames, deleting as we go
for ielement in range(1,num_elements+1):
key = 'DELETE' + str(ielement)
ktnName = 'tnName' + str(ielement)
ktnVersion = 'tnVersion' + str(ielement)
tnName = whichelement[ktnName]
tnVersion = int(whichelement[ktnVersion])
printit = ' Trigger Name (' + tnName + ',' + str(tnVersion) + ')'
## if request is to delete
if dowhatelement[key]=='DELETE':
## re-Get the element to delete
try:
trig_triggername = servant.GetTTriggerNames(tnName,tnVersion,[])
except:
emsg = "Triggernames_change: error on servant.GetTTriggerNames "
emsg = emsg + printit + ' '
display_exc(emsg,sys.exc_info())
display_footer()
return
## if a distinct element not found, don't delete
if len(trig_triggername)!=1:
print ' A unique match was not found for '
print printit + ' '
## if unused -- delete it !!
elif trig_triggername[0].statUsed=='unused':
print ' The following ' + printit + \
' is being deleted: '
triggernames_report(trig_triggername[0])
try:
servant.DelTTriggerName(trig_triggername[0])
except:
emsg = "Triggernames_change: error on servant.DelTTriggerName "
emsg = emsg + printit + ' '
display_exc(emsg,sys.exc_info())
display_footer()
return
## if that script is used, don't delete
else:
print ' ' + printit
print ' is no longer a candidate for deletion. '
triggernames_report(trig_triggername[0])
## else -- no request to delete
else:
print ' ' + printit + ' remains unaltered.'
## for triggername in trig_triggername:
## triggernames_report(triggername)
display_footer()
return
## for INSERT and UPDATE, just get the Trigger Name (one_triggername) involved
else:
title = taction + ': Trigger Name '
for ielement in range(1,num_elements+1):
key = taction + str(ielement)
ktnName = 'tnName' + str(ielement)
ktnVersion = 'tnVersion' + str(ielement)
if dowhatelement[key]==taction:
tnName = whichelement[ktnName]
tnVersion = int(whichelement[ktnVersion])
printit = ' Trigger Name (' + tnName + ',' + str(tnVersion) + ')'
try:
trig_triggername = servant.GetTTriggerNames(tnName,tnVersion,[])
except:
display_header('GetTTriggerNames ERROR','Main_Menu')
emsg = "triggernames_change: error on servant.GetTTriggerNames"
emsg = emsg + printit + ' '
display_exc(emsg,sys.exc_info())
display_footer()
return
##?? may be extraneous: this should never be > 1
if len(trig_triggername)>1:
display_header(title,'Main_Menu')
print ' The database record for '
print printit + ' has been altered. '
print 'The database must have been altered since the last query '
for triggernames in trig_triggername:
triggernames_report(triggernames)
display_colormap()
display_footer()
return
## case of another user who deletes the SCRIPT
elif len(trig_triggername)==0:
display_header(title,'Main_Menu')
print ' The database record for '
print printit + ' has been deleted. '
print 'The database must have been altered since the last query '
display_footer()
return
## case of another user who uses the SCRIPT in a script, so now no modification allowed
else:
if trig_triggername[0].statUsed!='unused' and taction=='UPDATE':
display_header(title,'Main_Menu')
print ' This ' + printit
print ' is no longer a candidate for modification. '
triggernames_report(trig_triggername[0])
display_colormap()
display_footer()
return
## ELEMENT is found and is a candidate for insert or modification
else:
one_triggername = trig_triggername[0]
break
## simpler case: action, slevel and element to be used is passed by function argument
else:
taction = action
if taction=='UPDATE' and one_triggername.statUsed!='unused':
title = 'Trigger Name Definition'
display_header(title,'Main_Menu')
print ' This Trigger Definition '
print ' is not a candidate for modification. '
triggernames_report(one_triggername)
##!! this is not really fatal, should I just let them insert a new term ?
print ' '
print 'Once a Trigger has been used in a Trigger List, it cannot be modified.'
print ' If you need a new different Trigger definition, go back to create (INSERT) a new one.'
print ' '
display_footer()
return
## print the header
title = taction + ': Trigger Name'
display_header(title,'triggernames_readchange')
## put the taction, instatCurr on the form
print ''
print ''
## from here, I must have either none or one_triggername to base a new Trigger Name on
## initialize form values with defaults, overwrite if reference element exists
tnName0 = history0 = ''
tnVersion0 = 0
statUsed0 = 'unused'
statCurr0 = 'local'
history0 = ''
l1sName0 = l2sName0 = l3sName0 = ''
l1sVersion0 = l2sVersion0 = l3sVersion0 = 0
l2GlobalCrate0 = 'global_crate'
l2GlobalExe0 = 'global_exe'
l1_scripts = []
l2_scripts = []
l3_scripts = []
## reference element
if one_triggername!=[]:
tnName0 = one_triggername.name
tnVersion0 = one_triggername.version
statCurr0 = one_triggername.statCurr
statUsed0 = one_triggername.statUsed
history0 = one_triggername.history
l1sName0 = one_triggername.l1sName
l1sVersion0 = one_triggername.l1sVersion
l2sName0 = one_triggername.l2sName
l2sVersion0 = one_triggername.l2sVersion
l3sName0 = one_triggername.l3sName
l3sVersion0 = one_triggername.l3sVersion
l2GlobalCrate0 = one_triggername.l2GlobalCrate
l2GlobalExe0 = one_triggername.l2GlobalExe
## get the script descriptions
try:
l1_scripts = servant.GetTScripts('l1',l1sName0,l1sVersion0,[])
l2_scripts = servant.GetTScripts('l2',l2sName0,l2sVersion0,[])
l3_scripts = servant.GetTScripts('l3',l3sName0,l3sVersion0,[])
except:
printit = ' Trigger Name (' + tnName + ',' + str(tnVersion) + ')'
emsg = "triggernames_change: error on servant.GetTScripts for "
emsg = emsg + printit + ' '
emsg = emsg + 'Level 1 SCRIPT (' + l1sName0 + ',' + str(l1sVersion0) + ')'
emsg = emsg + 'Level 2 SCRIPT (' + l2sName0 + ',' + str(l2sVersion0) + ')'
emsg = emsg + 'Level 3 SCRIPT (' + l3sName0 + ',' + str(l3sVersion0) + ')'
display_exc(emsg,sys.exc_info())
##!! this is not necessarily fatal
##!! display_footer()
##!! return
## place the lead element uid on the form and its number of parameters
print ''
print ''
## write the ELEMENT UID, allowing the name to be changed for INSERT
## and UPDATE (in case the autonaming would be different)
print '
'
## print ''
linktn = TDB_Report_Link('triggername',[tnName0,tnVersion0])
if taction=='INSERT':
## by default, the element name is determined by the client/server, so leave blank
if tnName0!='':
print """
Copy of Trigger Name/Version:
%s
""" % linktn
print '
New Trigger Name:'
print '
'
print '
Version:'
print ' *
'
else:
print """
Replacing Trigger Name/Version:
%s
""" % linktn
print '
New Trigger Name:'
print '
'
print '
, Version:'
print ' *
'
## write the description box
print '
'
print 'Description: '
print '
'
##??## the global crate and exe are defined at this level
##?? print '
'
## one row for every level
stat_curr = 'unknown'
history = ''
link = ''
if l1_scripts!=[]:
stat_curr = l1_scripts[0].statCurr
history = l1_scripts[0].history
link = TDB_Report_Link('L1Script',[l1sName0,l1sVersion0])
print '
'
print '
Level 1
'
print '
Script Name: '
print ' Version:'
if history!='': print ' Description: ' + history + ''
if link!='':
print ' Click here to view details of the Reference Level 1 Script '
print '' + link + ''
stat_curr = 'unknown'
history = ''
link = ''
if l2_scripts!=[]:
stat_curr = l2_scripts[0].statCurr
history = l2_scripts[0].history
link = TDB_Report_Link('L2Script',[l2sName0,l2sVersion0])
print '
'
print '
Level 2
'
print '
Script Name: '
print ' Version:'
if history!='': print ' Description: ' + history + ''
if link!='':
print ' Click here to view details of the Reference Level 2 Script '
print '' + link + ''
stat_curr = 'unknown'
history = ''
link = ''
if l3_scripts!=[]:
stat_curr = l3_scripts[0].statCurr
history = l3_scripts[0].history
link = TDB_Report_Link('L3Script',[l3sName0,l3sVersion0])
print '
'
print '
Level 3
'
print '
Script Name: '
print ' Version:'
if history!='': print ' Description: ' + history + ''
if link!='':
print ' Click here to view details of the Reference Level 3 Script '
print '' + link + ''
print '
'
## add the submit button here with some instructions
print """
"""
htopic = 'entername'
helpme = """Click here for additional help with: """ + \
TDB_Report_Link('helpme',[htopic],HELPDICT_HEADERS[htopic])
print '
%s
' % helpme
print """
"""
## create the links to the tdb_report interface to list valid terms
print '
'
print 'You must choose SCRIPT Name/Versions from existing SCRIPTS in the database.'
print ' NOTE !! right mouse click will list available* elements in a new window.'
print ' * You have chosen elements with Current Status among: '
print instatCurr
print 'on the previous form '
## now generate the links to look up existing level 1,2,3 scripts
for levels in ['1','2','3']:
link = TDB_Report_Link('L%sScript'%levels,[],'Level_%s_Scripts'%levels)
link = TDB_Report_Link_Add(link,[],instatCurr)
print ' '
print 'Click here for a complete list of available* '
print link + '. '
print '
'
display_footer()
return
## ###############################################################################
def triggernames_readchange():
"""Read the form written by triggernames_change, to INSERT or UPDATE a SCRIPT"""
## -------------------------------------------------------------------------------
## Connect to the CORBA service.
server,servant = connect_server()
## to get form content
form = FormContent()
## read in the preliminaries plus
## max_sTerms - the max possible # of terms on the form
try:
taction = form["taction"][0]
except:
emsg = 'triggernames_readchange: incomplete instructions.'
display_error(emsg,sys.exc_info())
return
instatCurr,instatForm = read_statcurr_menu(form)
## take care of taction=DELETE separately
if taction!='INSERT' and taction!='UPDATE':
display_error('triggernames_readchange: incorrect action')
return
## initialize/read in the reference term
oldtriggername = []
tnName0 = ''
tnVersion0 = 0
## an 'unused' reference term is required for an UPDATE
if taction=='UPDATE' or (form.has_key("tnName0") and form.has_key("tnVersion0")):
try:
tnName0 = form["tnName0"][0]
tnVersion0 = int(form["tnVersion0"][0])
except:
emsg = 'triggernames_readchange: incomplete reference triggername input'
display_error(emsg,sys.exc_info())
return
## make sure tnVersion0 is valid
if tnVersion0<=0:
display_error('Invalid reference element version input')
return
## re-Get the reference element
try:
trig_triggernames = servant.GetTTriggerNames(tnName0,tnVersion0,[])
oldtriggername = trig_triggernames[0]
oldname = oldtriggername.createUser
olddate = oldtriggername.createDate
except:
display_header('GetTTriggerNames Error')
emsg = 'triggernames_readchange error: error finding triggername for UPDATE'
display_exc(emsg,sys.exc_info())
display_footer()
return
## if UPDATE, see if the oldterm can still be modified
if oldtriggername.statUsed!='unused' and taction=='UPDATE':
display_header('UPDATE Trigger Names Error','Main_Menu')
print 'The SCRIPT listed below is no longer a candidate for modification. '
triggernames_report(oldtriggername)
display_colormap()
display_footer()
return
## if UPDATE, make sure the time on form is later than last modify_date
if taction=='UPDATE':
try:
ierror = check_modify_time(oldtriggername)
if ierror!='':
display_error(ierror)
return
except:
emsg = 'Error checking the form time for update conflict'
display_error(emsg,sys.exc_info())
return
## read in any general information on the new script
## nothing is required at this level
tnName = history = ''
if form.has_key("tnName"): tnName = form["tnName"][0]
if form.has_key("history"): history = form_history(form,"history")
l2GlobalCrate = 'global_crate'; l2GlobalExe = 'global_exe'
##?? if form.has_key("l2GlobalCrate"): l2GlobalCrate = form["l2GlobalCrate"][0]
##?? if form.has_key("l2GlobalExe"): l2GlobalExe = form["l2GlobalExe"][0]
## initialize status flags
statCurr = 'ambiguous'
statUsed = 'unused'
l1sName = l2sName = l3sName = ''
l1sVersion = l2sVersion = l3sVersion = 0
l1_scripts = []
l2_scripts = []
l3_scripts = []
printit = ''
## get the script records from the database
try:
l1sName = spacestripfirst(form['l1sName'][0])
l1sVersion = int(form['l1sVersion'][0])
l2sName = spacestripfirst(form['l2sName'][0])
l2sVersion = int(form['l2sVersion'][0])
l3sName = spacestripfirst(form['l3sName'][0])
l3sVersion = int(form['l3sVersion'][0])
printit = '[(' + l1sName + '/' + str(l1sVersion) + '),'
printit = printit + '[(' + l2sName + '/' + str(l2sVersion) + '),'
printit = printit + '[(' + l3sName + '/' + str(l3sVersion) + ')]'
l1_scripts = servant.GetTScripts('l1',l1sName,l1sVersion,[])
l2_scripts = servant.GetTScripts('l2',l2sName,l2sVersion,[])
l3_scripts = servant.GetTScripts('l3',l3sName,l3sVersion,[])
except:
display_header('GetTScripts ERROR','Main_Menu')
emsg = "triggernames_readchange: error on servant.GetTScripts for "
emsg = emsg +' Trigger Name (' + tnName + ')' + ' '
emsg = emsg + 'Level 1 SCRIPT (' + l1sName + ',' + str(l1sVersion) + ')'
emsg = emsg + 'Level 2 SCRIPT (' + l2sName + ',' + str(l2sVersion) + ')'
emsg = emsg + 'Level 3 SCRIPT (' + l3sName + ',' + str(l3sVersion) + ')'
if printit!='':
display_exc(emsg,sys.exc_info())
else:
display_exc(emsg,sys.exc_info())
display_footer()
return
## in any case, print the header at this point since some info messages may be needed
##old display_header('Trigger Name ' + taction + ' Report','Main_Menu')
display_header('Trigger Name ' + taction + ' Report','triggernames_change')
##!! print the oldname,olddate
##!! if taction=='UPDATE':
##!! print ' creator = ' + oldname
##!! print ' creation date = ' + olddate
## I'll need the dbname
dbname = 'anonymous'
if form.has_key("dbname"):
dbname = form["dbname"][0]
if dbname=='anonymous':
display_fatal('Improper identification')
return
dbdate = get_local_datetime()
##!! print the dbname,dbdate
##!! print ' current user = ' + dbname
##!! print ' current date = ' + dbdate
##!! print ' '
## make sure the scripts in this trigger are in the database
## enter the explicit names into the dictionary and s_name/versions
num_s1 = len(l1_scripts)
num_s2 = len(l2_scripts)
num_s3 = len(l3_scripts)
if num_s1<=0 or num_s2<=0 or num_s3<=0:
print ''
print 'Unable to find '
if num_s1<=0: print ' Level 1 '
if num_s2<=0: print ' Level 2 '
if num_s3<=0: print ' Level 3 '
print ' Script name/version(s) for : ' + printit
display_footer()
return
## get the statCurr of the scripts to determine the statCurr of the trigger
try:
statCurr = max([statCurr,l1_scripts[0].statCurr])
statCurr = max([statCurr,l2_scripts[0].statCurr])
statCurr = max([statCurr,l3_scripts[0].statCurr])
except:
emsg = "triggernames_readchange: error getting Script's statCurr."
display_exc(emsg,sys.exc_info())
display_footer()
return
error_list = []
for count,num,trig_scr,sN in ([1,num_s1,l1_scripts,l1sName],\
[2,num_s2,l2_scripts,l2sName],\
[3,num_s3,l3_scripts,l3sName]):
if num>=2:
print """
ALERT ! More than one Level %d script matched
the input string.
""" % count
print """ Here is a list of scripts matching your entry."""
for one_scr in trig_scr:
links = TDB_Report_Link('l%sScript'%str(count),[one_scr.sName,one_scr.sVersion])
print """
Level %s Script: %s
""" % (count,links)
if string.find(sN,'%')==-1:
links = TDB_Report_Link('l%sScript'%str(count),[trig_scr[0].sName,trig_scr[0].sVersion])
print """ The following latest (or most current) script
will be used: %s""" % (links)
else:
error_list.append(\
" Go back and enter a more complete Level %s script name."%str(count))
## if there were any errors finding scripts, trigger entry cannot continue
if error_list!=[]:
for errors in error_list:
display_exc(errors)
display_footer()
return
## complete the user/date part of the record
if taction=='INSERT':
cdate = dbdate
cuser = dbname
mdate = ''
muser = ''
else:
cdate = olddate
cuser = oldname
mdate = dbdate
muser = dbname
## complete the TScript struct
if taction=='UPDATE' and tnName==tnName0:
tnVersion = tnVersion0
else:
tnVersion = -1
## Get the complete script name and version
l1sName = l1_scripts[0].sName
l1sVersion = l1_scripts[0].sVersion
l2sName = l2_scripts[0].sName
l2sVersion = l2_scripts[0].sVersion
l3sName = l3_scripts[0].sName
l3sVersion = l3_scripts[0].sVersion
## check all string columns for double quotes before inserting into struct
emsg = ''
for aString in [tnName,statCurr,statUsed, history,\
l2GlobalCrate,l2GlobalExe,cuser,muser]:
if string.find(aString,'"')!=-1:
emsg = "Double quotes not allowed in the input string '%s'" % \
(aString)
display_exc(emsg)
display_footer()
return
## put together the proposed triggername struct here
one_triggername = TriggerDbServer.TTriggerName(tnName,tnVersion,statCurr,statUsed,\
l1sName,l1sVersion, l2sName,l2sVersion, l3sName,l3sVersion, history,\
l2GlobalCrate,l2GlobalExe,cdate,cuser,mdate,muser)
## this is where the new function for trigger name enforcement will be called
tnName,info_list,error_list = CheckTriggerName(servant,one_triggername)
## if there were any errors, trigger entry cannot continue
if error_list!=[]:
for errors in error_list:
display_exc(errors)
display_footer()
return
print ''
print ' Final tnName = %s. ' % tnName
## look for unbalanced < in description
temp_hist = check_html_history(history)
if temp_hist!='':
display_exc(temp_hist)
## if the history (description) is blank, construct a descriptions from L* scripts
if history=='':
l1shistory = l1_scripts[0].history
l2shistory = l2_scripts[0].history
l3shistory = l3_scripts[0].history
history = 'L1: ' + l1shistory + ' L2: ' + l2shistory + ' L3: ' + l3shistory
temp_hist = check_html_history(history)
if temp_hist!='':
display_exc(temp_hist)
## put the new name in the trigger name struct
one_triggername = TriggerDbServer.TTriggerName(tnName,tnVersion,
statCurr,statUsed,
l1sName,l1sVersion, l2sName,l2sVersion, l3sName,l3sVersion,
history, l2GlobalCrate,l2GlobalExe, cdate,cuser, mdate,muser)
## on insert or update, make sure that this is not a duplicate trigger
if taction=='INSERT' or taction=='UPDATE':
## find duplicate triggers:
duplicates = GetDuplicateTriggerNames(servant,one_triggername,[])
## eliminate the trigger being updated
if taction=='UPDATE':
duplicates2 = []
for dups in duplicates:
if dups.name==tnName0 and dups.version==tnVersion0:
print ' Trigger Name change detected '
pass
else:
duplicates2.append(dups)
duplicates = duplicates2
if duplicates!=[]:
print """
Duplicate trigger found !
It is generally misguided to create a new Trigger Name just to rename it.
Please use an existing trigger instead of defining a new one."""
for dups in duplicates:
linktn = TDB_Report_Link('triggername',[dups.name,dups.version])
print """ The trigger you have defined is identical
to TriggerName/Version: "%s" (status: "%s").""" % (linktn,dups.statCurr)
print ' '
## look for authorization to make a duplicate element
error_list = VerifyAuthorization(dbname,\
['triggermeister','simulatormeister'])
if error_list != []:
emsg = 'Abort %s of this trigger. A duplicate was found. '%taction
display_exc(emsg)
for errors in error_list:
display_exc(errors)
print ' '
display_footer()
return
else:
print """
Security override condition detected.
Continuing to create new script ..."""
## make the database entry
if taction=='INSERT':
try:
newVersion = servant.InsertTTriggerName(one_triggername)
print ''
print 'The new version number is '
print newVersion
print ' '
print 'InsertTTriggername: the Triggername was successfully entered into the database: '
print ''
## triggernames_report(one_triggername)
except:
print ' '
print 'InsertTTriggername Error: Failure to INSERT Triggername:'
print ' '
triggernames_report(one_triggername)
display_exc('',sys.exc_info())
display_colormap()
display_footer()
return
elif taction=='UPDATE':
try:
newVersion = servant.UpdateTTriggerName(oldtriggername,one_triggername)
print ''
print 'The new version number is '
print newVersion
print ' UpdateTTriggername: The TriggerName ' + oldtriggername.name + '/' + str(oldtriggername.version)
print ' has been deleted.
'
print ''
## triggernames_report(oldtriggername)
print ' It was replaced by this Triggername in the database: '
## triggernames_report(one_triggername)
except:
print ' '
print 'UpdateTTriggername Error: Failure to UPDATE Triggername: '
print ' '
triggernames_report(oldtriggername)
print ' with the following Triggername in the database: '
triggernames_report(one_triggername)
display_exc('',sys.exc_info())
display_colormap()
display_footer()
return
## look for lack of new version
if not newVersion or newVersion<=0:
newVersion = 0
print ' WARNING!!! The new version was not returned by Insert/UpdateTTriggerName'
print ' Getting all versions, using highest ranked version: '
## get the new entry
trig_triggernames = []
try:
trig_triggernames = servant.GetTTriggerNames(tnName,newVersion,[])
except:
print ''
print 'GetTTriggerNames Error: Failure to find new Triggername:'
print ' '
emsg = 'Final Check Error'
display_exc(emsg,sys.exc_info())
display_footer()
return
if trig_triggernames==[]:
print 'Final Check Error '
print 'The new Trigger Name cannot be found in the database. Something is wrong. '
print ' TRIGGER Name = ' + tnName + ', Version = ' + str(newVersion)
display_footer()
return
one_triggername = trig_triggernames[0]
if trig_triggernames!=[]:
print ' Database Report: '
triggernames_report(one_triggername)
## Make a quick update submit button for INSERT and UPDATE, which needs
## the following information on the form (in addition to function name in header)
## (assumes action='dummy' in *_change function)
print ''
print ''
print '' % one_triggername.name
print '' % one_triggername.version
print '' % one_triggername.name
print '' % one_triggername.version
print '
Click here to launch an immediate UPDATE to this Trigger Name: '
print ''
print '
Final check failed.'
print ' Unable to Get ' + printit
display_footer()
return
## ###############################################################################
def triggernames_report_text(one_triggername):
"This routine prints the trigger script (one_triggername) and its parameters"
## get/print the element information
tnName = one_triggername.name
tnVersion = one_triggername.version
statCurr = one_triggername.statCurr
statUsed = one_triggername.statUsed
l1sName = one_triggername.l1sName
l1sVersion = one_triggername.l1sVersion
l2sName = one_triggername.l2sName
l2sVersion = one_triggername.l2sVersion
l3sName = one_triggername.l3sName
l3sVersion = one_triggername.l3sVersion
history = one_triggername.history
## initialize the returned list
outtext = []
## add the element identification
outtext.append('tnName,tnVersion,stat_used,stat_curr,history')
outtext.append('l1sName,l1sVersion,l2sName,l2sVersion,l3sName,l3sVersion')
out = ''
for element in tnName,str(tnVersion),statUsed,statCurr,history:
if element==tnName:
out = out + element
elif element==history:
out = out + ', "' + element + '"'
else:
out = out + ', ' + element
for element in l1sName,str(l1sVersion),l2sName,str(l2sVersion),l3sName,str(l3sVersion):
out = out + ', ' + element
outtext.append(out)
return outtext
## ###############################################################################
def triggernames_print(atriggername):
"print out the triggername information in the struct atriggername"
## Usage:
## triggernames_print(script)
print ' tnName: '
print atriggername.name
print ' tnVersion: '
print atriggername.version
print ' Current Status: '
print atriggername.statCurr
print ' Usage Status: '
print atriggername.statUsed
print ' Level 1 Script Name/Version: '
print atriggername.l1sName + ' / '
print atriggername.l1sVersion
print ' Level 2 Script Name/Version: '
print atriggername.l2sName + ' / '
print atriggername.l2sVersion
print ' Level 3 Script Name/Version: '
print atriggername.l3sName + ' / '
print atriggername.l3sVersion
print ' History: '
print atriggername.history
print ' l2GlobalCrate: '
print atriggername.l2GlobalCrate
print ' l2GlobalExe: '
print atriggername.l2GlobalExe
print ' :createDate '
print atriggername.createDate
print ' :createUser '
print atriggername.createUser
print ' :modifyDate '
print atriggername.modifyDate
print ' :modifyUser '
print atriggername.modifyUser
print '
'
return
## ###############################################################################
def GetDuplicateTriggerNames(servant,atrigger,namespace=[]):
"""Return all duplicate trigger definitions to the input trigger atrigger
in the input namespace."""
## -------------------------------------------------------------------------------
## get duplicate triggers the db server way:
duplicates = []
try:
trig_triggernames = servant.GetTTriggerNames('',0,namespace)
for a_triggername in trig_triggernames:
if atrigger.l1sName == a_triggername.l1sName and \
atrigger.l1sVersion == a_triggername.l1sVersion and \
atrigger.l2sName == a_triggername.l2sName and \
atrigger.l2sVersion == a_triggername.l2sVersion and \
atrigger.l3sName == a_triggername.l3sName and \
atrigger.l3sVersion == a_triggername.l3sVersion and \
atrigger.l2GlobalCrate == a_triggername.l2GlobalCrate and \
atrigger.l2GlobalExe == a_triggername.l2GlobalExe:
## if this is the input trigger, don't worry
if atrigger.name==a_triggername.name and \
atrigger.version==a_triggername.version:
pass
else:
duplicates.append(a_triggername)
except:
display_exc('GetDuplicateTriggerNames: error in GetTTriggerNames', sys.exc_info())
display_footer()
return
return duplicates
## ###############################################################################
def CheckTriggerName(servant,atrigger):
"""check the trigger name in the atrigger triggername struct
for conformity to trigger naming rules.
Return a new triggername, a list of info messages, and a list of errors."""
## -------------------------------------------------------------------------------
info_list = []
error_list = []
tnName = atrigger.name
if DEBUG>=2: print '
in CheckTriggerName : tnName is ' + tnName
## make a database connection
aconn = getcon_read()
## remove leading or trailing spaces
if tnName!='':
while tnName[:1]==' ':
info_list.append('')
sTemp = tnName[1:]
tnName = sTemp
while tnName[len(tnName)-1:]==' ':
info_list.append('')
sTemp = tnName[:len(tnName)-1]
tnName = sTemp
## make sure the entered name contains no ^ symbols
if string.find(tnName,'^')!=-1:
emsg = ' ' + \
'Illegal "^" character in Trigger Name "%s" ! ' % \
tnName + '
'
error_list.append(emsg)
## Replace any internal spaces with a different character
if string.find(tnName,' ')!=-1:
info_list.append('')
tnName = re.sub(' ','_',tnName)
## get the script names, versions for autonaming
l1sName = atrigger.l1sName
l1sVersion = atrigger.l1sVersion
l2sName = atrigger.l2sName
l2sVersion = atrigger.l2sVersion
l3sName = atrigger.l3sName
l3sVersion = atrigger.l3sVersion
## if tnName is empty,
if tnName=='':
## try to find a trigger that used the same script names but perhaps other versions
sql = """SELECT tn_name,tn_version,tn_cdate FROM v_tlists
WHERE l1s_name='%s' AND l2s_name='%s' AND l3s_name='%s'
ORDER BY tn_cdate desc""" % (l1sName,l2sName,l3sName)
data_tn = getdata(aconn, sql)
if data_tn:
info_list.append(' Candidate trigger name found w/same l1l2l3 scripts:')
for tn_name,tn_version,tn_cdate in data_tn:
linktn = TDB_Report_Link('triggername',[tn_name,tn_version])
info_list.append('
Trigger Name/Version: %s
' % (linktn))
tnName = data_tn[0][0]
## if tnName is still empty,
## loop over terms again to construct a trigger name
## even though it might be too long (eliminate none, null, L2 Pass100, L3 ps1):
if tnName=='':
newName = ''
## initialize the new name to the L1 Script name
if l1sName!='none' and l1sName!='null':
newName = l1sName
## Add the L2 Script name (if it is not none, pass100, or null)
if l2sName!='none' and l2sName!='null' and string.upper(l2sName)!='PASS100':
if newName!='': newName = newName + '_'
newName = newName + l2sName
## Add the L3 Script name (if significant)
if l3sName!='none' and l3sName!='null' and l3sName!='ps1' and \
l3sName!='pf1' and l3sName!='mp1_pf1':
if newName!='': newName = newName + '_'
newName = newName + l3sName
## set the trigger name to the constructed new name or the L3 script name
if newName!='':
tnName = newName
else:
tnName = l3sName
## truncate the constructed name to 16 characters
tnName = tnName[0:15]
print """
No Trigger Name entered? This program constructed Trigger Name: "%s"
from Script information and then truncated it to 16 characters.
This name is not legal if it does not satisfy L3 ScriptRunner parsing rules
(only alpha, numeric, and underscores are allowed in Trigger Names).
Please make sure you know the rules and UPDATE the Name NOW
before you include this Trigger in a Trigger List. """ % tnName
## I need the scripts to look for prescales at L2 or L3,
## to look for conditions at L2 or L3 (not passall gets uppercase)
try:
l1_scripts = servant.GetTScripts('l1',l1sName,l1sVersion,[])
l2_scripts = servant.GetTScripts('l2',l2sName,l2sVersion,[])
l3_scripts = servant.GetTScripts('l3',l3sName,l3sVersion,[])
except:
error_list.append(emsg)
for err in sys.exc_info():
error_list.append(err)
## Add '_NOLUM' to triggernames for triggers which are unnormalizable
## Remove _NOLUM from the tnName if it is there (and anything after it)
## in order to solve the multiple _NOLUM problem and to prevent counting of
## _NOLUM characters in the trigger name length.
## _NOLUM characters are added later only under L2 or L3 prescale conditions
## and it otherwise not allowed in the trigger name
locps = max(-1,string.find(string.upper(tnName),'_NOLUM'))
if locps==-1:
tn1 = tnName
else:
tn1 = tnName[:locps]
print ''
tnName = tn1
locps = max(-1,string.find(string.upper(tnName),'NOLUM'))
if locps==-1:
tn1 = tnName
else:
tn1 = tnName[:locps]
print ''
tnName = tn1
## make sure there are terms at L3
if len(l3_scripts[0].terms)<1:
emsg = """CheckTriggerName: error getting terms in script for
Trigger Name ("%s") Level 3 SCRIPT ("%s","%s").
No terms found """ % (tnName,l3sName,l3sVersion)
error_list.append(emsg)
## make sure there are terms at L2 unless this is a null script
if len(l2_scripts[0].terms)<1 and string.upper(l2sName)!='NULL':
emsg = """CheckTriggerName: error getting terms in script for
Trigger Name ("%s") Level 2 SCRIPT ("%s","%s").
No terms found """ % (tnName,l2sName,l2sVersion)
error_list.append(emsg)
## assume there is no prescale, then look for a prescale at L2 and L3
is_there_nolum = 'no'
for sTerms in l2_scripts[0].terms:
try:
tName = sTerms._v.tName
tVersion = sTerms._v.tVersion
l2_terms = servant.GetTTerms('l2',tName,tVersion,[])
oName = l2_terms[0].tValues[0].name
if oName=='RANDOMPASS':
for pars in l2_terms[0].tValues:
if pars.parName=='PASSPERCENT' and pars.pvValue!='100.':
print '
Level 2 prescale found - TriggerName will be altered. '
is_there_nolum = 'yes'
except:
emsg = """triggernames_readchange: error on servant.GetTTerms
Trigger Name ("%s") Level 2 SCRIPT ("%s","%s")
Level 2 TERM ("%s","%s")
""" % (tnName,l2sName,l2sVersion,tName,tVersion)
error_list.append(emsg)
for err in sys.exc_info():
error_list.append(err)
for sTerms in l3_scripts[0].terms:
try:
tName = sTerms._v.tName
tVersion = sTerms._v.tVersion
l3_terms = servant.GetTTerms('l3',tName,tVersion,[])
oName = l3_terms[0].tValues[0].name
if oName=='L3FPreScale':
for pars in l3_terms[0].tValues:
if pars.parName=='prescale' and pars.pvValue!='1.':
print '
Level 3 prescale found. '
is_there_nolum = 'yes'
if oName=='L3FMarkAndPass' and len(l3_scripts[0].terms)==1:
print '
Level 3 MarkAndPass filter found. '
is_there_nolum = 'yes'
except:
emsg = """triggernames_readchange: error on servant.GetTTerms
Trigger Name ("%s") Level 3 SCRIPT ("%s","%s")
Level 3 TERM ("%s","%s")
""" % (tnName,l3sName,l3sVersion,tName,tVersion)
error_list.append(emsg)
for err in sys.exc_info():
error_list.append(err)
#################
## 12/08/05 mvi: new code for NOLUM:
## Need to check is any neoterms in L1 script have xrelated=NOLUM.
## If we find any, then we MUST set is_there_nolum = 'yes' and _NOLUM is added
## to the Name AFTER the trigger name length is checked
##
## To get the records, we use the V_L1_SCRIPTS view for the query.
##
qstring = """SELECT X_RELATED FROM V_L1_SCRIPTS where
s_name = '%s' and
s_version = %d and
x_related = 'nolum'""" % (l1sName,l1sVersion)
thedata = getdata(aconn, qstring)
for xR in thedata:
is_there_nolum = 'yes'
if DEBUG>=2:
print '
Found %s neoterms with NOLUM xrelated flag ' % len(thedata)
print '
Setting is_there_nolum to yes '
if is_there_nolum == 'no' and DEBUG>=2:
print '
No neoterms found with NOLUM xrelated flag = '
## 12/08/05 mvi: end of changes (checked by EG)
#################
## if a prescale is found, then append the _NOLUM string
appendme = ''
if is_there_nolum == 'yes':
appendme = '_NOLUM'
if appendme!='':
print """ This is not a normalizable trigger.
The _NOLUM string has been added to the trigger name to reflect this
(the addition of _NOLUM does not count against
the 16 character limit on trigger names)."""
tnName = tnName + appendme
## reduce the namespace:
if string.find(tnName,'l1')!=-1:
info_list.append('')
tnName = re.sub('l1','L1',tnName)
if string.find(tnName,'l2')!=-1:
info_list.append('')
tnName = re.sub('l2','L2',tnName)
if string.find(tnName,'l3')!=-1:
info_list.append('')
tnName = re.sub('l3','L3',tnName)
if string.find(string.upper(tnName),'MIN')!=-1 and \
string.find(string.upper(tnName),'BIAS')==-1:
info_list.append('')
tnName = re.sub('MIN','MN',tnName)
tnName = re.sub('Min','MN',tnName)
tnName = re.sub('min','mn',tnName)
if string.find(string.upper(tnName),'LOW')!=-1:
info_list.append('')
tnName = re.sub('LOW','LO',tnName)
tnName = re.sub('Low','LO',tnName)
tnName = re.sub('low','lo',tnName)
if string.find(string.upper(tnName),'MED')!=-1:
info_list.append('')
tnName = re.sub('MED','MD',tnName)
tnName = re.sub('Med','MD',tnName)
tnName = re.sub('med','md',tnName)
if string.find(string.upper(tnName),'MID')!=-1:
info_list.append('')
tnName = re.sub('MID','MD',tnName)
tnName = re.sub('Mid','MD',tnName)
tnName = re.sub('mid','md',tnName)
if string.find(string.upper(tnName),'HIGH')!=-1:
info_list.append('')
tnName = re.sub('HIGH','HI',tnName)
tnName = re.sub('High','HI',tnName)
tnName = re.sub('high','hi',tnName)
if string.find(string.upper(tnName),'MAX')!=-1:
info_list.append('')
tnName = re.sub('MAX','MX',tnName)
tnName = re.sub('Max','MX',tnName)
tnName = re.sub('max','mx',tnName)
if string.find(string.upper(tnName),'JET')!=-1:
info_list.append('')
tnName = re.sub('JET','JT',tnName)
tnName = re.sub('Jet','JT',tnName)
tnName = re.sub('jet','jt',tnName)
if string.find(string.upper(tnName),'MUON')!=-1:
info_list.append('')
tnName = re.sub('MUON','MU',tnName)
tnName = re.sub('Muon','MU',tnName)
tnName = re.sub('muon','mu',tnName)
if string.find(string.upper(tnName),'MUO')!=-1:
info_list.append('')
tnName = re.sub('MUO','MU',tnName)
tnName = re.sub('Muo','MU',tnName)
tnName = re.sub('muo','mu',tnName)
if string.find(string.upper(tnName),'JET')!=-1:
info_list.append('')
tnName = re.sub('JET','JT',tnName)
tnName = re.sub('Jet','JT',tnName)
tnName = re.sub('jet','jt',tnName)
if string.find(string.upper(tnName),'TRACK')!=-1:
info_list.append('')
tnName = re.sub('TRACK','TRK',tnName)
tnName = re.sub('Track','TRK',tnName)
tnName = re.sub('track','trk',tnName)
## remove square brackets (added when L1 Script contains vetos on neoterms):
try:
if (string.find(tnName,'[')!=-1 or string.find(tnName,']')!=-1):
info_list.append('')
tnName = string.replace(tnName,'[','_')
tnName = string.replace(tnName,']','_')
except:
for err in sys.exc_info():
error_list.append(err)
## remove double underscores
while string.find(tnName,'__')!=-1:
tnName = string.replace(tnName,'__','_')
## make sure the trigger name is not too long
## unless it is a zero or min_bias trigger or _NOLUM has been appended
if ((tnName[:len('min_bias')]=='min_bias' or \
tnName[:len('zero_bias')]=='zero_bias' or \
tnName[:len('xrel_bias')]=='xrel_bias') and \
len(tnName)>26) \
or \
(tnName[:len('min_bias')]!='min_bias' and \
tnName[:len('zero_bias')]!='zero_bias' and \
tnName[:len('xrel_bias')]!='xrel_bias'and \
len(tnName)>16 and \
string.find(tnName[len(tnName)-len('_NOLUM'):len(tnName)],'_NOLUM')==-1):
emsg = ' Trigger Name too long !\
%s
' % tnName
error_list.append(emsg)
error_list.append(' The trigger name must be 16 characters or less ' + \
'(thumbnail requirement). Go back to enter a shorter name.')
elif string.find(tnName[len(tnName)-len('_NOLUM'):len(tnName)],'_NOLUM')!=-1:
print ' The modified trigger name length is %d. ' % len(tnName)
else:
print ' The trigger name length is %d.' % len(tnName)
## upper case all names unless they use only L3FPrescale(1.) or L3FPassFraction(1.)
## and either no L2 (none/1) or L2 RANDOMPASS(PASSPERCENT=100.,TOOL=COMMISSION)
L3 = 'yes'
L2 = 'yes'
if tnName!=string.upper(tnName) and \
len(l3_scripts[0].terms)<=2 and len(l2_scripts[0].terms)==1:
## - move try except to include the loop over l3_scripts[0].terms
try:
for sTerms in l3_scripts[0].terms:
tName = sTerms._v.tName
tVersion = sTerms._v.tVersion
l3_terms = servant.GetTTerms('l3',tName,tVersion,[])
oName = l3_terms[0].tValues[0].name
if oName=='L3FPreScale':
for pars in l3_terms[0].tValues:
if pars.parName=='prescale' and pars.pvValue=='1.':
L3 = 'no'
elif oName=='L3FPassFraction':
for pars in l3_terms[0].tValues:
if pars.parName=='passFraction' and pars.pvValue=='1.':
L3 = 'no'
elif oName=='L3FMarkAndPass':
for pars in l3_terms[0].tValues:
if pars.parName=='pass_1_of_n' and pars.pvValue=='1.':
L3 = 'no'
else:
L3 = 'yes'
break
except:
emsg = """triggernames_readchange: error on GetTTerms
Trigger Name ("%s") Level 3 SCRIPT ("%s","%s")
Level 3 TERM ("%s","%s")
""" % (tnName,l3sName,l3sVersion,tName,tVersion)
error_list.append(emsg)
for err in sys.exc_info():
error_list.append(err)
##??
if DEBUG==3:
print '
DEBUG==3 CheckTriggerName: finished loop over l3_scripts[0].terms'
## - move try except to include the loop over l2_scripts[0].terms
try:
for sTerms in l2_scripts[0].terms:
tName = sTerms._v.tName
tVersion = sTerms._v.tVersion
l2_terms = servant.GetTTerms('l2',tName,tVersion,[])
oName = l2_terms[0].tValues[0].name
if oName=='RANDOMPASS':
for pars in l2_terms[0].tValues:
if pars.parName=='PASSPERCENT' and pars.pvValue=='100.':
L2 = 'no'
if oName=='RANDOMPASS' and L2 == 'no':
L2 = 'yes'
for pars2 in l2_terms[0].tValues:
if pars2.parName=='TOOL' and pars2.pvValue=='COMMISSION':
L2 = 'no'
except:
emsg = """triggernames_readchange: error on GetTTerms
Trigger Name ("%s") Level 2 SCRIPT ("%s","%s")
Level 2 TERM ("%s","%s")
""" % (tnName,l2sName,l2sVersion,tName,tVersion)
error_list.append(emsg)
for err in sys.exc_info():
error_list.append(err)
##??
if DEBUG==3:
print '
DEBUG==3 CheckTriggerName: finished loop over l2_scripts[0].terms'
if L2=='yes':
if l2sName=='none':
L2 = 'no'
## For L1 only triggers (no L2 or L3 requirements),
## look to see if this trigger qualifies for a zero_bias and xrel_bias name.
## The rules for min_bias_* names are not coded here since they are more difficult
## to code precisely.
if L2 == 'no' and L3 == 'no':
aconn = getcon_read()
sql = """SELECT NT_NAME,X_RELATED FROM V_L1_SCRIPTS
WHERE s_name='%s' AND S_VERSION='%d'""" % (l1sName,l1sVersion)
data_tn = getdata(aconn, sql)
is_zero_bias = 'yes'
is_xrel_bias = 'yes'
for nt_name,xrel in data_tn:
if xrel == 'no':
is_zero_bias = 'no'
is_xrel_bias = 'no'
break
if xrel == 'nolum':
is_zero_bias = 'no'
## a trigger can't qualify as both zero and xrel_bias
if is_xrel_bias == 'yes' and is_zero_bias == 'yes':
is_xrel_bias = 'no'
## loop over the 2 special bias possibilities to tell user trigger is special
for is_bias,the_bias,what_bias in \
([is_zero_bias,'zero_bias',"x_related='yes'"],\
[is_xrel_bias,'xrel_bias',"x_related='yes' and 'nolum'"]):
if is_bias == 'yes':
print """ This L1 only trigger qualifies as a %s trigger
(contains strictly %s neoterms).""" % (the_bias,what_bias)
## Fix the names if the user used the wrong *bias in the name
## if xrel_bias and tn name contains zero_bias, change it to xrel_bias
if the_bias=='xrel_bias' and string.find(tnName,'zero_bias')!=-1:
tnName = string.replace(tnName,'zero_bias','xrel_bias')
## if zero_bias and tn name contains xrel_bias, change it to zero_bias
if the_bias=='zero_bias' and string.find(tnName,'xrel_bias')!=-1:
tnName = string.replace(tnName,'xrel_bias','zero_bias')
## print a message confirming *bias criteria was met. user may not know.
if string.find(tnName,the_bias)==-1:
linkzb = TDB_Report_Link('triggername',\
['%s%s'%(the_bias,'%')],'%s%s triggers'%(the_bias,'%'))
linkzb = TDB_Report_Link_Add(linkzb,['elefmt'],['list'])
print """ You may choose to name the trigger %s_*,
where the * is representative of this trigger's neoterms.
Make the trigger name logically consistent
with and distinct from other %s
(and can be up to 26 characters long).""" % (the_bias,linkzb)
## make sure this trigger is not named a zb or xb name if it does not qualify
for is_bias,the_bias in ([is_zero_bias,'zero_bias'],\
[is_xrel_bias,'xrel_bias']):
if string.find(tnName,the_bias)!=-1 and is_bias=='no':
print """This trigger does NOT qualify as a %s trigger.""" % the_bias
tnName = string.replace(tnName,"%s%s"%(the_bias,'_'),'')
tnName = string.replace(tnName,the_bias,'')
if tnName == '':
tnName = l1sName[0:15]
print """
This program constructed Trigger Name: "%s"
from the L1 Script name and then truncated it to 16 characters.
This name is not legal if it does not satisfy L3 ScriptRunner parsing rules
(only alpha, numeric, and underscores are allowed in Trigger Names).
Please make sure you know the rules and update the Name NOW
before you include this Trigger in a Trigger List. """ % tnName
## For triggers with any L2 or L3 filtering: Upper case the trigger name.
tn1 = tnName
if L2 == 'yes' or L3 == 'yes':
tnName = string.upper(tn1)
if DEBUG==3:
print "
DEBUG==3 CheckTriggerName: final trigger name '%s'" % tnName
info_list.append('')
return tnName,info_list,error_list