CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/RecoLuminosity/LumiDB/scripts/lumiData.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,nameDealer,connectstrParser,cacheconfigParser,tablePrinter
00006 from RecoLuminosity.LumiDB.wordWrappers import wrap_always,wrap_onspace,wrap_onspace_strict
00007 def defaultfrontierConfigString(self):
00008         return """<frontier-connect><proxy url="https://cmst0frontier.cern.ch:3128"/><proxy url="https://cmst0frontier.cern.ch:3128"/><proxy url="https://cmst0frontier1.cern.ch:3128"/><proxy url="https://cmst0frontier2.cern.ch:3128"/><server url="https://cmsfrontier.cern.ch:8000/FrontierInt"/><server url="https://cmsfrontier.cern.ch:8000/FrontierInt"/><server url="https://cmsfrontier1.cern.ch:8000/FrontierInt"/><server url="https://cmsfrontier2.cern.ch:8000/FrontierInt"/><server url="https://cmsfrontier3.cern.ch:8000/FrontierInt"/><server url="https://cmsfrontier4.cern.ch:8000/FrontierInt"/></frontier-connect>"""
00009 def listRemoveDuplicate(inlist):
00010     d={}
00011     for x in inlist:
00012         d[x]=x
00013     return d.values()
00014 
00015 def runListInDB(dbsession,lumiversion=''):
00016     """
00017     list available runs in the DB
00018     output: [runnumber]
00019     """ 
00020     runlist=[]
00021     try:
00022         dbsession.transaction().start(True)
00023         schema=dbsession.nominalSchema()
00024          
00025         query=schema.tableHandle(nameDealer.lumisummaryTableName()).newQuery()
00026         query.addToOutputList("RUNNUM","run")
00027         query.addToOutputList("LUMIVERSION","lumiversion")
00028         queryBind=coral.AttributeList()
00029         queryBind.extend("lumiversion","string")
00030         if len(lumiversion)!=0:
00031             queryBind["lumiversion"].setData(lumiversion)
00032             query.setCondition("LUMIVERSION=:lumiversion",queryBind)
00033         query.addToOrderList('RUNNUM')
00034         result=coral.AttributeList()
00035         result.extend("run","unsigned int")
00036         result.extend("lumiversion","string")
00037         query.defineOutput(result)
00038         cursor=query.execute()
00039         while cursor.next():
00040             r=cursor.currentRow()['run'].data()
00041             v=cursor.currentRow()['lumiversion'].data()
00042             runlist.append((r,v))
00043         del query
00044         dbsession.transaction().commit()
00045     except Exception,e:
00046         print str(e)
00047         dbsession.transaction().rollback()
00048         del dbsession
00049     runlist=listRemoveDuplicate(runlist)
00050     runlist.sort()
00051     return runlist
00052 
00053 def printRunList(runlistdata):
00054     result=[['Run','Lumiversion']]
00055     for tp in runlistdata:
00056         i=[str(tp[0]),tp[1]]
00057         result.append(i)
00058     print tablePrinter.indent(result,hasHeader=True,separateRows=False,prefix='| ',postfix=' |',wrapfunc=lambda x: wrap_onspace(x,20) )
00059     
00060 def main():
00061     parser = argparse.ArgumentParser(prog=os.path.basename(sys.argv[0]),description="Lumi Data operations")
00062     # add required arguments
00063     parser.add_argument('-c',dest='connect',action='store',required=True,help='connect string to lumiDB')
00064     # add optional arguments
00065     parser.add_argument('-P',dest='authpath',action='store',help='path to authentication file')
00066     parser.add_argument('-lumiversion',dest='lumiversion',action='store',help='lumi data version, optional')
00067     parser.add_argument('-siteconfpath',dest='siteconfpath',action='store',help='specific path to site-local-config.xml file, default to $CMS_PATH/SITECONF/local/JobConfig, if path undefined, fallback to cern proxy&server')
00068     parser.add_argument('action',choices=['listrun'],help='command actions')
00069     parser.add_argument('--raw',dest='printraw',action='store_true',help='print raw data' )
00070     parser.add_argument('--verbose',dest='verbose',action='store_true',help='verbose mode for printing' )
00071     parser.add_argument('--debug',dest='debug',action='store_true',help='debug')
00072     # parse arguments
00073     args=parser.parse_args()
00074     connectstring=args.connect
00075     connectparser=connectstrParser.connectstrParser(connectstring)
00076     connectparser.parse()
00077     usedefaultfrontierconfig=False
00078     cacheconfigpath=''
00079     if connectparser.needsitelocalinfo():
00080         if not args.siteconfpath:
00081             cacheconfigpath=os.environ['CMS_PATH']
00082             if cacheconfigpath:
00083                 cacheconfigpath=os.path.join(cacheconfigpath,'SITECONF','local','JobConfig','site-local-config.xml')
00084             else:
00085                 usedefaultfrontierconfig=True
00086         else:
00087             cacheconfigpath=args.siteconfpath
00088             cacheconfigpath=os.path.join(cacheconfigpath,'site-local-config.xml')
00089         p=cacheconfigParser.cacheconfigParser()
00090         if usedefaultfrontierconfig:
00091             p.parseString(c.defaultfrontierConfigString)
00092         else:
00093             p.parse(cacheconfigpath)
00094         connectstring=connectparser.fullfrontierStr(connectparser.schemaname(),p.parameterdict())
00095     #print 'connectstring',connectstring
00096     runnumber=0
00097     svc = coral.ConnectionService()
00098     isverbose=False
00099     if args.debug :
00100         msg=coral.MessageStream('')
00101         msg.setMsgVerbosity(coral.message_Level_Debug)
00102         c.VERBOSE=True
00103 
00104     if args.verbose :
00105         c.VERBOSE=True
00106     if args.authpath and len(args.authpath)!=0:
00107         os.environ['CORAL_AUTH_PATH']=args.authpath
00108 
00109     session=svc.connect(connectstring,accessMode=coral.access_Update)
00110     session.typeConverter().setCppTypeForSqlType("unsigned int","NUMBER(10)")
00111 
00112     if args.action == 'listrun':
00113         lumiversion=''
00114         if args.lumiversion:
00115             lumiversion=args.lumiversion
00116         runlist=runListInDB(session,lumiversion)
00117         if args.printraw:
00118             print runlist
00119         else: printRunList(runlist)
00120     
00121     del session
00122     del svc
00123 if __name__=='__main__':
00124     main()
00125