ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/parseCrabFjr.py
(Generate patch)

Comparing COMP/CRAB/python/parseCrabFjr.py (file contents):
Revision 1.13 by farinafa, Wed Jun 18 08:32:02 2008 UTC vs.
Revision 1.16 by spiga, Wed Mar 23 10:48:39 2011 UTC

# Line 1 | Line 1
1   #!/usr/bin/env python
2  
3 < import sys, getopt, string
3 > import sys, getopt, string, os
4  
5   from ProdCommon.FwkJobRep.ReportParser import readJobReport
6   from DashboardAPI import apmonSend, apmonFree
# Line 23 | Line 23 | class parseFjr:
23          self.lfnList = False  
24          self.debug = 0
25          try:
26 <            opts, args = getopt.getopt(argv, "", ["input=", "dashboard=", "exitcode", "lfn" , "debug", "help"])
26 >            opts, args = getopt.getopt(argv, "", ["input=", "dashboard=", "exitcode", "lfn" , "debug", "popularity=", "help"])
27          except getopt.GetoptError:
28              print self.usage()
29              sys.exit(2)
# Line 43 | Line 43 | class parseFjr:
43                  self.exitCode = True
44              elif opt == "--lfn":
45                  self.lfnList = True
46 +            elif opt == "--popularity":
47 +                self.popularity = True
48 +                try:
49 +                   self.MonitorID = arg.split(",")[0]
50 +                   self.MonitorJobID = arg.split(",")[1]
51 +                   self.inputInfos = arg.split(",")[2]
52 +                except:
53 +                   self.MonitorID = ''
54 +                   self.MonitorJobID = ''
55 +                   self.inputInfos = ''
56              elif opt == "--dashboard":
57                  self.info2dash = True
58                  try:
# Line 54 | Line 64 | class parseFjr:
64              elif opt == "--debug" :
65                  self.debug = 1
66                  
67 <        if self.input == '' or (not self.info2dash and not self.lfnList and not self.exitCode)  :
67 >        if self.input == '' or (not self.info2dash and not self.lfnList and not self.exitCode and not self.popularity)  :
68              print self.usage()
69              sys.exit()
70          
# Line 67 | Line 77 | class parseFjr:
77      def run(self):
78  
79          # load FwkJobRep
80 <        jobReport = readJobReport(self.input)[0]
80 >        try:
81 >            jobReport = readJobReport(self.input)[0]
82 >        except:
83 >            print '50115'
84 >            sys.exit()
85 >            
86          if self.exitCode :
87              self.exitCodes(jobReport)
88          if self.lfnList :
89             self.lfn_List(jobReport)
90          if self.info2dash :
91             self.reportDash(jobReport)
92 +        if self.popularity:
93 +           self.popularityInfos(jobReport)
94          return
95  
96      def exitCodes(self, jobReport):
# Line 198 | Line 215 | class parseFjr:
215              print throughput_report
216          return storage_report, throughput_report
217  
218 +    def popularityInfos(self, jobReport):
219 +        report_dict = {}
220 +        inputList = []
221 +        inputParentList = []                        
222 +        report_dict['inputBlocks'] = ''
223 +        if (os.path.exists(self.inputInfos)):
224 +            file=open(self.inputInfos,'r')
225 +            lines = file.readlines()
226 +            for line in lines:
227 +                if line.find("inputBlocks")>=0:
228 +                    report_dict['inputBlocks']= line.split("=")[1].strip()
229 +                if line.find("inputFiles")>=0:
230 +                    inputList = line.split("=")[1].strip().split(";")
231 +                if line.find("parentFiles")>=0:
232 +                    inputParentList = line.split("=")[1].strip().split(";")
233 +            file.close()
234 +        basename = ''
235 +        if len(inputList):
236 +            basename = os.path.commonprefix(inputList)
237 +        basenameParent = ''
238 +        if len(inputParentList):
239 +            basenameParent = os.path.commonprefix(inputParentList)
240 +
241 +        readFile = {}  
242 +
243 +        readFileParent = {}
244 +        for inputFile in  jobReport.inputFiles:
245 +            if inputFile['LFN'].find(basename) >=0:
246 +                fileAttr = (inputFile.get("FileType"), "Local", inputFile.get("Runs"))
247 +                readFile[inputFile.get("LFN").split(basename)[1]] = fileAttr
248 +            else:
249 +                fileParentAttr = (inputFile.get("FileType"), "Local", inputFile.get("Runs"))
250 +                readParentFile[inputFile.get("LFN").split(basenameParent)[1]] = fileParentAttr
251 +        cleanedinputList = []
252 +        for file in inputList:        
253 +            cleanedinputList.append(file.split(basename)[1])
254 +        cleanedParentList = []
255 +        for file in inputParentList:        
256 +            cleanedParentList.append(file.split(basenameParent)[1])
257 +
258 +        inputString = ''
259 +        LumisString = ''
260 +        for f,t in readFile.items():
261 +            cleanedinputList.remove(f)    
262 +            inputString += '%s::%d::%s::%s;'%(f,1,t[0],t[1])
263 +            LumisString += '%s::%s;'%(t[2].keys()[0],t[2].values()[0])  
264 +
265 +        inputParentString = ''
266 +        LumisParentString  = ''
267 +        for fp,tp in readFileParent.items():
268 +            cleanedParentList.remove(fp)    
269 +            inputParentString += '%s::%d::%s::%s;'%(fp,1,tp[0],tp[1])
270 +            LumisParentString += '%s::%s;'%(tp[2].keys()[0],tp[2].values()[0])  
271 +
272 +        if len(cleanedinputList):
273 +           for file in cleanedinputList :
274 +               if len(jobReport.errors):
275 +                   if jobReport.errors[0]["Description"].find(file) >= 0:
276 +                       inputString += '%s::%d::%s::%s;'%(file,0,'Unknown','Local')
277 +                   else:
278 +                       inputString += '%s::%d::%s::%s;'%(file,2,'Unknown','Unknown')
279 +               else:
280 +                   inputString += '%s::%d::%s::%s;'%(file,2,'Unknown','Unknown')
281 +
282 +        if len(cleanedParentList):
283 +           for file in cleanedParentList :
284 +               if len(jobReport.errors):
285 +                   if jobReport.errors[0]["Description"].find(file) >= 0:
286 +                       inputString += '%s::%d::%s::%s;'%(file,0,'Unknown','Local')
287 +                   else:
288 +                       inputString += '%s::%d::%s::%s;'%(file,2,'Unknown','Unknown')
289 +               else:
290 +                   inputParentString += '%s::%d::%s::%s;'%(file,2,'Unknown','Unknown')
291 +
292 +        report_dict['inputFiles']= inputString
293 +        report_dict['parentFIles']= inputParentString
294 +        report_dict['lumisRange']= LumisString
295 +        report_dict['lumisParentRange']= LumisParentString
296 +        report_dict['Basename']= basename
297 +        report_dict['BasenameParent']= basenameParent
298 +
299 +         # send to DashBoard
300 +        apmonSend(self.MonitorID, self.MonitorJobID, report_dict)
301 +        apmonFree()
302 +
303 +        if self.debug == 1 :
304 +            for k,v in report_dict.items():
305 +                print "%s : %s"%(k,v)
306 +        return  
307 +
308      def n_of_events(self,jobReport):
309          '''
310          #Brian's patch to sent number of events procedded to the Dashboard

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines