58 dd_tier_re = re.compile(dd_tier.replace(
'*',
'.*')) ;
60 if os.environ[
'DD_SOURCE'] ==
"das":
62 query =
"dataset instance=cms_dbs_prod_global"
63 if os.environ[
'DD_RELEASE'] !=
"" :
64 query = query +
" release=" + os.environ[
'DD_RELEASE']
65 if os.environ[
'DD_SAMPLE'] !=
"":
66 query = query +
" primary_dataset=" + os.environ[
'DD_SAMPLE']
68 query = query +
" tier=" + dd_tier
69 if os.environ[
'DD_COND'] !=
"":
70 query = query +
" dataset=*" + os.environ[
'DD_COND'] +
"*"
71 if os.environ[
'DD_RUN'] !=
"":
72 query = query +
" run=" + os.environ[
'DD_RUN']
85 data = das_client.json.loads(das_client.get_data(
'https://cmsweb.cern.ch',query,0,0,0))
87 if data[
'nresults']==0:
88 print '[electronDataDiscovery.py] No DAS dataset for query:', query
90 while data[
'nresults']>1:
91 if data[
'data'][0][
'dataset'][0][
'name']==data[
'data'][1][
'dataset'][0][
'name']:
95 print '[electronDataDiscovery.py] Several DAS datasets for query:', query
96 for i
in range(data[
'nresults']):
97 print '[electronDataDiscovery.py] dataset['+str(i)+
']: '+data[
'data'][i][
'dataset'][0][
'name']
100 dataset = data[
'data'][0][
'dataset'][0][
'name']
102 query =
"file instance=cms_dbs_prod_global dataset="+dataset
113 data = das_client.json.loads(das_client.get_data(
'https://cmsweb.cern.ch',query,0,0,0))
115 if data[
'nresults']==0:
116 print '[electronDataDiscovery.py] No DAS file in dataset:', dataset
120 for i
in range(0,data[
'nresults']):
121 result.append(str(data[
'data'][i][
'file'][0][
'name']))
123 elif os.environ[
'DD_SOURCE'] ==
"dbs":
126 separator =
" where "
127 if os.environ[
'DD_RELEASE'] !=
"":
128 input = input + separator +
"release = " + os.environ[
'DD_RELEASE']
130 if os.environ[
'DD_SAMPLE'] !=
"":
131 input = input + separator +
"primds = " + os.environ[
'DD_SAMPLE']
133 if os.environ[
'DD_RUN'] !=
"":
134 input = input + separator +
"run = " + os.environ[
'DD_RUN']
136 input = input + separator +
"dataset like *" + os.environ[
'DD_COND'] +
"*" + dd_tier +
"*"
138 data = os.popen(
'dbs search --url="http://cmsdbsprod.cern.ch/cms_dbs_prod_global/servlet/DBSServlet" --query "'+input+
'"')
139 datalines = data.readlines()
142 for line
in datalines:
144 if line !=
"" and line[0] ==
"/":
147 elif os.environ[
'DD_SOURCE'] ==
"http":
150 separator =
" where "
151 if os.environ[
'DD_RELEASE'] !=
"":
152 input = input + separator +
"release = " + os.environ[
'DD_RELEASE']
154 if os.environ[
'DD_SAMPLE'] !=
"":
155 input = input + separator +
"primds = " + os.environ[
'DD_SAMPLE']
157 if os.environ[
'DD_RUN'] !=
"":
158 input = input + separator +
"run = " + os.environ[
'DD_RUN']
160 input = input + separator +
"dataset like *" + os.environ[
'DD_COND'] +
"*" + dd_tier +
"*"
162 url =
"https://cmsweb.cern.ch:443/dbs_discovery/aSearch"
163 final_input = urllib.quote(input) ;
165 agent =
"Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)"
166 ctypes =
"text/plain"
167 headers = {
'User-Agent':agent,
'Accept':ctypes}
168 params = {
'dbsInst':
'cms_dbs_prod_global',
169 'html':0,
'caseSensitive':
'on',
'_idx':0,
'pagerStep':-1,
170 'userInput':final_input,
171 'xml':0,
'details':0,
'cff':0,
'method':
'dbsapi'}
172 data = urllib.urlencode(params,doseq=
True)
173 req = urllib2.Request(url, data, headers)
177 response = urllib2.urlopen(req)
178 data = response.read()
179 except urllib2.HTTPError
as e:
187 datalines = data.readlines()
190 for line
in datalines:
192 if line !=
"" and line[0] ==
"/":
195 elif os.environ[
'DD_SOURCE'] ==
"lsf":
197 dbs_path =
'/'+os.environ[
'DD_SAMPLE']+
'/'+os.environ[
'DD_RELEASE']+
'-'+os.environ[
'DD_COND']+
'/'+os.environ[
'DD_TIER']+
'"'
198 if __name__ ==
"__main__":
199 print 'dbs path:',dbs_path
200 data = os.popen(
'dbs lsf --path="'+dbs_path+
'"')
201 datalines = data.readlines()
204 for line
in datalines:
206 if line !=
"" and line[0] ==
"/":
209 elif os.environ[
'DD_SOURCE'].startswith(
'/castor/cern.ch/cms/'):
211 castor_dir = os.environ[
'DD_SOURCE'].
replace(
'/castor/cern.ch/cms/',
'/',1)
213 data = os.popen(
'rfdir /castor/cern.ch/cms'+castor_dir)
214 subdirs = data.readlines()
219 subdir = line.split()[8]
220 data = os.popen(
'rfdir /castor/cern.ch/cms'+castor_dir+
'/'+subdir)
221 datalines = data.readlines()
222 for line
in datalines:
224 file = line.split()[8]
226 result.append(castor_dir+
'/'+subdir+
'/'+file)
229 elif os.environ[
'DD_SOURCE'].startswith(
'/eos/cms/'):
231 data = os.popen(
'/afs/cern.ch/project/eos/installation/pro/bin/eos.select find -f '+os.environ[
'DD_SOURCE'])
232 lines = data.readlines()
236 line = line.strip().
replace(
'/eos/cms/',
'/',1)
237 if line ==
"":
continue
238 if dd_sample_re.search(line) ==
None:
continue
239 if dd_cond_re.search(line) ==
None:
continue
240 if dd_tier_re.search(line) ==
None:
continue
241 if dd_run_re.search(line) ==
None:
continue
247 for line
in open(os.environ[
'DD_SOURCE']).readlines():
248 line = os.path.expandvars(line.strip())
249 if line ==
"":
continue
250 if dd_sample_re.search(line) ==
None:
continue
251 if dd_cond_re.search(line) ==
None:
continue
252 if dd_tier_re.search(line) ==
None:
continue
253 if dd_run_re.search(line) ==
None:
continue
257 diag =
'[electronDataDiscovery.py] No more files after filtering with :'
258 if os.environ[
'DD_SAMPLE']!=
'': diag +=
' ' + os.environ[
'DD_SAMPLE']
259 if os.environ[
'DD_COND']!=
'': diag +=
' ' + os.environ[
'DD_COND']
260 if dd_tier!=
'': diag +=
' ' + dd_tier
261 if os.environ[
'DD_RUN']!=
'': diag +=
' ' + os.environ[
'DD_RUN']