Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-06-29 02:25:55

0001 # Convert the RAW data from EDM .root files into DAQ .raw format
0002 #
0003 # usage: cmsRun $CMSSW_RELEASE_BASE/HLTrigger/Tools/python/convertToRaw.py \
0004 #           inputFiles=/store/path/file.root[,/store/path/file.root,...] \
0005 #           runNumber=NNNNNN \
0006 #           [lumiNumber=NNNN] \
0007 #           [eventsPerFile=50] \
0008 #           [eventsPerLumi=11650] \
0009 #           [outputPath=output_directory]
0010 #
0011 # The output files will appear as output_directory/runNNNNNN/runNNNNNN_lumiNNNN_indexNNNNNN.raw .
0012 
0013 import sys
0014 import os
0015 import FWCore.ParameterSet.Config as cms
0016 import FWCore.ParameterSet.VarParsing as VarParsing
0017 
0018 process = cms.Process("FAKE")
0019 
0020 process.maxEvents = cms.untracked.PSet(
0021     input = cms.untracked.int32(-1)                                 # to be overwritten after parsing the command line options
0022 )
0023 
0024 process.source = cms.Source("PoolSource",
0025     fileNames = cms.untracked.vstring()                             # to be overwritten after parsing the command line options
0026 )
0027 
0028 process.EvFDaqDirector = cms.Service( "EvFDaqDirector",
0029     runNumber = cms.untracked.uint32( 0 ),                          # to be overwritten after parsing the command line options
0030     baseDir = cms.untracked.string( "" ),                           # to be overwritten after parsing the command line options
0031     buBaseDir = cms.untracked.string( "" ),                         # to be overwritten after parsing the command line options
0032     useFileBroker = cms.untracked.bool( False ),
0033     fileBrokerKeepAlive = cms.untracked.bool( True ),
0034     fileBrokerPort = cms.untracked.string( "8080" ),
0035     fileBrokerUseLocalLock = cms.untracked.bool( True ),
0036     fuLockPollInterval = cms.untracked.uint32( 2000 ),
0037     requireTransfersPSet = cms.untracked.bool( False ),
0038     selectedTransferMode = cms.untracked.string( "" ),
0039     mergingPset = cms.untracked.string( "" ),
0040     outputAdler32Recheck = cms.untracked.bool( False ),
0041 )
0042 
0043 process.writer = cms.OutputModule("RawStreamFileWriterForBU",
0044     source = cms.InputTag('rawDataCollector'),
0045     numEventsPerFile = cms.uint32(0)                                # to be overwritten after parsing the command line options
0046 )
0047 
0048 process.endpath = cms.EndPath(process.writer)
0049 
0050 process.load('FWCore.MessageService.MessageLogger_cfi')
0051 process.MessageLogger.cerr.FwkReport.reportEvery = 0                # to be overwritten after parsing the command line options
0052 
0053 # parse command line options
0054 options = VarParsing.VarParsing ('python')
0055 for name in 'filePrepend', 'maxEvents', 'outputFile', 'secondaryOutputFile', 'section', 'tag', 'storePrepend', 'totalSections':
0056     del options._register[name]
0057     del options._beenSet[name]
0058     del options._info[name]
0059     del options._types[name]
0060     if name in options._singletons:
0061         del options._singletons[name]
0062     if name in options._lists:
0063         del options._lists[name]
0064     if name in options._noCommaSplit:
0065         del options._noCommaSplit[name]
0066     if name in options._noDefaultClear:
0067         del options._noDefaultClear[name]
0068 
0069 
0070 options.register('runNumber',
0071                  0,
0072                  VarParsing.VarParsing.multiplicity.singleton,
0073                  VarParsing.VarParsing.varType.int,
0074                  "Run number to use")
0075 
0076 options.register('lumiNumber',
0077                  None,
0078                  VarParsing.VarParsing.multiplicity.singleton,
0079                  VarParsing.VarParsing.varType.int,
0080                  "Luminosity section number to use")
0081 
0082 options.register('eventsPerLumi',
0083                  11650,
0084                  VarParsing.VarParsing.multiplicity.singleton,
0085                  VarParsing.VarParsing.varType.int,
0086                  "Number of events in the given luminosity section to process")
0087 
0088 options.register('eventsPerFile',
0089                  50,
0090                  VarParsing.VarParsing.multiplicity.singleton,
0091                  VarParsing.VarParsing.varType.int,
0092                  "Split the output into files with at most this number of events")
0093 
0094 options.register('outputPath',
0095                  os.getcwd(),
0096                  VarParsing.VarParsing.multiplicity.singleton,
0097                  VarParsing.VarParsing.varType.string,
0098                  "Output directory for the FED RAW data files")
0099 
0100 options.parseArguments()
0101 
0102 # check that the option values are valide
0103 if options.runNumber <= 0:
0104     sys.stderr.write('Invalid run number\n')
0105     sys.exit(1)
0106 
0107 if options.lumiNumber is not None and options.lumiNumber <= 0:
0108     sys.stderr.write('Invalid luminosity section number\n')
0109     sys.exit(1)
0110 
0111 if options.eventsPerLumi == 0 or options.eventsPerLumi < -1:
0112     sys.stderr.write('Invalid number of events per luminosity section\n')
0113     sys.exit(1)
0114 
0115 if options.eventsPerFile <= 0:
0116     sys.stderr.write('Invalid number of events per output file\n')
0117     sys.exit(1)
0118 
0119 # configure the job based on the command line options
0120 process.source.fileNames = options.inputFiles
0121 if options.lumiNumber is not None:
0122     # process only one lumisection
0123     process.source.lumisToProcess = cms.untracked.VLuminosityBlockRange('%d:%d' % (options.runNumber, options.lumiNumber))
0124     process.maxEvents.input = options.eventsPerLumi
0125 process.EvFDaqDirector.runNumber = options.runNumber
0126 process.EvFDaqDirector.baseDir = options.outputPath
0127 process.EvFDaqDirector.buBaseDir = options.outputPath
0128 process.writer.numEventsPerFile = options.eventsPerFile
0129 process.MessageLogger.cerr.FwkReport.reportEvery = options.eventsPerFile
0130 
0131 # create the output directory, if it does not exist
0132 outputRunPath = f'{options.outputPath}/run{options.runNumber:06d}'
0133 os.makedirs(outputRunPath, exist_ok=True)
0134 open(f'{outputRunPath}/fu.lock', 'w').close()