CMS 3D CMS Logo

convertToRaw.py
Go to the documentation of this file.
1 # Convert the RAW data from EDM .root files into DAQ .raw format
2 #
3 # usage: cmsRun $CMSSW_RELEASE_BASE/HLTrigger/Tools/python/convertToRaw.py \
4 # inputFiles=/store/path/file.root[,/store/path/file.root,...] \
5 # runNumber=NNNNNN \
6 # [lumiNumber=NNNN] \
7 # [eventsPerFile=50] \
8 # [eventsPerLumi=11650] \
9 # [outputPath=output_directory]
10 #
11 # The output files will appear as output_directory/runNNNNNN/runNNNNNN_lumiNNNN_indexNNNNNN.raw .
12 
13 import sys
14 import os
15 import FWCore.ParameterSet.Config as cms
16 import FWCore.ParameterSet.VarParsing as VarParsing
17 
18 process = cms.Process("FAKE")
19 
20 process.maxEvents = cms.untracked.PSet(
21  input = cms.untracked.int32(-1) # to be overwritten after parsing the command line options
22 )
23 
24 process.source = cms.Source("PoolSource",
25  fileNames = cms.untracked.vstring() # to be overwritten after parsing the command line options
26 )
27 
28 process.EvFDaqDirector = cms.Service( "EvFDaqDirector",
29  runNumber = cms.untracked.uint32( 0 ), # to be overwritten after parsing the command line options
30  baseDir = cms.untracked.string( "" ), # to be overwritten after parsing the command line options
31  buBaseDir = cms.untracked.string( "" ), # to be overwritten after parsing the command line options
32  useFileBroker = cms.untracked.bool( False ),
33  fileBrokerKeepAlive = cms.untracked.bool( True ),
34  fileBrokerPort = cms.untracked.string( "8080" ),
35  fileBrokerUseLocalLock = cms.untracked.bool( True ),
36  fuLockPollInterval = cms.untracked.uint32( 2000 ),
37  requireTransfersPSet = cms.untracked.bool( False ),
38  selectedTransferMode = cms.untracked.string( "" ),
39  mergingPset = cms.untracked.string( "" ),
40  outputAdler32Recheck = cms.untracked.bool( False ),
41 )
42 
43 process.writer = cms.OutputModule("RawStreamFileWriterForBU",
44  source = cms.InputTag('rawDataCollector'),
45  numEventsPerFile = cms.uint32(0) # to be overwritten after parsing the command line options
46 )
47 
48 process.endpath = cms.EndPath(process.writer)
49 
50 process.load('FWCore.MessageService.MessageLogger_cfi')
51 process.MessageLogger.cerr.FwkReport.reportEvery = 0 # to be overwritten after parsing the command line options
52 
53 # parse command line options
54 options = VarParsing.VarParsing ('python')
55 for name in 'filePrepend', 'maxEvents', 'outputFile', 'secondaryOutputFile', 'section', 'tag', 'storePrepend', 'totalSections':
56  del options._register[name]
57  del options._beenSet[name]
58  del options._info[name]
59  del options._types[name]
60  if name in options._singletons:
61  del options._singletons[name]
62  if name in options._lists:
63  del options._lists[name]
64  if name in options._noCommaSplit:
65  del options._noCommaSplit[name]
66  if name in options._noDefaultClear:
67  del options._noDefaultClear[name]
68 
69 
70 options.register('runNumber',
71  0,
72  VarParsing.VarParsing.multiplicity.singleton,
73  VarParsing.VarParsing.varType.int,
74  "Run number to use")
75 
76 options.register('lumiNumber',
77  None,
78  VarParsing.VarParsing.multiplicity.singleton,
79  VarParsing.VarParsing.varType.int,
80  "Luminosity section number to use")
81 
82 options.register('eventsPerLumi',
83  11650,
84  VarParsing.VarParsing.multiplicity.singleton,
85  VarParsing.VarParsing.varType.int,
86  "Number of events in the given luminosity section to process")
87 
88 options.register('eventsPerFile',
89  50,
90  VarParsing.VarParsing.multiplicity.singleton,
91  VarParsing.VarParsing.varType.int,
92  "Split the output into files with at most this number of events")
93 
94 options.register('outputPath',
95  os.getcwd(),
96  VarParsing.VarParsing.multiplicity.singleton,
97  VarParsing.VarParsing.varType.string,
98  "Output directory for the FED RAW data files")
99 
100 options.parseArguments()
101 
102 # check that the option values are valide
103 if options.runNumber <= 0:
104  sys.stderr.write('Invalid run number\n')
105  sys.exit(1)
106 
107 if options.lumiNumber is not None and options.lumiNumber <= 0:
108  sys.stderr.write('Invalid luminosity section number\n')
109  sys.exit(1)
110 
111 if options.eventsPerLumi == 0 or options.eventsPerLumi < -1:
112  sys.stderr.write('Invalid number of events per luminosity section\n')
113  sys.exit(1)
114 
115 if options.eventsPerFile <= 0:
116  sys.stderr.write('Invalid number of events per output file\n')
117  sys.exit(1)
118 
119 # configure the job based on the command line options
120 process.source.fileNames = options.inputFiles
121 if options.lumiNumber is not None:
122  # process only one lumisection
123  process.source.lumisToProcess = cms.untracked.VLuminosityBlockRange('%d:%d' % (options.runNumber, options.lumiNumber))
124  process.maxEvents.input = options.eventsPerLumi
125 process.EvFDaqDirector.runNumber = options.runNumber
126 process.EvFDaqDirector.baseDir = options.outputPath
127 process.EvFDaqDirector.buBaseDir = options.outputPath
128 process.writer.numEventsPerFile = options.eventsPerFile
129 process.MessageLogger.cerr.FwkReport.reportEvery = options.eventsPerFile
130 
131 # create the output directory, if it does not exist
132 outputRunPath = f'{options.outputPath}/run{options.runNumber:06d}'
133 os.makedirs(outputRunPath, exist_ok=True)
134 open(f'{outputRunPath}/fu.lock', 'w').close()