Index: trunk/Mars/hawc/processing/DiskToDB/extract-aux-data2.sh
===================================================================
--- trunk/Mars/hawc/processing/DiskToDB/extract-aux-data2.sh	(revision 20103)
+++ trunk/Mars/hawc/processing/DiskToDB/extract-aux-data2.sh	(revision 20104)
@@ -30,10 +30,8 @@
 # File to which the queries are written
 OUTPUT="insert-aux.sql"
-TMPOUT="./tmpAuxOut.sql"
 # The Mars build directory
-readonly MARS="/home/frankm/Dateien/Mars-6.24.00/build4/"
+readonly MARS="/home/hawc/Desktop/Mars/"
 # The path to your Mars/build directory where the processing macros are stored
-# MACROS="/home/frankm/Dateien/Mars/hawc/processing"
-readonly MACROS="/home/frankm/Dateien/Mars-6.24.00/build/Masterarbeit/Datenbank/HE01/Mexico/Cfiles/"
+readonly MACROS="/home/hawc/Desktop/Mars-src/hawc/processing/"
 readonly PROGRAM=$0
 INSERT="INSERT INTO"
@@ -96,4 +94,5 @@
 NIGHT="${4}"
 
+TMPOUT="./tmpAuxOut-${TEL}.sql"
 ERRCODE=
 
@@ -318,8 +317,10 @@
 
 # Delete last comma and replace it with closing parintheses
-sed -i '$s/,/)/' "${OUTPUT}"
-
-# Finish the query file with defining the column names
-echo "\
+if [ -f "${TMPOUT}" ]
+then
+	sed -i '$s/,/)/' "${OUTPUT}"
+
+	# Finish the query file with defining the column names
+	echo "\
 AS
 v(
@@ -337,5 +338,12 @@
 "\ >> ${OUTPUT}
 
-cat ${TMPOUT} >> ${OUTPUT}
+else
+	head -n -4 "${OUTPUT}" > out.sql.new && mv out.sql.new "${OUTPUT}"
+fi
+
+if [ -f "${TMPOUT}" ]
+then
+	cat ${TMPOUT} >> ${OUTPUT}
+fi
 
 rm -f ${TMPOUT}
Index: trunk/Mars/hawc/processing/DiskToDB/extract-raw-header2.sh
===================================================================
--- trunk/Mars/hawc/processing/DiskToDB/extract-raw-header2.sh	(revision 20103)
+++ trunk/Mars/hawc/processing/DiskToDB/extract-raw-header2.sh	(revision 20104)
@@ -32,5 +32,5 @@
 # define variables
 OUTPUT=insert-raw.sql
-readonly FITSDUMP="/home/frankm/Dateien/FACT++/build/fitsdump"
+readonly FITSDUMP="/home/hawc/Desktop/FACT++/fitsdump"
 readonly PROGRAM=$0
 INSERT="INSERT INTO"
@@ -108,5 +108,4 @@
 	local stat="${3}"
 
-	echo "${root} header not valid!"
 	echo "UPDATE DataOnDisk SET"		>> ${OUTPUT}
 	echo "header=${stat} "			>> ${OUTPUT}
@@ -213,4 +212,5 @@
 	if [ $EXT -ne 0 ]
 	then
+		echo "${ROOT} Fitsdump failed!"
 		SetRawStatus "${ROOT}" ${RUNID} "1"
 		continue
@@ -234,4 +234,5 @@
 		SetRawStatus "${ROOT}" ${RUNID} "0"
 	else
+		echo "${ROOT} header not valid!"
 		SetRawStatus "${ROOT}" ${RUNID} "2"
 	fi
Index: trunk/Mars/hawc/processing/DiskToDB/run-callisto2.sh
===================================================================
--- trunk/Mars/hawc/processing/DiskToDB/run-callisto2.sh	(revision 20103)
+++ trunk/Mars/hawc/processing/DiskToDB/run-callisto2.sh	(revision 20104)
@@ -32,7 +32,7 @@
 readonly STAR=star
 # Directory to Mars environment (usually Mars/build)
-readonly MARS="/home/frankm/Dateien/Mars-6.24.00/build4/"
+readonly MARS="/home/hawc/Desktop/Mars/"
 # Absolut path to macros
-readonly MACROS="/home/frankm/Dateien/Mars-6.24.00/hawc"
+readonly MACROS="/home/hawc/Desktop/Mars-src/hawc"
 readonly PROGRAM=$0
 REPLACE=false
@@ -139,81 +139,77 @@
        --compress \
        | \
-       while read -r -a LINE
-       do
-	       # Extract night/runid for data file and calibration file
-	       DATNIGHT=${LINE[0]}
-	       DATRUNID=${LINE[1]}
-	       DRSNIGHT=${LINE[2]}
-	       DRSRUNID=${LINE[3]}
-
-	       # Formatting of the file paths and names
-	       DATPATH=${DATNIGHT:0:4}/${DATNIGHT:4:2}/${DATNIGHT:6:2}
-	       DRSPATH=${DRSNIGHT:0:4}/${DRSNIGHT:4:2}/${DRSNIGHT:6:2}
-
-	       PREFIX=`printf ${DATNIGHT}_%03d ${DATRUNID}`
-
-	       DATNAME=`printf ${DATNIGHT}_%03d.fits.fz ${DATRUNID}`
-	       DRSNAME=`printf ${DRSNIGHT}_%03d.drs.fits ${DRSRUNID}`
-
-	       OUT="${DATA}"/../${CALLISTO}/${DATPATH}
-
-	       echo DAT=${DATNAME} [${DATPATH}]
-	       echo DRS=${DRSNAME} [${DRSPATH}]
-
-
-	       if [ ${REPLACE} = true ]
-	       then
-		       echo "deleting ${OUT}/.${PREFIX}.succsess !!!"
-		       rm -f "${OUT}"/.${PREFIX}.success
-	       fi
-
-	       # Check if not yet successfully processed
-	       # Removing this file can be used to trigger a re-processing
-	       # the next time this script is executed
-	       if [ ! -f "${OUT}/.${PREFIX}.success" ]
-	       then
-
-		       cd ${MARS}
-
-		       mkdir -p "${OUT}"
-
-		       # Trigger reprocessing of the process-fils in the star directory
-		       rm -f "${DATA}/${STAR}/${DATPATH}/.${PREFIX}.*"
-
-		       # Flag that a process is running
-		       rm -f "${OUT}"/.${PREFIX}.done
-		       rm -f "${OUT}"/.${PREFIX}.success
-
-		       touch "${OUT}"/.${PREFIX}.running
-
-		       echo ${DATA}
-
-		       # Execute the calibration and write output to log-file
-		       root -b -q -l ${MACROS}/callisto.C'("'"${DATA}"/${DATPATH}/${DATNAME}'","'"${DATA}"/${DRSPATH}/${DRSNAME}'", 0 ,"'"${OUT}"'")' \
-			       2>&1 | tee "${OUT}"/${PREFIX}.log
-
-		       RC=${PIPESTATUS[0]}
-
-
-		       # Remember exit status of callisto
-		       echo RC=${RC} | tee -a "${OUT}"/${PREFIX}.log
-		       echo ${RC} > "${OUT}"/.${PREFIX}.done
-		       # Processing is finished
-		       rm -f "${OUT}"/.${PREFIX}.running
-
-		       # If processing was successfull write corresponding flag
-		       if [ "${RC}" == "0" ]
-		       then
+	while read -r -a LINE
+	do
+		# Extract night/runid for data file and calibration file
+	       	DATNIGHT=${LINE[0]}
+		DATRUNID=${LINE[1]}
+		DRSNIGHT=${LINE[2]}
+		DRSRUNID=${LINE[3]}
+
+	       	# Formatting of the file paths and names
+		DATPATH=${DATNIGHT:0:4}/${DATNIGHT:4:2}/${DATNIGHT:6:2}
+		DRSPATH=${DRSNIGHT:0:4}/${DRSNIGHT:4:2}/${DRSNIGHT:6:2}
+
+		PREFIX=`printf ${DATNIGHT}_%03d ${DATRUNID}`
+
+		DATNAME=`printf ${DATNIGHT}_%03d.fits.fz ${DATRUNID}`
+		DRSNAME=`printf ${DRSNIGHT}_%03d.drs.fits ${DRSRUNID}`
+
+		OUT="${DATA}"/../${CALLISTO}/${DATPATH}
+
+		echo DAT=${DATNAME} [${DATPATH}]
+		echo DRS=${DRSNAME} [${DRSPATH}]
+
+
+		if [ ${REPLACE} = true ]
+		then
+			echo "deleting ${OUT}/.${PREFIX}.succsess !!!"
+		       	rm -f "${OUT}"/.${PREFIX}.success
+		fi
+
+		# Check if not yet successfully processed
+		# Removing this file can be used to trigger a re-processing
+		# the next time this script is executed
+		if [ ! -f "${OUT}/.${PREFIX}.success" ]
+		then
+
+	       		cd ${MARS}
+
+			mkdir -p "${OUT}"
+
+			# Trigger reprocessing of the process-fils in the star directory
+			rm -f "${DATA}/${STAR}/${DATPATH}/.${PREFIX}.*"
+
+			# Flag that a process is running
+			rm -f "${OUT}"/.${PREFIX}.done
+			rm -f "${OUT}"/.${PREFIX}.success
+
+			touch "${OUT}"/.${PREFIX}.running
+
+			echo ${DATA}
+
+			RC=0
+			# Execute the calibration and write output to log-file
+			root -b -q -l ${MACROS}/callisto.C'("'"${DATA}"/${DATPATH}/${DATNAME}'","'"${DATA}"/${DRSPATH}/${DRSNAME}'", 0 ,"'"${OUT}"'")' \
+			       2>&1 | tee "${OUT}"/${PREFIX}.log || RC=1
+
+		       	# Remember exit status of callisto
+		       	echo RC=${RC} | tee -a "${OUT}"/${PREFIX}.log
+			echo ${RC} > "${OUT}"/.${PREFIX}.done
+		       	# Processing is finished
+			rm -f "${OUT}"/.${PREFIX}.running
+
+		       	# If processing was successfull write corresponding flag
+			if [ "${RC}" == "0" ]
+			then
 				touch "${OUT}"/.${PREFIX}.success
-		       else
-				UpdateStatus ${TEL} ${NIGHT} ${DATRUNID} 1
-		       fi
-
-		       cd -
-
-		       echo "-----End of first iteration-----"
-	       else
-		       echo Skipped.
-	       fi
-
-       done
+		       	fi
+
+			cd -
+
+			echo "-----End of first iteration-----"
+		else
+			echo Skipped.
+		fi
+
+	done
Index: trunk/Mars/hawc/processing/DiskToDB/run-root2sql2.sh
===================================================================
--- trunk/Mars/hawc/processing/DiskToDB/run-root2sql2.sh	(revision 20103)
+++ trunk/Mars/hawc/processing/DiskToDB/run-root2sql2.sh	(revision 20104)
@@ -28,5 +28,5 @@
 
 # Path to the executable
-readonly ROOT2SQL="/home/frankm/Dateien/FACT++/build/root2sql"
+readonly ROOT2SQL="/home/hawc/Desktop/FACT++/root2sql"
 readonly PROGRAM=${0}
 
@@ -128,12 +128,5 @@
 	fi
 
-	mysql --defaults-file=${CRED} \
-		--compress \
-		-e "UPDATE DataOnDisk \
-		SET DataOnDisk.${col} = 6 \
-		WHERE DataOnDisk.Telescope = ${tel} \
-		AND DataOnDisk.NIGHT = ${night} \
-		AND DataOnDisk.calibration != 0;"
-
+	# Set col to 3 if the file is a DRS run
 	mysql --defaults-file=${CRED} \
 		--compress \
Index: trunk/Mars/hawc/processing/DiskToDB/run-scripts.sh
===================================================================
--- trunk/Mars/hawc/processing/DiskToDB/run-scripts.sh	(revision 20103)
+++ trunk/Mars/hawc/processing/DiskToDB/run-scripts.sh	(revision 20104)
@@ -36,49 +36,66 @@
 
 
+
+function LockExit()
+{
+	echo "ERROR: One instance of ${SCRPTN} already running" >&2
+	exit 1
+}
+
+function DescExit()
+{
+	echo "ERROR: Filedescriptor 200 already taken" >&2
+	exit 1
+}
+
+function ErrExit()
+{
+	echo "ERROR: Line `caller`: ${BASH_COMMAND}" >&2
+	exit 1
+}
+
+function StrgCExit()
+{
+	echo " "
+	echo "$0 was forcefully terminated" >&2
+	exit 1
+}
+
+trap ErrExit ERR
+trap StrgCExit INT
+
+# Telescope for which to process
+readonly TEL="${1}"
+if [ ${TEL} = "1" ]
+then
+	echo "Processing for Telescope 1"
+elif [ ${TEL} = "2" ]
+then
+	echo "Processing for Telescope 2"
+else
+	echo "No valid Telescope selected!" >&2
+	exit 1
+fi
+
 # Filename
 readonly SCRPTN=`basename $0 .sh`
 
 # For lockfile
-readonly LOCK="/tmp/${SCRPTN}.lock"
-
-function LockExit()
-{
-	echo "ERROR: One instance of ${SCRPTN} already running" >&2
-	exit 1
-}
-
-function DescExit()
-{
-	echo "ERROR: Filedescriptor 200 already taken" >&2
-	exit 1
-}
-
-function ErrExit()
-{
-	echo "ERROR: Line `caller`: ${BASH_COMMAND}" >&2
-	exit 1
-}
-
-function StrgCExit()
-{
-	echo " "
-	echo "$0 was forcefully terminated" >&2
-	exit 1
-}
-
-trap ErrExit ERR
-trap StrgCExit INT
-
-exec 200>${LOCK} || DescExit
-flock -n 200 || LockExit
+readonly LOCK="/tmp/${SCRPTN}${TEL}.lock"
+
+eval "exec 20${TEL}>${LOCK}" || DescExit
+flock -n "20${TEL}" || LockExit
+
+cd /home/hawc/Desktop/DiskToDB/
 
 # For logfile
 mkdir -p log
 readonly DATE=`date +%Y%m%d_%H%M`
-readonly LOG="./log/${SCRPTN}_${DATE}.log"
-# exec 3>&1 1>>${LOG}
-# exec 4>>${LOG}
-exec 3>&1
-exec 4>&1
+readonly LOG="./log/${SCRPTN}_${DATE}_${TEL}.log"
+exec 3>&1 1>>${LOG}
+exec 4>>${LOG}
+exec 5>&2 2>>${LOG}
+# exec 3>&1
+# exec 4>&1
 
 echo "Start processing data"
@@ -188,16 +205,17 @@
 }
 
-
 # Define variables
-# Telescope for which to process
-readonly TEL=1
-# Directory in which the raw data is located
-readonly DIR='/run/media/frankm/Neuer Datenträger/data/DATA/HE0'${TEL}
+# Directory in which the raw directory is located
+readonly DIR="/media/DATA/HAWCsEYE0${TEL}/"
 # Credentials for the SQL database
-readonly CRED='../credentials-read-only.cnf'
+readonly CRED='../Credentials/credentials-read-only.cnf'
 # Credentials for root2sql for callisto
-readonly CALLISTORC='../root2sql-callisto.rc'
+readonly CALLISTORC='../Credentials/root2sql-callisto.rc'
 # Credentials for root2sql for star
-readonly STARRC='../root2sql-star.rc'
+readonly STARRC='../Credentials/root2sql-star.rc'
+# ROOT init path
+readonly RPATH='../root-6.24.02/bin/thisroot.sh'
+
+echo "Processing data from ${DIR}"
 
 # Check if variable paths point to something sensible
@@ -206,11 +224,17 @@
 DoesFileExists "${CALLISTORC}"
 DoesFileExists "${STARRC}"
+DoesFileExists "${RPATH}"
 
 # SQL outputs
 mkdir -p ./queries
-readonly ONDISK='./queries/insert-OnDisk.sql'
-readonly RAW='./queries/insert-raw.sql'
-readonly CALIB='./queries/find-calibration2.sql'
-readonly AUX='./queries/insert-aux.sql'
+readonly ONDISK="./queries/insert-OnDisk-${TEL}.sql"
+readonly RAW="./queries/insert-raw-${TEL}.sql"
+readonly CALIB="./queries/find-calibration2-${TEL}.sql"
+readonly AUX="./queries/insert-aux-${TEL}.sql"
+
+# Init ROOT
+set +o nounset
+. "${RPATH}"
+set -o nounset
 
 # Create Database of existing files
@@ -247,6 +271,4 @@
 echo "Updating database"
 
-NIGHTS=20201111
-
 echo "Nights to process:"
 echo "${NIGHTS}"
Index: trunk/Mars/hawc/processing/DiskToDB/run-star2.sh
===================================================================
--- trunk/Mars/hawc/processing/DiskToDB/run-star2.sh	(revision 20103)
+++ trunk/Mars/hawc/processing/DiskToDB/run-star2.sh	(revision 20104)
@@ -32,7 +32,7 @@
 readonly STAR=star
 # Directory to Mars environment (usually Mars/build)
-readonly MARS="/home/frankm/Dateien/Mars-6.24.00/build4/"
+readonly MARS="/home/hawc/Desktop/Mars/"
 # Absolut path to macros
-readonly MACROS="/home/frankm/Dateien/Mars-6.24.00/hawc"
+readonly MACROS="/home/hawc/Desktop/Mars-src/hawc"
 readonly PROGRAM=$0
 REPLACE=false
@@ -110,13 +110,24 @@
 "\
 SELECT 
-    	NIGHT, RUNID
+    	Calibration.NIGHT,
+	Calibration.RUNID
 FROM 
-    	Calibration
+	Calibration
+INNER JOIN
+	DataOnDisk
+ON
+	DataOnDisk.Telescope = Calibration.Telescope
+AND
+	DataOnDisk.NIGHT = Calibration.NIGHT
+AND
+	DataOnDisk.RUNID = Calibration.RUNID
 WHERE
-	Telescope=${TEL}
+    	Calibration.Telescope = ${TEL}
+AND	
+	Calibration.NIGHT = ${NIGHT}
 AND
-	NIGHT=${NIGHT}
+	DataOnDisk.callisto = 0
 ORDER BY
-    	NIGHT, RUNID\
+    	Calibration.NIGHT, Calibration.RUNID\
 "\
  |  mysql \
@@ -165,10 +176,15 @@
 			touch "${OUT}"/.${PREFIX}.running
 
+			RC=0
+			# set +o pipefail
      			# Execute image parameter calculation and write log-file
 			root -b -q -l ${MACROS}/star.C'("'"${IN}"/${DATNAME}'","'"${OUT}"'")' \
-				2>&1 | tee "${OUT}"/${PREFIX}.log
-
-     			# Remember exit status of callisto
-			RC=${PIPESTATUS[0]}
+				2>&1 | tee "${OUT}"/${PREFIX}.log || RC=1
+
+			# RC=$?
+			# set -o pipefail
+
+     			# Remember exit status of star
+			# RC=${PIPESTATUS[0]}
 
 			echo RC=${RC} | tee -a "${OUT}"/${PREFIX}.log
@@ -182,6 +198,4 @@
 			then
 				touch "${OUT}"/.${PREFIX}.success
-			else
-				UpdateStatus ${TEL} ${NIGHT} ${DATRUNID} 1
 			fi
 
Index: trunk/Mars/hawc/processing/DiskToDB/update-file-table2.sh
===================================================================
--- trunk/Mars/hawc/processing/DiskToDB/update-file-table2.sh	(revision 20103)
+++ trunk/Mars/hawc/processing/DiskToDB/update-file-table2.sh	(revision 20104)
@@ -169,12 +169,15 @@
 ) SELECT * FROM DataOnDisk
 	WHERE (Telescope, NIGHT, RUNID, ISDRSFILE) NOT IN 
-	(SELECT Telescope, NIGHT, RUNID, ISDRSFILE FROM DataOnDisk_tmp);
+	(SELECT Telescope, NIGHT, RUNID, ISDRSFILE FROM DataOnDisk_tmp)
+	AND Telescope=${TEL};
 
-UPDATE DataOnDisk SET star = NULL WHERE NIGHT IN 
-	(SELECT NIGHT FROM TableNotDisk);
+UPDATE DataOnDisk SET header = NULL WHERE NIGHT IN 
+	(SELECT NIGHT FROM TableNotDisk)
+	AND Telescope=${TEL};
 
 DELETE FROM DataOnDisk 
 	WHERE (Telescope, NIGHT, RUNID, ISDRSFILE) NOT IN 
-	(SELECT Telescope, NIGHT, RUNID, ISDRSFILE FROM DataOnDisk_tmp);
+	(SELECT Telescope, NIGHT, RUNID, ISDRSFILE FROM DataOnDisk_tmp)
+	AND Telescope=${TEL};
 
 ${INSERT} DataOnDisk (SELECT * FROM DataOnDisk_tmp);
Index: trunk/Mars/hawc/processing/DiskToDB/write-calibration-query.sh
===================================================================
--- trunk/Mars/hawc/processing/DiskToDB/write-calibration-query.sh	(revision 20103)
+++ trunk/Mars/hawc/processing/DiskToDB/write-calibration-query.sh	(revision 20104)
@@ -97,5 +97,7 @@
 UPDATE DataOnDisk 
 SET DataOnDisk.calibration = 6
-WHERE DataOnDisk.header != 0;
+WHERE DataOnDisk.header != 0
+AND NIGHT=${NIGHT}
+AND Telescope=${TEL};
 
 CREATE TEMPORARY TABLE Calibration_tmp
@@ -205,9 +207,15 @@
 UPDATE DataOnDisk 
 SET DataOnDisk.calibration = 0
-WHERE DataOnDisk.header = 0;
+WHERE DataOnDisk.header = 0
+AND NIGHT=${NIGHT}
+AND Telescope=${TEL};
 
 -- Set Status to 2 if there was no drs file with step = 1 in the NIGHT
 UPDATE DataOnDisk
 SET DataOnDisk.calibration = 2
-WHERE EXISTS(SELECT * FROM Calibration WHERE NIGHT=${NIGHT}) = 0;
+WHERE EXISTS(
+	SELECT * FROM Calibration
+	WHERE NIGHT=${NIGHT}
+	AND Telescope=${TEL}
+	) = 0;
 "\ >> ${OUTPUT}
