5 |
|
from crab_util import * |
6 |
|
from crab_logger import Logger |
7 |
|
from crab_exceptions import * |
8 |
< |
from FwkJobRep.ReportParser import readJobReport |
8 |
> |
from ProdCommon.FwkJobRep.ReportParser import readJobReport |
9 |
> |
from ProdCommon.FwkJobRep.ReportState import checkSuccess |
10 |
|
from ProdCommon.MCPayloads.WorkflowSpec import WorkflowSpec |
11 |
|
from ProdCommon.DataMgmt.DBS.DBSWriter import DBSWriter |
12 |
|
from ProdCommon.DataMgmt.DBS.DBSErrors import DBSWriterError, formatEx,DBSReaderError |
25 |
|
""" |
26 |
|
|
27 |
|
try: |
28 |
< |
self.processedData = cfg_params['USER.publish_data_name'] |
28 |
> |
self.userprocessedData = cfg_params['USER.publish_data_name'] |
29 |
> |
self.processedData = None |
30 |
|
except KeyError: |
31 |
|
raise CrabException('Cannot publish output data, because you did not specify USER.publish_data_name parameter in the crab.cfg file') |
32 |
+ |
|
33 |
|
try: |
34 |
|
if (int(cfg_params['USER.copy_data']) != 1): raise KeyError |
35 |
|
except KeyError: |
44 |
|
self.globalDBS="http://cmsdbsprod.cern.ch/cms_dbs_prod_global/servlet/DBSServlet" |
45 |
|
try: |
46 |
|
self.DBSURL=cfg_params['USER.dbs_url_for_publication'] |
47 |
< |
common.logger.message('dbs url = '+self.DBSURL) |
48 |
< |
if (self.DBSURL == "http://cmsdbsprod.cern.ch/cms_dbs_prod_global/servlet/DBSServlet"): |
47 |
> |
common.logger.message('<dbs_url_for_publication> = '+self.DBSURL) |
48 |
> |
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"): |
49 |
|
msg = "You can not publish your data in the globalDBS = " + self.DBSURL + "\n" |
50 |
|
msg = msg + "Please write your local one in the [USER] section 'dbs_url_for_publication'" |
51 |
|
raise CrabException(msg) |
52 |
|
except KeyError: |
53 |
< |
msg = "Error. The [USER] section does not have 'dbs_url_for_publication'" |
54 |
< |
msg = msg + " entry, necessary to publish the data" |
53 |
> |
msg = "Warning. The [USER] section does not have 'dbs_url_for_publication'" |
54 |
> |
msg = msg + " entry, necessary to publish the data.\n" |
55 |
> |
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." |
56 |
|
raise CrabException(msg) |
57 |
|
|
58 |
|
self.content=file(self.pset).read() |
59 |
|
self.resDir = common.work_space.resDir() |
60 |
+ |
|
61 |
+ |
self.dataset_to_import=[] |
62 |
+ |
|
63 |
|
self.datasetpath=cfg_params['CMSSW.datasetpath'] |
64 |
+ |
if (self.datasetpath.upper() != 'NONE'): |
65 |
+ |
self.dataset_to_import.append(self.datasetpath) |
66 |
+ |
|
67 |
+ |
### Added PU dataset |
68 |
+ |
tmp = cfg_params.get('CMSSW.dataset_pu',None) |
69 |
+ |
if tmp : |
70 |
+ |
datasets = tmp.split(',') |
71 |
+ |
for dataset in datasets: |
72 |
+ |
dataset=string.strip(dataset) |
73 |
+ |
self.dataset_to_import.append(dataset) |
74 |
+ |
### |
75 |
+ |
|
76 |
|
self.SEName='' |
77 |
|
self.CMSSW_VERSION='' |
78 |
|
self.exit_status='' |
87 |
|
dbsWriter = DBSWriter(self.DBSURL,level='ERROR') |
88 |
|
|
89 |
|
try: |
90 |
< |
dbsWriter.importDataset(globalDBS, self.datasetpath, self.DBSURL) |
90 |
> |
dbsWriter.importDatasetWithoutParentage(globalDBS, self.datasetpath, self.DBSURL) |
91 |
|
except DBSWriterError, ex: |
92 |
|
msg = "Error importing dataset to be processed into local DBS\n" |
93 |
|
msg += "Source Dataset: %s\n" % datasetpath |
108 |
|
msg = "Error: Problem with "+file+" file" |
109 |
|
common.logger.message(msg) |
110 |
|
return self.exit_status |
111 |
< |
|
112 |
< |
if (self.datasetpath != 'None'): |
113 |
< |
common.logger.message("--->>> Importing parent dataset in the dbs") |
114 |
< |
status_import=self.importParentDataset(self.globalDBS, self.datasetpath) |
115 |
< |
if (status_import == 1): |
116 |
< |
common.logger.message('Problem with parent import from the global DBS '+self.globalDBS+ 'to the local one '+self.DBSURL) |
117 |
< |
self.exit_status='1' |
118 |
< |
return self.exit_status |
119 |
< |
common.logger.message("Parent import ok") |
111 |
> |
|
112 |
> |
if (len(self.dataset_to_import) != 0): |
113 |
> |
for dataset in self.dataset_to_import: |
114 |
> |
common.logger.message("--->>> Importing parent dataset in the dbs: " +dataset) |
115 |
> |
status_import=self.importParentDataset(self.globalDBS, dataset) |
116 |
> |
if (status_import == 1): |
117 |
> |
common.logger.message('Problem with parent '+ dataset +' import from the global DBS '+self.globalDBS+ 'to the local one '+self.DBSURL) |
118 |
> |
self.exit_status='1' |
119 |
> |
return self.exit_status |
120 |
> |
else: |
121 |
> |
common.logger.message('Import ok of dataset '+dataset) |
122 |
|
|
123 |
|
#// DBS to contact |
124 |
|
dbswriter = DBSWriter(self.DBSURL) |
134 |
|
datasets=fileinfo.dataset |
135 |
|
common.logger.debug(6,"FileInfo = " + str(fileinfo)) |
136 |
|
common.logger.debug(6,"DatasetInfo = " + str(datasets)) |
137 |
+ |
if len(datasets)<=0: |
138 |
+ |
self.exit_status = '1' |
139 |
+ |
msg = "Error: No info about dataset in the xml file "+file |
140 |
+ |
common.logger.message(msg) |
141 |
+ |
return self.exit_status |
142 |
|
for dataset in datasets: |
143 |
+ |
#### for production data |
144 |
+ |
self.processedData = dataset['ProcessedDataset'] |
145 |
+ |
if (dataset['PrimaryDataset'] == 'null'): |
146 |
+ |
#dataset['PrimaryDataset'] = dataset['ProcessedDataset'] |
147 |
+ |
dataset['PrimaryDataset'] = self.userprocessedData |
148 |
+ |
#else: # add parentage from input dataset |
149 |
+ |
elif self.datasetpath.upper() != 'NONE': |
150 |
+ |
dataset['ParentDataset']= self.datasetpath |
151 |
+ |
|
152 |
|
dataset['PSetContent']=self.content |
118 |
– |
#cfgMeta = {'name' : 'usercfg' , 'Type' : 'user' , 'annotation': 'user cfg', 'version' : 'private version'} # add real name of user cfg |
153 |
|
cfgMeta = {'name' : self.pset , 'Type' : 'user' , 'annotation': 'user cfg', 'version' : 'private version'} # add real name of user cfg |
154 |
|
common.logger.message("PrimaryDataset = %s"%dataset['PrimaryDataset']) |
155 |
|
common.logger.message("ProcessedDataset = %s"%dataset['ProcessedDataset']) |
156 |
< |
common.logger.message("--->>> Inserting primary: %s processed : %s"%(dataset['PrimaryDataset'],dataset['ProcessedDataset'])) |
156 |
> |
common.logger.message("<User Dataset Name> = /"+dataset['PrimaryDataset']+"/"+dataset['ProcessedDataset']+"/USER") |
157 |
> |
|
158 |
> |
common.logger.debug(6,"--->>> Inserting primary: %s processed : %s"%(dataset['PrimaryDataset'],dataset['ProcessedDataset'])) |
159 |
|
|
160 |
|
primary = DBSWriterObjects.createPrimaryDataset( dataset, dbswriter.dbs) |
161 |
|
common.logger.debug(6,"Primary: %s "%primary) |
166 |
|
processed = DBSWriterObjects.createProcessedDataset(primary, algo, dataset, dbswriter.dbs) |
167 |
|
common.logger.debug(6,"Processed: %s "%processed) |
168 |
|
|
169 |
< |
common.logger.message("Inserted primary %s processed %s"%(primary,processed)) |
169 |
> |
common.logger.debug(6,"Inserted primary %s processed %s"%(primary,processed)) |
170 |
|
|
171 |
|
common.logger.debug(6,"exit_status = %s "%self.exit_status) |
172 |
|
return self.exit_status |
194 |
|
self.noLFN.append(file['PFN']) |
195 |
|
else: |
196 |
|
if int(file['TotalEvents']) != 0 : |
197 |
< |
file.lumisections = {} |
197 |
> |
#file.lumisections = {} |
198 |
> |
# lumi info are now in run hash |
199 |
> |
file.runs = {} |
200 |
|
for ds in file.dataset: |
201 |
< |
ds['ProcessedDataset']=procdataset |
201 |
> |
### Fede for production |
202 |
> |
if (ds['PrimaryDataset'] == 'null'): |
203 |
> |
#ds['PrimaryDataset']=procdataset |
204 |
> |
ds['PrimaryDataset']=self.userprocessedData |
205 |
|
filestopublish.append(file) |
206 |
|
else: |
207 |
|
self.noEventsFiles.append(file['LFN']) |
216 |
|
Blocks=None |
217 |
|
try: |
218 |
|
Blocks=dbswriter.insertFiles(jobReport) |
219 |
< |
common.logger.message("Blocks = %s"%Blocks) |
219 |
> |
common.logger.message("Inserting file in blocks = %s"%Blocks) |
220 |
|
except DBSWriterError, ex: |
221 |
< |
common.logger.message("Insert file error: %s"%ex) |
221 |
> |
common.logger.error("Insert file error: %s"%ex) |
222 |
|
return Blocks |
223 |
|
|
224 |
|
def run(self): |
227 |
|
""" |
228 |
|
|
229 |
|
file_list = glob.glob(self.resDir+"crab_fjr*.xml") |
230 |
+ |
## Select only those fjr that are succesfull |
231 |
+ |
good_list=[] |
232 |
+ |
for fjr in file_list: |
233 |
+ |
reports = readJobReport(fjr) |
234 |
+ |
if len(reports)>0: |
235 |
+ |
if reports[0].status == "Success": |
236 |
+ |
good_list.append(fjr) |
237 |
+ |
file_list=good_list |
238 |
+ |
## |
239 |
|
common.logger.debug(6, "file_list = "+str(file_list)) |
240 |
|
common.logger.debug(6, "len(file_list) = "+str(len(file_list))) |
241 |
|
|
250 |
|
|
251 |
|
common.logger.message("--->>> Start files publication") |
252 |
|
for file in file_list: |
253 |
< |
common.logger.message("file = "+file) |
253 |
> |
common.logger.debug(1, "file = "+file) |
254 |
|
Blocks=self.publishAJobReport(file,self.processedData) |
255 |
|
if Blocks: |
256 |
< |
[BlocksList.append(x) for x in Blocks] |
256 |
> |
for x in Blocks: # do not allow multiple entries of the same block |
257 |
> |
if x not in BlocksList: |
258 |
> |
BlocksList.append(x) |
259 |
|
|
260 |
|
# close the blocks |
261 |
< |
common.logger.message("BlocksList = %s"%BlocksList) |
261 |
> |
common.logger.debug(6, "BlocksList = %s"%BlocksList) |
262 |
|
# dbswriter = DBSWriter(self.DBSURL,level='ERROR') |
263 |
|
dbswriter = DBSWriter(self.DBSURL) |
264 |
|
|
265 |
|
for BlockName in BlocksList: |
266 |
|
try: |
267 |
|
closeBlock=dbswriter.manageFileBlock(BlockName,maxFiles= 1) |
268 |
< |
common.logger.message("closeBlock %s"%closeBlock) |
268 |
> |
common.logger.debug(6, "closeBlock %s"%closeBlock) |
269 |
|
#dbswriter.dbs.closeBlock(BlockName) |
270 |
|
except DBSWriterError, ex: |
271 |
|
common.logger.message("Close block error %s"%ex) |
272 |
|
|
221 |
– |
common.logger.message("--->>> End files publication") |
273 |
|
if (len(self.noEventsFiles)>0): |
274 |
|
common.logger.message("--->>> WARNING: "+str(len(self.noEventsFiles))+" files not published because they contain 0 events are:") |
275 |
|
for lfn in self.noEventsFiles: |
282 |
|
common.logger.message("--->>> WARNING: "+str(len(self.problemFiles))+" files not published because they had problem with copy to SE") |
283 |
|
for lfn in self.problemFiles: |
284 |
|
common.logger.message("------ LFN: %s"%lfn) |
285 |
+ |
common.logger.message("--->>> End files publication") |
286 |
+ |
common.logger.message("--->>> To check data publication please use: InspectDBS2.py --DBSURL=<dbs_url_for_publication> --datasetPath=<User Dataset Name>") |
287 |
|
return self.exit_status |
288 |
|
|
289 |
|
else: |