1 from __future__
import print_function
14 tier0Url =
'https://cmsweb.cern.ch/t0wmadatasvc/prod/' 26 if t
in (unicode, str):
27 t = (list,
t(
'').join)[
bool(keepstr)]
31 return t(c
for c
in seq
if (c
in remaining
and not remaining.remove(c)))
34 from itertools
import groupby
35 s = sorted(enumerate(seq),key=
lambda i_v1:(i_v1[1],i_v1[0]))
36 return t(
next(g)
for k,g
in groupby(s,
lambda i_v: i_v[1]))
39 return t(c
for c
in seq
if not (c
in seen
or seen.append(c)))
43 def __init__( self, curl, response, proxy, timeout ):
44 super( ResponseError, self ).
__init__( response )
45 self.
args += ( curl, proxy )
49 errStr =
"""Wrong response for curl connection to Tier0DataSvc from URL \"%s\"""" %( self.
args[1].getinfo( self.
args[1].EFFECTIVE_URL ), )
51 errStr +=
""" using proxy \"%s\"""" %(
str( self.
args[ -1 ] ), )
52 errStr +=
""" with timeout \"%d\" with error code \"%d\".""" %( self.
timeout, self.
args[1].getinfo( self.
args[1].RESPONSE_CODE) )
54 errStr +=
"""\nFull response: \"%s\".""" %( self.
args[0].partition(
'<p>')[-1].rpartition(
'</p>')[0], )
56 errStr +=
"""\nFull response: \"%s\".""" %( self.
args[0], )
67 def __init__( self, uri, timeOut, retries, retryPeriod, proxy, debug ):
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. 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. 101 userAgent =
"User-Agent: ConditionWebServices/1.0 python/%d.%d.%d PycURL/%s" % ( sys.version_info[ :3 ] + ( pycurl.version_info()[ 1 ], ) )
107 if self.
_debug: debug =
" -v " 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)
113 process = subprocess.Popen(cmd, shell=
True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
114 (stdoutdata, stderrdata) = process.communicate()
115 retcode = process.returncode
118 if retcode != 0
or stderrdata:
120 msg =
"looks like curl returned an error: retcode=%s and took %s seconds" % (retcode,(end-start),)
121 msg +=
' msg = "'+
str(stderrdata)+
'"' 125 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)
126 process = subprocess.Popen(cmd, shell=
True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
127 (stdoutdata, stderrdata) = process.communicate()
128 retcode = process.returncode
130 msg =
"looks like curl returned an error for the second time: retcode=%s" % (retcode,)
131 msg +=
' msg = "'+
str(stderrdata)+
'"' 135 msg =
"curl returned ok upon the second try" 138 return json.loads(
''.
join(stdoutdata).
replace(
"'",
'"').
replace(
' None',
' "None"') )
143 Queries Tier0DataSvc to get the first condition safe run. 145 @returns: integer, the run number. 146 Raises if connection error, bad response, timeout after retries occur, or if the run number is not available. 148 firstConditionSafeRunAPI =
"firstconditionsaferun" 150 if safeRunDict
is None:
151 errStr =
"""First condition safe run is not available in Tier0DataSvc from URL \"%s\"""" %( os.path.join( self.
_uri, firstConditionSafeRunAPI ), )
153 errStr +=
""" using proxy \"%s\".""" %(
str( self.
_proxy ), )
155 return int(safeRunDict[
'result'][0])
159 Queries Tier0DataSvc to get the most recent Global Tag for a given workflow. 161 config: Tier0DataSvc API call for the workflow to be looked for; 162 @returns: a string with the Global Tag name. 163 Raises if connection error, bad response, timeout after retries occur, or if no Global Tags are available. 166 gtnames = sorted(
unique( [
str( di[
'global_tag' ] )
for di
in data[
'result']
if di[
'global_tag' ]
is not None ] ))
168 recentGT = gtnames[-1]
171 errStr =
"""No Global Tags for \"%s\" are available in Tier0DataSvc from URL \"%s\"""" %( config, os.path.join( self.
_uri, config ) )
173 errStr +=
""" using proxy \"%s\".""" %(
str( self.
_proxy ), )
180 print(
' fcsr = %s (%s)' % (t0.getFirstSafeRun(), type(t0.getFirstSafeRun()) ))
181 print(
' reco_config = %s' % t0.getGlobalTag(
'reco_config'))
182 print(
' express_config = %s' % t0.getGlobalTag(
'express_config'))
186 if __name__ ==
'__main__':
def getFirstSafeRun(self)
def __init__(self, message)
def replace(string, replacements)
def _queryTier0DataSvc(self, url)
S & print(S &os, JobReport::InputFile const &f)
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
def getGlobalTag(self, config)
def _raise_http_error(curl, response, proxy, timeout)
def __init__(self, uri, timeOut, retries, retryPeriod, proxy, debug)
def unique(seq, keepstr=True)
def __init__(self, curl, response, proxy, timeout)
static std::string join(char **cmd)
def setProxy(self, proxy)