2 from RecoLuminosity.LumiDB
import nameDealer,dbUtil,revisionDML,CommonUtil
16 select DATA_ID,ENTRY_NAME,LUMITYPE,ISTYPEDEFAULT,COMMENT,CTIME FROM LUMINORMSV2 18 {normname:[data_id,lumitype,istypedefault,comment,creationtime]} 21 qHandle=schema.newQuery()
24 qHandle.addToOutputList(
'DATA_ID')
25 qHandle.addToOutputList(
'ENTRY_NAME')
26 qHandle.addToOutputList(
'LUMITYPE')
27 qHandle.addToOutputList(
'ISTYPEDEFAULT')
28 qHandle.addToOutputList(
'COMMENT')
29 qHandle.addToOutputList(
'TO_CHAR(CTIME,\'MM/DD/YY HH24:MI\')',
'creationtime')
30 qResult=coral.AttributeList()
31 qResult.extend(
'DATA_ID',
'unsigned long long')
32 qResult.extend(
'ENTRY_NAME',
'string')
33 qResult.extend(
'LUMITYPE',
'string')
34 qResult.extend(
'ISTYPEDEFAULT',
'unsigned int')
35 qResult.extend(
'COMMENT',
'string')
36 qResult.extend(
'creationtime',
'string')
37 qHandle.defineOutput(qResult)
38 cursor=qHandle.execute()
40 normname=cursor.currentRow()[
'ENTRY_NAME'].
data()
41 if normname
not in result:
43 dataid=cursor.currentRow()[
'DATA_ID'].
data()
44 lumitype=cursor.currentRow()[
'LUMITYPE'].
data()
45 istypedefault=cursor.currentRow()[
'ISTYPEDEFAULT'].
data()
47 if not cursor.currentRow()[
'COMMENT'].isNull():
48 comment=cursor.currentRow()[
'COMMENT'].
data()
49 creationtime=cursor.currentRow()[
'creationtime'].
data()
50 if len(result[normname])==0:
51 result[normname]=[dataid,lumitype,istypedefault,comment,creationtime]
52 elif len(result[normname])!=0
and dataid>result[normname][0]:
53 result[normname]=[dataid,lumitype,istypedefault,comment,creationtime]
62 select max(DATA_ID) FROM LUMINORMSV2 WHERE ENTRY_NAME=:normname 66 qHandle=schema.newQuery()
69 qHandle.addToOutputList(
'DATA_ID')
71 qConditionStr=
'ENTRY_NAME=:normname ' 72 qCondition=coral.AttributeList()
73 qCondition.extend(
'normname',
'string')
74 qCondition[
'normname'].setData(normname)
75 qResult=coral.AttributeList()
76 qResult.extend(
'DATA_ID',
'unsigned long long')
77 qHandle.defineOutput(qResult)
79 qHandle.setCondition(qConditionStr,qCondition)
80 cursor=qHandle.execute()
82 dataid=cursor.currentRow()[
'DATA_ID'].
data()
83 luminormids.append(dataid)
88 if len(luminormids) !=0:
89 return max(luminormids)
94 select max(DATA_ID) FROM LUMINORMSV2 WHERE LUMITYPE=:lumitype 96 luminormidmap {normname:normid} 99 qHandle=schema.newQuery()
102 qHandle.addToOutputList(
'DATA_ID')
103 qHandle.addToOutputList(
'ENTRY_NAME')
104 qConditionStr=
'LUMITYPE=:lumitype' 105 qCondition=coral.AttributeList()
106 qCondition.extend(
'lumitype',
'string')
107 qCondition[
'lumitype'].setData(lumitype)
109 qConditionStr+=
' AND ISTYPEDEFAULT=:istypedefault' 110 qCondition.extend(
'istypedefault',
'unsigned int')
111 qCondition[
'istypedefault'].setData(
int(1))
112 qResult=coral.AttributeList()
113 qResult.extend(
'DATA_ID',
'unsigned long long')
114 qResult.extend(
'ENTRY_NAME',
'string')
115 qHandle.defineOutput(qResult)
116 qHandle.setCondition(qConditionStr,qCondition)
117 cursor=qHandle.execute()
119 if not cursor.currentRow()[
'DATA_ID'].isNull():
120 dataid=cursor.currentRow()[
'DATA_ID'].
data()
121 normname=cursor.currentRow()[
'ENTRY_NAME'].
data()
122 if normname
not in luminormidmap:
123 luminormidmap[normname]=dataid
125 if dataid>luminormidmap[normname]:
126 luminormidmap[normname]=dataid
135 select DATA_ID,LUMITYPE,ISTYPEDEFAULT,COMMENT,TO_CHAR(CTIME,\'MM/DD/YY HH24:MI\') FROM LUMINORMS WHERE ENTRY_NAME=:normname 137 [data_id[0],lumitype[1],istypedefault[2],comment[3],creationtime[4]] 140 qHandle=schema.newQuery()
143 qHandle.addToOutputList(
'DATA_ID')
144 qHandle.addToOutputList(
'LUMITYPE')
145 qHandle.addToOutputList(
'ISTYPEDEFAULT')
146 qHandle.addToOutputList(
'COMMENT')
147 qHandle.addToOutputList(
'TO_CHAR(CTIME,\'MM/DD/YY HH24:MI\')',
'ctime')
148 qConditionStr=
'ENTRY_NAME=:normname' 149 qCondition=coral.AttributeList()
150 qCondition.extend(
'normname',
'string')
151 qCondition[
'normname'].setData(normname)
152 qResult=coral.AttributeList()
153 qResult.extend(
'DATA_ID',
'unsigned long long')
154 qResult.extend(
'LUMITYPE',
'string')
155 qResult.extend(
'ISTYPEDEFAULT',
'unsigned int')
156 qResult.extend(
'COMMENT',
'string')
157 qResult.extend(
'ctime',
'string')
158 qHandle.defineOutput(qResult)
159 qHandle.setCondition(qConditionStr,qCondition)
160 cursor=qHandle.execute()
162 if not cursor.currentRow()[
'DATA_ID'].isNull():
163 dataid=cursor.currentRow()[
'DATA_ID'].
data()
166 lumitype=cursor.currentRow()[
'LUMITYPE'].
data()
167 istypedefault=cursor.currentRow()[
'ISTYPEDEFAULT'].
data()
169 if not cursor.currentRow()[
'COMMENT'].isNull():
170 comment=cursor.currentRow()[
'COMMENT'].
data()
171 creationtime=cursor.currentRow()[
'ctime'].
data()
172 if dataid
not in result:
173 result[dataid]=[dataid,lumitype,istypedefault,comment,creationtime]
178 maxdataid=
max(result.keys())
179 return result[maxdataid]
183 select * from luminormsv2data where data_id=normid 185 {since:[corrector(0),{paramname:paramvalue}(1),amodetag(2),egev(3),comment(4)]} 190 qHandle=schema.newQuery()
192 qHandle.addToTableList(l)
193 qConditionStr=
'DATA_ID=:normid' 194 qCondition=coral.AttributeList()
195 qCondition.extend(
'normid',
'unsigned long long')
196 qCondition[
'normid'].setData(normid)
197 qResult=coral.AttributeList()
198 qHandle.setCondition(qConditionStr,qCondition)
199 cursor=qHandle.execute()
201 since=cursor.currentRow()[
'SINCE'].
data()
202 corrector=cursor.currentRow()[
'CORRECTOR'].
data()
203 amodetag=cursor.currentRow()[
'AMODETAG'].
data()
204 nominalegev=cursor.currentRow()[
'NOMINALEGEV'].
data()
206 if not cursor.currentRow()[
'COMMENT'].isNull():
207 comment=cursor.currentRow()[
'COMMENT'].
data()
212 if not cursor.currentRow()[param.upper()].isNull():
213 paramvalue=cursor.currentRow()[param.upper()].
data()
214 paramdict[param]=paramvalue
215 result[since]=[correctorfunc,paramdict,amodetag,nominalegev,comment]
223 def createNorm(schema,normname,lumitype,istypedefault,branchinfo,comment=''):
225 branchinfo(normrevisionid,branchname) 231 entryinfo=(revision_id,entry_id,normname,data_id)
236 tabrowDefDict={
'DATA_ID':
'unsigned long long',
'ENTRY_ID':
'unsigned long long',
'ENTRY_NAME':
'string',
'LUMITYPE':
'string',
'ISTYPEDEFAULT':
'unsigned int',
'COMMENT':
'string',
'CTIME':
'time stamp'}
237 tabrowValueDict={
'DATA_ID':data_id,
'ENTRY_ID':entry_id,
'ENTRY_NAME':normname,
'LUMITYPE':lumitype,
'ISTYPEDEFAULT':istypedefault,
'COMMENT':comment,
'CTIME':coral.TimeStamp()}
240 return (revision_id,entry_id,data_id)
246 demote norm from typedefault to non default 251 raise ValueError(normname+
' does not exist, nothing to update')
252 setClause=
'ISTYPEDEFAULT=0' 253 updateCondition=
'DATA_ID=:thisnormid AND LUMITYPE=:lumitype' 254 inputData=coral.AttributeList()
255 inputData.extend(
'thisnormid',
'unsigned long long')
256 inputData.extend(
'LUMITYPE',
'string')
257 inputData[
'thisnormid'].setData(thisnormid)
258 inputData[
'LUMITYPE'].setData(lumitype)
266 set the named norm as default for a given type,reset the old default if any 267 thisnormid=normIdByName(schema,normname) 268 olddefaultid=normIdByType(schema,lumitype=lumitype,defaultonly=True) 270 update LUMINORMSV2 set ISTYPEDEFAULT=1 where DATA_ID=:thisnormid 272 raise ValueError('normname does not exist, nothing to update') 273 if olddefaultid and olddefaultid!=thisnormid: 274 update LUMINORMSV2 set ISTYPEDEFAULT=0 where DATA_ID=:olddefaultid 278 olddefaultid=
normIdByType(schema,lumitype=lumitype,defaultonly=
True)
280 raise ValueError(normname+
' does not exist, nothing to update')
281 setClause=
'ISTYPEDEFAULT=1' 282 updateCondition=
'DATA_ID=:thisnormid' 283 inputData=coral.AttributeList()
284 inputData.extend(
'thisnormid',
'unsigned long long')
285 inputData[
'thisnormid'].setData(thisnormid)
287 db.singleUpdate(nameDealer.luminormTable(),setClause,updateCondition,inputData)
289 setClause=
'ISTYPEDEFAULT=0' 290 updateCondition=
'DATA_ID=:olddefaultid' 291 inputData=coral.AttributeList()
292 inputData.extend(
'olddefaultid',
'unsigned long long')
293 inputData[
'olddefaultid'].setData(olddefaultid)
295 db.singleUpdate(nameDealer.luminormTable(),setClause,updateCondition,inputData)
300 insert into LUMINORMSV2DATA(DATA_ID,SINCERUN,CORRECTOR,...) values(normdataid,)sincerun,corrector,...); 301 require len(parameters)>=1. 303 parameterDict {'NORM_OCC1':normocc1,'NORM_OCC2':normocc2,'NORM_ET':normet,'NORM_PU':normpu,'DRIFT':drift,'A1':a1,...} 306 if len(parameters)==0:
307 raise ValueError(
'appendValueToNormId: at least one value is required')
311 tabrowDefDict[
'DATA_ID']=
'unsigned long long' 312 tabrowDefDict[
'CORRECTOR']=
'string' 313 tabrowDefDict[
'SINCE']=
'unsigned int' 314 tabrowDefDict[
'AMODETAG']=
'string' 315 tabrowDefDict[
'NOMINALEGEV']=
'unsigned int' 316 tabrowDefDict[
'COMMENT']=
'string' 318 tabrowValueDict[
'DATA_ID']=normdataid
319 tabrowValueDict[
'CORRECTOR']=corrector
320 tabrowValueDict[
'SINCE']=sincerun
321 tabrowValueDict[
'AMODETAG']=amodetag
322 tabrowValueDict[
'NOMINALEGEV']=egev
323 tabrowValueDict[
'COMMENT']=comment
324 for paramname,paramvalue
in parameters.items():
326 floatparam=
float(paramvalue)
327 tabrowDefDict[paramname.upper()]=
'float' 328 tabrowValueDict[paramname.upper()]=
float(paramvalue)
330 tabrowDefDict[paramname.upper()]=
'string' 331 tabrowValueDict[paramname.upper()]=paramvalue
339 def exportNormValue(schema,sourcenormname,destnormname,firstsince=None,lastsince=None):
341 copy specified piece of source norm to dest 343 time boundary [firstsince, lastsince] 349 copylastsince=4294967295
351 copylastsince=lastsince
355 raise RuntimeError(
'[ERROR] destnorm does not exist')
358 raise RuntimeError(
'[ERROR] sourcenorm does not exist')
360 for sincerun,normvalue
in normvalueDict.items():
361 if sincerun>copysince
and sincerun<copylastsince:
362 corrector=normvalue[0]
363 parameters=normvalue[1]
364 amodetag=normvalue[2]
def normInfoByName(schema, normname)
def normIdByName(schema, normname)
def luminormv2TableName()
def exportNormValue(schema, sourcenormname, destnormname, firstsince=None, lastsince=None)
copy/export/import
def allNorms(schema)
Norm/Correction/version DML API # # Author: Zhen Xie #.
def normIdByType(schema, lumitype='HF', defaultonly=True)
def insertValueToNormId(schema, normdataid, sincerun, corrector, amodetag, egev, parameters, comment='')
def promoteNormToTypeDefault(schema, normname, lumitype)
def addEntry(schema, datatableName, entryinfo, branchinfo)
def entryInBranch(schema, datatableName, entryname, branch)
def createNorm(schema, normname, lumitype, istypedefault, branchinfo, comment='')
def bookNewRevision(schema, datatableName)
def bookNewEntry(schema, datatableName)
def luminormv2dataTableName()
def addRevision(schema, datatableName, revisioninfo, branchinfo)
def normValueById(schema, normid)
def demoteNormFromTypeDefault(schema, normname, lumitype)
char data[epos_bytes_allocation]
def parselumicorrector(correctorStr)