CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC2_patch1/src/RecoLuminosity/LumiDB/scripts/lumidb2Schema.py

Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 VERSION='2.00'
00003 import os,sys
00004 import coral
00005 from RecoLuminosity.LumiDB import argparse,dbUtil,nameDealer,lumidbDDL,dataDML,revisionDML
00006 
00007 def createLumi(dbsession):
00008     print 'creating lumidb2 schema...'
00009     dbsession.transaction().start(False)
00010     schema=dbsession.nominalSchema()
00011     lumidbDDL.createTables(schema)
00012     dbsession.transaction().commit()
00013     
00014 def dropLumi(dbsession):
00015     print 'droping lumi db2 schema...'
00016     dbsession.transaction().start(False)
00017     schema=dbsession.nominalSchema()
00018     lumidbDDL.dropTables(schema,nameDealer.schemaV2Tables())
00019     dbsession.transaction().commit()
00020     
00021 def describeLumi(dbsession):
00022     print 'lumi db schema dump...'
00023     dbsession.transaction().start(True)
00024     schema=dbsession.nominalSchema()
00025     db=dbUtil.dbUtil(schema)
00026     db.describeSchema()
00027     dbsession.transaction().commit()
00028 
00029 def createIndex(dbsession):
00030     pass
00031     
00032 def dropIndex(dbsession):
00033     pass
00034 
00035 def createBranch(dbsession,branchname,parentname,comment):
00036     print 'creating branch ',branchname
00037     dbsession.transaction().start(False)
00038     (branchid,parentid,parentname)=revisionDML.createBranch(dbsession.nominalSchema(),branchname,parentname,comment)
00039     dbsession.transaction().commit()
00040     print 'branchid ',branchid,' parentname ',parentname,' parentid ',parentid
00041 
00042 def main():
00043     parser = argparse.ArgumentParser(prog=os.path.basename(sys.argv[0]),description="Lumi DB schema operations.")
00044     # add the arguments
00045     parser.add_argument('-c',dest='connect',action='store',required=True,help='connect string to lumiDB')
00046     parser.add_argument('-P',dest='authpath',action='store',help='path to authentication file')
00047     parser.add_argument('action',choices=['create','createbranch','drop','describe','addindex','dropindex'],help='action on the schema')
00048     parser.add_argument('--verbose',dest='verbose',action='store_true',help='verbose')
00049     parser.add_argument('--debug',dest='debug',action='store_true',help='debug mode')
00050     # parse arguments
00051     args=parser.parse_args()
00052     connectstring=args.connect
00053     if args.debug:
00054         msg=coral.MessageStream('')
00055         msg.setMsgVerbosity(coral.message_Level_Debug)
00056     svc = coral.ConnectionService()
00057     if args.authpath and len(args.authpath)!=0:
00058         os.environ['CORAL_AUTH_PATH']=args.authpath
00059     session=svc.connect(connectstring,accessMode=coral.access_Update)
00060     if args.action == 'create':
00061         createLumi(session)
00062     if args.action == 'createbranch':
00063         createBranch(session,'TRUNK',None,'root')
00064         createBranch(session,'NORM','TRUNK','hold normalization factor')
00065         createBranch(session,'DATA','TRUNK','hold data')
00066     if args.action == 'drop':
00067        dropLumi(session)
00068     if args.action == 'describe':
00069        describeLumi(session)
00070     if args.action == 'addindex':
00071        createIndex(session)
00072     if args.action == 'dropindex':
00073        dropIndex(session)
00074     if args.verbose :
00075         print 'verbose mode'
00076 if __name__=='__main__':
00077     main()
00078