CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Functions | Variables
lumiValidate Namespace Reference

Functions

def getValidationData
 
def insertupdateValidationData
 
def main
 

## Main Program

More...
 

Variables

string VERSION = '1.00'
 

Function Documentation

def lumiValidate.getValidationData (   dbsession,
  run = None,
  cmsls = None 
)
retrieve validation data per run or all
input: runnum, if not runnum, retrive all
output: {run:[[cmslsnum,flag,comment]]}

Definition at line 9 of file lumiValidate.py.

References lumiQueryAPI.validation().

Referenced by main().

9 
10 def getValidationData(dbsession,run=None,cmsls=None):
11  '''retrieve validation data per run or all
12  input: runnum, if not runnum, retrive all
13  output: {run:[[cmslsnum,flag,comment]]}
14  '''
15  result={}
16  try:
17  dbsession.transaction().start(True)
18  schema=dbsession.nominalSchema()
19  queryHandle=dbsession.nominalSchema().newQuery()
20  result=lumiQueryAPI.validation(queryHandle,run,cmsls)
21  del queryHandle
22  dbsession.transaction().commit()
23  except Exception, e:
24  dbsession.transaction().rollback()
25  del dbsession
26  raise Exception, 'lumiValidate.getValidationData:'+str(e)
27  return result
Definition: start.py:1
def getValidationData
Definition: lumiValidate.py:9
def lumiValidate.insertupdateValidationData (   dbsession,
  data 
)
input: data {run:[[ls,status,comment]]}

Definition at line 28 of file lumiValidate.py.

References lumiQueryAPI.lumisummaryByrun(), and nameDealer.lumivalidationTableName().

Referenced by main().

28 
29 def insertupdateValidationData(dbsession,data):
30  '''
31  input: data {run:[[ls,status,comment]]}
32  '''
33  toreplacenocomment=[]#[[('RUNNUM',runnum),('CMSLSNUM',cmslsnum),('FLAG',flag)],[]]
34  toreplacewcomment=[]#[[('RUNNUM',runnum),('CMSLSNUM',cmslsnum),('FLAG',flag),('COMMENT',comment)],[]]
35  toinsert=[] #[[('RUNNUM',runnum),('CMSLSNUM',cmslsnum),('FLAG',flag),('COMMENT',comment)],[]]
36  try:
37  dbsession.transaction().start(True)
38  dbutil=dbUtil.dbUtil(dbsession.nominalSchema())
39  for run,alllsdata in data.items():
40  lsselection=[]
41  if len(alllsdata)==0:#cross query lumisummary to get all the cmslsnum for this run,then insert all to default
42  queryHandle=dbsession.nominalSchema().newQuery()
43  lumisummaryData=lumiQueryAPI.lumisummaryByrun(queryHandle,run,'0001')
44  del queryHandle
45  for lumisummary in lumisummaryData:
46  if lumisummary[-1]==1:#cmsalive
47  lsselection.append([lumisummary[0],'UNKNOWN','NA'])
48  else:
49  lsselection=alllsdata
50  if len(lsselection)==0:
51  print 'no LS found for run '+str(run)+' do nothing'
52  continue
53  for lsdata in lsselection:
54  condition='RUNNUM=:runnum AND CMSLSNUM=:cmslsnum'
55  conditionDefDict={}
56  conditionDefDict['runnum']='unsigned int'
57  conditionDefDict['cmslsnum']='unsigned int'
58  conditionDict={}
59  conditionDict['runnum']=run
60  conditionDict['cmslsnum']=lsdata[0]
61  if dbutil.existRow(nameDealer.lumivalidationTableName(),condition,conditionDefDict,conditionDict):
62  if len(lsdata)>2 and lsdata[2]:
63  toreplacewcomment.append([('runnum',run),('cmslsnum',lsdata[0]),('flag',lsdata[1]),('comment',lsdata[2])])
64  else:
65  toreplacenocomment.append([('runnum',run),('cmslsnum',lsdata[0]),('flag',lsdata[1]),('comment','')])
66  else:
67  if len(lsdata)>2 and lsdata[2]:
68  toinsert.append([('RUNNUM',run),('CMSLSNUM',lsdata[0]),('FLAG',lsdata[1]),('COMMENT',lsdata[2])])
69  else:
70  toinsert.append([('RUNNUM',run),('CMSLSNUM',lsdata[0]),('FLAG',lsdata[1]),('COMMENT','N/A')])
71  dbsession.transaction().commit()
72  #print 'toreplace with comment ',toreplacewcomment
73  #print 'toreplace without comment ',toreplacenocomment
74  #print 'toinsert ',toinsert
75  #perform insert
76  if len(toinsert)!=0:
77  dbsession.transaction().start(False)
78  dbutil=dbUtil.dbUtil(dbsession.nominalSchema())
79  tabrowDef=[]
80  tabrowDef.append(('RUNNUM','unsigned int'))
81  tabrowDef.append(('CMSLSNUM','unsigned int'))
82  tabrowDef.append(('FLAG','string'))
83  tabrowDef.append(('COMMENT','string'))
84  dbutil.bulkInsert(nameDealer.lumivalidationTableName(),tabrowDef,toinsert)
85  dbsession.transaction().commit()
86  #perform update with comment
87  if len(toreplacewcomment)!=0:
88  dbsession.transaction().start(False)
89  dbutil=dbUtil.dbUtil(dbsession.nominalSchema())
90  updateAction='FLAG=:flag,COMMENT=:comment'
91  updateCondition='RUNNUM=:runnum and CMSLSNUM=:cmslsnum'
92  bindvarDef=[]
93  bindvarDef.append(('flag','string'))
94  bindvarDef.append(('comment','string'))
95  bindvarDef.append(('runnum','unsigned int'))
96  bindvarDef.append(('cmslsnum','unsigned int'))
97  dbutil.updateRows(nameDealer.lumivalidationTableName(),updateAction,updateCondition,bindvarDef,toreplacewcomment)
98  dbsession.transaction().commit()
99  #perform update with NO comment
100  if len(toreplacenocomment)!=0:
101  dbsession.transaction().start(False)
102  dbutil=dbUtil.dbUtil(dbsession.nominalSchema())
103  updateAction='FLAG=:flag'
104  updateCondition='RUNNUM=:runnum and CMSLSNUM=:cmslsnum'
105  bindvarDef=[]
106  bindvarDef.append(('flag','string'))
107  bindvarDef.append(('runnum','unsigned int'))
108  bindvarDef.append(('cmslsnum','unsigned int'))
109  dbutil.updateRows(nameDealer.lumivalidationTableName(),updateAction,updateCondition,bindvarDef,toreplacenocomment)
110  dbsession.transaction().commit()
111  except Exception, e:
112  dbsession.transaction().rollback()
113  del dbsession
114  raise Exception, 'lumiValidate.insertupdateValidationData:'+str(e)
Definition: start.py:1
def lumivalidationTableName
Definition: nameDealer.py:56
def insertupdateValidationData
Definition: lumiValidate.py:28
def lumiValidate.main ( )

## Main Program

Definition at line 123 of file lumiValidate.py.

References python.multivaluedict.append(), getValidationData(), insertupdateValidationData(), strip(), and CommonUtil.tolegalJSON().

124 def main():
125  parser = argparse.ArgumentParser(prog=os.path.basename(sys.argv[0]),description = "Lumi Validation",formatter_class=argparse.ArgumentDefaultsHelpFormatter)
126  allowedActions = ['batchupdate','update','dump']
127  allowedFlags = ['UNKNOWN','GOOD','BAD','SUSPECT']
128  # parse arguments
129  parser.add_argument('action',choices=allowedActions,help='command actions')
130  parser.add_argument('-c',dest='connect',action='store',required=True,help='connect string to lumiDB')
131  parser.add_argument('-P',dest='authpath',action='store',required=True,help='path to authentication file')
132  parser.add_argument('-i',dest='inputfile',action='store',help='lumi range selection file,required for batchupdate action')
133  parser.add_argument('-o',dest='outputfile',action='store',help='output to csv file')
134  parser.add_argument('-r',dest='runnumber',action='store',type=int,help='run number,optional')
135  parser.add_argument('-runls',dest='runls',action='store',help='selection string,optional. Example [1234:[],4569:[1,1],[2,100]]')
136  parser.add_argument('-flag',dest='flag',action='store',default='UNKNOWN',help='flag string,optional')
137  parser.add_argument('--verbose',dest='verbose',action='store_true',help='verbose mode for printing' )
138  parser.add_argument('--debug',dest='debug',action='store_true',help='debug')
139  options=parser.parse_args()
140  if options.flag.upper() not in allowedFlags:
141  print 'unrecognised flag ',options.flag.upper()
142  raise
143  os.environ['CORAL_AUTH_PATH'] = options.authpath
144  connectstring=options.connect
145  svc = coral.ConnectionService()
146  msg=coral.MessageStream('')
147  if options.debug:
148  msg.setMsgVerbosity(coral.message_Level_Debug)
149  else:
150  msg.setMsgVerbosity(coral.message_Level_Error)
151  session=svc.connect(connectstring,accessMode=coral.access_Update)
152  session.typeConverter().setCppTypeForSqlType("unsigned int","NUMBER(10)")
153  session.typeConverter().setCppTypeForSqlType("unsigned long long","NUMBER(20)")
154 
155  result={}#parsing result {run:[[ls,status,comment]]}
156  if options.debug :
157  msg=coral.MessageStream('')
158  msg.setMsgVerbosity(coral.message_Level_Debug)
159 
160  if options.action=='batchupdate':
161  #populate from csv file, require -i argument
162  if not options.inputfile:
163  print 'inputfile -i option is required for batchupdate'
164  raise
165  csvReader=csv.reader(open(options.inputfile),delimiter=',')
166  for row in csvReader:
167  if len(row)==0:
168  continue
169  fieldrun=str(row[0]).strip()
170  fieldls=str(row[1]).strip()
171  fieldstatus=row[2]
172  fieldcomment=row[3]
173  if not result.has_key(int(fieldrun)):
174  result[int(fieldrun)]=[]
175  result[int(fieldrun)].append([int(fieldls),fieldstatus,fieldcomment])
176  insertupdateValidationData(session,result)
177  if options.action=='update':
178  #update flag interactively, require -runls argument
179  #runls={run:[]} populate all CMSLSNUM found in LUMISUMMARY
180  #runls={run:[[1,1],[2,5]],run:[[1,1],[2,5]]}
181  #default value
182  if not options.runls and not options.runnumber:
183  print 'option -runls or -r is required for update'
184  raise
185  if not options.flag:
186  print 'option -flag is required for update'
187  raise
188  if options.flag.upper() not in allowedFlags:
189  print 'unrecognised flag ',options.flag
190  raise
191  if options.runnumber:
192  runlsjson='{"'+str(options.runnumber)+'":[]}'
193  elif options.runls:
194  runlsjson=CommonUtil.tolegalJSON(options.runls)
195  sparser=selectionParser.selectionParser(runlsjson)
196  runsandls=sparser.runsandls()
197  commentStr='NA'
198  statusStr=options.flag
199  for run,lslist in runsandls.items():
200  if not result.has_key(run):
201  result[run]=[]
202  for ls in lslist:
203  result[run].append([ls,statusStr,commentStr])
204  insertupdateValidationData(session,result)
205  if options.action=='dump':
206  if options.runls or options.inputfile:
207  if options.runls:
208  runlsjson=CommonUtil.tolegalJSON(options.runls)
209  sparser=selectionParser.selectionParser(runlsjson)
210  runsandls=sparser.runsandls()
211  if options.inputfile:
212  p=inputFilesetParser.inputFilesetParser(options.inputfile)
213  runsandls=p.runsandls()
214  for runnum,lslist in runsandls.items():
215  dataperrun=getValidationData(session,run=runnum,cmsls=lslist)
216  if dataperrun.has_key(runnum):
217  result[runnum]=dataperrun[runnum]
218  else:
219  result[runnum]=[]
220  else:
221  result=getValidationData(session,run=options.runnumber)
222  runs=result.keys()
223  runs.sort()
224  if options.outputfile:
225  r=csvReporter.csvReporter(options.outputfile)
226  for run in runs:
227  for perrundata in result[run]:
228  r.writeRow([str(run),str(perrundata[0]),perrundata[1],perrundata[2]])
229  else:
230  for run in runs:
231  print '== ='
232  if len(result[run])==0:
233  print str(run),'no validation data'
234  continue
235  for lsdata in result[run]:
236  print str(run)+','+str(lsdata[0])+','+lsdata[1]+','+lsdata[2]
237 
238  del session
del svc
void strip(std::string &input, const std::string &blanks=" \n\t")
Definition: stringTools.cc:16
def tolegalJSON
Definition: CommonUtil.py:105
def main
## Main Program
def insertupdateValidationData
Definition: lumiValidate.py:28
def getValidationData
Definition: lumiValidate.py:9

Variable Documentation

string lumiValidate.VERSION = '1.00'

Definition at line 2 of file lumiValidate.py.