10 from subprocess
import *
20 """ Picks up RelVal input files automatically and
21 returns a vector of strings with the paths to be used in [PoolSource].fileNames
22 PickRelValInputFiles( cmsswVersion, relVal, dataTier, condition, globalTag, maxVersions, skipFiles, numberOfFiles, debug )
23 - useDAS : switch to perform query in DAS rather than in DBS
24 optional; default: False
25 - cmsswVersion : CMSSW release to pick up the RelVal files from
26 optional; default: the current release (determined automatically from environment)
27 - formerVersion: use the last before the last valid CMSSW release to pick up the RelVal files from
28 applies also, if 'cmsswVersion' is set explicitly
29 optional; default: False
30 - relVal : RelVal sample to be used
31 optional; default: 'RelValTTbar'
32 - dataTier : data tier to be used
33 optional; default: 'GEN-SIM-RECO'
34 - condition : identifier of GlobalTag as defined in Configurations/PyReleaseValidation/python/autoCond.py
35 possibly overwritten, if 'globalTag' is set explicitly
36 optional; default: 'startup'
37 - globalTag : name of GlobalTag as it is used in the data path of the RelVals
38 optional; default: determined automatically as defined by 'condition' in Configurations/PyReleaseValidation/python/autoCond.py
39 !!! Determination is done for the release one runs in, not for the release the RelVals have been produced in.
40 !!! Example of deviation: data RelVals (CMSSW_4_1_X) might not only have the pure name of the GlobalTag 'GR_R_311_V2' in the full path,
41 but also an extension identifying the data: 'GR_R_311_V2_RelVal_wzMu2010B'
42 - maxVersions : max. versioning number of RelVal to check
44 - skipFiles : number of files to skip for a found RelVal sample
46 - numberOfFiles: number of files to pick up
47 setting it to negative values, returns all found ('skipFiles' remains active though)
49 - debug : switch to enable enhanced messages in 'stdout'
50 optional; default: False
53 _label =
'pickRelValInputFiles'
54 _defaultParameters = dicttypes.SortedKeysDict()
60 ConfigToolBase.__init__( self )
62 self.addParameter( self.
_defaultParameters,
'cmsswVersion' , os.getenv(
"CMSSW_VERSION" ) ,
'auto from environment' )
68 if isinstance(gt,tuple)
or isinstance(gt,list):
70 self.addParameter( self.
_defaultParameters,
'globalTag' , gt[ : -5 ] ,
'auto from \'condition\'' )
81 , formerVersion =
None
88 , numberOfFiles =
None
93 if cmsswVersion
is None:
95 if formerVersion
is None:
101 if condition
is None:
103 if globalTag
is None:
104 globalTag = autoCond[ condition ][ : -5 ]
105 if maxVersions
is None:
107 if skipFiles
is None:
109 if numberOfFiles
is None:
113 self.setParameter(
'useDAS' , useDAS )
114 self.setParameter(
'cmsswVersion' , cmsswVersion )
115 self.setParameter(
'formerVersion', formerVersion )
116 self.setParameter(
'relVal' , relVal )
117 self.setParameter(
'dataTier' , dataTier )
118 self.setParameter(
'condition' , condition )
119 self.setParameter(
'globalTag' , globalTag )
120 self.setParameter(
'maxVersions' , maxVersions )
121 self.setParameter(
'skipFiles' , skipFiles )
122 self.setParameter(
'numberOfFiles', numberOfFiles )
123 self.setParameter(
'debug' , debug )
127 print '%s DEBUG: Empty file list returned'%( self.
_label )
128 print ' This might be overwritten by providing input files explicitly to the source module in the main configuration file.'
132 cmsswVersion = self.
_parameters[
'cmsswVersion' ].value
133 formerVersion = self.
_parameters[
'formerVersion' ].value
138 maxVersions = self.
_parameters[
'maxVersions' ].value
140 numberOfFiles = self.
_parameters[
'numberOfFiles' ].value
148 hltPatchId =
'_hltpatch'
149 dqmPatchId =
'_dqmpatch'
153 if patchId
in cmsswVersion:
154 cmsswVersion = cmsswVersion.split( patchId )[ 0 ]
155 elif hltPatchId
in cmsswVersion:
156 cmsswVersion = cmsswVersion.split( hltPatchId )[ 0 ]
157 elif dqmPatchId
in cmsswVersion:
158 cmsswVersion = cmsswVersion.split( dqmPatchId )[ 0 ]
159 elif rootId
in cmsswVersion:
160 cmsswVersion = cmsswVersion.split( rootId )[ 0 ]
161 elif slhcId
in cmsswVersion:
162 cmsswVersion = cmsswVersion.split( slhcId )[ 0 ]
163 elif ibId
in cmsswVersion
or formerVersion:
164 outputTuple = Popen( [
'scram',
'l -c CMSSW' ], stdout = PIPE, stderr = PIPE ).
communicate()
165 if len( outputTuple[ 1 ] ) != 0:
166 print '%s INFO : SCRAM error'%( self.
_label )
168 print ' from trying to determine last valid releases before \'%s\''%( cmsswVersion )
170 print outputTuple[ 1 ]
174 versions = {
'last' :
''
177 for line
in outputTuple[ 0 ].splitlines():
178 version = line.split()[ 1 ]
179 if cmsswVersion.split( ibId )[ 0 ]
in version
or cmsswVersion.rpartition(
'_' )[ 0 ]
in version:
180 if not ( patchId
in version
or hltPatchId
in version
or dqmPatchId
in version
or slhcId
in version
or ibId
in version
or rootId
in version ):
181 versions[
'lastToLast' ] = versions[
'last' ]
182 versions[
'last' ] = version
183 if version == cmsswVersion:
188 if preId
in versions[
'lastToLast' ]
and not preId
in versions[
'last' ]
and not versions[
'last' ].endswith(
'_0' ):
189 versions[
'lastToLast' ] = versions[
'lastToLast' ].
split( preId )[ 0 ]
191 elif versions[
'last' ].endswith(
'_0' )
and not ( preId
in versions[
'lastToLast' ]
and versions[
'lastToLast' ].startswith( versions[
'last' ] ) ):
192 versions[
'lastToLast' ] =
''
193 for line
in outputTuple[ 0 ].splitlines():
194 version = line.split()[ 1 ]
195 versionParts = version.partition( preId )
196 if versionParts[ 0 ] == versions[
'last' ]
and versionParts[ 1 ] == preId:
197 versions[
'lastToLast' ] = version
198 elif versions[
'lastToLast' ] !=
'':
201 elif preId
in versions[
'last' ]
and not preId
in versions[
'lastToLast' ]
and versions[
'lastToLast' ].endswith(
'_0' ):
202 versions[
'lastToLast' ] =
''
203 cmsswVersion = versions[
'lastToLast' ]
205 cmsswVersion = versions[
'last' ]
209 print '%s DEBUG: Called with...'%( self.
_label )
210 for key
in self._parameters.keys():
211 print ' %s:\t'%( key ),
217 if key ==
'cmsswVersion' and cmsswVersion != self.
_parameters[ key ].value:
219 print ' ==> modified to last to last valid release %s (s. \'formerVersion\' parameter)'%( cmsswVersion )
221 print ' ==> modified to last valid release %s'%( cmsswVersion )
224 domain = socket.getfqdn().
split(
'.' )
226 if len( domain ) == 0:
227 print '%s INFO : Cannot determine domain of this computer'%( self.
_label )
231 elif os.uname()[0] ==
"Darwin":
232 print '%s INFO : Running on MacOSX without direct access to RelVal files.'%( self.
_label )
236 elif len( domain ) == 1:
237 print '%s INFO : Running on local host \'%s\' without direct access to RelVal files'%( self.
_label, domain[ 0 ] )
241 if not ( ( domain[ -2 ] ==
'cern' and domain[ -1 ] ==
'ch' )
or ( domain[ -2 ] ==
'fnal' and domain[ -1 ] ==
'gov' ) ):
242 print '%s INFO : Running on site \'%s.%s\' without direct access to RelVal files'%( self.
_label, domain[ -2 ], domain[ -1 ] )
246 if domain[ -2 ] ==
'cern':
247 domainSE =
'T2_CH_CERN'
248 elif domain[ -2 ] ==
'fnal':
249 domainSE =
'T1_US_FNAL_MSS'
251 print '%s DEBUG: Running at site \'%s.%s\''%( self.
_label, domain[ -2 ], domain[ -1 ] )
252 print '%s DEBUG: Looking for SE \'%s\''%( self.
_label, domainSE )
257 datasetAll =
'/%s/%s-%s-v*/%s'%( relVal, cmsswVersion, globalTag, dataTier )
260 print '%s DEBUG: Using DAS query'%( self.
_label )
261 dasLimit = numberOfFiles
264 for version
in range( maxVersions, 0, -1 ):
268 dataset =
'/%s/%s-%s-v%i/%s'%( relVal, cmsswVersion, globalTag, version, dataTier )
269 dasQuery =
'file dataset=%s | grep file.name'%( dataset )
271 print '%s DEBUG: Querying dataset \'%s\' with'%( self.
_label, dataset )
272 print ' \'%s\''%( dasQuery )
274 jsondict = das_client.get_data(
'https://cmsweb.cern.ch', dasQuery, 0, dasLimit,
False )
276 print '%s DEBUG: Received DAS JSON dictionary:'%( self.
_label )
277 print ' \'%s\''%( jsondict )
278 if jsondict[
'status' ] !=
'ok':
279 print 'There was a problem while querying DAS with query \'%s\'. Server reply was:\n %s' % (dasQuery, jsondict)
281 mongo_query = jsondict[
'mongo_query' ]
282 filters = mongo_query[
'filters' ]
283 data = jsondict[
'data' ]
285 print '%s DEBUG: Query in JSON dictionary:'%( self.
_label )
286 print ' \'%s\''%( mongo_query )
287 print '%s DEBUG: Filters in query:'%( self.
_label )
288 print ' \'%s\''%( filters )
289 print '%s DEBUG: Data in JSON dictionary:'%( self.
_label )
290 print ' \'%s\''%( data )
292 filePath = [ r
for r
in das_client.get_value( row, filters[
'grep' ] ) ][ 0 ]
294 print '%s DEBUG: Testing file entry \'%s\''%( self.
_label, filePath )
295 if len( filePath ) > 0:
296 if validVersion != version:
297 jsontestdict = das_client.get_data(
'https://cmsweb.cern.ch',
'site dataset=%s | grep site.name'%( dataset ), 0, 999,
False )
298 mongo_testquery = jsontestdict[
'mongo_query' ]
299 testfilters = mongo_testquery[
'filters' ]
300 testdata = jsontestdict[
'data' ]
302 print '%s DEBUG: Received DAS JSON dictionary (site test):'%( self.
_label )
303 print ' \'%s\''%( jsontestdict )
304 print '%s DEBUG: Query in JSON dictionary (site test):'%( self.
_label )
305 print ' \'%s\''%( mongo_testquery )
306 print '%s DEBUG: Filters in query (site test):'%( self.
_label )
307 print ' \'%s\''%( testfilters )
308 print '%s DEBUG: Data in JSON dictionary (site test):'%( self.
_label )
309 print ' \'%s\''%( testdata )
311 for testrow
in testdata:
312 siteName = [ tr
for tr
in das_client.get_value( testrow, testfilters[
'grep' ] ) ][ 0 ]
313 if siteName == domainSE:
318 print '%s DEBUG: Possible version \'v%s\' not available on SE \'%s\''%( self.
_label, version, domainSE )
320 validVersion = version
322 print '%s DEBUG: Valid version set to \'v%i\''%( self.
_label, validVersion )
323 if numberOfFiles == 0:
326 if not filePath
in filePathsTmp:
327 filePathsTmp.append( filePath )
329 print '%s DEBUG: File \'%s\' found'%( self.
_label, filePath )
332 if fileCount > skipFiles:
333 filePaths.append( filePath )
335 print '%s DEBUG: File \'%s\' found again'%( self.
_label, filePath )
337 if numberOfFiles == 0
and debug:
338 print '%s DEBUG: No files requested'%( self.
_label )
342 print '%s DEBUG: Using DBS query'%( self.
_label )
343 print '%s WARNING: DBS query disabled for DBS3 transition to new API'%( self.
_label )
389 if validVersion == 0:
390 print '%s WARNING : No RelVal file(s) found at all in datasets \'%s*\' on SE \'%s\''%( self.
_label, datasetAll, domainSE )
393 elif len( filePaths ) == 0:
394 print '%s WARNING : No RelVal file(s) picked up in dataset \'%s\''%( self.
_label, dataset )
397 elif len( filePaths ) < numberOfFiles:
398 print '%s INFO : Only %i RelVal file(s) instead of %i picked up in dataset \'%s\''%( self.
_label, len( filePaths ), numberOfFiles, dataset )
401 print '%s DEBUG: returning %i file(s):\n%s'%( self.
_label, len( filePaths ), filePaths )
static void * communicate(void *obj)