1 from __future__
import print_function
3 from RecoLuminosity.LumiDB
import nameDealer,dbUtil
11 create new tables if not exist 12 revisions,revisions_id,luminorms,luminorms_entries,luminorms_entries_id,fillscheme 18 print(
'creating fillscheme table')
19 fillschemeTab=coral.TableDescription()
21 fillschemeTab.insertColumn(
'FILLSCHEME_ID',
'unsigned long long' )
22 fillschemeTab.insertColumn(
'FILLSCHEMEPATTERN',
'string',128,
False )
23 fillschemeTab.insertColumn(
'CORRECTIONFACTOR',
'float' )
24 fillschemeTab.setPrimaryKey(
'FILLSCHEME_ID' )
25 db.createTable(fillschemeTab,withIdTable=
True)
29 print(
'creating revisions table')
30 revisionsTab=coral.TableDescription()
32 revisionsTab.insertColumn(
'REVISION_ID',
'unsigned long long')
33 revisionsTab.insertColumn(
'BRANCH_ID',
'unsigned long long')
34 revisionsTab.insertColumn(
'NAME',
'string',56,
False)
35 revisionsTab.insertColumn(
'BRANCH_NAME',
'string',56,
False)
36 revisionsTab.insertColumn(
'COMMENT',
'string',1024,
False)
37 revisionsTab.insertColumn(
'CTIME',
'time stamp',6)
38 revisionsTab.setPrimaryKey(
'REVISION_ID' )
39 revisionsTab.setUniqueConstraint((
'NAME'))
40 db.createTable(revisionsTab,withIdTable=
True)
44 print(
'creating luminorms table')
45 luminormsTab=coral.TableDescription()
47 luminormsTab.insertColumn(
'DATA_ID',
'unsigned long long')
48 luminormsTab.insertColumn(
'ENTRY_ID',
'unsigned long long')
49 luminormsTab.insertColumn(
'ENTRY_NAME',
'string',56,
False)
50 luminormsTab.insertColumn(
'AMODETAG',
'string',28,
False)
51 luminormsTab.insertColumn(
'NORM_1',
'float')
52 luminormsTab.insertColumn(
'EGEV_1',
'unsigned int')
53 luminormsTab.insertColumn(
'NORM_2',
'float')
54 luminormsTab.insertColumn(
'EGEV_2',
'unsigned int')
55 luminormsTab.setPrimaryKey(
'DATA_ID' )
56 db.createTable(luminormsTab,withIdTable=
True,withEntryTables=
True,withRevMapTable=
True)
60 print(
'creating lumidata table')
61 lumidataTab=coral.TableDescription()
63 lumidataTab.insertColumn(
'DATA_ID',
'unsigned long long')
64 lumidataTab.insertColumn(
'ENTRY_ID',
'unsigned long long')
65 lumidataTab.insertColumn(
'ENTRY_NAME',
'string',56,
False)
66 lumidataTab.insertColumn(
'SOURCE',
'string',128,
False)
67 lumidataTab.insertColumn(
'RUNNUM',
'unsigned int')
68 lumidataTab.insertColumn(
'NOMINALEGEV',
'float')
69 lumidataTab.setPrimaryKey(
'DATA_ID' )
70 db.createTable(lumidataTab,withIdTable=
True,withEntryTables=
True,withRevMapTable=
True)
74 print(
'creating lumisummaryv2 table')
75 summary=coral.TableDescription()
77 summary.insertColumn(
'DATA_ID',
'unsigned long long')
78 summary.insertColumn(
'RUNNUM',
'unsigned int')
79 summary.insertColumn(
'LUMILSNUM',
'unsigned int')
80 summary.insertColumn(
'CMSLSNUM',
'unsigned int')
81 summary.insertColumn(
'INSTLUMI',
'float')
82 summary.insertColumn(
'INSTLUMIERROR',
'float')
83 summary.insertColumn(
'INSTLUMIQUALITY',
'short')
84 summary.insertColumn(
'BEAMSTATUS',
'string',28,
False)
85 summary.insertColumn(
'BEAMENERGY',
'float')
86 summary.insertColumn(
'NUMORBIT',
'unsigned int')
87 summary.insertColumn(
'STARTORBIT',
'unsigned int')
88 summary.insertColumn(
'CMSBXINDEXBLOB',
'blob')
89 summary.insertColumn(
'BEAMINTENSITYBLOB_1',
'blob')
90 summary.insertColumn(
'BEAMINTENSITYBLOB_2',
'blob')
91 summary.insertColumn(
'BXLUMIVALUE_OCC1',
'blob')
92 summary.insertColumn(
'BXLUMIVALUE_OCC2',
'blob')
93 summary.insertColumn(
'BXLUMIVALUE_ET',
'blob')
94 summary.insertColumn(
'BXLUMIERROR_OCC1',
'blob')
95 summary.insertColumn(
'BXLUMIERROR_OCC2',
'blob')
96 summary.insertColumn(
'BXLUMIERROR_ET',
'blob')
97 summary.insertColumn(
'BXLUMIQUALITY_OCC1',
'blob')
98 summary.insertColumn(
'BXLUMIQUALITY_OCC2',
'blob')
99 summary.insertColumn(
'BXLUMIQUALITY_ET',
'blob')
100 summary.setPrimaryKey((
'DATA_ID',
'LUMILSNUM'))
101 db.createTable(summary,withIdTable=
False)
108 print(
'creating cmsrunsummary table')
109 cmsrunsummary=coral.TableDescription()
111 cmsrunsummary.insertColumn(
'RUNNUM',
'unsigned int')
112 cmsrunsummary.insertColumn(
'HLTKEY',
'string',128,
False)
113 cmsrunsummary.insertColumn(
'L1KEY',
'string',128,
False)
114 cmsrunsummary.insertColumn(
'FILLNUM',
'unsigned int')
115 cmsrunsummary.insertColumn(
'SEQUENCE',
'string',56,
False)
116 cmsrunsummary.insertColumn(
'STARTTIME',
'time stamp',6)
117 cmsrunsummary.insertColumn(
'STOPTIME',
'time stamp',6)
118 cmsrunsummary.insertColumn(
'EGEV',
'unsigned int')
119 cmsrunsummary.insertColumn(
'AMODETAG',
'string',28,
False)
120 cmsrunsummary.insertColumn(
'FILLSCHEME',
'string',128,
False)
121 cmsrunsummary.insertColumn(
'NCOLLIDINGBUNCHES',
'usigned int')
122 cmsrunsummary.setPrimaryKey(
'RUNNUM')
123 db.createTable(cmsrunsummary,withIdTable=
False)
129 print(
'creating trghltmap table')
130 trghlt=coral.TableDescription()
132 trghlt.insertColumn(
'HLTKEY',
'string',128,
False )
133 trghlt.insertColumn(
'HLTPATHNAME',
'string',256,
False )
134 trghlt.insertColumn(
'L1SEED',
'string' ,1024,
False)
135 trghlt.setNotNullConstraint(
'HLTKEY',
True)
136 trghlt.setNotNullConstraint(
'HLTPATHNAME',
True)
137 trghlt.setNotNullConstraint(
'L1SEED',
True)
138 db.createTable(trghlt,withIdTable=
False)
141 print(
'creating trgdata table')
142 trgdataTab=coral.TableDescription()
144 trgdataTab.insertColumn(
'DATA_ID',
'unsigned long long')
145 trgdataTab.insertColumn(
'ENTRY_ID',
'unsigned long long')
146 trgdataTab.insertColumn(
'ENTRY_NAME',
'string',56,
False)
147 trgdataTab.insertColumn(
'SOURCE',
'string',128,
False)
148 trgdataTab.insertColumn(
'RUNNUM',
'unsigned int')
149 trgdataTab.insertColumn(
'BITZERONAME',
'string',56,
False)
150 trgdataTab.insertColumn(
'BITNAMECLOB',
'string',6000)
151 trgdataTab.setPrimaryKey(
'DATA_ID' )
152 db.createTable(trgdataTab,withIdTable=
True,withEntryTables=
True,withRevMapTable=
True)
155 print(
'creating lstrg table')
156 lstrgTab=coral.TableDescription()
158 lstrgTab.insertColumn(
'DATA_ID',
'unsigned long long')
159 lstrgTab.insertColumn(
'RUNNUM',
'unsigned int')
160 lstrgTab.insertColumn(
'CMSLSNUM',
'unsigned int')
161 lstrgTab.insertColumn(
'DEADTIMECOUNT',
'unsigned long long')
162 lstrgTab.insertColumn(
'BITZEROCOUNT',
'unsigned int')
163 lstrgTab.insertColumn(
'BITZEROPRESCALE',
'unsigned int')
164 lstrgTab.insertColumn(
'DEADFRAC',
'float')
165 lstrgTab.insertColumn(
'PRESCALEBLOB',
'blob')
166 lstrgTab.insertColumn(
'TRGCOUNTBLOB',
'blob')
167 lstrgTab.setPrimaryKey( (
'DATA_ID',
'CMSLSNUM') )
168 db.createTable(lstrgTab,withIdTable=
False)
172 print(
'creating hltdata table')
173 hltdataTab=coral.TableDescription()
175 hltdataTab.insertColumn(
'DATA_ID',
'unsigned long long')
176 hltdataTab.insertColumn(
'ENTRY_ID',
'unsigned long long')
177 hltdataTab.insertColumn(
'ENTRY_NAME',
'string',56,
False)
178 hltdataTab.insertColumn(
'RUNNUM',
'unsigned int')
179 hltdataTab.insertColumn(
'SOURCE',
'string',128,
False)
180 hltdataTab.insertColumn(
'NPATH',
'unsigned int')
181 hltdataTab.insertColumn(
'PATHNAMECLOB',
'string',6000)
182 hltdataTab.setPrimaryKey(
'DATA_ID' )
183 db.createTable(hltdataTab,withIdTable=
True,withEntryTables=
True,withRevMapTable=
True)
187 print(
'creating lshlt table')
188 lshltTab=coral.TableDescription()
190 lshltTab.insertColumn(
'DATA_ID',
'unsigned long long')
191 lshltTab.insertColumn(
'RUNNUM',
'unsigned int')
192 lshltTab.insertColumn(
'CMSLSNUM',
'unsigned int')
193 lshltTab.insertColumn(
'PRESCALEBLOB',
'blob')
194 lshltTab.insertColumn(
'HLTCOUNTBLOB',
'blob')
195 lshltTab.insertColumn(
'HLTACCEPTBLOB',
'blob')
196 db.createTable(lshltTab,withIdTable=
False)
197 lshltTab.setPrimaryKey( (
'DATA_ID',
'CMSLSNUM') )
202 print(
'creating lumivalidation table')
203 lumivalidation=coral.TableDescription()
205 lumivalidation.insertColumn(
'RUNNUM',
'unsigned int' )
206 lumivalidation.insertColumn(
'CMSLSNUM',
'unsigned int' )
207 lumivalidation.insertColumn(
'FLAG',
'string',28,
False )
208 lumivalidation.insertColumn(
'COMMENT',
'string',1024,
False )
209 lumivalidation.setPrimaryKey( (
'RUNNUM',
'CMSLSNUM') )
210 lumivalidation.setNotNullConstraint(
'FLAG',
True)
211 db.createTable(lumivalidation,withIdTable=
False)
226 for tablename
in tablelist:
233 db.dropTable( tablename )
239 create tables of lumidb1 if not exist 245 lumivalidation=coral.TableDescription()
247 lumivalidation.insertColumn(
'RUNNUM',
'unsigned int' )
248 lumivalidation.insertColumn(
'CMSLSNUM',
'unsigned int' )
249 lumivalidation.insertColumn(
'FLAG',
'string',28,
False )
250 lumivalidation.insertColumn(
'COMMENT',
'string',1024,
False )
251 lumivalidation.setPrimaryKey((
'RUNNUM',
'CMSLSNUM'))
252 lumivalidation.setNotNullConstraint(
'FLAG',
True)
253 db.createTable(lumivalidation,withIdTable=
False)
257 cmsrunsummary=coral.TableDescription()
259 cmsrunsummary.insertColumn(
'RUNNUM',
'unsigned int')
260 cmsrunsummary.insertColumn(
'HLTKEY',
'string',128,
False)
261 cmsrunsummary.insertColumn(
'FILLNUM',
'unsigned int')
262 cmsrunsummary.insertColumn(
'SEQUENCE',
'string',56,
False)
263 cmsrunsummary.insertColumn(
'STARTTIME',
'time stamp',6)
264 cmsrunsummary.insertColumn(
'STOPTIME',
'time stamp',6)
265 cmsrunsummary.setPrimaryKey(
'RUNNUM')
266 cmsrunsummary.setNotNullConstraint(
'HLTKEY',
True)
267 cmsrunsummary.setNotNullConstraint(
'FILLNUM',
True)
268 cmsrunsummary.setNotNullConstraint(
'SEQUENCE',
True)
269 cmsrunsummary.createIndex(
'cmsrunsummary_fillnum',(
'FILLNUM'))
270 cmsrunsummary.createIndex(
'cmsrunsummary_startime',(
'STARTTIME'))
271 db.createTable(cmsrunsummary,withIdTable=
False)
275 summary=coral.TableDescription()
277 summary.insertColumn(
'LUMISUMMARY_ID',
'unsigned long long')
278 summary.insertColumn(
'RUNNUM',
'unsigned int')
279 summary.insertColumn(
'CMSLSNUM',
'unsigned int')
280 summary.insertColumn(
'LUMILSNUM',
'unsigned int')
281 summary.insertColumn(
'LUMIVERSION',
'string',28,
False)
282 summary.insertColumn(
'DTNORM',
'float')
283 summary.insertColumn(
'LHCNORM',
'float')
284 summary.insertColumn(
'CMSALIVE',
'short')
285 summary.insertColumn(
'INSTLUMI',
'float')
286 summary.insertColumn(
'INSTLUMIERROR',
'float')
287 summary.insertColumn(
'INSTLUMIQUALITY',
'short')
288 summary.insertColumn(
'BEAMSTATUS',
'string',28,
False)
289 summary.insertColumn(
'BEAMENERGY',
'float')
290 summary.insertColumn(
'NUMORBIT',
'unsigned int')
291 summary.insertColumn(
'STARTORBIT',
'unsigned int')
292 summary.insertColumn(
'LUMISECTIONQUALITY',
'short')
293 summary.insertColumn(
'CMSBXINDEXBLOB',
'blob')
294 summary.insertColumn(
'BEAMINTENSITYBLOB_1',
'blob')
295 summary.insertColumn(
'BEAMINTENSITYBLOB_2',
'blob')
296 summary.setPrimaryKey(
'LUMISUMMARY_ID')
297 summary.setNotNullConstraint(
'RUNNUM',
True)
298 summary.setNotNullConstraint(
'CMSLSNUM',
True)
299 summary.setNotNullConstraint(
'LUMILSNUM',
True)
300 summary.setNotNullConstraint(
'CMSALIVE',
True)
301 summary.setNotNullConstraint(
'LUMIVERSION',
True)
302 summary.setNotNullConstraint(
'DTNORM',
True)
303 summary.setNotNullConstraint(
'LHCNORM',
True)
304 summary.setNotNullConstraint(
'INSTLUMI',
True)
305 summary.setNotNullConstraint(
'INSTLUMIERROR',
True)
306 summary.setNotNullConstraint(
'INSTLUMIQUALITY',
True)
307 summary.setNotNullConstraint(
'STARTORBIT',
True)
308 summary.setNotNullConstraint(
'NUMORBIT',
True)
309 summary.setNotNullConstraint(
'LUMISECTIONQUALITY',
True)
310 summary.setNotNullConstraint(
'BEAMENERGY',
True)
311 summary.setNotNullConstraint(
'BEAMSTATUS',
True)
312 summary.setUniqueConstraint((
'RUNNUM',
'LUMIVERSION',
'LUMILSNUM'))
313 summary.createIndex(
'lumisummary_runnum',(
'RUNNUM'))
314 db.createTable(summary,withIdTable=
True)
318 detail=coral.TableDescription()
320 detail.insertColumn(
'LUMIDETAIL_ID',
'unsigned long long')
321 detail.insertColumn(
'LUMISUMMARY_ID',
'unsigned long long')
322 detail.insertColumn(
'BXLUMIVALUE',
'blob')
323 detail.insertColumn(
'BXLUMIERROR',
'blob')
324 detail.insertColumn(
'BXLUMIQUALITY',
'blob')
325 detail.insertColumn(
'ALGONAME',
'string',28,
False)
326 detail.setPrimaryKey(
'LUMIDETAIL_ID')
328 detail.setNotNullConstraint(
'BXLUMIVALUE',
True)
329 detail.setNotNullConstraint(
'BXLUMIERROR',
True)
330 detail.setNotNullConstraint(
'BXLUMIQUALITY',
True)
331 detail.setNotNullConstraint(
'ALGONAME',
True)
332 detail.setUniqueConstraint((
'LUMISUMMARY_ID',
'ALGONAME'))
333 db.createTable(detail,withIdTable=
True)
337 trg=coral.TableDescription()
339 trg.insertColumn(
'TRG_ID',
'unsigned long long')
340 trg.insertColumn(
'RUNNUM',
'unsigned int')
341 trg.insertColumn(
'CMSLSNUM',
'unsigned int')
342 trg.insertColumn(
'BITNUM',
'unsigned int')
343 trg.insertColumn(
'BITNAME',
'string',56,
False)
344 trg.insertColumn(
'TRGCOUNT',
'unsigned int')
345 trg.insertColumn(
'DEADTIME',
'unsigned long long')
346 trg.insertColumn(
'PRESCALE',
'unsigned int')
347 trg.setNotNullConstraint(
'RUNNUM',
True)
348 trg.setNotNullConstraint(
'CMSLSNUM',
True)
349 trg.setNotNullConstraint(
'BITNUM',
True)
350 trg.setNotNullConstraint(
'BITNAME',
True)
351 trg.setNotNullConstraint(
'TRGCOUNT',
True)
352 trg.setNotNullConstraint(
'DEADTIME',
True)
353 trg.setNotNullConstraint(
'PRESCALE',
True)
354 trg.setPrimaryKey(
'TRG_ID')
355 trg.createIndex(
'trg_runnum',(
'RUNNUM'))
356 db.createTable(trg,withIdTable=
True)
360 hlt=coral.TableDescription()
362 hlt.insertColumn(
'HLT_ID',
'unsigned long long')
363 hlt.insertColumn(
'RUNNUM',
'unsigned int')
364 hlt.insertColumn(
'CMSLSNUM',
'unsigned int')
365 hlt.insertColumn(
'PATHNAME',
'string',256,
False)
366 hlt.insertColumn(
'INPUTCOUNT',
'unsigned int')
367 hlt.insertColumn(
'ACCEPTCOUNT',
'unsigned int')
368 hlt.insertColumn(
'PRESCALE',
'unsigned int')
369 hlt.setPrimaryKey(
'HLT_ID' )
370 hlt.setNotNullConstraint(
'RUNNUM',
True)
371 hlt.setNotNullConstraint(
'CMSLSNUM',
True)
372 hlt.setNotNullConstraint(
'PATHNAME',
True)
373 hlt.setNotNullConstraint(
'INPUTCOUNT',
True)
374 hlt.setNotNullConstraint(
'ACCEPTCOUNT',
True)
375 hlt.setNotNullConstraint(
'PRESCALE',
True)
376 hlt.createIndex(
'hlt_runnum',(
'RUNNUM'))
377 db.createTable(hlt,withIdTable=
True)
381 trghlt=coral.TableDescription()
383 trghlt.insertColumn(
'HLTKEY',
'string',128,
False )
384 trghlt.insertColumn(
'HLTPATHNAME',
'string',256,
False )
385 trghlt.insertColumn(
'L1SEED',
'string',1024,false )
386 trghlt.setNotNullConstraint(
'HLTKEY',
True)
387 trghlt.setNotNullConstraint(
'HLTPATHNAME',
True)
388 trghlt.setNotNullConstraint(
'L1SEED',
True)
389 db.createTable(trghlt,withIdTable=
False)
402 modify old tables:cmsrunsummary 403 alter table cmsrunsummary add column(l1key string,egev unsigned int,amodetag string) 407 tableHandle.schemaEditor().insertColumn(
'L1KEY',
'string',128,
False)
408 tableHandle.schemaEditor().insertColumn(
'EGEV',
'unsigned int')
409 tableHandle.schemaEditor().insertColumn(
'AMODETAG',
'string',28,
False)
416 dropTables(schema,[
'REVISIONS',
'LUMINORMS',
'LUMIDATA',
'LUMISUMMARYV2',
'TRGDATA',
'LSTRG',
'HLTDATA',
'LSHLT'])
418 ncol=tableHandle.description().numberOfColumns()
420 for i
in range(ncol):
421 colname=tableHandle.description().columnDescription(i).
name()
422 if colname
in [
'L1KEY',
'EGEV',
'AMODETAG']:
423 todrop.append(colname)
424 for colname
in todrop:
425 tableHandle.schemaEditor().dropColumn(colname)
475 revtable.schemaEditor().setUniqueConstraint(
'NAME',
'revisions_name_uc')
488 if __name__ ==
"__main__":
489 import sessionManager
490 myconstr=
'oracle://devdb10/cms_xiezhen_dev' 491 authpath=
'/afs/cern.ch/user/x/xiezhen' 494 session=svc.openSession(isReadOnly=
False,cpp2sqltype=[(
'unsigned int',
'NUMBER(10)'),(
'unsigned long long',
'NUMBER(20)')])
495 schema=session.nominalSchema()
496 session.transaction().
start(
False)
508 session.transaction().
start(
False)
511 print(
'created old ',tables)
512 session.transaction().commit()
def dropTables(schema, tablelist)
def lumisummaryv2TableName()
def createOldSchema(schema)
def lumidetailTableName()
S & print(S &os, JobReport::InputFile const &f)
def lumisummaryTableName()
def describeIndices(schema)
def createNULLConstraints(schema)
def entryTableName(dataTableName)
def lumivalidationTableName()
def createIndices(schema)
def createFKConstraints(schema)
def createUniqueConstraints(schema)
def revmapTableName(dataTableName)
def dropNULLConstraints(schema)
def fillschemeTableName()
def cmsrunsummaryTableName()
def idTableName(dataTableName)
def dropUNIQUEConstraints(schema)
def dropFKConstrains(schema)