62 dd_tier_re = re.compile(dd_tier.replace(
'*',
'.*'));
64 if os.environ[
'DD_SOURCE'] ==
"das":
66 query =
"dataset instance=cms_dbs_prod_global"
67 if os.environ[
'DD_RELEASE'] !=
"":
68 query = query +
" release=" + os.environ[
'DD_RELEASE']
69 if os.environ[
'DD_SAMPLE'] !=
"":
70 query = query +
" primary_dataset=" + os.environ[
'DD_SAMPLE']
72 query = query +
" tier=" + dd_tier
73 if os.environ[
'DD_COND'] !=
"":
74 query = query +
" dataset=*" + os.environ[
'DD_COND'] +
"*"
75 if os.environ[
'DD_RUN'] !=
"":
76 query = query +
" run=" + os.environ[
'DD_RUN']
91 if data[
'nresults'] == 0:
92 print(
'[electronDataDiscovery.py] No DAS dataset for query:', query)
94 while data[
'nresults'] > 1:
95 if data[
'data'][0][
'dataset'][0][
'name'] == data[
'data'][1][
'dataset'][0][
'name']:
99 print(
'[electronDataDiscovery.py] Several DAS datasets for query:', query)
100 for i
in range(data[
'nresults']):
102 '[electronDataDiscovery.py] dataset[' +
str(i) +
']: ' + data[
'data'][i][
'dataset'][0][
'name'])
105 dataset = data[
'data'][0][
'dataset'][0][
'name']
107 query =
"file instance=cms_dbs_prod_global dataset=" + dataset
118 data = das_client.json.loads(
das_client.get_data(
'https://cmsweb.cern.ch', query, 0, 0, 0))
120 if data[
'nresults'] == 0:
121 print(
'[electronDataDiscovery.py] No DAS file in dataset:', dataset)
124 print(
'there is %d results' % nresults)
127 for i
in range(0, data[
'nresults']):
128 result.append(
str(data[
'data'][i][
'file'][0][
'name']))
130 elif os.environ[
'DD_SOURCE'] ==
"dbs":
133 separator =
" where "
134 if os.environ[
'DD_RELEASE'] !=
"":
135 input = input + separator +
"release = " + os.environ[
'DD_RELEASE']
137 if os.environ[
'DD_SAMPLE'] !=
"":
138 input = input + separator +
"primds = " + os.environ[
'DD_SAMPLE']
140 if os.environ[
'DD_RUN'] !=
"":
141 input = input + separator +
"run = " + os.environ[
'DD_RUN']
143 input = input + separator +
"dataset like *" + os.environ[
'DD_COND'] +
"*" + dd_tier +
"*"
146 'dbs search --url="http://cmsdbsprod.cern.ch/cms_dbs_prod_global/servlet/DBSServlet" --query "' + input +
'"')
147 datalines = data.readlines()
150 for line
in datalines:
152 if line !=
"" and line[0] ==
"/":
155 elif os.environ[
'DD_SOURCE'] ==
"http":
158 separator =
" where "
159 if os.environ[
'DD_RELEASE'] !=
"":
160 input = input + separator +
"release = " + os.environ[
'DD_RELEASE']
162 if os.environ[
'DD_SAMPLE'] !=
"":
163 input = input + separator +
"primds = " + os.environ[
'DD_SAMPLE']
165 if os.environ[
'DD_RUN'] !=
"":
166 input = input + separator +
"run = " + os.environ[
'DD_RUN']
168 input = input + separator +
"dataset like *" + os.environ[
'DD_COND'] +
"*" + dd_tier +
"*"
170 url =
"https://cmsweb.cern.ch:443/dbs_discovery/aSearch"
171 final_input = urllib.quote(input);
173 agent =
"Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)"
174 ctypes =
"text/plain"
175 headers = {
'User-Agent': agent,
'Accept': ctypes}
176 params = {
'dbsInst':
'cms_dbs_prod_global',
177 'html': 0,
'caseSensitive':
'on',
'_idx': 0,
'pagerStep': -1,
178 'userInput': final_input,
179 'xml': 0,
'details': 0,
'cff': 0,
'method':
'dbsapi'}
180 data = urllib.urlencode(params, doseq=
True)
181 req = urllib2.Request(url, data, headers)
185 response = urllib2.urlopen(req)
186 data = response.read()
187 except urllib2.HTTPError
as e:
195 datalines = data.readlines()
198 for line
in datalines:
200 if line !=
"" and line[0] ==
"/":
203 elif os.environ[
'DD_SOURCE'] ==
"lsf":
205 dbs_path =
'/' + os.environ[
'DD_SAMPLE'] +
'/' + os.environ[
'DD_RELEASE'] +
'-' + os.environ[
'DD_COND'] +
'/' + \
206 os.environ[
'DD_TIER'] +
'"'
207 if __name__ ==
"__main__":
208 print(
'dbs path:', dbs_path)
209 data = os.popen(
'dbs lsf --path="' + dbs_path +
'"')
210 datalines = data.readlines()
213 for line
in datalines:
215 if line !=
"" and line[0] ==
"/":
218 elif os.environ[
'DD_SOURCE'].startswith(
'/castor/cern.ch/cms/'):
220 castor_dir = os.environ[
'DD_SOURCE'].
replace(
'/castor/cern.ch/cms/',
'/', 1)
222 data = os.popen(
'rfdir /castor/cern.ch/cms' + castor_dir)
223 subdirs = data.readlines()
228 subdir = line.split()[8]
229 data = os.popen(
'rfdir /castor/cern.ch/cms' + castor_dir +
'/' + subdir)
230 datalines = data.readlines()
231 for line
in datalines:
233 file = line.split()[8]
235 result.append(castor_dir +
'/' + subdir +
'/' + file)
238 elif os.environ[
'DD_SOURCE'].startswith(
'/eos/cms/'):
240 data = os.popen(
'eos find -f ' + os.environ[
'DD_SOURCE'])
241 lines = data.readlines()
245 line = line.strip().
replace(
'/eos/cms/',
'/', 1)
246 if line ==
"":
continue
247 if dd_sample_re.search(line) ==
None:
continue
248 if dd_cond_re.search(line) ==
None:
continue
249 if dd_tier_re.search(line) ==
None:
continue
250 if dd_run_re.search(line) ==
None:
continue
256 for line
in open(os.environ[
'DD_SOURCE']).readlines():
257 line = os.path.expandvars(line.strip())
258 if line ==
"":
continue
259 if dd_sample_re.search(line) ==
None:
continue
260 if dd_cond_re.search(line) ==
None:
continue
261 if dd_tier_re.search(line) ==
None:
continue
262 if dd_run_re.search(line) ==
None:
continue
266 diag =
'[electronDataDiscovery.py] No more files after filtering with :'
267 if os.environ[
'DD_SAMPLE'] !=
'': diag +=
' ' + os.environ[
'DD_SAMPLE']
268 if os.environ[
'DD_COND'] !=
'': diag +=
' ' + os.environ[
'DD_COND']
269 if dd_tier !=
'': diag +=
' ' + dd_tier
270 if os.environ[
'DD_RUN'] !=
'': diag +=
' ' + os.environ[
'DD_RUN']