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
00030
00031
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
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
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