Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:15:59

0001 import sys
0002 import json
0003 import das_client
0004 
0005 def dasFileQuery(dataset):
0006   query   = 'dataset dataset=%s' % dataset
0007   host    = 'https://cmsweb.cern.ch'      # default
0008   idx     = 0                             # default
0009   limit   = 0                             # unlimited
0010   debug   = 0                             # default
0011   thr     = 300                           # default
0012   ckey    = ""                            # default
0013   cert    = ""                            # default
0014   jsondict = das_client.get_data(host, query, idx, limit, debug, thr, ckey, cert)
0015 
0016   # check if the pattern matches none, many, or one dataset
0017   if not jsondict['data'] or not jsondict['data'][0]['dataset']:
0018     sys.stderr.write('Error: the pattern "%s" does not match any dataset\n' % dataset)
0019     sys.exit(1)
0020     return []
0021   elif len(jsondict['data']) > 1:
0022     sys.stderr.write('Error: the pattern "%s" matches multiple datasets\n' % dataset)
0023     for d in jsondict['data']:
0024       sys.stderr.write('    %s\n' % d['dataset'][0]['name'])
0025     sys.exit(1)
0026     return []
0027   else:
0028     # expand the dataset name
0029     dataset = jsondict['data'][0]['dataset'][0]['name']
0030     query = 'file dataset=%s' % dataset
0031     jsondict = das_client.get_data(host, query, idx, limit, debug, thr, ckey, cert)
0032     # parse the results in JSON format, and extract the list of files
0033     files = sorted( f['file'][0]['name'] for f in jsondict['data'] )
0034     return files
0035