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:
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"
138 resp = json.loads(
''.
join(stdoutdata.decode()).
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__':
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
static std::string join(char **cmd)