Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-11-25 02:29:54

0001 #!/usr/bin/env python
0002 
0003 import httplib, urllib, urllib2, types, string, os, sys
0004 
0005 # return the list of files obtained from the data discovery and based upon environnement variables:
0006 # DBS_RELEASE, for example CMSSW_2_2_0_pre1
0007 # DBS_SAMPLE, for example RelValSingleElectronPt35
0008 # DBS_COND , for example MC_31X_V2-v1
0009 # DBS_TIER , for example RECO
0010 
0011 def search():
0012 
0013   if os.environ['DBS_RELEASE'] == "LOCAL":
0014     result = []
0015     for line in  open('dbs_discovery.txt').readlines():
0016       line = line.strip()
0017       if line == "": continue
0018       if line.find(os.environ['DBS_SAMPLE'])== -1: continue
0019       if line.find(os.environ['DBS_COND'])== -1: continue
0020       if line.find(os.environ['DBS_TIER'])== -1: continue
0021       result.append('file:'+line)
0022   else:
0023     url = "https://cmsweb.cern.ch:443/dbs_discovery/aSearch"
0024     if os.environ['DBS_RELEASE'] != "Any":
0025       input = "find file where release = " + os.environ['DBS_RELEASE']
0026     if os.environ['DBS_SAMPLE'] != "Any":
0027       input = input + " and primds = " + os.environ['DBS_SAMPLE']
0028     input = input + " and dataset like *" + os.environ['DBS_COND'] + "*" + os.environ['DBS_TIER'] + "*"
0029     final_input = urllib.quote(input) ;
0030 
0031     agent   = "Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)"
0032     ctypes  = "text/plain"
0033     headers = { 'User-Agent':agent, 'Accept':ctypes}
0034     params  = {'dbsInst':'cms_dbs_prod_global',
0035                'html':0,'caseSensitive':'on','_idx':0,'pagerStep':-1,
0036                'userInput':final_input,
0037                'xml':0,'details':0,'cff':0,'method':'dbsapi'}
0038     data    = urllib.urlencode(params,doseq=True)
0039     req     = urllib2.Request(url, data, headers)
0040     data    = ""
0041 
0042     try:
0043       response = urllib2.urlopen(req)
0044       data = response.read()
0045     except urllib2.HTTPError as e:
0046       if e.code==201:
0047         print(e.headers)       
0048         print(e.msg)
0049         pass
0050       else:
0051         raise e
0052 
0053     result = []
0054     for line in data.split("\n"):
0055       if line != "" and line[0] =="/":
0056         result.append(line)
0057 
0058   return result
0059 
0060 if __name__ == "__main__":
0061   for file in search():
0062     print(file)
0063 
0064     
0065     
0066