CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_8_patch3/src/RecoLuminosity/LumiDB/scripts/dumpFill.py

Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 #
00003 # dump all fills into files.
00004 # allfills.txt all the existing fills.
00005 # fill_num.txt all the runs in the fill
00006 # dumpFill -o outputdir
00007 # dumpFill -f fillnum generate runlist for the given fill
00008 #
00009 import os,os.path,sys
00010 import coral
00011 from RecoLuminosity.LumiDB import argparse,sessionManager,lumiCalcAPI
00012 MINFILL=1800
00013 MAXFILL=9999
00014 allfillname='allfills.txt'
00015 
00016 def tofiles(allfills,runsperfill,runtimes,outdir):
00017     f=open(os.path.join(outdir,allfillname),'w')
00018     for fill in allfills:
00019         print >>f,'%d'%(fill)
00020     f.close()
00021     for fill,runs in runsperfill.items():
00022         filename='fill_'+str(fill)+'.txt'
00023         if len(runs)!=0:
00024             f=open(os.path.join(outdir,filename),'w')
00025             for run in runs:
00026                 print >>f,'%d,%s'%(run,runtimes[run])
00027             f.close()
00028 if __name__ == '__main__':
00029     parser = argparse.ArgumentParser(prog=os.path.basename(sys.argv[0]),description = "Dump Fill",formatter_class=argparse.ArgumentDefaultsHelpFormatter)
00030     # parse arguments
00031     parser.add_argument('-c',dest='connect',action='store',required=False,help='connect string to lumiDB,optional',default='frontier://LumiCalc/CMS_LUMI_PROD')
00032     parser.add_argument('-P',dest='authpath',action='store',help='path to authentication file,optional')
00033     parser.add_argument('-o',dest='outputdir',action='store',required=False,help='output dir',default='.')
00034     parser.add_argument('--amodetag',dest='amodetag',action='store',required=False,help='amodetag',default='PROTPHYS')
00035     parser.add_argument('-f','--fill',
00036                         dest='fillnum',
00037                         action='store',
00038                         required=False,
00039                         help='specific fill',default=None)
00040     parser.add_argument('--minfill',dest='minfill',
00041                         type=int,
00042                         action='store',
00043                         required=False,
00044                         default=MINFILL,
00045                         help='min fill')
00046     parser.add_argument('--maxfill',dest='maxfill',
00047                         type=int,
00048                         action='store',
00049                         required=False,
00050                         default=MAXFILL,
00051                         help='maximum fillnumber '
00052                         )
00053     parser.add_argument('-siteconfpath',dest='siteconfpath',action='store',help='specific path to site-local-config.xml file, optional. If path undefined, fallback to cern proxy&server')
00054     parser.add_argument('--debug',dest='debug',action='store_true',help='debug')
00055     options=parser.parse_args()
00056     if options.authpath:
00057         os.environ['CORAL_AUTH_PATH'] = options.authpath
00058     svc=sessionManager.sessionManager(options.connect,authpath=options.authpath,debugON=options.debug)
00059     session=svc.openSession(isReadOnly=True,cpp2sqltype=[('unsigned int','NUMBER(10)'),('unsigned long long','NUMBER(20)')])
00060         
00061     session.transaction().start(True)
00062     allfills=lumiCalcAPI.fillInRange(session.nominalSchema(),fillmin=options.minfill,fillmax=options.maxfill,amodetag=options.amodetag)
00063     if len(allfills)==0:
00064         print 'no qualified fills found, do nothing... '
00065         exit(-1)
00066     allfills.sort()
00067     runsperfill={}
00068     runtimes={}
00069     irunlsdict={}
00070     if options.fillnum:
00071         if int(options.fillnum) in allfills:
00072             runsperfill=lumiCalcAPI.fillrunMap(session.nominalSchema(),fillnum=int(options.fillnum))
00073             allruns=runsperfill[ int(options.fillnum) ]
00074             allls=[None]*len(allruns)
00075             irunlsdict=dict(zip(allruns,allls))
00076             runresults=lumiCalcAPI.runsummary(session.nominalSchema(),irunlsdict)
00077             for r in runresults:
00078                 runtimes[r[0]]=r[7]
00079     else:
00080         for fill in allfills:
00081             runtimes={}
00082             runsperfill=lumiCalcAPI.fillrunMap(session.nominalSchema(),fillnum=fill)
00083             runs=runsperfill.values()#list of lists
00084             allruns=[item for sublist in runs for item in sublist]
00085             allls=[None]*len(allruns)
00086             irunlsdict=dict(zip(allruns,allls))
00087             runresults=lumiCalcAPI.runsummary(session.nominalSchema(),irunlsdict)
00088             for r in runresults:
00089                 runtimes[r[0]]=r[7]
00090             tofiles(allfills,runsperfill,runtimes,options.outputdir)
00091     session.transaction().commit()
00092 
00093