CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
lumiDBFiller.py
Go to the documentation of this file.
1 #! /usr/bin/python
2 
3 import string, os, time
4 import commands
5 lumiauthpath=''
6 lumilogpath=''
7 loaderconf=''
8 def isCollisionRun(run,authpath=''):
9  itIs = False
10  itIsAlso = False
11  isInAfill = False
12  command = 'dumpRunInfo.py -c oracle://cms_omds_lb/cms_runinfo -P '+authpath+' -r '+run+' --collision-only l1key | wc'
13  statusAndOutput = commands.getstatusoutput(command)
14  if statusAndOutput[1].split(' ')[2] == '2': itIs = True
15  command = 'dumpRunInfo.py -c oracle://cms_omds_lb/cms_runinfo -P '+authpath+' -r '+run+' --collision-only hltkey | wc'
16  statusAndOutput = commands.getstatusoutput(command)
17  if statusAndOutput[1].split(' ')[2] == '2': itIsAlso = True
18  command = 'dumpRunInfo.py -c oracle://cms_omds_lb/cms_runinfo -P '+authpath+' -r '+run+' fill'
19  statusAndOutput = commands.getstatusoutput(command)
20  fillnum=statusAndOutput[1].split('\n')[1].split(' ')[1]
21  if fillnum and fillnum != '0':
22  isInAfill=True
23  return itIs and itIsAlso and isInAfill
24 
25 def getRunnumberFromFileName(lumifilename):
26  runnumber=int(lumifilename.split('_')[4])
27  return runnumber
28 
29 def getRunsToBeUploaded(connectionString, dropbox, authpath=''):
30  #print 'authpath ',authpath
31  # get the last analyzed run
32  command = 'lumiData.py -c ' +connectionString+' -P '+authpath+' --raw listrun'
33  statusAndOutput = commands.getstatusoutput(command)
34  lastAnalyzedRunNumber = eval(statusAndOutput[1])[-1][0]
35  print 'Last run in DB: ', lastAnalyzedRunNumber
36 
37  # check if there are new runs to be uploaded
38  #command = 'ls -ltr '+dropbox
39  files=filter(os.path.isfile,[os.path.join(dropbox,x) for x in os.listdir(dropbox)])
40  #print files
41  files.sort(key=lambda x: os.path.getmtime(os.path.join(dropbox,x)))
42  #print 'sorted files ',files
43  lastRaw = files[-1]
44  lastRecordedRun = getRunnumberFromFileName(lastRaw)
45 
46  print 'Last lumi file produced: ', lastRaw +', Run: ', lastRecordedRun
47 
48  # if yes, fill a list with the runs yet to be uploaded
49  runsToBeAnalyzed = {}
50  if lastRecordedRun != lastAnalyzedRunNumber:
51  for file in files:
52  if len(file.split('_'))!=7: continue
53  thisrun=getRunnumberFromFileName(file)
54  #print 'this run ',thisrun
55  if thisrun>lastAnalyzedRunNumber and isCollisionRun(str(thisrun),authpath):
56  runsToBeAnalyzed[str(thisrun)] = file
57  return runsToBeAnalyzed
58 
59 import os, sys
60 from RecoLuminosity.LumiDB import argparse
61 def main():
62  parser = argparse.ArgumentParser(prog=os.path.basename(sys.argv[0]),description="Lumi Data scan")
63  parser.add_argument('-c',dest='connect',action='store',required=True,help='connect string to lumiDB')
64  parser.add_argument('-d',dest='dropbox',action='store',required=True,help='location of the lumi root files')
65  parser.add_argument('-P',dest='authpath',action='store',required=False,help='auth path')
66  parser.add_argument('-L',dest='logpath',action='store',required=False,help='log path')
67  parser.add_argument('-f',dest='loaderconf',action='store',required=True,help='path to loder config file')
68  args=parser.parse_args()
69  if args.authpath:
70  lumiauthpath=args.authpath
71  if args.logpath:
72  lumilogpath=args.logpath
73  loaderconf=args.loaderconf
74  runsToBeAnalyzed = getRunsToBeUploaded(args.connect, args.dropbox,lumiauthpath)
75 
76  runCounter=0
77  rs=runsToBeAnalyzed.keys()
78  rs.sort()
79  for run in rs:
80  runCounter+=1
81  if runCounter==1: print 'List of processed runs: '
82  print 'Run: ', run, ' file: ', runsToBeAnalyzed[run]
83  logFile=open(os.path.join(lumilogpath,'loadDB_run'+run+'.log'),'w',0)
84 
85  # filling the DB
86  command = '$LOCALRT/test/$SCRAM_ARCH/cmmdLoadLumiDB -r '+run+' -L "file:'+runsToBeAnalyzed[run]+'"'+' -f '+loaderconf+' --debug'
87  statusAndOutput = commands.getstatusoutput(command)
88  logFile.write(command+'\n')
89  logFile.write(statusAndOutput[1])
90  if not statusAndOutput[0] == 0:
91  print 'ERROR while loading info onto DB for run ' + run
92  print statusAndOutput[1]
93 
94  selectstring='"{'+run+':[]}"'
95  command = 'lumiValidate.py -c '+args.connect+' -P '+ lumiauthpath+' -runls '+selectstring+' update'
96  statusAndOutput = commands.getstatusoutput(command)
97  logFile.write(command+'\n')
98  logFile.write(statusAndOutput[1])
99  logFile.close()
100  if not statusAndOutput[0] == 0:
101  print 'ERROR while applying normalization to run '+ run
102  print statusAndOutput[1]
103 
104  if runCounter == 0: print 'No runs to be analyzed'
105 
106 if __name__=='__main__':
107  main()
def isCollisionRun
Definition: lumiDBFiller.py:8
def getRunsToBeUploaded
Definition: lumiDBFiller.py:29
tuple filter
USE THIS FOR SKIMMED TRACKS process.p = cms.Path(process.hltLevel1GTSeed*process.skimming*process.offlineBeamSpot*process.TrackRefitter2) OTHERWISE USE THIS.
Definition: align_tpl.py:86
def getRunnumberFromFileName
Definition: lumiDBFiller.py:25
double split
Definition: MVATrainer.cc:139