1 import FWCore.ParameterSet.Config
as cms
7 import Utilities.General.cmssw_das_client
as das_client
17 """ Picks up RelVal input files automatically and 18 returns a vector of strings with the paths to be used in [PoolSource].fileNames 19 PickRelValInputFiles( cmsswVersion, relVal, dataTier, condition, globalTag, maxVersions, skipFiles, numberOfFiles, debug ) 20 - useDAS : switch to perform query in DAS rather than in DBS 21 optional; default: False 22 - cmsswVersion : CMSSW release to pick up the RelVal files from 23 optional; default: the current release (determined automatically from environment) 24 - formerVersion: use the last before the last valid CMSSW release to pick up the RelVal files from 25 applies also, if 'cmsswVersion' is set explicitly 26 optional; default: False 27 - relVal : RelVal sample to be used 28 optional; default: 'RelValTTbar' 29 - dataTier : data tier to be used 30 optional; default: 'GEN-SIM-RECO' 31 - condition : identifier of GlobalTag as defined in Configurations/PyReleaseValidation/python/autoCond.py 32 possibly overwritten, if 'globalTag' is set explicitly 33 optional; default: 'startup' 34 - globalTag : name of GlobalTag as it is used in the data path of the RelVals 35 optional; default: determined automatically as defined by 'condition' in Configurations/PyReleaseValidation/python/autoCond.py 36 !!! Determination is done for the release one runs in, not for the release the RelVals have been produced in. 37 !!! 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, 38 but also an extension identifying the data: 'GR_R_311_V2_RelVal_wzMu2010B' 39 - maxVersions : max. versioning number of RelVal to check 41 - skipFiles : number of files to skip for a found RelVal sample 43 - numberOfFiles: number of files to pick up 44 setting it to negative values, returns all found ('skipFiles' remains active though) 46 - debug : switch to enable enhanced messages in 'stdout' 47 optional; default: False 50 _label =
'pickRelValInputFiles' 51 _defaultParameters = dicttypes.SortedKeysDict()
57 ConfigToolBase.__init__( self )
59 self.addParameter( self.
_defaultParameters,
'cmsswVersion' , os.getenv(
"CMSSW_VERSION" ) ,
'auto from environment' )
65 if isinstance(gt,tuple)
or isinstance(gt,list):
67 self.addParameter( self.
_defaultParameters,
'globalTag' , gt[ : -5 ] ,
'auto from \'condition\'' )
78 , formerVersion =
None 85 , numberOfFiles =
None 90 if cmsswVersion
is None:
92 if formerVersion
is None:
100 if globalTag
is None:
101 globalTag = autoCond[ condition ][ : -5 ]
102 if maxVersions
is None:
104 if skipFiles
is None:
106 if numberOfFiles
is None:
110 self.setParameter(
'useDAS' , useDAS )
111 self.setParameter(
'cmsswVersion' , cmsswVersion )
112 self.setParameter(
'formerVersion', formerVersion )
113 self.setParameter(
'relVal' , relVal )
114 self.setParameter(
'dataTier' , dataTier )
115 self.setParameter(
'condition' , condition )
116 self.setParameter(
'globalTag' , globalTag )
117 self.setParameter(
'maxVersions' , maxVersions )
118 self.setParameter(
'skipFiles' , skipFiles )
119 self.setParameter(
'numberOfFiles', numberOfFiles )
120 self.setParameter(
'debug' , debug )
124 print '%s DEBUG: Empty file list returned'%( self.
_label )
125 print ' This might be overwritten by providing input files explicitly to the source module in the main configuration file.' 129 cmsswVersion = self.
_parameters[
'cmsswVersion' ].value
130 formerVersion = self.
_parameters[
'formerVersion' ].value
135 maxVersions = self.
_parameters[
'maxVersions' ].value
137 numberOfFiles = self.
_parameters[
'numberOfFiles' ].value
145 hltPatchId =
'_hltpatch' 146 dqmPatchId =
'_dqmpatch' 150 if patchId
in cmsswVersion:
151 cmsswVersion = cmsswVersion.split( patchId )[ 0 ]
152 elif hltPatchId
in cmsswVersion:
153 cmsswVersion = cmsswVersion.split( hltPatchId )[ 0 ]
154 elif dqmPatchId
in cmsswVersion:
155 cmsswVersion = cmsswVersion.split( dqmPatchId )[ 0 ]
156 elif rootId
in cmsswVersion:
157 cmsswVersion = cmsswVersion.split( rootId )[ 0 ]
158 elif slhcId
in cmsswVersion:
159 cmsswVersion = cmsswVersion.split( slhcId )[ 0 ]
160 elif ibId
in cmsswVersion
or formerVersion:
161 outputTuple = Popen( [
'scram',
'l -c CMSSW' ], stdout = PIPE, stderr = PIPE ).
communicate()
162 if len( outputTuple[ 1 ] ) != 0:
163 print '%s INFO : SCRAM error'%( self.
_label )
165 print ' from trying to determine last valid releases before \'%s\''%( cmsswVersion )
167 print outputTuple[ 1 ]
171 versions = {
'last' :
'' 174 for line
in outputTuple[ 0 ].splitlines():
175 version = line.split()[ 1 ]
176 if cmsswVersion.split( ibId )[ 0 ]
in version
or cmsswVersion.rpartition(
'_' )[ 0 ]
in version:
177 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 ):
178 versions[
'lastToLast' ] = versions[
'last' ]
179 versions[
'last' ] = version
180 if version == cmsswVersion:
185 if preId
in versions[
'lastToLast' ]
and not preId
in versions[
'last' ]
and not versions[
'last' ].endswith(
'_0' ):
186 versions[
'lastToLast' ] = versions[
'lastToLast' ].
split( preId )[ 0 ]
188 elif versions[
'last' ].endswith(
'_0' )
and not ( preId
in versions[
'lastToLast' ]
and versions[
'lastToLast' ].startswith( versions[
'last' ] ) ):
189 versions[
'lastToLast' ] =
'' 190 for line
in outputTuple[ 0 ].splitlines():
191 version = line.split()[ 1 ]
192 versionParts = version.partition( preId )
193 if versionParts[ 0 ] == versions[
'last' ]
and versionParts[ 1 ] == preId:
194 versions[
'lastToLast' ] = version
195 elif versions[
'lastToLast' ] !=
'':
198 elif preId
in versions[
'last' ]
and not preId
in versions[
'lastToLast' ]
and versions[
'lastToLast' ].endswith(
'_0' ):
199 versions[
'lastToLast' ] =
'' 200 cmsswVersion = versions[
'lastToLast' ]
202 cmsswVersion = versions[
'last' ]
206 print '%s DEBUG: Called with...'%( self.
_label )
207 for key
in self._parameters.keys():
208 print ' %s:\t'%( key ),
214 if key ==
'cmsswVersion' and cmsswVersion != self.
_parameters[ key ].value:
216 print ' ==> modified to last to last valid release %s (s. \'formerVersion\' parameter)'%( cmsswVersion )
218 print ' ==> modified to last valid release %s'%( cmsswVersion )
221 domain = socket.getfqdn().
split(
'.' )
223 if len( domain ) == 0:
224 print '%s INFO : Cannot determine domain of this computer'%( self.
_label )
228 elif os.uname()[0] ==
"Darwin":
229 print '%s INFO : Running on MacOSX without direct access to RelVal files.'%( self.
_label )
233 elif len( domain ) == 1:
234 print '%s INFO : Running on local host \'%s\' without direct access to RelVal files'%( self.
_label, domain[ 0 ] )
238 if not ( ( domain[ -2 ] ==
'cern' and domain[ -1 ] ==
'ch' )
or ( domain[ -2 ] ==
'fnal' and domain[ -1 ] ==
'gov' ) ):
239 print '%s INFO : Running on site \'%s.%s\' without direct access to RelVal files'%( self.
_label, domain[ -2 ], domain[ -1 ] )
243 if domain[ -2 ] ==
'cern':
244 domainSE =
'T2_CH_CERN' 245 elif domain[ -2 ] ==
'fnal':
246 domainSE =
'T1_US_FNAL_MSS' 248 print '%s DEBUG: Running at site \'%s.%s\''%( self.
_label, domain[ -2 ], domain[ -1 ] )
249 print '%s DEBUG: Looking for SE \'%s\''%( self.
_label, domainSE )
254 datasetAll =
'/%s/%s-%s-v*/%s'%( relVal, cmsswVersion, globalTag, dataTier )
257 print '%s DEBUG: Using DAS query'%( self.
_label )
258 dasLimit = numberOfFiles
261 for version
in range( maxVersions, 0, -1 ):
265 dataset =
'/%s/%s-%s-v%i/%s'%( relVal, cmsswVersion, globalTag, version, dataTier )
266 dasQuery =
'file dataset=%s | grep file.name'%( dataset )
268 print '%s DEBUG: Querying dataset \'%s\' with'%( self.
_label, dataset )
269 print ' \'%s\''%( dasQuery )
270 jsondict = das_client.get_data(dasQuery,dasLimit)
272 print '%s DEBUG: Received DAS JSON dictionary:'%( self.
_label )
273 print ' \'%s\''%( jsondict )
274 if jsondict[
'status' ] !=
'ok':
275 print 'There was a problem while querying DAS with query \'%s\'. Server reply was:\n %s' % (dasQuery, jsondict)
277 mongo_query = jsondict[
'mongo_query' ]
278 filters = mongo_query[
'filters' ]
279 data = jsondict[
'data' ]
281 print '%s DEBUG: Query in JSON dictionary:'%( self.
_label )
282 print ' \'%s\''%( mongo_query )
283 print '%s DEBUG: Filters in query:'%( self.
_label )
284 print ' \'%s\''%( filters )
285 print '%s DEBUG: Data in JSON dictionary:'%( self.
_label )
286 print ' \'%s\''%( data )
288 filePath = [ r
for r
in das_client.get_value( row, filters[
'grep' ] ) ][ 0 ]
290 print '%s DEBUG: Testing file entry \'%s\''%( self.
_label, filePath )
291 if len( filePath ) > 0:
292 if validVersion != version:
293 jsontestdict = das_client.get_data(
'site dataset=%s | grep site.name' % ( dataset ), 999)
294 mongo_testquery = jsontestdict[
'mongo_query' ]
295 testfilters = mongo_testquery[
'filters' ]
296 testdata = jsontestdict[
'data' ]
298 print '%s DEBUG: Received DAS JSON dictionary (site test):'%( self.
_label )
299 print ' \'%s\''%( jsontestdict )
300 print '%s DEBUG: Query in JSON dictionary (site test):'%( self.
_label )
301 print ' \'%s\''%( mongo_testquery )
302 print '%s DEBUG: Filters in query (site test):'%( self.
_label )
303 print ' \'%s\''%( testfilters )
304 print '%s DEBUG: Data in JSON dictionary (site test):'%( self.
_label )
305 print ' \'%s\''%( testdata )
307 for testrow
in testdata:
308 siteName = [ tr
for tr
in das_client.get_value( testrow, testfilters[
'grep' ] ) ][ 0 ]
309 if siteName == domainSE:
314 print '%s DEBUG: Possible version \'v%s\' not available on SE \'%s\''%( self.
_label, version, domainSE )
316 validVersion = version
318 print '%s DEBUG: Valid version set to \'v%i\''%( self.
_label, validVersion )
319 if numberOfFiles == 0:
322 if not filePath
in filePathsTmp:
323 filePathsTmp.append( filePath )
325 print '%s DEBUG: File \'%s\' found'%( self.
_label, filePath )
328 if fileCount > skipFiles:
329 filePaths.append( filePath )
331 print '%s DEBUG: File \'%s\' found again'%( self.
_label, filePath )
333 if numberOfFiles == 0
and debug:
334 print '%s DEBUG: No files requested'%( self.
_label )
338 print '%s DEBUG: Using DBS query'%( self.
_label )
339 print '%s WARNING: DBS query disabled for DBS3 transition to new API'%( self.
_label )
385 if validVersion == 0:
386 print '%s WARNING : No RelVal file(s) found at all in datasets \'%s*\' on SE \'%s\''%( self.
_label, datasetAll, domainSE )
389 elif len( filePaths ) == 0:
390 print '%s WARNING : No RelVal file(s) picked up in dataset \'%s\''%( self.
_label, dataset )
393 elif len( filePaths ) < numberOfFiles:
394 print '%s INFO : Only %i RelVal file(s) instead of %i picked up in dataset \'%s\''%( self.
_label, len( filePaths ), numberOfFiles, dataset )
397 print '%s DEBUG: returning %i file(s):\n%s'%( self.
_label, len( filePaths ), filePaths )
static void * communicate(void *obj)