ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitHzz4l/scripts/select_lsf.sh
Revision: 1.3
Committed: Thu Nov 8 15:52:05 2012 UTC (12 years, 6 months ago) by anlevin
Content type: application/x-sh
Branch: MAIN
CVS Tags: compiled, HEAD
Changes since 1.2: +0 -0 lines
Log Message:
added back run_lsf and select_lsf scripts

File Contents

# Content
1 conf=$1
2 action=$2
3
4 if echo "$@" | grep ' \-\-pipe' ; then pipe=pipe; else pipe=; fi
5 if echo "$@" | grep ' \-\-delete' ; then delete=delete; else delete=no; fi
6 if echo "$@" | grep ' \-\-lsf' ; then lsf=lsf; else lsf=; fi
7
8 if hostname | grep 'cern\.ch' &> /dev/null; then
9 catalogDir=/home/mitprod/catalog
10 skimDirBase=/data/blue/dkralph/ntuple-prod
11 else
12 catalogDir=/home/cmsprod/catalog
13 skimDirBase=/mnt/hadoop/cmsprod/skim
14 fi
15
16 limit_procs() {
17 nprocs=`ps auxw|grep $1 | wc -l`
18 while (( $nprocs > 19 )); do echo -n "."; sleep 1; nprocs=`ps auxw|grep $1 | wc -l`; done
19 }
20
21 if ! [ "$action" == "select" ] && ! [ "$action" == "merge" ] && ! [ "$action" == "check" ]; then
22 echo -e "\nERROR: bad action parameter"
23 return
24 fi
25 if [ -f badfiles.txt ]; then rm -v badfiles.txt; fi
26
27 label=`grep '^\^label' $conf | awk '{print $2}'`; if ! [ $label ]; then echo "no label in config file!"; return; fi
28 exe=`grep '^\^exe' $conf | awk '{print $2}'`; if ! [ $exe ]; then echo "no exe in config file!"; return; fi
29 ntupdir=`grep '^\^ntupdir' $conf | awk '{print $2}'`; if ! [ $ntupdir ]; then echo "no ntupdir in config file!"; return; fi
30
31 base_args= #`echo $@ | sed -n 's/[^ ][^ ]*//1p' | sed -n 's/[^ ][^ ]*//1p'`
32 # optional args:
33 base_args="$base_args --mH 120"
34 debug=`grep '^\^debug' $conf | awk '{print $2}'`; if [ $debug ]; then base_args="$base_args --debug"; fi
35 efftype=`grep '^\^efftype' $conf | awk '{print $2}'`; if [ $efftype ]; then base_args="$base_args --efftype $efftype"; fi
36 fakeScheme=`grep '^\^fakeScheme' $conf | awk '{print $2}'`; if [ $fakeScheme ]; then base_args="$base_args --fakeScheme $fakeScheme"; fi
37 faketype=`grep '^\^faketype' $conf | awk '{print $2}'`; if [ $faketype ]; then base_args="$base_args --faketype $faketype"; fi
38 mcfmfname=`grep '^\^mcfmfname' $conf | awk '{print $2}'`; if [ $mcfmfname ]; then base_args="$base_args --mcfmfname $mcfmfname"; fi
39 doFSR=`grep '^\^doFSR' $conf | awk '{print $2}'`; if [ $doFSR ]; then base_args="$base_args --doFSR"; fi
40 doJets=`grep '^\^doJets' $conf | awk '{print $2}'`; if [ $doJets ]; then base_args="$base_args --doJets"; fi
41 do_escale=`grep '^\^do_escale' $conf | awk '{print $2}'`; if [ $do_escale ]; then base_args="$base_args --do_escale --smearing_scaling_dataset 2012Jul13ReReco"; fi
42 do_eregression=`grep '^\^do_eregression' $conf | awk '{print $2}'`; if [ $do_eregression ]; then base_args="$base_args --do_eregression"; fi
43 correct_muon_momentum=`grep '^\^correct_muon_momentum' $conf | awk '{print $2}'`; if [ $correct_muon_momentum ]; then base_args="$base_args --correct_muon_momentum"; fi
44 n_events_to_process=`grep '^\^n_events_to_process' $conf | awk '{print $2}'`; if [ $n_events_to_process ]; then base_args="$base_args --n_events_to_process $n_events_to_process"; fi
45 # check optional args
46 if ! [ -s $jsonFile ]; then echo "bad JSON: $jsonFile"; return; fi
47
48 echo -e "=====================\n${action}'ing jobs with: $label\n\tbase_args: $base_args\n=============================\n"
49
50 while read -u 7 line; do
51 if echo $line | grep '^\^\|^#\|^\$' &>/dev/null; then continue; fi
52 args=$base_args
53 dset=`echo $line | awk '{print $1}'`
54 outdir=$ntupdir/$label/$dset;
55 book=`echo $line | awk '{print $4}'`
56 if hostname | grep 'mit\.edu\|t3btch' &>/dev/null && echo $book | grep 'cern' &> /dev/null; then continue; fi
57 if hostname | grep 'cern\.ch' &>/dev/null && echo $book | grep 't2mit\|local' &> /dev/null; then continue; fi
58 catalog=$catalogDir/$book
59 skimmed=`echo $line | awk '{print $5}'`
60 if ! [ "$skimmed" == "skimmed" ] && ! [ "$skimmed" == "unskimmed" ]; then echo "bad skim parameter"; return; fi
61 era=`echo $line | awk '{print $6}'`
62 if [ "$era" != "2011" ] && [ "$era" != "2012" ]; then echo "bad era: $era"; return; fi
63 args="$args --era $era"
64 if [ "`echo $line | awk '{print $2}'`" == "0" ]; then
65 args="$args --mc"
66 else
67 json=`echo $line | awk '{print $7}'`
68 if [ $json ]; then
69 args="$args --jsonFile $json";
70 fi
71 fi
72
73 # skimmed or unskimmed?
74 if [ "$skimmed" == "unskimmed" ]; then
75 outdir=$outdir/unskimmed
76 rm /tmp/Files;
77 rm /tmp/Filesets;
78 scp anlevin@dtmit08.cern.ch:$catalog/$dset/Files /tmp/Files;
79 scp anlevin@dtmit08.cern.ch:$catalog/$dset/Filesets /tmp/Filesets
80 if ! [ -f /tmp/Files ]; then echo -e "\nERROR: catalog not found in $catalog/$dset"; return; fi
81 if ! [ -f /tmp/Filesets ]; then echo -e "\nERROR: catalog not found in $catalog/$dset"; return; fi
82 unskimmed_dir=`head -n1 /tmp/Filesets | awk '{print $2}'`
83 inputfilelist=`sed "s@[^ ][^ ]* \([^ ][^ ]*\.root\) @$unskimmed_dir/\1@" /tmp/Files | awk '{print $1}'`
84 echo "inputfilelist = "
85 echo $inputfilelist
86 elif [ "$skimmed" == "skimmed" ]; then
87 skimdir=$skimDirBase/`grep '^\^skim' $conf | awk '{print $2}'`/$book/$dset
88 if ! [ -d $skimdir ]; then
89 if hostname | grep 'mit\.edu\|t3btch' &>/dev/null; then
90 skimdir=/mnt/hadoop/dkralph/ntuple-prod/`grep '^\^skim' $conf | awk '{print $2}'`/$book/$dset
91 else
92 echo "skimdir $skimdir not found!"
93 return
94 fi
95 fi
96 inputfilelist=`ls $skimdir/*$dset*.root`
97 fi
98
99 mkdir -p $outdir
100
101 # run merge
102 if [ "$action" == "merge" ]; then
103 . ./scripts/merge.sh $outdir $dset
104 continue
105 fi
106
107 # clean old files from output dir
108 if [ "$delete" == "delete" ] && [ "$action" == "select" ]; then
109 if ls $outdir/*$dset*.root &> /dev/null || ls $outdir/*$dset*.nevents &> /dev/null; then
110 echo " --------> removing: $outdir/*$dset*{.root,.nevents}"
111 rm $outdir/*$dset*{.root,.nevents}
112 fi
113 fi
114
115 # run jobs
116 echo -e "$dset:\t\t\t\t\t\t\t`echo $inputfilelist | wc -w` files\n\t$args\n"
117 njobs=1
118 for inputfile in $inputfilelist; do
119 outfile=$outdir/`basename $inputfile`
120
121 echo "inputfile = " $inputfile
122
123 if [ -s $outfile ]; then
124 if [ "$action" == "check" ]; then
125 printf "." #"%4dok" $njobs
126 fi
127 (( njobs += 1))
128 continue # if we're selecting and file's already there, don't overwrite it
129 else
130 if [ "$action" == "check" ]; then
131 echo -e "\nERROR: missing $outfile " #\n(from: $inputfile)"
132 (( njobs += 1))
133 continue
134 fi
135
136 printf "%4d" $njobs
137
138 if [ "$lsf" == "lsf" ]; then
139 logFile=`echo $outfile | sed 's/\.root/\.out/'`
140 echo $logFile;
141 bsub -q 8nh -o $logFile /afs/cern.ch/user/a/anlevin/cms/cmssw/CMSSW_5_3_2_patch3/src/MitHzz4l/scripts/run_lsf.sh $exe --inputfile $inputfile --output $outfile $args
142 else
143 if hostname | grep 'cern\.ch' &>/dev/null; then
144 logFile=`echo $outfile | sed 's@/dkralph/@/dkralph/logs/@' | sed 's/\.root/\.txt/'`
145 else
146 logFile=`echo $outfile | sed 's@/temp/dkralph/@/scratch/dkralph/logs/@' | sed 's/\.root/\.txt/'`
147 fi
148 mkdir -p `dirname $logFile`
149 if [ "$pipe" == "pipe" ]; then
150 $exe --inputfile $inputfile --output $outfile $args &> $logFile &
151 else
152 echo "$exe --inputfile $inputfile --output $outfile $args"
153 $exe --inputfile $inputfile --output $outfile $args
154 echo "return value: $?"
155 fi
156 limit_procs $exe
157 fi
158 # sleep 0.15
159 (( njobs += 1))
160 fi
161 done
162 echo -e "\n"
163 done 7< $conf
164
165 if [ "$action" == "merge" ] && [ -f badfiles.txt ]; then
166 grep 'has no keys\|probably not closed' badfiles.txt | awk '{print $5}' > files-to-delete.txt
167 echo -e "\n\n`wc -l files-to-delete.txt | awk '{print $1}'` bad files written to files-to-delete.txt"
168 grep 'has no keys\|probably not closed' badfiles.txt | awk '{print $5}' | sed 's/\.root/\.nevents/' >> files-to-delete.txt
169 fi