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 71 of file das.py.

References edm.print().

Referenced by main(), and query().

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

Definition at line 55 of file das.py.

References cmsPerfStripChart.dict, and str.

Referenced by main(), and deep_tau::DeepTauBase::Output.Output().

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

Definition at line 123 of file das.py.

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

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

Definition at line 6 of file das.py.

References get_data(), edm.print(), and digitizers_cfi.strip.

Referenced by MonitorElementsDb.analyze(), l1t::OMDSReader.basicQuery(), l1t::OMDSReader.basicQueryGenericKey(), l1t::OMDSReader.basicQueryView(), cvtChar(), SiStripCoralIface.doNameQuery(), SiStripCoralIface.doQuery(), SiStripCoralIface.doSettingsQuery(), cond::CredentialStore.exportAll(), HcalQIEManager.getHfQieTable(), RPCDCCLinkMapHandler.getNewObjects(), RPCLBLinkMapHandler.getNewObjects(), cond.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().

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

Variable Documentation

das.__author__
private

Definition at line 8 of file das.py.