forked from CMSROMA/Utilities
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmakeArguments.sh
executable file
·95 lines (69 loc) · 2.17 KB
/
makeArguments.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/bin/bash
usage(){
echo "`basename $0` -f filelist -u ui_working_dir [-n file_per_job | --nJobs] "
echo " -f, --filelist: can specify many time, one for each filelist "
}
#------------------------------ parsing
# options may be followed by one colon to indicate they have a required argument
if ! options=$(getopt -u -o hf:n:u: -l help,filelist:,file_per_job:,nJobs:,ui_working_dir:,parentFilelist: -- "$@")
then
# something went wrong, getopt will put out an error message for us
usage
exit 1
fi
set -- $options
while [ $# -gt 0 ]
do
case $1 in
-h|--help) usage; exit 0;;
-f|--filelist) FILELIST="$FILELIST $2"; shift ;;
-p|--parentFilelist) PARENTFILELIST="$PARENTFILELIST $2"; shift;;
-n|--file_per_job) FILE_PER_JOB=$2; shift ;;
--nJobs) NJOBS=$2; shift;;
-u|--ui_working_dir) UI_WORKING_DIR=$2 ; shift;;
(--) shift; break;;
(-*) echo "$0: error - unrecognized option $1" 1>&2; usage >> /dev/stderr; exit 1;;
(*) break;;
esac
shift
done
#------------------------------ checking
if [ -z "$FILELIST" ];then
echo "[ERROR] FILELIST not defined" >> /dev/stderr
usage >> /dev/stderr
exit 1
fi
if [ -z "$UI_WORKING_DIR" ];then
echo "[ERROR] UI_WORKING_DIR not defined" >> /dev/stderr
usage >> /dev/stderr
exit 1
fi
tmpFilelist=filelist/filelist.list
cat $FILELIST > $tmpFilelist
if [ -n "$NJOBS" ];then
nFiles=`cat $FILELIST | wc -l`
let FILE_PER_JOB=$nFiles/$NJOBS
if [ "`echo \"$nFiles%$NJOBS\" | bc`" != "0" ];then
let FILE_PER_JOB=$FILE_PER_JOB+1
fi
fi
# if FILE_PER_JOB is not specified uses makechain.sh default: 10
makechain.sh $tmpFilelist $FILE_PER_JOB
#============================== Writing the argumets file
cat > $UI_WORKING_DIR/share/arguments.xml <<EOF
<arguments>
EOF
for file in filelist/`basename $tmpFilelist .list`/*.list
do
job=`basename $file .list | sed 's|.*-\([0-9]*\)|\1|'`
# echo $job
files="`cat $file | sed 's|$|,|'`"
cat >> $UI_WORKING_DIR/share/arguments.xml <<EOF
<Job MaxEvents="-1" JobID="$job" InputFiles="$files">
</Job>
EOF
sed -i 's|,">|">|' $UI_WORKING_DIR/share/arguments.xml
done
cat >> $UI_WORKING_DIR/share/arguments.xml <<EOF
</arguments>
EOF