ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/cbrown/AnalysisFramework/DistributedModelCalculations/CBAFviaCRAB/SendCrabJob.sh
Revision: 1.1
Committed: Thu Jan 19 13:55:39 2012 UTC (13 years, 3 months ago) by buchmann
Content type: application/x-sh
Branch: MAIN
Log Message:
First commit of script to submit crab jobs, monitor them, and produce plots; this is still in active development so if in doubt use the .py one or help out :-)

File Contents

# User Rev Content
1 buchmann 1.1 #!/bin/bash
2    
3     function usage {
4     echo "You can use this script to send crab jobs for scans. You can either run it directly and answer the two questions, or you can answer them directly using -n NAME -j NJOBS"
5     exit 1
6     }
7    
8     function clean_file {
9     echo "Cleaning: $1"
10     if [ -e $1 ]; then
11     rm $1
12     fi
13     }
14    
15     function clean {
16     clean_file "Crab_Jobs/runthis.sh"
17     clean_file "Crab_Jobs/runthis.sh"
18     clean_file "Crab_Jobs/crabconfig.cfg"
19     clean_file "Crab_Jobs/Modules.tar"
20     clean_file "Crab_Jobs/AddFiles.tar"
21     clean_file "Crab_Jobs/dummy.py"
22     }
23    
24     function produce_all_plots {
25     directory=$1
26     cp ../Limits/PlotScanResults.exec .
27     ./PlotScanResults.exec $directory
28     rm ../Limits/PlotScanResults.exec
29     rm LOGerr.txt
30     rm Tex.txt
31     rm LOG.txt
32     echo "All plots have been generated. That's all, now have a look at the results :-)"
33     }
34    
35     function mail_all_plots {
36     tar -cvf Plots.tar $1
37     echo "About to send all plots"
38     ####### DO NOT UPLOAD THE SCRIPT IN THIS LOCATION OR MARCO WILL GET *VERY,VERY,VERY MAD* AT YOU
39     /shome/buchmann/material/send_mail_with_attachment.sh $1 Plots.tar
40     rm Plots.tar
41     }
42    
43     name=""
44     njobs=1234567890
45     while getopts "j:n:h" OPTION
46     do
47     case $OPTION in
48     j)
49     njobs=$OPTARG
50     echo "Have received option for number of jobs. njobs=$njobs set".
51     ;;
52     n)
53     name=$OPTARG
54     echo "Have received option for name. name=$name set".
55     ;;
56     h)
57     usage
58     exit
59     ;;
60     esac
61     done
62    
63     while [ $njobs -lt 1 ] || [ $njobs -gt 5000 ];
64     do
65     njobs=0
66     echo "Question 1: How many jobs would you like to split this into? (0<njobs<5000), (-j) njobs="
67     read njobs
68     done
69     echo "Accepted number of jobs: $njobs"
70    
71     if [[ "$name" == "" ]]; then
72     echo ""
73     else
74     if [ -d "Crab_Jobs/$name" ]; then
75     echo "The directory identifier you provided ($name) is taken. Please try again."
76     name=""
77     else
78     echo "The directory identifier you provided ($name) is ok."
79     fi
80     fi
81    
82     if [[ "$name" == "" ]]; then
83     echo "Question 2: Name for this job? [no spaces!] (-n) name="
84     read name
85     fi
86    
87     if [ -d "Crab_Jobs/$name" ]; then
88     echo "The directory identifier you provided ($name) is also taken. Please start again."
89     exit -1
90     fi
91    
92    
93     echo "Accepted job name : $name"
94    
95     echo "We have now established the number of jobs (${njobs}) as well as the jobs name (${name}) which will serve as working directory"
96     mkdir -p Crab_Jobs
97    
98     eval "cat templates/runthis.sh | sed 's/TOTNJOBS/${njobs}/' > Crab_Jobs/runthis.sh"
99     eval "cat templates/crabconfig.cfg | sed 's/NJOBS/${njobs}/' | sed 's/WORKINGDIR/${name}/' > Crab_Jobs/crabconfig.cfg"
100    
101     echo "Have generated the run script (runthis.sh) as well as the crab configuration file (crabconfig.cfg); will now attempt to create the crab job"
102    
103     cp templates/dummy.py Crab_Jobs/
104     cp templates/Fake_Makefile Makefile
105    
106     tar -cvf Crab_Jobs/Modules.tar ../../Plotting/Modules/ >/dev/null 2>/dev/null
107     tar -cvf Crab_Jobs/AddFiles.tar ../Limits/TimedLimitCapsule.C >/dev/null 2>/dev/null
108     tar -rvf Crab_Jobs/AddFiles.tar ../LimitsFromSystematics/WorkerScript.C >/dev/null 2>/dev/null
109     tar -rvf Crab_Jobs/AddFiles.tar ../last_configuration.C >/dev/null 2>/dev/null
110     tar -rvf Crab_Jobs/AddFiles.tar ../Systematics/SystematicsWorkerScript.C >/dev/null 2>/dev/null
111     tar -rvf Crab_Jobs/AddFiles.tar Makefile >/dev/null 2>/dev/null
112    
113     bash utils/get_latest_root_version.sh
114     rootfilename=`ls | grep root | grep gcc`
115     echo "Attaching root file $rootfilename to tarball ..."
116     tar -rvf Crab_Jobs/AddFiles.tar $rootfilename >/dev/null 2>/dev/null
117    
118     cd Crab_Jobs && crab -create -cfg crabconfig.cfg
119     cd ../
120     rm Makefile
121    
122     if [[ -e Crab_Jobs/$name ]]; then
123     echo "Crab seems to have run correctly. Will now clean up a bit."
124     rm Crab_Jobs/AddFiles.tar
125     rm Crab_Jobs/Modules.tar
126     rm Crab_Jobs/dummy.py
127     if [[ -f Crab_Jobs/dummy.pyc ]]; then
128     rm Crab_Jobs/dummy.pyc
129     fi
130     rm Crab_Jobs/crabconfig.cfg
131     rm Crab_Jobs/runthis.sh
132     else
133     echo "There seems to have been a problem while trying to generate the crab job (can't find any Crab_Jobs/$name directory); please verify that the crab environment is correctly set up. If you would like to create the crab job manually (and monitor it yourself), you can still do: \n \n cd Crab_Jobs && crab -c crabconfig.cfg -create -submit"
134     exit -1
135     fi
136    
137     echo "Would you like to submit the jobs manually (e.g. for testing) [me] or would you like this script to submit the jobs and monitor them [anything else]?"
138     read answer
139     if [[ "$answer" == "me" ]]; then
140     echo "Command you might need:"
141     echo "cd Crab_Jobs && crab -c ${name} -submit"
142     echo "You're on your own now. Goodbye!"
143     exit 0
144     fi
145    
146     echo "You chose to have this handled automatically. Please sit back, submitting jobs now!"
147     cd Crab_Jobs && crab -c ${name} -submit && cd ..
148     echo "Ok, everything has been submitted. Now let's check on the status ... (this will take a long time)"
149     ### THIS SCRIPT REMAINS ON THE T3!!! DO NOT UPLOAD IT!
150     /shome/buchmann/material/check_status_plus_LIST.sh -r `pwd`/Crab_Jobs/${name}
151    
152     echo "Now going to fuse everything related to this job: ${name}"
153     python utils/fusejobs.py -d ${name}
154     rm -r Plots/
155     source /swshare/ROOT/thisroot.sh
156     produce_all_plots "/scratch/`whoami`/bussolaresults/${name}.root"
157     rm -r Plots_${name}/
158     mv Plots/ Plots_${name}/
159     mail_all_plots Plots_${name}
160     echo "Done. Your results are in Plots_${name}/ :-)"