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.17 by spiga, Wed Mar 23 16:48:53 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 +        if len(inputList) == 1 and inputList[0] == '':
235 +            inputList=[]
236 +        if len(inputParentList) == 1 and inputParentList[0] == '':
237 +            inputParentList=[]
238 +        basename = ''
239 +        if len(inputList) > 1:
240 +            basename = os.path.commonprefix(inputList)
241 +        elif len(inputList) == 1:
242 +            basename =  "%s/"%os.path.dirname(inputList[0])
243 +        basenameParent = ''
244 +        if len(inputParentList) > 1:
245 +            basenameParent = os.path.commonprefix(inputParentList)
246 +        elif len(inputParentList) == 1:
247 +            basenameParent = "%s/"%os.path.dirname(inputParentList[0])
248 +
249 +        readFile = {}  
250 +
251 +        readFileParent = {}
252 +        fileAttr = []
253 +        fileParentAttr = []
254 +        for inputFile in  jobReport.inputFiles:
255 +            if inputFile['LFN'].find(basename) >=0:
256 +                fileAttr = (inputFile.get("FileType"), "Local", inputFile.get("Runs"))
257 +                readFile[inputFile.get("LFN").split(basename)[1]] = fileAttr
258 +            else:
259 +                fileParentAttr = (inputFile.get("FileType"), "Local", inputFile.get("Runs"))
260 +                readParentFile[inputFile.get("LFN").split(basenameParent)[1]] = fileParentAttr
261 +        cleanedinputList = []
262 +        for file in inputList:        
263 +            cleanedinputList.append(file.split(basename)[1])
264 +        cleanedParentList = []
265 +        for file in inputParentList:        
266 +            cleanedParentList.append(file.split(basenameParent)[1])
267 +
268 +        inputString = ''
269 +        LumisString = ''
270 +        for f,t in readFile.items():
271 +            cleanedinputList.remove(f)    
272 +            inputString += '%s::%d::%s::%s;'%(f,1,t[0],t[1])
273 +            LumisString += '%s::%s;'%(t[2].keys()[0],t[2].values()[0])  
274 +
275 +        inputParentString = ''
276 +        LumisParentString  = ''
277 +        for fp,tp in readFileParent.items():
278 +            cleanedParentList.remove(fp)    
279 +            inputParentString += '%s::%d::%s::%s;'%(fp,1,tp[0],tp[1])
280 +            LumisParentString += '%s::%s;'%(tp[2].keys()[0],tp[2].values()[0])  
281 +
282 +        if len(cleanedinputList):
283 +           for file in cleanedinputList :
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 +                   inputString += '%s::%d::%s::%s;'%(file,2,'Unknown','Unknown')
291 +
292 +        if len(cleanedParentList):
293 +           for file in cleanedParentList :
294 +               if len(jobReport.errors):
295 +                   if jobReport.errors[0]["Description"].find(file) >= 0:
296 +                       inputString += '%s::%d::%s::%s;'%(file,0,'Unknown','Local')
297 +                   else:
298 +                       inputString += '%s::%d::%s::%s;'%(file,2,'Unknown','Unknown')
299 +               else:
300 +                   inputParentString += '%s::%d::%s::%s;'%(file,2,'Unknown','Unknown')
301 +
302 +        report_dict['inputFiles']= inputString
303 +        report_dict['parentFIles']= inputParentString
304 +        report_dict['lumisRange']= LumisString
305 +        report_dict['lumisParentRange']= LumisParentString
306 +        report_dict['Basename']= basename
307 +        report_dict['BasenameParent']= basenameParent
308 +
309 +         # send to DashBoard
310 +        apmonSend(self.MonitorID, self.MonitorJobID, report_dict)
311 +        apmonFree()
312 +
313 +       # if self.debug == 1 :
314 +        print "Popularity start"
315 +        for k,v in report_dict.items():
316 +            print "%s : %s"%(k,v)
317 +        print "Popularity stop"
318 +        return  
319 +
320      def n_of_events(self,jobReport):
321          '''
322          #Brian's patch to sent number of events procedded to the Dashboard

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines