ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/OSUT3Analysis/DBTools/scripts/crabclean
Revision: 1.2
Committed: Fri Oct 19 16:41:12 2012 UTC (12 years, 6 months ago) by ahart
Branch: MAIN
CVS Tags: V00-00-01, V00-00-05
Changes since 1.1: +79 -18 lines
Log Message:
Use the results from CRAB instead of the filenames of the output.

File Contents

# Content
1 #!/usr/bin/env perl
2
3 use strict;
4 use Getopt::Long;
5
6 sub printHelp;
7 sub parseCrabDir;
8
9 my %opt;
10 Getopt::Long::Configure ("bundling");
11 GetOptions (\%opt, "dumb|d", "force|f", "help|h");
12
13 printHelp () if $opt{"help"} || !$ARGV[0] || (!$opt{"dumb"} && !$ARGV[1]);
14 my $crabDir = $ARGV[0];
15 my $outputDir = $ARGV[0];
16 $outputDir = $ARGV[1] if !$opt{"dumb"};
17 if (!(-e $outputDir) || !(-d $outputDir))
18 {
19 print "Output directory $outputDir does not exist!\n";
20 exit;
21 }
22 opendir (CRAB_OUTPUT, "$outputDir");
23 my @crabOutput = readdir (CRAB_OUTPUT);
24 closedir (CRAB_OUTPUT);
25 my %filesToKeep;
26 if (!$opt{"dumb"})
27 {
28 if (!(-e $crabDir) || !(-d $crabDir))
29 {
30 print "CRAB directory $crabDir does not exist!\n";
31 exit;
32 }
33 parseCrabDir ($crabDir, \%filesToKeep);
34 }
35 else
36 {
37 foreach my $file (@crabOutput)
38 {
39 next if ($file eq "." || $file eq "..");
40 next if !($file =~ m/^.*_[^_]*_[^_]*_[^_]*\.root$/);
41 my $jobNumber = $file;
42 my $submissionNumber = $file;
43 $jobNumber =~ s/^.*_([^_]*)_[^_]*_[^_]*\.root$/$1/;
44 $submissionNumber =~ s/^.*_[^_]*_([^_]*)_[^_]*\.root$/$1/;
45 if (!(defined $filesToKeep{$jobNumber})
46 || $filesToKeep{$jobNumber} < $submissionNumber)
47 {
48 $filesToKeep{$jobNumber} = $submissionNumber;
49 }
50 }
51 }
52 foreach my $file (@crabOutput)
53 {
54 next if ($file eq "." || $file eq "..");
55 next if !($file =~ m/^.*_[^_]*_[^_]*_[^_]*\.root$/);
56 my $jobNumber = $file;
57 my $submissionNumber = $file;
58 $jobNumber =~ s/^.*_([^_]*)_[^_]*_[^_]*\.root$/$1/;
59 $submissionNumber =~ s/^.*_[^_]*_([^_]*)_[^_]*\.root$/$1/;
60 if (!(defined $filesToKeep{$jobNumber}))
61 {
62 print "No information found for job $jobNumber!\n";
63 }
64 elsif (($opt{"dumb"} && $filesToKeep{$jobNumber} != $submissionNumber)
65 || (!$opt{"dumb"} && $filesToKeep{$jobNumber} ne $file))
66 {
67 system ("rm -f $outputDir/$file") if $opt{"force"};
68 system ("rm -i $outputDir/$file") if !$opt{"force"};
69 }
70 }
71
72 sub
73 printHelp
74 {
75 my $exeName = $0;
76 $exeName =~ s/^.*\/([^\/]*)$/$1/;
77
78 print "Usage: $exeName [OPTION]... CRAB_DIR OUTPUT_DIR\n";
79 print "Deletes excess EDM output caused by multiple CRAB submissions using the results\n";
80 print "contained in the CRAB working directory provided.\n";
81 print "\n";
82 print "Mandatory arguments to long options are mandatory for short options too.\n";
83 printf "%-29s%s\n", " -d, --dumb", "tries to use the filenames of the output instead of";
84 printf "%-29s%s\n", " ", "the results from the CRAB working directory; useful";
85 printf "%-29s%s\n", " ", "if the working directory has been lost";
86 printf "%-29s%s\n", " -f, --force", "never prompt (default is to prompt before any";
87 printf "%-29s%s\n", " ", "removal)";
88 printf "%-29s%s\n", " -h, --help", "print this help message";
89
90 exit;
91 }
92
93 sub
94 parseCrabDir
95 {
96 my $crabDir = shift;
97 my $filesToKeep = shift;
98
99 opendir (CRAB_RESULTS, "$crabDir/res");
100 my @crabResults = readdir (CRAB_RESULTS);
101 closedir (CRAB_RESULTS);
102 for my $file (@crabResults)
103 {
104 next if !($file =~ m/^crab_fjr_[^\.]*\.xml$/);
105 my $jobNumber = $file;
106 $jobNumber =~ s/^crab_fjr_([^\.]*)\.xml$/$1/;
107 my @status = `grep 'ExitStatus' $crabDir/res/$file`;
108 my $wrapperStatus = $status[0];
109 $wrapperStatus =~ s/^.*ExitStatus="([^"]*)".*$/$1/;
110 if ($wrapperStatus != 0)
111 {
112 print "Job $jobNumber failed (return value $wrapperStatus). Skipping.\n";
113 next;
114 }
115 my @surlForGrid = `grep -A 1 '<SurlForGrid>' $crabDir/res/$file`;
116 my $fileName = $surlForGrid[1];
117 $fileName =~ s/^.*\/([^\/]*)\n/$1/;
118 $filesToKeep->{$jobNumber} = $fileName;
119 }
120 }