source: branches/MarsGapdTimeJitter/datacenter/scripts/copyoutput@ 18221

Last change on this file since 18221 was 10048, checked in by Daniela Dorner, 14 years ago
  • Property svn:executable set to *
File size: 3.7 KB
Line 
1#!/bin/sh
2#
3# ========================================================================
4#
5# *
6# * This file is part of MARS, the MAGIC Analysis and Reconstruction
7# * Software. It is distributed to you in the hope that it can be a useful
8# * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
9# * It is distributed WITHOUT ANY WARRANTY.
10# *
11# * Permission to use, copy, modify and distribute this software and its
12# * documentation for any purpose is hereby granted without fee,
13# * provided that the above copyright notice appear in all copies and
14# * that both that copyright notice and this permission notice appear
15# * in supporting documentation. It is provided "as is" without express
16# * or implied warranty.
17# *
18#
19#
20# Author(s): Daniela Dorner 10/2010 <mailto:daniela.dorner@unige.ch>
21#
22# Copyright: MAGIC Software Development, 2000-2010
23#
24#
25# ========================================================================
26#
27# script copy processing output from one site to the other
28#
29# FIXME: solve problem how to know which files have to be copied for which
30# step (alias/function for file-definitions?)
31
32if [ "$SOURCEFILEPATH" = "" ]
33then
34 source `dirname $0`/sourcefile
35else
36 source $SOURCEFILEPATH/sourcefile
37fi
38printprocesslog "INFO starting $0"
39program="corsika"
40
41function copyandcheckfile()
42{
43 # do rsync of file
44 command="rsync -aR -u "$extension"/"$1" "$remotemachine":"$todir
45 printprocesslog "DEBUG executing: "$command
46 if ! $command
47 then
48 printprocesslog "ERROR could not rsync file "$1
49 continue
50 fi
51 # get local checksum
52 if ! checksum1=`md5sum $fromdir/$1`
53 then
54 printprocesslog "ERROR could not get md5sum file "$1
55 continue
56 else
57 checksum1=`echo $checksum1 | awk ' { print \$1 } '`
58 fi
59 # get remote checksum
60 if ! checksum2=`ssh $remotemachine " md5sum $todir/$extension/$1 " `
61 then
62 printprocesslog "ERROR could not get remote md5sum file "$1" from "$remotemachine
63 continue
64 else
65 checksum2=`echo $checksum2 | awk ' { print \$1 } '`
66 fi
67 # compare checksums
68 if ! [ "$checksum1" = "$checksum2" ]
69 then
70 printprocesslog "ERROR local and remote md5sum for file "$1" do not match"
71 continue
72 fi
73}
74
75for step in ${tocopy[@]}
76do
77 printprocesslog "INFO copying output of step "$step
78 getstepinfo
79
80 # get primaries for which output has to be copied
81 query="SELECT "${prims[@]}" FROM "$step"Status WHERE NOT ISNULL(fStartTime) AND NOT ISNULL(fStopTime) AND ISNULL(fAvailable) AND ISNULL(fReturnCode) AND fProcessingSiteKEY="$sitekey
82 primstocopy=( `sendquery` )
83 num=`expr ${#primstocopy[@]} / ${#prims[@]} `
84 if [ ${#primstocopy[@]} -eq 0 ]
85 then
86 printprocesslog "INFO no files to copy for step "$step
87 continue
88 fi
89 # BE CAREFUL:
90 # this only works for corsika so far
91 for (( s=0 ; s < $num ; s++ ))
92 do
93 runnum=${primstocopy[$s+$s]}
94 filenum=${primstocopy[$s+$s+1]}
95 printprocesslog "INFO copying corsika files for run "$runnum" file "$filenum
96 extension=`printf %08d $runnum | cut -c 1-4`/`printf %08d $runnum | cut -c 5-8`
97 cd $mcpath/$program
98 fromdir=$mcpath/$program/$extension
99 todir=$remotedir"/simulated/"$program
100 # copy files and check md5sums
101 corsikafile=cer000`printf %06d $filenum | cut -c 4-6`
102 copyandcheckfile $corsikafile
103 corsikalogfile=cer000`printf %06d $filenum | cut -c 4-6`".log"
104 copyandcheckfile $corsikalogfile
105
106 # in case all copying succeeded and the checksums are ok
107 # continue and update the DB
108 query="UPDATE "$step"Status SET fAvailable=Now() WHERE fFileNumber="$filenum" AND fRunNumber="$runnum
109 sendquery >/dev/null
110 done
111done
112
Note: See TracBrowser for help on using the repository browser.