Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:34:06

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