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 process.EvFDaqDirector = cms.Service( "EvFDaqDirector",
30  runNumber = cms.untracked.uint32( 0 ), # to be overwritten after parsing the command line options
31  baseDir = cms.untracked.string( "" ), # to be overwritten after parsing the command line options
32  buBaseDir = cms.untracked.string( "" ), # to be overwritten after parsing the command line options
33  useFileBroker = cms.untracked.bool( False ),
34  fileBrokerKeepAlive = cms.untracked.bool( True ),
35  fileBrokerPort = cms.untracked.string( "8080" ),
36  fileBrokerUseLocalLock = cms.untracked.bool( True ),
37  fuLockPollInterval = cms.untracked.uint32( 2000 ),
38  requireTransfersPSet = cms.untracked.bool( False ),
39  selectedTransferMode = cms.untracked.string( "" ),
40  mergingPset = cms.untracked.string( "" ),
41  outputAdler32Recheck = cms.untracked.bool( False ),
42 )
43 
44 process.writer = cms.OutputModule("RawStreamFileWriterForBU",
45  source = cms.InputTag('rawDataCollector'), # to be overwritten after parsing the command line options
46  numEventsPerFile = cms.uint32(0) # to be overwritten after parsing the command line options
47 )
48 
49 process.endpath = cms.EndPath(process.writer)
50 
51 process.load('FWCore.MessageService.MessageLogger_cfi')
52 process.MessageLogger.cerr.FwkReport.reportEvery = 0 # to be overwritten after parsing the command line options
53 
54 # parse command line options
55 options = VarParsing.VarParsing ('python')
56 for name in 'filePrepend', 'maxEvents', 'outputFile', 'secondaryOutputFile', 'section', 'tag', 'storePrepend', 'totalSections':
57  del options._register[name]
58  del options._beenSet[name]
59  del options._info[name]
60  del options._types[name]
61  if name in options._singletons:
62  del options._singletons[name]
63  if name in options._lists:
64  del options._lists[name]
65  if name in options._noCommaSplit:
66  del options._noCommaSplit[name]
67  if name in options._noDefaultClear:
68  del options._noDefaultClear[name]
69 
70 
71 options.register('runNumber',
72  0,
73  VarParsing.VarParsing.multiplicity.singleton,
74  VarParsing.VarParsing.varType.int,
75  "Run number to use")
76 
77 options.register('lumiNumber',
78  None,
79  VarParsing.VarParsing.multiplicity.singleton,
80  VarParsing.VarParsing.varType.int,
81  "Luminosity section number to use")
82 
83 options.register('eventsPerLumi',
84  11650,
85  VarParsing.VarParsing.multiplicity.singleton,
86  VarParsing.VarParsing.varType.int,
87  "Number of events in the given luminosity section to process")
88 
89 options.register('eventsPerFile',
90  50,
91  VarParsing.VarParsing.multiplicity.singleton,
92  VarParsing.VarParsing.varType.int,
93  "Split the output into files with at most this number of events")
94 
95 options.register('rawDataCollection',
96  'rawDataCollector',
97  VarParsing.VarParsing.multiplicity.singleton,
98  VarParsing.VarParsing.varType.string,
99  "FEDRawDataCollection to be repacked into RAW format")
100 
101 options.register('outputPath',
102  os.getcwd(),
103  VarParsing.VarParsing.multiplicity.singleton,
104  VarParsing.VarParsing.varType.string,
105  "Output directory for the FED RAW data files")
106 
107 options.parseArguments()
108 
109 # check that the option values are valide
110 if options.runNumber <= 0:
111  sys.stderr.write('Invalid run number\n')
112  sys.exit(1)
113 
114 if options.lumiNumber is not None and options.lumiNumber <= 0:
115  sys.stderr.write('Invalid luminosity section number\n')
116  sys.exit(1)
117 
118 if options.eventsPerLumi == 0 or options.eventsPerLumi < -1:
119  sys.stderr.write('Invalid number of events per luminosity section\n')
120  sys.exit(1)
121 
122 if options.eventsPerFile <= 0:
123  sys.stderr.write('Invalid number of events per output file\n')
124  sys.exit(1)
125 
126 # configure the job based on the command line options
127 process.source.fileNames = options.inputFiles
128 if options.lumiNumber is not None:
129  # process only one lumisection
130  process.source.lumisToProcess = cms.untracked.VLuminosityBlockRange('%d:%d' % (options.runNumber, options.lumiNumber))
131  process.maxEvents.input = options.eventsPerLumi
132 process.EvFDaqDirector.runNumber = options.runNumber
133 process.EvFDaqDirector.baseDir = options.outputPath
134 process.EvFDaqDirector.buBaseDir = options.outputPath
135 process.writer.source = options.rawDataCollection
136 process.writer.numEventsPerFile = options.eventsPerFile
137 process.MessageLogger.cerr.FwkReport.reportEvery = options.eventsPerFile
138 
139 # create the output directory, if it does not exist
140 outputRunPath = f'{options.outputPath}/run{options.runNumber:06d}'
141 os.makedirs(outputRunPath, exist_ok=True)
142 open(f'{outputRunPath}/fu.lock', 'w').close()