Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2025-05-15 02:27:44

0001 #!/usr/bin/env python3
0002 """
0003 _Repack_
0004 
0005 Module that generates standard repack configurations
0006 
0007 """
0008 import copy
0009 import FWCore.ParameterSet.Config as cms
0010 import HLTrigger.HLTfilters.hltHighLevel_cfi as hlt
0011 import Configuration.Skimming.RAWSkims_cff as RawSkims
0012 from Configuration.AlCa.GlobalTag import GlobalTag
0013 
0014 def repackProcess(**args):
0015     """
0016     _repackProcess_
0017 
0018     Creates and returns a repack process
0019 
0020     supported options:
0021 
0022     - outputs      : defines output modules
0023     - globalTag    : contains trigger paths for the selected raw skims in outputs
0024 
0025     Additional comments:
0026 
0027     The selectEvents parameter within the outputs option is of type list, provided by T0.
0028     The paths in the list have an added ":HLT" to the string, which needs to be removed for propper use of the raw skim machinery.
0029 
0030     """
0031     from Configuration.EventContent.EventContent_cff import RAWEventContent
0032     from Configuration.EventContent.EventContent_cff import HLTSCOUTEventContent
0033     from Configuration.EventContent.EventContent_cff import L1SCOUTEventContent
0034     process = cms.Process("REPACK")
0035     process.load("FWCore.MessageLogger.MessageLogger_cfi")
0036     
0037     process.maxEvents = cms.untracked.PSet(input=cms.untracked.int32(-1))
0038 
0039     process.configurationMetadata = cms.untracked.PSet(
0040         name=cms.untracked.string("repack-config"),
0041         version=cms.untracked.string("none"),
0042         annotation=cms.untracked.string("auto generated configuration")
0043     )
0044 
0045     process.options = cms.untracked.PSet(
0046         Rethrow=cms.untracked.vstring("ProductNotFound", "TooManyProducts", "TooFewProducts"),
0047         wantSummary=cms.untracked.bool(False)
0048     )
0049 
0050     process.source = cms.Source(
0051         "NewEventStreamFileReader",
0052         fileNames=cms.untracked.vstring()
0053     )
0054 
0055     defaultDataTier = "RAW"
0056 
0057     # Should we default to something if dataTier arg isn't provided?
0058     dataTier = args.get('dataTier', defaultDataTier)
0059     eventContent = RAWEventContent
0060     if dataTier == "HLTSCOUT":
0061         eventContent = HLTSCOUTEventContent
0062     elif dataTier == "L1SCOUT":
0063         eventContent = L1SCOUTEventContent
0064 
0065     outputs = args.get('outputs', [])
0066 
0067     if len(outputs) > 0:
0068         process.outputPath = cms.EndPath()
0069         
0070     globalTag = args.get('globalTag', None)   
0071     if globalTag:
0072         process.load('Configuration.StandardSequences.FrontierConditions_GlobalTag_cff')
0073         process.GlobalTag = GlobalTag(process.GlobalTag, globalTag, '')
0074     
0075     for output in outputs:
0076 
0077         selectEventsBase = output.get('selectEvents', None)
0078         rawSkim = output.get('rawSkim', None)
0079 
0080         if rawSkim:
0081 
0082             skim = getattr(RawSkims, rawSkim)
0083             setattr(process, rawSkim, skim)
0084 
0085             selectEventsBase = [item.replace(":HLT", "") for item in selectEventsBase]
0086 
0087             baseSelection = hlt.hltHighLevel.clone(
0088                 TriggerResultsTag = "TriggerResults::HLT",
0089                 HLTPaths = cms.vstring(selectEventsBase)
0090             )
0091 
0092             path = cms.Path(skim + baseSelection)
0093             
0094             baseSelectionName = output['moduleLabel'].split('_')[1] + f'_{rawSkim}'
0095 
0096             setattr(process, baseSelectionName, baseSelection)
0097             selectEvents = f"{baseSelectionName}Path"
0098             setattr(process, selectEvents, path)
0099 
0100         else:
0101             selectEvents = selectEventsBase
0102 
0103         moduleLabel = output['moduleLabel']
0104         maxSize = output.get('maxSize', None)
0105 
0106         outputModule = cms.OutputModule(
0107             "PoolOutputModule",
0108             compressionAlgorithm=copy.copy(eventContent.compressionAlgorithm),
0109             compressionLevel=copy.copy(eventContent.compressionLevel),
0110             fileName=cms.untracked.string("%s.root" % moduleLabel)
0111         )
0112 
0113         outputModule.dataset = cms.untracked.PSet(dataTier=cms.untracked.string(dataTier))
0114 
0115         if maxSize is not None:
0116             outputModule.maxSize = cms.untracked.int32(maxSize)
0117 
0118         if selectEvents is not None:
0119             outputModule.SelectEvents = cms.untracked.PSet(
0120                 SelectEvents=cms.vstring(selectEvents)
0121             )
0122 
0123         setattr(process, moduleLabel, outputModule)
0124 
0125         process.outputPath += outputModule
0126 
0127     return process