CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/PhysicsTools/PatAlgos/python/tools/cmsswVersionTools.py

Go to the documentation of this file.
00001 import FWCore.ParameterSet.Config as cms
00002 
00003 from FWCore.GuiBrowsers.ConfigToolBase import *
00004 from PhysicsTools.PatAlgos.tools.helpers import *
00005 from PhysicsTools.PatAlgos.tools.jetTools import *
00006 from Configuration.PyReleaseValidation.autoCond import autoCond
00007 
00008 import os
00009 import socket
00010 from subprocess import *
00011 
00012 
00013 ## ------------------------------------------------------
00014 ## Deal with backweard incompatibilities of conditions
00015 ## ------------------------------------------------------
00016 
00017 def run42xOn3yzMcInput( process
00018                       , l1MenuTag    = 'L1GtTriggerMenu_L1Menu_Commissioning2010_v4_mc' # L1 menu for Fall10 REDIGI (CMSSW_3_8_7)
00019                       ):
00020   """
00021   """
00022   # Use correct L1 trigger menu
00023   import CondCore.DBCommon.CondDBCommon_cfi
00024   process.l1GtTriggerMenu = cms.ESSource( "PoolDBESSource"
00025   , CondCore.DBCommon.CondDBCommon_cfi.CondDBCommon
00026   , toGet   = cms.VPSet(
00027       cms.PSet(
00028         connect = cms.untracked.string( 'frontier://FrontierProd/CMS_COND_31X_L1T' )
00029       , record  = cms.string( 'L1GtTriggerMenuRcd' )
00030       , tag     = cms.string( l1MenuTag )
00031       )
00032     )
00033   )
00034   process.preferL1GtTriggerMenu = cms.ESPrefer( "PoolDBESSource", "l1GtTriggerMenu" )
00035 
00036 
00037 ## ------------------------------------------------------
00038 ## Re-configuration of PATJetProducer
00039 ## ------------------------------------------------------
00040 
00041 def run36xOn35xInput(process,
00042                      genJets = "",
00043                      postfix=""):
00044     """
00045     ------------------------------------------------------------------
00046     Reconfigure the PATJetProducer to be able to run the 36X version
00047     of PAT on 35X input samples.
00048 
00049     process : process
00050     ------------------------------------------------------------------
00051     """
00052     print "*********************************************************************"
00053     print "NOTE TO USER: when running on 35X sample with 36X s/w versions you   "
00054     print "              need to adapt for different event contents. The        "
00055     print "              adaptations need to be made:                           "
00056     print "                                                                     "
00057     print "               - re-configuration of secondary vertex tag discrimi-  "
00058     print "                 nator information.                                  "
00059     print "                                                                     "
00060     print "*********************************************************************"
00061     ## re-configure b-discriminator sources for pat jets
00062     process.patJets.discriminatorSources = cms.VInputTag(
00063         cms.InputTag("combinedSecondaryVertexBJetTags"),
00064         cms.InputTag("combinedSecondaryVertexMVABJetTags"),
00065         cms.InputTag("jetBProbabilityBJetTags"),
00066         cms.InputTag("jetProbabilityBJetTags"),
00067         cms.InputTag("simpleSecondaryVertexBJetTags"),
00068         cms.InputTag("softElectronByPtBJetTags"),
00069         cms.InputTag("softElectronByIP3dBJetTags"),
00070         cms.InputTag("softMuonBJetTags"),
00071         cms.InputTag("softMuonByPtBJetTags"),
00072         cms.InputTag("softMuonByIP3dBJetTags"),
00073         cms.InputTag("trackCountingHighEffBJetTags"),
00074         cms.InputTag("trackCountingHighPurBJetTags"),
00075     )
00076     if genJets != "" :
00077         print "*********************************************************************"
00078         print "NOTE TO USER: when running on 31X samples re-recoed in 3.5.x         "
00079         print "              with this CMSSW version of PAT                         "
00080         print "              it is required to re-run the GenJet production for     "
00081         print "              anti-kT since that is not part of the re-reco          "
00082         print "*********************************************************************"
00083         process.load("RecoJets.Configuration.GenJetParticles_cff")
00084         process.load("RecoJets.JetProducers." + genJets +"_cfi")
00085         process.patDefaultSequence.replace( getattr(process,"patCandidates"+postfix), process.genParticlesForJets+getattr(process,genJets)+getattr(process,"patCandidates"+postfix))
00086 
00087 
00088 
00089 ## ------------------------------------------------------
00090 ## Re-implementation of jetTools
00091 ## ------------------------------------------------------
00092 
00093 class RunBTagging35X(ConfigToolBase):
00094 
00095     """
00096     ------------------------------------------------------------------
00097     Define sequence to run b tagging on AOD input for a given jet
00098     collection including a JetTracksAssociatorAtVertex module with
00099     name 'jetTracksAssociatorAtVertex' + 'label'.
00100 
00101     Return value is a pair of (sequence, labels) where 'sequence'
00102     is the cms.Sequence, and 'labels' is a vector with the follow-
00103     ing entries:
00104 
00105      * labels['jta']      = the name of the JetTrackAssociator module
00106      * labels['tagInfos'] = a list of names of the TagInfo modules
00107      * labels['jetTags '] = a list of names of the JetTag modules
00108 
00109     This is a re-implementation to run the 36X version of PAT on 35X
00110     input samples.
00111     ------------------------------------------------------------------
00112     """
00113     _label='runBTagging35X'
00114     _defaultParameters=dicttypes.SortedKeysDict()
00115     def __init__(self):
00116         ConfigToolBase.__init__(self)
00117         self.addParameter(self._defaultParameters,'jetCollection',self._defaultValue, 'input jet collection',Type=cms.InputTag)
00118         self.addParameter(self._defaultParameters,'label',self._defaultValue, 'postfix label to identify new sequence/modules', Type=str)
00119         self.addParameter(self._defaultParameters,'postfix',"", "postfix of default sequence (do not confuse with 'label')")
00120         self._parameters=copy.deepcopy(self._defaultParameters)
00121         self._comment = ""
00122 
00123     def getDefaultParameters(self):
00124         return self._defaultParameters
00125 
00126     def __call__(self,process,
00127                  jetCollection     = None,
00128                  label             = None,
00129                  postfix           = None) :
00130         if  jetCollection is None:
00131             jetCollection=self._defaultParameters['jetCollection'].value
00132         if  label is None:
00133             label=self._defaultParameters['label'].value
00134         if postfix  is None:
00135             postfix=self._defaultParameters['postfix'].value
00136         self.setParameter('jetCollection',jetCollection)
00137         self.setParameter('label',label)
00138         self.setParameter('postfix',postfix)
00139 
00140         return self.apply(process)
00141 
00142     def apply(self, process):
00143         jetCollection=self._parameters['jetCollection'].value
00144         label=self._parameters['label'].value
00145         postfix=self._parameters['postfix'].value
00146 
00147         if hasattr(process, "addAction"):
00148             process.disableRecording()
00149 
00150         try:
00151             comment=inspect.stack(2)[2][4][0].rstrip("\n")
00152             if comment.startswith("#"):
00153                 self.setComment(comment.lstrip("#"))
00154         except:
00155             pass
00156 
00157         #############################
00158         ### TOOL CODE STARTS HERE ###
00159         #############################
00160         print "*********************************************************************"
00161         print "NOTE TO USER: when running on 35X sample with 36X s/w versions you   "
00162         print "              need to adapt for different event contents. The        "
00163         print "              adaptations need to be made:                           "
00164         print "                                                                     "
00165         print "               - re-configuration of secondary vertex tag discrimi-  "
00166         print "                 nator information.                                  "
00167         print "                                                                     "
00168         print "               - take out soft electron tagger information, which    "
00169         print "                 is not available on 35X.                            "
00170         print "*********************************************************************"
00171 
00172         if (label == ''):
00173         ## label is not allowed to be empty
00174             raise ValueError, "label for re-running b tagging is not allowed to be empty"
00175 
00176         ## import track associator & b tag configuration
00177         process.load("RecoJets.JetAssociationProducers.ak5JTA_cff")
00178         from RecoJets.JetAssociationProducers.ak5JTA_cff import ak5JetTracksAssociatorAtVertex
00179         process.load("RecoBTag.Configuration.RecoBTag_cff")
00180         import RecoBTag.Configuration.RecoBTag_cff as btag
00181 
00182         # add negative tag infos
00183         import PhysicsTools.PatAlgos.recoLayer0.bTagging_cff as nbtag
00184 
00185         ## define jetTracksAssociator; for switchJetCollection
00186         ## the label is 'AOD' as empty labels will lead to crashes
00187         ## of crab. In this case the postfix label is skiped,
00188         ## otherwise a postfix label is added as for the other
00189         ## labels
00190         jtaLabel = 'jetTracksAssociatorAtVertex'+postfix
00191 
00192         if (not label == 'AOD'):
00193             jtaLabel  += label
00194         ## define tag info labels (compare with jetProducer_cfi.py)
00195         ipTILabel = 'impactParameterTagInfos'     + label
00196         svTILabel = 'secondaryVertexTagInfos'     + label
00197         smTILabel = 'softMuonTagInfos'            + label
00198 
00199         ## produce tag infos
00200         setattr( process, ipTILabel, btag.impactParameterTagInfos.clone(jetTracks = cms.InputTag(jtaLabel)) )
00201         setattr( process, svTILabel, btag.secondaryVertexTagInfos.clone(trackIPTagInfos = cms.InputTag(ipTILabel)) )
00202         setattr( process, smTILabel, btag.softMuonTagInfos.clone(jets = jetCollection) )
00203 
00204         ## make VInputTag from strings
00205         def vit(*args) : return cms.VInputTag( *[ cms.InputTag(x) for x in args ] )
00206 
00207         ## produce btags
00208         setattr( process, 'jetBProbabilityBJetTags'+label, btag.jetBProbabilityBJetTags.clone(tagInfos = vit(ipTILabel)) )
00209         setattr( process, 'jetProbabilityBJetTags' +label, btag.jetProbabilityBJetTags.clone (tagInfos = vit(ipTILabel)) )
00210         setattr( process, 'trackCountingHighPurBJetTags'+label, btag.trackCountingHighPurBJetTags.clone(tagInfos = vit(ipTILabel)) )
00211         setattr( process, 'trackCountingHighEffBJetTags'+label, btag.trackCountingHighEffBJetTags.clone(tagInfos = vit(ipTILabel)) )
00212         setattr( process, 'simpleSecondaryVertexBJetTags'+label, btag.simpleSecondaryVertexBJetTags.clone(tagInfos = vit(svTILabel)) )
00213         setattr( process, 'combinedSecondaryVertexBJetTags'+label, btag.combinedSecondaryVertexBJetTags.clone(tagInfos = vit(ipTILabel, svTILabel)) )
00214         setattr( process, 'combinedSecondaryVertexMVABJetTags'+label, btag.combinedSecondaryVertexMVABJetTags.clone(tagInfos = vit(ipTILabel, svTILabel)) )
00215         setattr( process, 'softMuonBJetTags'+label, btag.softMuonBJetTags.clone(tagInfos = vit(smTILabel)) )
00216         setattr( process, 'softMuonByPtBJetTags'+label, btag.softMuonByPtBJetTags.clone(tagInfos = vit(smTILabel)) )
00217         setattr( process, 'softMuonByIP3dBJetTags'+label, btag.softMuonByIP3dBJetTags.clone(tagInfos = vit(smTILabel)) )
00218 
00219         ## define vector of (output) labels
00220         labels = { 'jta'      : jtaLabel,
00221                    'tagInfos' : (ipTILabel,svTILabel,smTILabel),
00222                    'jetTags'  : [ (x + label) for x in ('jetBProbabilityBJetTags',
00223                                                         'jetProbabilityBJetTags',
00224                                                         'trackCountingHighPurBJetTags',
00225                                                         'trackCountingHighEffBJetTags',
00226                                                         'simpleSecondaryVertexBJetTags',
00227                                                         'combinedSecondaryVertexBJetTags',
00228                                                         'combinedSecondaryVertexMVABJetTags',
00229                                                         'softMuonBJetTags',
00230                                                         'softMuonByPtBJetTags',
00231                                                         'softMuonByIP3dBJetTags'
00232                                                         )
00233                                   ]
00234                    }
00235 
00236         ## extend an existing sequence by otherLabels
00237         def mkseq(process, firstlabel, *otherlabels):
00238             seq = getattr(process, firstlabel)
00239             for x in otherlabels: seq += getattr(process, x)
00240             return cms.Sequence(seq)
00241 
00242         ## add tag infos to the process
00243         setattr( process, 'btaggingTagInfos'+label, mkseq(process, *(labels['tagInfos']) ) )
00244         ## add b tags to the process
00245         setattr( process, 'btaggingJetTags'+label,  mkseq(process, *(labels['jetTags'])  ) )
00246         ## add a combined sequence to the process
00247         seq = mkseq(process, 'btaggingTagInfos'+label, 'btaggingJetTags' + label)
00248         setattr( process, 'btagging'+label, seq )
00249         ## return the combined sequence and the labels defined above
00250 
00251         if hasattr(process, "addAction"):
00252             process.enableRecording()
00253             action=self.__copy__()
00254             process.addAction(action)
00255         return (seq, labels)
00256 
00257 
00258 runBTagging35X=RunBTagging35X()
00259 
00260 
00261 class AddJetCollection35X(ConfigToolBase):
00262 
00263     """
00264     ------------------------------------------------------------------
00265     Add a new collection of jets. Takes the configuration from the
00266     already configured standard jet collection as starting point;
00267     replaces before calling addJetCollection will also affect the
00268     new jet collections. This is a re-implementation to run the
00269     36X version of PAT on 35X input samples.
00270     ------------------------------------------------------------------
00271     """
00272     _label='addJetCollection35X'
00273     _defaultParameters=dicttypes.SortedKeysDict()
00274     def __init__(self):
00275         ConfigToolBase.__init__(self)
00276         self.addParameter(self._defaultParameters,'jetCollection',self._defaultValue,'Input jet collection', cms.InputTag)
00277         self.addParameter(self._defaultParameters,'algoLabel',self._defaultValue, "label to indicate the jet algorithm (e.g.'AK5')",str)
00278         self.addParameter(self._defaultParameters,'typeLabel',self._defaultValue, "label to indicate the type of constituents (e.g. 'Calo', 'Pflow', 'Jpt', ...)",str)
00279         self.addParameter(self._defaultParameters,'doJTA',True, "run b tagging sequence for new jet collection and add it to the new pat jet collection")
00280         self.addParameter(self._defaultParameters,'doBTagging',True, 'run JetTracksAssociation and JetCharge and add it to the new pat jet collection (will autom. be true if doBTagging is set to true)')
00281         self.addParameter(self._defaultParameters,'jetCorrLabel',None, "algorithm and type of JEC; use 'None' for no JEC; examples are ('AK5','Calo'), ('SC7','Calo'), ('KT4','PF')", tuple,acceptNoneValue=True)
00282         self.addParameter(self._defaultParameters,'doType1MET',True, "if jetCorrLabel is not 'None', set this to 'True' to redo the Type1 MET correction for the new jet colllection; at the moment it must be 'False' for non CaloJets otherwise the JetMET POG module crashes. ")
00283         self.addParameter(self._defaultParameters,'doL1Cleaning',True, "copy also the producer modules for cleanLayer1 will be set to 'True' automatically when doL1Counters is 'True'")
00284         self.addParameter(self._defaultParameters,'doL1Counters',False, "copy also the filter modules that accept/reject the event looking at the number of jets")
00285         self.addParameter(self._defaultParameters,'genJetCollection',cms.InputTag("ak5GenJets"), "GenJet collection to match to")
00286         self.addParameter(self._defaultParameters,'doJetID',True, "add jetId variables to the added jet collection?")
00287         self.addParameter(self._defaultParameters,'jetIdLabel',"ak5", " specify the label prefix of the xxxJetID object; in general it is the jet collection tag like ak5, kt4 sc5, aso. For more information have a look to SWGuidePATTools#add_JetCollection")
00288         self.addParameter(self._defaultParameters,'standardAlgo',"AK5", "standard algorithm label of the collection from which the clones for the new jet collection will be taken from (note that this jet collection has to be available in the event before hand)")
00289         self.addParameter(self._defaultParameters,'standardType',"Calo", "standard constituent type label of the collection from which the clones for the new jet collection will be taken from (note that this jet collection has to be available in the event before hand)")
00290 
00291         self._parameters=copy.deepcopy(self._defaultParameters)
00292         self._comment = ""
00293 
00294     def getDefaultParameters(self):
00295         return self._defaultParameters
00296 
00297     def __call__(self,process,
00298                  jetCollection      = None,
00299                  algoLabel          = None,
00300                  typeLabel          = None,
00301                  doJTA              = None,
00302                  doBTagging         = None,
00303                  jetCorrLabel       = None,
00304                  doType1MET         = None,
00305                  doL1Cleaning       = None,
00306                  doL1Counters       = None,
00307                  genJetCollection   = None,
00308                  doJetID            = None,
00309                  jetIdLabel         = None,
00310                  standardAlgo       = None,
00311                  standardType       = None):
00312 
00313         if jetCollection  is None:
00314             jetCollection=self._defaultParameters['jetCollection'].value
00315         if algoLabel is None:
00316             algoLabel=self._defaultParameters['algoLabel'].value
00317         if typeLabel is None:
00318             typeLabel=self._defaultParameters['typeLabel'].value
00319         if doJTA is None:
00320             doJTA=self._defaultParameters['doJTA'].value
00321         if doBTagging is None:
00322             doBTagging=self._defaultParameters['doBTagging'].value
00323         if jetCorrLabel  is None:
00324             jetCorrLabel=self._defaultParameters['jetCorrLabel'].value
00325         if doType1MET  is None:
00326             doType1MET=self._defaultParameters['doType1MET'].value
00327         if doL1Cleaning is None:
00328             doL1Cleaning=self._defaultParameters['doL1Cleaning'].value
00329         if doL1Counters  is None:
00330             doL1Counters=self._defaultParameters['doL1Counters'].value
00331         if genJetCollection  is None:
00332             genJetCollection=self._defaultParameters['genJetCollection'].value
00333         if doJetID  is None:
00334             doJetID=self._defaultParameters['doJetID'].value
00335         if jetIdLabel  is None:
00336             jetIdLabel=self._defaultParameters['jetIdLabel'].value
00337         if standardAlgo is None:
00338             standardAlgo=self._defaultParameters['standardAlgo'].value
00339         if standardType is None:
00340             standardType=self._defaultParameters['standardType'].value
00341 
00342         self.setParameter('jetCollection',jetCollection)
00343         self.setParameter('algoLabel',algoLabel)
00344         self.setParameter('typeLabel',typeLabel)
00345         self.setParameter('doJTA',doJTA)
00346         self.setParameter('doBTagging',doBTagging)
00347         self.setParameter('jetCorrLabel',jetCorrLabel)
00348         self.setParameter('doType1MET',doType1MET)
00349         self.setParameter('doL1Cleaning',doL1Cleaning)
00350         self.setParameter('doL1Counters',doL1Counters)
00351         self.setParameter('genJetCollection',genJetCollection)
00352         self.setParameter('doJetID',doJetID)
00353         self.setParameter('jetIdLabel',jetIdLabel)
00354         self.setParameter('standardAlgo',standardAlgo)
00355         self.setParameter('standardType',standardType)
00356 
00357         self.apply(process)
00358 
00359     def toolCode(self, process):
00360         jetCollection=self._parameters['jetCollection'].value
00361         algoLabel=self._parameters['algoLabel'].value
00362         typeLabel=self._parameters['typeLabel'].value
00363         doJTA=self._parameters['doJTA'].value
00364         doBTagging=self._parameters['doBTagging'].value
00365         jetCorrLabel=self._parameters['jetCorrLabel'].value
00366         doType1MET =self._parameters['doType1MET'].value
00367         doL1Cleaning=self._parameters['doL1Cleaning'].value
00368         doL1Counters=self._parameters['doL1Counters'].value
00369         genJetCollection=self._parameters['genJetCollection'].value
00370         doJetID=self._parameters['doJetID'].value
00371         jetIdLabel=self._parameters['jetIdLabel'].value
00372         standardAlgo=self._parameters['standardAlgo'].value
00373         standardType=self._parameters['standardType'].value
00374 
00375         ## define common label for pre pat jet
00376         ## creation steps in makePatJets
00377         #label=standardAlgo+standardType
00378 
00379         ## create old module label from standardAlgo
00380         ## and standardType and return
00381         def oldLabel(prefix=''):
00382             return jetCollectionString(prefix, '', '')
00383 
00384         ## create new module label from old module
00385         ## label and return
00386         def newLabel(oldLabel):
00387             newLabel=oldLabel
00388             if(oldLabel.find(standardAlgo)>=0 and oldLabel.find(standardType)>=0):
00389                 oldLabel=oldLabel.replace(standardAlgo, algoLabel).replace(standardType, typeLabel)
00390             else:
00391                 oldLabel=oldLabel+algoLabel+typeLabel
00392             return oldLabel
00393 
00394         ## clone module and add it to the patDefaultSequence
00395         def addClone(hook, **replaceStatements):
00396             ## create a clone of the hook with corresponding
00397             ## parameter replacements
00398             newModule = getattr(process, hook).clone(**replaceStatements)
00399             ## add the module to the sequence
00400             addModuleToSequence(hook, newModule)
00401 
00402         ## add module to the patDefaultSequence
00403         def addModuleToSequence(hook, newModule):
00404             hookModule = getattr(process, hook)
00405             ## add the new module with standardAlgo &
00406             ## standardType replaced in module label
00407             setattr( process, newLabel(hook), newModule)
00408             ## add new module to default sequence
00409             ## just behind the hookModule
00410             process.patDefaultSequence.replace( hookModule, hookModule*newModule )
00411 
00412         print "*********************************************************************"
00413         print "NOTE TO USER: when running on 35X sample with 36X s/w versions you   "
00414         print "              need to adapt for different event contents. The        "
00415         print "              adaptations need to be made:                           "
00416         print "                                                                     "
00417         print "               - re-configuration of secondary vertex tag discrimi-  "
00418         print "                 nator information.                                  "
00419         print "                                                                     "
00420         print "               - take out soft electron tagger information, which    "
00421         print "                 is not available on 35X.                            "
00422         print "*********************************************************************"
00423 
00424         ## add a clone of patJets
00425         addClone(oldLabel(), jetSource = jetCollection)
00426         ## add a clone of selectedPatJets
00427         addClone(oldLabel('selected'), src=cms.InputTag(newLabel(oldLabel())))
00428         ## add a clone of cleanPatJets
00429         if( doL1Cleaning ):
00430             addClone(oldLabel('clean'), src=cms.InputTag(newLabel(oldLabel('selected'))))
00431         ## add a clone of countPatJets
00432         if( doL1Counters ):
00433             if( doL1Cleaning ):
00434                 addClone(oldLabel('count'), src=cms.InputTag(newLabel(oldLabel('clean'))))
00435             else:
00436                 addClone(oldLabel('count'), src=cms.InputTag(newLabel(oldLabel('selected'))))
00437 
00438         ## get attributes of new module
00439         l1Jets = getattr(process, newLabel(oldLabel()))
00440 
00441         ## add a clone of gen jet matching
00442         addClone('patJetPartonMatch', src = jetCollection)
00443         addClone('patJetGenJetMatch', src = jetCollection, matched = genJetCollection)
00444 
00445         ## add a clone of parton and flavour associations
00446         addClone('patJetPartonAssociation', jets = jetCollection)
00447         addClone('patJetFlavourAssociation', srcByReference = cms.InputTag(newLabel('patJetPartonAssociation')))
00448 
00449         ## fix label for input tag
00450         def fixInputTag(x): x.setModuleLabel(newLabel(x.moduleLabel))
00451         ## fix label for vector of input tags
00452         def fixVInputTag(x): x[0].setModuleLabel(newLabel(x[0].moduleLabel))
00453 
00454         ## provide allLayer1Jet inputs with individual labels
00455         fixInputTag(l1Jets.genJetMatch)
00456         fixInputTag(l1Jets.genPartonMatch)
00457         fixInputTag(l1Jets.JetPartonMapSource)
00458 
00459         ## make VInputTag from strings
00460         def vit(*args) : return cms.VInputTag( *[ cms.InputTag(x) for x in args ] )
00461 
00462         if (doJTA or doBTagging):
00463             ## add clone of jet track association
00464             process.load("RecoJets.JetAssociationProducers.ak5JTA_cff")
00465             from RecoJets.JetAssociationProducers.ak5JTA_cff import ak5JetTracksAssociatorAtVertex
00466             ## add jet track association module to processes
00467             jtaLabel = 'jetTracksAssociatorAtVertex'+algoLabel+typeLabel
00468             setattr( process, jtaLabel, ak5JetTracksAssociatorAtVertex.clone(jets = jetCollection) )
00469             process.makePatJets.replace(process.patJetCharge, getattr(process,jtaLabel)+process.patJetCharge)
00470             l1Jets.trackAssociationSource = cms.InputTag(jtaLabel)
00471             addClone('patJetCharge', src=cms.InputTag(jtaLabel)),
00472             fixInputTag(l1Jets.jetChargeSource)
00473         else:
00474             ## switch embedding of track association and jet
00475             ## charge estimate to 'False'
00476             l1Jets.addAssociatedTracks = False
00477             l1Jets.addJetCharge = False
00478 
00479         if (doBTagging):
00480             ## define postfixLabel
00481             postfixLabel=algoLabel+typeLabel
00482             ## add b tagging sequence
00483             (btagSeq, btagLabels) = runBTagging35X(process, jetCollection, postfixLabel)
00484             ## add b tagging sequence before running the allLayer1Jets modules
00485             process.makePatJets.replace(getattr(process,jtaLabel), getattr(process,jtaLabel)+btagSeq)
00486             ## replace corresponding tags for pat jet production
00487             l1Jets.trackAssociationSource = cms.InputTag(btagLabels['jta'])
00488             l1Jets.tagInfoSources = cms.VInputTag( *[ cms.InputTag(x) for x in btagLabels['tagInfos'] ] )
00489             l1Jets.discriminatorSources = cms.VInputTag( *[ cms.InputTag(x) for x in btagLabels['jetTags']  ] )
00490         else:
00491             ## switch general b tagging info switch off
00492             l1Jets.addBTagInfo = False
00493 
00494         if (doJetID):
00495             l1Jets.addJetID = cms.bool(True)
00496             jetIdLabelNew = jetIdLabel + 'JetID'
00497             l1Jets.jetIDMap = cms.InputTag( jetIdLabelNew )
00498         else :
00499             l1Jets.addJetID = cms.bool(False)
00500 
00501         if (jetCorrLabel != None):
00502             ## add clone of jet energy corrections;
00503             ## catch a couple of exceptions first
00504             if (jetCorrLabel == False ):
00505                 raise ValueError, "In addJetCollection 'jetCorrLabel' must be set to 'None', not 'False'"
00506             if (jetCorrLabel == "None"):
00507                 raise ValueError, "In addJetCollection 'jetCorrLabel' must be set to 'None' (without quotes)"
00508             ## check for the correct format
00509             if type(jetCorrLabel) != type(('AK5','Calo')):
00510                 raise ValueError, "In addJetCollection 'jetCorrLabel' must be 'None', or of type ('Algo','Type')"
00511 
00512             ## add clone of jetCorrFactors
00513             addClone('patJetCorrFactors', jetSource = jetCollection)
00514             switchJECParameters( getattr(process,newLabel('patJetCorrFactors')), jetCorrLabel[0], jetCorrLabel[1], oldAlgo='AK5',oldType='Calo' )
00515             fixVInputTag(l1Jets.jetCorrFactorsSource)
00516 
00517             ## switch type1MET corrections off for PFJets
00518             if( jetCollection.__str__().find('PFJets')>=0 ):
00519                 print '================================================='
00520                 print 'Type1MET corrections are switched off for PFJets.'
00521                 print 'of type %s%s.' % (jetCorrLabel[0].swapcase(), jetCorrLabel[1])
00522                 print 'Users are recommened to use pfMET together with  '
00523                 print 'PFJets.'
00524                 print '================================================='
00525                 doType1MET=False
00526 
00527             ## add a clone of the type1MET correction for the new jet collection
00528             if (doType1MET):
00529                 ## in case there is no jet correction service in the paths add it
00530                 ## as L2L3 if possible, as combined from L2 and L3 otherwise
00531                 if not hasattr( process, '%s%sL2L3' % (jetCorrLabel[0].swapcase(), jetCorrLabel[1]) ):
00532                     setattr( process, '%s%sL2L3' % (jetCorrLabel[0].swapcase(), jetCorrLabel[1]),
00533                              cms.ESSource("JetCorrectionServiceChain",
00534                                           correctors = cms.vstring('%s%sL2Relative' % (jetCorrLabel[0].swapcase(), jetCorrLabel[1]),
00535                                                                    '%s%sL3Absolute' % (jetCorrLabel[0].swapcase(), jetCorrLabel[1])
00536                                                                    )
00537                                           )
00538                              )
00539                 ## add a clone of the type1MET correction
00540                 ## and the following muonMET correction
00541                 addClone('metJESCorAK5CaloJet', inputUncorJetsLabel = jetCollection.value(),
00542                          corrector = cms.string('%s%sL2L3' % (jetCorrLabel[0].swapcase(), jetCorrLabel[1]))
00543                          )
00544                 addClone('metJESCorAK5CaloJetMuons', uncorMETInputTag = cms.InputTag(newLabel('metJESCorAK5CaloJet')))
00545                 addClone('patMETs', metSource = cms.InputTag(newLabel('metJESCorAK5CaloJetMuons')))
00546                 l1MET = getattr(process, newLabel('patMETs'))
00547                 ## add new met collections output to the pat summary
00548                 process.patCandidateSummary.candidates += [ cms.InputTag(newLabel('patMETs')) ]
00549         else:
00550             ## switch jetCorrFactors off
00551             l1Jets.addJetCorrFactors = False
00552 
00553 
00554 
00555 addJetCollection35X=AddJetCollection35X()
00556 
00557 
00558 class SwitchJetCollection35X(ConfigToolBase):
00559 
00560     """
00561     ------------------------------------------------------------------
00562     Switch the collection of jets in PAT from the default value to a
00563     new jet collection. This is a re-implementation to run the 36X
00564     version of PAT on 35X input samples.
00565     ------------------------------------------------------------------
00566     """
00567     _label='switchJetCollection35X'
00568     _defaultParameters=dicttypes.SortedKeysDict()
00569     def __init__(self):
00570         ConfigToolBase.__init__(self)
00571         self.addParameter(self._defaultParameters,'jetCollection',self._defaultValue,'Input jet collection', cms.InputTag)
00572         self.addParameter(self._defaultParameters,'doJTA',True, "run b tagging sequence for new jet collection and add it to the new pat jet collection")
00573         self.addParameter(self._defaultParameters,'doBTagging',True, 'run JetTracksAssociation and JetCharge and add it to the new pat jet collection (will autom. be true if doBTagging is set to true)')
00574         self.addParameter(self._defaultParameters,'jetCorrLabel',None, "algorithm and type of JEC; use 'None' for no JEC; examples are ('AK5','Calo'), ('SC7','Calo'), ('KT4','PF')", tuple,acceptNoneValue=True)
00575         self.addParameter(self._defaultParameters,'doType1MET',True, "if jetCorrLabel is not 'None', set this to 'True' to redo the Type1 MET correction for the new jet colleection; at the moment it must be 'False' for non CaloJets otherwise the JetMET POG module crashes. ")
00576         self.addParameter(self._defaultParameters,'genJetCollection',cms.InputTag("ak5GenJets"), "GenJet collection to match to")
00577         self.addParameter(self._defaultParameters,'doJetID',True, "add jetId variables to the added jet collection")
00578         self.addParameter(self._defaultParameters,'jetIdLabel',"ak5", " specify the label prefix of the xxxJetID object; in general it is the jet collection tag like ak5, kt4 sc5, aso. For more information have a look to SWGuidePATTools#add_JetCollection")
00579         self.addParameter(self._defaultParameters,'postfix',"", "postfix of default sequence")
00580 
00581         self._parameters=copy.deepcopy(self._defaultParameters)
00582         self._comment = ""
00583 
00584     def getDefaultParameters(self):
00585         return self._defaultParameters
00586 
00587     def __call__(self,process,
00588                  jetCollection      = None,
00589                  doJTA              = None,
00590                  doBTagging         = None,
00591                  jetCorrLabel       = None,
00592                  doType1MET         = None,
00593                  genJetCollection   = None,
00594                  doJetID            = None,
00595                  jetIdLabel         = None,
00596                  postfix            = None):
00597 
00598         if jetCollection  is None:
00599             jetCollection=self._defaultParameters['jetCollection'].value
00600         if doJTA is None:
00601             doJTA=self._defaultParameters['doJTA'].value
00602         if doBTagging is None:
00603             doBTagging=self._defaultParameters['doBTagging'].value
00604         if jetCorrLabel  is None:
00605             jetCorrLabel=self._defaultParameters['jetCorrLabel'].value
00606         if doType1MET  is None:
00607             doType1MET=self._defaultParameters['doType1MET'].value
00608         if genJetCollection  is None:
00609             genJetCollection=self._defaultParameters['genJetCollection'].value
00610         if doJetID  is None:
00611             doJetID=self._defaultParameters['doJetID'].value
00612         if jetIdLabel  is None:
00613             jetIdLabel=self._defaultParameters['jetIdLabel'].value
00614         if postfix  is None:
00615             postfix=self._defaultParameters['postfix'].value
00616 
00617         self.setParameter('jetCollection',jetCollection)
00618         self.setParameter('doJTA',doJTA)
00619         self.setParameter('doBTagging',doBTagging)
00620         self.setParameter('jetCorrLabel',jetCorrLabel)
00621         self.setParameter('doType1MET',doType1MET)
00622         self.setParameter('genJetCollection',genJetCollection)
00623         self.setParameter('doJetID',doJetID)
00624         self.setParameter('jetIdLabel',jetIdLabel)
00625         self.setParameter('postfix',postfix)
00626 
00627         self.apply(process)
00628 
00629     def toolCode(self, process):
00630         jetCollection=self._parameters['jetCollection'].value
00631         doJTA=self._parameters['doJTA'].value
00632         doBTagging=self._parameters['doBTagging'].value
00633         jetCorrLabel=self._parameters['jetCorrLabel'].value
00634         doType1MET =self._parameters['doType1MET'].value
00635         genJetCollection=self._parameters['genJetCollection'].value
00636         doJetID=self._parameters['doJetID'].value
00637         jetIdLabel=self._parameters['jetIdLabel'].value
00638         postfix=self._parameters['postfix'].value
00639 
00640 
00641         ## save label of old input jet collection
00642         oldLabel = applyPostfix(process, "patJets", postfix).jetSource;
00643 
00644         ## replace input jet collection for generator matches
00645         applyPostfix(process, "patJetPartonMatch", postfix).src = jetCollection
00646         applyPostfix(process, "patJetGenJetMatch", postfix).src = jetCollection
00647         applyPostfix(process, "patJetGenJetMatch", postfix).matched = genJetCollection
00648         applyPostfix(process, "patJetPartonAssociation", postfix).jets = jetCollection
00649         ## replace input jet collection for pat jet production
00650         applyPostfix(process, "patJets", postfix).jetSource = jetCollection
00651 
00652         ## make VInputTag from strings
00653         def vit(*args) : return cms.VInputTag( *[ cms.InputTag(x) for x in args ] )
00654 
00655         if (doJTA or doBTagging):
00656             ## replace jet track association
00657             process.load("RecoJets.JetAssociationProducers.ak5JTA_cff")
00658             from RecoJets.JetAssociationProducers.ak5JTA_cff import ak5JetTracksAssociatorAtVertex
00659             setattr(process, "jetTracksAssociatorAtVertex"+postfix, ak5JetTracksAssociatorAtVertex.clone(jets = jetCollection))
00660             getattr(process, "patDefaultSequence"+postfix).replace(
00661                 applyPostfix(process, "patJetCharge", postfix),
00662                 getattr(process, "jetTracksAssociatorAtVertex" + postfix) #module with postfix that is not n patDefaultSequence
00663                 + applyPostfix(process, "patJetCharge", postfix)
00664                 )
00665 
00666             applyPostfix(process, "patJetCharge", postfix).src = 'jetTracksAssociatorAtVertex'+postfix
00667             applyPostfix(process, "patJets", postfix).trackAssociationSource = 'jetTracksAssociatorAtVertex'+postfix
00668         else:
00669             ## remove the jet track association from the std
00670             ## sequence
00671             removeIfInSequence(process,  "patJetCharge",  "patDefaultSequence", postfix)
00672             ## switch embedding of track association and jet
00673             ## charge estimate to 'False'
00674             applyPostfix(process, "patJets", postfix).addAssociatedTracks = False
00675             applyPostfix(process, "patJets", postfix).addJetCharge = False
00676 
00677         if (doBTagging):
00678             ## replace b tagging sequence; add postfix label 'AOD' as crab will
00679             ## crash when confronted with empy labels
00680             (btagSeq, btagLabels) = runBTagging35X(process, jetCollection, 'AOD',postfix)
00681             ## add b tagging sequence before running the allLayer1Jets modules
00682             getattr(process, "patDefaultSequence"+postfix).replace(
00683                 getattr( process,"jetTracksAssociatorAtVertex"+postfix),
00684                 getattr( process,"jetTracksAssociatorAtVertex"+postfix) + btagSeq
00685                 )
00686 
00687             ## replace corresponding tags for pat jet production
00688             applyPostfix(process, "patJets", postfix).trackAssociationSource = btagLabels['jta']
00689             applyPostfix(process, "patJets", postfix).tagInfoSources = cms.VInputTag( *[ cms.InputTag(x) for x in btagLabels['tagInfos'] ] )
00690             applyPostfix(process, "patJets", postfix).discriminatorSources = cms.VInputTag( *[ cms.InputTag(x) for x in btagLabels['jetTags']  ] )
00691         else:
00692             ## remove b tagging from the std sequence
00693             removeIfInSequence(process,  "secondaryVertexNegativeTagInfos",  "patDefaultSequence", postfix)
00694             removeIfInSequence(process,  "simpleSecondaryVertexNegativeBJetTags",  "patDefaultSequence", postfix)
00695 
00696             ## switch embedding of b tagging for pat
00697             ## jet production to 'False'
00698             applyPostfix(process, "patJets", postfix).addBTagInfo = False
00699 
00700         if (doJetID):
00701             jetIdLabelNew = jetIdLabel + 'JetID'
00702             applyPostfix(process, "patJets", postfix).jetIDMap = cms.InputTag( jetIdLabelNew )
00703         else:
00704             applyPostfix(process, "patJets", postfix).addJetID = cms.bool(False)
00705 
00706 
00707         if (jetCorrLabel!=None):
00708             ## replace jet energy corrections; catch
00709             ## a couple of exceptions first
00710             if (jetCorrLabel == False ):
00711                 raise ValueError, "In switchJetCollection 'jetCorrLabel' must be set to 'None', not 'False'"
00712             if (jetCorrLabel == "None"):
00713                 raise ValueError, "In switchJetCollection 'jetCorrLabel' must be set to 'None' (without quotes)"
00714             ## check for the correct format
00715             if (type(jetCorrLabel)!=type(('AK5','Calo'))):
00716                 raise ValueError, "In switchJetCollection 'jetCorrLabel' must be 'None', or of type ('Algo','Type')"
00717 
00718             ## switch JEC parameters to the new jet collection
00719             applyPostfix(process, "patJetCorrFactors", postfix).jetSource = jetCollection
00720             switchJECParameters(applyPostfix(process, "patJetCorrFactors", postfix), jetCorrLabel[0], jetCorrLabel[1], oldAlgo='AK5',oldType='Calo')
00721 
00722             ## switch type1MET corrections off for PFJets
00723             if( jetCollection.__str__().find('PFJets')>=0 ):
00724                 print '================================================='
00725                 print 'Type1MET corrections are switched off for PFJets.'
00726                 print 'of type %s%s.' % (jetCorrLabel[0].swapcase(), jetCorrLabel[1])
00727                 print 'Users are recommened to use pfMET together with  '
00728                 print 'PFJets.'
00729                 print '================================================='
00730                 doType1MET=False
00731 
00732             ## redo the type1MET correction for the new jet collection
00733             if (doType1MET):
00734                 ## in case there is no jet correction service in the paths add it
00735                 ## as L2L3 if possible, as combined from L2 and L3 otherwise
00736                 if not hasattr( process, '%s%sL2L3' % (jetCorrLabel[0].swapcase(), jetCorrLabel[1]) ):
00737                     setattr( process, '%s%sL2L3' % (jetCorrLabel[0].swapcase(), jetCorrLabel[1]),
00738                              cms.ESSource("JetCorrectionServiceChain",
00739                                           correctors = cms.vstring('%s%sL2Relative' % (jetCorrLabel[0].swapcase(), jetCorrLabel[1]),
00740                                                                    '%s%sL3Absolute' % (jetCorrLabel[0].swapcase(), jetCorrLabel[1])
00741                                                                    )
00742                                           )
00743                              )
00744                 ## configure the type1MET correction the following muonMET
00745                 ## corrections have the metJESCorAK5CaloJet as input and
00746                 ## are automatically correct
00747                 applyPostfix(process, "metJESCorAK5CaloJet", postfix).inputUncorJetsLabel = jetCollection.value()
00748                 applyPostfix(process, "metJESCorAK5CaloJet", postfix).corrector = '%s%sL2L3' % (jetCorrLabel[0].swapcase(), jetCorrLabel[1])
00749         else:
00750             ## remove the jetCorrFactors from the std sequence
00751             process.patJetMETCorrections.remove(process.patJetCorrFactors)
00752             ## switch embedding of jetCorrFactors off
00753             ## for pat jet production
00754             applyPostfix(process, "patJets", postfix).addJetCorrFactors = False
00755 
00756 
00757 switchJetCollection35X=SwitchJetCollection35X()
00758 
00759 
00760 ## ------------------------------------------------------
00761 ## Automatic pick-up of RelVal input files
00762 ## ------------------------------------------------------
00763 
00764 class PickRelValInputFiles( ConfigToolBase ):
00765     """  Picks up RelVal input files automatically and
00766   returns a vector of strings with the paths to be used in [PoolSource].fileNames
00767     PickRelValInputFiles( cmsswVersion, relVal, dataTier, condition, globalTag, maxVersions, skipFiles, numberOfFiles, debug )
00768     - cmsswVersion : CMSSW release to pick up the RelVal files from
00769                      optional; default: the current release (determined automatically from environment)
00770     - formerVersion: use the last before the last valid CMSSW release to pick up the RelVal files from
00771                      applies also, if 'cmsswVersion' is set explicitly
00772                      optional; default: False
00773     - relVal       : RelVal sample to be used
00774                      optional; default: 'RelValTTbar'
00775     - dataTier     : data tier to be used
00776                      optional; default: 'GEN-SIM-RECO'
00777     - condition    : identifier of GlobalTag as defined in Configurations/PyReleaseValidation/python/autoCond.py
00778                      possibly overwritten, if 'globalTag' is set explicitly
00779                      optional; default: 'startup'
00780     - globalTag    : name of GlobalTag as it is used in the data path of the RelVals
00781                      optional; default: determined automatically as defined by 'condition' in Configurations/PyReleaseValidation/python/autoCond.py
00782       !!!            Determination is done for the release one runs in, not for the release the RelVals have been produced in.
00783       !!!            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,
00784                      but also an extension identifying the data: 'GR_R_311_V2_RelVal_wzMu2010B'
00785     - maxVersions  : max. versioning number of RelVal to check
00786                      optional; default: 9
00787     - skipFiles    : number of files to skip for a found RelVal sample
00788                      optional; default: 0
00789     - numberOfFiles: number of files to pick up
00790                      setting it to negative values, returns all found ('skipFiles' remains active though)
00791                      optional; default: -1
00792     - debug        : switch to enable enhanced messages in 'stdout'
00793                      optional; default: False
00794     """
00795 
00796     _label             = 'pickRelValInputFiles'
00797     _defaultParameters = dicttypes.SortedKeysDict()
00798 
00799     def getDefaultParameters( self ):
00800         return self._defaultParameters
00801 
00802     def __init__( self ):
00803         ConfigToolBase.__init__( self )
00804         self.addParameter( self._defaultParameters, 'cmsswVersion' , os.getenv( "CMSSW_VERSION" )                                        , 'auto from environment' )
00805         self.addParameter( self._defaultParameters, 'formerVersion', False                                                               , '' )
00806         self.addParameter( self._defaultParameters, 'relVal'       , 'RelValTTbar'                                                       , '' )
00807         self.addParameter( self._defaultParameters, 'dataTier'     , 'GEN-SIM-RECO'                                                      , '' )
00808         self.addParameter( self._defaultParameters, 'condition'    , 'startup'                                                           , '' )
00809         self.addParameter( self._defaultParameters, 'globalTag'    , autoCond[ self.getDefaultParameters()[ 'condition' ].value ][ : -5 ], 'auto from \'condition\'' )
00810         self.addParameter( self._defaultParameters, 'maxVersions'  , 9                                                                   , '' )
00811         self.addParameter( self._defaultParameters, 'skipFiles'    , 0                                                                   , '' )
00812         self.addParameter( self._defaultParameters, 'numberOfFiles', -1                                                                  , 'all' )
00813         self.addParameter( self._defaultParameters, 'debug'        , False                                                               , '' )
00814         self._parameters = copy.deepcopy( self._defaultParameters )
00815         self._comment = ""
00816 
00817     def __call__( self
00818                 , cmsswVersion  = None
00819                 , formerVersion = None
00820                 , relVal        = None
00821                 , dataTier      = None
00822                 , condition     = None
00823                 , globalTag     = None
00824                 , maxVersions   = None
00825                 , skipFiles     = None
00826                 , numberOfFiles = None
00827                 , debug         = None
00828                 ):
00829         if cmsswVersion is None:
00830             cmsswVersion = self.getDefaultParameters()[ 'cmsswVersion' ].value
00831         if formerVersion is None:
00832             formerVersion = self.getDefaultParameters()[ 'formerVersion' ].value
00833         if relVal is None:
00834             relVal = self.getDefaultParameters()[ 'relVal' ].value
00835         if dataTier is None:
00836             dataTier = self.getDefaultParameters()[ 'dataTier' ].value
00837         if condition is None:
00838             condition = self.getDefaultParameters()[ 'condition' ].value
00839         if globalTag is None:
00840             globalTag = autoCond[ condition ][ : -5 ] # auto from 'condition'
00841         if maxVersions is None:
00842             maxVersions = self.getDefaultParameters()[ 'maxVersions' ].value
00843         if skipFiles is None:
00844             skipFiles = self.getDefaultParameters()[ 'skipFiles' ].value
00845         if numberOfFiles is None:
00846             numberOfFiles = self.getDefaultParameters()[ 'numberOfFiles' ].value
00847         if debug is None:
00848             debug = self.getDefaultParameters()[ 'debug' ].value
00849         self.setParameter( 'cmsswVersion' , cmsswVersion )
00850         self.setParameter( 'formerVersion', formerVersion )
00851         self.setParameter( 'relVal'       , relVal )
00852         self.setParameter( 'dataTier'     , dataTier )
00853         self.setParameter( 'condition'    , condition )
00854         self.setParameter( 'globalTag'    , globalTag )
00855         self.setParameter( 'maxVersions'  , maxVersions )
00856         self.setParameter( 'skipFiles'    , skipFiles )
00857         self.setParameter( 'numberOfFiles', numberOfFiles )
00858         self.setParameter( 'debug'        , debug )
00859         return self.apply()
00860 
00861     def messageEmptyList( self ):
00862         print '%s DEBUG: Empty file list returned'%( self._label )
00863         print '    This might be overwritten by providing input files explicitly to the source module in the main configuration file.'
00864 
00865     def apply( self ):
00866         cmsswVersion  = self._parameters[ 'cmsswVersion'  ].value
00867         formerVersion = self._parameters[ 'formerVersion' ].value
00868         relVal        = self._parameters[ 'relVal'        ].value
00869         dataTier      = self._parameters[ 'dataTier'      ].value
00870         condition     = self._parameters[ 'condition'     ].value # only used for GT determination in initialization, if GT not explicitly given
00871         globalTag     = self._parameters[ 'globalTag'     ].value
00872         maxVersions   = self._parameters[ 'maxVersions'   ].value
00873         skipFiles     = self._parameters[ 'skipFiles'     ].value
00874         numberOfFiles = self._parameters[ 'numberOfFiles' ].value
00875         debug         = self._parameters[ 'debug'         ].value
00876 
00877         filePaths = []
00878 
00879         patchId = '_patch'
00880         slhcId  = '_SLHC'
00881         ibId    = '_X_'
00882         if patchId in cmsswVersion:
00883             cmsswVersion = cmsswVersion.split( patchId )[ 0 ]
00884         elif slhcId in cmsswVersion:
00885             cmsswVersion = cmsswVersion.split( slhcId )[ 0 ]
00886         elif ibId in cmsswVersion or formerVersion:
00887             outputTuple = Popen( [ 'scram', 'l -c CMSSW' ], stdout = PIPE, stderr = PIPE ).communicate()
00888             if len( outputTuple[ 1 ] ) != 0:
00889                 print '%s INFO : SCRAM error'%( self._label )
00890                 if debug:
00891                     print '    from trying to determine last valid releases before \'%s\''%( cmsswVersion )
00892                     print
00893                     print outputTuple[ 1 ]
00894                     print
00895                     self.messageEmptyList()
00896                 return filePaths
00897             versions = { 'last'      :''
00898                        , 'lastToLast':''
00899                        }
00900             for line in outputTuple[ 0 ].splitlines():
00901                 version = line.split()[ 1 ]
00902                 if cmsswVersion.split( ibId )[ 0 ] in version or cmsswVersion.rpartition( '_' )[ 0 ] in version:
00903                     if not ( patchId in version or slhcId in version or ibId in version ):
00904                         versions[ 'lastToLast' ] = versions[ 'last' ]
00905                         versions[ 'last' ]       = version
00906                         if version == cmsswVersion:
00907                             break
00908             if formerVersion:
00909                 cmsswVersion = versions[ 'lastToLast' ]
00910             else:
00911                 cmsswVersion = versions[ 'last' ]
00912 
00913         if debug:
00914             print '%s DEBUG: Called with...'%( self._label )
00915             for key in self._parameters.keys():
00916                print '    %s:\t'%( key ),
00917                print self._parameters[ key ].value,
00918                if self._parameters[ key ].value is self.getDefaultParameters()[ key ].value:
00919                    print ' (default)'
00920                else:
00921                    print
00922                if key == 'cmsswVersion' and cmsswVersion != self._parameters[ key ].value:
00923                    if formerVersion:
00924                        print '    ==> modified to last to last valid release %s (s. \'formerVersion\' parameter)'%( cmsswVersion )
00925                    else:
00926                        print '    ==> modified to last valid release %s'%( cmsswVersion )
00927 
00928         command   = ''
00929         storage   = ''
00930         domain    = socket.getfqdn().split( '.' )
00931         if len( domain ) == 0:
00932             print '%s INFO : Cannot determine domain of this computer'%( self._label )
00933             if debug:
00934                 self.messageEmptyList()
00935             return filePaths
00936         elif len( domain ) == 1:
00937             print '%s INFO : Running on local host \'%s\' without direct access to RelVal files'%( self._label, domain[ 0 ] )
00938             if debug:
00939                 self.messageEmptyList()
00940             return filePaths
00941         if domain[ -2 ] == 'cern' and domain[ -1 ] == 'ch':
00942             command = 'nsls'
00943             storage = '/castor/cern.ch/cms'
00944         elif domain[ -2 ] == 'fnal' and domain[ -1 ] == 'gov':
00945             command = 'ls'
00946             storage = '/pnfs/cms/WAX/11'
00947         else:
00948             print '%s INFO : Running on site \'%s.%s\' without direct access to RelVal files'%( self._label, domain[ -2 ], domain[ -1 ] )
00949             if debug:
00950                 self.messageEmptyList()
00951             return filePaths
00952         if debug:
00953             print '%s DEBUG: Running at site \'%s.%s\''%( self._label, domain[ -2 ], domain[ -1 ] )
00954             print '    using command   \'%s\''%( command )
00955             print '    on storage path %s'%( storage )
00956         rfdirPath    = '/store/relval/%s/%s/%s/%s-v'%( cmsswVersion, relVal, dataTier, globalTag )
00957         argument     = '%s%s'%( storage, rfdirPath )
00958         validVersion = 0
00959 
00960         for version in range( maxVersions, 0, -1 ):
00961             filePaths = []
00962             fileCount = 0
00963             if debug:
00964                 print '%s DEBUG: Checking directory \'%s%i\''%( self._label, argument, version )
00965             directories = Popen( [ command, '%s%i'%( argument, version ) ], stdout = PIPE, stderr = PIPE ).communicate()[0]
00966             for directory in directories.splitlines():
00967                 files = Popen( [ command, '%s%i/%s'%( argument, version, directory ) ], stdout = PIPE, stderr = PIPE ).communicate()[0]
00968                 for file in files.splitlines():
00969                     if len( file ) > 0 and validVersion != version:
00970                         validVersion = version
00971                         if debug:
00972                             print '%s DEBUG: Valid version set to \'v%i\''%( self._label, validVersion )
00973                     if numberOfFiles == 0:
00974                         break
00975                     if len( file ) > 0:
00976                         if debug:
00977                             print '%s DEBUG: File \'%s\' found'%( self._label, file )
00978                         fileCount += 1
00979                     if fileCount > skipFiles:
00980                         filePath = '%s%i/%s/%s'%( rfdirPath, version, directory, file )
00981                         filePaths.append( filePath )
00982                     if numberOfFiles > 0 and len( filePaths ) >= numberOfFiles:
00983                         break
00984                 if debug:
00985                     if numberOfFiles != 0:
00986                         print '%s DEBUG: %i file(s) found so far'%( self._label, fileCount )
00987                     else:
00988                         print '%s DEBUG: No files requested'%( self._label )
00989                 if numberOfFiles >= 0 and len( filePaths ) >= numberOfFiles:
00990                     break
00991             if numberOfFiles > 0:
00992                 if len( filePaths ) >= numberOfFiles:
00993                     break
00994             if validVersion > 0:
00995                 break
00996 
00997         if validVersion == 0:
00998             print '%s INFO : No RelVal file(s) found at all in \'%s*\''%( self._label, argument )
00999             if debug:
01000                 self.messageEmptyList()
01001         elif len( filePaths ) == 0:
01002             print '%s INFO : No RelVal file(s) picked up in \'%s%i\''%( self._label, argument, validVersion )
01003             if debug:
01004                 self.messageEmptyList()
01005         elif len( filePaths ) < numberOfFiles:
01006             print '%s INFO : Only %i RelVal files picked up in \'%s%i\''%( self._label, len( filePaths ), argument, validVersion )
01007 
01008         if debug:
01009             print '%s DEBUG: returning %i file(s)\n%s'%( self._label, len( filePaths ), filePaths )
01010         return filePaths
01011 
01012 pickRelValInputFiles = PickRelValInputFiles()