CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes
tier0.Tier0Handler Class Reference
Inheritance diagram for tier0.Tier0Handler:

Public Member Functions

def __init__ (self, uri, timeOut, retries, retryPeriod, proxy, debug)
 
def getFirstSafeRun (self)
 
def getGlobalTag (self, config)
 
def setDebug (self)
 
def setProxy (self, proxy)
 
def unsetDebug (self)
 

Private Member Functions

def _queryTier0DataSvc (self, url)
 

Private Attributes

 _debug
 
 _proxy
 
 _retries
 
 _retryPeriod
 
 _timeOut
 
 _uri
 

Detailed Description

Definition at line 65 of file tier0.py.

Constructor & Destructor Documentation

◆ __init__()

def tier0.Tier0Handler.__init__ (   self,
  uri,
  timeOut,
  retries,
  retryPeriod,
  proxy,
  debug 
)
Parameters:
uri: Tier0DataSvc URI;
timeOut: time out for Tier0DataSvc HTTPS calls;
retries: maximum retries for Tier0DataSvc HTTPS calls;
retryPeriod: sleep time between two Tier0DataSvc HTTPS calls;
proxy: HTTP proxy for accessing Tier0DataSvc HTTPS calls;
debug: if set to True, enables debug information.

Definition at line 67 of file tier0.py.

67  def __init__( self, uri, timeOut, retries, retryPeriod, proxy, debug ):
68  """
69  Parameters:
70  uri: Tier0DataSvc URI;
71  timeOut: time out for Tier0DataSvc HTTPS calls;
72  retries: maximum retries for Tier0DataSvc HTTPS calls;
73  retryPeriod: sleep time between two Tier0DataSvc HTTPS calls;
74  proxy: HTTP proxy for accessing Tier0DataSvc HTTPS calls;
75  debug: if set to True, enables debug information.
76  """
77  self._uri = uri
78  self._timeOut = timeOut
79  self._retries = retries
80  self._retryPeriod = retryPeriod
81  self._proxy = proxy
82  self._debug = debug
83 
def __init__(self, dataset, job_number, job_id, job_name, isDA, isMC, applyBOWS, applyEXTRACOND, extraconditions, runboundary, lumilist, intlumi, maxevents, gt, allFromGT, alignmentDB, alignmentTAG, apeDB, apeTAG, bowDB, bowTAG, vertextype, tracktype, refittertype, ttrhtype, applyruncontrol, ptcut, CMSSW_dir, the_dir)

Member Function Documentation

◆ _queryTier0DataSvc()

def tier0.Tier0Handler._queryTier0DataSvc (   self,
  url 
)
private
Queries Tier0DataSvc.
url: Tier0DataSvc URL.
@returns: dictionary, from whence the required information must be retrieved according to the API call.
Raises if connection error, bad response, or timeout after retries occur.

Definition at line 93 of file tier0.py.

References EcalMatacqAnalyzer._debug, tier0.Tier0Handler._debug, EcalABAnalyzer._debug, uploads.uploader._debug, EcalLaserAnalyzer2._debug, EcalLaserAnalyzer._debug, tier0.Tier0Handler._proxy, tier0.Tier0Handler._retries, tier0.Tier0Handler._timeOut, join(), python.rootplot.root2matplotlib.replace(), and str.

Referenced by FrontierCondition_GT_autoExpress_cfi.Tier0Handler.getFirstSafeRun(), tier0.Tier0Handler.getFirstSafeRun(), FrontierCondition_GT_autoExpress_cfi.Tier0Handler.getGlobalTag(), and tier0.Tier0Handler.getGlobalTag().

93  def _queryTier0DataSvc( self, url ):
94  """
95  Queries Tier0DataSvc.
96  url: Tier0DataSvc URL.
97  @returns: dictionary, from whence the required information must be retrieved according to the API call.
98  Raises if connection error, bad response, or timeout after retries occur.
99  """
100 
101  userAgent = "User-Agent: ConditionWebServices/1.0 python/%d.%d.%d PycURL/%s" % ( sys.version_info[ :3 ] + ( pycurl.version_info()[ 1 ], ) )
102 
103  proxy = ""
104  if self._proxy: proxy = ' --proxy=%s ' % self._proxy
105 
106  debug = " -s -S "
107  if self._debug: debug = " -v "
108 
109  cmd = '/usr/bin/curl -k -L --user-agent "%s" %s --connect-timeout %i --retry %i %s %s ' % (userAgent, proxy, self._timeOut, self._retries, debug, url)
110 
111  # time the curl to understand if re-tries have been carried out
112  start = time.time()
113  process = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
114  (stdoutdata, stderrdata) = process.communicate()
115  retcode = process.returncode
116  end = time.time()
117 
118  if retcode != 0 or stderrdata:
119 
120  # if the first curl has failed, logg its stderror and prepare and independent retry
121  msg = "looks like curl returned an error: retcode=%s and took %s seconds" % (retcode,(end-start),)
122  msg += ' msg = "'+str(stderrdata)+'"'
123  logging.error(msg)
124 
125  time.sleep(10)
126  cmd = '/usr/bin/curl -k -L --user-agent "%s" %s --connect-timeout %i --retry %i %s %s ' % (userAgent, proxy, self._timeOut, self._retries, "-v", url)
127  process = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
128  (stdoutdata, stderrdata) = process.communicate()
129  retcode = process.returncode
130  if retcode != 0:
131  msg = "looks like curl returned an error for the second time: retcode=%s" % (retcode,)
132  msg += ' msg = "'+str(stderrdata)+'"'
133  logging.error(msg)
134  raise Tier0Error(msg)
135  else :
136  msg = "curl returned ok upon the second try"
137  logging.info(msg)
138  resp = json.loads( ''.join(stdoutdata.decode()).replace( "'", '"').replace(' None', ' "None"') )
139  return resp
140 
141 
def replace(string, replacements)
static std::string join(char **cmd)
Definition: RemoteFile.cc:21
#define str(s)

◆ getFirstSafeRun()

def tier0.Tier0Handler.getFirstSafeRun (   self)
Queries Tier0DataSvc to get the first condition safe run.
Parameters:
@returns: integer, the run number.
Raises if connection error, bad response, timeout after retries occur, or if the run number is not available.

Definition at line 142 of file tier0.py.

References tier0.Tier0Handler._proxy, tier0.Tier0Handler._queryTier0DataSvc(), tier0.Tier0Handler._uri, createfilelist.int, and str.

142  def getFirstSafeRun( self ):
143  """
144  Queries Tier0DataSvc to get the first condition safe run.
145  Parameters:
146  @returns: integer, the run number.
147  Raises if connection error, bad response, timeout after retries occur, or if the run number is not available.
148  """
149  firstConditionSafeRunAPI = "firstconditionsaferun"
150  safeRunDict = self._queryTier0DataSvc( os.path.join( self._uri, firstConditionSafeRunAPI ) )
151  if safeRunDict is None:
152  errStr = """First condition safe run is not available in Tier0DataSvc from URL \"%s\"""" %( os.path.join( self._uri, firstConditionSafeRunAPI ), )
153  if self._proxy:
154  errStr += """ using proxy \"%s\".""" %( str( self._proxy ), )
155  raise Tier0Error( errStr )
156  return int(safeRunDict['result'][0])
157 
#define str(s)

◆ getGlobalTag()

def tier0.Tier0Handler.getGlobalTag (   self,
  config 
)
Queries Tier0DataSvc to get the most recent Global Tag for a given workflow.
Parameters:
config: Tier0DataSvc API call for the workflow to be looked for;
@returns: a string with the Global Tag name.
Raises if connection error, bad response, timeout after retries occur, or if no Global Tags are available.

Definition at line 158 of file tier0.py.

References tier0.Tier0Handler._proxy, tier0.Tier0Handler._queryTier0DataSvc(), tier0.Tier0Handler._uri, str, and tier0.unique().

158  def getGlobalTag( self, config ):
159  """
160  Queries Tier0DataSvc to get the most recent Global Tag for a given workflow.
161  Parameters:
162  config: Tier0DataSvc API call for the workflow to be looked for;
163  @returns: a string with the Global Tag name.
164  Raises if connection error, bad response, timeout after retries occur, or if no Global Tags are available.
165  """
166  data = self._queryTier0DataSvc( os.path.join( self._uri, config ) )
167  gtnames = sorted(unique( [ str( di[ 'global_tag' ] ) for di in data['result'] if di[ 'global_tag' ] is not None ] ))
168  try:
169  recentGT = gtnames[-1]
170  return recentGT
171  except IndexError:
172  errStr = """No Global Tags for \"%s\" are available in Tier0DataSvc from URL \"%s\"""" %( config, os.path.join( self._uri, config ) )
173  if self._proxy:
174  errStr += """ using proxy \"%s\".""" %( str( self._proxy ), )
175  raise Tier0Error( errStr )
176 
177 
def unique(seq, keepstr=True)
Definition: tier0.py:24
#define str(s)

◆ setDebug()

def tier0.Tier0Handler.setDebug (   self)

Definition at line 84 of file tier0.py.

References EcalMatacqAnalyzer._debug, tier0.Tier0Handler._debug, EcalABAnalyzer._debug, uploads.uploader._debug, EcalLaserAnalyzer2._debug, and EcalLaserAnalyzer._debug.

84  def setDebug( self ):
85  self._debug = True
86 

◆ setProxy()

def tier0.Tier0Handler.setProxy (   self,
  proxy 
)

Definition at line 90 of file tier0.py.

References tier0.Tier0Handler._proxy.

90  def setProxy( self, proxy ):
91  self._proxy = proxy
92 

◆ unsetDebug()

def tier0.Tier0Handler.unsetDebug (   self)

Definition at line 87 of file tier0.py.

References EcalMatacqAnalyzer._debug, tier0.Tier0Handler._debug, EcalABAnalyzer._debug, uploads.uploader._debug, EcalLaserAnalyzer2._debug, and EcalLaserAnalyzer._debug.

87  def unsetDebug( self ):
88  self._debug = False
89 

Member Data Documentation

◆ _debug

tier0.Tier0Handler._debug
private

◆ _proxy

tier0.Tier0Handler._proxy
private

◆ _retries

tier0.Tier0Handler._retries
private

◆ _retryPeriod

tier0.Tier0Handler._retryPeriod
private

Definition at line 80 of file tier0.py.

◆ _timeOut

tier0.Tier0Handler._timeOut
private

◆ _uri

tier0.Tier0Handler._uri
private