6 from Configuration.AlCa.autoCond
import autoCond
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' )
75 , formerVersion =
None
82 , numberOfFiles =
None
87 if cmsswVersion
is None:
89 if formerVersion
is None:
98 globalTag = autoCond[ condition ][ : -5 ]
99 if maxVersions
is None:
101 if skipFiles
is None:
103 if numberOfFiles
is None:
107 self.setParameter(
'useDAS' , useDAS )
108 self.setParameter(
'cmsswVersion' , cmsswVersion )
109 self.setParameter(
'formerVersion', formerVersion )
110 self.setParameter(
'relVal' , relVal )
111 self.setParameter(
'dataTier' , dataTier )
112 self.setParameter(
'condition' , condition )
113 self.setParameter(
'globalTag' , globalTag )
114 self.setParameter(
'maxVersions' , maxVersions )
115 self.setParameter(
'skipFiles' , skipFiles )
116 self.setParameter(
'numberOfFiles', numberOfFiles )
117 self.setParameter(
'debug' , debug )
121 print '%s DEBUG: Empty file list returned'%( self.
_label )
122 print ' This might be overwritten by providing input files explicitly to the source module in the main configuration file.'
126 cmsswVersion = self.
_parameters[
'cmsswVersion' ].value
127 formerVersion = self.
_parameters[
'formerVersion' ].value
132 maxVersions = self.
_parameters[
'maxVersions' ].value
134 numberOfFiles = self.
_parameters[
'numberOfFiles' ].value
142 hltPatchId =
'_hltpatch'
143 dqmPatchId =
'_dqmpatch'
147 if patchId
in cmsswVersion:
148 cmsswVersion = cmsswVersion.split( patchId )[ 0 ]
149 elif hltPatchId
in cmsswVersion:
150 cmsswVersion = cmsswVersion.split( hltPatchId )[ 0 ]
151 elif dqmPatchId
in cmsswVersion:
152 cmsswVersion = cmsswVersion.split( dqmPatchId )[ 0 ]
153 elif rootId
in cmsswVersion:
154 cmsswVersion = cmsswVersion.split( rootId )[ 0 ]
155 elif slhcId
in cmsswVersion:
156 cmsswVersion = cmsswVersion.split( slhcId )[ 0 ]
157 elif ibId
in cmsswVersion
or formerVersion:
158 outputTuple = Popen( [
'scram',
'l -c CMSSW' ], stdout = PIPE, stderr = PIPE ).
communicate()
159 if len( outputTuple[ 1 ] ) != 0:
160 print '%s INFO : SCRAM error'%( self.
_label )
162 print ' from trying to determine last valid releases before \'%s\''%( cmsswVersion )
164 print outputTuple[ 1 ]
168 versions = {
'last' :
''
171 for line
in outputTuple[ 0 ].splitlines():
172 version = line.split()[ 1 ]
173 if cmsswVersion.split( ibId )[ 0 ]
in version
or cmsswVersion.rpartition(
'_' )[ 0 ]
in version:
174 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 ):
175 versions[
'lastToLast' ] = versions[
'last' ]
176 versions[
'last' ] = version
177 if version == cmsswVersion:
182 if preId
in versions[
'lastToLast' ]
and not preId
in versions[
'last' ]
and not versions[
'last' ].endswith(
'_0' ):
183 versions[
'lastToLast' ] = versions[
'lastToLast' ].
split( preId )[ 0 ]
185 elif versions[
'last' ].endswith(
'_0' )
and not ( preId
in versions[
'lastToLast' ]
and versions[
'lastToLast' ].startswith( versions[
'last' ] ) ):
186 versions[
'lastToLast' ] =
''
187 for line
in outputTuple[ 0 ].splitlines():
188 version = line.split()[ 1 ]
189 versionParts = version.partition( preId )
190 if versionParts[ 0 ] == versions[
'last' ]
and versionParts[ 1 ] == preId:
191 versions[
'lastToLast' ] = version
192 elif versions[
'lastToLast' ] !=
'':
195 elif preId
in versions[
'last' ]
and not preId
in versions[
'lastToLast' ]
and versions[
'lastToLast' ].endswith(
'_0' ):
196 versions[
'lastToLast' ] =
''
197 cmsswVersion = versions[
'lastToLast' ]
199 cmsswVersion = versions[
'last' ]
203 print '%s DEBUG: Called with...'%( self.
_label )
204 for key
in self._parameters.keys():
205 print ' %s:\t'%( key ),
211 if key ==
'cmsswVersion' and cmsswVersion != self.
_parameters[ key ].value:
213 print ' ==> modified to last to last valid release %s (s. \'formerVersion\' parameter)'%( cmsswVersion )
215 print ' ==> modified to last valid release %s'%( cmsswVersion )
218 domain = socket.getfqdn().
split(
'.' )
220 if len( domain ) == 0:
221 print '%s INFO : Cannot determine domain of this computer'%( self.
_label )
225 elif os.uname()[0] ==
"Darwin":
226 print '%s INFO : Running on MacOSX without direct access to RelVal files.'%( self.
_label )
230 elif len( domain ) == 1:
231 print '%s INFO : Running on local host \'%s\' without direct access to RelVal files'%( self.
_label, domain[ 0 ] )
235 if not ( ( domain[ -2 ] ==
'cern' and domain[ -1 ] ==
'ch' )
or ( domain[ -2 ] ==
'fnal' and domain[ -1 ] ==
'gov' ) ):
236 print '%s INFO : Running on site \'%s.%s\' without direct access to RelVal files'%( self.
_label, domain[ -2 ], domain[ -1 ] )
240 if domain[ -2 ] ==
'cern':
241 domainSE =
'T2_CH_CERN'
242 elif domain[ -2 ] ==
'fnal':
243 domainSE =
'T1_US_FNAL_MSS'
245 print '%s DEBUG: Running at site \'%s.%s\''%( self.
_label, domain[ -2 ], domain[ -1 ] )
246 print '%s DEBUG: Looking for SE \'%s\''%( self.
_label, domainSE )
251 datasetAll =
'/%s/%s-%s-v*/%s'%( relVal, cmsswVersion, globalTag, dataTier )
254 print '%s DEBUG: Using DAS query'%( self.
_label )
255 dasLimit = numberOfFiles
258 for version
in range( maxVersions, 0, -1 ):
262 dataset =
'/%s/%s-%s-v%i/%s'%( relVal, cmsswVersion, globalTag, version, dataTier )
263 dasQuery =
'file dataset=%s | grep file.name'%( dataset )
265 print '%s DEBUG: Querying dataset \'%s\' with'%( self.
_label, dataset )
266 print ' \'%s\''%( dasQuery )
268 jsondict = das_client.get_data(dasQuery, dasLimit)
270 print '%s DEBUG: Received DAS JSON dictionary:'%( self.
_label )
271 print ' \'%s\''%( jsondict )
272 if jsondict[
'status' ] !=
'ok':
273 print 'There was a problem while querying DAS with query \'%s\'. Server reply was:\n %s' % (dasQuery, jsondict)
275 mongo_query = jsondict[
'mongo_query' ]
276 filters = mongo_query[
'filters' ]
277 data = jsondict[
'data' ]
279 print '%s DEBUG: Query in JSON dictionary:'%( self.
_label )
280 print ' \'%s\''%( mongo_query )
281 print '%s DEBUG: Filters in query:'%( self.
_label )
282 print ' \'%s\''%( filters )
283 print '%s DEBUG: Data in JSON dictionary:'%( self.
_label )
284 print ' \'%s\''%( data )
286 filePath = [ r
for r
in das_client.get_value( row, filters[
'grep' ] ) ][ 0 ]
288 print '%s DEBUG: Testing file entry \'%s\''%( self.
_label, filePath )
289 if len( filePath ) > 0:
290 if validVersion != version:
291 jsontestdict = das_client.get_data(
'site dataset=%s | grep site.name'%( dataset ), 999)
292 mongo_testquery = jsontestdict[
'mongo_query' ]
293 testfilters = mongo_testquery[
'filters' ]
294 testdata = jsontestdict[
'data' ]
296 print '%s DEBUG: Received DAS JSON dictionary (site test):'%( self.
_label )
297 print ' \'%s\''%( jsontestdict )
298 print '%s DEBUG: Query in JSON dictionary (site test):'%( self.
_label )
299 print ' \'%s\''%( mongo_testquery )
300 print '%s DEBUG: Filters in query (site test):'%( self.
_label )
301 print ' \'%s\''%( testfilters )
302 print '%s DEBUG: Data in JSON dictionary (site test):'%( self.
_label )
303 print ' \'%s\''%( testdata )
305 for testrow
in testdata:
306 siteName = [ tr
for tr
in das_client.get_value( testrow, testfilters[
'grep' ] ) ][ 0 ]
307 if siteName == domainSE:
312 print '%s DEBUG: Possible version \'v%s\' not available on SE \'%s\''%( self.
_label, version, domainSE )
314 validVersion = version
316 print '%s DEBUG: Valid version set to \'v%i\''%( self.
_label, validVersion )
317 if numberOfFiles == 0:
320 if not filePath
in filePathsTmp:
321 filePathsTmp.append( filePath )
323 print '%s DEBUG: File \'%s\' found'%( self.
_label, filePath )
326 if fileCount > skipFiles:
327 filePaths.append( filePath )
329 print '%s DEBUG: File \'%s\' found again'%( self.
_label, filePath )
331 if numberOfFiles == 0
and debug:
332 print '%s DEBUG: No files requested'%( self.
_label )
336 print '%s DEBUG: Using DBS query'%( self.
_label )
337 print '%s WARNING: DBS query disabled for DBS3 transition to new API'%( self.
_label )
383 if validVersion == 0:
384 print '%s WARNING : No RelVal file(s) found at all in datasets \'%s*\' on SE \'%s\''%( self.
_label, datasetAll, domainSE )
387 elif len( filePaths ) == 0:
388 print '%s WARNING : No RelVal file(s) picked up in dataset \'%s\''%( self.
_label, dataset )
391 elif len( filePaths ) < numberOfFiles:
392 print '%s INFO : Only %i RelVal file(s) instead of %i picked up in dataset \'%s\''%( self.
_label, len( filePaths ), numberOfFiles, dataset )
395 print '%s DEBUG: returning %i file(s):\n%s'%( self.
_label, len( filePaths ), filePaths )
static void * communicate(void *obj)