CMS 3D CMS Logo

Functions | Variables

electronDataDiscovery Namespace Reference

Functions

def common_search
def search
def search2

Variables

tuple dd_cond_re = re.compile(os.environ['DD_COND'].replace('*','.*'))
tuple dd_release_re = re.compile(os.environ['DD_RELEASE'].replace('*','.*'))
tuple dd_run_re = re.compile(os.environ['DD_RUN'].replace('*','.*'))
tuple dd_sample_re = re.compile(os.environ['DD_SAMPLE'].replace('*','.*'))
tuple files = dd.search()

Function Documentation

def electronDataDiscovery::common_search (   dd_tier)

Definition at line 55 of file electronDataDiscovery.py.

00056                           :
00057 
00058   dd_tier_re = re.compile(dd_tier.replace('*','.*')) ;
00059 
00060   if os.environ['DD_SOURCE'] == "das":
00061   
00062     query = "dataset instance=cms_dbs_prod_global"
00063     if os.environ['DD_RELEASE'] != "" :
00064       query = query + " release=" + os.environ['DD_RELEASE']
00065     if os.environ['DD_SAMPLE'] != "":
00066       query = query + " primary_dataset=" + os.environ['DD_SAMPLE']
00067     if dd_tier != "":
00068       query = query + " tier=" + dd_tier
00069     if os.environ['DD_COND'] != "":
00070       query = query + " dataset=*" + os.environ['DD_COND'] + "*"
00071     if os.environ['DD_RUN'] != "":
00072       query = query + " run=" + os.environ['DD_RUN']
00073     #query = query + " | unique" # too long ??
00074     
00075     #data = os.popen('das_client.py --limit=0 --query "'+query+'"')
00076     #datalines = data.readlines()
00077     #data.close()
00078     #datasets = []
00079     #for line in datalines:
00080     #  line = line.rstrip()
00081     #  if line != "" and line[0] =="/":
00082     #    datasets.append(line)
00083     #dataset = datasets[0]
00084     
00085     data = das_client.json.loads(das_client.get_data('https://cmsweb.cern.ch',query,0,0,0))
00086             
00087     if data['nresults']==0:
00088       print '[electronDataDiscovery.py] No DAS dataset for query:', query
00089       return []
00090     while data['nresults']>1:
00091       if data['data'][0]['dataset'][0]['name']==data['data'][1]['dataset'][0]['name']:
00092         data['data'].pop(0)
00093         data['nresults'] -= 1
00094       else:
00095         print '[electronDataDiscovery.py] Several DAS datasets for query:', query
00096         for i in range(data['nresults']):
00097           print '[electronDataDiscovery.py] dataset['+str(i)+']: '+data['data'][i]['dataset'][0]['name']
00098         return []
00099 
00100     dataset = data['data'][0]['dataset'][0]['name']
00101     
00102     query = "file instance=cms_dbs_prod_global dataset="+dataset
00103     
00104     #data = os.popen('das_client.py --limit=0 --query "'+query+'"')
00105     #datalines = data.readlines()
00106     #data.close()
00107     #result = []
00108     #for line in datalines:
00109     #  line = line.rstrip()
00110     #  if line != "" and line[0] =="/":
00111     #    result.append(line)
00112     
00113     data = das_client.json.loads(das_client.get_data('https://cmsweb.cern.ch',query,0,0,0))
00114     
00115     if data['nresults']==0:
00116       print '[electronDataDiscovery.py] No DAS file in dataset:', dataset
00117       return []
00118       
00119     result = []
00120     for i in range(0,data['nresults']):
00121       result.append(str(data['data'][i]['file'][0]['name']))
00122     
00123   elif os.environ['DD_SOURCE'] == "dbs":
00124   
00125     input = "find file"
00126     separator = " where "
00127     if os.environ['DD_RELEASE'] != "":
00128       input = input + separator + "release = " + os.environ['DD_RELEASE']
00129       separator = " and "
00130     if os.environ['DD_SAMPLE'] != "":
00131       input = input + separator + "primds = " + os.environ['DD_SAMPLE']
00132       separator = " and "
00133     if os.environ['DD_RUN'] != "":
00134       input = input + separator + "run = " + os.environ['DD_RUN']
00135       separator = " and "
00136     input = input + separator + "dataset like *" + os.environ['DD_COND'] + "*" + dd_tier + "*"
00137     
00138     data = os.popen('dbs search --url="http://cmsdbsprod.cern.ch/cms_dbs_prod_global/servlet/DBSServlet" --query "'+input+'"')
00139     datalines = data.readlines()
00140     data.close()
00141     result = []
00142     for line in datalines:
00143       line = line.rstrip()
00144       if line != "" and line[0] =="/":
00145         result.append(line)
00146     
00147   elif os.environ['DD_SOURCE'] == "http":
00148   
00149     input = "find file"
00150     separator = " where "
00151     if os.environ['DD_RELEASE'] != "":
00152       input = input + separator + "release = " + os.environ['DD_RELEASE']
00153       separator = " and "
00154     if os.environ['DD_SAMPLE'] != "":
00155       input = input + separator + "primds = " + os.environ['DD_SAMPLE']
00156       separator = " and "
00157     if os.environ['DD_RUN'] != "":
00158       input = input + separator + "run = " + os.environ['DD_RUN']
00159       separator = " and "
00160     input = input + separator + "dataset like *" + os.environ['DD_COND'] + "*" + dd_tier + "*"
00161     
00162     url = "https://cmsweb.cern.ch:443/dbs_discovery/aSearch"
00163     final_input = urllib.quote(input) ;
00164     
00165     agent   = "Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)"
00166     ctypes  = "text/plain"
00167     headers = { 'User-Agent':agent, 'Accept':ctypes}
00168     params  = {'dbsInst':'cms_dbs_prod_global',
00169                'html':0,'caseSensitive':'on','_idx':0,'pagerStep':-1,
00170                'userInput':final_input,
00171                'xml':0,'details':0,'cff':0,'method':'dbsapi'}
00172     data    = urllib.urlencode(params,doseq=True)
00173     req     = urllib2.Request(url, data, headers)
00174     data    = ""
00175     
00176     try:
00177       response = urllib2.urlopen(req)
00178       data = response.read()
00179     except urllib2.HTTPError, e:
00180       if e.code==201:
00181         print e.headers       
00182         print e.msg
00183         pass
00184       else:
00185         raise e
00186 
00187     datalines = data.readlines()
00188     data.close()
00189     result = []
00190     for line in datalines:
00191       line = line.rstrip()
00192       if line != "" and line[0] =="/":
00193         result.append(line)
00194     
00195   elif os.environ['DD_SOURCE'] == "lsf":
00196   
00197     dbs_path = '/'+os.environ['DD_SAMPLE']+'/'+os.environ['DD_RELEASE']+'-'+os.environ['DD_COND']+'/'+os.environ['DD_TIER']+'"'
00198     if __name__ == "__main__":
00199       print 'dbs path:',dbs_path
00200     data = os.popen('dbs lsf --path="'+dbs_path+'"')
00201     datalines = data.readlines()
00202     data.close()
00203     result = []
00204     for line in datalines:
00205       line = line.rstrip()
00206       if line != "" and line[0] =="/":
00207         result.append(line)
00208       
00209   elif os.environ['DD_SOURCE'].startswith('/castor/cern.ch/cms/'): # assumed to be a castor dir
00210   
00211     castor_dir = os.environ['DD_SOURCE'].replace('/castor/cern.ch/cms/','/',1)
00212     result = []
00213     data = os.popen('rfdir /castor/cern.ch/cms'+castor_dir)
00214     subdirs = data.readlines()
00215     data.close()
00216     datalines = []
00217     for line in subdirs:
00218       line = line.rstrip()
00219       subdir = line.split()[8]
00220       data = os.popen('rfdir /castor/cern.ch/cms'+castor_dir+'/'+subdir)
00221       datalines = data.readlines()
00222       for line in datalines:
00223         line = line.rstrip()
00224         file = line.split()[8]
00225         if file != "":
00226           result.append(castor_dir+'/'+subdir+'/'+file)
00227       data.close()
00228       
00229   elif os.environ['DD_SOURCE'].startswith('/eos/cms/'): # assumed to be an eos dir
00230   
00231     data = os.popen('/afs/cern.ch/project/eos/installation/pro/bin/eos.select find -f '+os.environ['DD_SOURCE'])
00232     lines = data.readlines()
00233     data.close()
00234     result = []
00235     for line in lines:
00236       line = line.strip().replace('/eos/cms/','/',1)
00237       if line == "": continue
00238       if dd_sample_re.search(line) == None: continue
00239       if dd_cond_re.search(line) == None: continue
00240       if dd_tier_re.search(line) == None: continue
00241       if dd_run_re.search(line) == None: continue
00242       result.append(line)
00243       
00244   else: # os.environ['DD_SOURCE'] is assumed to be a file name
00245   
00246     result = []
00247     for line in open(os.environ['DD_SOURCE']).readlines():
00248       line = os.path.expandvars(line.strip())
00249       if line == "": continue
00250       if dd_sample_re.search(line) == None: continue
00251       if dd_cond_re.search(line) == None: continue
00252       if dd_tier_re.search(line) == None: continue
00253       if dd_run_re.search(line) == None: continue
00254       result.append(line)
00255       
00256     if len(result)==0:
00257       diag = '[electronDataDiscovery.py] No more files after filtering with :'
00258       if os.environ['DD_SAMPLE']!='': diag += ' ' + os.environ['DD_SAMPLE']
00259       if os.environ['DD_COND']!='': diag += ' ' + os.environ['DD_COND']
00260       if dd_tier!='': diag += ' ' + dd_tier
00261       if os.environ['DD_RUN']!='': diag += ' ' + os.environ['DD_RUN']
00262       print diag
00263       
00264   return result

def electronDataDiscovery::search ( )

Definition at line 265 of file electronDataDiscovery.py.

Referenced by AlignmentMonitorTemplate::event().

00266             :
00267   return common_search(os.environ['DD_TIER'])

def electronDataDiscovery::search2 ( )

Definition at line 268 of file electronDataDiscovery.py.

00269              :
00270   return common_search(os.environ['DD_TIER_SECONDARY'])
00271 
00272         
00273         
00274 

Variable Documentation

tuple electronDataDiscovery::dd_cond_re = re.compile(os.environ['DD_COND'].replace('*','.*'))

Definition at line 52 of file electronDataDiscovery.py.

tuple electronDataDiscovery::dd_release_re = re.compile(os.environ['DD_RELEASE'].replace('*','.*'))

Definition at line 50 of file electronDataDiscovery.py.

tuple electronDataDiscovery::dd_run_re = re.compile(os.environ['DD_RUN'].replace('*','.*'))

Definition at line 53 of file electronDataDiscovery.py.

tuple electronDataDiscovery::dd_sample_re = re.compile(os.environ['DD_SAMPLE'].replace('*','.*'))

Definition at line 51 of file electronDataDiscovery.py.

tuple electronDataDiscovery::files = dd.search()

Definition at line 10 of file electronDataDiscovery.py.