CMS 3D CMS Logo

lumidb2Schema.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 from __future__ import print_function
3 VERSION='2.00'
4 import os,sys
5 import coral
6 from RecoLuminosity.LumiDB import argparse,dbUtil,nameDealer,lumidbDDL,dataDML,revisionDML
7 
8 def createLumi(dbsession):
9  print('creating lumidb2 schema...')
10  dbsession.transaction().start(False)
11  schema=dbsession.nominalSchema()
13  dbsession.transaction().commit()
14 
15 def dropLumi(dbsession):
16  print('droping lumi db2 schema...')
17  dbsession.transaction().start(False)
18  schema=dbsession.nominalSchema()
20  dbsession.transaction().commit()
21 
22 def describeLumi(dbsession):
23  print('lumi db schema dump...')
24  dbsession.transaction().start(True)
25  schema=dbsession.nominalSchema()
26  db=dbUtil.dbUtil(schema)
27  db.describeSchema()
28  dbsession.transaction().commit()
29 
30 def createIndex(dbsession):
31  pass
32 
33 def dropIndex(dbsession):
34  pass
35 
36 def createBranch(dbsession,branchname,parentname,comment):
37  print('creating branch ',branchname)
38  dbsession.transaction().start(False)
39  (branchid,parentid,parentname)=revisionDML.createBranch(dbsession.nominalSchema(),branchname,parentname,comment)
40  dbsession.transaction().commit()
41  print('branchid ',branchid,' parentname ',parentname,' parentid ',parentid)
42 
43 def main():
44  parser = argparse.ArgumentParser(prog=os.path.basename(sys.argv[0]),description="Lumi DB schema operations.")
45  # add the arguments
46  parser.add_argument('-c',dest='connect',action='store',required=True,help='connect string to lumiDB')
47  parser.add_argument('-P',dest='authpath',action='store',help='path to authentication file')
48  parser.add_argument('action',choices=['create','createbranch','drop','describe','addindex','dropindex'],help='action on the schema')
49  parser.add_argument('--verbose',dest='verbose',action='store_true',help='verbose')
50  parser.add_argument('--debug',dest='debug',action='store_true',help='debug mode')
51  # parse arguments
52  args=parser.parse_args()
53  connectstring=args.connect
54  if args.debug:
55  msg=coral.MessageStream('')
56  msg.setMsgVerbosity(coral.message_Level_Debug)
57  svc = coral.ConnectionService()
58  if args.authpath and len(args.authpath)!=0:
59  os.environ['CORAL_AUTH_PATH']=args.authpath
60  session=svc.connect(connectstring,accessMode=coral.access_Update)
61  if args.action == 'create':
62  createLumi(session)
63  if args.action == 'createbranch':
64  createBranch(session,'TRUNK',None,'root')
65  createBranch(session,'NORM','TRUNK','hold normalization factor')
66  createBranch(session,'DATA','TRUNK','hold data')
67  if args.action == 'drop':
68  dropLumi(session)
69  if args.action == 'describe':
70  describeLumi(session)
71  if args.action == 'addindex':
72  createIndex(session)
73  if args.action == 'dropindex':
74  dropIndex(session)
75  if args.verbose :
76  print('verbose mode')
77 if __name__=='__main__':
78  main()
79 
Definition: start.py:1
def dropTables(schema, tablelist)
Definition: lumidbDDL.py:223
def createTables(schema)
Definition: lumidbDDL.py:9
def dropIndex(dbsession)
def createIndex(dbsession)
S & print(S &os, JobReport::InputFile const &f)
Definition: JobReport.cc:65
def createLumi(dbsession)
Definition: lumidb2Schema.py:8
def dropLumi(dbsession)
def createBranch(dbsession, branchname, parentname, comment)
def describeLumi(dbsession)
Definition: main.py:1
def createBranch(schema, name, parentname, comment='')
Definition: revisionDML.py:433
def schemaV2Tables()
Definition: nameDealer.py:5