1 from __future__
import print_function
2 from __future__
import absolute_import
3 from builtins
import range
5 from RecoLuminosity.LumiDB
import nameDealer,dbUtil
13 create new tables if not exist 14 revisions,revisions_id,luminorms,luminorms_entries,luminorms_entries_id,fillscheme 20 print(
'creating fillscheme table')
21 fillschemeTab=coral.TableDescription()
23 fillschemeTab.insertColumn(
'FILLSCHEME_ID',
'unsigned long long' )
24 fillschemeTab.insertColumn(
'FILLSCHEMEPATTERN',
'string',128,
False )
25 fillschemeTab.insertColumn(
'CORRECTIONFACTOR',
'float' )
26 fillschemeTab.setPrimaryKey(
'FILLSCHEME_ID' )
27 db.createTable(fillschemeTab,withIdTable=
True)
31 print(
'creating revisions table')
32 revisionsTab=coral.TableDescription()
34 revisionsTab.insertColumn(
'REVISION_ID',
'unsigned long long')
35 revisionsTab.insertColumn(
'BRANCH_ID',
'unsigned long long')
36 revisionsTab.insertColumn(
'NAME',
'string',56,
False)
37 revisionsTab.insertColumn(
'BRANCH_NAME',
'string',56,
False)
38 revisionsTab.insertColumn(
'COMMENT',
'string',1024,
False)
39 revisionsTab.insertColumn(
'CTIME',
'time stamp',6)
40 revisionsTab.setPrimaryKey(
'REVISION_ID' )
41 revisionsTab.setUniqueConstraint((
'NAME'))
42 db.createTable(revisionsTab,withIdTable=
True)
46 print(
'creating luminorms table')
47 luminormsTab=coral.TableDescription()
49 luminormsTab.insertColumn(
'DATA_ID',
'unsigned long long')
50 luminormsTab.insertColumn(
'ENTRY_ID',
'unsigned long long')
51 luminormsTab.insertColumn(
'ENTRY_NAME',
'string',56,
False)
52 luminormsTab.insertColumn(
'AMODETAG',
'string',28,
False)
53 luminormsTab.insertColumn(
'NORM_1',
'float')
54 luminormsTab.insertColumn(
'EGEV_1',
'unsigned int')
55 luminormsTab.insertColumn(
'NORM_2',
'float')
56 luminormsTab.insertColumn(
'EGEV_2',
'unsigned int')
57 luminormsTab.setPrimaryKey(
'DATA_ID' )
58 db.createTable(luminormsTab,withIdTable=
True,withEntryTables=
True,withRevMapTable=
True)
62 print(
'creating lumidata table')
63 lumidataTab=coral.TableDescription()
65 lumidataTab.insertColumn(
'DATA_ID',
'unsigned long long')
66 lumidataTab.insertColumn(
'ENTRY_ID',
'unsigned long long')
67 lumidataTab.insertColumn(
'ENTRY_NAME',
'string',56,
False)
68 lumidataTab.insertColumn(
'SOURCE',
'string',128,
False)
69 lumidataTab.insertColumn(
'RUNNUM',
'unsigned int')
70 lumidataTab.insertColumn(
'NOMINALEGEV',
'float')
71 lumidataTab.setPrimaryKey(
'DATA_ID' )
72 db.createTable(lumidataTab,withIdTable=
True,withEntryTables=
True,withRevMapTable=
True)
76 print(
'creating lumisummaryv2 table')
77 summary=coral.TableDescription()
79 summary.insertColumn(
'DATA_ID',
'unsigned long long')
80 summary.insertColumn(
'RUNNUM',
'unsigned int')
81 summary.insertColumn(
'LUMILSNUM',
'unsigned int')
82 summary.insertColumn(
'CMSLSNUM',
'unsigned int')
83 summary.insertColumn(
'INSTLUMI',
'float')
84 summary.insertColumn(
'INSTLUMIERROR',
'float')
85 summary.insertColumn(
'INSTLUMIQUALITY',
'short')
86 summary.insertColumn(
'BEAMSTATUS',
'string',28,
False)
87 summary.insertColumn(
'BEAMENERGY',
'float')
88 summary.insertColumn(
'NUMORBIT',
'unsigned int')
89 summary.insertColumn(
'STARTORBIT',
'unsigned int')
90 summary.insertColumn(
'CMSBXINDEXBLOB',
'blob')
91 summary.insertColumn(
'BEAMINTENSITYBLOB_1',
'blob')
92 summary.insertColumn(
'BEAMINTENSITYBLOB_2',
'blob')
93 summary.insertColumn(
'BXLUMIVALUE_OCC1',
'blob')
94 summary.insertColumn(
'BXLUMIVALUE_OCC2',
'blob')
95 summary.insertColumn(
'BXLUMIVALUE_ET',
'blob')
96 summary.insertColumn(
'BXLUMIERROR_OCC1',
'blob')
97 summary.insertColumn(
'BXLUMIERROR_OCC2',
'blob')
98 summary.insertColumn(
'BXLUMIERROR_ET',
'blob')
99 summary.insertColumn(
'BXLUMIQUALITY_OCC1',
'blob')
100 summary.insertColumn(
'BXLUMIQUALITY_OCC2',
'blob')
101 summary.insertColumn(
'BXLUMIQUALITY_ET',
'blob')
102 summary.setPrimaryKey((
'DATA_ID',
'LUMILSNUM'))
103 db.createTable(summary,withIdTable=
False)
110 print(
'creating cmsrunsummary table')
111 cmsrunsummary=coral.TableDescription()
113 cmsrunsummary.insertColumn(
'RUNNUM',
'unsigned int')
114 cmsrunsummary.insertColumn(
'HLTKEY',
'string',128,
False)
115 cmsrunsummary.insertColumn(
'L1KEY',
'string',128,
False)
116 cmsrunsummary.insertColumn(
'FILLNUM',
'unsigned int')
117 cmsrunsummary.insertColumn(
'SEQUENCE',
'string',56,
False)
118 cmsrunsummary.insertColumn(
'STARTTIME',
'time stamp',6)
119 cmsrunsummary.insertColumn(
'STOPTIME',
'time stamp',6)
120 cmsrunsummary.insertColumn(
'EGEV',
'unsigned int')
121 cmsrunsummary.insertColumn(
'AMODETAG',
'string',28,
False)
122 cmsrunsummary.insertColumn(
'FILLSCHEME',
'string',128,
False)
123 cmsrunsummary.insertColumn(
'NCOLLIDINGBUNCHES',
'usigned int')
124 cmsrunsummary.setPrimaryKey(
'RUNNUM')
125 db.createTable(cmsrunsummary,withIdTable=
False)
131 print(
'creating trghltmap table')
132 trghlt=coral.TableDescription()
134 trghlt.insertColumn(
'HLTKEY',
'string',128,
False )
135 trghlt.insertColumn(
'HLTPATHNAME',
'string',256,
False )
136 trghlt.insertColumn(
'L1SEED',
'string' ,1024,
False)
137 trghlt.setNotNullConstraint(
'HLTKEY',
True)
138 trghlt.setNotNullConstraint(
'HLTPATHNAME',
True)
139 trghlt.setNotNullConstraint(
'L1SEED',
True)
140 db.createTable(trghlt,withIdTable=
False)
143 print(
'creating trgdata table')
144 trgdataTab=coral.TableDescription()
146 trgdataTab.insertColumn(
'DATA_ID',
'unsigned long long')
147 trgdataTab.insertColumn(
'ENTRY_ID',
'unsigned long long')
148 trgdataTab.insertColumn(
'ENTRY_NAME',
'string',56,
False)
149 trgdataTab.insertColumn(
'SOURCE',
'string',128,
False)
150 trgdataTab.insertColumn(
'RUNNUM',
'unsigned int')
151 trgdataTab.insertColumn(
'BITZERONAME',
'string',56,
False)
152 trgdataTab.insertColumn(
'BITNAMECLOB',
'string',6000)
153 trgdataTab.setPrimaryKey(
'DATA_ID' )
154 db.createTable(trgdataTab,withIdTable=
True,withEntryTables=
True,withRevMapTable=
True)
157 print(
'creating lstrg table')
158 lstrgTab=coral.TableDescription()
160 lstrgTab.insertColumn(
'DATA_ID',
'unsigned long long')
161 lstrgTab.insertColumn(
'RUNNUM',
'unsigned int')
162 lstrgTab.insertColumn(
'CMSLSNUM',
'unsigned int')
163 lstrgTab.insertColumn(
'DEADTIMECOUNT',
'unsigned long long')
164 lstrgTab.insertColumn(
'BITZEROCOUNT',
'unsigned int')
165 lstrgTab.insertColumn(
'BITZEROPRESCALE',
'unsigned int')
166 lstrgTab.insertColumn(
'DEADFRAC',
'float')
167 lstrgTab.insertColumn(
'PRESCALEBLOB',
'blob')
168 lstrgTab.insertColumn(
'TRGCOUNTBLOB',
'blob')
169 lstrgTab.setPrimaryKey( (
'DATA_ID',
'CMSLSNUM') )
170 db.createTable(lstrgTab,withIdTable=
False)
174 print(
'creating hltdata table')
175 hltdataTab=coral.TableDescription()
177 hltdataTab.insertColumn(
'DATA_ID',
'unsigned long long')
178 hltdataTab.insertColumn(
'ENTRY_ID',
'unsigned long long')
179 hltdataTab.insertColumn(
'ENTRY_NAME',
'string',56,
False)
180 hltdataTab.insertColumn(
'RUNNUM',
'unsigned int')
181 hltdataTab.insertColumn(
'SOURCE',
'string',128,
False)
182 hltdataTab.insertColumn(
'NPATH',
'unsigned int')
183 hltdataTab.insertColumn(
'PATHNAMECLOB',
'string',6000)
184 hltdataTab.setPrimaryKey(
'DATA_ID' )
185 db.createTable(hltdataTab,withIdTable=
True,withEntryTables=
True,withRevMapTable=
True)
189 print(
'creating lshlt table')
190 lshltTab=coral.TableDescription()
192 lshltTab.insertColumn(
'DATA_ID',
'unsigned long long')
193 lshltTab.insertColumn(
'RUNNUM',
'unsigned int')
194 lshltTab.insertColumn(
'CMSLSNUM',
'unsigned int')
195 lshltTab.insertColumn(
'PRESCALEBLOB',
'blob')
196 lshltTab.insertColumn(
'HLTCOUNTBLOB',
'blob')
197 lshltTab.insertColumn(
'HLTACCEPTBLOB',
'blob')
198 db.createTable(lshltTab,withIdTable=
False)
199 lshltTab.setPrimaryKey( (
'DATA_ID',
'CMSLSNUM') )
204 print(
'creating lumivalidation table')
205 lumivalidation=coral.TableDescription()
207 lumivalidation.insertColumn(
'RUNNUM',
'unsigned int' )
208 lumivalidation.insertColumn(
'CMSLSNUM',
'unsigned int' )
209 lumivalidation.insertColumn(
'FLAG',
'string',28,
False )
210 lumivalidation.insertColumn(
'COMMENT',
'string',1024,
False )
211 lumivalidation.setPrimaryKey( (
'RUNNUM',
'CMSLSNUM') )
212 lumivalidation.setNotNullConstraint(
'FLAG',
True)
213 db.createTable(lumivalidation,withIdTable=
False)
228 for tablename
in tablelist:
235 db.dropTable( tablename )
241 create tables of lumidb1 if not exist 247 lumivalidation=coral.TableDescription()
249 lumivalidation.insertColumn(
'RUNNUM',
'unsigned int' )
250 lumivalidation.insertColumn(
'CMSLSNUM',
'unsigned int' )
251 lumivalidation.insertColumn(
'FLAG',
'string',28,
False )
252 lumivalidation.insertColumn(
'COMMENT',
'string',1024,
False )
253 lumivalidation.setPrimaryKey((
'RUNNUM',
'CMSLSNUM'))
254 lumivalidation.setNotNullConstraint(
'FLAG',
True)
255 db.createTable(lumivalidation,withIdTable=
False)
259 cmsrunsummary=coral.TableDescription()
261 cmsrunsummary.insertColumn(
'RUNNUM',
'unsigned int')
262 cmsrunsummary.insertColumn(
'HLTKEY',
'string',128,
False)
263 cmsrunsummary.insertColumn(
'FILLNUM',
'unsigned int')
264 cmsrunsummary.insertColumn(
'SEQUENCE',
'string',56,
False)
265 cmsrunsummary.insertColumn(
'STARTTIME',
'time stamp',6)
266 cmsrunsummary.insertColumn(
'STOPTIME',
'time stamp',6)
267 cmsrunsummary.setPrimaryKey(
'RUNNUM')
268 cmsrunsummary.setNotNullConstraint(
'HLTKEY',
True)
269 cmsrunsummary.setNotNullConstraint(
'FILLNUM',
True)
270 cmsrunsummary.setNotNullConstraint(
'SEQUENCE',
True)
271 cmsrunsummary.createIndex(
'cmsrunsummary_fillnum',(
'FILLNUM'))
272 cmsrunsummary.createIndex(
'cmsrunsummary_startime',(
'STARTTIME'))
273 db.createTable(cmsrunsummary,withIdTable=
False)
277 summary=coral.TableDescription()
279 summary.insertColumn(
'LUMISUMMARY_ID',
'unsigned long long')
280 summary.insertColumn(
'RUNNUM',
'unsigned int')
281 summary.insertColumn(
'CMSLSNUM',
'unsigned int')
282 summary.insertColumn(
'LUMILSNUM',
'unsigned int')
283 summary.insertColumn(
'LUMIVERSION',
'string',28,
False)
284 summary.insertColumn(
'DTNORM',
'float')
285 summary.insertColumn(
'LHCNORM',
'float')
286 summary.insertColumn(
'CMSALIVE',
'short')
287 summary.insertColumn(
'INSTLUMI',
'float')
288 summary.insertColumn(
'INSTLUMIERROR',
'float')
289 summary.insertColumn(
'INSTLUMIQUALITY',
'short')
290 summary.insertColumn(
'BEAMSTATUS',
'string',28,
False)
291 summary.insertColumn(
'BEAMENERGY',
'float')
292 summary.insertColumn(
'NUMORBIT',
'unsigned int')
293 summary.insertColumn(
'STARTORBIT',
'unsigned int')
294 summary.insertColumn(
'LUMISECTIONQUALITY',
'short')
295 summary.insertColumn(
'CMSBXINDEXBLOB',
'blob')
296 summary.insertColumn(
'BEAMINTENSITYBLOB_1',
'blob')
297 summary.insertColumn(
'BEAMINTENSITYBLOB_2',
'blob')
298 summary.setPrimaryKey(
'LUMISUMMARY_ID')
299 summary.setNotNullConstraint(
'RUNNUM',
True)
300 summary.setNotNullConstraint(
'CMSLSNUM',
True)
301 summary.setNotNullConstraint(
'LUMILSNUM',
True)
302 summary.setNotNullConstraint(
'CMSALIVE',
True)
303 summary.setNotNullConstraint(
'LUMIVERSION',
True)
304 summary.setNotNullConstraint(
'DTNORM',
True)
305 summary.setNotNullConstraint(
'LHCNORM',
True)
306 summary.setNotNullConstraint(
'INSTLUMI',
True)
307 summary.setNotNullConstraint(
'INSTLUMIERROR',
True)
308 summary.setNotNullConstraint(
'INSTLUMIQUALITY',
True)
309 summary.setNotNullConstraint(
'STARTORBIT',
True)
310 summary.setNotNullConstraint(
'NUMORBIT',
True)
311 summary.setNotNullConstraint(
'LUMISECTIONQUALITY',
True)
312 summary.setNotNullConstraint(
'BEAMENERGY',
True)
313 summary.setNotNullConstraint(
'BEAMSTATUS',
True)
314 summary.setUniqueConstraint((
'RUNNUM',
'LUMIVERSION',
'LUMILSNUM'))
315 summary.createIndex(
'lumisummary_runnum',(
'RUNNUM'))
316 db.createTable(summary,withIdTable=
True)
320 detail=coral.TableDescription()
322 detail.insertColumn(
'LUMIDETAIL_ID',
'unsigned long long')
323 detail.insertColumn(
'LUMISUMMARY_ID',
'unsigned long long')
324 detail.insertColumn(
'BXLUMIVALUE',
'blob')
325 detail.insertColumn(
'BXLUMIERROR',
'blob')
326 detail.insertColumn(
'BXLUMIQUALITY',
'blob')
327 detail.insertColumn(
'ALGONAME',
'string',28,
False)
328 detail.setPrimaryKey(
'LUMIDETAIL_ID')
330 detail.setNotNullConstraint(
'BXLUMIVALUE',
True)
331 detail.setNotNullConstraint(
'BXLUMIERROR',
True)
332 detail.setNotNullConstraint(
'BXLUMIQUALITY',
True)
333 detail.setNotNullConstraint(
'ALGONAME',
True)
334 detail.setUniqueConstraint((
'LUMISUMMARY_ID',
'ALGONAME'))
335 db.createTable(detail,withIdTable=
True)
339 trg=coral.TableDescription()
341 trg.insertColumn(
'TRG_ID',
'unsigned long long')
342 trg.insertColumn(
'RUNNUM',
'unsigned int')
343 trg.insertColumn(
'CMSLSNUM',
'unsigned int')
344 trg.insertColumn(
'BITNUM',
'unsigned int')
345 trg.insertColumn(
'BITNAME',
'string',56,
False)
346 trg.insertColumn(
'TRGCOUNT',
'unsigned int')
347 trg.insertColumn(
'DEADTIME',
'unsigned long long')
348 trg.insertColumn(
'PRESCALE',
'unsigned int')
349 trg.setNotNullConstraint(
'RUNNUM',
True)
350 trg.setNotNullConstraint(
'CMSLSNUM',
True)
351 trg.setNotNullConstraint(
'BITNUM',
True)
352 trg.setNotNullConstraint(
'BITNAME',
True)
353 trg.setNotNullConstraint(
'TRGCOUNT',
True)
354 trg.setNotNullConstraint(
'DEADTIME',
True)
355 trg.setNotNullConstraint(
'PRESCALE',
True)
356 trg.setPrimaryKey(
'TRG_ID')
357 trg.createIndex(
'trg_runnum',(
'RUNNUM'))
358 db.createTable(trg,withIdTable=
True)
362 hlt=coral.TableDescription()
364 hlt.insertColumn(
'HLT_ID',
'unsigned long long')
365 hlt.insertColumn(
'RUNNUM',
'unsigned int')
366 hlt.insertColumn(
'CMSLSNUM',
'unsigned int')
367 hlt.insertColumn(
'PATHNAME',
'string',256,
False)
368 hlt.insertColumn(
'INPUTCOUNT',
'unsigned int')
369 hlt.insertColumn(
'ACCEPTCOUNT',
'unsigned int')
370 hlt.insertColumn(
'PRESCALE',
'unsigned int')
371 hlt.setPrimaryKey(
'HLT_ID' )
372 hlt.setNotNullConstraint(
'RUNNUM',
True)
373 hlt.setNotNullConstraint(
'CMSLSNUM',
True)
374 hlt.setNotNullConstraint(
'PATHNAME',
True)
375 hlt.setNotNullConstraint(
'INPUTCOUNT',
True)
376 hlt.setNotNullConstraint(
'ACCEPTCOUNT',
True)
377 hlt.setNotNullConstraint(
'PRESCALE',
True)
378 hlt.createIndex(
'hlt_runnum',(
'RUNNUM'))
379 db.createTable(hlt,withIdTable=
True)
383 trghlt=coral.TableDescription()
385 trghlt.insertColumn(
'HLTKEY',
'string',128,
False )
386 trghlt.insertColumn(
'HLTPATHNAME',
'string',256,
False )
387 trghlt.insertColumn(
'L1SEED',
'string',1024,false )
388 trghlt.setNotNullConstraint(
'HLTKEY',
True)
389 trghlt.setNotNullConstraint(
'HLTPATHNAME',
True)
390 trghlt.setNotNullConstraint(
'L1SEED',
True)
391 db.createTable(trghlt,withIdTable=
False)
404 modify old tables:cmsrunsummary 405 alter table cmsrunsummary add column(l1key string,egev unsigned int,amodetag string) 409 tableHandle.schemaEditor().insertColumn(
'L1KEY',
'string',128,
False)
410 tableHandle.schemaEditor().insertColumn(
'EGEV',
'unsigned int')
411 tableHandle.schemaEditor().insertColumn(
'AMODETAG',
'string',28,
False)
418 dropTables(schema,[
'REVISIONS',
'LUMINORMS',
'LUMIDATA',
'LUMISUMMARYV2',
'TRGDATA',
'LSTRG',
'HLTDATA',
'LSHLT'])
420 ncol=tableHandle.description().numberOfColumns()
422 for i
in range(ncol):
423 colname=tableHandle.description().columnDescription(i).
name()
424 if colname
in [
'L1KEY',
'EGEV',
'AMODETAG']:
425 todrop.append(colname)
426 for colname
in todrop:
427 tableHandle.schemaEditor().dropColumn(colname)
477 revtable.schemaEditor().setUniqueConstraint(
'NAME',
'revisions_name_uc')
490 if __name__ ==
"__main__":
491 from .
import sessionManager
492 myconstr=
'oracle://devdb10/cms_xiezhen_dev' 493 authpath=
'/afs/cern.ch/user/x/xiezhen' 496 session=svc.openSession(isReadOnly=
False,cpp2sqltype=[(
'unsigned int',
'NUMBER(10)'),(
'unsigned long long',
'NUMBER(20)')])
497 schema=session.nominalSchema()
498 session.transaction().
start(
False)
510 session.transaction().
start(
False)
513 print(
'created old ',tables)
514 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)