ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/OSUT3Analysis/DBTools/scripts/crabclean
(Generate patch)

Comparing UserCode/OSUT3Analysis/DBTools/scripts/crabclean (file contents):
Revision 1.2 by ahart, Fri Oct 19 16:41:12 2012 UTC vs.
Revision 1.6 by ahart, Fri May 10 00:24:02 2013 UTC

# Line 2 | Line 2
2  
3   use strict;
4   use Getopt::Long;
5 + use Mysql;
6  
7   sub printHelp;
8   sub parseCrabDir;
9  
10 + our $db = Mysql->connect ("cmshead.mps.ohio-state.edu", "ntuple", "osuT3User") or die "Failed to connect to Tier 3, stopped";
11 +
12   my %opt;
13   Getopt::Long::Configure ("bundling");
14 < GetOptions (\%opt, "dumb|d", "force|f", "help|h");
14 > GetOptions (\%opt, "dumb|d", "force|f", "dataset|s", "help|h");
15  
16 < printHelp () if $opt{"help"} || !$ARGV[0] || (!$opt{"dumb"} && !$ARGV[1]);
16 > printHelp () if $opt{"help"} || !$ARGV[0] || (!$opt{"dumb"} && !$opt{"dataset"} && !$ARGV[1]);
17   my $crabDir = $ARGV[0];
18   my $outputDir = $ARGV[0];
19 < $outputDir = $ARGV[1] if !$opt{"dumb"};
19 > my $dataset = $ARGV[0];
20 > $outputDir = $ARGV[1] if !$opt{"dumb"} && !$opt{"dataset"};
21 >
22 > if ($opt{"dataset"})
23 >  {
24 >    my $queryDataset = $dataset;
25 >    $queryDataset =~ s/\*/%/g;
26 >    $queryDataset =~ s/(.*)/%$1%/g;
27 >    my $query = "select workingDirectory,location,dataset,user,creationTime from ntuple where dataset like '$queryDataset' order by creationTime";
28 >    $db->selectdb ("ntuple");
29 >    my $results = $db->query ($query);
30 >    if ($results->numrows () == 1)
31 >      {
32 >        my @row = $results->fetchrow ();
33 >        $crabDir = "$row[0]/ntuple";
34 >        $outputDir = $row[1];
35 >      }
36 >    if ($results->numrows () == 0)
37 >      {
38 >        print "Database entry does not exist.\n";
39 >        exit;
40 >      }
41 >    if ($results->numrows () > 1)
42 >      {
43 >        my %workingDir;
44 >        my %location;
45 >        print "Found multiple database entries matching\n";
46 >        print "\"$dataset\":\n";
47 >        for (my $i = 1; $i <= $results->numrows (); $i++)
48 >          {
49 >            my @row = $results->fetchrow ();
50 >            $workingDir{"$i"} = $row[0];
51 >            $location{"$i"} = $row[1];
52 >            printf "(%2d) $row[2]\n", $i;
53 >            print "     created by $row[3] on $row[4]\n";
54 >          }
55 >        print "\nWhich entry would you like to use?: ";
56 >        my $response = <STDIN>;
57 >        $response =~ s/[ \t\n]//g;
58 >        if (!(exists $workingDir{$response}))
59 >          {
60 >            print "Your selection \"$response\" was not a valid option! Quitting.\n";
61 >            exit;
62 >          }
63 >        $crabDir = "$workingDir{$response}/ntuple";
64 >        $outputDir = $location{$response};
65 >      }
66 >  }
67 >
68   if (!(-e $outputDir) || !(-d $outputDir))
69    {
70      print "Output directory $outputDir does not exist!\n";
# Line 76 | Line 127 | printHelp
127    $exeName =~ s/^.*\/([^\/]*)$/$1/;
128  
129    print "Usage: $exeName [OPTION]... CRAB_DIR OUTPUT_DIR\n";
130 +  print "  or: $exeName -d [OPTION]... OUTPUT_DIR\n";
131 +  print "  or: $exeName -s [OPTION]... DATASET\n";
132    print "Deletes excess EDM output caused by multiple CRAB submissions using the results\n";
133    print "contained in the CRAB working directory provided.\n";
134    print "\n";
# Line 86 | Line 139 | printHelp
139    printf "%-29s%s\n", "  -f, --force", "never prompt (default is to prompt before any";
140    printf "%-29s%s\n", "             ", "removal)";
141    printf "%-29s%s\n", "  -h, --help", "print this help message";
142 +  printf "%-29s%s\n", "  -s, --dataset", "tells the script to expect a dataset name instead";
143 +  printf "%-29s%s\n", "               ", "of a directory";
144  
145    exit;
146   }
# Line 107 | Line 162 | parseCrabDir
162        my @status = `grep 'ExitStatus' $crabDir/res/$file`;
163        my $wrapperStatus = $status[0];
164        $wrapperStatus =~ s/^.*ExitStatus="([^"]*)".*$/$1/;
165 +      $wrapperStatus =~ s/\n//g;
166        if ($wrapperStatus != 0)
167          {
168            print "Job $jobNumber failed (return value $wrapperStatus). Skipping.\n";

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines