CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
lumiSchema.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 VERSION='2.00'
3 import os,sys
4 import coral
5 from RecoLuminosity.LumiDB import argparse,dbUtil,nameDealer
6 
7 def createLumi(dbsession):
8  print 'creating lumi db schema...'
9  dbsession.transaction().start(False)
10  schema=dbsession.nominalSchema()
11  db=dbUtil.dbUtil(schema)
12  #cms run summary table
13 
14  cmsrunsummary=coral.TableDescription()
15  cmsrunsummary.setName( nameDealer.cmsrunsummaryTableName() )
16  cmsrunsummary.insertColumn('RUNNUM','unsigned int')
17  cmsrunsummary.insertColumn('HLTKEY','string')
18  cmsrunsummary.insertColumn('FILLNUM','unsigned int')
19  cmsrunsummary.insertColumn('SEQUENCE','string')
20  cmsrunsummary.insertColumn('STARTTIME','time stamp',6)
21  cmsrunsummary.insertColumn('STOPTIME','time stamp',6)
22  cmsrunsummary.setPrimaryKey('RUNNUM')
23  cmsrunsummary.setNotNullConstraint('HLTKEY',True)
24  cmsrunsummary.setNotNullConstraint('FILLNUM',True)
25  cmsrunsummary.setNotNullConstraint('SEQUENCE',True)
26  cmsrunsummary.createIndex('cmsrunsummary_fillnum',('FILLNUM'))
27  cmsrunsummary.createIndex('cmsrunsummary_startime',('STARTTIME'))
28  db.createTable(cmsrunsummary,False)
29 
30  #lumi summary table
31  summary=coral.TableDescription()
32  summary.setName( nameDealer.lumisummaryTableName() )
33  summary.insertColumn('LUMISUMMARY_ID','unsigned long long')
34  summary.insertColumn('RUNNUM','unsigned int')
35  summary.insertColumn('CMSLSNUM','unsigned int')
36  summary.insertColumn('LUMILSNUM','unsigned int')
37  summary.insertColumn('LUMIVERSION','string')
38  summary.insertColumn('DTNORM','float')
39  summary.insertColumn('LHCNORM','float')
40  summary.insertColumn('INSTLUMI','float')
41  summary.insertColumn('INSTLUMIERROR','float')
42  summary.insertColumn('INSTLUMIQUALITY','short')
43  summary.insertColumn('CMSALIVE','short')
44  summary.insertColumn('STARTORBIT','unsigned int')
45  summary.insertColumn('NUMORBIT','unsigned int')
46  summary.insertColumn('LUMISECTIONQUALITY','short')
47  summary.insertColumn('BEAMENERGY','float')
48  summary.insertColumn('BEAMSTATUS','string')
49  summary.insertColumn('CMSBXINDEXBLOB','blob')
50  summary.insertColumn('BEAMINTENSITYBLOB_1','blob')
51  summary.insertColumn('BEAMINTENSITYBLOB_2','blob')
52 
53  summary.setPrimaryKey('LUMISUMMARY_ID')
54  summary.setNotNullConstraint('RUNNUM',True)
55  summary.setNotNullConstraint('CMSLSNUM',True)
56  summary.setNotNullConstraint('LUMILSNUM',True)
57  summary.setNotNullConstraint('LUMIVERSION',True)
58  summary.setNotNullConstraint('DTNORM',True)
59  summary.setNotNullConstraint('LHCNORM',True)
60  summary.setNotNullConstraint('INSTLUMI',True)
61  summary.setNotNullConstraint('INSTLUMIERROR',True)
62  summary.setNotNullConstraint('INSTLUMIQUALITY',True)
63  summary.setNotNullConstraint('CMSALIVE',True)
64  summary.setNotNullConstraint('STARTORBIT',True)
65  summary.setNotNullConstraint('NUMORBIT',True)
66  summary.setNotNullConstraint('LUMISECTIONQUALITY',True)
67  summary.setNotNullConstraint('BEAMENERGY',True)
68  summary.setNotNullConstraint('BEAMSTATUS',True)
69 
70  summary.setUniqueConstraint(('RUNNUM','LUMIVERSION','LUMILSNUM'))
71  summary.createIndex('lumisummary_runnum',('RUNNUM'))
72 
73  db.createTable(summary,True)
74  #lumi detail table
75  detail=coral.TableDescription()
76  detail.setName( nameDealer.lumidetailTableName() )
77  detail.insertColumn('LUMIDETAIL_ID','unsigned long long')
78  detail.insertColumn('LUMISUMMARY_ID','unsigned long long')
79  detail.insertColumn('BXLUMIVALUE','blob')
80  detail.insertColumn('BXLUMIERROR','blob')
81  detail.insertColumn('BXLUMIQUALITY','blob')
82  detail.insertColumn('ALGONAME','string')
83  detail.setPrimaryKey('LUMIDETAIL_ID')
84  detail.createForeignKey('DETAILSOURCE','LUMISUMMARY_ID',nameDealer.lumisummaryTableName(),'LUMISUMMARY_ID')
85  detail.setNotNullConstraint('BXLUMIVALUE',True)
86  detail.setNotNullConstraint('BXLUMIERROR',True)
87  detail.setNotNullConstraint('BXLUMIQUALITY',True)
88  detail.setNotNullConstraint('ALGONAME',True)
89 
90  detail.setUniqueConstraint(('LUMISUMMARY_ID','ALGONAME'))
91 
92  db.createTable(detail,True)
93  #trg table
94  trg=coral.TableDescription()
95  trg.setName( nameDealer.trgTableName() )
96  trg.insertColumn('TRG_ID','unsigned long long')
97  trg.insertColumn('RUNNUM','unsigned int')
98  trg.insertColumn('CMSLSNUM','unsigned int')
99  trg.insertColumn('BITNUM','unsigned int')
100  trg.insertColumn('BITNAME','string')
101  trg.insertColumn('TRGCOUNT','unsigned int')
102  trg.insertColumn('DEADTIME','unsigned long long')
103  trg.insertColumn('PRESCALE','unsigned int')
104 
105  trg.setNotNullConstraint('RUNNUM',True)
106  trg.setNotNullConstraint('CMSLSNUM',True)
107  trg.setNotNullConstraint('BITNUM',True)
108  trg.setNotNullConstraint('BITNAME',True)
109  trg.setNotNullConstraint('TRGCOUNT',True)
110  trg.setNotNullConstraint('DEADTIME',True)
111  trg.setNotNullConstraint('PRESCALE',True)
112  trg.setPrimaryKey('TRG_ID')
113  trg.createIndex('trg_runnum',('RUNNUM'))
114 
115  db.createTable(trg,True)
116  #hlt table
117  hlt=coral.TableDescription()
118  hlt.setName( nameDealer.hltTableName() )
119  hlt.insertColumn( 'HLT_ID','unsigned long long')
120  hlt.insertColumn( 'RUNNUM','unsigned int')
121  hlt.insertColumn( 'CMSLSNUM','unsigned int')
122  hlt.insertColumn( 'PATHNAME','string')
123  hlt.insertColumn( 'INPUTCOUNT','unsigned int')
124  hlt.insertColumn( 'ACCEPTCOUNT','unsigned int')
125  hlt.insertColumn( 'PRESCALE','unsigned int')
126  hlt.setPrimaryKey( 'HLT_ID' )
127  hlt.setNotNullConstraint('RUNNUM',True)
128  hlt.setNotNullConstraint('CMSLSNUM',True)
129  hlt.setNotNullConstraint('PATHNAME',True)
130  hlt.setNotNullConstraint('INPUTCOUNT',True)
131  hlt.setNotNullConstraint('ACCEPTCOUNT',True)
132  hlt.setNotNullConstraint('PRESCALE',True)
133  hlt.createIndex('hlt_runnum',('RUNNUM'))
134  db.createTable(hlt,True)
135  #trghlt map table
136  trghlt=coral.TableDescription()
137  trghlt.setName( nameDealer.trghltMapTableName() )
138  #trghlt.insertColumn( 'RUNNUM','unsigned int' )
139  trghlt.insertColumn( 'HLTKEY','string' )
140  trghlt.insertColumn( 'HLTPATHNAME','string' )
141  trghlt.insertColumn( 'L1SEED','string' )
142  trghlt.setNotNullConstraint('HLTKEY',True)
143  trghlt.setNotNullConstraint('HLTPATHNAME',True)
144  trghlt.setNotNullConstraint('L1SEED',True)
145  db.createTable(trghlt,False)
146  #lumiresult table
147  lumiresult=coral.TableDescription()
148  lumiresult.setName( nameDealer.lumiresultTableName() )
149  lumiresult.insertColumn( 'RUNNUM','unsigned int' )
150  lumiresult.insertColumn( 'LUMIVERSION','string' )
151  lumiresult.insertColumn( 'DELIVEREDLUMI','float' )
152  lumiresult.insertColumn( 'RECORDEDLUMI','float' )
153  db.createTable(lumiresult,False)
154  #lumihltresult table
155  lumihltresult=coral.TableDescription()
156  lumihltresult.setName( nameDealer.lumihltresultTableName() )
157  lumihltresult.insertColumn( 'RUNNUM','unsigned int' )
158  lumihltresult.insertColumn( 'LUMIVERSION','string' )
159  lumihltresult.insertColumn( 'HLTPATH','float' )
160  lumihltresult.insertColumn( 'RECORDEDLUMI','float' )
161  db.createTable(lumihltresult,False)
162 
163  #lumivalidation table
164  lumivalidation=coral.TableDescription()
165  lumivalidation.setName( nameDealer.lumivalidationTableName() )
166  lumivalidation.insertColumn( 'RUNNUM','unsigned int' )
167  lumivalidation.insertColumn( 'CMSLSNUM','unsigned int' )
168  lumivalidation.insertColumn( 'FLAG','string' )
169  lumivalidation.insertColumn( 'COMMENT','string' )
170  lumivalidation.setPrimaryKey(('RUNNUM','CMSLSNUM'))
171  lumivalidation.setNotNullConstraint('FLAG',True)
172 
173  db.createTable(lumivalidation,False)
174  dbsession.transaction().commit()
175 
176 def createValidation(dbsession):
177  '''
178  lumivalidation table
179  '''
180  dbsession.transaction().start(False)
181  schema=dbsession.nominalSchema()
182  db=dbUtil.dbUtil(schema)
183  lumivalidation=coral.TableDescription()
184  lumivalidation.setName( nameDealer.lumivalidationTableName() )
185  lumivalidation.insertColumn( 'RUNNUM','unsigned int' )
186  lumivalidation.insertColumn( 'CMSLSNUM','unsigned int' )
187  lumivalidation.insertColumn( 'FLAG','string' )
188  lumivalidation.insertColumn( 'COMMENT','string' )
189  lumivalidation.setPrimaryKey(('RUNNUM','CMSLSNUM'))
190  lumivalidation.setNotNullConstraint('FLAG',True)
191  db.createTable(lumivalidation,False)
192  dbsession.transaction().commit()
193 
194 def dropLumi(dbsession):
195  print 'droping lumi db schema...'
196  dbsession.transaction().start(False)
197  schema=dbsession.nominalSchema()
198  db=dbUtil.dbUtil(schema)
199  db.dropTable( nameDealer.lumidetailTableName() )
200  db.dropTable( nameDealer.cmsrunsummaryTableName() )
201  db.dropTable( nameDealer.lumisummaryTableName() )
202  db.dropTable( nameDealer.trgTableName() )
203  db.dropTable( nameDealer.hltTableName() )
204  db.dropTable( nameDealer.trghltMapTableName() )
205  db.dropTable( nameDealer.lumiresultTableName() )
206  db.dropTable( nameDealer.lumihltresultTableName() )
207  db.dropTable( nameDealer.lumivalidationTableName() )
208  dbsession.transaction().commit()
209 
210 def describeLumi(dbsession):
211  print 'lumi db schema dump...'
212  dbsession.transaction().start(True)
213  schema=dbsession.nominalSchema()
214  db=dbUtil.dbUtil(schema)
215  db.describeSchema()
216  dbsession.transaction().commit()
217 
218 def createIndex(dbsession):
219  dbsession.transaction().start(False)
220  schema=dbsession.nominalSchema()
221  schema.tableHandle( nameDealer.lumisummaryTableName() ).schemaEditor().createIndex('lumisummary_runnum',('RUNNUM'))
222  schema.tableHandle( nameDealer.trgTableName() ).schemaEditor().createIndex('trg_runnum',('RUNNUM'))
223  schema.tableHandle( nameDealer.hltTableName() ).schemaEditor().createIndex('hlt_runnum',('RUNNUM'))
224  dbsession.transaction().commit()
225 
226 def dropIndex(dbsession):
227  dbsession.transaction().start(False)
228  schema=dbsession.nominalSchema()
229  schema.tableHandle( nameDealer.lumisummaryTableName() ).schemaEditor().dropIndex('lumisummary_runnum')
230  schema.tableHandle( nameDealer.trgTableName() ).schemaEditor().dropIndex('trg_runnum')
231  schema.tableHandle( nameDealer.hltTableName() ).schemaEditor().dropIndex('hlt_runnum')
232  dbsession.transaction().commit()
233 
234 def main():
235  parser = argparse.ArgumentParser(prog=os.path.basename(sys.argv[0]),description="Lumi DB schema operations.")
236  # add the arguments
237  parser.add_argument('-c',dest='connect',action='store',required=True,help='connect string to lumiDB')
238  parser.add_argument('-P',dest='authpath',action='store',help='path to authentication file')
239  parser.add_argument('action',choices=['create','drop','describe','addindex','dropindex'],help='action on the schema')
240  parser.add_argument('--validationTab',dest='validationTab',action='store_true',help='validation table only')
241  parser.add_argument('--verbose',dest='verbose',action='store_true',help='verbose')
242  parser.add_argument('--debug',dest='debug',action='store_true',help='debug mode')
243  # parse arguments
244  args=parser.parse_args()
245  connectstring=args.connect
246  if args.debug:
247  msg=coral.MessageStream('')
248  msg.setMsgVerbosity(coral.message_Level_Debug)
249  svc = coral.ConnectionService()
250  if args.authpath and len(args.authpath)!=0:
251  os.environ['CORAL_AUTH_PATH']=args.authpath
252  session=svc.connect(connectstring,accessMode=coral.access_Update)
253  if args.action == 'create':
254  if args.validationTab:
255  createValidation(session)
256  else:
257  createLumi(session)
258  if args.action == 'drop':
259  dropLumi(session)
260  if args.action == 'describe':
261  describeLumi(session)
262  if args.action == 'addindex':
263  createIndex(session)
264  if args.action == 'dropindex':
265  dropIndex(session)
266  if args.verbose :
267  print 'verbose mode'
268 if __name__=='__main__':
269  main()
270 
def createValidation
Definition: lumiSchema.py:176
Definition: start.py:1
def lumivalidationTableName
Definition: nameDealer.py:85
def lumisummaryTableName
Definition: nameDealer.py:25
def trghltMapTableName
Definition: nameDealer.py:76
def hltTableName
Definition: nameDealer.py:55
def dropLumi
Definition: lumiSchema.py:194
def lumiresultTableName
Definition: nameDealer.py:79
def lumidetailTableName
Definition: nameDealer.py:34
def createLumi
Definition: lumiSchema.py:7
def createIndex
Definition: lumiSchema.py:218
def lumihltresultTableName
Definition: nameDealer.py:82
def describeLumi
Definition: lumiSchema.py:210
def dropIndex
Definition: lumiSchema.py:226
def trgTableName
Definition: nameDealer.py:52
def cmsrunsummaryTableName
Definition: nameDealer.py:16