2 #------------------------------------------------------------------
4 # Purpose: A general purpose larsoft batch submit script.
8 # submit_lar.sh [options]
12 # -c, --config <arg> - Configuration (fcl) file (required).
13 # -s, --source <arg> - Input file (full path).
14 # -S, --source-list <arg> - Input file list (full path, one per line).
15 # -o, --output <arg> - Output file name.
16 # -n, --nevts <arg> - Number of events to process.
17 # --nskip <arg> - Number of events to skip.
18 # --nfile <arg> - Number of files to process (use with option -S).
19 # --nfile_skip <arg> - Number of files to skip (use with option -S).
20 # --args <args...> - Arguments for lar command line (place at end).
24 # -r, --release <arg> - Release tag (default "development").
25 # -q, -b, --build <arg> - Release build qualifier (default "debug", or "prof").
26 # --localdir <arg> - Larsoft local test release directory (default none).
27 # --localtar <arg> - Tarball of local test release.
28 # --mrb - Use mrb-style environment initialization (see below).
29 # --srt - Use srt-style environment initialization (see below).
33 # -N, --numjobs - Number of jobs to submit (default 1).
34 # --opportunistic - Use opportunistic grid.
35 # --OS <arg> - Specify OS (comma-separated list with no spaces, e.g. SL5,SL6).
39 # --ubfcl <arg> - Ubfcl version (default none).
43 # -h, --help - Print help.
44 # --group <arg> - Group or experiment (default $GROUP).
45 # --workdir <arg> - Work directory (default current directory).
46 # --outdir <arg> - Output directory.
47 # --cluster <arg> - Job cluster.
48 # --process <arg> - Process within cluster.
49 # --procmap <arg> - Name of process map file (override $PROCESS).
50 # --init-script <arg> - User initialization script execute.
51 # --init-source <arg> - User initialization script to source (bash).
52 # --end-script <arg> - User end-of-job script to execute.
56 # MRB vs. SRT environment setup.
58 # Environmental setup inside the worker batch script is controlled by
59 # options --release (-r), --build (-b, -q), --localdir, and --localtar. These options are
60 # interpreted differently depending on whether one is using an MRB (--mrb)
61 # or SRT (--srt) environment. Options --srt and --mrb are mutually
62 # exclusive. If neither is specified, --mrb is the default.
64 # For SRT-style environment:
66 # a) Use option --release or -r to specify larsoft frozen release.
67 # b) Use option --build, -b, or -q to specify build type ("debug" or "prof")
68 # c) If you have a local test release, specify the (bluearc) location of
69 # the test release using --localdir, or use --localtar to specify the
70 # absolute or relative path of the local release tarball.
72 # For MRB-style environment:
74 # a) Use option --release or -r to specify uboonecode version. Note that
75 # larsoft is setup as a dependent product of uboonecode.
76 # b) Use option --build or -b to specify build full qualifiers (e.g.
77 # "debug:e4" or "e4:prof").
78 # c) Options --localdir and --localtar are used in a similar way as for
79 # SRT. Here, --localdir should point to, or your tarball should be
80 # made relative to, the mrb localProducts directory ($MRB_INSTALL).
81 # If your local test release includes uboonecode, then you do not
82 # need options --release or --build.
86 # 1. Each batch worker is uniquely identified by two numbers stored
87 # in environment variables $CLUSTER and $PROCESS (the latter is
88 # a small integer that starts from zero and varies for different
89 # jobs in a parallel job group). These environment variables are
90 # normally set by the batch system, but can be overridden by options
91 # --cluster and --process (e.g. to rerun failed jobs).
93 # It is not allowed to specify multiple jobs (-N option with >1 job)
94 # and to specify --process at the same time.
96 # 2. The work directory must be set to an existing directory owned
97 # by the submitter and readable by the batch worker. Files from the
98 # work directory are copied to the batch worker scratch directory at
99 # the start of the job.
101 # 3. The job configuration file (-c option), initialization and end-of-job
102 # scripts (optins --init-script, --init-source, --end-script) may
103 # be stored in the work directory specified by option --workdir, or they
104 # may be specified as absolute paths.
106 # 4. The output directory must exist and be writable by the batch
107 # worker (i.e. be group-writable for grid jobs). The worker
108 # makes a new subdirectory called ${CLUSTER}_${PROCESS} in the output
109 # directory and copies all files in the batch scratch directory there
110 # at the end of the job. If the output directory is not specified, the
111 # default is /grid/data/<group>/outstage/<user> (user is defined as
112 # owner of work directory).
114 # 5. The number of jobs option (-N or --numjobs) is used in two ways.
115 # It is passed to jobsub to generate the requested number of batch jobs,
116 # and it is passed to condor_lar.sh (as option --njobs) to control how
117 # condor_lar.sh delivers files and events to individual workers.
119 # Created: H. Greenlee, 29-Aug-2012
121 #------------------------------------------------------------------
154 while [ $# -gt 0 ]; do
159 awk '/^# Usage:/,/^# End options/{print $0}' $0 | cut -c3- | head -n -2
165 if [ $# -gt 1 ]; then
173 if [ $# -gt 1 ]; then
181 if [ $# -gt 1 ]; then
189 if [ $# -gt 1 ]; then
197 if [ $# -gt 1 ]; then
203 # Number of events to skip.
205 if [ $# -gt 1 ]; then
211 # Number of files to process.
213 if [ $# -gt 1 ]; then
219 # Number of files to skip.
221 if [ $# -gt 1 ]; then
227 # General arguments for lar command line.
229 if [ $# -gt 1 ]; then
238 if [ $# -gt 1 ]; then
244 # Release build qualifier.
246 if [ $# -gt 1 ]; then
252 # Local test release directory.
254 if [ $# -gt 1 ]; then
260 # Local test release tarball.
262 if [ $# -gt 1 ]; then
280 if [ $# -gt 1 ]; then
286 # Number of batch jobs.
288 if [ $# -gt 1 ]; then
294 # Opportunistic grid flag.
301 if [ $# -gt 1 ]; then
309 if [ $# -gt 1 ]; then
317 if [ $# -gt 1 ]; then
325 if [ $# -gt 1 ]; then
333 if [ $# -gt 1 ]; then
339 # Process within cluster.
341 if [ $# -gt 1 ]; then
349 if [ $# -gt 1 ]; then
355 # User initialization script.
357 if [ $# -gt 1 ]; then
363 # User source initialization script.
365 if [ $# -gt 1 ]; then
371 # User end-of-job script.
373 if [ $# -gt 1 ]; then
381 echo "Unknown option $1"
387 # Do MRB/SRT checks, and set some environment-specific defaults.
389 # Make sure at lease one of MRB and SRT is specified.
390 # If neither is specified, set MRB by default.
392 if [ $MRB -eq 0 -a $SRT -eq 0 ]; then
396 # Make sure both MRB and SRT are not set.
398 if [ $MRB -ne 0 -a $SRT -ne 0 ]; then
399 echo "Both --mrb and --srt were specified."
403 # Set defaults for MRB.
405 if [ $MRB -ne 0 ]; then
406 if [ x$QUAL = x ]; then
411 # Set defaults for SRT.
413 if [ $SRT -ne 0 ]; then
414 if [ x$REL = x ]; then
417 if [ x$QUAL = x ]; then
423 #echo "INFILE=$INFILE"
424 #echo "INLIST=$INLIST"
425 #echo "OUTFILE=$OUTFILE"
429 #echo "NFILE_SKIP=$NFILE_SKIP"
433 #echo "LOCALDIR=$LOCALDIR"
434 #echo "LOCALTAR=$LOCALTAR"
438 #echo "NUMJOBS=$NUMJOBS"
439 #echo "OPPORTUNISTIC=$OPPORTUNISTIC"
441 #echo "WORKDIR=$WORKDIR"
442 #echo "OUTDIR=$OUTDIR"
445 #echo "PROCMAP=$PROCMAP"
446 #echo "INITSCRIPT=$INITSCRIPT"
447 #echo "INITSOURCE=$INITSOURCE"
448 #echo "ENDSCRIPT=$ENDSCRIPT"
450 # Done with arguments.
452 # Make sure all required options have been specified.
454 if [ x$GROUP = x ]; then
455 echo "Group not specified."
458 if [ x$OUTDIR = x ]; then
459 echo "Output directory not specified."
462 if [ x$WORKDIR = x ]; then
463 echo "Work directory not specified."
466 if [ x$FCL = x ]; then
467 echo "Configuration file not specified."
471 # Construct options for jobsub
474 if [ x$GRP != x ]; then
475 JOBSUB_OPTS="$JOBSUB_OPTS --group=$GRP"
477 if [ $NUMJOBS -gt 1 ]; then
478 JOBSUB_OPTS="$JOBSUB_OPTS -N $NUMJOBS"
480 JOBSUB_OPTS="$JOBSUB_OPTS --grid"
481 if [ $OPPORTUNISTIC -ne 0 ]; then
482 JOBSUB_OPTS="$JOBSUB_OPTS --opportunistic"
484 if [ x$OS != x ]; then
485 JOBSUB_OPTS="$JOBSUB_OPTS --OS=$OS"
488 # Construct condor_lar.sh options.
491 if [ x$FCL != x ]; then
492 BATCH_OPTS="$BATCH_OPTS -c $FCL"
494 if [ x$INFILE != x ]; then
495 BATCH_OPTS="$BATCH_OPTS -s $INFILE"
497 if [ x$INLIST != x ]; then
498 BATCH_OPTS="$BATCH_OPTS -S $INLIST"
500 if [ x$OUTFILE != x ]; then
501 BATCH_OPTS="$BATCH_OPTS -o $OUTFILE"
503 if [ $NEVT -gt 0 ]; then
504 BATCH_OPTS="$BATCH_OPTS -n $NEVT"
506 if [ $NSKIP -gt 0 ]; then
507 BATCH_OPTS="$BATCH_OPTS --nskip $NSKIP"
509 if [ $NFILE -gt 0 ]; then
510 BATCH_OPTS="$BATCH_OPTS --nfile $NFILE"
512 if [ $NFILE_SKIP -gt 0 ]; then
513 BATCH_OPTS="$BATCH_OPTS --nfile_skip $NFILE_SKIP"
515 if [ $NUMJOBS -gt 1 ]; then
516 BATCH_OPTS="$BATCH_OPTS --njobs $NUMJOBS"
518 if [ x$REL != x ]; then
519 BATCH_OPTS="$BATCH_OPTS -r $REL"
521 if [ x$QUAL != x ]; then
522 BATCH_OPTS="$BATCH_OPTS -q $QUAL"
524 if [ x$LOCALDIR != x ]; then
525 BATCH_OPTS="$BATCH_OPTS --localdir $LOCALDIR"
527 if [ x$LOCALTAR != x ]; then
528 BATCH_OPTS="$BATCH_OPTS --localtar $LOCALTAR"
530 if [ $MRB -ne 0 ]; then
531 BATCH_OPTS="$BATCH_OPTS --mrb"
533 if [ $SRT -ne 0 ]; then
534 BATCH_OPTS="$BATCH_OPTS --srt"
536 if [ x$UBFCL != x ]; then
537 BATCH_OPTS="$BATCH_OPTS --ubfcl $UBFCL"
539 if [ x$GRP != x ]; then
540 BATCH_OPTS="$BATCH_OPTS --group $GRP"
542 if [ x$WORKDIR != x ]; then
543 BATCH_OPTS="$BATCH_OPTS --workdir $WORKDIR"
545 if [ x$OUTDIR != x ]; then
546 BATCH_OPTS="$BATCH_OPTS --outdir $OUTDIR"
548 if [ x$CLUS != x ]; then
549 BATCH_OPTS="$BATCH_OPTS --cluster $CLUS"
551 if [ x$PROC != x ]; then
552 BATCH_OPTS="$BATCH_OPTS --process $PROC"
554 if [ x$PROCMAP != x ]; then
555 BATCH_OPTS="$BATCH_OPTS --procmap $PROCMAP"
557 if [ x$INITSCRIPT != x ]; then
558 BATCH_OPTS="$BATCH_OPTS --init-script $INITSCRIPT"
560 if [ x$INITSOURCE != x ]; then
561 BATCH_OPTS="$BATCH_OPTS --init-source $INITSOURCE"
563 if [ x$ENDSCRIPT != x ]; then
564 BATCH_OPTS="$BATCH_OPTS --end-script $ENDSCRIPT"
567 if [ -n "$ARGS" ]; then
568 BATCH_OPTS="$BATCH_OPTS $ARGS"
571 # Make a fresh copy of batch worker script in work directory and go there.
573 cp `which condor_lar.sh` $WORKDIR
578 CMD="jobsub $JOBSUB_OPTS condor_lar.sh $BATCH_OPTS"