CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/DQMOffline/EGamma/python/electronDbsDiscovery.py

Go to the documentation of this file.
00001 
00002 #===================================================================
00003 # This python module is querying https://cmsweb.cern.ch/dbs_discovery/
00004 # so to get the list of input files. One must call :
00005 #   search(), to get the list of primary files
00006 #   search2(), to get the list of eventual secondary files
00007 # 
00008 # The selection of files is configured thanks to shell
00009 # environment variables: 
00010 # 
00011 #   DBS_RELEASE, for example CMSSW_2_2_0_pre1
00012 #   DBS_SAMPLE, for example RelValSingleElectronPt35
00013 #   DBS_RUN, for example Any
00014 #   DBS_COND , for example MC_31X_V2-v1
00015 #   DBS_TIER , for example RECO
00016 #   DBS_TIER_SECONDARY, for eventual secondary files
00017 #   
00018 #   DBS_STRATEGY:
00019 #     search: use dbs search
00020 #     castor: use rfdir
00021 #     lsf: use dbs lsf
00022 #     local: look within electronDbsDiscovery.txt
00023 #   DBS_CASTOR_DIR: top dir to scrutiny when the strategy is "castor"
00024 #     for relvals: '/store/relval/${DBS_RELEASE}/${DBS_SAMPLE}/${DBS_TIER}/${DBS_COND}/'
00025 #     for harvested dqm: '/store/unmerged/dqm/${DBS_SAMPLE}-${DBS_RELEASE}-${DBS_COND}-DQM-DQMHarvest-OfflineDQM'
00026 #
00027 # In DBS_COND, DBS_TIER and DBS_TIER_SECONDARY,
00028 # one can use wildcard *.
00029 #===================================================================
00030 
00031 #import httpslib, urllib, urllib2, types, string, os, sys
00032 import os, sys
00033 
00034 if not os.environ.has_key('DBS_STRATEGY'):
00035   os.environ['DBS_STRATEGY'] = "search"
00036 if not os.environ.has_key('DBS_RELEASE'):
00037   os.environ['DBS_RELEASE'] = "Any"
00038 if not os.environ.has_key('DBS_SAMPLE'):
00039   os.environ['DBS_SAMPLE'] = "Any"
00040 if not os.environ.has_key('DBS_RUN'):
00041   os.environ['DBS_RUN'] = "Any"
00042 if not os.environ.has_key('DBS_TIER_SECONDARY'):
00043   os.environ['DBS_TIER_SECONDARY'] = ""
00044 
00045 def common_search(dbs_tier):
00046 
00047   if os.environ['DBS_STRATEGY'] == "local":
00048   
00049     result = []
00050     for line in  open('electronDbsDiscovery.txt').readlines():
00051       line = os.path.expandvars(line.strip())
00052       if line == "": continue
00053       if os.environ['DBS_SAMPLE'] != "Any" and line.find(os.environ['DBS_SAMPLE'])== -1: continue
00054       if line.find(os.environ['DBS_COND'])== -1: continue
00055       if line.find(dbs_tier)== -1: continue
00056       result.append('file:'+line)
00057       
00058   elif os.environ['DBS_STRATEGY'] == "castor":
00059   
00060     castor_dir = os.environ['DBS_CASTOR_DIR']
00061     result = []
00062     data = os.popen('rfdir /castor/cern.ch/cms'+castor_dir)
00063     subdirs = data.readlines()
00064     data.close()
00065     datalines = []
00066     for line in subdirs:
00067       line = line.rstrip()
00068       subdir = line.split()[8]
00069       data = os.popen('rfdir /castor/cern.ch/cms'+castor_dir+'/'+subdir)
00070       datalines = data.readlines()
00071       for line in datalines:
00072         line = line.rstrip()
00073         file = line.split()[8]
00074         if file != "":
00075           result.append(castor_dir+'/'+subdir+'/'+file)
00076       data.close()
00077       
00078   elif os.environ['DBS_STRATEGY'] == "lsf":
00079   
00080     dbs_path = '/'+os.environ['DBS_SAMPLE']+'/'+os.environ['DBS_RELEASE']+'-'+os.environ['DBS_COND']+'/'+os.environ['DBS_TIER']+'"'
00081     if __name__ == "__main__":
00082       print 'dbs path:',dbs_path
00083     data = os.popen('dbs lsf --path="'+dbs_path+'"')
00084     datalines = data.readlines()
00085     data.close()
00086     result = []
00087     for line in datalines:
00088       line = line.rstrip()
00089       if line != "" and line[0] =="/":
00090         result.append(line)
00091       
00092   else:
00093   
00094     input = "find file"
00095     separator = " where "
00096     if os.environ['DBS_RELEASE'] != "Any":
00097       input = input + separator + "release = " + os.environ['DBS_RELEASE']
00098       separator = " and "
00099     if os.environ['DBS_SAMPLE'] != "Any":
00100       input = input + separator + "primds = " + os.environ['DBS_SAMPLE']
00101       separator = " and "
00102     if os.environ['DBS_RUN'] != "Any":
00103       input = input + separator + "run = " + os.environ['DBS_RUN']
00104       separator = " and "
00105     input = input + separator + "dataset like *" + os.environ['DBS_COND'] + "*" + dbs_tier + "*"
00106     
00107     #url = "https://cmsweb.cern.ch:443/dbs_discovery/aSearch"
00108     #final_input = urllib.quote(input) ;
00109     #
00110     #agent   = "Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)"
00111     #ctypes  = "text/plain"
00112     #headers = { 'User-Agent':agent, 'Accept':ctypes}
00113     #params  = {'dbsInst':'cms_dbs_prod_global',
00114     #           'html':0,'caseSensitive':'on','_idx':0,'pagerStep':-1,
00115     #           'userInput':final_input,
00116     #           'xml':0,'details':0,'cff':0,'method':'dbsapi'}
00117     #data    = urllib.urlencode(params,doseq=True)
00118     #req     = urllib2.Request(url, data, headers)
00119     #data    = ""
00120     #
00121     #try:
00122     #  response = urllib2.urlopen(req)
00123     #  data = response.read()
00124     #except urllib2.HTTPError, e:
00125     #  if e.code==201:
00126     #    print e.headers       
00127     #    print e.msg
00128     #    pass
00129     #  else:
00130     #    raise e
00131 
00132     data = os.popen('dbs search --url="https://cmsdbsprod.cern.ch/cms_dbs_prod_global/servlet/DBSServlet" --query "'+input+'"')
00133     datalines = data.readlines()
00134     data.close()
00135     result = []
00136     for line in datalines:
00137       line = line.rstrip()
00138       if line != "" and line[0] =="/":
00139         result.append(line)
00140     
00141   return result
00142 
00143 def search():
00144   return common_search(os.environ['DBS_TIER'])
00145 
00146 def search2():
00147   return common_search(os.environ['DBS_TIER_SECONDARY'])
00148 
00149         
00150         
00151