SubmitCommand.pl
Go to the documentation of this file.
1 #!/usr/bin/perl
2 # M. Toups
3 # 12/1/14
4 #
5 # Short script to submit optical library generation with
6 # project.py.
7 #
8 use strict;
9 use warnings;
10 use File::Basename qw(fileparse);
11 use Cwd qw(abs_path);
12 
13 my ($xml, $fcl, $workdir, $check, $merge) = @ARGV;
14 
15 if(!(defined($xml) || defined($fcl) || defined($workdir))) {
16  print "Usage: perl SubmitCommand.pl <project.py xml file> <fcl file> <work dir> [<checkana?>] [<merge?>]\n";
17  exit(1);
18 }
19 
20 if(!(-e "${workdir}/buildopticallibrary")) {
21  mkdir "${workdir}/buildopticallibrary", 0775;
22 }
23 
24 if(!(-e "${workdir}/buildopticallibrary/xml")) {
25  mkdir "${workdir}/buildopticallibrary/xml", 0775;
26 }
27 
28 if(!(-e "${workdir}/buildopticallibrary)/fcl")) {
29  mkdir "${workdir}/buildopticallibrary/fcl", 0775;
30 }
31 
32 my $NPhotonsPerVoxel = 30000;
33 my $NVoxelsPerJob = 240;
34 my $NJobs = 9375;
35 my $StartJob = 0;
36 
37 for(my $i=$StartJob; $i<$StartJob+$NJobs; $i++) {
38 
39  my ($fcl_filename, $fcl_directories, $fcl_suffix) = fileparse($fcl,".fcl");
40  my ($xml_filename, $xml_directories, $xml_suffix) = fileparse($xml,".xml");
41 
42  if(!(-e "${workdir}/buildopticallibrary/fcl/${fcl_filename}_${i}${fcl_suffix}")) {
43 
44  open IN, "${fcl}" or die $!;
45  open OUT, ">${workdir}/buildopticallibrary/fcl/${fcl_filename}_${i}${fcl_suffix}" or die $!;
46 
47  while(<IN>) {
48  if(/physics.producers.generator.FirstVoxel/) {
49  print OUT "physics.producers.generator.FirstVoxel: " . $NVoxelsPerJob*$i . "\n";
50  }
51  elsif(/physics.producers.generator.LastVoxel/) {
52  print OUT "physics.producers.generator.LastVoxel: " . ($NVoxelsPerJob*($i+1)-1) . "\n";
53  }
54  elsif(/physics.producers.generator.N/) {
55  print OUT "physics.producers.generator.N: ${NPhotonsPerVoxel}\n";
56  }
57  else {
58  print OUT "$_";
59  }
60  }
61  close IN or die $!;
62  close OUT or die $!;
63  }
64 
65  if(!(-e ">${workdir}/buildopticallibrary/xml/${xml_filename}_${i}${xml_suffix}")) {
66 
67  open IN, "${xml}" or die $!;
68  open OUT, ">${workdir}/buildopticallibrary/xml/${xml_filename}_${i}${xml_suffix}" or die $!;
69 
70  while(<IN>) {
71  if(/ENTITY name/) {
72  print OUT '<!ENTITY name "gen_photon_ball_' . $i . '">' . "\n";
73  }
74  elsif(/<fcl>(.*)<\/fcl>/) {
75  print OUT " <fcl>" . abs_path(${workdir}) . "\/buildopticallibrary\/fcl\/${fcl_filename}_${i}${fcl_suffix}<\/fcl>\n";
76  }
77  else {
78  print OUT "$_";
79  }
80  }
81 
82  close IN or die $!;
83  close OUT or die $!;
84  }
85 
86  if(!defined($check)) {
87  if(!defined($merge)) {
88  system qq|project.py --xml ${workdir}/buildopticallibrary/xml/${xml_filename}_${i}${xml_suffix} --submit|;
89  sleep 1;
90  } else {
91  system qq|project.py --xml ${workdir}/buildopticallibrary/xml/${xml_filename}_${i}${xml_suffix} --merge|;
92  }
93  } else {
94  system qq|project.py --xml ${workdir}/buildopticallibrary/xml/${xml_filename}_${i}${xml_suffix} --checkana|;
95  }
96 
97 }
98 
99