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']
84 data = das_client.json.loads(das_client.get_data(
'https://cmsweb.cern.ch',query,0,0,0))
86 if data[
'nresults']==0:
87 print '[electronDataDiscovery.py] No DAS dataset for query:', query
89 if data[
'nresults']>1:
90 print '[electronDataDiscovery.py] Several DAS datasets for query:', query
93 dataset = data[
'data'][0][
'dataset'][0][
'name']
95 query =
"file instance=cms_dbs_prod_global dataset="+dataset
106 data = das_client.json.loads(das_client.get_data(
'https://cmsweb.cern.ch',query,0,0,0))
108 if data[
'nresults']==0:
109 print '[electronDataDiscovery.py] No DAS file in dataset:', dataset
113 for i
in range(0,data[
'nresults']):
114 result.append(str(data[
'data'][i][
'file'][0][
'name']))
116 elif os.environ[
'DD_SOURCE'] ==
"dbs":
119 separator =
" where "
120 if os.environ[
'DD_RELEASE'] !=
"":
121 input = input + separator +
"release = " + os.environ[
'DD_RELEASE']
123 if os.environ[
'DD_SAMPLE'] !=
"":
124 input = input + separator +
"primds = " + os.environ[
'DD_SAMPLE']
126 if os.environ[
'DD_RUN'] !=
"":
127 input = input + separator +
"run = " + os.environ[
'DD_RUN']
129 input = input + separator +
"dataset like *" + os.environ[
'DD_COND'] +
"*" + dd_tier +
"*"
131 data = os.popen(
'dbs search --url="http://cmsdbsprod.cern.ch/cms_dbs_prod_global/servlet/DBSServlet" --query "'+input+
'"')
132 datalines = data.readlines()
135 for line
in datalines:
137 if line !=
"" and line[0] ==
"/":
140 elif os.environ[
'DD_SOURCE'] ==
"http":
143 separator =
" where "
144 if os.environ[
'DD_RELEASE'] !=
"":
145 input = input + separator +
"release = " + os.environ[
'DD_RELEASE']
147 if os.environ[
'DD_SAMPLE'] !=
"":
148 input = input + separator +
"primds = " + os.environ[
'DD_SAMPLE']
150 if os.environ[
'DD_RUN'] !=
"":
151 input = input + separator +
"run = " + os.environ[
'DD_RUN']
153 input = input + separator +
"dataset like *" + os.environ[
'DD_COND'] +
"*" + dd_tier +
"*"
155 url =
"https://cmsweb.cern.ch:443/dbs_discovery/aSearch"
156 final_input = urllib.quote(input) ;
158 agent =
"Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)"
159 ctypes =
"text/plain"
160 headers = {
'User-Agent':agent,
'Accept':ctypes}
161 params = {
'dbsInst':
'cms_dbs_prod_global',
162 'html':0,
'caseSensitive':
'on',
'_idx':0,
'pagerStep':-1,
163 'userInput':final_input,
164 'xml':0,
'details':0,
'cff':0,
'method':
'dbsapi'}
165 data = urllib.urlencode(params,doseq=
True)
166 req = urllib2.Request(url, data, headers)
170 response = urllib2.urlopen(req)
171 data = response.read()
172 except urllib2.HTTPError, e:
180 datalines = data.readlines()
183 for line
in datalines:
185 if line !=
"" and line[0] ==
"/":
188 elif os.environ[
'DD_SOURCE'] ==
"lsf":
190 dbs_path =
'/'+os.environ[
'DD_SAMPLE']+
'/'+os.environ[
'DD_RELEASE']+
'-'+os.environ[
'DD_COND']+
'/'+os.environ[
'DD_TIER']+
'"'
191 if __name__ ==
"__main__":
192 print 'dbs path:',dbs_path
193 data = os.popen(
'dbs lsf --path="'+dbs_path+
'"')
194 datalines = data.readlines()
197 for line
in datalines:
199 if line !=
"" and line[0] ==
"/":
202 elif os.environ[
'DD_SOURCE'].startswith(
'/castor/cern.ch/cms/'):
204 castor_dir = os.environ[
'DD_SOURCE'].
replace(
'/castor/cern.ch/cms/',
'/',1)
206 data = os.popen(
'rfdir /castor/cern.ch/cms'+castor_dir)
207 subdirs = data.readlines()
212 subdir = line.split()[8]
213 data = os.popen(
'rfdir /castor/cern.ch/cms'+castor_dir+
'/'+subdir)
214 datalines = data.readlines()
215 for line
in datalines:
217 file = line.split()[8]
219 result.append(castor_dir+
'/'+subdir+
'/'+file)
222 elif os.environ[
'DD_SOURCE'].startswith(
'/eos/cms/'):
224 data = os.popen(
'/afs/cern.ch/project/eos/installation/pro/bin/eos.select find -f '+os.environ[
'DD_SOURCE'])
225 lines = data.readlines()
229 line = line.strip().
replace(
'/eos/cms/',
'/',1)
230 if line ==
"":
continue
231 if dd_sample_re.search(line) ==
None:
continue
232 if dd_cond_re.search(line) ==
None:
continue
233 if dd_tier_re.search(line) ==
None:
continue
234 if dd_run_re.search(line) ==
None:
continue
240 for line
in open(os.environ[
'DD_SOURCE']).readlines():
241 line = os.path.expandvars(line.strip())
242 if line ==
"":
continue
243 if dd_sample_re.search(line) ==
None:
continue
244 if dd_cond_re.search(line) ==
None:
continue
245 if dd_tier_re.search(line) ==
None:
continue
246 if dd_run_re.search(line) ==
None:
continue
250 diag =
'[electronDataDiscovery.py] No more files after filtering with :'
251 if os.environ[
'DD_SAMPLE']!=
'': diag +=
' ' + os.environ[
'DD_SAMPLE']
252 if os.environ[
'DD_COND']!=
'': diag +=
' ' + os.environ[
'DD_COND']
253 if dd_tier!=
'': diag +=
' ' + dd_tier
254 if os.environ[
'DD_RUN']!=
'': diag +=
' ' + os.environ[
'DD_RUN']