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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
|
#!/usr/bin/env perl
# R. Mankel, DESY Hamburg 06-Jul-2007
# A. Parenti, DESY Hamburg 27-Mar-2008
# $Revision: 1.8 $
# $Date: 2011/06/15 14:51:45 $
#
# Prepare the run script for the merge job.
# The main action is to embed the output directory
# into the script
#
# Usage:
#
# mps_scriptm.pl [-c] inScript outScript runDir cfgName njobs mssDir \
# [CastorPool]
#
BEGIN {
use File::Basename;
unshift(@INC, dirname($0)."/mpslib");
}
use Mpslib;
use POSIX;
$inScript = "undefined";
$outScript = "undefined";
$runDir = "undefined";
$cfgName = "undefined";
$nJobs = "undefined";
$mssDirLocal = "undefined"; # not to confuse with mssDir from 'mpslib'.
$castorPool = "undefined";
# parse the arguments
while (@ARGV) {
$arg = shift(@ARGV);
if ($arg =~ /\A-/) { # check for option
if ($arg =~ "h") {
$helpwanted = 1;
}
elsif ($arg =~ "c") {
# Check which jobs are "OK" and write just them to the cfg file
$checkok = 1;
}
elsif ($arg =~ "d") {
$localdir = 1;
}
elsif ($arg =~ "u") {
$updateDb = 1;
}
$optionstring = "$optionstring$arg";
}
else { # parameters not related to options
$i = $i + 1;
if ($i eq 1) {
$inScript = $arg;
}
elsif ($i eq 2) {
$outScript = $arg;
}
elsif ($i eq 3) {
$runDir = $arg;
}
elsif ($i eq 4) {
$cfgName = $arg;
}
elsif ($i eq 5) {
$nJobs = $arg;
}
elsif ($i eq 6) {
$mssDirLocal = $arg;
}
elsif ($i eq 7) {
$castorPool = $arg;
}
}
}
if ($cfgName eq "undefined") {
print "Insufficient information given\n";
exit 1;
}
if ($checkok == 1) {
read_db();
}
# open the input file
open INFILE,"$inScript";
undef $/; # undefining the INPUT-RECORD_SEPARATOR means slurp whole file
$body = <INFILE>; # read whole file
close INFILE;
$/ = "\n"; # back to normal
# replace RUNDIR setting
$nn = ($body =~ m/RUNDIR=(.+)$/m);
if ($nn != 1) {
print "mps_script.pl: no (unambiguous) RUNDIR directive found in runscript\n";
exit 1;
}
$nn = ($body =~ s/RUNDIR=(.+)$/RUNDIR=$runDir/m);
# replace the cfg name
$nn = ($body =~ s/CONFIG_FILE=(.*)$/CONFIG_FILE=\$RUNDIR\/$cfgName/m);
if ($nn <1) {
print "Warning: mps_script matches cfg: $nn\n";
}
#replace CMSSW_RELEASE_AREA with evironment variable
$body =~ s/cd\s+CMSSW_RELEASE_AREA/cd $ENV{'CMSSW_BASE'}/g;
# replace MSSDIR setting
$nn = ($body =~ m/MSSDIR=(.+)$/m);
if ($nn != 1) {
print "mps_script.pl: no (unambiguous) MSSDIR directive found in runscript\n";
}
$nn = ($body =~ s/MSSDIR=(.+)$/MSSDIR=$mssDirLocal/m);
if ($castorPool ne "undefined") {
# replace MSSDIRPOOL setting...
$nn = ($body =~ s/MSSDIRPOOL=(.*)$/MSSDIRPOOL=$castorPool/m);
} else {
#... or empty the field.
$nn = ($body =~ s/MSSDIRPOOL=(.*)$/MSSDIRPOOL=/m);
}
# now we have to expand lines that contain the ISN directive
@LINES = split "\n",$body;
foreach $theLine (@LINES) {
if ($theLine =~ m/ISN/) {
$newBlock = "";
for ($i = 1; $i <= $nJobs; ++$i) {
if ($checkok==1 && @JOBSTATUS[$i-1] ne "OK") {next;}
$newLine = $theLine;
$isnRep = sprintf "%03d",$i;
$newLine =~ s/ISN/$isnRep/g;
if ($i != 1) { $newBlock = $newBlock . "\n"; }
$newBlock = $newBlock . $newLine;
}
$theLine = $newBlock;
}
}
$body = join "\n",@LINES;
# store the output file
open OUTFILE,">$outScript";
print OUTFILE $body;
close OUTFILE;
system "chmod a+x $outScript";
|