CMS 3D CMS Logo

Classes | Functions | Variables
das Namespace Reference

Classes

class  DASOptionParser
 

Functions

def get_data (host, query, idx, limit, debug)
 
def get_value (data, filters)
 
def main ()
 
def query (query_str, verbose=False)
 

Variables

 __author__
 

Function Documentation

def das.get_data (   host,
  query,
  idx,
  limit,
  debug 
)
Contact DAS server and retrieve data for given DAS query

Definition at line 70 of file das.py.

Referenced by main(), and query().

70 def get_data(host, query, idx, limit, debug):
71  """Contact DAS server and retrieve data for given DAS query"""
72  params = {'input':query, 'idx':idx, 'limit':limit}
73  path = '/das/cache'
74  pat = re.compile('http[s]{0,1}://')
75  if not pat.match(host):
76  msg = 'Invalid hostname: %s' % host
77  raise Exception(msg)
78  url = host + path
79  headers = {"Accept": "application/json"}
80  encoded_data = urllib.urlencode(params, doseq=True)
81  url += '?%s' % encoded_data
82  req = urllib2.Request(url=url, headers=headers)
83  if debug:
84  hdlr = urllib2.HTTPHandler(debuglevel=1)
85  opener = urllib2.build_opener(hdlr)
86  else:
87  opener = urllib2.build_opener()
88  fdesc = opener.open(req)
89  data = fdesc.read()
90  fdesc.close()
91 
92  pat = re.compile(r'^[a-z0-9]{32}')
93  if data and isinstance(data, str) and pat.match(data) and len(data) == 32:
94  pid = data
95  else:
96  pid = None
97  count = 5 # initial waiting time in seconds
98  timeout = 30 # final waiting time in seconds
99  while pid:
100  params.update({'pid':data})
101  encoded_data = urllib.urlencode(params, doseq=True)
102  url = host + path + '?%s' % encoded_data
103  req = urllib2.Request(url=url, headers=headers)
104  try:
105  fdesc = opener.open(req)
106  data = fdesc.read()
107  fdesc.close()
108  except urllib2.HTTPError as err:
109  print err
110  return ""
111  if data and isinstance(data, str) and pat.match(data) and len(data) == 32:
112  pid = data
113  else:
114  pid = None
115  time.sleep(count)
116  if count < timeout:
117  count *= 2
118  else:
119  count = timeout
120  return data
121 
def get_data(host, query, idx, limit, debug)
Definition: das.py:70
def das.get_value (   data,
  filters 
)
Filter data from a row for given list of filters

Definition at line 54 of file das.py.

References cmsPerfStripChart.dict, and harvestTrackValidationPlots.str.

Referenced by main().

54 def get_value(data, filters):
55  """Filter data from a row for given list of filters"""
56  for ftr in filters:
57  if ftr.find('>') != -1 or ftr.find('<') != -1 or ftr.find('=') != -1:
58  continue
59  row = dict(data)
60  for key in ftr.split('.'):
61  if isinstance(row, dict) and key in row:
62  row = row[key]
63  if isinstance(row, list):
64  for item in row:
65  if isinstance(item, dict) and key in item:
66  row = item[key]
67  break
68  yield str(row)
69 
def get_value(data, filters)
Definition: das.py:54
def das.main ( )
Main function

Definition at line 122 of file das.py.

References get_data(), get_value(), and join().

122 def main():
123  """Main function"""
124  optmgr = DASOptionParser()
125  opts, _ = optmgr.get_opt()
126  host = opts.host
127  debug = opts.verbose
128  query = opts.query
129  idx = opts.idx
130  limit = opts.limit
131  if not query:
132  raise Exception('You must provide input query')
133  data = get_data(host, query, idx, limit, debug)
134  if opts.format == 'plain':
135  jsondict = json.loads(data)
136  mongo_query = jsondict['mongo_query']
137  if 'filters' in mongo_query:
138  filters = mongo_query['filters']
139  data = jsondict['data']
140  if isinstance(data, dict):
141  rows = [r for r in get_value(data, filters)]
142  print ' '.join(rows)
143  elif isinstance(data, list):
144  for row in data:
145  rows = [r for r in get_value(row, filters)]
146  print ' '.join(rows)
147  else:
148  print jsondict
149  else:
150  print data
151 
152 
def get_data(host, query, idx, limit, debug)
Definition: das.py:70
def main()
Definition: das.py:122
def get_value(data, filters)
Definition: das.py:54
static std::string join(char **cmd)
Definition: RemoteFile.cc:18
def das.query (   query_str,
  verbose = False 
)

Definition at line 5 of file das.py.

References get_data(), and digi_MixPreMix_cfi.strip.

Referenced by shallowTree_test_template.add_rawRelVals(), MonitorElementsDb.analyze(), l1t::OMDSReader.basicQuery(), l1t::OMDSReader.basicQueryGenericKey(), l1t::OMDSReader.basicQueryView(), cvtChar(), SiStripCoralIface.doNameQuery(), SiStripCoralIface.doQuery(), SiStripCoralIface.doSettingsQuery(), cond::CredentialStore.exportAll(), RunDCSLVDat.getBarrelRset(), RunDCSHVDat.getBarrelRset(), RunDCSHVDat.getEndcapAnodeRset(), RunDCSHVDat.getEndcapDynodeRset(), RunDCSLVDat.getEndcapRset(), HcalQIEManager.getHfQieTable(), RunDCSMagnetDat.getMagnetRset(), RPCDCCLinkMapHandler.getNewObjects(), RPCLBLinkMapHandler.getNewObjects(), getNextSequenceValue(), HcalQIEManager.getTableFromDb(), cond::CredentialStore.listConnections(), cond::CredentialStore.listPrincipals(), L1CaloHcalScaleConfigOnlineProd.newObject(), SiStripPayloadHandler< SiStripPayload >.queryConfigMap(), RunInfoRead.readData(), DQMSummaryReader.readData(), cond.selectAuthorization(), cond.selectConnection(), cond::CredentialStore.selectForUser(), cond::CredentialStore.selectPermissions(), cond.selectPrincipal(), and cond::CredentialStore.startSession().

5 def query(query_str, verbose=False):
6  'simple query function to interface with DAS, better than using Popen as everything is handled by python'
7  if verbose:
8  print 'querying DAS with: "%s"' % query_str
9  data = get_data(
10  'https://cmsweb.cern.ch',
11  query_str,
12  0, 0, False)
13 
14  to_get = query_str.split()[0].strip(',')
15  if data['status'] != 'ok':
16  raise RuntimeError('Das query crashed')
17 
18  #-1 works both when getting dataset from files and files from datasets,
19  #not checked on everything
20  return [i[to_get][-1]['name'] for i in data['data']]
21 
def query(query_str, verbose=False)
Definition: das.py:5
def get_data(host, query, idx, limit, debug)
Definition: das.py:70

Variable Documentation

das.__author__
private

Definition at line 7 of file das.py.