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

[14.0.X] TkAl: fix PV validation and PV resolution submission scripts #44468

Merged
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 30 additions & 16 deletions Alignment/OfflineValidation/scripts/submitPVResolutionJobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ def getFilesForRun(blob):
"""
returns the list of list files associated with a given dataset for a certain run
"""

cmd2 = ' dasgoclient -limit=0 -query \'file run='+blob[0]+' dataset='+blob[1]+'\''
q = Popen(cmd2 , shell=True, stdout=PIPE, stderr=PIPE)
out, err = q.communicate()
Expand Down Expand Up @@ -187,11 +186,11 @@ def as_dict(config):
return dictionary

#######################################################
def batchScriptCERN(theCMSSW_BASE,runindex, eosdir,lumiToRun,key,config):
def batchScriptCERN(theCMSSW_BASE, cfgdir, runindex, eosdir, lumiToRun, key, config, tkCollection, isUnitTest=False):
#######################################################
'''prepare the batch script, to run on HTCondor'''
script = """#!/bin/bash
source /afs/cern.ch/cms/caf/setup.sh
#source /afs/cern.ch/cms/caf/setup.sh
CMSSW_DIR={CMSSW_BASE_DIR}/src/Alignment/OfflineValidation/test
echo "the mother directory is $CMSSW_DIR"
export X509_USER_PROXY=$CMSSW_DIR/.user_proxy
Expand All @@ -202,22 +201,26 @@ def batchScriptCERN(theCMSSW_BASE,runindex, eosdir,lumiToRun,key,config):
cd $CMSSW_DIR
eval `scram runtime -sh`
cd $LXBATCH_DIR
cp -pr $CMSSW_DIR/cfg/PrimaryVertexResolution_{KEY}_{runindex}_cfg.py .
cmsRun PrimaryVertexResolution_{KEY}_{runindex}_cfg.py GlobalTag={GT} lumi={LUMITORUN} {REC} {EXT} >& log_{KEY}_run{runindex}.out
cp -pr {CFGDIR}/PrimaryVertexResolution_{KEY}_{runindex}_cfg.py .
cmsRun PrimaryVertexResolution_{KEY}_{runindex}_cfg.py TrackCollection={TRKS} GlobalTag={GT} lumi={LUMITORUN} {REC} {EXT} >& log_{KEY}_run{runindex}.out
ls -lh .
#for payloadOutput in $(ls *root ); do cp $payloadOutput $OUT_DIR/pvresolution_{KEY}_{runindex}.root ; done
for payloadOutput in $(ls *root ); do xrdcp -f $payloadOutput root://eoscms/$OUT_DIR/pvresolution_{KEY}_{runindex}.root ; done
tar czf log_{KEY}_run{runindex}.tgz log_{KEY}_run{runindex}.out
for logOutput in $(ls *tgz ); do cp $logOutput $LOG_DIR/ ; done
""".format(CMSSW_BASE_DIR=theCMSSW_BASE,
CFGDIR=cfgdir,
runindex=runindex,
MYDIR=eosdir,
KEY=key,
LUMITORUN=lumiToRun,
TRKS=tkCollection,
GT=config['globaltag'],
EXT="external="+config['external'] if 'external' in config.keys() else "",
REC="records="+config['records'] if 'records' in config.keys() else "")


if not isUnitTest:
script += """for payloadOutput in $(ls *root ); do xrdcp -f $payloadOutput root://eoscms/$OUT_DIR/pvresolution_{KEY}_{runindex}.root ; done
tar czf log_{KEY}_run{runindex}.tgz log_{KEY}_run{runindex}.out
for logOutput in $(ls *tgz ); do cp $logOutput $LOG_DIR/ ; done
""".format(KEY=key, runindex=runindex)

return script

#######################################################
Expand All @@ -237,7 +240,7 @@ def mkdir_eos(out_path):
p.wait()

# now check that the directory exists
command2="/afs/cern.ch/project/eos/installation/cms/bin/eos.select ls "+out_path
command2="eos ls "+out_path
p = subprocess.Popen(command2,shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
(out, err) = p.communicate()
p.wait()
Expand Down Expand Up @@ -307,6 +310,7 @@ def main():

cwd = os.getcwd()
bashdir = os.path.join(cwd,"BASH")
cfgdir = os.path.join(cwd,"cfg")

runs.sort()

Expand All @@ -331,6 +335,9 @@ def main():
lumimask = inputDict["Input"]["lumimask"]
print("\n\n Using JSON file:",lumimask)

tkCollection = inputDict["Input"]["trackcollection"]
print("\n\n Using trackCollection:", tkCollection)

mytuple=[]
print("\n\n First run:",opts.start,"last run:",opts.end)

Expand All @@ -350,14 +357,20 @@ def main():

pool = multiprocessing.Pool(processes=20) # start 20 worker processes
count = pool.map(getFilesForRun,mytuple)
file_info = dict(zip(runs, count))

if(opts.verbose):
print(file_info)
print("printing count")
pprint.pprint(count)

# limit the runs in the dictionary to the filtered ones
file_info = dict(zip([run for run, _ in mytuple], count))

if(opts.verbose):
print("printing file_info")
pprint.pprint(file_info)

count=0
for run in runs:
count=count+1
#if(count>10):
# continue
#run = run.strip("[").strip("]")
Expand All @@ -370,6 +383,7 @@ def main():
print("=====> excluding run:",run)
continue

count=count+1
files = file_info[run]
if(opts.verbose):
print(run, files)
Expand Down Expand Up @@ -405,7 +419,7 @@ def main():

scriptFileName = os.path.join(bashdir,"batchHarvester_"+key+"_"+str(count-1)+".sh")
scriptFile = open(scriptFileName,'w')
scriptFile.write(batchScriptCERN(input_CMSSW_BASE,run,eosdir,theLumi,key,value))
scriptFile.write(batchScriptCERN(input_CMSSW_BASE,cfgdir,run,eosdir,theLumi,key,value,tkCollection,opts.isUnitTest))
scriptFile.close()
#os.system('chmod +x %s' % scriptFileName)

Expand All @@ -417,9 +431,9 @@ def main():
key = key.split(":", 1)[1]

job_submit_file = write_HTCondor_submit_file(bashdir,"batchHarvester_"+key,count,None)
os.system("chmod u+x "+bashdir+"/*.sh")

if opts.submit:
os.system("chmod u+x "+bashdir+"/*.sh")
submissionCommand = "condor_submit "+job_submit_file
print(submissionCommand)
os.system(submissionCommand)
Expand Down
38 changes: 21 additions & 17 deletions Alignment/OfflineValidation/scripts/submitPVValidationJobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def forward_proxy(rundir):
shutil.copyfile(local_proxy, os.path.join(rundir,".user_proxy"))

##############################################
def write_HTCondor_submit_file(path, name, nruns, proxy_path=None):
def write_HTCondor_submit_file(path, logs, name, nruns, proxy_path=None):
##############################################
"""Writes 'job.submit' file in `path`.
Arguments:
Expand All @@ -84,7 +84,7 @@ def write_HTCondor_submit_file(path, name, nruns, proxy_path=None):

job_submit_template="""\
universe = vanilla
requirements = (OpSysAndVer =?= "CentOS7")
requirements = (OpSysAndVer =?= "AlmaLinux9")
executable = {script:s}
output = {jobm:s}/{out:s}.out
error = {jobm:s}/{out:s}.err
Expand All @@ -102,7 +102,7 @@ def write_HTCondor_submit_file(path, name, nruns, proxy_path=None):
with open(job_submit_file, "w") as f:
f.write(job_submit_template.format(script = os.path.join(path,name+"_$(ProcId).sh"),
out = name+"_$(ProcId)",
jobm = os.path.abspath(path),
jobm = os.path.abspath(logs),
flavour = "tomorrow",
njobs = str(nruns),
proxy = proxy_path))
Expand Down Expand Up @@ -328,21 +328,22 @@ def ConfigSectionMap(config, section):

###### method to create recursively directories on EOS #############
def mkdir_eos(out_path):
print("creating",out_path)
print("============== creating",out_path)
newpath='/'
for dir in out_path.split('/'):
newpath=os.path.join(newpath,dir)
# do not issue mkdir from very top of the tree
if newpath.find('test_out') > 0:
#getCommandOutput("eos mkdir"+newpath)
command="/afs/cern.ch/project/eos/installation/cms/bin/eos.select mkdir "+newpath
command="eos mkdir "+newpath
p = subprocess.Popen(command,shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
(out, err) = p.communicate()
print("============== created ",out_path)
#print(out,err)
p.wait()

# now check that the directory exists
command2="/afs/cern.ch/project/eos/installation/cms/bin/eos.select ls "+out_path
command2="eos ls "+out_path
p = subprocess.Popen(command2,shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
(out, err) = p.communicate()
p.wait()
Expand Down Expand Up @@ -543,7 +544,7 @@ def createTheLSFFile(self):
fout.close()


def createTheBashFile(self):
def createTheBashFile(self, isUnitTest):
###############################

# directory to store the BASH to be submitted
Expand All @@ -556,10 +557,6 @@ def createTheBashFile(self):

job_name = self.output_full_name

log_dir = os.path.join(self.the_dir,"log")
if not os.path.exists(log_dir):
os.makedirs(log_dir)

fout.write("#!/bin/bash \n")
#fout.write("export EOS_MGM_URL=root://eoscms.cern.ch \n")
fout.write("JobName="+job_name+" \n")
Expand All @@ -576,9 +573,11 @@ def createTheBashFile(self):
fout.write("cp "+os.path.join(self.cfg_dir,self.outputCfgName)+" . \n")
fout.write("echo \"cmsRun "+self.outputCfgName+"\" \n")
fout.write("cmsRun "+self.outputCfgName+" \n")
fout.write("echo \"Content of working dir is \"`ls -lh` \n")
fout.write("echo \"Content of working dir is:\" \n")
fout.write("ls -lh | sort \n")
#fout.write("less condor_exec.exe \n")
fout.write("for RootOutputFile in $(ls *root ); do xrdcp -f ${RootOutputFile} root://eoscms//eos/cms${OUT_DIR}/${RootOutputFile} ; done \n")
if(not isUnitTest):
fout.write("for RootOutputFile in $(ls *root ); do xrdcp -f ${RootOutputFile} root://eoscms//eos/cms${OUT_DIR}/${RootOutputFile} ; done \n")
#fout.write("mv ${JobName}.out ${CMSSW_DIR}/BASH \n")
fout.write("echo \"Job ended at \" `date` \n")
fout.write("exit 0 \n")
Expand Down Expand Up @@ -1054,11 +1053,11 @@ def main():
vertextype[iConf], tracktype[iConf],
refittertype[iConf], ttrhtype[iConf],
applyruncontrol[iConf],
ptcut[iConf],input_CMSSW_BASE,'.')
ptcut[iConf],input_CMSSW_BASE,os.getcwd())

aJob.setEOSout(eosdir)
aJob.createTheCfgFile(theSrcFiles)
aJob.createTheBashFile()
aJob.createTheBashFile(opts.isUnitTest)

output_file_list1.append("xrdcp root://eoscms//eos/cms"+aJob.getOutputFileName()+" /tmp/$USER/"+opts.taskname+" \n")
if jobN == 0:
Expand All @@ -1069,10 +1068,15 @@ def main():
output_file_list2.append("/tmp/$USER/"+opts.taskname+"/"+os.path.split(aJob.getOutputFileName())[1]+" ")
del aJob

job_submit_file = write_HTCondor_submit_file(theBashDir,theBaseName,totalJobs,None)
## create the log directory
theLogDir = os.path.join(os.getcwd(),"log")
if not os.path.exists(theLogDir):
os.makedirs(theLogDir)

job_submit_file = write_HTCondor_submit_file(theBashDir,theLogDir,theBaseName,totalJobs,None)
os.system("chmod u+x "+theBashDir+"/*.sh")

if opts.submit:
os.system("chmod u+x "+theBashDir+"/*.sh")
submissionCommand = "condor_submit "+job_submit_file
submissionOutput = getCommandOutput(submissionCommand)
print(submissionOutput)
Expand Down
13 changes: 6 additions & 7 deletions Alignment/OfflineValidation/test/PVResolutionExample.ini
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
# submitPVResolutionJobs.py -j UNIT_TEST -i PVResolutionExample.ini -D /JetHT/Run2018C-TkAlMinBias-12Nov2019_UL2018-v2/ALCARECO -v
# submitPVResolutionJobs.py -j UNIT_TEST -i PVResolutionExample.ini -D /JetHT/Run2022B-TkAlJetHT-PromptReco-v1/ALCARECO -v
[Input]
# also on afs:
#lumimask=/afs/cern.ch/cms/CAF/CMSCOMM/COMM_DQM/certification/Collisions18/13TeV/DCSOnly/json_DCSONLY.txt
lumimask=/eos/cms/store/group/comm_dqm/certification/Collisions18/13TeV/DCSOnly/json_DCSONLY.txt
lumimask=/eos/user/c/cmsdqm/www/CAF/certification/Collisions22/DCSOnly_JSONS/Cert_Collisions2022_355100_362760_eraBCDEFG_13p6TeV_DCSOnly_TkPx_New.json
trackcollection=ALCARECOTkAlJetHT
[Validation:Prompt]
globaltag=111X_dataRun2_v3
globaltag=140X_dataRun3_Prompt_v2
records=TrackerAlignmentRcd:TrackerAlignment_PCL_byRun_v2_express,TrackerAlignmentErrorExtendedRcd:TrackerAlignmentExtendedErr_2009_v2_express_IOVs,TrackerSurfaceDeformationRcd:TrackerSurafceDeformations_v1_express
[Validation:Ultra-Legacy]
globaltag=111X_dataRun2_v3
[Validation:ReReco]
globaltag=140X_dataRun3_ForTkAlReReco_v1
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ def best_match(rcd):
VarParsing.VarParsing.varType.string, # string, int, or float
"record:fle.db picks the following record from this external file")

options.register ('TrackCollection',
'ALCARECOTkAlMinBias',
VarParsing.VarParsing.multiplicity.singleton, # singleton or list
VarParsing.VarParsing.varType.string, # string, int, or float
"track collection to use")

options.register ('GlobalTag',
'110X_dataRun3_Prompt_v3',
VarParsing.VarParsing.multiplicity.singleton, # singleton or list
Expand All @@ -63,13 +69,14 @@ def best_match(rcd):

options.parseArguments()

print("TrackCollection : ", options.TrackCollection)
print("conditionGT : ", options.GlobalTag)
print("conditionOverwrite: ", options.records)
print("external conditions:", options.external)
print("outputFile : ", options.outputRootFile)

process.load("FWCore.MessageService.MessageLogger_cfi")
process.MessageLogger.cerr = cms.untracked.PSet(enable = cms.untracked.bool(False))
process.MessageLogger.cerr = cms.untracked.PSet(enable = cms.untracked.bool(True)) #False to silence errors
process.MessageLogger.cout = cms.untracked.PSet(INFO = cms.untracked.PSet(
reportEvery = cms.untracked.int32(1000) # every 100th only
# limit = cms.untracked.int32(10) # or limit to 10 printouts...
Expand Down Expand Up @@ -126,7 +133,7 @@ def best_match(rcd):

process.load("RecoTracker.TrackProducer.TrackRefitters_cff")
# remove the following lines if you run on RECO files
process.TrackRefitter.src = 'ALCARECOTkAlMinBias'
process.TrackRefitter.src = options.TrackCollection
process.TrackRefitter.NavigationSchool = ''

####################################################################
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,18 @@ echo " TESTING Primary Vertex Validation run-by-run submission ..."
submitPVValidationJobs.py -j UNIT_TEST -D /HLTPhysics/Run2023D-TkAlMinBias-PromptReco-v2/ALCARECO \
-i ${CMSSW_BASE}/src/Alignment/OfflineValidation/test/testPVValidation_Relvals_DATA.ini -r --unitTest || die "Failure running PV Validation run-by-run submission" $?

echo -e "\n\n TESTING Primary Vertex Validation script execution ..."
# Define script name
scriptName="PVValidation_testingOfflineGT_HLTPhysics_Run2023D_0.sh"

# Create directory if it doesn't exist
mkdir -p "./testExecution"

# Copy script to the test execution directory
cp -pr "./BASH/${scriptName}" "./testExecution/"

# Change directory to the test execution directory
cd "./testExecution" || exit 1

# Execute the script and handle errors
./"${scriptName}" || die "Failure running PVValidation script" $?
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,24 @@
function die { echo $1: status $2 ; exit $2; }

echo " TESTING Split Vertex Validation submission ..."
submitPVResolutionJobs.py -j UNIT_TEST -D /JetHT/Run2018C-TkAlMinBias-12Nov2019_UL2018-v2/ALCARECO \
submitPVResolutionJobs.py -j UNIT_TEST -D /JetHT/Run2022B-TkAlJetHT-PromptReco-v1/ALCARECO \
-i ${CMSSW_BASE}/src/Alignment/OfflineValidation/test/PVResolutionExample.ini --unitTest || die "Failure running Split Vertex Validation submission" $?

echo -e "\n\n TESTING Primary Vertex Split script execution ..."
# Define script name
scriptName="batchHarvester_Prompt_0.sh"

# Create directory if it doesn't exist
mkdir -p "./testExecution"

# Copy script to the test execution directory
cp -pr "./BASH/${scriptName}" "./testExecution/"

# Change directory to the test execution directory
cd "./testExecution" || exit 1

# Execute the script and handle errors
./"${scriptName}" || die "Failure running PVSplit script" $?

# Dump to screen the content of the log file
cat log*.out