]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TPC/macros/testTPC/agent.sh
Adding protection - in case of several agents try to write to the same directory
[u/mrichter/AliRoot.git] / TPC / macros / testTPC / agent.sh
1 #!/usr/local/bin/bash
2 #aguments
3 #1 working directory
4
5
6 # Example usage:
7 # $ALICE_ROOT/TPC/macros/testTPC/agent.sh /afs/cern.ch/user/m/miranov/public/test2008/reckr191xx
8
9 # Or submit as many agents you want on batch machines:
10 # bsub -q 1nd $ALICE_ROOT/TPC/macros/testTPC/agent.sh /afs/cern.ch/user/m/miranov/public/test2008/reckr191xx
11
12 #
13 #  AGENT to run some action:
14 #  3 components to be present
15 #
16
17 #  0. CREATE ACTION LIST ( see $ALICE_ROOT/TPC/macros/testTPC/AlienToolkit.cxx)
18 #
19
20 #  1. WORKING DIRECTORY SETUP (in prev. example /afs/cern.ch/user/m/miranov/public/test2008/reckr191xx)
21 #    1.a  action.list
22 #    1.b  empty out directory
23 #    1.c  macros directory -with  <action>.C  - e.g rec.C  FindKrClustersRaw.C
24
25
26 # 2. ENVIRONMENT SETUP:
27 #
28 # 2.a  Copy the script  to setup aliroot root to the  ~/.bagentsetup
29 # 2.b  Export envirnment variables needed OCDB_PATH, AGENTINPUTTYPE, AGENTSE in the .bagentsetup script
30 # 2.c  Get a valid token: alien-token-init
31 # 2.d  Copy certificates to default place -  ~/.agentauth/
32 #      cp /tmp/*$UID* ~/.agentauth/
33
34
35
36 #
37 #setup environment
38 #
39 #ALIEN -get token
40 echo xxxxxxxxxxxxxxxxxxxxxxxxx
41 echo xxxxxxxxxxxxxxxxxxxxxxxxx
42 echo xxxxxxxxxxxxxxxxxxxxxxxxx
43 echo ENVIRONMENT
44 echo ALIEN       - $ALIEN
45 echo GSHELL_ROOT - $GSHELL_ROOT
46 echo HOME        - $HOME
47 echo ALIROOT   =`which aliroot` 
48 echo    ROOT   =`which root` 
49 echo xxxxxxxxxxxxxxxxxxxxxxxxx
50 echo xxxxxxxxxxxxxxxxxxxxxxxxx
51 echo xxxxxxxxxxxxxxxxxxxxxxxxx
52 cp ~/.agentauth/*   /tmp/
53 source /tmp/gclient_env_$UID
54 export  PATH=.:${GSHELL_ROOT}/bin:${PATH}.
55
56 #aliensh -c ps
57 #ALIROOT
58 # test if ~/.bagentsetup exists
59 if [ ! -f ~/.bagentsetup ]; then
60   echo "ERROR: '~/.bagentsetup' init script not found\!"
61   exit 1
62 fi
63
64 source ~/.bagentsetup
65 echo xxxxxxxxxxxxxxxxxxxxxxxxx
66 echo ENVIRONMENT
67 echo ALIROOT   =`which aliroot` 
68 echo    ROOT   =`which root` 
69 echo xxxxxxxxxxxxxxxxxxxxxxxxx
70
71
72 #chek env
73 if [ "x$AGENTINPUTTYPE" == "x" ]; then
74   echo "WARNING: environment variable 'AGENTINPUTTYPE' falling back to default (castor)\!\!"
75   export     AGENTINPUTTYPE=2
76 fi
77 if [ "x$OCDB_PATH" == "x" ]; then
78   echo "WARNING: environment variable 'OCDB_PATH' falling back to default (local:///afs/cern.ch/alice/tpctest/OCDB)\!\!"
79   export     OCDB_PATH=local:///afs/cern.ch/alice/tpctest/OCDB
80 fi
81 if [ "x$AGENTSE" == "x" ]; then
82   echo "WARNUNG: environment variable 'AGENTSE' falling back to default (ALICE::CERN::SE)\!\!"
83   export     AGENTSE=ALICE::CERN::SE
84 fi
85
86 #
87 #
88 echo OPERATING SYSTEM
89 uname -a
90 #export workdir
91 export jobhome=`pwd`
92
93 #cd to workdir and check for 'macros' and 'out' dir
94 cd $1
95 if [ ! -d macros ]; then
96   echo "ERROR: no 'macros' dir in '$1'. Does it exist?"
97   exit 1
98 fi
99 if [ ! -d out ]; then
100   echo "ERROR: no 'out' dir in '$1'. Does it exist?"
101   exit 1
102 fi
103
104 # check if we are able to write to this dir, the alien SE, can readback from the alien SE and delete stuff
105 touch agend_alien_tst$HOSTNAME.txt || exit 1
106 date >> agend_alien_tst$HOSTNAME.txt
107 #copy to alien
108 alien_cp -dn agend_alien_tst$HOSTNAME.txt alien:${alien_HOME}agend_alien_tst$HOSTNAME.txt@$AGENTSE
109
110 #see if it is there
111 res=`alien_ls ${alien_HOME}agend_alien_tst$HOSTNAME.txt | grep agend_alien_tst`
112 if [ "x$res" == "x" ]; then
113   echo "ERROR: could not write on storage element '$AGENTSE'"
114   exit 1
115 fi
116
117 #copy back
118 alien_cp -n alien:${alien_HOME}agend_alien_tst$HOSTNAME.txt agend_alien_tst_back.txt 
119 res=`diff agend_alien_tst$HOSTNAME.txt agend_alien_tst_back.txt`
120 if [ "x$res" != "x" ]; then
121   echo "ERROR: problems reading from storage element '$AGENTSE'"
122   exit 1
123 fi
124
125 #try to delete from alien
126 res=`alien_rm -d ${alien_HOME}agend_alien_tst$HOSTNAME.txt`
127 if [ "x$res" != "x" ]; then
128   echo "ERROR: cannot delete from storage element '$AGENTSE'"
129   exit 1
130 fi
131
132 #try to delete local files
133 res=`rm agend_alien_tst*`
134 if [ "x$res" != "x" ]; then
135   echo "ERROR: cannot delete local files"
136   exit 1
137 fi
138
139 echo Current Dir
140 pwd
141
142 aliroot -b -q $ALICE_ROOT/TPC/macros/testTPC/AliTPCjobs.cxx+
143
144 #alien_cp -d job.list alien:${alien_HOME}job.list@$AGENTSE
145