Functions | |
def | allNorms |
Norm/Correction/version DML API # # Author: Zhen Xie #. | |
def | createNorm |
def | demoteNormFromTypeDefault |
def | exportNormValue |
copy/export/import | |
def | insertValueToNormId |
def | normIdByName |
def | normIdByType |
def | normInfoByName |
def | normValueById |
def | promoteNormToTypeDefault |
def normDML::allNorms | ( | schema | ) |
Norm/Correction/version DML API # # Author: Zhen Xie #.
list all lumi norms select DATA_ID,ENTRY_NAME,LUMITYPE,ISTYPEDEFAULT,COMMENT,CTIME FROM LUMINORMSV2 output: {normname:[data_id,lumitype,istypedefault,comment,creationtime]}
Definition at line 13 of file normDML.py.
00014 : 00015 ''' 00016 list all lumi norms 00017 select DATA_ID,ENTRY_NAME,LUMITYPE,ISTYPEDEFAULT,COMMENT,CTIME FROM LUMINORMSV2 00018 output: 00019 {normname:[data_id,lumitype,istypedefault,comment,creationtime]} 00020 ''' 00021 result={} 00022 qHandle=schema.newQuery() 00023 try: 00024 qHandle.addToTableList( nameDealer.luminormv2TableName() ) 00025 qHandle.addToOutputList('DATA_ID') 00026 qHandle.addToOutputList('ENTRY_NAME') 00027 qHandle.addToOutputList('LUMITYPE') 00028 qHandle.addToOutputList('ISTYPEDEFAULT') 00029 qHandle.addToOutputList('COMMENT') 00030 qHandle.addToOutputList('TO_CHAR(CTIME,\'MM/DD/YY HH24:MI\')','creationtime') 00031 qResult=coral.AttributeList() 00032 qResult.extend('DATA_ID','unsigned long long') 00033 qResult.extend('ENTRY_NAME','string') 00034 qResult.extend('LUMITYPE','string') 00035 qResult.extend('ISTYPEDEFAULT','unsigned int') 00036 qResult.extend('COMMENT','string') 00037 qResult.extend('creationtime','string') 00038 qHandle.defineOutput(qResult) 00039 cursor=qHandle.execute() 00040 while cursor.next(): 00041 normname=cursor.currentRow()['ENTRY_NAME'].data() 00042 if not result.has_key(normname): 00043 result[normname]=[] 00044 dataid=cursor.currentRow()['DATA_ID'].data() 00045 lumitype=cursor.currentRow()['LUMITYPE'].data() 00046 istypedefault=cursor.currentRow()['ISTYPEDEFAULT'].data() 00047 comment='' 00048 if not cursor.currentRow()['COMMENT'].isNull(): 00049 comment=cursor.currentRow()['COMMENT'].data() 00050 creationtime=cursor.currentRow()['creationtime'].data() 00051 if len(result[normname])==0: 00052 result[normname]=[dataid,lumitype,istypedefault,comment,creationtime] 00053 elif len(result[normname])!=0 and dataid>result[normname][0]: 00054 result[normname]=[dataid,lumitype,istypedefault,comment,creationtime] 00055 except : 00056 del qHandle 00057 raise 00058 del qHandle 00059 return result
def normDML::createNorm | ( | schema, | |
normname, | |||
lumitype, | |||
istypedefault, | |||
branchinfo, | |||
comment = '' |
|||
) |
branchinfo(normrevisionid,branchname)
Definition at line 223 of file normDML.py.
00224 : 00225 ''' 00226 branchinfo(normrevisionid,branchname) 00227 ''' 00228 try: 00229 entry_id=revisionDML.entryInBranch(schema,nameDealer.luminormv2TableName(),normname,branchinfo[1]) 00230 if entry_id is None: 00231 (revision_id,entry_id,data_id)=revisionDML.bookNewEntry(schema,nameDealer.luminormv2TableName()) 00232 entryinfo=(revision_id,entry_id,normname,data_id) 00233 revisionDML.addEntry(schema,nameDealer.luminormv2TableName(),entryinfo,branchinfo) 00234 else: 00235 (revision_id,data_id)=revisionDML.bookNewRevision( schema,nameDealer.luminormv2TableName() ) 00236 revisionDML.addRevision(schema,nameDealer.luminormv2TableName(),(revision_id,data_id),branchinfo) 00237 tabrowDefDict={'DATA_ID':'unsigned long long','ENTRY_ID':'unsigned long long','ENTRY_NAME':'string','LUMITYPE':'string','ISTYPEDEFAULT':'unsigned int','COMMENT':'string','CTIME':'time stamp'} 00238 tabrowValueDict={'DATA_ID':data_id,'ENTRY_ID':entry_id,'ENTRY_NAME':normname,'LUMITYPE':lumitype,'ISTYPEDEFAULT':istypedefault,'COMMENT':comment,'CTIME':coral.TimeStamp()} 00239 db=dbUtil.dbUtil(schema) 00240 db.insertOneRow(nameDealer.luminormv2TableName(),tabrowDefDict,tabrowValueDict) 00241 return (revision_id,entry_id,data_id) 00242 except : 00243 raise
def normDML::demoteNormFromTypeDefault | ( | schema, | |
normname, | |||
lumitype | |||
) |
demote norm from typedefault to non default
Definition at line 244 of file normDML.py.
00245 : 00246 ''' 00247 demote norm from typedefault to non default 00248 ''' 00249 try: 00250 thisnormid=normIdByName(schema,normname) 00251 if not thisnormid: 00252 raise ValueError(normname+' does not exist, nothing to update') 00253 setClause='ISTYPEDEFAULT=0' 00254 updateCondition='DATA_ID=:thisnormid AND LUMITYPE=:lumitype' 00255 inputData=coral.AttributeList() 00256 inputData.extend('thisnormid','unsigned long long') 00257 inputData.extend('LUMITYPE','string') 00258 inputData['thisnormid'].setData(thisnormid) 00259 inputData['LUMITYPE'].setData(lumitype) 00260 db=dbUtil.dbUtil(schema) 00261 db.singleUpdate(nameDealer.luminormv2TableName(),setClause,updateCondition,inputData) 00262 except : 00263 raise
def normDML::exportNormValue | ( | schema, | |
sourcenormname, | |||
destnormname, | |||
firstsince = None , |
|||
lastsince = None |
|||
) |
copy/export/import
copy specified piece of source norm to dest input: time boundary [firstsince, lastsince] if None: open
Definition at line 339 of file normDML.py.
00340 : 00341 ''' 00342 copy specified piece of source norm to dest 00343 input: 00344 time boundary [firstsince, lastsince] 00345 if None: open 00346 ''' 00347 copysince=0 00348 if firstsince: 00349 copysince=firstsince 00350 copylastsince=4294967295 00351 if lastsince: 00352 copylastsince=lastsince 00353 try: 00354 destnormid=normIdByName(schema,destnornmae) 00355 if not destnormid: 00356 raise RuntimeError('[ERROR] destnorm does not exist') 00357 sourcenormid=normIdByName(schema,sourcenorname) 00358 if not sourcenormid: 00359 raise RuntimeError('[ERROR] sourcenorm does not exist') 00360 normvalueDict=normValueById(schema,sourcenormid) #{since:[corrector,{paramname:paramvalue},amodetag,egev,comment]} 00361 for sincerun,normvalue in normvalueDict.items(): 00362 if sincerun>copysince and sincerun<copylastsince: 00363 corrector=normvalue[0] 00364 parameters=normvalue[1] 00365 amodetag=normvalue[2] 00366 egev=normvalue[3] 00367 comment=normvalue[4] 00368 insertValueToNormId(schema,destnormid,sincerun,corrector,amodetag,egev,comment=comment) 00369 except: 00370 raise
def normDML::insertValueToNormId | ( | schema, | |
normdataid, | |||
sincerun, | |||
corrector, | |||
amodetag, | |||
egev, | |||
parameters, | |||
comment = '' |
|||
) |
insert into LUMINORMSV2DATA(DATA_ID,SINCERUN,CORRECTOR,...) values(normdataid,)sincerun,corrector,...); require len(parameters)>=1. input: parameterDict {'NORM_OCC1':normocc1,'NORM_OCC2':normocc2,'NORM_ET':normet,'NORM_PU':normpu,'DRIFT':drift,'A1':a1,...} output:
Definition at line 298 of file normDML.py.
00299 : 00300 ''' 00301 insert into LUMINORMSV2DATA(DATA_ID,SINCERUN,CORRECTOR,...) values(normdataid,)sincerun,corrector,...); 00302 require len(parameters)>=1. 00303 input: 00304 parameterDict {'NORM_OCC1':normocc1,'NORM_OCC2':normocc2,'NORM_ET':normet,'NORM_PU':normpu,'DRIFT':drift,'A1':a1,...} 00305 output: 00306 ''' 00307 if len(parameters)==0: 00308 raise ValueError('appendValueToNormId: at least one value is required') 00309 try: 00310 db=dbUtil.dbUtil(schema) 00311 tabrowDefDict={} 00312 tabrowDefDict['DATA_ID']='unsigned long long' 00313 tabrowDefDict['CORRECTOR']='string' 00314 tabrowDefDict['SINCE']='unsigned int' 00315 tabrowDefDict['AMODETAG']='string' 00316 tabrowDefDict['NOMINALEGEV']='unsigned int' 00317 tabrowDefDict['COMMENT']='string' 00318 tabrowValueDict={} 00319 tabrowValueDict['DATA_ID']=normdataid 00320 tabrowValueDict['CORRECTOR']=corrector 00321 tabrowValueDict['SINCE']=sincerun 00322 tabrowValueDict['AMODETAG']=amodetag 00323 tabrowValueDict['NOMINALEGEV']=egev 00324 tabrowValueDict['COMMENT']=comment 00325 for paramname,paramvalue in parameters.items(): 00326 try: 00327 floatparam=float(paramvalue) 00328 tabrowDefDict[paramname.upper()]='float' 00329 tabrowValueDict[paramname.upper()]=float(paramvalue) 00330 except ValueError: 00331 tabrowDefDict[paramname.upper()]='string' 00332 tabrowValueDict[paramname.upper()]=paramvalue 00333 db.insertOneRow(nameDealer.luminormv2dataTableName(),tabrowDefDict,tabrowValueDict) 00334 except: raise
def normDML::normIdByName | ( | schema, | |
normname | |||
) |
select max(DATA_ID) FROM LUMINORMSV2 WHERE ENTRY_NAME=:normname
Definition at line 60 of file normDML.py.
00061 : 00062 ''' 00063 select max(DATA_ID) FROM LUMINORMSV2 WHERE ENTRY_NAME=:normname 00064 ''' 00065 luminormids=[] 00066 result=None 00067 qHandle=schema.newQuery() 00068 try: 00069 qHandle.addToTableList( nameDealer.luminormv2TableName() ) 00070 qHandle.addToOutputList('DATA_ID') 00071 if normname: 00072 qConditionStr='ENTRY_NAME=:normname ' 00073 qCondition=coral.AttributeList() 00074 qCondition.extend('normname','string') 00075 qCondition['normname'].setData(normname) 00076 qResult=coral.AttributeList() 00077 qResult.extend('DATA_ID','unsigned long long') 00078 qHandle.defineOutput(qResult) 00079 if normname: 00080 qHandle.setCondition(qConditionStr,qCondition) 00081 cursor=qHandle.execute() 00082 while cursor.next(): 00083 dataid=cursor.currentRow()['DATA_ID'].data() 00084 luminormids.append(dataid) 00085 except : 00086 del qHandle 00087 raise 00088 del qHandle 00089 if len(luminormids) !=0: 00090 return max(luminormids) 00091 return result
def normDML::normIdByType | ( | schema, | |
lumitype = 'HF' , |
|||
defaultonly = True |
|||
) |
select max(DATA_ID) FROM LUMINORMSV2 WHERE LUMITYPE=:lumitype output: luminormidmap {normname:normid}
Definition at line 92 of file normDML.py.
00093 : 00094 ''' 00095 select max(DATA_ID) FROM LUMINORMSV2 WHERE LUMITYPE=:lumitype 00096 output: 00097 luminormidmap {normname:normid} 00098 ''' 00099 luminormidmap={} 00100 qHandle=schema.newQuery() 00101 try: 00102 qHandle.addToTableList( nameDealer.luminormv2TableName() ) 00103 qHandle.addToOutputList('DATA_ID') 00104 qHandle.addToOutputList('ENTRY_NAME') 00105 qConditionStr='LUMITYPE=:lumitype' 00106 qCondition=coral.AttributeList() 00107 qCondition.extend('lumitype','string') 00108 qCondition['lumitype'].setData(lumitype) 00109 if defaultonly: 00110 qConditionStr+=' AND ISTYPEDEFAULT=:istypedefault' 00111 qCondition.extend('istypedefault','unsigned int') 00112 qCondition['istypedefault'].setData(int(1)) 00113 qResult=coral.AttributeList() 00114 qResult.extend('DATA_ID','unsigned long long') 00115 qResult.extend('ENTRY_NAME','string') 00116 qHandle.defineOutput(qResult) 00117 qHandle.setCondition(qConditionStr,qCondition) 00118 cursor=qHandle.execute() 00119 while cursor.next(): 00120 if not cursor.currentRow()['DATA_ID'].isNull(): 00121 dataid=cursor.currentRow()['DATA_ID'].data() 00122 normname=cursor.currentRow()['ENTRY_NAME'].data() 00123 if not luminormidmap.has_key(normname): 00124 luminormidmap[normname]=dataid 00125 else: 00126 if dataid>luminormidmap[normname]: 00127 luminormidmap[normname]=dataid 00128 except : 00129 del qHandle 00130 raise 00131 del qHandle 00132 return luminormidmap
def normDML::normInfoByName | ( | schema, | |
normname | |||
) |
select DATA_ID,LUMITYPE,ISTYPEDEFAULT,COMMENT,TO_CHAR(CTIME,\'MM/DD/YY HH24:MI\') FROM LUMINORMS WHERE ENTRY_NAME=:normname output: [data_id[0],lumitype[1],istypedefault[2],comment[3],creationtime[4]]
Definition at line 133 of file normDML.py.
00134 : 00135 ''' 00136 select DATA_ID,LUMITYPE,ISTYPEDEFAULT,COMMENT,TO_CHAR(CTIME,\'MM/DD/YY HH24:MI\') FROM LUMINORMS WHERE ENTRY_NAME=:normname 00137 output: 00138 [data_id[0],lumitype[1],istypedefault[2],comment[3],creationtime[4]] 00139 ''' 00140 result={} 00141 qHandle=schema.newQuery() 00142 try: 00143 qHandle.addToTableList( nameDealer.luminormv2TableName() ) 00144 qHandle.addToOutputList('DATA_ID') 00145 qHandle.addToOutputList('LUMITYPE') 00146 qHandle.addToOutputList('ISTYPEDEFAULT') 00147 qHandle.addToOutputList('COMMENT') 00148 qHandle.addToOutputList('TO_CHAR(CTIME,\'MM/DD/YY HH24:MI\')','ctime') 00149 qConditionStr='ENTRY_NAME=:normname' 00150 qCondition=coral.AttributeList() 00151 qCondition.extend('normname','string') 00152 qCondition['normname'].setData(normname) 00153 qResult=coral.AttributeList() 00154 qResult.extend('DATA_ID','unsigned long long') 00155 qResult.extend('LUMITYPE','string') 00156 qResult.extend('ISTYPEDEFAULT','unsigned int') 00157 qResult.extend('COMMENT','string') 00158 qResult.extend('ctime','string') 00159 qHandle.defineOutput(qResult) 00160 qHandle.setCondition(qConditionStr,qCondition) 00161 cursor=qHandle.execute() 00162 while cursor.next(): 00163 if not cursor.currentRow()['DATA_ID'].isNull(): 00164 dataid=cursor.currentRow()['DATA_ID'].data() 00165 else: 00166 continue 00167 lumitype=cursor.currentRow()['LUMITYPE'].data() 00168 istypedefault=cursor.currentRow()['ISTYPEDEFAULT'].data() 00169 comment='' 00170 if not cursor.currentRow()['COMMENT'].isNull(): 00171 comment=cursor.currentRow()['COMMENT'].data() 00172 creationtime=cursor.currentRow()['ctime'].data() 00173 if not result.has_key(dataid): 00174 result[dataid]=[dataid,lumitype,istypedefault,comment,creationtime] 00175 except : 00176 del qHandle 00177 raise 00178 if len(result)>0: 00179 maxdataid=max(result.keys()) 00180 return result[maxdataid] return result
def normDML::normValueById | ( | schema, | |
normid | |||
) |
select * from luminormsv2data where data_id=normid output: {since:[corrector(0),{paramname:paramvalue}(1),amodetag(2),egev(3),comment(4)]}
Definition at line 181 of file normDML.py.
00182 : 00183 ''' 00184 select * from luminormsv2data where data_id=normid 00185 output: 00186 {since:[corrector(0),{paramname:paramvalue}(1),amodetag(2),egev(3),comment(4)]} 00187 ''' 00188 result={} 00189 l=nameDealer.luminormv2dataTableName() 00190 paramdict={} 00191 qHandle=schema.newQuery() 00192 try: 00193 qHandle.addToTableList(l) 00194 qConditionStr='DATA_ID=:normid' 00195 qCondition=coral.AttributeList() 00196 qCondition.extend('normid','unsigned long long') 00197 qCondition['normid'].setData(normid) 00198 qResult=coral.AttributeList() 00199 qHandle.setCondition(qConditionStr,qCondition) 00200 cursor=qHandle.execute() 00201 while cursor.next(): 00202 since=cursor.currentRow()['SINCE'].data() 00203 corrector=cursor.currentRow()['CORRECTOR'].data() 00204 amodetag=cursor.currentRow()['AMODETAG'].data() 00205 nominalegev=cursor.currentRow()['NOMINALEGEV'].data() 00206 comment='' 00207 if not cursor.currentRow()['COMMENT'].isNull(): 00208 comment=cursor.currentRow()['COMMENT'].data() 00209 (correctorfunc,params)=CommonUtil.parselumicorrector(corrector) 00210 paramdict={} 00211 for param in params: 00212 paramvalue=0.0 00213 if not cursor.currentRow()[param.upper()].isNull(): 00214 paramvalue=cursor.currentRow()[param.upper()].data() 00215 paramdict[param]=paramvalue 00216 result[since]=[correctorfunc,paramdict,amodetag,nominalegev,comment] 00217 except: 00218 raise 00219 return result 00220 00221 #======================================================= 00222 # INSERT/UPDATE requires in update transaction #=======================================================
def normDML::promoteNormToTypeDefault | ( | schema, | |
normname, | |||
lumitype | |||
) |
set the named norm as default for a given type,reset the old default if any thisnormid=normIdByName(schema,normname) olddefaultid=normIdByType(schema,lumitype=lumitype,defaultonly=True) if thisnormid: update LUMINORMSV2 set ISTYPEDEFAULT=1 where DATA_ID=:thisnormid else: raise ValueError('normname does not exist, nothing to update') if olddefaultid and olddefaultid!=thisnormid: update LUMINORMSV2 set ISTYPEDEFAULT=0 where DATA_ID=:olddefaultid
Definition at line 264 of file normDML.py.
00265 : 00266 ''' 00267 set the named norm as default for a given type,reset the old default if any 00268 thisnormid=normIdByName(schema,normname) 00269 olddefaultid=normIdByType(schema,lumitype=lumitype,defaultonly=True) 00270 if thisnormid: 00271 update LUMINORMSV2 set ISTYPEDEFAULT=1 where DATA_ID=:thisnormid 00272 else: 00273 raise ValueError('normname does not exist, nothing to update') 00274 if olddefaultid and olddefaultid!=thisnormid: 00275 update LUMINORMSV2 set ISTYPEDEFAULT=0 where DATA_ID=:olddefaultid 00276 ''' 00277 try: 00278 thisnormid=normIdByName(schema,normname) 00279 olddefaultid=normIdByType(schema,lumitype=lumitype,defaultonly=True) 00280 if not thisnormid: 00281 raise ValueError(normname+' does not exist, nothing to update') 00282 setClause='ISTYPEDEFAULT=1' 00283 updateCondition='DATA_ID=:thisnormid' 00284 inputData=coral.AttributeList() 00285 inputData.extend('thisnormid','unsigned long long') 00286 inputData['thisnormid'].setData(thisnormid) 00287 db=dbUtil.dbUtil(schema) 00288 db.singleUpdate(nameDealer.luminormTable(),setClause,updateCondition,inputData) 00289 if olddefaultid: 00290 setClause='ISTYPEDEFAULT=0' 00291 updateCondition='DATA_ID=:olddefaultid' 00292 inputData=coral.AttributeList() 00293 inputData.extend('olddefaultid','unsigned long long') 00294 inputData['olddefaultid'].setData(olddefaultid) 00295 db=dbUtil.dbUtil(schema) 00296 db.singleUpdate(nameDealer.luminormTable(),setClause,updateCondition,inputData) 00297 except : raise