8# ------------------------------------------------------------------------------------------------
 
   10#     Utility script for finding PMT supply voltages corresponding to the nominal gain setting.
 
   12# ------------------------------------------------------------------------------------------------
 
   15if [ -z $JPP_DIR ]; then
 
   16    echo "Variable JPP_DIR undefined."
 
   21source $JPP_DIR/setenv.sh $JPP_DIR
 
   23set_variable:  DEBUG        CALIBRATION_DEBUG            2
 
   24set_variable:  WORKDIR      CALIBRATION_WORKDIR          ${TMPDIR:-/tmp}
 
   26set_variable:  DETID        EDITTUNEHV_DETID             -1
 
   27set_variable:  RUNID        EDITTUNEHV_RUNID             -1
 
   28set_variable:  OUTPUT_FILE  EDITTUNEHV_OUTPUT_FILE       "HVtuningEdit.json"
 
   32    usage "$script <input file> <output files> [detector identifier] [run number] [PMT set]\n\n"           \
 
   33          "Note: The operation performed depends on the input parameters.\n"                     \
 
   34          "      Possible operations are to update according to:\n"                              \
 
   35          "        - the high-voltage settings corresponding to a specific DAQ run\n"            \
 
   36          "          if both detector ID and run number are specified.\n"                        \
 
   37          "        - the vendor high-voltage settings\n"                                         \
 
   38          "          if the detector ID is specified, but the run number is left unspecified.\n" \
 
   39          "        - manually specifiable values\n"                                              \
 
   40          "          if both detector ID and run number are left unspecified.\n\n"               \
 
   41          "      A set of PMTs on which the operation should be performed can be optionally\n"   \
 
   42          "      specified via the command line."
 
   46    2) set_variable OUTPUT_FILE        $2;
 
   47       set_variable INPUT_FILE         $1;;
 
   48    *) set_variable INPUT_FILE         $1
 
   49       set_variable OUTPUT_FILE        $2
 
   51       set_array    IDENTIFIERS        ""
 
   54       for ARGUMENT in ${argv[3,-1]}; do
 
   55           if [[ ${ARGUMENT} =~ ^-?[0-9]+$ ]]; then
 
   56               set_array IDENTIFIERS   ${IDENTIFIERS[@]} ${ARGUMENT}
 
   58               set_array PMTSET        ${PMTSET[@]} ${ARGUMENT}
 
   62       if (( ${#IDENTIFIERS} > 0 )); then
 
   63           set_variable  DETID         ${IDENTIFIERS[1]}
 
   66       if (( ${#IDENTIFIERS} > 1 )); then
 
   67           set_variable  RUNID         ${IDENTIFIERS[2]}
 
   72let "TIMER = $(date +%s)"
 
   78set_variable         COOKIE            $(cat ~/.km3netdb_cookie)
 
   79set_variable         LOGIN             ${${COOKIE#*_}%%_*}
 
   80set_variable         LOCATIONID        $(getLocationID -L ${LOGIN})
 
   83if (( ${DETID} > 0 )); then
 
   85    if (( ${RUNID} > 0 )); then
 
   87        set_variable DETOID   $( getDetector -D ${DETID} -- )
 
   90            -q pmt_hv_run_settings     \
 
   91            -@ "detoid = ${DETOID}"    \
 
   92            -@ "run    = ${RUNID}" --  > ${WORKDIR}/HVfile.txt
 
   94        set_array HVTABLE   2 ${WORKDIR}/HVfile.txt
 
  100            -@ "detid  = ${DETID}" --  > ${WORKDIR}/HVfile.txt
 
  102        set_array HVTABLE   1 ${WORKDIR}/HVfile.txt
 
  109    let "TIMER = $(date +%s) - $TIMER"
 
  114        ${HVTABLE:+-b "${HVTABLE[*]}"}       \
 
  115        ${PMTSET:+-P "${PMTSET[*]}"}         \
 
  116        -# "login       = ${LOGIN}"          \
 
  117        -# "locationID  = ${LOCATIONID}"     \
 
  118        -# "elapsedTime = ${TIMER}"          \