1 from __future__
import print_function
2 import FWCore.ParameterSet.Config
as cms
10 GlobalTag.globaltag =
"103X_dataRun2_Express_v2" 26 tier0Url =
'https://cmsweb.cern.ch/t0wmadatasvc/prod/' 37 if t
in (unicode, str):
38 t = (list,
t(
'').join)[
bool(keepstr)]
42 return t(c
for c
in seq
if (c
in remaining
and not remaining.remove(c)))
45 from itertools
import groupby
46 s = sorted(enumerate(seq),key=
lambda i_v1:(i_v1[1],i_v1[0]))
47 return t(
next(g)
for k,g
in groupby(s,
lambda i_v: i_v[1]))
50 return t(c
for c
in seq
if not (c
in seen
or seen.append(c)))
54 def __init__( self, uri, timeOut, retries, retryPeriod, proxy, debug ):
57 uri: Tier0DataSvc URI; 58 timeOut: time out for Tier0DataSvc HTTPS calls; 59 retries: maximum retries for Tier0DataSvc HTTPS calls; 60 retryPeriod: sleep time between two Tier0DataSvc HTTPS calls; 61 proxy: HTTP proxy for accessing Tier0DataSvc HTTPS calls; 62 debug: if set to True, enables debug information. 83 url: Tier0DataSvc URL. 84 @returns: dictionary, from whence the required information must be retrieved according to the API call. 85 Raises if connection error, bad response, or timeout after retries occur. 88 userAgent =
"User-Agent: DQMIntegration/2.0 python/%d.%d.%d PycURL/%s" % ( sys.version_info[ :3 ] + ( pycurl.version_info()[ 1 ], ) )
94 if self.
_debug: debug =
" -v " 96 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)
98 process = subprocess.Popen(cmd, shell=
True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
99 (stdoutdata, stderrdata) = process.communicate()
100 retcode = process.returncode
102 if retcode != 0
or stderrdata:
103 msg =
"looks like curl returned an error: retcode=%s" % (retcode,)
104 msg +=
' msg = "'+
str(stderrdata)+
'"' 107 return json.loads(
''.
join(stdoutdata).
replace(
"'",
'"').
replace(
' None',
' "None"') )
111 Queries Tier0DataSvc to get the first condition safe run. 113 @returns: integer, the run number. 114 Raises if connection error, bad response, timeout after retries occur, or if the run number is not available. 116 firstConditionSafeRunAPI =
"firstconditionsaferun" 118 if safeRunDict
is None:
119 errStr =
"""First condition safe run is not available in Tier0DataSvc from URL \"%s\" """ %( os.path.join( self.
_uri, firstConditionSafeRunAPI ), )
121 errStr +=
""" using proxy \"%s\".""" %(
str( self.
_proxy ), )
123 return int(safeRunDict[
'result'][0])
127 Queries Tier0DataSvc to get the most recent Global Tag for a given workflow. 129 config: Tier0DataSvc API call for the workflow to be looked for; 130 @returns: a string with the Global Tag name. 131 Raises if connection error, bad response, timeout after retries occur, or if no Global Tags are available. 134 gtnames = sorted(
unique( [
str( di[
'global_tag' ] )
for di
in data[
'result']
if di[
'global_tag' ]
is not None ] ))
136 recentGT = gtnames[-1]
139 errStr =
"""No Global Tags for \"%s\" are available in Tier0DataSvc from URL \"%s\" """ %( config, os.path.join( self.
_uri, config ) )
141 errStr +=
""" using proxy \"%s\".""" %(
str( self.
_proxy ), )
146 if 'http_proxy' in os.environ:
147 proxyurl = os.environ[
'http_proxy' ]
152 GlobalTag.globaltag = cms.string( t0.getGlobalTag(
'express_config' ) )
153 print(
"The query to the Tier0 DataService returns the express GT: \"%s\"" % ( GlobalTag.globaltag.value(), ))
154 except Tier0Error
as error:
156 print(
"Error in querying the Tier0 DataService")
158 print(
"Falling back to the default value of the express GT: \"%s\"" % ( GlobalTag.globaltag.value(), ))
160 print(
"Using hardcoded GT: \"%s\"" % GlobalTag.globaltag.value())
def replace(string, replacements)
def __init__(self, message)
S & print(S &os, JobReport::InputFile const &f)
def __init__(self, uri, timeOut, retries, retryPeriod, proxy, debug)
def getGlobalTag(self, config)
def _queryTier0DataSvc(self, url)
static std::string join(char **cmd)
def setProxy(self, proxy)
def unique(seq, keepstr=True)
def getFirstSafeRun(self)