1 from __future__
import print_function
15 tier0Url =
'https://cmsweb.cern.ch/t0wmadatasvc/prod/' 27 if t
in (unicode, str):
28 t = (list,
t(
'').join)[
bool(keepstr)]
32 return t(c
for c
in seq
if (c
in remaining
and not remaining.remove(c)))
35 from itertools
import groupby
36 s = sorted(enumerate(seq),key=
lambda i_v1:(i_v1[1],i_v1[0]))
37 return t(
next(g)
for k,g
in groupby(s,
lambda i_v: i_v[1]))
40 return t(c
for c
in seq
if not (c
in seen
or seen.append(c)))
44 def __init__( self, curl, response, proxy, timeout ):
45 super( ResponseError, self ).
__init__( response )
46 self.
args += ( curl, proxy )
50 errStr =
"""Wrong response for curl connection to Tier0DataSvc from URL \"%s\"""" %( self.
args[1].getinfo( self.
args[1].EFFECTIVE_URL ), )
52 errStr +=
""" using proxy \"%s\"""" %(
str( self.
args[ -1 ] ), )
53 errStr +=
""" with timeout \"%d\" with error code \"%d\".""" %( self.
timeout, self.
args[1].getinfo( self.
args[1].RESPONSE_CODE) )
55 errStr +=
"""\nFull response: \"%s\".""" %( self.
args[0].partition(
'<p>')[-1].rpartition(
'</p>')[0], )
57 errStr +=
"""\nFull response: \"%s\".""" %( self.
args[0], )
68 def __init__( self, uri, timeOut, retries, retryPeriod, proxy, debug ):
71 uri: Tier0DataSvc URI; 72 timeOut: time out for Tier0DataSvc HTTPS calls; 73 retries: maximum retries for Tier0DataSvc HTTPS calls; 74 retryPeriod: sleep time between two Tier0DataSvc HTTPS calls; 75 proxy: HTTP proxy for accessing Tier0DataSvc HTTPS calls; 76 debug: if set to True, enables debug information. 97 url: Tier0DataSvc URL. 98 @returns: dictionary, from whence the required information must be retrieved according to the API call. 99 Raises if connection error, bad response, or timeout after retries occur. 102 userAgent =
"User-Agent: ConditionWebServices/1.0 python/%d.%d.%d PycURL/%s" % ( sys.version_info[ :3 ] + ( pycurl.version_info()[ 1 ], ) )
108 if self.
_debug: debug =
" -v " 110 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)
114 process = subprocess.Popen(cmd, shell=
True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
115 (stdoutdata, stderrdata) = process.communicate()
116 retcode = process.returncode
119 if retcode != 0
or stderrdata:
121 msg =
"looks like curl returned an error: retcode=%s and took %s seconds" % (retcode,(end-start),)
122 msg +=
' msg = "'+
str(stderrdata)+
'"' 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
131 msg =
"looks like curl returned an error for the second time: retcode=%s" % (retcode,)
132 msg +=
' msg = "'+
str(stderrdata)+
'"' 136 msg =
"curl returned ok upon the second try" 139 return json.loads(
''.
join(stdoutdata).
replace(
"'",
'"').
replace(
' None',
' "None"') )
144 Queries Tier0DataSvc to get the first condition safe run. 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. 149 firstConditionSafeRunAPI =
"firstconditionsaferun" 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 ), )
154 errStr +=
""" using proxy \"%s\".""" %(
str( self.
_proxy ), )
156 return int(safeRunDict[
'result'][0])
160 Queries Tier0DataSvc to get the most recent Global Tag for a given workflow. 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. 167 gtnames = sorted(
unique( [
str( di[
'global_tag' ] )
for di
in data[
'result']
if di[
'global_tag' ]
is not None ] ))
169 recentGT = gtnames[-1]
172 errStr =
"""No Global Tags for \"%s\" are available in Tier0DataSvc from URL \"%s\"""" %( config, os.path.join( self.
_uri, config ) )
174 errStr +=
""" using proxy \"%s\".""" %(
str( self.
_proxy ), )
181 print(
' fcsr = %s (%s)' % (t0.getFirstSafeRun(), type(t0.getFirstSafeRun()) ))
182 print(
' reco_config = %s' % t0.getGlobalTag(
'reco_config'))
183 print(
' express_config = %s' % t0.getGlobalTag(
'express_config'))
187 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)