Skip to content

Commit

Permalink
add unittest for simBeamSpot writer and reader
Browse files Browse the repository at this point in the history
  • Loading branch information
francescobrivio committed Jun 13, 2023
1 parent 78ee4e1 commit efca3b9
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 12 deletions.
47 changes: 38 additions & 9 deletions CondTools/BeamSpot/test/BeamProfile2DBReader_cfg.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,56 @@
import FWCore.ParameterSet.Config as cms
import FWCore.ParameterSet.VarParsing as VarParsing

process = cms.Process("READ")

options = VarParsing.VarParsing()
options.register('unitTest',
False, # default value
VarParsing.VarParsing.multiplicity.singleton, # singleton or list
VarParsing.VarParsing.varType.bool, # string, int, or float
"are we running the unit test?")
options.register('inputTag',
"myTagName", # default value
VarParsing.VarParsing.multiplicity.singleton, # singleton or list
VarParsing.VarParsing.varType.string, # string, int, or float
"output tag name")
options.register('startRun',
1, # default value
VarParsing.VarParsing.multiplicity.singleton, # singleton or list
VarParsing.VarParsing.varType.int, # string, int, or float
"location of the input data")
options.register('startLumi',
1, # default value
VarParsing.VarParsing.multiplicity.singleton, # singleton or list
VarParsing.VarParsing.varType.int, # string, int, or float
"IOV Start Lumi")
options.parseArguments()

process.load("FWCore.MessageService.MessageLogger_cfi")
#process.MessageLogger.cerr.FwkReport.reportEvery = 1000000 # do not clog output with IO
process.MessageLogger.cerr.FwkReport.reportEvery = 1000000 # do not clog output with IO

process.maxEvents = cms.untracked.PSet( input = cms.untracked.int32(1) ) # large number of events is needed since we probe 5000LS for run (see below)
process.maxEvents = cms.untracked.PSet( input = cms.untracked.int32(1) ) # large number of events is needed since we probe 5000LS for run (see below)

####################################################################
# Empty source
####################################################################

process.source = cms.Source("EmptySource",
firstRun = cms.untracked.uint32(1),
firstLuminosityBlock = cms.untracked.uint32(1), # probe one LS after the other
numberEventsInLuminosityBlock = cms.untracked.uint32(1), # probe one event per LS
numberEventsInRun = cms.untracked.uint32(1), # a number of events > the number of LS possible in a real run (5000 s ~ 32 h)
firstRun = cms.untracked.uint32(options.startRun),
firstLuminosityBlock = cms.untracked.uint32(options.startRun), # probe one LS after the other
numberEventsInLuminosityBlock = cms.untracked.uint32(1), # probe one event per LS
numberEventsInRun = cms.untracked.uint32(1), # a number of events > the number of LS possible in a real run (5000 s ~ 32 h)
)

####################################################################
# Connect to conditions DB
####################################################################

if options.unitTest:
tag_name = 'simBS_tag'
else:
tag_name = options.inputTag

# either from Global Tag
# process.load("Configuration.StandardSequences.FrontierConditions_GlobalTag_cfi")
# from Configuration.AlCa.GlobalTag import GlobalTag
Expand All @@ -33,20 +62,20 @@
# process.dbInput = cms.ESSource("PoolDBESSource",
# CondDBSimBeamSpot,
# toGet = cms.VPSet(cms.PSet(record = cms.string('SimBeamSpotObjectsRcd'),
# tag = cms.string('your_tag_name') # customize with input tag name
# tag = cms.string(tag_name) # customize with input tag name
# )
# )
# )

# ...or specify local db file:
from CondCore.CondDB.CondDB_cfi import *
CondDBSimBeamSpot = CondDB.clone(connect = cms.string("sqlite_file:your_db_file.db")) # customize with input db file
CondDBSimBeamSpot = CondDB.clone(connect = cms.string("sqlite_file:test_%s.db" % tag_name)) # customize with input db file
process.PoolDBESSource = cms.ESSource("PoolDBESSource",
CondDBSimBeamSpot,
DumpStat=cms.untracked.bool(True),
toGet = cms.VPSet(cms.PSet(
record = cms.string('SimBeamSpotObjectsRcd'),
tag = cms.string('your_tag_name') # customize with input tag name
tag = cms.string(tag_name) # customize with input tag name
))
)

Expand Down
2 changes: 1 addition & 1 deletion CondTools/BeamSpot/test/BuildFile.xml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<test name="testReadWriteOnlineBSFromDB" command="testReadWriteOnlineBSFromDB.sh"/>
<test name="testReadWriteBeamSpotsFromDB" command="testReadWriteBeamSpotsFromDB.sh"/>
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

function die { echo $1: status $2 ; exit $2; }

echo "TESTING BeamSpotOnline From DB Read / Write codes ..."
echo "TESTING BeamSpot + BeamSpotOnline + SimBeamSpot From DB Read / Write codes ..."

## clean the input db files
if test -f "test_BSHLT_tag.db"; then
Expand All @@ -13,6 +13,10 @@ if test -f "test_BSLegacy_tag.db"; then
rm -fr test_BSLegacy_tag.db
fi

if test -f "test_simBS_tag.db"; then
rm -fr test_simBS_tag.db
fi

## copy the input file
cp -pr $CMSSW_BASE/src/CondTools/BeamSpot/data/BeamFitResults_Run306171.txt .

Expand All @@ -22,8 +26,11 @@ cmsRun ${SCRAM_TEST_PATH}/BeamSpotOnlineRecordsWriter_cfg.py unitTest=True input

printf "TESTING Writing BeamSpotOnlineHLTObjectsRcd DB object ...\n\n"
cmsRun ${SCRAM_TEST_PATH}/BeamSpotOnlineRecordsWriter_cfg.py unitTest=True inputRecord=BeamSpotOnlineHLTObjectsRcd || die "Failure writing payload for BeamSpotOnlineHLTObjectsRcd" $?
# test read

printf "TESTING Writing SimBeamSpotObjectsRcd DB object ...\n\n"
cmsRun ${SCRAM_TEST_PATH}/BeamProfile2DBWriter_cfg.py unitTest=True || die "Failure writing payload for SimBeamSpotObjectsRcd" $?

# test read
printf "TESTING Reading BeamSpotOnlineLegacyObjectsRcd DB object ...\n\n"
cmsRun ${SCRAM_TEST_PATH}/BeamSpotOnlineRecordsReader_cfg.py unitTest=True inputRecord=BeamSpotOnlineLegacyObjectsRcd || die "Failure reading payload for BeamSpotOnlineLegacyObjectsRcd" $?

Expand All @@ -35,3 +42,6 @@ cmsRun ${SCRAM_TEST_PATH}/BeamSpotRcdPrinter_cfg.py || die "Failure running Beam

printf "TESTING converting BeamSpotOnlineObjects from BeamSpotObjects ...\n\n"
cmsRun ${SCRAM_TEST_PATH}/BeamSpotOnlineFromOfflineConverter_cfg.py unitTest=True || die "Failure running BeamSpotRcdPrinter" $?

printf "TESTING Reading SimBeamSpotObjectsRcd DB object ...\n\n"
cmsRun ${SCRAM_TEST_PATH}/BeamProfile2DBReader_cfg.py unitTest=True || die "Failure reading payload for SimBeamSpotObjectsRcd" $?

0 comments on commit efca3b9

Please sign in to comment.