submit_t2k_nd280_mc_jobs.pl
Go to the documentation of this file.
1 #-------------------------------------------------------------------------------------------------
2 # Submit GENIE/nd280 event generation job using the full geometry and a JNUBEAM ntuple-based flux
3 # description.
4 #
5 # Syntax:
6 # shell$ perl submit_t2k_nd280_mc_jobs.pl <options>
7 #
8 # Options:
9 # --version : GENIE version
10 # --flux-run : Input flux run number
11 # [--flux-version] : JNUBEAM flux version, <07a, 10a, 10b, 10c, ...>, default: 10c
12 # [--flux-config] : JNUBEAM config, <nominal, flat36mm, yshift2mm,...>, default: nominal
13 # [--flux-file-prefix] : JNUBEAM flux file prefix, default: nu.nd.
14 # [--flux-file-suffix] : JNUBEAM flux file suffix, default: .root
15 # [--arch] : <SL4.x86_32, SL5.x86_64, SL6.x86_64, ...>, default: SL6.x86_64
16 # [--production] : default: <version>
17 # [--cycle] : default: 01
18 # [--use-valgrind] : default: off
19 # [--batch-system] : <PBS, LSF>, default: PBS
20 # [--queue] : default: prod
21 # [--softw-topdir] : top level dir for softw installations, default: /opt/ppd/t2k/softw/GENIE
22 # [--jobs-topdir] : top level dir for job files, default: /opt/ppd/t2k/scratch/GENIE/
23 #
24 # Example:
25 # shell$ perl submit_t2k_nd280_mc_jobs.pl --flux-run 180 --version v2.4.0 --production mdc0 --cycle 01
26 #
27 # Tested at the RAL/PPD Tier2 PBS batch farm.
28 #
29 # Costas Andreopoulos <constantinos.andreopoulos \at cern.ch>
30 # STFC, Rutherford Appleton Lab
31 #-------------------------------------------------------------------------------------------------
32 
33 #!/usr/bin/perl
34 
35 use File::Path;
36 
37 # inputs
38 #
39 $iarg=0;
40 foreach (@ARGV) {
41  if($_ eq '--version') { $genie_version = $ARGV[$iarg+1]; }
42  if($_ eq '--flux-run') { $flux_run = $ARGV[$iarg+1]; }
43  if($_ eq '--flux-version') { $flux_version = $ARGV[$iarg+1]; }
44  if($_ eq '--flux-config') { $flux_config = $ARGV[$iarg+1]; }
45  if($_ eq '--flux-file-prefix') { $flux_file_prefix = $ARGV[$iarg+1]; }
46  if($_ eq '--flux-file-suffix') { $flux_file_suffix = $ARGV[$iarg+1]; }
47  if($_ eq '--arch') { $arch = $ARGV[$iarg+1]; }
48  if($_ eq '--production') { $production = $ARGV[$iarg+1]; }
49  if($_ eq '--cycle') { $cycle = $ARGV[$iarg+1]; }
50  if($_ eq '--use-valgrind') { $use_valgrind = $ARGV[$iarg+1]; }
51  if($_ eq '--batch-system') { $batch_system = $ARGV[$iarg+1]; }
52  if($_ eq '--queue') { $queue = $ARGV[$iarg+1]; }
53  if($_ eq '--softw-topdir') { $softw_topdir = $ARGV[$iarg+1]; }
54  if($_ eq '--jobs-topdir') { $jobs_topdir = $ARGV[$iarg+1]; }
55  $iarg++;
56 }
57 die("** Aborting [Undefined flux file run #. Use the --flux-run option]")
58 unless defined $flux_run;
59 die("** Aborting [Undefined GENIE version. Use the --version option]")
60 unless defined $genie_version;
61 
62 $use_valgrind = 0 unless defined $use_valgrind;
63 $arch = "SL6.x86_64" unless defined $arch;
64 $production = "$genie_version" unless defined $production;
65 $cycle = "01" unless defined $cycle;
66 $batch_system = "PBS" unless defined $batch_system;
67 $queue = "prod" unless defined $queue;
68 $softw_topdir = "/opt/ppd/t2k/softw/GENIE" unless defined $softw_topdir;
69 $flux_version = "10c" unless defined $flux_version;
70 $flux_config = "nominal" unless defined $flux_config;
71 $flux_file_prefix = "nu.nd." unless defined $flux_file_prefix;
72 $flux_file_suffix = ".root" unless defined $flux_file_suffix;
73 $jobs_topdir = "/opt/ppd/t2k/scratch/GENIE/" unless defined $jobs_topdir;
74 $job_pot = "1E+18";
75 $mcrun_base = 10000000;
76 $mcseed_base = 210921029;
77 $time_limit = "30:00:00";
78 $genie_setup = "$softw_topdir/generator/builds/$arch/$genie_version-setup";
79 $inputs_dir = "$softw_topdir/data/job_inputs";
80 $job_dir = "$jobs_topdir/nd280mc-$production\_$cycle";
81 $flux_dir = "$inputs_dir/t2k_flux/$flux_version/nd/$flux_config";
82 $flux_file = "$flux_dir/$flux_file_prefix$flux_run$flux_file_suffix";
83 $flux_det_loc = "nd5";
84 $geom_file = "$inputs_dir/t2k_geom/ND280.root";
85 $xspl_file = "$inputs_dir/xspl/gxspl-t2k-$genie_version.xml";
86 $geom_dunits = "clhep_def_density_unit";
87 $geom_lunits = "mm";
88 $file_prefix = "genie_nd280";
89 $mcrun = $mcrun_base + $flux_run;
90 $mcseed = $mcseed_base + $flux_run;
91 
92 die("** Aborting [Can not find GENIE setup script: ....... $genie_setup]")
93 unless -e $genie_setup;
94 die("** Aborting [Can not find flux file: ................ $flux_file]")
95 unless -e $flux_file;
96 die("** Aborting [Can not find geometry file: ............ $geom_file]")
97 unless -e $geom_file;
98 die("** Aborting [Can not find cross sections file: ...... $xspl_file]")
99 unless -e $xspl_file;
100 
101 print "@@@ Will submit job with MC run number = $mcrun (seed number = $mcseed)\n";
102 
103 # make the jobs directory
104 #
105 mkpath ($job_dir, {verbose => 1, mode=>0777});
106 die("$job_dir doesn't exist") unless -d $job_dir;
107 
108 # form event generation and file conversion commands
109 #
110 $fntemplate = "$job_dir/nd280job-$mcrun";
111 $ghep_file = "$file_prefix.$production\_$cycle.$mcrun.ghep.root";
112 $grep_pipe = "grep -B 50 -A 30 -i \"warn\\|error\\|fatal\" ";
113 $valgrind_cmd = "valgrind --tool=memcheck --error-limit=no --leak-check=yes --show-reachable=yes";
114 $evgen_opt = "-g $geom_file -f $flux_file,$flux_det_loc -r $mcrun --seed $mcseed -L $geom_lunits -D $geom_dunits -E $job_pot --cross-sections $xspl_file";
115 $evgen_cmd = "gevgen_t2k $evgen_opt | $grep_pipe &> $fntemplate.evgen.log";
116 $frenm_cmd = "mv gntp.$mcrun.ghep.root $ghep_file";
117 $fconv_cmd = "gntpc -f t2k_rootracker -i $ghep_file --seed $mcseed | $grep_pipe &> $fntemplate.conv.log";
118 
119 print "@@@ exec: $evgen_cmd \n";
120 
121 #
122 # submit
123 #
124 
125 # PBS case
126 if($batch_system eq 'PBS') {
127  $batch_script = "$fntemplate.pbs";
128  open(PBS, ">$batch_script") or die("Can not create the PBS batch script");
129  print PBS "#!/bin/bash \n";
130  print PBS "#PBS -N $mcrun\_nd280-$production-$cycle \n";
131  print PBS "#PBS -l cput=$time_limit \n";
132  print PBS "#PBS -o $fntemplate.pbsout.log \n";
133  print PBS "#PBS -e $fntemplate.pbserr.log \n";
134  print PBS "source $genie_setup \n";
135  print PBS "cd $job_dir \n";
136  print PBS "$evgen_cmd \n";
137  print PBS "$frenm_cmd \n";
138  print PBS "$fconv_cmd \n";
139  close(PBS);
140  `qsub -q $queue $batch_script`;
141 }
142 
143 # LSF case
144 if($batch_system eq 'LSF') {
145  $batch_script = "$fntemplate.sh";
146  open(LSF, ">$batch_script") or die("Can not create the LSF batch script");
147  print LSF "#!/bin/bash \n";
148  print LSF "#BSUB-j $mcrun\_nd280-$production-$cycle \n";
149  print LSF "#BSUB-q $queue \n";
150  print LSF "#BSUB-c $time_limit \n";
151  print LSF "#BSUB-o $fntemplate.lsfout.log \n";
152  print LSF "#BSUB-e $fntemplate.lsferr.log \n";
153  print LSF "source $genie_setup \n";
154  print LSF "cd $job_dir \n";
155  print LSF "$evgen_cmd \n";
156  print LSF "$frenm_cmd \n";
157  print LSF "$fconv_cmd \n";
158  close(LSF);
159  `bsub < $batch_script`;
160 }
161