justIN           Dashboard       Workflows       Jobs       AWT       Sites       Storages       Docs       Login

Workflow 3610, Stage 1

Priority50
Processors1
Wall seconds80000
RSS bytes2097152000 (2000 MiB)
Max distance for inputs0.0
Enabled input RSEs CERN_PDUNE_EOS, DUNE_CERN_EOS, DUNE_ES_PIC, DUNE_FR_CCIN2P3_DISK, DUNE_IN_TIFR, DUNE_IT_INFN_CNAF, DUNE_UK_GLASGOW, DUNE_UK_LANCASTER_CEPH, DUNE_UK_MANCHESTER_CEPH, DUNE_US_BNL_SDCC, DUNE_US_FNAL_DISK_STAGE, FNAL_DCACHE, FNAL_DCACHE_STAGING, FNAL_DCACHE_TEST, MANCHESTER, MONTECARLO, NIKHEF, PRAGUE, QMUL, RAL-PP, RAL_ECHO, SURFSARA, T3_US_NERSC
Enabled output RSEs CERN_PDUNE_EOS, DUNE_CERN_EOS, DUNE_ES_PIC, DUNE_FR_CCIN2P3_DISK, DUNE_IN_TIFR, DUNE_IT_INFN_CNAF, DUNE_UK_GLASGOW, DUNE_UK_LANCASTER_CEPH, DUNE_UK_MANCHESTER_CEPH, DUNE_US_BNL_SDCC, DUNE_US_FNAL_DISK_STAGE, FNAL_DCACHE, FNAL_DCACHE_STAGING, FNAL_DCACHE_TEST, MANCHESTER, NIKHEF, PRAGUE, QMUL, RAL-PP, RAL_ECHO, SURFSARA, T3_US_NERSC
Enabled sites BR_CBPF, CA_SFU, CA_Victoria, CERN, CH_UNIBE-LHEP, CZ_FZU, ES_CIEMAT, ES_PIC, FR_CCIN2P3, IN_TIFR, IT_CNAF, UK_Bristol, UK_Brunel, UK_Durham, UK_Edinburgh, UK_Imperial, UK_Lancaster, UK_Liverpool, UK_Manchester, UK_Oxford, UK_RAL-Tier1, UK_Sheffield, US_BNL, US_Caltech, US_Colorado, US_FNAL-FermiGrid, US_FNAL-T1, US_Michigan, US_MIT, US_Nebraska, US_NotreDame, US_PuertoRico, US_SU-ITS, US_Swan, US_UChicago, US_UConn-HPC, US_UCSD, US_Wisconsin
Scopeusertests
Events for this stage

Output patterns

 DestinationPatternLifetimeFor next stage
1https://fndcadoor.fnal.gov:2880/dune/scratch/users/twalton/Mx2ProdData/2024-10-02-12-11-10/data/03610/1*.root
2https://fndcadoor.fnal.gov:2880/dune/scratch/users/twalton/Mx2ProdData/2024-10-02-12-11-10/opts/03610/1*.opts
3https://fndcadoor.fnal.gov:2880/dune/scratch/users/twalton/Mx2ProdData/2024-10-02-12-11-10/logs/03610/1*.log
4https://fndcadoor.fnal.gov:2880/dune/scratch/users/twalton/Mx2ProdData/2024-10-02-12-11-10/json/03610/1*.json

Environment variables

NameValue
APPLY_ALIGNMENT0
DEBUG_SUBMISSION_SCRIPT0
FILE_TIERrawdigs,supdigs,rockmu
INPUT_TAR_DIR_LOCAL/cvmfs/fifeuser1.opensciencegrid.org/sw/dune/5c60dc3f2f87be0ea165648244e670847bdb0a33
JOBSCRIPT_TEST0
MINERVA_RELEASEv101r2p1
NEVENTS-1
OPTION_FILEBuildRawDigits_fRawData.opts,OfflinePedSup_fRawDigits.opts,RockMuonReconstructionTest.opts
SAVE_LINJC0
SAVE_NUMIB0
SAVE_PDSTL0
USERtwalton

File states

Total filesFindingUnallocatedAllocatedOutputtingProcessedNot foundFailed
117000011700

Job states

TotalSubmittedStartedProcessingOutputtingFinishedNotusedAbortedStalledJobscript errorOutputting failedNone processed
1760000176000000
Files processed0010102020303040405050606070708080Oct-02 17:00Oct-02 18:00Oct-02 19:00Oct-02 20:00Files processedBin start timesNumber per binUS_FNAL-FermiG…US_FNAL-FermiGrid
Replicas per RSE117490.025244.5117269.975244.50000000000003Replicas per RSEFNAL_DCACHE (50%)DUNE_US_FNAL_DISK_STAGE (50%)

RSEs used

NameInputsOutputs
DUNE_US_FNAL_DISK_STAGE1170

Stats of processed input files as CSV or JSON, and of uploaded output files as CSV or JSON (up to 10000 files included)

Jobscript

#!/bin/bash

#+++++++++++++++++++++++++++++++++++++++++
# enter software setup script
#+++++++++++++++++++++++++++++++++++++++++
export JUSTIN_SUBID=`echo "${JUSTIN_JOBSUB_ID}" | sed 's/@/./g'`
echo -e "Creating the file $HOME/workspace/env_${JUSTIN_WORKFLOW_ID}.${JUSTIN_STAGE_ID}.${JUSTIN_SUBID}.log" > $HOME/workspace/env_${JUSTIN_WORKFLOW_ID}.${JUSTIN_STAGE_ID}.${JUSTIN_SUBID}.log
export envlog="$HOME/workspace/env_${JUSTIN_WORKFLOW_ID}.${JUSTIN_STAGE_ID}.${JUSTIN_SUBID}.log"


echo -e "The software is Mx2 ${MINERVA_RELEASE}" 2>&1 | tee -a $envlog
source /cvmfs/minerva.opensciencegrid.org/minerva2x2/products/releases/${MINERVA_RELEASE}/setup.sh 
date +"%n%a %b %d %T %Z %Y%n" | tee -a $envlog

if [ ${DEBUG_SUBMISSION_SCRIPT} -eq 1 ]; then
   echo -e "Subdirectories in cvmfs" 2>&1 | tee -a $envlog
   ls -lha /cvmfs/minerva.opensciencegrid.org/ 2>&1 | tee -a $envlog
   echo -e "\n\n" 2>&1 | tee -a $envlog
fi

if [ ${DEBUG_SUBMISSION_SCRIPT} -eq 1 ]; then
   echo -e "Checking the path" 2>&1 | tee -a $envlog
   echo -e "$PATH" 2>&1 | tee -a $envlog
   echo -e "\n\n" 2>&1 | tee -a $envlog
fi

if [ ${DEBUG_SUBMISSION_SCRIPT} -eq 1 ]; then
   compgen -c | grep -i setenv 2>&1 | tee -a $envlog
   echo -e "\n\n" 2>&1 | tee -a $envlog
fi

if [ ${DEBUG_SUBMISSION_SCRIPT} -eq 1 ]; then
   ls -lhs /usr/bin/id 2>&1 | tee -a $envlog
   ls -lhs /usr/bin 2>&1 | tee -a $envlog
   echo -e "\n\n" 2>&1 | tee -a $envlog
fi

if [ ${DEBUG_SUBMISSION_SCRIPT} -eq 1 ]; then
   echo -e "HOME" 2>&1 | tee -a $envlog
   ls -lha $HOME 2>&1 | tee -a $envlog
   echo -e "\n\n" 2>&1 | tee -a $envlog
fi


cd $HOME/cmtuser
echo -e "The Minervascripts is ${MINERVASCRIPTS}" 2>&1 | tee -a $envlog
source ${MINERVASCRIPTS}/setenvProject.sh Minerva ${MINERVA_RELEASE} 2>&1 | tee -a $envlog
echo -e "\n\n" 2>&1 | tee -a $envlog


#++++++++++++++++++++++++++++++++++++++++
# setup 
#++++++++++++++++++++++++++++++++++++++++
echo -e "Setup DUNE and Metacat" 2>&1 | tee -a $envlog
source /cvmfs/dune.opensciencegrid.org/products/dune/setup_dune.sh 2>&1 | tee -a $envlog
export METACAT_SERVER_URL=https://metacat.fnal.gov:9443/dune_meta_prod/app
export METACAT_AUTH_SERVER_URL=https://metacat.fnal.gov:8143/auth/dune
setup metacat


#+++++++++++++++++++++++++++++++++++++++++
# environment variables
#+++++++++++++++++++++++++++++++++++++++++
if [ ${DEBUG_SUBMISSION_SCRIPT} -eq 1 ]; then
   echo -e "==========================================================================" > $envlog
   /usr/bin/printenv 2>&1 | tee -a $envlog
   echo -e "==========================================================================" > $envlog
fi


#+++++++++++++++++++++++++++++++++++++++++
# get node information
#+++++++++++++++++++++++++++++++++++++++++
echo -e "The node working directory $PWD" 2>&1 | tee -a $envlog
HOST=`/bin/hostname`
echo -e "\t\thost is $HOST" 2>&1 | tee -a $envlog
echo -e "\t\tjustin site is $JUSTIN_SITE_NAME" 2>&1 | tee -a $envlog
echo -e "\t\tthe current directory is $PWD" 2>&1 | tee -a $envlog


#+++++++++++++++++++++++++++++++++++++++++
# prepare to launch job
#+++++++++++++++++++++++++++++++++++++++++
echo -e "Checking if tarfiles exist in the directory [$INPUT_TAR_DIR_LOCAL]." | tee -a $envlog
ls -lha $INPUT_TAR_DIR_LOCAL 2>&1 | tee -a $envlog
echo -e "\n\n" | tee -a $envlog

if [ ${DEBUG_SUBMISSION_SCRIPT} -eq 1 ]; then
   echo -e "The output of the setup script." | tee -a $envlog
   echo -e "==============================================================================================================\n" | tee -a $envlog
   less ${INPUT_TAR_DIR_LOCAL}/Minerva_${MINERVA_RELEASE}/Tools/SystemTests/cmt/setup.sh 2>&1 | tee -a $envlog
   echo -e "==============================================================================================================\n\n" | tee -a $envlog
fi


#++++++++++++++++++++++++++++++++++++
# setup workspace
#+++++++++++++++++++++++++++++++++++
export WORKSPACE=/home/workspace
cd ${WORKSPACE}


#+++++++++++++++++++++++++++++++++++++++++
# setup the system tests
#+++++++++++++++++++++++++++++++++++++++++
echo -e "Running the cmt setup script." 2>&1 | tee -a $envlog
cd ${INPUT_TAR_DIR_LOCAL}/Minerva_${MINERVA_RELEASE}
cd Tools/SystemTests/cmt
source setup.sh 

echo -e "The Systemtests setup is ${SYSTEMTESTSROOT}" 2>&1 | tee -a $envlog
if [ ${DEBUG_SUBMISSION_SCRIPT} -eq 1 ]; then
   echo -e "==============================================================================================================\n" | tee -a $envlog
   ls -lha $SYSTEMTESTSROOT | tee -a $envlog
   compgen -c | grep -i system 2>&1 | tee -a $envlog
   echo -e "\n\n" | tee -a $envlog | tee -a $envlog
fi

cd ../../../Det/MinervaXmlConditions/cmt/
source setup.sh

echo -e "The MinervaXmlConditions setup is ${MINERVAXMLCONDITIONSROOT}" 2>&1 | tee -a $envlog
if [ ${DEBUG_SUBMISSION_SCRIPT} -eq 1 ]; then
   echo -e "==============================================================================================================\n" | tee -a $envlog
   ls -lha $MINERVAXMLCONDITIONSROOT | tee -a $envlog
   compgen -c | grep -i system 2>&1 | tee -a $envlog
   echo -e "\n\n" | tee -a $envlog | tee -a $envlog
fi

SUCCESS=`compgen -c | grep -i SystemTestsApp.exe | wc -l`
if [ ${SUCCESS} -eq 0 ]; then
   echo -e "Please contact expert. The SystemTest execuable does not exist.\n" 2>&1 | tee -a $envlog
   if [ ${JOBSCRIPT_TEST} -eq 0 ]; then
      echo -e "Updating jobscript name jobscript_${JUSTIN_WORKFLOW_ID}.${JUSTIN_STAGE_ID}.${JUSTIN_SUBID}.log\n" 2>&1 | tee -a $envlog
      mv jobscript.log jobscript_${JUSTIN_WORKFLOW_ID}.${JUSTIN_STAGE_ID}.${JUSTIN_SUBID}.log
   fi
   exit 1
fi



#+++++++++++++++++++++++++++++
# go to working directory
#+++++++++++++++++++++++++++++
cd ${WORKSPACE}


#++++++++++++++++++++++++++++++++++++++++++++++++++++++
# Get the file
# TODO - update to retrieve many files
#++++++++++++++++++++++++++++++++++++++++++++++++++++++
echo -e "\n\nRetrieving the file." | tee -a $envlog
did_pfn_rse=`$JUSTIN_PATH/justin-get-file`
did=`echo $did_pfn_rse | cut -f1 -d' '`
pfn=`echo $did_pfn_rse | cut -f2 -d' '`
rse=`echo $did_pfn_rse | cut -f3 -d' '`

if [ "$did_pfn_rse" = "" ] ; then
  echo -e "justIN does not get a file. Exiting the jobscript." 2>&1 | tee -a $envlog
  if [ ${JOBSCRIPT_TEST} -eq 0 ]; then
     echo -e "Updating jobscript name jobscript_${JUSTIN_WORKFLOW_ID}.${JUSTIN_STAGE_ID}.${JUSTIN_SUBID}.log\n" 2>&1 | tee -a $envlog
     mv jobscript.log jobscript_${JUSTIN_WORKFLOW_ID}.${JUSTIN_STAGE_ID}.${JUSTIN_SUBID}.log
  fi
  exit 0
fi

echo -e "\tThe file data identifier (DID) is [$did]" | tee -a $envlog
echo -e "\tThe file physical file name (PFN) is [$pfn]" | tee -a $envlog
echo -e "\tThe file Rucio storage element (RSE) is [$rse]\n" | tee -a $envlog


#+++++++++++++++++++++++++++++++++++++++++++++++++++++
# Copy file to local disk
# File can be opened from /pnfs
#+++++++++++++++++++++++++++++++++++++++++++++++++++++
if [ ${DEBUG_SUBMISSION_SCRIPT} -eq 1 ]; then
   compgen -c | grep -i xrd 2>&1 | tee -a $envlog
fi
echo -e "Running xrdcopy ${pfn} ${WORKSPACE}/" 2>&1 | tee -a $envlog
xrdcopy ${pfn} ${WORKSPACE}/ 
echo -e "\tCompleted the copying.\n" 2>&1 | tee -a $envlog


#++++++++++++++++++++++++++++++++++++++++++++++++++++++
# Get the filename
#++++++++++++++++++++++++++++++++++++++++++++++++++++++
IFS=':' read -r -a array <<< "$did"
export FILENAME="${array[1]}"
echo -e "The input file is ${FILENAME}" 2>&1 | tee -a $envlog


#+++++++++++++++++++++++++++++++++++++++++
# define some parameters
#+++++++++++++++++++++++++++++++++++++++++
if [[ $FILENAME == *".dat"* ]]; then
   ext=".dat"
elif [[ $FILENAME == *".root"* ]]; then
   ext=".root"
fi



#+++++++++++++++++++++++++++++++++++++++++
# parse the input file name
#+++++++++++++++++++++++++++++++++++++++++
INPUT_FILE=${FILENAME##*/}
IFS='_' read -a flist <<< "$INPUT_FILE";
export WORDS="${flist[0]}"
export RUN="${flist[1]}"
export SUBRUN="${flist[2]}"
export DATA_STREAM="${flist[3]}"
export DAQ_SOFTWARE="${flist[4]}"
export TIMESTAMP="${flist[5]}"
export DATA_TYPE="${flist[6]}"




#+++++++++++++++++++++++++++++++++++++++++
# create an output directory
#+++++++++++++++++++++++++++++++++++++++++
cd ${WORKSPACE}
export OUTFILES_DIR=${WORKSPACE}
echo -e "The output files are placed in the directory [$OUTFILES_DIR]\n" | tee -a $envlog



#++++++++++++++++++++++++++++++++++++++++
# parse input parameters
#++++++++++++++++++++++++++++++++++++++++
IFS="," read -a OPTS <<< "$OPTION_FILE";
IFS="," read -a TIER <<< "$FILE_TIER";

if [ "${#OPTS[@]}" != "${#TIER[@]}" ]; then
   echo -e "Please see the help menu. Each input option file must accompained a file tier.\n" 2>&1 | tee -a $envlog
   if [ ${JOBSCRIPT_TEST} -eq 0 ]; then
     echo -e "Updating jobscript name jobscript_${JUSTIN_WORKFLOW_ID}.${JUSTIN_STAGE_ID}.${JUSTIN_SUBID}.log\n" 2>&1 | tee -a $envlog
     mv jobscript.log jobscript_${JUSTIN_WORKFLOW_ID}.${JUSTIN_STAGE_ID}.${JUSTIN_SUBID}.log
   fi
   exit 1
fi

total="${#OPTS[@]}"
echo -e "\n\nRunning over $total options file(s)" | tee -a $envlog
echo -e "\t[$OPTION_FILE]\n" | tee -a $envlog


#++++++++++++++++++++++++++++++++++++++++
# loop over input option files
#++++++++++++++++++++++++++++++++++++++++
for ((i = 0; i < total; ++i)); do
 
    export OPT_FILE="${OPTS[$i]}"
    export OPT_TIER="${TIER[$i]}"
 

    echo -e "\t---------------- $OPT_FILE ($OPT_TIER)------------------------------" | tee -a $envlog


    #+++++++++++++++++++++++++++++++++++++++++
    # create the output file names
    #+++++++++++++++++++++++++++++++++++++++++
    export UPDATED_TIMESTAMP=$(date +'%y%m%d%H%M')
    export UPDATED_DATA_TYPE=$( echo "${DATA_TYPE}" )

    if [[ $OPT_TIER == "rawdigs" ]]; then
       export UPDATED_DATA_TYPE="RawDigits"${ext}
    elif [[ $OPT_TIER == "pdstl" ]]; then
       export UPDATED_DATA_TYPE="Pedestal"${ext}
    elif [[ $OPT_TIER == "gain" ]]; then
       export UPDATED_DATA_TYPE="Gain"${ext}
    elif [[ $OPT_TIER == "supdigs" ]]; then
       export UPDATED_DATA_TYPE="SupDigits"${ext}
    elif [[ $OPT_TIER == "rockmu" ]]; then
       export UPDATED_DATA_TYPE="RockMuons"${ext}  
    elif [[ $OPT_TIER == "reco" ]]; then
       export UPDATED_DATA_TYPE="RecoData"${ext}
    else 
       echo -e "The file tier [$OPT_TIER] is not implemented. Please contact expert.\n" 2>&1 | tee -a $envlog
       if [ ${JOBSCRIPT_TEST} -eq 0 ]; then
          echo -e "Updating jobscript name jobscript_${JUSTIN_WORKFLOW_ID}.${JUSTIN_STAGE_ID}.${JUSTIN_SUBID}.log\n" 2>&1 | tee -a $envlog
          mv jobscript.log jobscript_${JUSTIN_WORKFLOW_ID}.${JUSTIN_STAGE_ID}.${JUSTIN_SUBID}.log
       fi
       exit 1
    fi


    export OUTPUT_FILE=${WORDS}_${RUN}_${SUBRUN}_${DATA_STREAM}_${DAQ_SOFTWARE}_${UPDATED_TIMESTAMP}_${UPDATED_DATA_TYPE}
    export OPTION_FILENAME=$OUTFILES_DIR/"${OUTPUT_FILE/$ext/.opts}"
    export JSON_FILENAME=$OUTFILES_DIR/"${OUTPUT_FILE/$ext/.json}"
    export LOG_FILENAME=$OUTFILES_DIR/"${OUTPUT_FILE/$ext/.log}"
    export HISTO_FILENAME=$OUTFILES_DIR/"${OUTPUT_FILE/$ext/_histos.root}"
    export ROOT_FILENAME=$OUTFILES_DIR/"${OUTPUT_FILE/$ext/.root}"


    echo -e "\n\t++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" 2>&1 | tee -a $envlog
    echo -e "\tOutput option filename is $OPTION_FILENAME" 2>&1 | tee -a $envlog
    echo -e "\tOutput metadata json filename is $JSON_FILENAME" 2>&1 | tee -a $envlog
    echo -e "\tOutput job log file name is $LOG_FILENAME" 2>&1 | tee -a $envlog
    echo -e "\tOutput histo root file name is $HISTO_FILENAME" 2>&1 | tee -a $envlog
    echo -e "\tOutput root file name is $ROOT_FILENAME" 2>&1 | tee -a $envlog
    echo -e "\n\t++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n\n" 2>&1 | tee -a $envlog


    OPT_EXISTS=`ls ${SYSTEMTESTSROOT}/options/Mx2Prod/${OPT_FILE} | wc -l`
    if [ ${OPT_EXISTS} -ne 1 ]; then
       echo -e "\tThe option file does not exists in the directory [${SYSTEMTESTSROOT}/options/Mx2Prod/]. Please check your tarball." 2>&1 | tee -a $envlog
       if [ ${JOBSCRIPT_TEST} -eq 0 ]; then
          echo -e "Updating jobscript name jobscript_${JUSTIN_WORKFLOW_ID}.${JUSTIN_STAGE_ID}.${JUSTIN_SUBID}.log\n" 2>&1 | tee -a $envlog
          mv jobscript.log jobscript_${JUSTIN_WORKFLOW_ID}.${JUSTIN_STAGE_ID}.${JUSTIN_SUBID}.log
       fi
       exit 1
    fi

    echo -e "\tCopying cp ${SYSTEMTESTSROOT}/options/Mx2Prod/${OPT_FILE} ${OPTION_FILENAME}\n\n" 2>&1 | tee -a $envlog 
    cp ${SYSTEMTESTSROOT}/options/Mx2Prod/${OPT_FILE} ${OPTION_FILENAME} | tee -a $envlog


    echo -e "\t++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" 2>&1 | tee -a $envlog
    echo -e "\tThe file tier is [$OPT_TIER]" 2>&1 | tee -a $envlog
    echo -e "\tThe data stream is [$DATA_STREAM]" 2>&1 | tee -a $envlog 
    echo -e "\t++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n\n" 2>&1 | tee -a $envlog


    #==================================================================
    #
    #  Configure the option file based on input parameters, etc.
    #
    #=================================================================

    # common configuration for all option files
    sed -e "s,ApplicationMgr.EvtMax.*$,ApplicationMgr.EvtMax = ${NEVENTS};,g" -i ${OPTION_FILENAME}

    if [[ $OPT_TIER == "rockmu" || $OPT_TIER == "reco" ]]; then
       sed -e "s,EventSelector.PrintFreq.*$,EventSelector.PrintFreq = 1;,g" -i ${OPTION_FILENAME}
    fi

    # special configuration for pedestal 
    if [[ $OPT_TIER == "pdstl" ]]; then
       export ALLOUTFILENAME=$OUTFILES_DIR/"${OUTPUT_FILE/${DATA_STREAM}/pdstl_table_all}"
       export SCRUBBEDOUTFILENAME=$OUTFILES_DIR/"${OUTPUT_FILE/${DATA_STREAM}/pdstl_table_scrubbed}"

       echo -e "\t++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" 2>&1 | tee -a $envlog
       echo -e "\tOutput pedestal table file is $ALLOUTFILENAME" 2>&1 | tee -a $envlog
       echo -e "\tOutput scrubbed pedestal table file is $SCRUBBEDOUTFILENAME" 2>&1 | tee -a $envlog
       echo -e "\t++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n\n" 2>&1 | tee -a $envlog
    fi

    # special configuration for light injection
    if [[ $OPT_TIER == "gain" ]]; then
       export GAINTABLEFILENAME=$OUTFILES_DIR/"${OUTPUT_FILE/${DATA_STREAM}/gain_table}"
       export GAINPROBLEMCHANNELSFILENAME=$OUTFILES_DIR/"${OUTPUT_FILE/${DATA_STREAM}/problem_channels}"
       export GAINTUNEDHVFILENAME=$OUTFILES_DIR/"${OUTPUT_FILE/${DATA_STREAM}/tuned_hvs}"

       echo -e "\t++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" 2>&1 | tee -a $envlog
       echo -e "\tOutput max gain file is  $GAINTABLEFILENAME" 2>&1 | tee -a $envlog
       echo -e "\tOutput problem channel file is $GAINPROBLEMCHANNELSFILENAME" 2>&1 | tee -a $envlog
       echo -e "\tOutput HV file is $GAINTUNEDHVFILENAME" 2>&1 | tee -a $envlog
       echo -e "\t++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n\n" 2>&1 | tee -a $envlog
    fi 

    # special configuration for rock muons
    if [[ $OPT_TIER == "rockmu" ]]; then
       export ROCKMUONDSTFILENAME=$OUTFILES_DIR/"${OUTPUT_FILE/${ext}/_dst.root}"
       export ROCKMUONFILENAME=$ROOT_FILENAME
    
       echo -e "\t++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" 2>&1 | tee -a $envlog
       echo -e "\tOutput rock muon DST file is ROCKMUONDSTFILENAME" 2>&1 | tee -a $envlog
       echo -e "\tOutput rock muon calibration file is $ROCKMUONFILENAME" 2>&1 | tee -a $envlog
       echo -e "\t++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n\n" 2>&1 | tee -a $envlog
    fi



    # BuildRawDigits_fRawData.opts
    if [[ $OPT_TIER == "rawdigs" ]]; then
       echo -e "\tConfiguring the raw data to raw digits option file" 2>&1 | tee -a $envlog

       if [[ $DATA_STREAM == "pdstl" ]]; then
          echo -e "\t\tupdating the pedestal portion" 2>&1 | tee -a $envlog
          sed -e "s,ApplicationMgr.OutStream.*$,ApplicationMgr.OutStream = {\"PdstlStream\"};,g"\
              -e "s,LinjcStream.*$,,g"\
              -e "s,numibeamStream.*$,,g"\
              -e "s,FilterSequence.Members.*$,FilterSequence.Members = {\"TriggerTypeFilter/PdstlFilter\"};,g"\
              -e "s,BuildRawEventAlg.InputFileName.*$,BuildRawEventAlg.InputFileName = \"${FILENAME}\";,g"\
              -e "s,PdstlStream.Output.*$,PdstlStream.Output=\"DATAFILE='PFN:$ROOT_FILENAME' TYP='POOL_ROOTTREE' OPT='RECREATE'\";,g"\
              -i ${OPTION_FILENAME}
       elif [[ $DATA_STREAM == "linjc" ]]; then
            echo -e "\t\tupdating the light injection portion" 2>&1 | tee -a $envlog
            sed -e "s,ApplicationMgr.OutStream.*$,ApplicationMgr.OutStream = {\"LinjcStream\"};,g"\
                -e "s,PdstlStream.*$,,g"\
                -e "s,numibeamStream.*$,,g"\
                -e "s,FilterSequence.Members.*$,FilterSequence.Members = {\"TriggerTypeFilter/LinjcFilter\"};,g"\ 
                -e "s,BuildRawEventAlg.InputFileName.*$,BuildRawEventAlg.InputFileName = \"${FILENAME}\";,g"\
                -e "s,LinjcStream.Output.*$,LinjcStream.Output=\"DATAFILE='PFN:$ROOT_FILENAME' TYP='POOL_ROOTTREE' OPT='RECREATE'\";,g"\
                -i ${OPTION_FILENAME}
       elif [[ $DATA_STREAM == "numib" ]]; then
            echo -e "\t\tupdating the numi beam portion" 2>&1 | tee -a $envlog
            sed -e "s,ApplicationMgr.OutStream.*$,ApplicationMgr.OutStream = {\"numibeamStream\"};,g"\
                -e "s,PdstlStream.*$,,g"\
                -e "s,LinjcStream.*$,,g"\
                -e "s,FilterSequence.Members.*$,FilterSequence.Members = {\"TriggerTypeFilter/numibeamFilter\"};,g"\
                -e "s,BuildRawEventAlg.InputFileName.*$,BuildRawEventAlg.InputFileName = \"${FILENAME}\";,g"\
                -e "s,numibeamStream.Output.*$,numibeamStream.Output=\"DATAFILE='PFN:$ROOT_FILENAME' TYP='POOL_ROOTTREE' OPT='RECREATE'\";,g"\
                -i ${OPTION_FILENAME}
       elif [[ $DATA_STREAM == "numip" ]]; then
            echo -e "\t\tupdating the pedestal and numi beam portion" 2>&1 | tee -a $envlog
            export PDSTL_ROOT_FILENAME="${ROOT_FILENAME/$DATA_STREAM/pdstl}"
            export NUMIB_ROOT_FILENAME="${ROOT_FILENAME/$DATA_STREAM/numib}"
            sed -e "s,ApplicationMgr.OutStream.*$,ApplicationMgr.OutStream = {\"PdstlStream\"\,\"numibeamStream\"};,g"\
                -e "s,LinjcStream.*$,,g"\
                -e "s,FilterSequence.Members.*$,FilterSequence.Members = {\"TriggerTypeFilter/PdstlFilter\"\,\"TriggerTypeFilter/numibeamFilter\"};,g"\
                -e "s,BuildRawEventAlg.InputFileName.*$,BuildRawEventAlg.InputFileName = \"${FILENAME}\";,g"\
                -e "s,PdstlStream.Output.*$,PdstlStream.Output=\"DATAFILE='PFN:$PDSTL_ROOT_FILENAME' TYP='POOL_ROOTTREE' OPT='RECREATE'\";,g"\
                -e "s,numibeamStream.Output.*$,numibeamStream.Output=\"DATAFILE='PFN:$NUMIB_ROOT_FILENAME' TYP='POOL_ROOTTREE' OPT='RECREATE'\";,g"\
               -i ${OPTION_FILENAME}
       elif [[ $DATA_STREAM == "numil" ]]; then
            echo -e "\t\tupdating the light injection and numi beam portion" 2>&1 | tee -a $envlog
            export LINJC_ROOT_FILENAME="${ROOT_FILENAME/$DATA_STREAM/linjc}"
            export NUMIB_ROOT_FILENAME="${ROOT_FILENAME/$DATA_STREAM/numib}"
            sed -e "s,ApplicationMgr.OutStream.*$,ApplicationMgr.OutStream = {\"LinjcStream\"\,\"numibeamStream\"};,g"\
                -e "s,PdstlStream.*$,,g"\
                -e "s,FilterSequence.Members.*$,FilterSequence.Members = {\"TriggerTypeFilter/LinjcFilter\"\,\"TriggerTypeFilter/numibeamFilter\"};,g"\
                -e "s,BuildRawEventAlg.InputFileName.*$,BuildRawEventAlg.InputFileName = \"${FILENAME}\";,g"\
                -e "s,LinjcStream.Output.*$,LinjcStream.Output=\"DATAFILE='PFN:$LINJC_ROOT_FILENAME' TYP='POOL_ROOTTREE' OPT='RECREATE'\";,g"\
                -e "s,numibeamStream.Output.*$,numibeamStream.Output=\"DATAFILE='PFN:$NUMIB_ROOT_FILENAME' TYP='POOL_ROOTTREE' OPT='RECREATE'\";,g"\
                -i ${OPTION_FILENAME}
       else 
           echo -e "Please set the data stream environment variable to (pdstl, linjc, numib, numip, or numil)" 2>&1 | tee -a $envlog
           echo -e "Exit the executable script." 2>&1 | tee -a $envlog
           if [ ${JOBSCRIPT_TEST} -eq 0 ]; then
              echo -e "Updating jobscript name jobscript_${JUSTIN_WORKFLOW_ID}.${JUSTIN_STAGE_ID}.${JUSTIN_SUBID}.log\n" 2>&1 | tee -a $envlog
              mv jobscript.log jobscript_${JUSTIN_WORKFLOW_ID}.${JUSTIN_STAGE_ID}.${JUSTIN_SUBID}.log
           fi
           exit 1
       fi

    # PedestalFinder_fRawDigits.opts 
    elif [[ $OPT_TIER == "pdstl" ]]; then
         echo -e "\tConfiguring the pedestal finder option file" 2>&1 | tee -a $envlog
         sed -e "s,PedestalRawDigits.root,$FILENAME,g" \
             -e "s,HistogramPersistencySvc.OutputFile.*$,HistogramPersistencySvc.OutputFile = \"$HISTO_FILENAME\";,g" \
             -e "s,PedestalFinder.AllOutFileName.*$,PedestalFinder.AllOutFileName = \"$ALLOUTFILENAME\";,g" \
             -e "s,PedestalFinder.ScrubbedOutFileName.*$,PedestalFinder.ScrubbedOutFileName = \"$SCRUBBEDOUTFILENAME\";,g" \
             -i ${OPTION_FILENAME}

    # MaxPEGain.opts
    elif [[ $OPT_TIER == "gain" ]]; then
         echo -e "\tConfiguring the PMT gain option file" 2>&1 | tee -a $envlog
         sed -e "s,LightInjectionRawDigits.root,$FILENAME,g" \
             -e "s,HistogramPersistencySvc.OutputFile.*$,HistogramPersistencySvc.OutputFile = \"$HISTO_FILENAME\";,g" \
             -e "s,MaxPEGainAlg.OutFileName.*$,MaxPEGainAlg.OutFileName = \"$GAINTABLEFILENAME\";,g" \
             -e "s,MaxPEGainAlg.ProblemChannelFileName.*$,MaxPEGainAlg.ProblemChannelFileName = \"$GAINPROBLEMCHANNELSFILENAME\";,g" \
             -e "s,MaxPEGainAlg.HVFileName.*$,MaxPEGainAlg.HVFileName = \"$GAINTUNEDHVFILENAME\";,g" \
             -i ${OPTION_FILENAME}

    # OfflinePedSup_fRawDigits.opts
    elif [[ $OPT_TIER == "supdigs" ]]; then
         echo -e "\tConfiguring the suppressed digits option file" 2>&1 | tee -a $envlog
         sed -e "s,NumibeamRawDigits.root,$FILENAME,g" \
             -e "s,SupDigits.root,$ROOT_FILENAME,g"\
             -i ${OPTION_FILENAME}

    # RockMuonReconstruction.opts
    elif [[ $OPT_TIER == "rockmu" ]]; then
         echo -e "\tConfiguring the rock muons option file" 2>&1 | tee -a $envlog 
         sed -e "s,NumibeamSupDigits.root,$FILENAME,g" \
             -e "s,DSTWriterAlg.OutputFile.*$,DSTWriterAlg.OutputFile = \"$ROCKMUONDSTFILENAME\";,g" \
             -e "s,HistogramPersistencySvc.OutputFile.*$,HistogramPersistencySvc.OutputFile = \"$HISTO_FILENAME\";,g" \
             -e "s,RockMuonCalibrationAlg.OutputFilename.*$,RockMuonCalibrationAlg.OutputFilename = \"$ROCKMUONFILENAME\";,g" \
             -i ${OPTION_FILENAME} 
   
    # Reconstruction
    elif [[ $OPT_TIER == "reco" ]]; then
         echo -e "\tConfiguring the reconstruction option file" 2>&1 | tee -a $envlog

    # The file tier is not defined
    else 
         echo -e "The file tier is not recognized. Please see the help menu." 2>&1 | tee -a $envlog
         echo -e "Exit the executable script." 2>&1 | tee -a $envlog
         if [ ${JOBSCRIPT_TEST} -eq 0 ]; then
            echo -e "Updating jobscript name jobscript_${JUSTIN_WORKFLOW_ID}.${JUSTIN_STAGE_ID}.${JUSTIN_SUBID}.log\n" 2>&1 | tee -a $envlog
            mv jobscript.log jobscript_${JUSTIN_WORKFLOW_ID}.${JUSTIN_STAGE_ID}.${JUSTIN_SUBID}.log
        fi
        exit 1
    fi


    # print debug information
    if [ ${DEBUG_SUBMISSION_SCRIPT} -eq 1 ]; then
       echo -e "Printing the output of ${OPTION_FILENAME}\n" 2>&1 | tee -a $envlog
       less ${OPTION_FILENAME}
    fi
    #=================================================================================================
    #=================================================================================================
    #=================================================================================================



    #+++++++++++++++++++++++++++++++++++++++++
    # running the option file
    #+++++++++++++++++++++++++++++++++++++++++
    echo -e "\tRunning the option file [$OPTION_FILENAME]\n" 2>&1 | tee -a $envlog
    export GAUDI_START_TIME="$(date -u +%s)"
    SystemTestsApp.exe ${OPTION_FILENAME} >> ${LOG_FILENAME}
    export GAUDI_END_TIME="$(date -u +%s)"

    

    #++++++++++++++++++++++++++
    #  check job output
    #+++++++++++++++++++++++++
    export GAUDI_JOB_SUCCESS=true
    export GAUDI_ROOT_FILE=""

    if [[ $OPT_TIER == "rawdigs" ]]; then
       if [[ $DATA_STREAM == "pdstl" || $DATA_STREAM == "linjc" || $DATA_STREAM == "numib" ]]; then
          if [ ! -f "$ROOT_FILENAME" ]; then
             echo -e "The output file [$ROOT_FILENAME] does not exist. Exiting!" 2>&1 | tee -a $envlog 
             GAUDI_JOB_SUCCESS=false
          fi
       elif [[ $DATA_STREAM == "numip" ]]; then
            if [ ! -f "$PDSTL_ROOT_FILENAME" ]; then
               echo -e "The output file [$PDSTL_ROOT_FILENAME] does not exist. Exiting!" 2>&1 | tee -a $envlog
               GAUDI_JOB_SUCCESS=false
            fi
            if [ ! -f "$NUMIB_ROOT_FILENAME" ]; then
               echo -e "The output file [$NUMIB_ROOT_FILENAME] does not exist. Exiting!" 2>&1 | tee -a $envlog
               GAUDI_JOB_SUCCESS=false
            fi
       elif [[ $DATA_STREAM == "numil" ]]; then
            if [ ! -f "$LINJC_ROOT_FILENAME" ]; then
               echo -e "The output file [$LINJC_ROOT_FILENAME] does not exist. Exiting!" 2>&1 | tee -a $envlog
               GAUDI_JOB_SUCCESS=false
            fi
            if [ ! -f "$NUMIB_ROOT_FILENAME" ]; then
               echo -e "The output file [$NUMIB_ROOT_FILENAME] does not exist. Exiting!" 2>&1 | tee -a $envlog
               GAUDI_JOB_SUCCESS=false
            fi
       fi
    elif [[ $OPT_TIER == "pdstl" ]]; then
         if [ ! -f "$ALLOUTFILENAME" ]; then
            echo -e "The output file [$ALLOUTFILENAME] does not exist. Exiting!" 2>&1 | tee -a $envlog
            GAUDI_JOB_SUCCESS=false
         fi
         if [ ! -f "$SCRUBBEDOUTFILENAME" ]; then
            echo -e "The output file [$SCRUBBEDOUTFILENAME] does not exist. Exiting!" 2>&1 | tee -a $envlog
            GAUDI_JOB_SUCCESS=false
         fi
    elif [[ $OPT_TIER == "gain" ]]; then
         if [ ! -f "$GAINTABLEFILENAME" ]; then
            echo -e "The output file [$GAINTABLEFILENAME] does not exist. Exiting!" 2>&1 | tee -a $envlog
            GAUDI_JOB_SUCCESS=false
         fi
         if [ ! -f "$GAINPROBLEMCHANNELSFILENAME" ]; then
            echo -e "The output file [$GAINPROBLEMCHANNELSFILENAME] does not exist. Exiting!" 2>&1 | tee -a $envlog
            GAUDI_JOB_SUCCESS=false
         fi
         if [ ! -f "$GAINTUNEDHVFILENAME" ]; then
            echo -e "The output file [$GAINTUNEDHVFILENAME] does not exist. Exiting!" 2>&1 | tee -a $envlog
            GAUDI_JOB_SUCCESS=false
         fi
    elif [[ $OPT_TIER == "supdigs" ]]; then
         if [ ! -f "$ROOT_FILENAME" ]; then
             echo -e "The output file [$ROOT_FILENAME] does not exist. Exiting!" 2>&1 | tee -a $envlog
             GAUDI_JOB_SUCCESS=false
         fi       
    elif [[ $OPT_TIER == "rockmu" ]]; then
         if [ ! -f "$ROCKMUONDSTFILENAME" ]; then
            echo -e "The output file [$ROCKMUONDSTFILENAME] does not exist. Exiting!" 2>&1 | tee -a $envlog
            GAUDI_JOB_SUCCESS=false
         fi
         if [ ! -f "$ROCKMUONFILENAME" ]; then
            echo -e "The output file [$ROCKMUONFILENAME] does not exist. Exiting!" 2>&1 | tee -a $envlog
            GAUDI_JOB_SUCCESS=false
         fi
    fi



    #+++++++++++++++++++++++++
    # create metadata file
    #+++++++++++++++++++++++++
    if [[ $OPT_TIER == "rockmu" || $OPT_TIER == "reco" ]]; then
       echo -e "Creating the metadata file [$JSON_FILENAME] for tier [$OPT_TIER]" 2>&1 | tee -a $envlog
       export METADATA_EXTRACT=${INPUT_TAR_DIR_LOCAL}/Minerva_${MINERVA_RELEASE}/Tools/ProductionScriptsLite/Mx2_scripts/Mx2MetadataExtract.py
       
       export filename=""
       if [[ $OPT_TIER == "rockmu" ]]; then
          filename=`ls *RockMuons.root`
       elif [[ $OPT_TIER == "rockmu" ]]; then
          filename=`ls *RecoData.root`
       fi
       export fsize=`ls -l ${filename} | cut -f5 -d' '`
       export checksum=`xrdadler32 ${filename} | cut -f1 -d' '`

       if [ -f "$METADATA_EXTRACT" ]; then
          echo -e "Running the command [python ${METADATA_EXTRACT} --name=${filename} --ifile=${did} --ofile=${JSON_FILENAME}] --size=${fsize} --checksum=${checksum}" 2>&1 | tee -a $envlog
          (
            setup metacat
            setup python v3_9_15
            python ${METADATA_EXTRACT} --name=${filename} --ifile=${did} --ofile=${JSON_FILENAME} --size=${fsize} --checksum=${checksum}
          )
       else :
          echo -e "Cannot create the metadata file [$JSON_FILENAME]. The script [$METADATA_EXTRACT] does not exist." 2>&1 | tee -a $envlog
       fi
    fi

    

    #++++++++++++++++++++++
    # clean up
    #++++++++++++++++++++++
    if [[ $OPT_TIER == "rawdigs" ]]; then
       if [[ $DATA_STREAM == "numip" && $SAVE_PDSTL -eq 1 ]]; then
          echo -e "Removing the output numi beam file [$NUMIB_ROOT_FILENAME]\n" 2>&1 | tee -a $envlog
          rm -f $NUMIB_ROOT_FILENAME
       elif [[ $DATA_STREAM == "numip" && $SAVE_NUMIB -eq 1 ]]; then
            echo -e "Removing the output pedestal file [$PDSTL_ROOT_FILENAME]\n" 2>&1 | tee -a $envlog
            rm -f $PDSTL_ROOT_FILENAME
       elif [[ $DATA_STREAM == "numil" && $SAVE_LINJC -eq 1 ]]; then
            echo -e "Removing the output numi beam file [$NUMIB_ROOT_FILENAME]\n" 2>&1 | tee -a $envlog
            rm -f ${NUMIB_ROOT_FILENAME}
       elif [[ $DATA_STREAM == "numil" && $SAVE_NUMIB -eq 1 ]]; then
            echo -e "Removing the output light injection file [$LINJC_ROOT_FILENAME]\n" 2>&1 | tee -a $envlog
            rm -f $LINJC_ROOT_FILENAME
       fi 
    fi



    #++++++++++++++++++++++++++
    # update the input file
    #++++++++++++++++++++++++++
    inext=$(( $i + 1 ))
    if [ ${inext} -lt ${total} ]; then
       if [[ "${TIER[$i+1]}" == "pdstl" ]]; then
          FILENAME=`ls * | grep -i pdstl | grep -i root`
       elif [[ "${TIER[$i+1]}" == "gain" ]]; then
          FILENAME=`ls * | grep -i linjc | grep -i root`
       elif [[ "${TIER[$i+1]}" == "supdigs" ]]; then
          FILENAME=`ls * | grep -i numib | grep -i RawDigits.root`
       elif [[ "${TIER[$i+1]}" == "rockmu" ]]; then
          FILENAME=`ls * | grep -i numi | grep -i SupDigits.root`
       else 
          echo -e "Please see the help menu. The file tier [${TIER[i+1]}] is invalid.\n" 2>&1 | tee -a $envlog
          if [ ${JOBSCRIPT_TEST} -eq 0 ]; then
             echo -e "Updating jobscript name jobscript_${JUSTIN_WORKFLOW_ID}.${JUSTIN_STAGE_ID}.${JUSTIN_SUBID}.log\n" 2>&1 | tee -a $envlog
             mv jobscript.log jobscript_${JUSTIN_WORKFLOW_ID}.${JUSTIN_STAGE_ID}.${JUSTIN_SUBID}.log
          fi
          exit 1
       fi
       echo -e "\tThe next input file is [$FILENAME]\n\n" 2>&1 | tee -a $envlog
    fi


#++++++++++++++++++++++++++++++++++++++++++++++
# end of executing the option files
#++++++++++++++++++++++++++++++++++++++++++++++
done


#++++++++++++++++++++++
# final clean up
#++++++++++++++++++++++
if [  -f "$INPUT_FILE" ]; then
   echo -e "\tRemoving the input file ${WORKSPACE}/${INPUT_FILE}\n" 2>&1 | tee -a $envlog
   rm -f ${WORKSPACE}/${INPUT_FILE}
fi


######################################
#
# END OF RUNNING GAUDI JOBS
#
######################################


#+++++++++++++++++++++++++++++++++++++++++++
# marking input file as processed
#+++++++++++++++++++++++++++++++++++++++++++
if [ ${JOBSCRIPT_TEST} -eq 0 ]; then
   echo -e "Marking the input file(s) [${pfn}] as processed.\n" 2>&1 | tee -a $envlog
   echo -e "${pfn}" > justin-processed-pfns.txt
fi


#++++++++++++++++++++++++++++++++++++++++++++++++++++++
# checking the contents of the current directory 
#++++++++++++++++++++++++++++++++++++++++++++++++++++++
echo -e "\n\nThe contents in the ${WORKSPACE} directory:" 2>&1 | tee -a $envlog
ls -lha * 2>&1 | tee -a $envlog
echo -e "" | tee -a $envlog


#+++++++++++++++++++++++++++++++++++++++++
# end of script
#+++++++++++++++++++++++++++++++++++++++++
date +"%n%a %b %d %T %Z %Y%n" | tee -a $envlog
echo -e "Exit the jobscript.\n\n" 2>&1 | tee -a $envlog


if [ ${JOBSCRIPT_TEST} -eq 0 ]; then
   echo -e "Updating jobscript name jobscript_${JUSTIN_WORKFLOW_ID}.${JUSTIN_STAGE_ID}.${JUSTIN_SUBID}.log\n" 2>&1 | tee -a $envlog
   mv jobscript.log jobscript_${JUSTIN_WORKFLOW_ID}.${JUSTIN_STAGE_ID}.${JUSTIN_SUBID}.log
fi

exit 0
justIN time: 2024-11-24 07:26:08 UTC       justIN version: 01.01.09