8 |
|
from DBSAPI.dbsApiException import * |
9 |
|
import common |
10 |
|
from crab_util import * |
11 |
< |
from LumiList import LumiList |
11 |
> |
try: # Can remove when CMSSW 3.7 and earlier are dropped |
12 |
> |
from FWCore.PythonUtilities.LumiList import LumiList |
13 |
> |
except ImportError: |
14 |
> |
from LumiList import LumiList |
15 |
> |
|
16 |
|
import os |
17 |
|
|
18 |
|
|
107 |
|
self.parent = {} # DBS output: parents of each file |
108 |
|
self.lumis = {} # DBS output: lumis in each file |
109 |
|
self.lumiMask = None |
110 |
+ |
self.splitByLumi = False |
111 |
+ |
self.splitDataByEvent = 0 |
112 |
|
|
113 |
|
def fetchDBSInfo(self): |
114 |
|
""" |
116 |
|
""" |
117 |
|
## get DBS URL |
118 |
|
global_url="http://cmsdbsprod.cern.ch/cms_dbs_prod_global/servlet/DBSServlet" |
119 |
< |
caf_url = "http://cmsdbsprod.cern.ch/cms_dbs_caf_analysis_01/servlet/DBSServlet" |
114 |
< |
dbs_url_map = {'glite': global_url, |
115 |
< |
'glite_slc5':global_url,\ |
116 |
< |
'glitecoll':global_url,\ |
117 |
< |
'condor': global_url,\ |
118 |
< |
'condor_g': global_url,\ |
119 |
< |
'glidein': global_url,\ |
120 |
< |
'lsf': global_url,\ |
121 |
< |
'caf': caf_url,\ |
122 |
< |
'sge': global_url,\ |
123 |
< |
'arc': global_url,\ |
124 |
< |
'pbs': global_url |
125 |
< |
} |
126 |
< |
|
127 |
< |
dbs_url_default = dbs_url_map[(common.scheduler.name()).lower()] |
128 |
< |
dbs_url= self.cfg_params.get('CMSSW.dbs_url', dbs_url_default) |
119 |
> |
dbs_url= self.cfg_params.get('CMSSW.dbs_url', global_url) |
120 |
|
common.logger.info("Accessing DBS at: "+dbs_url) |
121 |
|
|
122 |
|
## check if runs are selected |
124 |
|
if (self.cfg_params.has_key('CMSSW.runselection')): |
125 |
|
runselection = parseRange2(self.cfg_params['CMSSW.runselection']) |
126 |
|
|
127 |
< |
## check if lumiMask is set |
127 |
> |
## check if various lumi parameters are set |
128 |
|
self.lumiMask = self.cfg_params.get('CMSSW.lumi_mask',None) |
129 |
+ |
self.lumiParams = self.cfg_params.get('CMSSW.total_number_of_lumis',None) or \ |
130 |
+ |
self.cfg_params.get('CMSSW.lumis_per_job',None) |
131 |
+ |
|
132 |
|
lumiList = None |
133 |
|
if self.lumiMask: |
134 |
|
lumiList = LumiList(filename=self.lumiMask) |
135 |
+ |
if runselection: |
136 |
+ |
runList = LumiList(runs = runselection) |
137 |
|
|
138 |
|
self.splitByRun = int(self.cfg_params.get('CMSSW.split_by_run', 0)) |
139 |
< |
|
139 |
> |
self.splitDataByEvent = int(self.cfg_params.get('CMSSW.split_by_event', 0)) |
140 |
|
common.logger.log(10-1,"runselection is: %s"%runselection) |
141 |
+ |
|
142 |
+ |
if not self.splitByRun: |
143 |
+ |
self.splitByLumi = self.lumiMask or self.lumiParams or self.ads |
144 |
+ |
|
145 |
+ |
if self.splitByRun and not runselection: |
146 |
+ |
msg = "Error: split_by_run must be combined with a runselection" |
147 |
+ |
raise CrabException(msg) |
148 |
+ |
|
149 |
|
## service API |
150 |
|
args = {} |
151 |
|
args['url'] = dbs_url |
161 |
|
api = DBSAPI.dbsApi.DbsApi(args) |
162 |
|
self.files = self.queryDbs(api,path=self.datasetPath,runselection=runselection,useParent=useparent) |
163 |
|
|
164 |
+ |
# Check to see what the dataset is |
165 |
+ |
pdsName = self.datasetPath.split("/")[1] |
166 |
+ |
primDSs = api.listPrimaryDatasets(pdsName) |
167 |
+ |
dataType = primDSs[0]['Type'] |
168 |
+ |
common.logger.debug("Datatype is %s" % dataType) |
169 |
+ |
if dataType == 'data' and not \ |
170 |
+ |
(self.splitByRun or self.splitByLumi or self.splitDataByEvent): |
171 |
+ |
msg = 'Data must be split by lumi or by run. ' \ |
172 |
+ |
'Please see crab -help for the correct settings' |
173 |
+ |
raise CrabException(msg) |
174 |
+ |
|
175 |
+ |
|
176 |
+ |
|
177 |
|
anFileBlocks = [] |
178 |
|
if self.skipBlocks: anFileBlocks = readTXTfile(self, fileBlocks_FileName) |
179 |
|
|
188 |
|
# asked retry the list of parent for the given child |
189 |
|
if useparent==1: |
190 |
|
parList = [x['LogicalFileName'] for x in file['ParentList']] |
191 |
< |
if self.ads or self.lumiMask: |
191 |
> |
if self.splitByLumi: |
192 |
|
fileLumis = [ (x['RunNumber'], x['LumiSectionNumber']) |
193 |
|
for x in file['LumiList'] ] |
194 |
|
self.parent[filename] = parList |
195 |
|
# For LumiMask, intersection of two lists. |
196 |
< |
if self.lumiMask: |
196 |
> |
if self.lumiMask and runselection: |
197 |
> |
self.lumis[filename] = runList.filterLumis(lumiList.filterLumis(fileLumis)) |
198 |
> |
elif runselection: |
199 |
> |
self.lumis[filename] = runList.filterLumis(fileLumis) |
200 |
> |
elif self.lumiMask: |
201 |
|
self.lumis[filename] = lumiList.filterLumis(fileLumis) |
202 |
|
else: |
203 |
|
self.lumis[filename] = fileLumis |
225 |
|
msg = "No new fileblocks available for dataset: "+str(self.datasetPath) |
226 |
|
raise CrabException(msg) |
227 |
|
|
207 |
– |
saveFblocks='' |
208 |
– |
for block in self.eventsPerBlock.keys() : |
209 |
– |
saveFblocks += str(block)+'\n' |
210 |
– |
common.logger.log(10-1,"DBSInfo: total nevts %i in block %s "%(self.eventsPerBlock[block],block)) |
211 |
– |
writeTXTfile(self, fileBlocks_FileName , saveFblocks) |
228 |
|
|
229 |
|
if len(self.eventsPerBlock) <= 0: |
230 |
|
raise NotExistingDatasetError(("\nNo data for %s in DBS\nPlease check" |
234 |
|
|
235 |
|
def queryDbs(self,api,path=None,runselection=None,useParent=None): |
236 |
|
|
237 |
< |
allowedRetriveValue = ['retrive_block', 'retrive_run'] |
238 |
< |
if self.ads or self.lumiMask: |
237 |
> |
|
238 |
> |
allowedRetriveValue = [] |
239 |
> |
if self.splitByLumi or self.splitByRun or useParent == 1: |
240 |
> |
allowedRetriveValue.extend(['retrive_block', 'retrive_run']) |
241 |
> |
if self.splitByLumi: |
242 |
|
allowedRetriveValue.append('retrive_lumi') |
243 |
< |
if useParent == 1: allowedRetriveValue.append('retrive_parent') |
243 |
> |
if useParent == 1: |
244 |
> |
allowedRetriveValue.append('retrive_parent') |
245 |
|
common.logger.debug("Set of input parameters used for DBS query: %s" % allowedRetriveValue) |
246 |
|
try: |
247 |
< |
if len(runselection) <=0 : |
248 |
< |
if useParent==1 or self.splitByRun==1 or self.ads or self.lumiMask: |
229 |
< |
if self.ads: |
230 |
< |
files = api.listFiles(analysisDataset=path, retriveList=allowedRetriveValue) |
231 |
< |
else : |
232 |
< |
files = api.listFiles(path=path, retriveList=allowedRetriveValue) |
233 |
< |
else: |
234 |
< |
files = api.listDatasetFiles(self.datasetPath) |
235 |
< |
else : |
236 |
< |
files=[] |
247 |
> |
if self.splitByRun: |
248 |
> |
files = [] |
249 |
|
for arun in runselection: |
250 |
|
try: |
251 |
|
if self.ads: |
258 |
|
common.logger.info(msg) |
259 |
|
pass |
260 |
|
|
261 |
+ |
else: |
262 |
+ |
if allowedRetriveValue: |
263 |
+ |
if self.ads: |
264 |
+ |
files = api.listFiles(analysisDataset=path, retriveList=allowedRetriveValue) |
265 |
+ |
else : |
266 |
+ |
files = api.listFiles(path=path, retriveList=allowedRetriveValue) |
267 |
+ |
else: |
268 |
+ |
files = api.listDatasetFiles(self.datasetPath) |
269 |
+ |
|
270 |
|
except DbsBadRequest, msg: |
271 |
|
raise DataDiscoveryError(msg) |
272 |
|
except DBSError, msg: |