Skip to content

Commit

Permalink
introduce unit test for AlCaHarvesting in Calibration/TkAlCaRecoProdu…
Browse files Browse the repository at this point in the history
…cers
  • Loading branch information
mmusich committed May 28, 2021
1 parent 7947c24 commit 04dede8
Show file tree
Hide file tree
Showing 5 changed files with 171 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Calibration/TkAlCaRecoProducers/test/BuildFile.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
<environment>
<bin file="testCalibrationTkAlCaRecoProducers.cpp">
<flags TEST_RUNNER_ARGS=" /bin/bash Calibration/TkAlCaRecoProducers/test testAlCaHarvesting.sh"/>
<use name="FWCore/Utilities"/>
</bin>
</environment>

<use name="DQMServices/Core"/>
<use name="FWCore/Framework"/>
<use name="boost"/>
Expand Down
74 changes: 74 additions & 0 deletions Calibration/TkAlCaRecoProducers/test/parseFwkJobReport.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
from __future__ import print_function
import xml.etree.ElementTree as ET

## declare all constants here
TARGET_LIST_OF_TAGS=['SiPixelQualityFromDbRcd_other', 'SiPixelQualityFromDbRcd_prompt', 'SiPixelQualityFromDbRcd_stuckTBM',
'SiStripApvGain_pcl', 'SiStripApvGainAAG_pcl', 'SiStripBadStrip_pcl', 'SiPixelAli_pcl']
TARGET_DQM_FILES=1
TARGET_DB_FILES=7

def parseXML(xmlfile):

# create element tree object
tree = ET.parse(xmlfile)

# get root element
root = tree.getroot()

if( len(root.findall('AnalysisFile'))!=8):
print("ERROR: not found enough AnalysisFile entries in the FrameworkJobReport.xml")
return -1

listOfInputTags=[]

countDBfiles=0
countDQMfiles=0
# iterate news items
for item in root.findall('AnalysisFile'):
# iterate child elements of item
for child in item:
if(child.tag == 'FileName'):
if(child.text=='sqlite_file:promptCalibConditions.db'):
countDBfiles+=1
elif(child.text=='./DQM_V0001_R000325022__Express__PCLTest__ALCAPROMPT.root'):
countDQMfiles+=1
else:
pass
if(child.tag == 'inputtag'):
listOfInputTags.append(child.attrib['Value'])

if(countDBfiles!=TARGET_DB_FILES):
print("ERROR! Found a not expected number DB files,",countDBfiles)
return -1

if(countDQMfiles!=TARGET_DQM_FILES):
print("ERROR! Found a not expected number of DQM files",countDQMfiles)
return -1

## That's strict!
if(listOfInputTags!=TARGET_LIST_OF_TAGS):
print("ERROR! This ",[x for x in listOfTags if x not in listOfInputTags]," is the set of different tags")
return -1

return 0

def main():
try:
f = open("FrameworkJobReport.xml")
# Do something with the file
except IOError:
print("File not accessible")

# parse xml file
result = parseXML('FrameworkJobReport.xml')
if(result==0):
print("All is fine with the world!")
else:
print("Parsing the FwkJobReport results in failure!")

return result

if __name__ == "__main__":

# calling main function
main()
14 changes: 14 additions & 0 deletions Calibration/TkAlCaRecoProducers/test/testAlCaHarvesting.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#! /bin/bash

function die { echo $1: status $2 ; exit $2; }
function cleanTheHouse {
rm -fr millepede.*
rm -fr pede*
rm -fr treeFile.root
}

echo "TESTING Calibration/TkAlCaRecoProducers ..."
cmsRun -e ${LOCAL_TEST_DIR}/testPCLAlCaHarvesting.py || die "Failure running testPCLAlCaHarvesting.py" $?
cleanTheHouse
echo "PARSING Framework Job Report ..."
python ${LOCAL_TEST_DIR}/parseFwkJobReport.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#include "FWCore/Utilities/interface/TestHelper.h"

RUNTEST()
73 changes: 73 additions & 0 deletions Calibration/TkAlCaRecoProducers/test/testPCLAlCaHarvesting.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import FWCore.ParameterSet.Config as cms

process = cms.Process('ALCAHARVEST')

# import of standard configurations
process.load('Configuration.StandardSequences.Services_cff')
process.load('SimGeneral.HepPDTESSource.pythiapdt_cfi')
process.load('FWCore.MessageService.MessageLogger_cfi')
process.load('Configuration.EventContent.EventContent_cff')
process.load('Configuration.StandardSequences.GeometryRecoDB_cff')
process.load('Configuration.StandardSequences.MagneticField_cff')
process.load('Configuration.StandardSequences.AlCaHarvesting_cff')
process.load('Configuration.StandardSequences.FrontierConditions_GlobalTag_cff')

process.source = cms.Source("EmptySource",
firstRun = cms.untracked.uint32(325022),
numberEventsInRun = cms.untracked.uint32(1),
numberEventsInLuminosityBlock = cms.untracked.uint32(1),
firstTime = cms.untracked.uint64(6614916085915320320),
timeBetweenEvents = cms.untracked.uint64(1)
)

process.maxEvents = cms.untracked.PSet(
input = cms.untracked.int32(1)
)

process.PoolDBOutputService.toPut.append(process.ALCAHARVESTSiStripQuality_dbOutput)
process.PoolDBOutputService.toPut.append(process.ALCAHARVESTSiStripGains_dbOutput)
process.PoolDBOutputService.toPut.append(process.ALCAHARVESTSiStripGainsAAG_dbOutput )
process.PoolDBOutputService.toPut.append(process.ALCAHARVESTSiPixelAli_dbOutput)
process.PoolDBOutputService.toPut.extend(process.ALCAHARVESTSiPixelQuality_dbOutput)

process.pclMetadataWriter.recordsToMap.append(process.ALCAHARVESTSiStripQuality_metadata)
process.pclMetadataWriter.recordsToMap.append(process.ALCAHARVESTSiStripGains_metadata )
process.pclMetadataWriter.recordsToMap.append(process.ALCAHARVESTSiStripGainsAAG_metadata)
process.pclMetadataWriter.recordsToMap.append(process.ALCAHARVESTSiPixelAli_metadata)
process.pclMetadataWriter.recordsToMap.extend(process.ALCAHARVESTSiPixelQuality_metadata)

process.load('Configuration.StandardSequences.FrontierConditions_GlobalTag_cff')
from Configuration.AlCa.GlobalTag import GlobalTag
process.GlobalTag = GlobalTag(process.GlobalTag, 'auto:run2_data', '')

process.SiStripQuality = cms.Path(process.ALCAHARVESTSiStripQuality)
process.alcaSiStripQualityHarvester.CalibrationThreshold = cms.untracked.uint32(0)

process.SiStripGains = cms.Path(process.ALCAHARVESTSiStripGains)
#process.alcaSiStripGainsHarvester.

process.SiStripGainsAAG = cms.Path(process.ALCAHARVESTSiStripGainsAAG)
#process.alcaSiStripGainsAAGHarvester.

process.SiPixelAli = cms.Path(process.ALCAHARVESTSiPixelAli)

process.SiPixelQuality = cms.Path(process.ALCAHARVESTSiPixelQuality)

process.ALCAHARVESTDQMSaveAndMetadataWriter = cms.Path(process.dqmSaver+process.pclMetadataWriter)

process.schedule = cms.Schedule(process.SiStripQuality,
process.SiStripGains,
process.SiStripGainsAAG,
process.SiPixelAli,
process.SiPixelQuality,
process.ALCAHARVESTDQMSaveAndMetadataWriter)

from PhysicsTools.PatAlgos.tools.helpers import associatePatAlgosToolsTask
associatePatAlgosToolsTask(process)

# Customisation from command line

# Add early deletion of temporary data products to reduce peak memory need
from Configuration.StandardSequences.earlyDeleteSettings_cff import customiseEarlyDelete
process = customiseEarlyDelete(process)
# End adding early deletion

0 comments on commit 04dede8

Please sign in to comment.