CMS 3D CMS Logo

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

Functions

def allNorms
 Norm/Correction/version DML API # # Author: Zhen Xie #. More...
 
def createNorm
 
def demoteNormFromTypeDefault
 
def exportNormValue
 copy/export/import More...
 
def insertValueToNormId
 
def normIdByName
 
def normIdByType
 
def normInfoByName
 
def normValueById
 
def promoteNormToTypeDefault
 

Function Documentation

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.

References data, nameDealer.luminormv2TableName(), and GetRecoTauVFromDQM_MC_cff.next.

13 
14 def allNorms(schema):
15  '''
16  list all lumi norms
17  select DATA_ID,ENTRY_NAME,LUMITYPE,ISTYPEDEFAULT,COMMENT,CTIME FROM LUMINORMSV2
18  output:
19  {normname:[data_id,lumitype,istypedefault,comment,creationtime]}
20  '''
21  result={}
22  qHandle=schema.newQuery()
23  try:
24  qHandle.addToTableList( nameDealer.luminormv2TableName() )
25  qHandle.addToOutputList('DATA_ID')
26  qHandle.addToOutputList('ENTRY_NAME')
27  qHandle.addToOutputList('LUMITYPE')
28  qHandle.addToOutputList('ISTYPEDEFAULT')
29  qHandle.addToOutputList('COMMENT')
30  qHandle.addToOutputList('TO_CHAR(CTIME,\'MM/DD/YY HH24:MI\')','creationtime')
31  qResult=coral.AttributeList()
32  qResult.extend('DATA_ID','unsigned long long')
33  qResult.extend('ENTRY_NAME','string')
34  qResult.extend('LUMITYPE','string')
35  qResult.extend('ISTYPEDEFAULT','unsigned int')
36  qResult.extend('COMMENT','string')
37  qResult.extend('creationtime','string')
38  qHandle.defineOutput(qResult)
39  cursor=qHandle.execute()
40  while next(cursor):
41  normname=cursor.currentRow()['ENTRY_NAME'].data()
42  if normname not in result:
43  result[normname]=[]
44  dataid=cursor.currentRow()['DATA_ID'].data()
45  lumitype=cursor.currentRow()['LUMITYPE'].data()
46  istypedefault=cursor.currentRow()['ISTYPEDEFAULT'].data()
47  comment=''
48  if not cursor.currentRow()['COMMENT'].isNull():
49  comment=cursor.currentRow()['COMMENT'].data()
50  creationtime=cursor.currentRow()['creationtime'].data()
51  if len(result[normname])==0:
52  result[normname]=[dataid,lumitype,istypedefault,comment,creationtime]
53  elif len(result[normname])!=0 and dataid>result[normname][0]:
54  result[normname]=[dataid,lumitype,istypedefault,comment,creationtime]
55  except :
56  del qHandle
57  raise
58  del qHandle
59  return result
def allNorms
Norm/Correction/version DML API # # Author: Zhen Xie #.
Definition: normDML.py:13
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
def luminormv2TableName
Definition: nameDealer.py:40
def normDML.createNorm (   schema,
  normname,
  lumitype,
  istypedefault,
  branchinfo,
  comment = '' 
)
branchinfo(normrevisionid,branchname)    

Definition at line 223 of file normDML.py.

References revisionDML.addEntry(), revisionDML.addRevision(), revisionDML.bookNewEntry(), revisionDML.bookNewRevision(), revisionDML.entryInBranch(), and nameDealer.luminormv2TableName().

224 def createNorm(schema,normname,lumitype,istypedefault,branchinfo,comment=''):
225  '''
226  branchinfo(normrevisionid,branchname)
227  '''
228  try:
229  entry_id=revisionDML.entryInBranch(schema,nameDealer.luminormv2TableName(),normname,branchinfo[1])
230  if entry_id is None:
231  (revision_id,entry_id,data_id)=revisionDML.bookNewEntry(schema,nameDealer.luminormv2TableName())
232  entryinfo=(revision_id,entry_id,normname,data_id)
233  revisionDML.addEntry(schema,nameDealer.luminormv2TableName(),entryinfo,branchinfo)
234  else:
235  (revision_id,data_id)=revisionDML.bookNewRevision( schema,nameDealer.luminormv2TableName() )
236  revisionDML.addRevision(schema,nameDealer.luminormv2TableName(),(revision_id,data_id),branchinfo)
237  tabrowDefDict={'DATA_ID':'unsigned long long','ENTRY_ID':'unsigned long long','ENTRY_NAME':'string','LUMITYPE':'string','ISTYPEDEFAULT':'unsigned int','COMMENT':'string','CTIME':'time stamp'}
238  tabrowValueDict={'DATA_ID':data_id,'ENTRY_ID':entry_id,'ENTRY_NAME':normname,'LUMITYPE':lumitype,'ISTYPEDEFAULT':istypedefault,'COMMENT':comment,'CTIME':coral.TimeStamp()}
239  db=dbUtil.dbUtil(schema)
240  db.insertOneRow(nameDealer.luminormv2TableName(),tabrowDefDict,tabrowValueDict)
241  return (revision_id,entry_id,data_id)
242  except :
243  raise
def createNorm
Definition: normDML.py:223
def bookNewRevision
Definition: revisionDML.py:330
def bookNewEntry
Definition: revisionDML.py:316
def entryInBranch
Definition: revisionDML.py:188
def luminormv2TableName
Definition: nameDealer.py:40
def normDML.demoteNormFromTypeDefault (   schema,
  normname,
  lumitype 
)
demote norm from typedefault to non default

Definition at line 244 of file normDML.py.

References nameDealer.luminormv2TableName(), and normIdByName().

245 def demoteNormFromTypeDefault(schema,normname,lumitype):
246  '''
247  demote norm from typedefault to non default
248  '''
249  try:
250  thisnormid=normIdByName(schema,normname)
251  if not thisnormid:
252  raise ValueError(normname+' does not exist, nothing to update')
253  setClause='ISTYPEDEFAULT=0'
254  updateCondition='DATA_ID=:thisnormid AND LUMITYPE=:lumitype'
255  inputData=coral.AttributeList()
256  inputData.extend('thisnormid','unsigned long long')
257  inputData.extend('LUMITYPE','string')
258  inputData['thisnormid'].setData(thisnormid)
259  inputData['LUMITYPE'].setData(lumitype)
260  db=dbUtil.dbUtil(schema)
261  db.singleUpdate(nameDealer.luminormv2TableName(),setClause,updateCondition,inputData)
262  except :
263  raise
def demoteNormFromTypeDefault
Definition: normDML.py:244
def luminormv2TableName
Definition: nameDealer.py:40
def normIdByName
Definition: normDML.py:60
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.

References insertValueToNormId(), normIdByName(), and normValueById().

340 def exportNormValue(schema,sourcenormname,destnormname,firstsince=None,lastsince=None):
341  '''
342  copy specified piece of source norm to dest
343  input:
344  time boundary [firstsince, lastsince]
345  if None: open
346  '''
347  copysince=0
348  if firstsince:
349  copysince=firstsince
350  copylastsince=4294967295
351  if lastsince:
352  copylastsince=lastsince
353  try:
354  destnormid=normIdByName(schema,destnornmae)
355  if not destnormid:
356  raise RuntimeError('[ERROR] destnorm does not exist')
357  sourcenormid=normIdByName(schema,sourcenorname)
358  if not sourcenormid:
359  raise RuntimeError('[ERROR] sourcenorm does not exist')
360  normvalueDict=normValueById(schema,sourcenormid) #{since:[corrector,{paramname:paramvalue},amodetag,egev,comment]}
361  for sincerun,normvalue in normvalueDict.items():
362  if sincerun>copysince and sincerun<copylastsince:
363  corrector=normvalue[0]
364  parameters=normvalue[1]
365  amodetag=normvalue[2]
366  egev=normvalue[3]
367  comment=normvalue[4]
368  insertValueToNormId(schema,destnormid,sincerun,corrector,amodetag,egev,comment=comment)
369  except:
370  raise
def exportNormValue
copy/export/import
Definition: normDML.py:339
def insertValueToNormId
Definition: normDML.py:298
def normValueById
Definition: normDML.py:181
def normIdByName
Definition: normDML.py:60
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.

References nameDealer.luminormv2dataTableName().

Referenced by exportNormValue().

299 def insertValueToNormId(schema,normdataid,sincerun,corrector,amodetag,egev,parameters,comment=''):
300  '''
301  insert into LUMINORMSV2DATA(DATA_ID,SINCERUN,CORRECTOR,...) values(normdataid,)sincerun,corrector,...);
302  require len(parameters)>=1.
303  input:
304  parameterDict {'NORM_OCC1':normocc1,'NORM_OCC2':normocc2,'NORM_ET':normet,'NORM_PU':normpu,'DRIFT':drift,'A1':a1,...}
305  output:
306  '''
307  if len(parameters)==0:
308  raise ValueError('appendValueToNormId: at least one value is required')
309  try:
310  db=dbUtil.dbUtil(schema)
311  tabrowDefDict={}
312  tabrowDefDict['DATA_ID']='unsigned long long'
313  tabrowDefDict['CORRECTOR']='string'
314  tabrowDefDict['SINCE']='unsigned int'
315  tabrowDefDict['AMODETAG']='string'
316  tabrowDefDict['NOMINALEGEV']='unsigned int'
317  tabrowDefDict['COMMENT']='string'
318  tabrowValueDict={}
319  tabrowValueDict['DATA_ID']=normdataid
320  tabrowValueDict['CORRECTOR']=corrector
321  tabrowValueDict['SINCE']=sincerun
322  tabrowValueDict['AMODETAG']=amodetag
323  tabrowValueDict['NOMINALEGEV']=egev
324  tabrowValueDict['COMMENT']=comment
325  for paramname,paramvalue in parameters.items():
326  try:
327  floatparam=float(paramvalue)
328  tabrowDefDict[paramname.upper()]='float'
329  tabrowValueDict[paramname.upper()]=float(paramvalue)
330  except ValueError:
331  tabrowDefDict[paramname.upper()]='string'
332  tabrowValueDict[paramname.upper()]=paramvalue
333  db.insertOneRow(nameDealer.luminormv2dataTableName(),tabrowDefDict,tabrowValueDict)
334  except:
raise
def luminormv2dataTableName
Definition: nameDealer.py:43
def insertValueToNormId
Definition: normDML.py:298
def normDML.normIdByName (   schema,
  normname 
)
select max(DATA_ID) FROM LUMINORMSV2 WHERE ENTRY_NAME=:normname

Definition at line 60 of file normDML.py.

References data, nameDealer.luminormv2TableName(), bookConverter.max, and GetRecoTauVFromDQM_MC_cff.next.

Referenced by demoteNormFromTypeDefault(), exportNormValue(), and promoteNormToTypeDefault().

60 
61 def normIdByName(schema,normname):
62  '''
63  select max(DATA_ID) FROM LUMINORMSV2 WHERE ENTRY_NAME=:normname
64  '''
65  luminormids=[]
66  result=None
67  qHandle=schema.newQuery()
68  try:
69  qHandle.addToTableList( nameDealer.luminormv2TableName() )
70  qHandle.addToOutputList('DATA_ID')
71  if normname:
72  qConditionStr='ENTRY_NAME=:normname '
73  qCondition=coral.AttributeList()
74  qCondition.extend('normname','string')
75  qCondition['normname'].setData(normname)
76  qResult=coral.AttributeList()
77  qResult.extend('DATA_ID','unsigned long long')
78  qHandle.defineOutput(qResult)
79  if normname:
80  qHandle.setCondition(qConditionStr,qCondition)
81  cursor=qHandle.execute()
82  while next(cursor):
83  dataid=cursor.currentRow()['DATA_ID'].data()
84  luminormids.append(dataid)
85  except :
86  del qHandle
87  raise
88  del qHandle
89  if len(luminormids) !=0:
90  return max(luminormids)
91  return result
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
def luminormv2TableName
Definition: nameDealer.py:40
def normIdByName
Definition: normDML.py:60
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.

References data, nameDealer.luminormv2TableName(), and GetRecoTauVFromDQM_MC_cff.next.

Referenced by promoteNormToTypeDefault().

92 
93 def normIdByType(schema,lumitype='HF',defaultonly=True):
94  '''
95  select max(DATA_ID) FROM LUMINORMSV2 WHERE LUMITYPE=:lumitype
96  output:
97  luminormidmap {normname:normid}
98  '''
99  luminormidmap={}
100  qHandle=schema.newQuery()
101  try:
102  qHandle.addToTableList( nameDealer.luminormv2TableName() )
103  qHandle.addToOutputList('DATA_ID')
104  qHandle.addToOutputList('ENTRY_NAME')
105  qConditionStr='LUMITYPE=:lumitype'
106  qCondition=coral.AttributeList()
107  qCondition.extend('lumitype','string')
108  qCondition['lumitype'].setData(lumitype)
109  if defaultonly:
110  qConditionStr+=' AND ISTYPEDEFAULT=:istypedefault'
111  qCondition.extend('istypedefault','unsigned int')
112  qCondition['istypedefault'].setData(int(1))
113  qResult=coral.AttributeList()
114  qResult.extend('DATA_ID','unsigned long long')
115  qResult.extend('ENTRY_NAME','string')
116  qHandle.defineOutput(qResult)
117  qHandle.setCondition(qConditionStr,qCondition)
118  cursor=qHandle.execute()
119  while next(cursor):
120  if not cursor.currentRow()['DATA_ID'].isNull():
121  dataid=cursor.currentRow()['DATA_ID'].data()
122  normname=cursor.currentRow()['ENTRY_NAME'].data()
123  if normname not in luminormidmap:
124  luminormidmap[normname]=dataid
125  else:
126  if dataid>luminormidmap[normname]:
127  luminormidmap[normname]=dataid
128  except :
129  del qHandle
130  raise
131  del qHandle
132  return luminormidmap
def normIdByType
Definition: normDML.py:92
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
def luminormv2TableName
Definition: nameDealer.py:40
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.

References data, nameDealer.luminormv2TableName(), bookConverter.max, and GetRecoTauVFromDQM_MC_cff.next.

134 def normInfoByName(schema,normname):
135  '''
136  select DATA_ID,LUMITYPE,ISTYPEDEFAULT,COMMENT,TO_CHAR(CTIME,\'MM/DD/YY HH24:MI\') FROM LUMINORMS WHERE ENTRY_NAME=:normname
137  output:
138  [data_id[0],lumitype[1],istypedefault[2],comment[3],creationtime[4]]
139  '''
140  result={}
141  qHandle=schema.newQuery()
142  try:
143  qHandle.addToTableList( nameDealer.luminormv2TableName() )
144  qHandle.addToOutputList('DATA_ID')
145  qHandle.addToOutputList('LUMITYPE')
146  qHandle.addToOutputList('ISTYPEDEFAULT')
147  qHandle.addToOutputList('COMMENT')
148  qHandle.addToOutputList('TO_CHAR(CTIME,\'MM/DD/YY HH24:MI\')','ctime')
149  qConditionStr='ENTRY_NAME=:normname'
150  qCondition=coral.AttributeList()
151  qCondition.extend('normname','string')
152  qCondition['normname'].setData(normname)
153  qResult=coral.AttributeList()
154  qResult.extend('DATA_ID','unsigned long long')
155  qResult.extend('LUMITYPE','string')
156  qResult.extend('ISTYPEDEFAULT','unsigned int')
157  qResult.extend('COMMENT','string')
158  qResult.extend('ctime','string')
159  qHandle.defineOutput(qResult)
160  qHandle.setCondition(qConditionStr,qCondition)
161  cursor=qHandle.execute()
162  while next(cursor):
163  if not cursor.currentRow()['DATA_ID'].isNull():
164  dataid=cursor.currentRow()['DATA_ID'].data()
165  else:
166  continue
167  lumitype=cursor.currentRow()['LUMITYPE'].data()
168  istypedefault=cursor.currentRow()['ISTYPEDEFAULT'].data()
169  comment=''
170  if not cursor.currentRow()['COMMENT'].isNull():
171  comment=cursor.currentRow()['COMMENT'].data()
172  creationtime=cursor.currentRow()['ctime'].data()
173  if dataid not in result:
174  result[dataid]=[dataid,lumitype,istypedefault,comment,creationtime]
175  except :
176  del qHandle
177  raise
178  if len(result)>0:
179  maxdataid=max(result.keys())
180  return result[maxdataid]
return result
def normInfoByName
Definition: normDML.py:133
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
def luminormv2TableName
Definition: nameDealer.py:40
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.

References data, nameDealer.luminormv2dataTableName(), GetRecoTauVFromDQM_MC_cff.next, and CommonUtil.parselumicorrector().

Referenced by exportNormValue().

182 def normValueById(schema,normid):
183  '''
184  select * from luminormsv2data where data_id=normid
185  output:
186  {since:[corrector(0),{paramname:paramvalue}(1),amodetag(2),egev(3),comment(4)]}
187  '''
188  result={}
190  paramdict={}
191  qHandle=schema.newQuery()
192  try:
193  qHandle.addToTableList(l)
194  qConditionStr='DATA_ID=:normid'
195  qCondition=coral.AttributeList()
196  qCondition.extend('normid','unsigned long long')
197  qCondition['normid'].setData(normid)
198  qResult=coral.AttributeList()
199  qHandle.setCondition(qConditionStr,qCondition)
200  cursor=qHandle.execute()
201  while next(cursor):
202  since=cursor.currentRow()['SINCE'].data()
203  corrector=cursor.currentRow()['CORRECTOR'].data()
204  amodetag=cursor.currentRow()['AMODETAG'].data()
205  nominalegev=cursor.currentRow()['NOMINALEGEV'].data()
206  comment=''
207  if not cursor.currentRow()['COMMENT'].isNull():
208  comment=cursor.currentRow()['COMMENT'].data()
209  (correctorfunc,params)=CommonUtil.parselumicorrector(corrector)
210  paramdict={}
211  for param in params:
212  paramvalue=0.0
213  if not cursor.currentRow()[param.upper()].isNull():
214  paramvalue=cursor.currentRow()[param.upper()].data()
215  paramdict[param]=paramvalue
216  result[since]=[correctorfunc,paramdict,amodetag,nominalegev,comment]
217  except:
218  raise
219  return result
220 
221 #=======================================================
222 # INSERT/UPDATE requires in update transaction
#=======================================================
def parselumicorrector
Definition: CommonUtil.py:271
def luminormv2dataTableName
Definition: nameDealer.py:43
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
def normValueById
Definition: normDML.py:181
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.

References normIdByName(), and normIdByType().

265 def promoteNormToTypeDefault(schema,normname,lumitype):
266  '''
267  set the named norm as default for a given type,reset the old default if any
268  thisnormid=normIdByName(schema,normname)
269  olddefaultid=normIdByType(schema,lumitype=lumitype,defaultonly=True)
270  if thisnormid:
271  update LUMINORMSV2 set ISTYPEDEFAULT=1 where DATA_ID=:thisnormid
272  else:
273  raise ValueError('normname does not exist, nothing to update')
274  if olddefaultid and olddefaultid!=thisnormid:
275  update LUMINORMSV2 set ISTYPEDEFAULT=0 where DATA_ID=:olddefaultid
276  '''
277  try:
278  thisnormid=normIdByName(schema,normname)
279  olddefaultid=normIdByType(schema,lumitype=lumitype,defaultonly=True)
280  if not thisnormid:
281  raise ValueError(normname+' does not exist, nothing to update')
282  setClause='ISTYPEDEFAULT=1'
283  updateCondition='DATA_ID=:thisnormid'
284  inputData=coral.AttributeList()
285  inputData.extend('thisnormid','unsigned long long')
286  inputData['thisnormid'].setData(thisnormid)
287  db=dbUtil.dbUtil(schema)
288  db.singleUpdate(nameDealer.luminormTable(),setClause,updateCondition,inputData)
289  if olddefaultid:
290  setClause='ISTYPEDEFAULT=0'
291  updateCondition='DATA_ID=:olddefaultid'
292  inputData=coral.AttributeList()
293  inputData.extend('olddefaultid','unsigned long long')
294  inputData['olddefaultid'].setData(olddefaultid)
295  db=dbUtil.dbUtil(schema)
296  db.singleUpdate(nameDealer.luminormTable(),setClause,updateCondition,inputData)
297  except :
raise
def promoteNormToTypeDefault
Definition: normDML.py:264
def normIdByType
Definition: normDML.py:92
def normIdByName
Definition: normDML.py:60