CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Attributes
FrontierCondition_GT_autoExpress_cfi.Tier0DasInterface Class Reference

Public Member Functions

def __init__
 
def expressGlobalTag
 
def firstConditionSafeRun
 
def getData
 
def getResultList
 
def getValues
 
def lastPromptRun
 
def promptGlobalTag
 

Private Attributes

 _debug
 
 _maxretry
 
 _proxy
 
 _retry
 
 _t0DasBaseUrl
 

Detailed Description

Class handling common Tier0-DAS queries and connected utilities

Definition at line 20 of file FrontierCondition_GT_autoExpress_cfi.py.

Constructor & Destructor Documentation

def FrontierCondition_GT_autoExpress_cfi.Tier0DasInterface.__init__ (   self,
  url = 'https://cmsweb.cern.ch/t0wmadatasvc/prod/',
  proxy = None 
)

Member Function Documentation

def FrontierCondition_GT_autoExpress_cfi.Tier0DasInterface.expressGlobalTag (   self)
Query the GT currently used by express = GT used by the last run released for express.

Definition at line 192 of file FrontierCondition_GT_autoExpress_cfi.py.

References FrontierCondition_GT_autoExpress_cfi.Tier0DasInterface._t0DasBaseUrl, TkLasBeam.getData(), FrontierCondition_GT_autoExpress_cfi.Tier0DasInterface.getData(), DTKeyedConfigCache.getData(), DTPosNeg.getData(), SiStripThreshold.getData(), and FrontierCondition_GT_autoExpress_cfi.Tier0DasInterface.getResultList().

193  def expressGlobalTag(self):
194  """
195  Query the GT currently used by express = GT used by the last run released for express.
196  """
197  url = self._t0DasBaseUrl + "express_config"
198  #print "url =", url
199  try:
200  gt = "UNKNOWN"
201  json = self.getData(url)
202  results = self.getResultList(json)
203  config = ast.literal_eval(results[0])[0]
204  gt = config['global_tag']
205  # FIXME: do we realluy need to raise?
206  if gt == "UNKNOWN":
207  raise KeyError
208  return gt
209  except:
210  print "[Tier0DasInterface::expressGlobalTag] error"
211  raise
212  return None
213 
def FrontierCondition_GT_autoExpress_cfi.Tier0DasInterface.firstConditionSafeRun (   self)
Query to ge the run for which the Tier0 system considers safe the update to the conditions

Definition at line 155 of file FrontierCondition_GT_autoExpress_cfi.py.

References FrontierCondition_GT_autoExpress_cfi.Tier0DasInterface._t0DasBaseUrl, TkLasBeam.getData(), FrontierCondition_GT_autoExpress_cfi.Tier0DasInterface.getData(), DTKeyedConfigCache.getData(), DTPosNeg.getData(), SiStripThreshold.getData(), and FrontierCondition_GT_autoExpress_cfi.Tier0DasInterface.getResultList().

156  def firstConditionSafeRun(self):
157  """
158  Query to ge the run for which the Tier0 system considers safe the update to the conditions
159  """
160  url = self._t0DasBaseUrl + "firstconditionsaferun"
161  try:
162  json = self.getData(url)
163  results = self.getResultList(json)
164  return results[0]
165  except Exception as details:
166  print "[Tier0DasInterface::firstConditionSafeRun] error", details
167  raise
168  return 0
def FrontierCondition_GT_autoExpress_cfi.Tier0DasInterface.getData (   self,
  src,
  tout = 5 
)
Get the JSON file for a give query specified via the Tier0-DAS url.
Timeout can be set via paramter.

Definition at line 35 of file FrontierCondition_GT_autoExpress_cfi.py.

References FrontierCondition_GT_autoExpress_cfi.Tier0DasInterface._debug, EcalMatacqAnalyzer._debug, EcalABAnalyzer._debug, EcalLaserAnalyzer2._debug, EcalLaserAnalyzer._debug, FrontierCondition_GT_autoExpress_cfi.Tier0DasInterface._maxretry, FrontierCondition_GT_autoExpress_cfi.Tier0DasInterface._proxy, FrontierCondition_GT_autoExpress_cfi.Tier0DasInterface._retry, TkLasBeam.getData(), FrontierCondition_GT_autoExpress_cfi.Tier0DasInterface.getData(), DTKeyedConfigCache.getData(), DTPosNeg.getData(), and SiStripThreshold.getData().

Referenced by FrontierCondition_GT_autoExpress_cfi.Tier0DasInterface.expressGlobalTag(), FrontierCondition_GT_autoExpress_cfi.Tier0DasInterface.firstConditionSafeRun(), FrontierCondition_GT_autoExpress_cfi.Tier0DasInterface.getData(), FrontierCondition_GT_autoExpress_cfi.Tier0DasInterface.lastPromptRun(), and FrontierCondition_GT_autoExpress_cfi.Tier0DasInterface.promptGlobalTag().

35 
36  def getData(self, src, tout=5):
37  """
38  Get the JSON file for a give query specified via the Tier0-DAS url.
39  Timeout can be set via paramter.
40  """
41  # actually get the json file from the given url of the T0-Das service
42  # and returns the data
43 
44  try:
45  if self._proxy:
46  print "setting proxy"
47  opener = urllib2.build_opener(urllib2.HTTPHandler(),
48  urllib2.HTTPSHandler(),
49  urllib2.ProxyHandler({'http':self._proxy, 'https':self._proxy}))
50  urllib2.install_opener(opener)
51  req = urllib2.Request(src)
52  req.add_header("User-Agent",
53  "DQMIntegration/1.0 python/%d.%d.%d" % sys.version_info[:3])
54  req.add_header("Accept","application/json")
55  jsonCall = urllib2.urlopen(req, timeout = tout)
56  url = jsonCall.geturl()
57  except urllib2.HTTPError, error:
58  #print error.url
59  errStr = "Cannot retrieve Tier-0 DAS data from URL \"" + error.url + "\""
60  if self._proxy:
61  errStr += " using proxy \"" + self._proxy + "\""
62  print errStr
63  print error
64  raise urllib2.HTTPError("FIXME: handle exceptions")
65  except urllib2.URLError, error:
66  if self._retry < self._maxretry:
67  print 'Try # ' + str(self._retry) + " connection to Tier-0 DAS timed-out"
68  self._retry += 1
69  newtout = tout*self._retry
70  time.sleep(3*self._retry)
71  return self.getData(src,newtout)
72  else:
73  errStr = "Cannot retrieve Tier-0 DAS data from URL \"" + src + "\""
74  if self._proxy:
75  errStr += " using proxy \"" + self._proxy + "\""
76  self._retry = 0
77  print errStr
78  print error
79  raise urllib2.URLError('TimeOut reading ' + src)
80 
81  except:
82  raise
83  else:
84  if self._debug:
85  print url
86  jsonInfo = jsonCall.info()
87  if self._debug:
88  print jsonInfo
89  jsonText = jsonCall.read()
90  data = json.loads(jsonText)
91  if self._debug:
92  print "data:", data
93  return data
def FrontierCondition_GT_autoExpress_cfi.Tier0DasInterface.getResultList (   self,
  json 
)
Extractt the result list out of the JSON file

Definition at line 94 of file FrontierCondition_GT_autoExpress_cfi.py.

Referenced by FrontierCondition_GT_autoExpress_cfi.Tier0DasInterface.expressGlobalTag(), FrontierCondition_GT_autoExpress_cfi.Tier0DasInterface.firstConditionSafeRun(), FrontierCondition_GT_autoExpress_cfi.Tier0DasInterface.lastPromptRun(), and FrontierCondition_GT_autoExpress_cfi.Tier0DasInterface.promptGlobalTag().

94 
95  def getResultList(self, json):
96  """
97  Extractt the result list out of the JSON file
98  """
99  resultList = []
100  #FIXME try
101  resultList = json['result']
102 
103  #print self.getValues(json, 'result')
104  return resultList
def FrontierCondition_GT_autoExpress_cfi.Tier0DasInterface.getValues (   self,
  json,
  key,
  selection = '' 
)
Extract the value corrisponding to a given key from a JSON file. It is also possible to apply further selections.

Definition at line 105 of file FrontierCondition_GT_autoExpress_cfi.py.

106  def getValues(self, json, key, selection=''):
107  """
108  Extract the value corrisponding to a given key from a JSON file. It is also possible to apply further selections.
109  """
110  # lookup for a key in a json file applying possible selections
111  data = []
112  check = 0
113  if selection != '':
114  check = 1
115  (k, v) = selection
116 
117  for o in json:
118  #print o
119  try:
120  if check == 1:
121  if (o[k] == v):
122  data.append(o[key])
123  else:
124  data.append(o[key])
125  except KeyError as error:
126  print "[Tier0DasInterface::getValues] key: " + key + " not found in json file"
127  print error
128  raise
129  except:
130  print "[Tier0DasInterface::getValues] unknown error"
131  raise
132  #pass
133  #print data
134  return data
def FrontierCondition_GT_autoExpress_cfi.Tier0DasInterface.lastPromptRun (   self)
Query to get the last run released for prompt

Definition at line 135 of file FrontierCondition_GT_autoExpress_cfi.py.

References FrontierCondition_GT_autoExpress_cfi.Tier0DasInterface._t0DasBaseUrl, TkLasBeam.getData(), FrontierCondition_GT_autoExpress_cfi.Tier0DasInterface.getData(), DTKeyedConfigCache.getData(), DTPosNeg.getData(), SiStripThreshold.getData(), and FrontierCondition_GT_autoExpress_cfi.Tier0DasInterface.getResultList().

136  def lastPromptRun(self):
137  """
138  Query to get the last run released for prompt
139  """
140  url = self._t0DasBaseUrl + "reco_config"
141  try:
142  json = self.getData(url)
143  results = self.getResultList(json)
144  workflowlist = ast.literal_eval(results[0])
145  maxRun = -1
146  for workflow in workflowlist:
147  run = workflow['run']
148  if int(run) > maxRun:
149  maxRun = run
150  return maxRun
151  except:
152  print "[Tier0DasInterface::lastPromptRun] error"
153  raise
154  return 0
def FrontierCondition_GT_autoExpress_cfi.Tier0DasInterface.promptGlobalTag (   self,
  dataset 
)
Query the GT currently used by prompt = GT used by the last run released for prompt.

Definition at line 169 of file FrontierCondition_GT_autoExpress_cfi.py.

References FrontierCondition_GT_autoExpress_cfi.Tier0DasInterface._t0DasBaseUrl, TkLasBeam.getData(), FrontierCondition_GT_autoExpress_cfi.Tier0DasInterface.getData(), DTKeyedConfigCache.getData(), DTPosNeg.getData(), SiStripThreshold.getData(), and FrontierCondition_GT_autoExpress_cfi.Tier0DasInterface.getResultList().

170  def promptGlobalTag(self, dataset):
171  """
172  Query the GT currently used by prompt = GT used by the last run released for prompt.
173  """
174  url = self._t0DasBaseUrl + "reco_config"
175  #print "url =", url
176  try:
177  json = self.getData(url)
178  results = self.getResultList(json)
179  workflowlist = ast.literal_eval(results[0])
180  gt = "UNKNOWN"
181  for workflow in workflowlist:
182  if workflow['primary_dataset'] == dataset:
183  gt = workflow['global_tag']
184  # FIXME: do we realluy need to raise?
185  if gt == "UNKNOWN":
186  raise KeyError
187  return gt
188  except:
189  print "[Tier0DasInterface::promptGlobalTag] error"
190  raise
191  return None

Member Data Documentation

FrontierCondition_GT_autoExpress_cfi.Tier0DasInterface._debug
private

Definition at line 29 of file FrontierCondition_GT_autoExpress_cfi.py.

Referenced by FrontierCondition_GT_autoExpress_cfi.Tier0DasInterface.getData(), cmsPerfSuite.PerfSuite.optionParse(), and cmsPerfSuite.PerfSuite.runCmsReport().

FrontierCondition_GT_autoExpress_cfi.Tier0DasInterface._maxretry
private

Definition at line 31 of file FrontierCondition_GT_autoExpress_cfi.py.

Referenced by FrontierCondition_GT_autoExpress_cfi.Tier0DasInterface.getData().

FrontierCondition_GT_autoExpress_cfi.Tier0DasInterface._proxy
private

Definition at line 32 of file FrontierCondition_GT_autoExpress_cfi.py.

Referenced by FrontierCondition_GT_autoExpress_cfi.Tier0DasInterface.getData().

FrontierCondition_GT_autoExpress_cfi.Tier0DasInterface._retry
private

Definition at line 30 of file FrontierCondition_GT_autoExpress_cfi.py.

Referenced by FrontierCondition_GT_autoExpress_cfi.Tier0DasInterface.getData().

FrontierCondition_GT_autoExpress_cfi.Tier0DasInterface._t0DasBaseUrl
private

Definition at line 28 of file FrontierCondition_GT_autoExpress_cfi.py.

Referenced by FrontierCondition_GT_autoExpress_cfi.Tier0DasInterface.expressGlobalTag(), FrontierCondition_GT_autoExpress_cfi.Tier0DasInterface.firstConditionSafeRun(), FrontierCondition_GT_autoExpress_cfi.Tier0DasInterface.lastPromptRun(), and FrontierCondition_GT_autoExpress_cfi.Tier0DasInterface.promptGlobalTag().