CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Functions | Variables
electronDataDiscovery Namespace Reference

Functions

def common_search
 
def search
 
def search2
 

Variables

tuple dd_cond_re = re.compile(os.environ['DD_COND'].replace('*','.*'))
 
tuple dd_release_re = re.compile(os.environ['DD_RELEASE'].replace('*','.*'))
 
tuple dd_run_re = re.compile(os.environ['DD_RUN'].replace('*','.*'))
 
tuple dd_sample_re = re.compile(os.environ['DD_SAMPLE'].replace('*','.*'))
 
tuple files = dd.search()
 

Function Documentation

def electronDataDiscovery.common_search (   dd_tier)

Definition at line 55 of file electronDataDiscovery.py.

References python.rootplot.root2matplotlib.replace().

Referenced by search(), and search2().

55 
56 def common_search(dd_tier):
57 
58  dd_tier_re = re.compile(dd_tier.replace('*','.*')) ;
59 
60  if os.environ['DD_SOURCE'] == "das":
61 
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']
67  if dd_tier != "":
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']
73 
74  #data = os.popen('das_client.py --limit=0 --query "'+query+'"')
75  #datalines = data.readlines()
76  #data.close()
77  #datasets = []
78  #for line in datalines:
79  # line = line.rstrip()
80  # if line != "" and line[0] =="/":
81  # datasets.append(line)
82  #dataset = datasets[0]
83 
84  data = das_client.json.loads(das_client.get_data('https://cmsweb.cern.ch',query,0,0,0))
85 
86  if data['nresults']==0:
87  print '[electronDataDiscovery.py] No DAS dataset for query:', query
88  return []
89  if data['nresults']>1:
90  print '[electronDataDiscovery.py] Several DAS datasets for query:', query
91  return []
92 
93  dataset = data['data'][0]['dataset'][0]['name']
94 
95  query = "file instance=cms_dbs_prod_global dataset="+dataset
96 
97  #data = os.popen('das_client.py --limit=0 --query "'+query+'"')
98  #datalines = data.readlines()
99  #data.close()
100  #result = []
101  #for line in datalines:
102  # line = line.rstrip()
103  # if line != "" and line[0] =="/":
104  # result.append(line)
105 
106  data = das_client.json.loads(das_client.get_data('https://cmsweb.cern.ch',query,0,0,0))
107 
108  if data['nresults']==0:
109  print '[electronDataDiscovery.py] No DAS file in dataset:', dataset
110  return []
111 
112  result = []
113  for i in range(0,data['nresults']):
114  result.append(str(data['data'][i]['file'][0]['name']))
115 
116  elif os.environ['DD_SOURCE'] == "dbs":
117 
118  input = "find file"
119  separator = " where "
120  if os.environ['DD_RELEASE'] != "":
121  input = input + separator + "release = " + os.environ['DD_RELEASE']
122  separator = " and "
123  if os.environ['DD_SAMPLE'] != "":
124  input = input + separator + "primds = " + os.environ['DD_SAMPLE']
125  separator = " and "
126  if os.environ['DD_RUN'] != "":
127  input = input + separator + "run = " + os.environ['DD_RUN']
128  separator = " and "
129  input = input + separator + "dataset like *" + os.environ['DD_COND'] + "*" + dd_tier + "*"
130 
131  data = os.popen('dbs search --url="http://cmsdbsprod.cern.ch/cms_dbs_prod_global/servlet/DBSServlet" --query "'+input+'"')
132  datalines = data.readlines()
133  data.close()
134  result = []
135  for line in datalines:
136  line = line.rstrip()
137  if line != "" and line[0] =="/":
138  result.append(line)
139 
140  elif os.environ['DD_SOURCE'] == "http":
141 
142  input = "find file"
143  separator = " where "
144  if os.environ['DD_RELEASE'] != "":
145  input = input + separator + "release = " + os.environ['DD_RELEASE']
146  separator = " and "
147  if os.environ['DD_SAMPLE'] != "":
148  input = input + separator + "primds = " + os.environ['DD_SAMPLE']
149  separator = " and "
150  if os.environ['DD_RUN'] != "":
151  input = input + separator + "run = " + os.environ['DD_RUN']
152  separator = " and "
153  input = input + separator + "dataset like *" + os.environ['DD_COND'] + "*" + dd_tier + "*"
154 
155  url = "https://cmsweb.cern.ch:443/dbs_discovery/aSearch"
156  final_input = urllib.quote(input) ;
157 
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)
167  data = ""
168 
169  try:
170  response = urllib2.urlopen(req)
171  data = response.read()
172  except urllib2.HTTPError, e:
173  if e.code==201:
174  print e.headers
175  print e.msg
176  pass
177  else:
178  raise e
179 
180  datalines = data.readlines()
181  data.close()
182  result = []
183  for line in datalines:
184  line = line.rstrip()
185  if line != "" and line[0] =="/":
186  result.append(line)
187 
188  elif os.environ['DD_SOURCE'] == "lsf":
189 
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()
195  data.close()
196  result = []
197  for line in datalines:
198  line = line.rstrip()
199  if line != "" and line[0] =="/":
200  result.append(line)
201 
202  elif os.environ['DD_SOURCE'].startswith('/castor/cern.ch/cms/'): # assumed to be a castor dir
203 
204  castor_dir = os.environ['DD_SOURCE'].replace('/castor/cern.ch/cms/','/',1)
205  result = []
206  data = os.popen('rfdir /castor/cern.ch/cms'+castor_dir)
207  subdirs = data.readlines()
208  data.close()
209  datalines = []
210  for line in subdirs:
211  line = line.rstrip()
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:
216  line = line.rstrip()
217  file = line.split()[8]
218  if file != "":
219  result.append(castor_dir+'/'+subdir+'/'+file)
220  data.close()
221 
222  elif os.environ['DD_SOURCE'].startswith('/eos/cms/'): # assumed to be an eos dir
223 
224  data = os.popen('/afs/cern.ch/project/eos/installation/pro/bin/eos.select find -f '+os.environ['DD_SOURCE'])
225  lines = data.readlines()
226  data.close()
227  result = []
228  for line in lines:
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
235  result.append(line)
236 
237  else: # os.environ['DD_SOURCE'] is assumed to be a file name
238 
239  result = []
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
247  result.append(line)
248 
249  if len(result)==0:
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']
255  print diag
256 
257  return result
def electronDataDiscovery.search ( )

Definition at line 258 of file electronDataDiscovery.py.

References common_search().

259 def search():
260  return common_search(os.environ['DD_TIER'])
def electronDataDiscovery.search2 ( )

Definition at line 261 of file electronDataDiscovery.py.

References common_search().

262 def search2():
263  return common_search(os.environ['DD_TIER_SECONDARY'])
264 
265 
266 
267 

Variable Documentation

tuple electronDataDiscovery.dd_cond_re = re.compile(os.environ['DD_COND'].replace('*','.*'))

Definition at line 52 of file electronDataDiscovery.py.

tuple electronDataDiscovery.dd_release_re = re.compile(os.environ['DD_RELEASE'].replace('*','.*'))

Definition at line 50 of file electronDataDiscovery.py.

tuple electronDataDiscovery.dd_run_re = re.compile(os.environ['DD_RUN'].replace('*','.*'))

Definition at line 53 of file electronDataDiscovery.py.

tuple electronDataDiscovery.dd_sample_re = re.compile(os.environ['DD_SAMPLE'].replace('*','.*'))

Definition at line 51 of file electronDataDiscovery.py.

tuple electronDataDiscovery.files = dd.search()

Definition at line 10 of file electronDataDiscovery.py.