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

def electronDataDiscovery::search ( )

Definition at line 258 of file electronDataDiscovery.py.

Referenced by AlignmentMonitorTemplate::event().

00259             :
00260   return common_search(os.environ['DD_TIER'])

def electronDataDiscovery::search2 ( )

Definition at line 261 of file electronDataDiscovery.py.

00262              :
00263   return common_search(os.environ['DD_TIER_SECONDARY'])
00264 
00265         
00266         
00267 

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.