Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 import os, sys
00030
00031 if not os.environ.has_key('DBS_RELEASE'):
00032 os.environ['DBS_RELEASE'] = "Any"
00033 if not os.environ.has_key('DBS_SAMPLE'):
00034 os.environ['DBS_SAMPLE'] = "Any"
00035 if not os.environ.has_key('DBS_RUN'):
00036 os.environ['DBS_RUN'] = "Any"
00037 if not os.environ.has_key('DBS_TIER_SECONDARY'):
00038 os.environ['DBS_TIER_SECONDARY'] = ""
00039 if not os.environ.has_key('DBS_STRATEGY'):
00040 os.environ['DBS_STRATEGY'] = "search"
00041
00042 def common_search(dbs_tier):
00043
00044 if os.environ['DBS_STRATEGY'] == "local":
00045
00046 result = []
00047 for line in open('electronDbsDiscovery.txt').readlines():
00048 line = os.path.expandvars(line.strip())
00049 if line == "": continue
00050 if os.environ['DBS_SAMPLE'] != "Any" and line.find(os.environ['DBS_SAMPLE'])== -1: continue
00051 if line.find(os.environ['DBS_COND'])== -1: continue
00052 if line.find(dbs_tier)== -1: continue
00053 result.append('file:'+line)
00054
00055 elif os.environ['DBS_STRATEGY'] == "castor":
00056
00057 castor_dir = '/castor/cern.ch/cms/store/relval/'+os.environ['DBS_RELEASE']+'/'+os.environ['DBS_SAMPLE']+'/'+os.environ['DBS_TIER']+'/'+os.environ['DBS_COND']+'/'
00058 if __name__ == "__main__":
00059 print 'castor dir:',castor_dir
00060 result = []
00061 data = os.popen('rfdir '+castor_dir)
00062 subdirs = data.readlines()
00063 data.close()
00064 datalines = []
00065 for line in subdirs:
00066 line = line.rstrip()
00067 subdir = line.split()[8]
00068 data = os.popen('rfdir '+castor_dir+'/'+subdir)
00069 datalines = data.readlines()
00070 for line in datalines:
00071 line = line.rstrip()
00072 file = line.split()[8]
00073 if file != "":
00074 result.append('/store/relval/'+os.environ['DBS_RELEASE']+'/'+os.environ['DBS_SAMPLE']+'/'+os.environ['DBS_TIER']+'/'+os.environ['DBS_COND']+'/'+subdir+'/'+file)
00075 data.close()
00076
00077 elif os.environ['DBS_STRATEGY'] == "lsf":
00078
00079 dbs_path = '/'+os.environ['DBS_SAMPLE']+'/'+os.environ['DBS_RELEASE']+'-'+os.environ['DBS_COND']+'/'+os.environ['DBS_TIER']+'"'
00080 if __name__ == "__main__":
00081 print 'dbs path:',dbs_path
00082 data = os.popen('dbs lsf --path="'+dbs_path+'"')
00083 datalines = data.readlines()
00084 data.close()
00085 result = []
00086 for line in datalines:
00087 line = line.rstrip()
00088 if line != "" and line[0] =="/":
00089 result.append(line)
00090
00091 else:
00092
00093 input = "find file"
00094 separator = " where "
00095 if os.environ['DBS_RELEASE'] != "Any":
00096 input = input + separator + "release = " + os.environ['DBS_RELEASE']
00097 separator = " and "
00098 if os.environ['DBS_SAMPLE'] != "Any":
00099 input = input + separator + "primds = " + os.environ['DBS_SAMPLE']
00100 separator = " and "
00101 if os.environ['DBS_RUN'] != "Any":
00102 input = input + separator + "run = " + os.environ['DBS_RUN']
00103 separator = " and "
00104 input = input + separator + "dataset like *" + os.environ['DBS_COND'] + "*" + dbs_tier + "*"
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131 data = os.popen('dbs search --url="https://cmsdbsprod.cern.ch/cms_dbs_prod_global/servlet/DBSServlet" --query "'+input+'"')
00132 datalines = data.readlines()
00133 data.close()
00134 result = []
00135 for line in datalines:
00136 line = line.rstrip()
00137 if line != "" and line[0] =="/":
00138 result.append(line)
00139
00140 return result
00141
00142 def search():
00143 return common_search(os.environ['DBS_TIER'])
00144
00145 def search2():
00146 return common_search(os.environ['DBS_TIER_SECONDARY'])
00147
00148
00149
00150