Skip to content

Commit

Permalink
improve scripts and actually return failure if does not pass checks
Browse files Browse the repository at this point in the history
  • Loading branch information
mmusich committed May 28, 2021
1 parent 0a5f3d1 commit 61f3cb0
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 14 deletions.
31 changes: 21 additions & 10 deletions Calibration/TkAlCaRecoProducers/test/parseFwkJobReport.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
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']
'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
Expand All @@ -15,30 +21,33 @@ def parseXML(xmlfile):
# get root element
root = tree.getroot()

if( len(root.findall('AnalysisFile'))!=8):
print("ERROR: not found enough AnalysisFile entries in the FrameworkJobReport.xml")
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=='sqlite_file:promptCalibConditions.db'):
if(child.text==TARGET_DB_FILENAME):
countDBfiles+=1
elif(child.text=='./DQM_V0001_R000325022__Express__PCLTest__ALCAPROMPT.root'):
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 DB files,",countDBfiles)
print("ERROR! Found a not expected number of DB files",countDBfiles)
return -1

if(countDQMfiles!=TARGET_DQM_FILES):
Expand All @@ -52,22 +61,24 @@ def parseXML(xmlfile):

return 0

#_____________________________________________________
def main():
try:
f = open("FrameworkJobReport.xml")
# Do something with the file
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)

return result

#_____________________________________________________
if __name__ == "__main__":

# calling main function
Expand Down
58 changes: 54 additions & 4 deletions Calibration/TkAlCaRecoProducers/test/testPCLAlCaHarvesting.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,52 @@
import FWCore.ParameterSet.Config as cms
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
Expand All @@ -12,11 +59,14 @@
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(325022),
firstRun = cms.untracked.uint32(options.inputRun),
numberEventsInRun = cms.untracked.uint32(1),
numberEventsInLuminosityBlock = cms.untracked.uint32(1),
firstTime = cms.untracked.uint64(6614916085915320320),
firstTime = cms.untracked.uint64(options.inputTime),
timeBetweenEvents = cms.untracked.uint64(1)
)

Expand All @@ -38,7 +88,7 @@

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

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

0 comments on commit 61f3cb0

Please sign in to comment.