Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce AlCaHarvesting / PCLMetadataWriter unit test #33880

Merged
merged 4 commits into from
May 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,9 @@ void SiStripGainsPCLHarvester::gainQualityMonitor(DQMStore::IBooker& ibooker_,

if (Gain != 1.) {
std::vector<MonitorElement*> charge_histos = APVGain::FetchMonitor(new_charge_histos, DetId, tTopo_);

if (!Charge_Vs_Index)
continue;
TH2S* chvsidx = (Charge_Vs_Index)->getTH2S();
int bin = chvsidx->GetXaxis()->FindBin(Index);
TH1D* Proj = chvsidx->ProjectionY("proj", bin, bin);
Expand Down
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
85 changes: 85 additions & 0 deletions Calibration/TkAlCaRecoProducers/test/parseFwkJobReport.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
from __future__ import print_function
import xml.etree.ElementTree as ET
import sys

## 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_DQM_FILENAME='./DQM_V0001_R000325022__Express__PCLTest__ALCAPROMPT.root'
TARGET_DB_FILES=7
TARGET_DB_FILENAME='sqlite_file:promptCalibConditions.db'
TOTAL_TARGET_FILES=TARGET_DQM_FILES+TARGET_DB_FILES

#_____________________________________________________
def parseXML(xmlfile):

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

# get root element
root = tree.getroot()

totAnaEntries=len(root.findall('AnalysisFile'))

if(totAnaEntries!=TOTAL_TARGET_FILES):
print("ERROR: found a not expected number (",totAnaEntries,") of 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==TARGET_DB_FILENAME):
countDBfiles+=1
elif(child.text==TARGET_DQM_FILENAME):
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 of 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")
except IOError:
print("File not accessible")
sys.exit(1)

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

#_____________________________________________________
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()
123 changes: 123 additions & 0 deletions Calibration/TkAlCaRecoProducers/test/testPCLAlCaHarvesting.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
from __future__ import print_function
import calendar
import CondCore.Utilities.conddblib as conddb

#___________________________________________________________________
def findRunStopTime(run_number):
con = conddb.connect(url = conddb.make_url("pro"))
session = con.session()
RunInfo = session.get_dbtype(conddb.RunInfo)
bestRun = session.query(RunInfo.run_number,RunInfo.start_time, RunInfo.end_time).filter(RunInfo.run_number >= run_number).first()
if bestRun is None:
raise Exception("Run %s can't be matched with an existing run in the database." % run_number)

start= bestRun[1]
stop = bestRun[2]

bestRunStartTime = calendar.timegm( bestRun[1].utctimetuple() ) << 32
bestRunStopTime = calendar.timegm( bestRun[2].utctimetuple() ) << 32

print("run start time:",start,"(",bestRunStartTime,")")
print("run stop time: ",stop,"(",bestRunStopTime,")")

return bestRunStopTime

import optparse
parser = optparse.OptionParser(usage = 'Usage: %prog [options] <file> [<file> ...]\n')
parser.add_option('-G', '--inputGT',
dest = 'inputGT',
default = 'auto:run2_data',
help = 'Global Tag to get conditions')

parser.add_option('-r', '--inputRun',
dest = 'inputRun',
default = 325022,
help = 'run to be used')

parser.add_option('-t', '--inputTime',
dest = 'inputTime',
default = 6614916085915320320,
help = 'time to be used')

parser.add_option('-e', '--enableJobReport',
dest = 'empty',
default = None,
help = 'unused')

(options, arguments) = parser.parse_args()

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')

##
## configure the source with an random run
##
process.source = cms.Source("EmptySource",
firstRun = cms.untracked.uint32(options.inputRun),
numberEventsInRun = cms.untracked.uint32(1),
numberEventsInLuminosityBlock = cms.untracked.uint32(1),
firstTime = cms.untracked.uint64(options.inputTime),
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, options.inputGT, '')

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
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ void SiStripQualityHotStripIdentifierRoot::bookHistos() {
}
if (!gotNentries) {
edm::LogWarning("SiStripQualityHotStripIdentifierRoot")
<< " [SiStripQualityHotStripIdentifierRoot::bookHistos] :: Histogram with to check # of evemnts missing"
<< " [SiStripQualityHotStripIdentifierRoot::bookHistos] :: Histogram with to check # of events missing"
<< std::endl;
}
for (; iter != iterEnd; ++iter) {
Expand Down