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 # [rawDataCollection=rawDataCollector] \
10 # [outputPath=output_directory]
11 #
12 # The output files will appear as output_directory/runNNNNNN/runNNNNNN_lumiNNNN_indexNNNNNN.raw .
13 
14 import sys
15 import os
16 import FWCore.ParameterSet.Config as cms
17 import FWCore.ParameterSet.VarParsing as VarParsing
18 
19 process = cms.Process("FAKE")
20 
21 process.maxEvents = cms.untracked.PSet(
22  input = cms.untracked.int32(-1) # to be overwritten after parsing the command line options
23 )
24 
25 process.source = cms.Source("PoolSource",
26  fileNames = cms.untracked.vstring() # to be overwritten after parsing the command line options
27 )
28 
29 from EventFilter.Utilities.EvFDaqDirector_cfi import EvFDaqDirector as _EvFDaqDirector
30 process.EvFDaqDirector = _EvFDaqDirector.clone(
31  baseDir = "", # to be overwritten after parsing the command line options
32  buBaseDir = "", # to be overwritten after parsing the command line options
33  runNumber = 0 # to be overwritten after parsing the command line options
34 )
35 
36 process.writer = cms.OutputModule("RawStreamFileWriterForBU",
37  source = cms.InputTag('rawDataCollector'), # to be overwritten after parsing the command line options
38  numEventsPerFile = cms.uint32(0) # to be overwritten after parsing the command line options
39 )
40 
41 process.endpath = cms.EndPath(process.writer)
42 
43 process.load('FWCore.MessageService.MessageLogger_cfi')
44 process.MessageLogger.cerr.FwkReport.reportEvery = 0 # to be overwritten after parsing the command line options
45 
46 # parse command line options
47 options = VarParsing.VarParsing ('python')
48 for name in 'filePrepend', 'maxEvents', 'outputFile', 'secondaryOutputFile', 'section', 'tag', 'storePrepend', 'totalSections':
49  del options._register[name]
50  del options._beenSet[name]
51  del options._info[name]
52  del options._types[name]
53  if name in options._singletons:
54  del options._singletons[name]
55  if name in options._lists:
56  del options._lists[name]
57  if name in options._noCommaSplit:
58  del options._noCommaSplit[name]
59  if name in options._noDefaultClear:
60  del options._noDefaultClear[name]
61 
62 
63 options.register('runNumber',
64  0,
65  VarParsing.VarParsing.multiplicity.singleton,
66  VarParsing.VarParsing.varType.int,
67  "Run number to use")
68 
69 options.register('lumiNumber',
70  None,
71  VarParsing.VarParsing.multiplicity.singleton,
72  VarParsing.VarParsing.varType.int,
73  "Luminosity section number to use")
74 
75 options.register('eventsPerLumi',
76  11650,
77  VarParsing.VarParsing.multiplicity.singleton,
78  VarParsing.VarParsing.varType.int,
79  "Number of events in the given luminosity section to process")
80 
81 options.register('eventsPerFile',
82  50,
83  VarParsing.VarParsing.multiplicity.singleton,
84  VarParsing.VarParsing.varType.int,
85  "Split the output into files with at most this number of events")
86 
87 options.register('rawDataCollection',
88  'rawDataCollector',
89  VarParsing.VarParsing.multiplicity.singleton,
90  VarParsing.VarParsing.varType.string,
91  "FEDRawDataCollection to be repacked into RAW format")
92 
93 options.register('outputPath',
94  os.getcwd(),
95  VarParsing.VarParsing.multiplicity.singleton,
96  VarParsing.VarParsing.varType.string,
97  "Output directory for the FED RAW data files")
98 
99 options.parseArguments()
100 
101 # check that the option values are valide
102 if options.runNumber <= 0:
103  sys.stderr.write('Invalid run number\n')
104  sys.exit(1)
105 
106 if options.lumiNumber is not None and options.lumiNumber <= 0:
107  sys.stderr.write('Invalid luminosity section number\n')
108  sys.exit(1)
109 
110 if options.eventsPerLumi == 0 or options.eventsPerLumi < -1:
111  sys.stderr.write('Invalid number of events per luminosity section\n')
112  sys.exit(1)
113 
114 if options.eventsPerFile <= 0:
115  sys.stderr.write('Invalid number of events per output file\n')
116  sys.exit(1)
117 
118 # configure the job based on the command line options
119 process.source.fileNames = options.inputFiles
120 if options.lumiNumber is not None:
121  # process only one lumisection
122  process.source.lumisToProcess = cms.untracked.VLuminosityBlockRange('%d:%d' % (options.runNumber, options.lumiNumber))
123  process.maxEvents.input = options.eventsPerLumi
124 process.EvFDaqDirector.runNumber = options.runNumber
125 process.EvFDaqDirector.baseDir = options.outputPath
126 process.EvFDaqDirector.buBaseDir = options.outputPath
127 process.writer.source = options.rawDataCollection
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()