00001
00002 VERSION='2.00'
00003 import os,sys
00004 import coral
00005 from RecoLuminosity.LumiDB import argparse,dbUtil,nameDealer
00006
00007 def createLumi(dbsession):
00008 print 'creating lumi db schema...'
00009 dbsession.transaction().start(False)
00010 schema=dbsession.nominalSchema()
00011 db=dbUtil.dbUtil(schema)
00012
00013
00014 cmsrunsummary=coral.TableDescription()
00015 cmsrunsummary.setName( nameDealer.cmsrunsummaryTableName() )
00016 cmsrunsummary.insertColumn('RUNNUM','unsigned int')
00017 cmsrunsummary.insertColumn('HLTKEY','string')
00018 cmsrunsummary.insertColumn('FILLNUM','unsigned int')
00019 cmsrunsummary.insertColumn('SEQUENCE','string')
00020 cmsrunsummary.insertColumn('STARTTIME','time stamp',6)
00021 cmsrunsummary.insertColumn('STOPTIME','time stamp',6)
00022 cmsrunsummary.setPrimaryKey('RUNNUM')
00023 cmsrunsummary.setNotNullConstraint('HLTKEY',True)
00024 cmsrunsummary.setNotNullConstraint('FILLNUM',True)
00025 cmsrunsummary.setNotNullConstraint('SEQUENCE',True)
00026 cmsrunsummary.createIndex('cmsrunsummary_fillnum',('FILLNUM'))
00027 cmsrunsummary.createIndex('cmsrunsummary_startime',('STARTTIME'))
00028 db.createTable(cmsrunsummary,False)
00029
00030
00031 summary=coral.TableDescription()
00032 summary.setName( nameDealer.lumisummaryTableName() )
00033 summary.insertColumn('LUMISUMMARY_ID','unsigned long long')
00034 summary.insertColumn('RUNNUM','unsigned int')
00035 summary.insertColumn('CMSLSNUM','unsigned int')
00036 summary.insertColumn('LUMILSNUM','unsigned int')
00037 summary.insertColumn('LUMIVERSION','string')
00038 summary.insertColumn('DTNORM','float')
00039 summary.insertColumn('LHCNORM','float')
00040 summary.insertColumn('INSTLUMI','float')
00041 summary.insertColumn('INSTLUMIERROR','float')
00042 summary.insertColumn('INSTLUMIQUALITY','short')
00043 summary.insertColumn('CMSALIVE','short')
00044 summary.insertColumn('STARTORBIT','unsigned int')
00045 summary.insertColumn('NUMORBIT','unsigned int')
00046 summary.insertColumn('LUMISECTIONQUALITY','short')
00047 summary.insertColumn('BEAMENERGY','float')
00048 summary.insertColumn('BEAMSTATUS','string')
00049 summary.insertColumn('CMSBXINDEXBLOB','blob')
00050 summary.insertColumn('BEAMINTENSITYBLOB_1','blob')
00051 summary.insertColumn('BEAMINTENSITYBLOB_2','blob')
00052
00053 summary.setPrimaryKey('LUMISUMMARY_ID')
00054 summary.setNotNullConstraint('RUNNUM',True)
00055 summary.setNotNullConstraint('CMSLSNUM',True)
00056 summary.setNotNullConstraint('LUMILSNUM',True)
00057 summary.setNotNullConstraint('LUMIVERSION',True)
00058 summary.setNotNullConstraint('DTNORM',True)
00059 summary.setNotNullConstraint('LHCNORM',True)
00060 summary.setNotNullConstraint('INSTLUMI',True)
00061 summary.setNotNullConstraint('INSTLUMIERROR',True)
00062 summary.setNotNullConstraint('INSTLUMIQUALITY',True)
00063 summary.setNotNullConstraint('CMSALIVE',True)
00064 summary.setNotNullConstraint('STARTORBIT',True)
00065 summary.setNotNullConstraint('NUMORBIT',True)
00066 summary.setNotNullConstraint('LUMISECTIONQUALITY',True)
00067 summary.setNotNullConstraint('BEAMENERGY',True)
00068 summary.setNotNullConstraint('BEAMSTATUS',True)
00069
00070 summary.setUniqueConstraint(('RUNNUM','LUMIVERSION','LUMILSNUM'))
00071 summary.createIndex('lumisummary_runnum',('RUNNUM'))
00072
00073 db.createTable(summary,True)
00074
00075 detail=coral.TableDescription()
00076 detail.setName( nameDealer.lumidetailTableName() )
00077 detail.insertColumn('LUMIDETAIL_ID','unsigned long long')
00078 detail.insertColumn('LUMISUMMARY_ID','unsigned long long')
00079 detail.insertColumn('BXLUMIVALUE','blob')
00080 detail.insertColumn('BXLUMIERROR','blob')
00081 detail.insertColumn('BXLUMIQUALITY','blob')
00082 detail.insertColumn('ALGONAME','string')
00083 detail.setPrimaryKey('LUMIDETAIL_ID')
00084 detail.createForeignKey('DETAILSOURCE','LUMISUMMARY_ID',nameDealer.lumisummaryTableName(),'LUMISUMMARY_ID')
00085 detail.setNotNullConstraint('BXLUMIVALUE',True)
00086 detail.setNotNullConstraint('BXLUMIERROR',True)
00087 detail.setNotNullConstraint('BXLUMIQUALITY',True)
00088 detail.setNotNullConstraint('ALGONAME',True)
00089
00090 detail.setUniqueConstraint(('LUMISUMMARY_ID','ALGONAME'))
00091
00092 db.createTable(detail,True)
00093
00094 trg=coral.TableDescription()
00095 trg.setName( nameDealer.trgTableName() )
00096 trg.insertColumn('TRG_ID','unsigned long long')
00097 trg.insertColumn('RUNNUM','unsigned int')
00098 trg.insertColumn('CMSLSNUM','unsigned int')
00099 trg.insertColumn('BITNUM','unsigned int')
00100 trg.insertColumn('BITNAME','string')
00101 trg.insertColumn('TRGCOUNT','unsigned int')
00102 trg.insertColumn('DEADTIME','unsigned long long')
00103 trg.insertColumn('PRESCALE','unsigned int')
00104
00105 trg.setNotNullConstraint('RUNNUM',True)
00106 trg.setNotNullConstraint('CMSLSNUM',True)
00107 trg.setNotNullConstraint('BITNUM',True)
00108 trg.setNotNullConstraint('BITNAME',True)
00109 trg.setNotNullConstraint('TRGCOUNT',True)
00110 trg.setNotNullConstraint('DEADTIME',True)
00111 trg.setNotNullConstraint('PRESCALE',True)
00112 trg.setPrimaryKey('TRG_ID')
00113 trg.createIndex('trg_runnum',('RUNNUM'))
00114
00115 db.createTable(trg,True)
00116
00117 hlt=coral.TableDescription()
00118 hlt.setName( nameDealer.hltTableName() )
00119 hlt.insertColumn( 'HLT_ID','unsigned long long')
00120 hlt.insertColumn( 'RUNNUM','unsigned int')
00121 hlt.insertColumn( 'CMSLSNUM','unsigned int')
00122 hlt.insertColumn( 'PATHNAME','string')
00123 hlt.insertColumn( 'INPUTCOUNT','unsigned int')
00124 hlt.insertColumn( 'ACCEPTCOUNT','unsigned int')
00125 hlt.insertColumn( 'PRESCALE','unsigned int')
00126 hlt.setPrimaryKey( 'HLT_ID' )
00127 hlt.setNotNullConstraint('RUNNUM',True)
00128 hlt.setNotNullConstraint('CMSLSNUM',True)
00129 hlt.setNotNullConstraint('PATHNAME',True)
00130 hlt.setNotNullConstraint('INPUTCOUNT',True)
00131 hlt.setNotNullConstraint('ACCEPTCOUNT',True)
00132 hlt.setNotNullConstraint('PRESCALE',True)
00133 hlt.createIndex('hlt_runnum',('RUNNUM'))
00134 db.createTable(hlt,True)
00135
00136 trghlt=coral.TableDescription()
00137 trghlt.setName( nameDealer.trghltMapTableName() )
00138
00139 trghlt.insertColumn( 'HLTKEY','string' )
00140 trghlt.insertColumn( 'HLTPATHNAME','string' )
00141 trghlt.insertColumn( 'L1SEED','string' )
00142 trghlt.setNotNullConstraint('HLTKEY',True)
00143 trghlt.setNotNullConstraint('HLTPATHNAME',True)
00144 trghlt.setNotNullConstraint('L1SEED',True)
00145 db.createTable(trghlt,False)
00146
00147 lumiresult=coral.TableDescription()
00148 lumiresult.setName( nameDealer.lumiresultTableName() )
00149 lumiresult.insertColumn( 'RUNNUM','unsigned int' )
00150 lumiresult.insertColumn( 'LUMIVERSION','string' )
00151 lumiresult.insertColumn( 'DELIVEREDLUMI','float' )
00152 lumiresult.insertColumn( 'RECORDEDLUMI','float' )
00153 db.createTable(lumiresult,False)
00154
00155 lumihltresult=coral.TableDescription()
00156 lumihltresult.setName( nameDealer.lumihltresultTableName() )
00157 lumihltresult.insertColumn( 'RUNNUM','unsigned int' )
00158 lumihltresult.insertColumn( 'LUMIVERSION','string' )
00159 lumihltresult.insertColumn( 'HLTPATH','float' )
00160 lumihltresult.insertColumn( 'RECORDEDLUMI','float' )
00161 db.createTable(lumihltresult,False)
00162
00163
00164 lumivalidation=coral.TableDescription()
00165 lumivalidation.setName( nameDealer.lumivalidationTableName() )
00166 lumivalidation.insertColumn( 'RUNNUM','unsigned int' )
00167 lumivalidation.insertColumn( 'CMSLSNUM','unsigned int' )
00168 lumivalidation.insertColumn( 'FLAG','string' )
00169 lumivalidation.insertColumn( 'COMMENT','string' )
00170 lumivalidation.setPrimaryKey(('RUNNUM','CMSLSNUM'))
00171 lumivalidation.setNotNullConstraint('FLAG',True)
00172
00173 db.createTable(lumivalidation,False)
00174 dbsession.transaction().commit()
00175
00176 def createValidation(dbsession):
00177 '''
00178 lumivalidation table
00179 '''
00180 dbsession.transaction().start(False)
00181 schema=dbsession.nominalSchema()
00182 db=dbUtil.dbUtil(schema)
00183 lumivalidation=coral.TableDescription()
00184 lumivalidation.setName( nameDealer.lumivalidationTableName() )
00185 lumivalidation.insertColumn( 'RUNNUM','unsigned int' )
00186 lumivalidation.insertColumn( 'CMSLSNUM','unsigned int' )
00187 lumivalidation.insertColumn( 'FLAG','string' )
00188 lumivalidation.insertColumn( 'COMMENT','string' )
00189 lumivalidation.setPrimaryKey(('RUNNUM','CMSLSNUM'))
00190 lumivalidation.setNotNullConstraint('FLAG',True)
00191 db.createTable(lumivalidation,False)
00192 dbsession.transaction().commit()
00193
00194 def dropLumi(dbsession):
00195 print 'droping lumi db schema...'
00196 dbsession.transaction().start(False)
00197 schema=dbsession.nominalSchema()
00198 db=dbUtil.dbUtil(schema)
00199 db.dropTable( nameDealer.lumidetailTableName() )
00200 db.dropTable( nameDealer.cmsrunsummaryTableName() )
00201 db.dropTable( nameDealer.lumisummaryTableName() )
00202 db.dropTable( nameDealer.trgTableName() )
00203 db.dropTable( nameDealer.hltTableName() )
00204 db.dropTable( nameDealer.trghltMapTableName() )
00205 db.dropTable( nameDealer.lumiresultTableName() )
00206 db.dropTable( nameDealer.lumihltresultTableName() )
00207 db.dropTable( nameDealer.lumivalidationTableName() )
00208 dbsession.transaction().commit()
00209
00210 def describeLumi(dbsession):
00211 print 'lumi db schema dump...'
00212 dbsession.transaction().start(True)
00213 schema=dbsession.nominalSchema()
00214 db=dbUtil.dbUtil(schema)
00215 db.describeSchema()
00216 dbsession.transaction().commit()
00217
00218 def createIndex(dbsession):
00219 dbsession.transaction().start(False)
00220 schema=dbsession.nominalSchema()
00221 schema.tableHandle( nameDealer.lumisummaryTableName() ).schemaEditor().createIndex('lumisummary_runnum',('RUNNUM'))
00222 schema.tableHandle( nameDealer.trgTableName() ).schemaEditor().createIndex('trg_runnum',('RUNNUM'))
00223 schema.tableHandle( nameDealer.hltTableName() ).schemaEditor().createIndex('hlt_runnum',('RUNNUM'))
00224 dbsession.transaction().commit()
00225
00226 def dropIndex(dbsession):
00227 dbsession.transaction().start(False)
00228 schema=dbsession.nominalSchema()
00229 schema.tableHandle( nameDealer.lumisummaryTableName() ).schemaEditor().dropIndex('lumisummary_runnum')
00230 schema.tableHandle( nameDealer.trgTableName() ).schemaEditor().dropIndex('trg_runnum')
00231 schema.tableHandle( nameDealer.hltTableName() ).schemaEditor().dropIndex('hlt_runnum')
00232 dbsession.transaction().commit()
00233
00234 def main():
00235 parser = argparse.ArgumentParser(prog=os.path.basename(sys.argv[0]),description="Lumi DB schema operations.")
00236
00237 parser.add_argument('-c',dest='connect',action='store',required=True,help='connect string to lumiDB')
00238 parser.add_argument('-P',dest='authpath',action='store',help='path to authentication file')
00239 parser.add_argument('action',choices=['create','drop','describe','addindex','dropindex'],help='action on the schema')
00240 parser.add_argument('--validationTab',dest='validationTab',action='store_true',help='validation table only')
00241 parser.add_argument('--verbose',dest='verbose',action='store_true',help='verbose')
00242 parser.add_argument('--debug',dest='debug',action='store_true',help='debug mode')
00243
00244 args=parser.parse_args()
00245 connectstring=args.connect
00246 if args.debug:
00247 msg=coral.MessageStream('')
00248 msg.setMsgVerbosity(coral.message_Level_Debug)
00249 svc = coral.ConnectionService()
00250 if args.authpath and len(args.authpath)!=0:
00251 os.environ['CORAL_AUTH_PATH']=args.authpath
00252 session=svc.connect(connectstring,accessMode=coral.access_Update)
00253 if args.action == 'create':
00254 if args.validationTab:
00255 createValidation(session)
00256 else:
00257 createLumi(session)
00258 if args.action == 'drop':
00259 dropLumi(session)
00260 if args.action == 'describe':
00261 describeLumi(session)
00262 if args.action == 'addindex':
00263 createIndex(session)
00264 if args.action == 'dropindex':
00265 dropIndex(session)
00266 if args.verbose :
00267 print 'verbose mode'
00268 if __name__=='__main__':
00269 main()
00270