7 from RecoLuminosity.LumiDB
import inputFilesetParser,selectionParser,csvReporter,argparse,CommonUtil,dbUtil,nameDealer,lumiQueryAPI
10 '''retrieve validation data per run or all
11 input: runnum, if not runnum, retrive all
12 output: {run:[[cmslsnum,flag,comment]]}
16 dbsession.transaction().
start(
True)
17 schema=dbsession.nominalSchema()
18 queryHandle=dbsession.nominalSchema().newQuery()
21 dbsession.transaction().commit()
23 dbsession.transaction().rollback()
25 raise Exception,
'lumiValidate.getValidationData:'+str(e)
30 input: data {run:[[ls,status,comment]]}
36 dbsession.transaction().
start(
True)
38 for run,alllsdata
in data.items():
41 queryHandle=dbsession.nominalSchema().newQuery()
44 for lumisummary
in lumisummaryData:
45 if lumisummary[-1]==1:
46 lsselection.append([lumisummary[0],
'UNKNOWN',
'NA'])
49 if len(lsselection)==0:
50 print 'no LS found for run '+str(run)+
' do nothing'
52 for lsdata
in lsselection:
53 condition=
'RUNNUM=:runnum AND CMSLSNUM=:cmslsnum'
55 conditionDefDict[
'runnum']=
'unsigned int'
56 conditionDefDict[
'cmslsnum']=
'unsigned int'
58 conditionDict[
'runnum']=run
59 conditionDict[
'cmslsnum']=lsdata[0]
61 if len(lsdata)>2
and lsdata[2]:
62 toreplacewcomment.append([(
'runnum',run),(
'cmslsnum',lsdata[0]),(
'flag',lsdata[1]),(
'comment',lsdata[2])])
64 toreplacenocomment.append([(
'runnum',run),(
'cmslsnum',lsdata[0]),(
'flag',lsdata[1]),(
'comment',
'')])
66 if len(lsdata)>2
and lsdata[2]:
67 toinsert.append([(
'RUNNUM',run),(
'CMSLSNUM',lsdata[0]),(
'FLAG',lsdata[1]),(
'COMMENT',lsdata[2])])
69 toinsert.append([(
'RUNNUM',run),(
'CMSLSNUM',lsdata[0]),(
'FLAG',lsdata[1]),(
'COMMENT',
'N/A')])
70 dbsession.transaction().commit()
76 dbsession.transaction().
start(
False)
79 tabrowDef.append((
'RUNNUM',
'unsigned int'))
80 tabrowDef.append((
'CMSLSNUM',
'unsigned int'))
81 tabrowDef.append((
'FLAG',
'string'))
82 tabrowDef.append((
'COMMENT',
'string'))
84 dbsession.transaction().commit()
86 if len(toreplacewcomment)!=0:
87 dbsession.transaction().
start(
False)
89 updateAction=
'FLAG=:flag,COMMENT=:comment'
90 updateCondition=
'RUNNUM=:runnum and CMSLSNUM=:cmslsnum'
92 bindvarDef.append((
'flag',
'string'))
93 bindvarDef.append((
'comment',
'string'))
94 bindvarDef.append((
'runnum',
'unsigned int'))
95 bindvarDef.append((
'cmslsnum',
'unsigned int'))
97 dbsession.transaction().commit()
99 if len(toreplacenocomment)!=0:
100 dbsession.transaction().
start(
False)
102 updateAction=
'FLAG=:flag'
103 updateCondition=
'RUNNUM=:runnum and CMSLSNUM=:cmslsnum'
105 bindvarDef.append((
'flag',
'string'))
106 bindvarDef.append((
'runnum',
'unsigned int'))
107 bindvarDef.append((
'cmslsnum',
'unsigned int'))
109 dbsession.transaction().commit()
111 dbsession.transaction().rollback()
113 raise Exception,
'lumiValidate.insertupdateValidationData:'+str(e)
125 allowedActions = [
'batchupdate',
'update',
'dump']
126 allowedFlags = [
'UNKNOWN',
'GOOD',
'BAD',
'SUSPECT']
128 parser.add_argument(
'action',choices=allowedActions,help=
'command actions')
129 parser.add_argument(
'-c',dest=
'connect',action=
'store',required=
True,help=
'connect string to lumiDB')
130 parser.add_argument(
'-P',dest=
'authpath',action=
'store',required=
True,help=
'path to authentication file')
131 parser.add_argument(
'-i',dest=
'inputfile',action=
'store',help=
'lumi range selection file,required for batchupdate action')
132 parser.add_argument(
'-o',dest=
'outputfile',action=
'store',help=
'output to csv file')
133 parser.add_argument(
'-r',dest=
'runnumber',action=
'store',type=int,help=
'run number,optional')
134 parser.add_argument(
'-runls',dest=
'runls',action=
'store',help=
'selection string,optional. Example [1234:[],4569:[1,1],[2,100]]')
135 parser.add_argument(
'-flag',dest=
'flag',action=
'store',default=
'UNKNOWN',help=
'flag string,optional')
136 parser.add_argument(
'--verbose',dest=
'verbose',action=
'store_true',help=
'verbose mode for printing' )
137 parser.add_argument(
'--debug',dest=
'debug',action=
'store_true',help=
'debug')
138 options=parser.parse_args()
139 if options.flag.upper()
not in allowedFlags:
140 print 'unrecognised flag ',options.flag.upper()
142 os.environ[
'CORAL_AUTH_PATH'] = options.authpath
143 connectstring=options.connect
144 svc = coral.ConnectionService()
145 msg=coral.MessageStream(
'')
147 msg.setMsgVerbosity(coral.message_Level_Debug)
149 msg.setMsgVerbosity(coral.message_Level_Error)
150 session=svc.connect(connectstring,accessMode=coral.access_Update)
151 session.typeConverter().setCppTypeForSqlType(
"unsigned int",
"NUMBER(10)")
152 session.typeConverter().setCppTypeForSqlType(
"unsigned long long",
"NUMBER(20)")
156 msg=coral.MessageStream(
'')
157 msg.setMsgVerbosity(coral.message_Level_Debug)
159 if options.action==
'batchupdate':
161 if not options.inputfile:
162 print 'inputfile -i option is required for batchupdate'
164 csvReader=csv.reader(open(options.inputfile),delimiter=
',')
165 for row
in csvReader:
168 fieldrun=str(row[0]).
strip()
169 fieldls=str(row[1]).
strip()
172 if not result.has_key(int(fieldrun)):
173 result[int(fieldrun)]=[]
174 result[int(fieldrun)].
append([int(fieldls),fieldstatus,fieldcomment])
176 if options.action==
'update':
181 if not options.runls
and not options.runnumber:
182 print 'option -runls or -r is required for update'
185 print 'option -flag is required for update'
187 if options.flag.upper()
not in allowedFlags:
188 print 'unrecognised flag ',options.flag
190 if options.runnumber:
191 runlsjson=
'{"'+str(options.runnumber)+
'":[]}'
195 runsandls=sparser.runsandls()
197 statusStr=options.flag
198 for run,lslist
in runsandls.items():
199 if not result.has_key(run):
202 result[run].
append([ls,statusStr,commentStr])
204 if options.action==
'dump':
205 if options.runls
or options.inputfile:
209 runsandls=sparser.runsandls()
210 if options.inputfile:
212 runsandls=p.runsandls()
213 for runnum,lslist
in runsandls.items():
215 if dataperrun.has_key(runnum):
216 result[runnum]=dataperrun[runnum]
223 if options.outputfile:
226 for perrundata
in result[run]:
227 r.writeRow([str(run),str(perrundata[0]),perrundata[1],perrundata[2]])
231 if len(result[run])==0:
232 print str(run),
'no validation data'
234 for lsdata
in result[run]:
235 print str(run)+
','+str(lsdata[0])+
','+lsdata[1]+
','+lsdata[2]
239 if __name__ ==
'__main__':
def lumivalidationTableName
def insertupdateValidationData