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

Comparing COMP/CRAB/python/Publisher.py (file contents):
Revision 1.7 by fanzago, Tue Dec 18 10:58:20 2007 UTC vs.
Revision 1.30 by slacapra, Wed Jun 10 11:40:03 2009 UTC

# Line 3 | Line 3 | import common
3   import time, glob
4   from Actor import *
5   from crab_util import *
6 from crab_logger import Logger
6   from crab_exceptions import *
7 < from FwkJobRep.ReportParser import readJobReport
7 > from ProdCommon.FwkJobRep.ReportParser import readJobReport
8 > from ProdCommon.FwkJobRep.ReportState import checkSuccess
9   from ProdCommon.MCPayloads.WorkflowSpec import WorkflowSpec
10   from ProdCommon.DataMgmt.DBS.DBSWriter import DBSWriter
11   from ProdCommon.DataMgmt.DBS.DBSErrors import DBSWriterError, formatEx,DBSReaderError
# Line 23 | Line 23 | class Publisher(Actor):
23          - publishes output data on DBS and DLS
24          """
25  
26 +        self.cfg_params=cfg_params
27 +      
28          try:
29 <            self.processedData = cfg_params['USER.publish_data_name']
28 <        except KeyError:
29 >        if not cfg_params.has_key('USER.publish_data_name')
30              raise CrabException('Cannot publish output data, because you did not specify USER.publish_data_name parameter in the crab.cfg file')
31 <        try:
32 <            if (int(cfg_params['USER.copy_data']) != 1): raise KeyError
33 <        except KeyError:
34 <            raise CrabException('You can not publish data because you did not selected *** copy_data = 1  *** in the crab.cfg file')
35 <        try:
36 <            self.pset = cfg_params['CMSSW.pset']
37 <        except KeyError:
38 <            raise CrabException('Cannot publish output data, because you did not specify the psetname in [CMSSW] of your crab.cfg file')
39 <        try:
40 <            self.globalDBS=cfg_params['CMSSW.dbs_url']
41 <        except KeyError:
42 <            self.globalDBS="http://cmsdbsprod.cern.ch/cms_dbs_prod_global/servlet/DBSServlet"
43 <        try:
44 <            self.DBSURL=cfg_params['USER.dbs_url_for_publication']
45 <            common.logger.message('<dbs_url_for_publication> = '+self.DBSURL)
46 <            if (self.DBSURL == "http://cmsdbsprod.cern.ch/cms_dbs_prod_global/servlet/DBSServlet") or (self.DBSURL == "https://cmsdbsprod.cern.ch:8443/cms_dbs_prod_global_writer/servlet/DBSServlet"):
47 <                msg = "You can not publish your data in the globalDBS = " + self.DBSURL + "\n"
48 <                msg = msg + "Please write your local one in the [USER] section 'dbs_url_for_publication'"
49 <                raise CrabException(msg)
50 <        except KeyError:
51 <            msg = "Error. The [USER] section does not have 'dbs_url_for_publication'"
52 <            msg = msg + " entry, necessary to publish the data"
31 >        self.userprocessedData = cfg_params['USER.publish_data_name']
32 >        self.processedData = None
33 >
34 >        if (not cfg_params.has_key('USER.copy_data') or int(cfg_params['USER.copy_data']) != 1 ) or \
35 >            (not cfg_params.has_key('USER.publish_data') or int(cfg_params['USER.publish_data']) != 1 ):
36 >            msg  = 'You can not publish data because you did not selected \n'
37 >            msg += '\t*** copy_data = 1 or publish_data = 1  *** in the crab.cfg file'
38 >
39 >        # try:
40 >        #     self.pset = cfg_params['CMSSW.pset']
41 >        # except KeyError:
42 >        #     raise CrabException('Cannot publish output data, because you did not specify the psetname in [CMSSW] of your crab.cfg file')
43 >
44 >        self.globalDBS=cfg_params.get('CMSSW.dbs_url',"http://cmsdbsprod.cern.ch/cms_dbs_prod_global/servlet/DBSServlet")
45 >
46 >        if not cfg_params.has_key('USER.dbs_url_for_publication'):
47 >            msg = "Warning. The [USER] section does not have 'dbs_url_for_publication'"
48 >            msg = msg + " entry, necessary to publish the data.\n"
49 >            msg = msg + "Use the command **crab -publish -USER.dbs_url_for_publication=dbs_url_for_publication*** \nwhere dbs_url_for_publication is your local dbs instance."
50 >            raise CrabException(msg)
51 >
52 >        self.DBSURL=cfg_params['USER.dbs_url_for_publication']
53 >        common.logger.info('<dbs_url_for_publication> = '+self.DBSURL)
54 >        if (self.DBSURL == "http://cmsdbsprod.cern.ch/cms_dbs_prod_global/servlet/DBSServlet") or (self.DBSURL == "https://cmsdbsprod.cern.ch:8443/cms_dbs_prod_global_writer/servlet/DBSServlet"):
55 >            msg = "You can not publish your data in the globalDBS = " + self.DBSURL + "\n"
56 >            msg = msg + "Please write your local one in the [USER] section 'dbs_url_for_publication'"
57              raise CrabException(msg)
58              
59          self.content=file(self.pset).read()
60          self.resDir = common.work_space.resDir()
61 +        
62 +        self.dataset_to_import=[]
63 +        
64          self.datasetpath=cfg_params['CMSSW.datasetpath']
65 +        if (self.datasetpath.upper() != 'NONE'):
66 +            self.dataset_to_import.append(self.datasetpath)
67 +        
68 +        ### Added PU dataset
69 +        tmp = cfg_params.get('CMSSW.dataset_pu',None)
70 +        if tmp :
71 +            datasets = tmp.split(',')
72 +            for dataset in datasets:
73 +                dataset=string.strip(dataset)
74 +                self.dataset_to_import.append(dataset)
75 +        ###        
76 +            
77 +        self.skipOcheck=cfg_params.get('CMSSW.publish_zero_event',0)
78 +    
79          self.SEName=''
80          self.CMSSW_VERSION=''
81          self.exit_status=''
# Line 68 | Line 90 | class Publisher(Actor):
90          dbsWriter = DBSWriter(self.DBSURL,level='ERROR')
91          
92          try:
93 +            #dbsWriter.importDatasetWithoutParentage(globalDBS, self.datasetpath, self.DBSURL)
94              dbsWriter.importDataset(globalDBS, self.datasetpath, self.DBSURL)
95          except DBSWriterError, ex:
96              msg = "Error importing dataset to be processed into local DBS\n"
97              msg += "Source Dataset: %s\n" % datasetpath
98              msg += "Source DBS: %s\n" % globalDBS
99              msg += "Destination DBS: %s\n" % self.DBSURL
100 <            common.logger.message(msg)
100 >            common.logger.info(msg)
101 >            common.logger.debug(str(ex))
102              return 1
103          return 0
104            
# Line 87 | Line 111 | class Publisher(Actor):
111          except IndexError:
112              self.exit_status = '1'
113              msg = "Error: Problem with "+file+" file"  
114 <            common.logger.message(msg)
114 >            common.logger.info(msg)
115              return self.exit_status
116 <            
117 <        if (self.datasetpath != 'None'):
118 <            common.logger.message("--->>> Importing parent dataset in the dbs")
119 <            status_import=self.importParentDataset(self.globalDBS, self.datasetpath)
120 <            if (status_import == 1):
121 <                common.logger.message('Problem with parent import from the global DBS '+self.globalDBS+ 'to the local one '+self.DBSURL)
122 <                self.exit_status='1'
123 <                return self.exit_status
124 <            common.logger.message("Parent import ok")
116 >
117 >        if (len(self.dataset_to_import) != 0):
118 >           for dataset in self.dataset_to_import:
119 >               common.logger.info("--->>> Importing parent dataset in the dbs: " +dataset)
120 >               status_import=self.importParentDataset(self.globalDBS, dataset)
121 >               if (status_import == 1):
122 >                   common.logger.info('Problem with parent '+ dataset +' import from the global DBS '+self.globalDBS+ 'to the local one '+self.DBSURL)
123 >                   self.exit_status='1'
124 >                   return self.exit_status
125 >               else:    
126 >                   common.logger.info('Import ok of dataset '+dataset)
127              
128          #// DBS to contact
129          dbswriter = DBSWriter(self.DBSURL)                        
# Line 107 | Line 133 | class Publisher(Actor):
133          except IndexError:
134              self.exit_status = '1'
135              msg = "Error: No file to publish in xml file"+file+" file"  
136 <            common.logger.message(msg)
136 >            common.logger.info(msg)
137              return self.exit_status
138  
139          datasets=fileinfo.dataset
140 <        common.logger.debug(6,"FileInfo = " + str(fileinfo))
141 <        common.logger.debug(6,"DatasetInfo = " + str(datasets))
140 >        common.logger.log(10-1,"FileInfo = " + str(fileinfo))
141 >        common.logger.log(10-1,"DatasetInfo = " + str(datasets))
142 >        if len(datasets)<=0:
143 >           self.exit_status = '1'
144 >           msg = "Error: No info about dataset in the xml file "+file
145 >           common.logger.info(msg)
146 >           return self.exit_status
147          for dataset in datasets:
148              #### for production data
149 +            self.processedData = dataset['ProcessedDataset']
150              if (dataset['PrimaryDataset'] == 'null'):
151 <                dataset['PrimaryDataset'] = dataset['ProcessedDataset']
152 <                
151 >                #dataset['PrimaryDataset'] = dataset['ProcessedDataset']
152 >                dataset['PrimaryDataset'] = self.userprocessedData
153 >            #else: # add parentage from input dataset
154 >            elif self.datasetpath.upper() != 'NONE':
155 >                dataset['ParentDataset']= self.datasetpath
156 >    
157              dataset['PSetContent']=self.content
158              cfgMeta = {'name' : self.pset , 'Type' : 'user' , 'annotation': 'user cfg', 'version' : 'private version'} # add real name of user cfg
159 <            common.logger.message("PrimaryDataset = %s"%dataset['PrimaryDataset'])
160 <            common.logger.message("ProcessedDataset = %s"%dataset['ProcessedDataset'])
161 <            common.logger.message("<User Dataset Name> = /"+dataset['PrimaryDataset']+"/"+dataset['ProcessedDataset']+"/USER")
159 >            common.logger.info("PrimaryDataset = %s"%dataset['PrimaryDataset'])
160 >            common.logger.info("ProcessedDataset = %s"%dataset['ProcessedDataset'])
161 >            common.logger.info("<User Dataset Name> = /"+dataset['PrimaryDataset']+"/"+dataset['ProcessedDataset']+"/USER")
162 >            self.dataset_to_check="/"+dataset['PrimaryDataset']+"/"+dataset['ProcessedDataset']+"/USER"
163              
164 <            common.logger.debug(6,"--->>> Inserting primary: %s processed : %s"%(dataset['PrimaryDataset'],dataset['ProcessedDataset']))
164 >            common.logger.log(10-1,"--->>> Inserting primary: %s processed : %s"%(dataset['PrimaryDataset'],dataset['ProcessedDataset']))
165              
166              primary = DBSWriterObjects.createPrimaryDataset( dataset, dbswriter.dbs)
167 <            common.logger.debug(6,"Primary:  %s "%primary)
167 >            common.logger.log(10-1,"Primary:  %s "%primary)
168              
169              algo = DBSWriterObjects.createAlgorithm(dataset, cfgMeta, dbswriter.dbs)
170 <            common.logger.debug(6,"Algo:  %s "%algo)
170 >            common.logger.log(10-1,"Algo:  %s "%algo)
171  
172              processed = DBSWriterObjects.createProcessedDataset(primary, algo, dataset, dbswriter.dbs)
173 <            common.logger.debug(6,"Processed:  %s "%processed)
173 >            common.logger.log(10-1,"Processed:  %s "%processed)
174              
175 <            common.logger.debug(6,"Inserted primary %s processed %s"%(primary,processed))
175 >            common.logger.log(10-1,"Inserted primary %s processed %s"%(primary,processed))
176              
177 <        common.logger.debug(6,"exit_status = %s "%self.exit_status)
177 >        common.logger.log(10-1,"exit_status = %s "%self.exit_status)
178          return self.exit_status    
179  
180      def publishAJobReport(self,file,procdataset):
# Line 162 | Line 199 | class Publisher(Actor):
199              elif (file['LFN'] == ''):
200                  self.noLFN.append(file['PFN'])
201              else:
202 <                if int(file['TotalEvents']) != 0 :
203 <                    file.lumisections = {}
202 >                if  self.skipOcheck==0:
203 >                    if int(file['TotalEvents']) != 0:
204 >                        #file.lumisections = {}
205 >                        # lumi info are now in run hash
206 >                        file.runs = {}
207 >                        for ds in file.dataset:
208 >                            ### Fede for production
209 >                            if (ds['PrimaryDataset'] == 'null'):
210 >                                #ds['PrimaryDataset']=procdataset
211 >                                ds['PrimaryDataset']=self.userprocessedData
212 >                        filestopublish.append(file)
213 >                    else:
214 >                        self.noEventsFiles.append(file['LFN'])
215 >                else:
216 >                    file.runs = {}
217                      for ds in file.dataset:
168                        ds['ProcessedDataset']=procdataset
218                          ### Fede for production
219                          if (ds['PrimaryDataset'] == 'null'):
220 <                            ds['PrimaryDataset']=procdataset
220 >                            #ds['PrimaryDataset']=procdataset
221 >                            ds['PrimaryDataset']=self.userprocessedData
222                      filestopublish.append(file)
223 <                else:
174 <                    self.noEventsFiles.append(file['LFN'])
223 >      
224          jobReport.files = filestopublish
225          ### if all files of FJR have number of events = 0
226          if (len(filestopublish) == 0):
# Line 183 | Line 232 | class Publisher(Actor):
232          Blocks=None
233          try:
234              Blocks=dbswriter.insertFiles(jobReport)
235 <            common.logger.message("Blocks = %s"%Blocks)
235 >            common.logger.info("Inserting file in blocks = %s"%Blocks)
236          except DBSWriterError, ex:
237 <            common.logger.message("Insert file error: %s"%ex)
237 >            common.logger.info("Insert file error: %s"%ex)
238          return Blocks
239  
240      def run(self):
# Line 194 | Line 243 | class Publisher(Actor):
243          """
244          
245          file_list = glob.glob(self.resDir+"crab_fjr*.xml")
246 <        common.logger.debug(6, "file_list = "+str(file_list))
247 <        common.logger.debug(6, "len(file_list) = "+str(len(file_list)))
246 >        ## Select only those fjr that are succesfull
247 >        good_list=[]
248 >        for fjr in file_list:
249 >            reports = readJobReport(fjr)
250 >            if len(reports)>0:
251 >               if reports[0].status == "Success":
252 >                  good_list.append(fjr)
253 >        file_list=good_list
254 >        ##
255 >        common.logger.log(10-1, "file_list = "+str(file_list))
256 >        common.logger.log(10-1, "len(file_list) = "+str(len(file_list)))
257              
258          if (len(file_list)>0):
259              BlocksList=[]
260 <            common.logger.message("--->>> Start dataset publication")
260 >            common.logger.info("--->>> Start dataset publication")
261              self.exit_status=self.publishDataset(file_list[0])
262              if (self.exit_status == '1'):
263                  return self.exit_status
264 <            common.logger.message("--->>> End dataset publication")
264 >            common.logger.info("--->>> End dataset publication")
265  
266  
267 <            common.logger.message("--->>> Start files publication")
267 >            common.logger.info("--->>> Start files publication")
268              for file in file_list:
269 <                common.logger.message("file = "+file)
269 >                common.logger.debug( "file = "+file)
270                  Blocks=self.publishAJobReport(file,self.processedData)
271                  if Blocks:
272 <                    [BlocksList.append(x) for x in Blocks]
272 >                    for x in Blocks: # do not allow multiple entries of the same block
273 >                        if x not in BlocksList:
274 >                           BlocksList.append(x)
275                      
276              # close the blocks
277 <            common.logger.debug(6, "BlocksList = %s"%BlocksList)
277 >            common.logger.log(10-1, "BlocksList = %s"%BlocksList)
278              # dbswriter = DBSWriter(self.DBSURL,level='ERROR')
279              dbswriter = DBSWriter(self.DBSURL)
280              
281              for BlockName in BlocksList:
282                  try:  
283                      closeBlock=dbswriter.manageFileBlock(BlockName,maxFiles= 1)
284 <                    common.logger.debug(6, "closeBlock %s"%closeBlock)
284 >                    common.logger.log(10-1, "closeBlock %s"%closeBlock)
285                      #dbswriter.dbs.closeBlock(BlockName)
286                  except DBSWriterError, ex:
287 <                    common.logger.message("Close block error %s"%ex)
287 >                    common.logger.info("Close block error %s"%ex)
288  
289              if (len(self.noEventsFiles)>0):
290 <                common.logger.message("--->>> WARNING: "+str(len(self.noEventsFiles))+" files not published because they contain 0 events are:")
290 >                common.logger.info("--->>> WARNING: "+str(len(self.noEventsFiles))+" files not published because they contain 0 events are:")
291                  for lfn in self.noEventsFiles:
292 <                    common.logger.message("------ LFN: %s"%lfn)
292 >                    common.logger.info("------ LFN: %s"%lfn)
293              if (len(self.noLFN)>0):
294 <                common.logger.message("--->>> WARNING: there are "+str(len(self.noLFN))+" files not published because they have empty LFN")
294 >                common.logger.info("--->>> WARNING: there are "+str(len(self.noLFN))+" files not published because they have empty LFN")
295                  for pfn in self.noLFN:
296 <                    common.logger.message("------ pfn: %s"%pfn)
296 >                    common.logger.info("------ pfn: %s"%pfn)
297              if (len(self.problemFiles)>0):
298 <                common.logger.message("--->>> WARNING: "+str(len(self.problemFiles))+" files not published because they had problem with copy to SE")
298 >                common.logger.info("--->>> WARNING: "+str(len(self.problemFiles))+" files not published because they had problem with copy to SE")
299                  for lfn in self.problemFiles:
300 <                    common.logger.message("------ LFN: %s"%lfn)
301 <            common.logger.message("--->>> End files publication")
302 <            common.logger.message("--->>> To check data publication please use: InspectDBS2.py --DBSURL=<dbs_url_for_publication> --datasetPath=<User Dataset Name>")
300 >                    common.logger.info("------ LFN: %s"%lfn)
301 >            common.logger.info("--->>> End files publication")
302 >          
303 >            self.cfg_params['USER.dataset_to_check']=self.dataset_to_check
304 >            from InspectDBS import InspectDBS
305 >            check=InspectDBS(self.cfg_params)
306 >            check.checkPublication()
307              return self.exit_status
308  
309          else:
310 <            common.logger.message("--->>> "+self.resDir+" empty: no file to publish on DBS")
310 >            common.logger.info("--->>> "+self.resDir+" empty: no file to publish on DBS")
311              self.exit_status = '1'
312              return self.exit_status
313      

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines