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

Improvements for SubmitPVsplit unit test #46719

Merged
merged 3 commits into from
Nov 18, 2024
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
54 changes: 39 additions & 15 deletions Alignment/OfflineValidation/scripts/submitPVResolutionJobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,20 +190,29 @@ def batchScriptCERN(theCMSSW_BASE, cfgdir, runindex, eosdir, lumiToRun, key, con
#######################################################
'''prepare the batch script, to run on HTCondor'''
script = """#!/bin/bash
#source /afs/cern.ch/cms/caf/setup.sh
CMSSW_DIR={CMSSW_BASE_DIR}/src/Alignment/OfflineValidation/test
echo "the mother directory is $CMSSW_DIR"
echo "The mother directory is $CMSSW_DIR"
export X509_USER_PROXY=$CMSSW_DIR/.user_proxy
#OUT_DIR=$CMSSW_DIR/harvest ## for local storage
OUT_DIR={MYDIR}
LOG_DIR=$CMSSW_DIR/out
LXBATCH_DIR=`pwd`
cd $CMSSW_DIR
eval `scram runtime -sh`
LXBATCH_DIR=$PWD
# Check if CMSSW environment is set by checking CMSSW_BASE or other variables
if [[ -z "$CMSSW_BASE" || -z "$CMSSW_VERSION" || -z "$SCRAM_ARCH" ]]; then
echo "CMSSW environment not detected. Sourcing scramv1 runtime..."
cd $CMSSW_DIR
# Assuming you have a valid CMSSW release environment to source
source /cvmfs/cms.cern.ch/cmsset_default.sh
eval $(scramv1 runtime -sh) # This sets the CMSSW environment
else
echo "CMSSW environment is already set. Continuing..."
fi
cd $LXBATCH_DIR
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 .
# Print the contents of the current directory using $PWD and echo
echo "Contents of the current directory ($PWD):"
echo "$(ls -lh "$PWD")"
""".format(CMSSW_BASE_DIR=theCMSSW_BASE,
CFGDIR=cfgdir,
runindex=runindex,
Expand Down Expand Up @@ -302,11 +311,11 @@ def main():
runs.sort()
print("\n\n Will run on the following runs: \n",runs)

if(not os.path.exists("cfg")):
os.system("mkdir cfg")
os.system("mkdir BASH")
os.system("mkdir harvest")
os.system("mkdir out")
# List of directories to create
directories = ["cfg", "BASH", "harvest", "out"]

for directory in directories:
os.makedirs(directory, exist_ok=True)

cwd = os.getcwd()
bashdir = os.path.join(cwd,"BASH")
Expand Down Expand Up @@ -412,10 +421,25 @@ def main():
key = key.split(":", 1)[1]
print("dealing with",key)

os.system("cp "+input_CMSSW_BASE+"/src/Alignment/OfflineValidation/test/PrimaryVertexResolution_templ_cfg.py ./cfg/PrimaryVertexResolution_"+key+"_"+run+"_cfg.py")
os.system("sed -i 's|XXX_FILES_XXX|"+listOfFiles+"|g' "+cwd+"/cfg/PrimaryVertexResolution_"+key+"_"+run+"_cfg.py")
os.system("sed -i 's|XXX_RUN_XXX|"+run+"|g' "+cwd+"/cfg/PrimaryVertexResolution_"+key+"_"+run+"_cfg.py")
os.system("sed -i 's|YYY_KEY_YYY|"+key+"|g' "+cwd+"/cfg/PrimaryVertexResolution_"+key+"_"+run+"_cfg.py")
# Paths and variables
template_file = os.path.join(input_CMSSW_BASE, "src/Alignment/OfflineValidation/test/PrimaryVertexResolution_templ_cfg.py")
output_file = f"./cfg/PrimaryVertexResolution_{key}_{run}_cfg.py"

# Copy the template file to the destination
shutil.copy(template_file, output_file)

# Read and replace placeholders in the copied file
with open(output_file, 'r') as file:
content = file.read()

# Replace placeholders with actual values
content = content.replace("XXX_FILES_XXX", listOfFiles)
content = content.replace("XXX_RUN_XXX", run)
content = content.replace("YYY_KEY_YYY", key)

# Write the modified content back to the file
with open(output_file, 'w') as file:
file.write(content)

scriptFileName = os.path.join(bashdir,"batchHarvester_"+key+"_"+str(count-1)+".sh")
scriptFile = open(scriptFileName,'w')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,36 @@ echo -e "\n\n TESTING Primary Vertex Split script execution ..."
scriptName="batchHarvester_Prompt_0.sh"

# Create directory if it doesn't exist
mkdir -p "./testExecution"
testdir=$PWD
mkdir ${testdir}/"testExecution"

# Check if the script exists and is a regular file
if [ -f "./BASH/${scriptName}" ]; then
if [ -f "${testdir}/BASH/${scriptName}" ]; then
# Copy script to the test execution directory
cp -pr "./BASH/${scriptName}" "./testExecution/"
cp "${testdir}/BASH/${scriptName}" "${testdir}/testExecution/"
else
# Emit a warning if the script doesn't exist or is not a regular file
echo "Warning: Script '${scriptName}' not found or is not a regular file. Skipping excution of further tests."
exit 0
fi

# Change directory to the test execution directory
cd "./testExecution" || exit 1
cd "${testdir}/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
$PWD/"${scriptName}" || die "Failure running PVSplit script" $?

# Dump to screen the content of the log file(s) with clear headers
log_files=(log*.out)
if [[ ${#log_files[@]} -gt 0 ]]; then
echo "Displaying content of log files:"
for log_file in "${log_files[@]}"; do
echo "========================================"
echo "Content of $log_file:"
echo "========================================"
cat "$log_file"
echo # Add an extra blank line for separation
done
else
echo "No log files found matching 'log*.out'."
fi