ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/Reporter.py
Revision: 1.17
Committed: Tue Jun 29 17:46:42 2010 UTC (14 years, 10 months ago) by ewv
Content type: text/x-python
Branch: MAIN
CVS Tags: CRAB_2_7_4_pre2, CRAB_2_7_4_pre1
Changes since 1.16: +4 -1 lines
Log Message:
Grab LumiList from CMSSW libraries for CMSSW 3.8 and higher

File Contents

# Content
1 import os, common, string
2 from Actor import *
3 from crab_util import *
4 from ProdCommon.FwkJobRep.ReportParser import readJobReport
5 try: # Can remove when CMSSW 3.7 and earlier are dropped
6 from FWCore.PythonUtilities.LumiList import LumiList
7 except ImportError:
8 from LumiList import LumiList
9
10 try: # FUTURE: Python 2.6, prior to 2.6 requires simplejson
11 import json
12 except:
13 import simplejson as json
14
15
16 class Reporter(Actor):
17 """ A class to report a short summary of the info of a task, including what
18 is needed for user analysis, such as #events requestes/done, integrated
19 lumi and so one.
20 """
21 def __init__(self, cfg_params):
22 self.cfg_params = cfg_params
23 self.fjrDirectory = cfg_params.get('USER.outputdir' ,
24 common.work_space.resDir()) + '/'
25 return
26
27 def run(self):
28 """
29 The main method of the class: report status of a task
30 """
31 common.logger.debug( "Reporter::run() called")
32 task = common._db.getTask()
33
34 msg= "--------------------\n"
35 msg += "Dataset: %s\n"%str(task['dataset'])
36 if self.cfg_params.has_key('USER.copy_data') and int(self.cfg_params['USER.copy_data'])==1:
37 msg+= "Remote output :\n"
38 ## TODO: SL should come from jobDB!
39 from PhEDExDatasvcInfo import PhEDExDatasvcInfo
40
41 stageout = PhEDExDatasvcInfo(self.cfg_params)
42 endpoint, lfn, SE, SE_PATH, user = stageout.getEndpoint()
43 #print endpoint, lfn, SE, SE_PATH, user
44
45 msg+= "SE: %s %s srmPath: %s\n"%(self.cfg_params['USER.storage_element'],SE,endpoint)
46
47 else:
48 msg += "Local output: %s\n" % task['outputDirectory']
49 #print task
50 possible_status = [ 'Created',
51 'Undefined',
52 'Submitting',
53 'Submitted',
54 'NotSubmitted',
55 'Waiting',
56 'Ready',
57 'Scheduled',
58 'Running',
59 'Done',
60 'Killing',
61 'Killed',
62 'Aborted',
63 'Unknown',
64 'Done (Failed)',
65 'Cleared',
66 'Retrieved'
67 ]
68 eventsRead=0
69 eventsRequired=0
70 filesRead=0
71 filesRequired=0
72 lumis = []
73 for job in task.getJobs():
74 if (job.runningJob['applicationReturnCode']>0 or job.runningJob['wrapperReturnCode']>0): continue
75 # get FJR filename
76 fjr = self.fjrDirectory + job['outputFiles'][-1]
77
78 jobReport = readJobReport(fjr)
79 if len(jobReport) > 0:
80 inputFiles = jobReport[0].inputFiles
81 for inputFile in inputFiles:
82 # Accumulate the list of lum sections run over
83 for run in inputFile.runs.keys():
84 for lumi in inputFile.runs[run]:
85 lumis.append((run, lumi))
86 filesRead+=1
87 eventsRead+=int(inputFile['EventsRead'])
88 #print jobReport[0].inputFiles,'\n'
89 else:
90 pass
91 #print 'no FJR avaialble for job #%s'%job['jobId']
92 #print "--------------------------"
93
94 # Compact and write the list of successful lumis
95
96 lumiList = LumiList(lumis = lumis)
97 compactList = lumiList.getCompactList()
98
99 lumiFilename = task['outputDirectory'] + 'lumiSummary.json'
100 lumiSummary = open(lumiFilename, 'w')
101 json.dump(compactList, lumiSummary)
102 lumiSummary.write('\n')
103 lumiSummary.close()
104
105 msg += "Total Events read: %s\n" % eventsRead
106 msg += "Total Files read: %s\n" % filesRead
107 msg += "Total Jobs : %s\n" % len(task.getJobs())
108 msg += "Luminosity section summary file: %s\n" % lumiFilename
109 list_ID={}
110
111 # TEMPORARY by Fabio, to be removed
112 # avoid clashes between glite_slc5 and glite schedulers when a server is used
113 # otherwise, -report with a server requires a local scheduler
114 if self.cfg_params.get('CRAB.server_name', None) is None:
115 common.logger.debug( "Reporter updating task status")
116 task = common.scheduler.queryEverything(task['id'])
117
118 for st in possible_status:
119 list_ID = common._db.queryAttrRunJob({'statusScheduler':st},'jobId')
120 if (len(list_ID)>0):
121 msg+= " # Jobs: %s:%s\n"%(str(st),len(list_ID))
122 pass
123 msg+= "\n----------------------------\n"
124 common.logger.info(msg)
125 return
126
127