2 from RecoLuminosity.LumiDB
import nameDealer,dbUtil
10 create new tables if not exist
11 revisions,revisions_id,luminorms,luminorms_entries,luminorms_entries_id,fillscheme
17 print 'creating fillscheme table'
18 fillschemeTab=coral.TableDescription()
20 fillschemeTab.insertColumn(
'FILLSCHEME_ID',
'unsigned long long' )
21 fillschemeTab.insertColumn(
'FILLSCHEMEPATTERN',
'string',128,
False )
22 fillschemeTab.insertColumn(
'CORRECTIONFACTOR',
'float' )
23 fillschemeTab.setPrimaryKey(
'FILLSCHEME_ID' )
24 db.createTable(fillschemeTab,withIdTable=
True)
28 print 'creating revisions table'
29 revisionsTab=coral.TableDescription()
31 revisionsTab.insertColumn(
'REVISION_ID',
'unsigned long long')
32 revisionsTab.insertColumn(
'BRANCH_ID',
'unsigned long long')
33 revisionsTab.insertColumn(
'NAME',
'string',56,
False)
34 revisionsTab.insertColumn(
'BRANCH_NAME',
'string',56,
False)
35 revisionsTab.insertColumn(
'COMMENT',
'string',1024,
False)
36 revisionsTab.insertColumn(
'CTIME',
'time stamp',6)
37 revisionsTab.setPrimaryKey(
'REVISION_ID' )
38 revisionsTab.setUniqueConstraint((
'NAME'))
39 db.createTable(revisionsTab,withIdTable=
True)
43 print 'creating luminorms table'
44 luminormsTab=coral.TableDescription()
46 luminormsTab.insertColumn(
'DATA_ID',
'unsigned long long')
47 luminormsTab.insertColumn(
'ENTRY_ID',
'unsigned long long')
48 luminormsTab.insertColumn(
'ENTRY_NAME',
'string',56,
False)
49 luminormsTab.insertColumn(
'AMODETAG',
'string',28,
False)
50 luminormsTab.insertColumn(
'NORM_1',
'float')
51 luminormsTab.insertColumn(
'EGEV_1',
'unsigned int')
52 luminormsTab.insertColumn(
'NORM_2',
'float')
53 luminormsTab.insertColumn(
'EGEV_2',
'unsigned int')
54 luminormsTab.setPrimaryKey(
'DATA_ID' )
55 db.createTable(luminormsTab,withIdTable=
True,withEntryTables=
True,withRevMapTable=
True)
59 print 'creating lumidata table'
60 lumidataTab=coral.TableDescription()
62 lumidataTab.insertColumn(
'DATA_ID',
'unsigned long long')
63 lumidataTab.insertColumn(
'ENTRY_ID',
'unsigned long long')
64 lumidataTab.insertColumn(
'ENTRY_NAME',
'string',56,
False)
65 lumidataTab.insertColumn(
'SOURCE',
'string',128,
False)
66 lumidataTab.insertColumn(
'RUNNUM',
'unsigned int')
67 lumidataTab.insertColumn(
'NOMINALEGEV',
'float')
68 lumidataTab.setPrimaryKey(
'DATA_ID' )
69 db.createTable(lumidataTab,withIdTable=
True,withEntryTables=
True,withRevMapTable=
True)
73 print 'creating lumisummaryv2 table'
74 summary=coral.TableDescription()
76 summary.insertColumn(
'DATA_ID',
'unsigned long long')
77 summary.insertColumn(
'RUNNUM',
'unsigned int')
78 summary.insertColumn(
'LUMILSNUM',
'unsigned int')
79 summary.insertColumn(
'CMSLSNUM',
'unsigned int')
80 summary.insertColumn(
'INSTLUMI',
'float')
81 summary.insertColumn(
'INSTLUMIERROR',
'float')
82 summary.insertColumn(
'INSTLUMIQUALITY',
'short')
83 summary.insertColumn(
'BEAMSTATUS',
'string',28,
False)
84 summary.insertColumn(
'BEAMENERGY',
'float')
85 summary.insertColumn(
'NUMORBIT',
'unsigned int')
86 summary.insertColumn(
'STARTORBIT',
'unsigned int')
87 summary.insertColumn(
'CMSBXINDEXBLOB',
'blob')
88 summary.insertColumn(
'BEAMINTENSITYBLOB_1',
'blob')
89 summary.insertColumn(
'BEAMINTENSITYBLOB_2',
'blob')
90 summary.insertColumn(
'BXLUMIVALUE_OCC1',
'blob')
91 summary.insertColumn(
'BXLUMIVALUE_OCC2',
'blob')
92 summary.insertColumn(
'BXLUMIVALUE_ET',
'blob')
93 summary.insertColumn(
'BXLUMIERROR_OCC1',
'blob')
94 summary.insertColumn(
'BXLUMIERROR_OCC2',
'blob')
95 summary.insertColumn(
'BXLUMIERROR_ET',
'blob')
96 summary.insertColumn(
'BXLUMIQUALITY_OCC1',
'blob')
97 summary.insertColumn(
'BXLUMIQUALITY_OCC2',
'blob')
98 summary.insertColumn(
'BXLUMIQUALITY_ET',
'blob')
99 summary.setPrimaryKey((
'DATA_ID',
'LUMILSNUM'))
100 db.createTable(summary,withIdTable=
False)
107 print 'creating cmsrunsummary table'
108 cmsrunsummary=coral.TableDescription()
110 cmsrunsummary.insertColumn(
'RUNNUM',
'unsigned int')
111 cmsrunsummary.insertColumn(
'HLTKEY',
'string',128,
False)
112 cmsrunsummary.insertColumn(
'L1KEY',
'string',128,
False)
113 cmsrunsummary.insertColumn(
'FILLNUM',
'unsigned int')
114 cmsrunsummary.insertColumn(
'SEQUENCE',
'string',56,
False)
115 cmsrunsummary.insertColumn(
'STARTTIME',
'time stamp',6)
116 cmsrunsummary.insertColumn(
'STOPTIME',
'time stamp',6)
117 cmsrunsummary.insertColumn(
'EGEV',
'unsigned int')
118 cmsrunsummary.insertColumn(
'AMODETAG',
'string',28,
False)
119 cmsrunsummary.insertColumn(
'FILLSCHEME',
'string',128,
False)
120 cmsrunsummary.insertColumn(
'NCOLLIDINGBUNCHES',
'usigned int')
121 cmsrunsummary.setPrimaryKey(
'RUNNUM')
122 db.createTable(cmsrunsummary,withIdTable=
False)
128 print 'creating trghltmap table'
129 trghlt=coral.TableDescription()
131 trghlt.insertColumn(
'HLTKEY',
'string',128,
False )
132 trghlt.insertColumn(
'HLTPATHNAME',
'string',256,
False )
133 trghlt.insertColumn(
'L1SEED',
'string' ,1024,
False)
134 trghlt.setNotNullConstraint(
'HLTKEY',
True)
135 trghlt.setNotNullConstraint(
'HLTPATHNAME',
True)
136 trghlt.setNotNullConstraint(
'L1SEED',
True)
137 db.createTable(trghlt,withIdTable=
False)
140 print 'creating trgdata table'
141 trgdataTab=coral.TableDescription()
143 trgdataTab.insertColumn(
'DATA_ID',
'unsigned long long')
144 trgdataTab.insertColumn(
'ENTRY_ID',
'unsigned long long')
145 trgdataTab.insertColumn(
'ENTRY_NAME',
'string',56,
False)
146 trgdataTab.insertColumn(
'SOURCE',
'string',128,
False)
147 trgdataTab.insertColumn(
'RUNNUM',
'unsigned int')
148 trgdataTab.insertColumn(
'BITZERONAME',
'string',56,
False)
149 trgdataTab.insertColumn(
'BITNAMECLOB',
'string',6000)
150 trgdataTab.setPrimaryKey(
'DATA_ID' )
151 db.createTable(trgdataTab,withIdTable=
True,withEntryTables=
True,withRevMapTable=
True)
154 print 'creating lstrg table'
155 lstrgTab=coral.TableDescription()
157 lstrgTab.insertColumn(
'DATA_ID',
'unsigned long long')
158 lstrgTab.insertColumn(
'RUNNUM',
'unsigned int')
159 lstrgTab.insertColumn(
'CMSLSNUM',
'unsigned int')
160 lstrgTab.insertColumn(
'DEADTIMECOUNT',
'unsigned long long')
161 lstrgTab.insertColumn(
'BITZEROCOUNT',
'unsigned int')
162 lstrgTab.insertColumn(
'BITZEROPRESCALE',
'unsigned int')
163 lstrgTab.insertColumn(
'DEADFRAC',
'float')
164 lstrgTab.insertColumn(
'PRESCALEBLOB',
'blob')
165 lstrgTab.insertColumn(
'TRGCOUNTBLOB',
'blob')
166 lstrgTab.setPrimaryKey( (
'DATA_ID',
'CMSLSNUM') )
167 db.createTable(lstrgTab,withIdTable=
False)
171 print 'creating hltdata table'
172 hltdataTab=coral.TableDescription()
174 hltdataTab.insertColumn(
'DATA_ID',
'unsigned long long')
175 hltdataTab.insertColumn(
'ENTRY_ID',
'unsigned long long')
176 hltdataTab.insertColumn(
'ENTRY_NAME',
'string',56,
False)
177 hltdataTab.insertColumn(
'RUNNUM',
'unsigned int')
178 hltdataTab.insertColumn(
'SOURCE',
'string',128,
False)
179 hltdataTab.insertColumn(
'NPATH',
'unsigned int')
180 hltdataTab.insertColumn(
'PATHNAMECLOB',
'string',6000)
181 hltdataTab.setPrimaryKey(
'DATA_ID' )
182 db.createTable(hltdataTab,withIdTable=
True,withEntryTables=
True,withRevMapTable=
True)
186 print 'creating lshlt table'
187 lshltTab=coral.TableDescription()
189 lshltTab.insertColumn(
'DATA_ID',
'unsigned long long')
190 lshltTab.insertColumn(
'RUNNUM',
'unsigned int')
191 lshltTab.insertColumn(
'CMSLSNUM',
'unsigned int')
192 lshltTab.insertColumn(
'PRESCALEBLOB',
'blob')
193 lshltTab.insertColumn(
'HLTCOUNTBLOB',
'blob')
194 lshltTab.insertColumn(
'HLTACCEPTBLOB',
'blob')
195 db.createTable(lshltTab,withIdTable=
False)
196 lshltTab.setPrimaryKey( (
'DATA_ID',
'CMSLSNUM') )
201 print 'creating lumivalidation table'
202 lumivalidation=coral.TableDescription()
204 lumivalidation.insertColumn(
'RUNNUM',
'unsigned int' )
205 lumivalidation.insertColumn(
'CMSLSNUM',
'unsigned int' )
206 lumivalidation.insertColumn(
'FLAG',
'string',28,
False )
207 lumivalidation.insertColumn(
'COMMENT',
'string',1024,
False )
208 lumivalidation.setPrimaryKey( (
'RUNNUM',
'CMSLSNUM') )
209 lumivalidation.setNotNullConstraint(
'FLAG',
True)
210 db.createTable(lumivalidation,withIdTable=
False)
225 for tablename
in tablelist:
232 db.dropTable( tablename )
238 create tables of lumidb1 if not exist
244 lumivalidation=coral.TableDescription()
246 lumivalidation.insertColumn(
'RUNNUM',
'unsigned int' )
247 lumivalidation.insertColumn(
'CMSLSNUM',
'unsigned int' )
248 lumivalidation.insertColumn(
'FLAG',
'string',28,
False )
249 lumivalidation.insertColumn(
'COMMENT',
'string',1024,
False )
250 lumivalidation.setPrimaryKey((
'RUNNUM',
'CMSLSNUM'))
251 lumivalidation.setNotNullConstraint(
'FLAG',
True)
252 db.createTable(lumivalidation,withIdTable=
False)
256 cmsrunsummary=coral.TableDescription()
258 cmsrunsummary.insertColumn(
'RUNNUM',
'unsigned int')
259 cmsrunsummary.insertColumn(
'HLTKEY',
'string',128,
False)
260 cmsrunsummary.insertColumn(
'FILLNUM',
'unsigned int')
261 cmsrunsummary.insertColumn(
'SEQUENCE',
'string',56,
False)
262 cmsrunsummary.insertColumn(
'STARTTIME',
'time stamp',6)
263 cmsrunsummary.insertColumn(
'STOPTIME',
'time stamp',6)
264 cmsrunsummary.setPrimaryKey(
'RUNNUM')
265 cmsrunsummary.setNotNullConstraint(
'HLTKEY',
True)
266 cmsrunsummary.setNotNullConstraint(
'FILLNUM',
True)
267 cmsrunsummary.setNotNullConstraint(
'SEQUENCE',
True)
268 cmsrunsummary.createIndex(
'cmsrunsummary_fillnum',(
'FILLNUM'))
269 cmsrunsummary.createIndex(
'cmsrunsummary_startime',(
'STARTTIME'))
270 db.createTable(cmsrunsummary,withIdTable=
False)
274 summary=coral.TableDescription()
276 summary.insertColumn(
'LUMISUMMARY_ID',
'unsigned long long')
277 summary.insertColumn(
'RUNNUM',
'unsigned int')
278 summary.insertColumn(
'CMSLSNUM',
'unsigned int')
279 summary.insertColumn(
'LUMILSNUM',
'unsigned int')
280 summary.insertColumn(
'LUMIVERSION',
'string',28,
False)
281 summary.insertColumn(
'DTNORM',
'float')
282 summary.insertColumn(
'LHCNORM',
'float')
283 summary.insertColumn(
'CMSALIVE',
'short')
284 summary.insertColumn(
'INSTLUMI',
'float')
285 summary.insertColumn(
'INSTLUMIERROR',
'float')
286 summary.insertColumn(
'INSTLUMIQUALITY',
'short')
287 summary.insertColumn(
'BEAMSTATUS',
'string',28,
False)
288 summary.insertColumn(
'BEAMENERGY',
'float')
289 summary.insertColumn(
'NUMORBIT',
'unsigned int')
290 summary.insertColumn(
'STARTORBIT',
'unsigned int')
291 summary.insertColumn(
'LUMISECTIONQUALITY',
'short')
292 summary.insertColumn(
'CMSBXINDEXBLOB',
'blob')
293 summary.insertColumn(
'BEAMINTENSITYBLOB_1',
'blob')
294 summary.insertColumn(
'BEAMINTENSITYBLOB_2',
'blob')
295 summary.setPrimaryKey(
'LUMISUMMARY_ID')
296 summary.setNotNullConstraint(
'RUNNUM',
True)
297 summary.setNotNullConstraint(
'CMSLSNUM',
True)
298 summary.setNotNullConstraint(
'LUMILSNUM',
True)
299 summary.setNotNullConstraint(
'CMSALIVE',
True)
300 summary.setNotNullConstraint(
'LUMIVERSION',
True)
301 summary.setNotNullConstraint(
'DTNORM',
True)
302 summary.setNotNullConstraint(
'LHCNORM',
True)
303 summary.setNotNullConstraint(
'INSTLUMI',
True)
304 summary.setNotNullConstraint(
'INSTLUMIERROR',
True)
305 summary.setNotNullConstraint(
'INSTLUMIQUALITY',
True)
306 summary.setNotNullConstraint(
'STARTORBIT',
True)
307 summary.setNotNullConstraint(
'NUMORBIT',
True)
308 summary.setNotNullConstraint(
'LUMISECTIONQUALITY',
True)
309 summary.setNotNullConstraint(
'BEAMENERGY',
True)
310 summary.setNotNullConstraint(
'BEAMSTATUS',
True)
311 summary.setUniqueConstraint((
'RUNNUM',
'LUMIVERSION',
'LUMILSNUM'))
312 summary.createIndex(
'lumisummary_runnum',(
'RUNNUM'))
313 db.createTable(summary,withIdTable=
True)
317 detail=coral.TableDescription()
319 detail.insertColumn(
'LUMIDETAIL_ID',
'unsigned long long')
320 detail.insertColumn(
'LUMISUMMARY_ID',
'unsigned long long')
321 detail.insertColumn(
'BXLUMIVALUE',
'blob')
322 detail.insertColumn(
'BXLUMIERROR',
'blob')
323 detail.insertColumn(
'BXLUMIQUALITY',
'blob')
324 detail.insertColumn(
'ALGONAME',
'string',28,
False)
325 detail.setPrimaryKey(
'LUMIDETAIL_ID')
327 detail.setNotNullConstraint(
'BXLUMIVALUE',
True)
328 detail.setNotNullConstraint(
'BXLUMIERROR',
True)
329 detail.setNotNullConstraint(
'BXLUMIQUALITY',
True)
330 detail.setNotNullConstraint(
'ALGONAME',
True)
331 detail.setUniqueConstraint((
'LUMISUMMARY_ID',
'ALGONAME'))
332 db.createTable(detail,withIdTable=
True)
336 trg=coral.TableDescription()
338 trg.insertColumn(
'TRG_ID',
'unsigned long long')
339 trg.insertColumn(
'RUNNUM',
'unsigned int')
340 trg.insertColumn(
'CMSLSNUM',
'unsigned int')
341 trg.insertColumn(
'BITNUM',
'unsigned int')
342 trg.insertColumn(
'BITNAME',
'string',56,
False)
343 trg.insertColumn(
'TRGCOUNT',
'unsigned int')
344 trg.insertColumn(
'DEADTIME',
'unsigned long long')
345 trg.insertColumn(
'PRESCALE',
'unsigned int')
346 trg.setNotNullConstraint(
'RUNNUM',
True)
347 trg.setNotNullConstraint(
'CMSLSNUM',
True)
348 trg.setNotNullConstraint(
'BITNUM',
True)
349 trg.setNotNullConstraint(
'BITNAME',
True)
350 trg.setNotNullConstraint(
'TRGCOUNT',
True)
351 trg.setNotNullConstraint(
'DEADTIME',
True)
352 trg.setNotNullConstraint(
'PRESCALE',
True)
353 trg.setPrimaryKey(
'TRG_ID')
354 trg.createIndex(
'trg_runnum',(
'RUNNUM'))
355 db.createTable(trg,withIdTable=
True)
359 hlt=coral.TableDescription()
361 hlt.insertColumn(
'HLT_ID',
'unsigned long long')
362 hlt.insertColumn(
'RUNNUM',
'unsigned int')
363 hlt.insertColumn(
'CMSLSNUM',
'unsigned int')
364 hlt.insertColumn(
'PATHNAME',
'string',256,
False)
365 hlt.insertColumn(
'INPUTCOUNT',
'unsigned int')
366 hlt.insertColumn(
'ACCEPTCOUNT',
'unsigned int')
367 hlt.insertColumn(
'PRESCALE',
'unsigned int')
368 hlt.setPrimaryKey(
'HLT_ID' )
369 hlt.setNotNullConstraint(
'RUNNUM',
True)
370 hlt.setNotNullConstraint(
'CMSLSNUM',
True)
371 hlt.setNotNullConstraint(
'PATHNAME',
True)
372 hlt.setNotNullConstraint(
'INPUTCOUNT',
True)
373 hlt.setNotNullConstraint(
'ACCEPTCOUNT',
True)
374 hlt.setNotNullConstraint(
'PRESCALE',
True)
375 hlt.createIndex(
'hlt_runnum',(
'RUNNUM'))
376 db.createTable(hlt,withIdTable=
True)
380 trghlt=coral.TableDescription()
382 trghlt.insertColumn(
'HLTKEY',
'string',128,
False )
383 trghlt.insertColumn(
'HLTPATHNAME',
'string',256,
False )
384 trghlt.insertColumn(
'L1SEED',
'string',1024,false )
385 trghlt.setNotNullConstraint(
'HLTKEY',
True)
386 trghlt.setNotNullConstraint(
'HLTPATHNAME',
True)
387 trghlt.setNotNullConstraint(
'L1SEED',
True)
388 db.createTable(trghlt,withIdTable=
False)
401 modify old tables:cmsrunsummary
402 alter table cmsrunsummary add column(l1key string,egev unsigned int,amodetag string)
406 tableHandle.schemaEditor().insertColumn(
'L1KEY',
'string',128,
False)
407 tableHandle.schemaEditor().insertColumn(
'EGEV',
'unsigned int')
408 tableHandle.schemaEditor().insertColumn(
'AMODETAG',
'string',28,
False)
415 dropTables(schema,[
'REVISIONS',
'LUMINORMS',
'LUMIDATA',
'LUMISUMMARYV2',
'TRGDATA',
'LSTRG',
'HLTDATA',
'LSHLT'])
417 ncol=tableHandle.description().numberOfColumns()
419 for i
in range(ncol):
420 colname=tableHandle.description().columnDescription(i).
name()
421 if colname
in [
'L1KEY',
'EGEV',
'AMODETAG']:
422 todrop.append(colname)
423 for colname
in todrop:
424 tableHandle.schemaEditor().dropColumn(colname)
474 revtable.schemaEditor().setUniqueConstraint(
'NAME',
'revisions_name_uc')
487 if __name__ ==
"__main__":
488 import sessionManager
489 myconstr=
'oracle://devdb10/cms_xiezhen_dev'
490 authpath=
'/afs/cern.ch/user/x/xiezhen'
493 session=svc.openSession(isReadOnly=
False,cpp2sqltype=[(
'unsigned int',
'NUMBER(10)'),(
'unsigned long long',
'NUMBER(20)')])
494 schema=session.nominalSchema()
495 session.transaction().
start(
False)
507 session.transaction().
start(
False)
510 print 'created old ',tables
511 session.transaction().commit()
def lumivalidationTableName
def createUniqueConstraints
def dropUNIQUEConstraints
def createNULLConstraints
def lumisummaryv2TableName
def cmsrunsummaryTableName