CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
dumpFill.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 #
3 # dump all fills into files.
4 # allfills.txt all the existing fills.
5 # fill_num.txt all the runs in the fill
6 # dumpFill -o outputdir
7 # dumpFill -f fillnum generate runlist for the given fill
8 #
9 import os,os.path,sys
10 import coral
11 from RecoLuminosity.LumiDB import argparse,sessionManager,lumiCalcAPI
12 MINFILL=1800
13 MAXFILL=9999
14 allfillname='allfills.txt'
15 
16 def tofiles(allfills,runsperfill,runtimes,outdir):
17  f=open(os.path.join(outdir,allfillname),'w')
18  for fill in allfills:
19  print >>f,'%d'%(fill)
20  f.close()
21  for fill,runs in runsperfill.items():
22  filename='fill_'+str(fill)+'.txt'
23  if len(runs)!=0:
24  f=open(os.path.join(outdir,filename),'w')
25  for run in runs:
26  print >>f,'%d,%s'%(run,runtimes[run])
27  f.close()
28 if __name__ == '__main__':
29  parser = argparse.ArgumentParser(prog=os.path.basename(sys.argv[0]),description = "Dump Fill",formatter_class=argparse.ArgumentDefaultsHelpFormatter)
30  # parse arguments
31  parser.add_argument('-c',dest='connect',action='store',required=False,help='connect string to lumiDB,optional',default='frontier://LumiCalc/CMS_LUMI_PROD')
32  parser.add_argument('-P',dest='authpath',action='store',help='path to authentication file,optional')
33  parser.add_argument('-o',dest='outputdir',action='store',required=False,help='output dir',default='.')
34  parser.add_argument('--amodetag',dest='amodetag',action='store',required=False,help='amodetag',default='PROTPHYS')
35  parser.add_argument('-f','--fill',
36  dest='fillnum',
37  action='store',
38  required=False,
39  help='specific fill',default=None)
40  parser.add_argument('--minfill',dest='minfill',
41  type=int,
42  action='store',
43  required=False,
44  default=MINFILL,
45  help='min fill')
46  parser.add_argument('--maxfill',dest='maxfill',
47  type=int,
48  action='store',
49  required=False,
50  default=MAXFILL,
51  help='maximum fillnumber '
52  )
53  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')
54  parser.add_argument('--debug',dest='debug',action='store_true',help='debug')
55  options=parser.parse_args()
56  if options.authpath:
57  os.environ['CORAL_AUTH_PATH'] = options.authpath
58  svc=sessionManager.sessionManager(options.connect,authpath=options.authpath,debugON=options.debug)
59  session=svc.openSession(isReadOnly=True,cpp2sqltype=[('unsigned int','NUMBER(10)'),('unsigned long long','NUMBER(20)')])
60 
61  session.transaction().start(True)
62  allfills=lumiCalcAPI.fillInRange(session.nominalSchema(),fillmin=options.minfill,fillmax=options.maxfill,amodetag=options.amodetag)
63  if len(allfills)==0:
64  print 'no qualified fills found, do nothing... '
65  exit(-1)
66  allfills.sort()
67  runsperfill={}
68  runtimes={}
69  irunlsdict={}
70  if options.fillnum:
71  if int(options.fillnum) in allfills:
72  runsperfill=lumiCalcAPI.fillrunMap(session.nominalSchema(),fillnum=int(options.fillnum))
73  allruns=runsperfill[ int(options.fillnum) ]
74  allls=[None]*len(allruns)
75  irunlsdict=dict(zip(allruns,allls))
76  runresults=lumiCalcAPI.runsummary(session.nominalSchema(),irunlsdict)
77  for r in runresults:
78  runtimes[r[0]]=r[7]
79  else:
80  for fill in allfills:
81  runtimes={}
82  runsperfill=lumiCalcAPI.fillrunMap(session.nominalSchema(),fillnum=fill)
83  runs=runsperfill.values()#list of lists
84  allruns=[item for sublist in runs for item in sublist]
85  allls=[None]*len(allruns)
86  irunlsdict=dict(zip(allruns,allls))
87  runresults=lumiCalcAPI.runsummary(session.nominalSchema(),irunlsdict)
88  for r in runresults:
89  runtimes[r[0]]=r[7]
90  tofiles(allfills,runsperfill,runtimes,options.outputdir)
91  session.transaction().commit()
92 
93 
Definition: start.py:1
tuple zip
Definition: archive.py:476
def tofiles
Definition: dumpFill.py:16
def runsummary
Lumi data management and calculation API # # Author: Zhen Xie #.
Definition: lumiCalcAPI.py:10
def fillrunMap
Definition: lumiCalcAPI.py:41
def fillInRange
Definition: lumiCalcAPI.py:35