forked from UMN-CMS/WR-lite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcondor_filelist_Billy.perl
executable file
·295 lines (261 loc) · 9.21 KB
/
condor_filelist_Billy.perl
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
#!/usr/bin/perl
use Getopt::Long;
#------------------------
#$prodSpace=$ENV{"HOME"}."/work";
$prodSpace="/data/cmszfs1/user/".$ENV{"USER"};
$batch=10;
$startPoint=0;
$nosubmit='';
$use_xrootd=''; # '' is false in perl
#$executable=$ENV{"HOME"}."/bin/batch_cmsRun";
$executable=$ENV{"HOME"}."/batch_cmsRun";
$rt=$ENV{"LOCALRT"};
$arch=$ENV{"SCRAM_ARCH"};
$jobBase="default";
print "$executable\n";
GetOptions(
"batch=i" => \$batch,
"start=i" => \$startPoint,
"nosubmit" => \$nosubmit,
"prodspace=s" => \$prodSpace,
"jobname=s" => \$jobBase,
"xrootd" => \$use_xrootd,
"nice" => \$nice_user
);
print @ARGV;
print "\n";
print @ARGV[0];
print "\n";
print @ARGV[1];
print "\n";
print @ARGV[2];
print "\n";
print "$#ARGV\n";
$nargs = $#ARGV;
print "$nargs\n";
if ($#ARGV!=2 && $#ARGV!=6) {
print "Usage: [BASE CONFIG] [NAME OF FILE CONTAINING LIST OF FILENAMES] [isMC=True/False] [runRandomTrack=True/False] [runLocally=True/False] [isSig=True/False] [hasDpho=True/False]\n\n";
print " --batch (number of files per jobs) (default $batch)\n";
print " --start (output file number for first job) (default $startPoint)\n";
print " --jobname (name of the job) (default based on base config)\n";
print " --prodSpace (production space) (default $prodSpace)\n";
print " --nosubmit (don't actually submit, just make files)\n";
print " --xrootd (use xrootd for file access)\n";
print " --nice (set nice_user=true)\n";
exit(1);
}
$basecfg=shift @ARGV;
$filelist=shift @ARGV;
$cmsRunArguments=shift @ARGV;
#$cmsRunArguments2nd=shift @ARGV;
if($nargs==6) {
$cmsRunArguments4th=shift @ARGV;
$cmsRunArguments5th=shift @ARGV;
print "cmsRun Arguments: $cmsRunArguments, $cmsRunArguments2nd, $cmsRunArguments3rd, $cmsRunArguments4th, and $cmsRunArguments5th\n";
}
# if($nargs==3) {
# print "cmsRun Arguments: $cmsRunArguments and $cmsRunArguments2nd\n";
# }
if($nargs==2){
print "cmsRun Arguments: $cmsRunArguments"
}
if ($jobBase eq "default") {
my $stub3=$basecfg;
$stub3=~s|.*/||g;
$stub3=~s|_cfg.py||;
$stub3=~s|[.]py||;
$jobBase=$stub3;
}
if (length($rt)<2) {
print "You must run \"cmsenv\" in the right release area\n";
print "before running this script!\n";
exit(1);
}
if ($use_xrootd) {
# Try to find the user's proxy file
open(VOMSY,"voms-proxy-info|");
while (<VOMSY>) {
if (/path\s+:\s+(\S+)/) {
$voms_proxy=$1;
}
}
close(VOMSY);
}
#------------------------
print "Setting up a job based on $basecfg into $jobBase using $filelist\n";
if ($nosubmit) {
print " Will not actually submit this job\n";
}
$cfg=$basecfg;
system("mkdir -p $prodSpace/$jobBase");
system("mkdir -p $prodSpace/logs");
mkdir("$prodSpace/$jobBase/cfg");
mkdir("$prodSpace/$jobBase/log");
$linearn=0;
srand(); # make sure rand is ready to go
if ($nosubmit) {
open(SUBMIT,">condor_submit.txt");
} else {
open(SUBMIT,"|condor_submit");
}
print(SUBMIT "Executable = $executable\n");
#if($nargs==3) {
if($nargs==2) {
print(SUBMIT "Arguments = \"$cmsRunArguments\"\n");
}
if($nargs==6) {
print(SUBMIT "Arguments = \"$cmsRunArguments $cmsRunArguments2nd $cmsRunArguments3rd $cmsRunArguments4th $cmsRunArguments5th\"\n");
}
print(SUBMIT "Universe = vanilla\n");
print(SUBMIT "Output = $prodSpace/logs/output\n");
print(SUBMIT "Error = $prodSpace/logs/error\n");
print(SUBMIT "request_memory = 1024\n");
print(SUBMIT "Requirements = (Arch==\"X86_64\")");
# Zebras are for remote login, not cluster computing
print(SUBMIT " && (Machine != \"zebra01.spa.umn.edu\" && Machine != \"zebra02.spa.umn.edu\" && Machine != \"zebra03.spa.umn.edu\" && Machine != \"zebra04.spa.umn.edu\" && Machine != \"caffeine.spa.umn.edu\")");
#print(SUBMIT " && (Machine != \"scorpion13.spa.umn.edu\")");
print(SUBMIT " && (Machine != \"scorpion45.spa.umn.edu\")");
print(SUBMIT " && (Machine != \"scorpion46.spa.umn.edu\")");
#print(SUBMIT " && (Machine != \"scorpion24.spa.umn.edu\" && Machine != \"scorpion20.spa.umn.edu\" && Machine != \"scorpion44.spa.umn.edu\")");
#print(SUBMIT " && (Machine != \"scorpion42.spa.umn.edu\" && Machine != \"scorpion43.spa.umn.edu\" && Machine != \"scorpion45.spa.umn.edu\" && Machine != \"scorpion46.spa.umn.edu\" && Machine != \"scorpion5.spa.umn.edu\")");
### Scorpions that don't have cmsRun ###
print(SUBMIT " && (Machine != \"scorpion1.spa.umn.edu\")");
print(SUBMIT " && (Machine != \"scorpion17.spa.umn.edu\")");
#### Scorpions that don't have cmsset_default ###
print(SUBMIT " && (Machine != \"scorpion16.spa.umn.edu\")");
print(SUBMIT " && (Machine != \"scorpion18.spa.umn.edu\")");
print(SUBMIT " && (Machine != \"scorpion6.spa.umn.edu\")");
# These machines are VMs that run the grid interface
print(SUBMIT " && (Machine != \"gc1-ce.spa.umn.edu\" && Machine != \"gc1-hn.spa.umn.edu\" && Machine != \"gc1-se.spa.umn.edu\" && Machine != \"red.spa.umn.edu\" && Machine != \"hadoop-test.spa.umn.edu\")");
print(SUBMIT "\n");
print(SUBMIT "+CondorGroup=\"cmsfarm\"\n");
if ($use_xrootd) {
# If the proxy file exists and is a normal file, we use it
if (-f $voms_proxy) {
print("Found voms proxy: $voms_proxy\n");
print(SUBMIT "should_transfer_files = YES\n");
print(SUBMIT "transfer_input_files = $voms_proxy\n");
print(SUBMIT "X509UserProxy = $voms_proxy\n");
}
# Invalid file
else {
print("No voms proxy found! Please run `voms-proxy-init` and confirm that the file exists at /tmp/x509*\n");
exit(1);
}
}
if ($nice_user) {
print(SUBMIT "nice_user = True\n");
}
open(FLIST,$filelist);
while (<FLIST>) {
chomp;
push @flist,$_;
}
close(FLIST);
$i=0;
$ii=$startPoint-1;
while ($i<=$#flist) {
$ii++;
@jobf=();
for ($j=0; $j<$batch && $i<=$#flist; $j++) {
push @jobf,$flist[$i];
$i++;
}
$jobCfg=specializeCfg($cfg,$ii,@jobf);
$stub=$jobCfg;
$stub=~s|.*/([^/]+)_cfg.py$|$1|;
$log="$prodSpace/$jobBase/log/$stub.log";
$elog="$prodSpace/$jobBase/log/$stub.err";
$sleep=(($ii*2) % 60)+2; # Never sleep more than a ~minute, but always sleep at least 2
if($nargs==2) {
print(SUBMIT "Arguments = $arch $rt $prodSpace/$jobBase $jobCfg $log $elog $fname $sleep $jobf[0] $cmsRunArguments\n");
}
if($nargs==6) {
print(SUBMIT "Arguments = $arch $rt $prodSpace/$jobBase $jobCfg $log $elog $fname $sleep $jobf[0] $cmsRunArguments $cmsRunArguments2nd $cmsRunArguments3rd $cmsRunArguments4th $cmsRunArguments5th\n");
}
print(SUBMIT "Queue\n");
}
close(SUBMIT);
sub specializeCfg($$@) {
my ($inp, $index, @files)=@_;
$stub2=$jobBase;
$stub2.=sprintf("_%03d",$index);
$mycfg="$prodSpace/$jobBase/cfg/".$stub2."_cfg.py";
print " $inp $index --> $stub2 ($mycfg) \n";
#print "$inp $text\n";
open(INP,$inp);
open(OUTP,">$mycfg");
$sector=0;
$had2=0;
$had3=0;
while(<INP>) {
if (/TFileService/) {
$sector=2;
$had2=1;
}
if (/PoolOutputModule/) {
$sector=3;
$had3=1;
}
if (/[.]Source/) {
$sector=1;
}
if (/rivetAnalyzer[.]OutputFile/) {
$sector=4;
}
# TFile Service Block
if ($sector==2 && /^[^\#]*fileName\s*=/) {
if ($had3==1) {
$fname="$prodSpace/$jobBase/".$stub2."-hist.root";
} else {
$fname="$prodSpace/$jobBase/".$stub2.".root";
}
unlink($fname);
print OUTP " fileName = cms.string(\"$fname\"),\n";
# PoolOutputModule Block
} elsif ($sector==3 && /^[^\#]*fileName\s*=/) {
if ($had2==1) {
$fname="$prodSpace/$jobBase/".$stub2."-pool.root";
} else {
$fname="$prodSpace/$jobBase/".$stub2.".root";
}
unlink($fname);
print OUTP " fileName = cms.untracked.string(\"$fname\"),\n";
# *Source Block (PoolSource, etc.)
} elsif ($sector==4 && /^[^\#]*rivetAnalyzer[.]OutputFile\s*=/) {
$fname="$prodSpace/$jobBase/".$stub2.".yoda";
unlink($fname);
print OUTP "process.rivetAnalyzer.OutputFile = cms.string(\"$fname\")\n";
# PoolOutputModule Block
} elsif ($sector==1 && /^[^\#]*fileNames\s*=/) {
print OUTP " fileNames=cms.untracked.vstring(\n";
for ($qq=0; $qq<=$#files; $qq++) {
$storefile=$files[$qq];
if ($storefile=~/store/) {
if ($use_xrootd) {
$storefile=~s|.*/store|root://cmsxrootd.fnal.gov//store|;
} else {
$storefile=~s|.*/store|/store|;
}
} else {
$storefile="file:".$storefile;
}
print OUTP " '".$storefile."'";
print OUTP "," if ($qq!=$#files);
print OUTP "\n";
}
print OUTP " )\n";
} else {
print OUTP;
}
$depth++ if (/\{/ && $sector!=0);
if (/\}/ && $sector!=0) {
$depth--;
$sector=0 if ($depth==0);
}
# printf("%d %d %s",$sector,$depth,$_);
}
close(OUTP);
close(INP);
return $mycfg;
}