Index: trunk/MagicSoft/Mars/datacenter/scripts/copyscript
===================================================================
--- trunk/MagicSoft/Mars/datacenter/scripts/copyscript	(revision 8193)
+++ trunk/MagicSoft/Mars/datacenter/scripts/copyscript	(revision 8215)
@@ -38,5 +38,5 @@
 # - filling the information from the *.rbk and *.run files into the DB
 # using the macros filldotrbk.C and filldotrun.C
-# - copying all logfiles to the correct directory:
+# - moving all logfiles to the correct directory:
 # /subsystemdata/subsystem/YYYY/MM/DD/file.*
 # - building the sequences for the standard analysis in the database
@@ -100,111 +100,109 @@
 #find all dates in transfer-directory
 dates=`find $transdir/*/ -type d | grep -o --regexp=20[0-9][0-9]_[0-1][0-9]_[0-3][0-9]` >> $scriptlog 2>&1
-if [ "$dates" = "" ]
+if ! [ "$dates" = "" ]
 then 
-   echo "nothing to do -> exit"  >> $scriptlog 2>&1
-   finish >> $scriptlog 2>&1
+   echo "dates found: "$dates  >> $scriptlog 2>&1 
+   #loop over dates 
+   for date in ${dates[@]}
+   do 
+      printprocesslog "INFO processing files for $date"
+      #find all files for this date
+      files=`find $transdir/*/$date/ -name "*.*"`  >> $scriptlog 2>&1
+      if [ "$files" = "" ]
+      then
+         echo "no files found for $date"  >> $scriptlog 2>&1
+         continue
+      else
+         echo "files found for $date"  >> $scriptlog 2>&1
+      fi
+
+      date2=`echo $date | sed -e 's/_/\//g'`
+      copylogpath=$logpath/$program/$date2
+      echo "copylogpath: "$copylogpath >> $scriptlog 2>&1
+      makedir $copylogpath >> $scriptlog 2>&1
+
+      #loop over all files in the directories for this date
+      for file in $files
+      do
+         echo "file: "$file  >> $scriptlog 2>&1
+         filename=`basename $file`
+
+         #check for each file whether it has to be processed
+         if grep -i "$filename: OK" $transdir/.check  >> $scriptlog 2>&1
+         then
+            newfile=`echo $file | sed -e 's/home\/lapalma\/transfer/magic\/subsystemdata/' -e 's/ccdata/cc/' -e 's/cacodata/caco/' -e 's/drivelogs/drive/' -e 's/_/\//1' -e 's/_/\//1' `
+            echo "file (new path): "$newfile >> $scriptlog 2>&1
+            newpath=`dirname $newfile`
+            #make sure, that the needed directories are available
+            makedir $newpath >> $scriptlog 2>&1
+
+            #run macros if the file is a *.rbk or a *.run file to
+            #fill the information into the db
+            if echo $filename | grep \\\.rbk$  >> $scriptlog 2>&1
+            then
+               echo "found rbk-file $filename"  >> $scriptlog 2>&1
+
+               checkfillrbk=`root -q -b $macrospath/filldotrbk.C+\("\"$file\""\,kFALSE\) | tee $copylogpath/filldotrbk-$filename-log.txt | intgrep`
+
+               case $checkfillrbk in
+                  1) echo " checkfillrbk=$checkfillrbk -> everything ok " >> $scriptlog 2>&1
+                     echo "  -> go on with moving file" >> $scriptlog 2>&1
+                     ;;
+                  *) echo " checkfillrbk=$checkfillrbk - Error -> go on with next file" >> $scriptlog 2>&1
+                     printprocesslog "ERROR filldotrbk.C failed for $file"
+                     continue
+                     ;;
+               esac
+            fi
+
+            if echo $file | grep 'CC_.*.run' >> $scriptlog 2>&1  && ! echo $file | grep .run.html >> $scriptlog 2>&1
+            then
+               echo "found run-file $filename" >> $scriptlog 2>&1
+
+               checkfillrun=`root -q -b $macrospath/filldotrun.C+\("\"$file\""\,kFALSE\) | tee $copylogpath/filldotrun-$filename-log.txt | intgrep`
+
+               case $checkfillrun in
+                  1) echo " checkfillrun=$checkfillrun -> everything ok " >> $scriptlog 2>&1
+                     echo "  -> insert date in SequenceBuildStatus for $date" >> $scriptlog 2>&1
+
+                     checkinsertdate=`root -q -b $macrospath/insertdate.C+\("\"$date\""\) | tee $copylogpath/insertdate-$date-log.txt | intgrep`
+
+                     case $checkinsertdate in
+                        1) echo "date inserted" >> $scriptlog 2>&1 ;;
+                        *) echo " checkinsertdate=$checkinsertdate -> ERROR - insert date didn't work" >> $scriptlog 2>&1
+                           printprocesslog "ERROR insertdate.C failed for $date"
+                           continue
+                           ;;
+                     esac
+                     echo " -> go on with moving file" >> $scriptlog 2>&1
+                     ;;
+                  *) echo " checkfillrun=$checkfillrun Error -> go on with next file" >> $scriptlog 2>&1
+                     printprocesslog "ERROR filldotrun.C failed for $file"
+                     continue
+                     ;;
+               esac
+            fi
+
+            if mv -v $file $newpath >> $scriptlog 2>&1
+            then
+               #add file to donelist
+               filename3=`echo $file | cut -c $char-999`
+               echo "$filename3 processed" >> $transdir/.processed
+               echo $filename" moved and added to .processed" >> $scriptlog 2>&1
+            else
+               echo $file" couldn't be moved!!!!!" >> $scriptlog 2>&1
+               printprocesslog "WARN moving of file $file didn't work"
+            fi
+
+         else
+            #if the checksum for the file is not ok or the file was
+            #already processed (entry in donelist) -> go on with next file
+            echo $file": checksum not ok " >> $scriptlog 2>&1
+            printprocesslog "WARN checksum for file $file is not ok"
+         fi
+      done
+   done
 fi
 
-echo "dates found: "$dates  >> $scriptlog 2>&1 
-#loop over dates 
-for date in ${dates[@]}
-do 
-   printprocesslog "INFO processing files for $date"
-   #find all files for this date
-   files=`find $transdir/*/$date/ -name "*.*"`  >> $scriptlog 2>&1
-   if [ "$files" = "" ]
-   then 
-      echo "no files found for $date"  >> $scriptlog 2>&1
-      continue
-   else
-      echo "files found for $date"  >> $scriptlog 2>&1
-   fi
-   
-   date2=`echo $date | sed -e 's/_/\//g'`
-   copylogpath=$logpath/$program/$date2
-   echo "copylogpath: "$copylogpath >> $scriptlog 2>&1
-   makedir $copylogpath >> $scriptlog 2>&1
-   
-   #loop over all files in the directories for this date
-   for file in $files
-   do
-      echo "file: "$file  >> $scriptlog 2>&1 
-      filename=`basename $file`
-                        
-      #check for each file whether it has to be processed
-      if grep -i "$filename: OK" $transdir/.check  >> $scriptlog 2>&1 
-      then
-         newfile=`echo $file | sed -e 's/home\/lapalma\/transfer/magic\/subsystemdata/' -e 's/ccdata/cc/' -e 's/cacodata/caco/' -e 's/drivelogs/drive/' -e 's/_/\//1' -e 's/_/\//1' `
-         echo "file (new path): "$newfile >> $scriptlog 2>&1 
-         newpath=`dirname $newfile`
-         #make sure, that the needed directories are available
-         makedir $newpath >> $scriptlog 2>&1 
-         
-         #run macros if the file is a *.rbk or a *.run file to
-         #fill the information into the db
-         if echo $filename | grep \\\.rbk$  >> $scriptlog 2>&1 
-         then
-            echo "found rbk-file $filename"  >> $scriptlog 2>&1 
-            
-            checkfillrbk=`root -q -b $macrospath/filldotrbk.C+\("\"$file\""\,kFALSE\) | tee $copylogpath/filldotrbk-$filename-log.txt | intgrep`
-            
-            case $checkfillrbk in
-               1) echo " checkfillrbk=$checkfillrbk -> everything ok " >> $scriptlog 2>&1 
-                  echo "  -> go on with copying file" >> $scriptlog 2>&1 
-                  ;;
-               *) echo " checkfillrbk=$checkfillrbk - Error -> go on with next file" >> $scriptlog 2>&1 
-                  printprocesslog "ERROR filldotrbk.C failed for $file"
-                  continue
-                  ;;
-            esac
-         fi
-         
-         if echo $file | grep 'CC_.*.run' >> $scriptlog 2>&1  && ! echo $file | grep .run.html >> $scriptlog 2>&1 
-         then
-            echo "found run-file $filename" >> $scriptlog 2>&1 
-            
-            checkfillrun=`root -q -b $macrospath/filldotrun.C+\("\"$file\""\,kFALSE\) | tee $copylogpath/filldotrun-$filename-log.txt | intgrep`
-            
-            case $checkfillrun in
-               1) echo " checkfillrun=$checkfillrun -> everything ok " >> $scriptlog 2>&1 
-                  echo "  -> insert date in SequenceBuildStatus for $date" >> $scriptlog 2>&1 
-
-                  checkinsertdate=`root -q -b $macrospath/insertdate.C+\("\"$date\""\) | tee $copylogpath/insertdate-$date-log.txt | intgrep`
-                  
-                  case $checkinsertdate in
-                     1) echo "date inserted" >> $scriptlog 2>&1 ;;
-                     *) echo " checkinsertdate=$checkinsertdate -> ERROR - insert date didn't work" >> $scriptlog 2>&1 
-                        printprocesslog "ERROR insertdate.C failed for $date"
-                        continue
-                        ;;
-                  esac
-                  echo " -> go on with copying file" >> $scriptlog 2>&1 
-                  ;;
-               *) echo " checkfillrun=$checkfillrun Error -> go on with next file" >> $scriptlog 2>&1 
-                  printprocesslog "ERROR filldotrun.C failed for $file"
-                  continue
-                  ;;
-            esac
-         fi
-
-         if mv -v $file $newpath >> $scriptlog 2>&1 
-         then
-            #add file to donelist
-            filename3=`echo $file | cut -c $char-999`
-            echo "$filename3 processed" >> $transdir/.processed
-            echo $filename" moved and added to .processed" >> $scriptlog 2>&1 
-         else
-            echo $file" couldn't be moved!!!!!" >> $scriptlog 2>&1 
-            printprocesslog "WARN moving of file $file didn't work"
-         fi
-
-      else
-         #if the checksum for the file is not ok or the file was
-         #already processed (entry in donelist) -> go on with next file
-         echo $file": checksum not ok " >> $scriptlog 2>&1 
-         printprocesslog "WARN checksum for file $file is not ok"
-      fi
-   done
-done
 
 echo "remove empty directories: "  >> $scriptlog 2>&1 
@@ -214,6 +212,48 @@
 
 
-
-#second part of the script:
+# second part of the script
+#searching optical data files, inserting the information into the db and
+#moving the files
+file=""
+opticalfiles=`find $transdir/optical -name '*.instr'`
+for opticalfile in $opticalfiles
+do
+   printprocesslog "INFO process "$opticalfile
+#   echo $opticalfile
+   file=`basename $opticalfile`
+   year=`echo $file | cut -c 0-4`
+   opticallogpath=$logpath/filloptical/$year
+   makedir $opticallogpath >> $scriptlog 2>&1
+   opticallogfile=$opticallogpath/filloptical-$file.log
+#   echo "logfile: "$opticallogfile
+  
+   checkfilloptical=`root -q -b $macrospath/filloptical.C+\("\"$opticalfile\""\,kFALSE\) | tee $opticallogfile | intgrep`
+#   checkfilloptical=`root -q -b $macrospath/filloptical.C+\("\"$opticalfile\""\) | tee $opticallogfile | intgrep`
+            
+   case $checkfilloptical in
+      1) echo " checkfilloptical=$checkfilloptical -> everything ok -> go on with moving file" >> $scriptlog 2>&1 
+         newdir=$subsystempath/optical/$year
+         newfile=$newdir/$file
+         makedir $newdir >> $scriptlog 2>&1
+         
+         if mv -v $opticalfile $newfile >> $scriptlog 2>&1 
+         then
+            echo "moved "$opticalfile" successfully" >> $scriptlog 2>&1 
+            printprocesslog "INFO moved "$opticalfile" successfully"
+         else
+            echo $opticalfile" couldn't be moved!!!!!" >> $scriptlog 2>&1 
+            printprocesslog "WARN moving of file $opticalfile didn't work"
+         fi
+
+         ;;
+      *) echo " checkfilloptical=$checkfilloptical - Error -> go on with next file" >> $scriptlog 2>&1 
+         printprocesslog "ERROR filloptical.C failed for $opticalfile"
+         continue
+         ;;
+   esac
+done
+
+
+# third part of the script:
 #update the catalog file magic_favorites.edb
 printprocesslog "INFO processing new catalog files"
@@ -258,5 +298,5 @@
 
       oldcatalogpath=$setuppath/oldcatalogs
-      makedir $oldcatalogpath
+      makedir $oldcatalogpath >> $scriptlog 2>&1
       #rsync current catalogfile to directory with old catalogfiles including the date of the new catalogfile into the filename
       if ! rsync -av $catalog $oldcatalogpath/$magfav.$date >> $scriptlog 2>&1 
