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.3 by ahart, Wed Feb 6 00:33:04 2013 UTC vs.
Revision 1.4 by ahart, Sat Mar 9 11:58:55 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 $query = "select workingDirectory,location,dataset,user,creationTime from ntuple where dataset like '$dataset' order by creationTime";
25 >    $db->selectdb ("ntuple");
26 >    my $results = $db->query ($query);
27 >    if ($results->numrows () == 1)
28 >      {
29 >        my @row = $results->fetchrow ();
30 >        $crabDir = "$row[0]/ntuple";
31 >        $outputDir = $row[1];
32 >      }
33 >    if ($results->numrows () == 0)
34 >      {
35 >        print "Database entry does not exist.\n";
36 >        exit;
37 >      }
38 >    my %workingDir;
39 >    my %location;
40 >    print "Found multiple database entries matching\n";
41 >    print "\"$dataset\":\n";
42 >    for (my $i = 1; $i <= $results->numrows (); $i++)
43 >      {
44 >        my @row = $results->fetchrow ();
45 >        $workingDir{"$i"} = $row[0];
46 >        $location{"$i"} = $row[1];
47 >        printf "(%2d) $row[2]\n", $i;
48 >        print "     created by $row[3] on $row[4]\n";
49 >      }
50 >    print "\nWhich entry would you like to use?: ";
51 >    my $response = <STDIN>;
52 >    $response =~ s/[ \t\n]//g;
53 >    if (!(exists $workingDir{$response}))
54 >      {
55 >        print "Your selection \"$response\" was not a valid option! Quitting.\n";
56 >        exit;
57 >      }
58 >    $crabDir = "$workingDir{$response}/ntuple";
59 >    $outputDir = $location{$response};
60 >  }
61 >
62   if (!(-e $outputDir) || !(-d $outputDir))
63    {
64      print "Output directory $outputDir does not exist!\n";
# Line 77 | Line 122 | printHelp
122  
123    print "Usage: $exeName [OPTION]... CRAB_DIR OUTPUT_DIR\n";
124    print "  or: $exeName -d [OPTION]... OUTPUT_DIR\n";
125 +  print "  or: $exeName -s [OPTION]... DATASET\n";
126    print "Deletes excess EDM output caused by multiple CRAB submissions using the results\n";
127    print "contained in the CRAB working directory provided.\n";
128    print "\n";
# Line 87 | Line 133 | printHelp
133    printf "%-29s%s\n", "  -f, --force", "never prompt (default is to prompt before any";
134    printf "%-29s%s\n", "             ", "removal)";
135    printf "%-29s%s\n", "  -h, --help", "print this help message";
136 +  printf "%-29s%s\n", "  -s, --dataset", "tells the script to expect a dataset name instead";
137 +  printf "%-29s%s\n", "               ", "of a directory";
138  
139    exit;
140   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines