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

Comparing UserCode/OSUT3Analysis/DBTools/scripts/osudb (file contents):
Revision 1.10 by ahart, Wed Oct 17 18:28:47 2012 UTC vs.
Revision 1.13 by ahart, Mon Oct 22 13:50:25 2012 UTC

# Line 12 | Line 12 | sub dbDelete;
12   sub dbDeleteOther;
13   sub addSlashes;
14   sub uploadRelease;
15 + sub downloadRelease;
16   sub datasetExists;
17  
18   our $db = Mysql->connect ("cmshead.mps.ohio-state.edu", "ntuple", "osuT3User") or die "Failed to connect to Tier 3, stopped";
19  
20   my %opt;
21   Getopt::Long::Configure ("bundling");
22 < GetOptions (\%opt, "comment|c=s", "format|f=s", "pyConfig|p=s", "crabCfg|b=s", "jsonFile|j=s", "lumiSummary|s=s", "location|l=s", "fileList|t=s", "release|r=s", "other|o", "help|h");
22 > GetOptions (\%opt, "comment|c=s", "format|f=s", "pyConfig|p=s", "crabCfg|b=s", "jsonFile|j=s", "lumiSummary|s=s", "location|l=s", "fileList|t=s", "release|r=s", "other|o", "recipe|e=s", "help|h");
23   my $argc = @ARGV;
24  
25   printHelp ($ARGV[0]) if $opt{"help"};
26   printHelp () if $argc != 2 && $ARGV[0] ne "createOther";
27 < printHelp () if $ARGV[0] ne "create" && $ARGV[0] ne "createOther" && $ARGV[0] ne "update" && $ARGV[0] ne "finish" && $ARGV[0] ne "deprecate" && $ARGV[0] ne "uploadRelease" && $ARGV[0] ne "deleteEntry";
27 > printHelp () if $ARGV[0] ne "create" && $ARGV[0] ne "createOther" && $ARGV[0] ne "update" && $ARGV[0] ne "finish" && $ARGV[0] ne "deprecate" && $ARGV[0] ne "uploadRelease" && $ARGV[0] ne "downloadRelease" && $ARGV[0] ne "deleteEntry";
28   if (($ARGV[0] eq "create" || $ARGV[0] eq "finish") && !$opt{"location"})
29    {
30      print "The directory containing the ntuples must be given!\n";
31      exit;
32    }
33 < if ($ARGV[0] eq "uploadRelease" && !$opt{"pyConfig"} && !$opt{"release"})
33 > if ($ARGV[0] eq "uploadRelease" && (!$opt{"pyConfig"} || !$opt{"release"} || !$opt{"recipe"}))
34    {
35 <    print "Both the Python and the CMSSW release must be given!\n";
35 >    print "The Python config, CMSSW release directory, and recipe file must be given!\n";
36      exit;
37    }
38   if ($ARGV[0] eq "uploadRelease")
# Line 43 | Line 44 | if ($ARGV[0] eq "uploadRelease")
44      $cmsswRelease =~ s/^.*CMSSW_([^\/]*).*$/CMSSW_$1/;
45      `tar -C $parentDir -czf $ARGV[1].tar.gz $opt{"release"}`;
46      $opt{"format"} = "BEAN" if !$opt{"format"};
47 <    uploadRelease ($opt{"format"}, $cmsswRelease, "$ARGV[1].tar.gz", $opt{"pyConfig"}, $ARGV[1], "$ENV{'USER'}\@$ENV{'HOSTNAME'}", $opt{"comment"});
47 >    uploadRelease ($opt{"format"}, $cmsswRelease, "$ARGV[1].tar.gz", $opt{"pyConfig"}, $ARGV[1], "$ENV{'USER'}", $opt{"comment"}, $opt{"recipe"});
48 >  }
49 > elsif ($ARGV[0] eq "downloadRelease")
50 >  {
51 >    downloadRelease ($ARGV[1], $opt{"pyConfig"});
52    }
53   elsif ($ARGV[0] eq "createOther")
54    {
# Line 51 | Line 56 | elsif ($ARGV[0] eq "createOther")
56      @listOfFiles = reverse (@listOfFiles);
57      pop (@listOfFiles);
58      @listOfFiles = reverse (@listOfFiles);
59 <    dbOtherCreate ("$ENV{'USER'}\@$ENV{'HOSTNAME'}", \@listOfFiles, $opt{"comment"});
59 >    dbOtherCreate ("$ENV{'USER'}", \@listOfFiles, $opt{"comment"});
60    }
61   else
62    {
# Line 420 | Line 425 | printHelp
425      }
426    elsif ($command eq "uploadRelease")
427      {
428 <      print "Usage: $exeName -p FILE -r DIRECTORY [OPTION]... uploadRelease NAME\n";
428 >      print "Usage: $exeName -e FILE -p FILE -r DIRECTORY [OPTION]... uploadRelease NAME\n";
429        print "Copies an ntuple release to the appropriate area on the Tier 3, and creates a\n";
430        print "database entry for it, with NAME being the name of the release. An ntuple\n";
431        print "release is a CMSSW release with all the necessary packages added for creating\n";
# Line 428 | Line 433 | printHelp
433        print "\n";
434        print "Mandatory arguments to long options are mandatory for short options too.\n";
435        printf "%-29s%s\n", "  -c, --comment COMMENT", "comment for the database entry";
436 +      printf "%-29s%s\n", "  -e, --recipe FILE", "file containing the recipe for the release";
437        printf "%-29s%s\n", "  -f, --format FORMAT", "ntuple format (default: BEAN)";
438        printf "%-29s%s\n", "  -p, --pyConfig FILE", "default Python config for the release";
439        printf "%-29s%s\n", "  -r, --release DIRECTORY", "CMSSW release containing ntuple packages";
440      }
441 +  elsif ($command eq "downloadRelease")
442 +    {
443 +      print "Usage: $exeName [OPTION]... downloadRelease NAME\n";
444 +      print "Copies an ntuple release to the current directory on the Tier 3. Optionally\n";
445 +      print "copies the corresponding Python configuration file registered in the database.\n";
446 +      print "\n";
447 +      print "Mandatory arguments to long options are mandatory for short options too.\n";
448 +      printf "%-29s%s\n", "  -p, --pyConfig FILE", "Python configuration file name";
449 +    }
450    else
451      {
452        print "Usage: $exeName [OPTION]... COMMAND NAME\n";
# Line 443 | Line 458 | printHelp
458        print "\n";
459        print "COMMAND may be one of the following:\n";
460        printf "%-29s%s\n", "  create", "creates the entry";
461 <      printf "%-29s%s\n", "  create", "creates an entry for non-ntuple data";
461 >      printf "%-29s%s\n", "  createOther", "creates an entry for non-ntuple data";
462        printf "%-29s%s\n", "  update", "updates the entry";
463        printf "%-29s%s\n", "  finish", "finalizes the database entry";
464        printf "%-29s%s\n", "  deleteEntry", "removes the database entry";
465        printf "%-29s%s\n", "  deprecate", "marks the dataset for deletion";
466        printf "%-29s%s\n", "  uploadRelease", "upload an ntuple release";
467 +      printf "%-29s%s\n", "  downloadRelease", "download an ntuple release";
468      }
469  
470    exit;
# Line 502 | Line 518 | uploadRelease
518    my $name = shift;
519    my $user = shift;
520    my $comment = shift;
521 +  my $recipeName = shift;
522  
506  move ($release, "/home/hart/public_html/releases/$name.tar.gz") or die "Ntuple releases may only be uploaded on the Tier 3, stopped";
523    if (!(-e $psetName))
524      {
525        print "$psetName does not exist!\n";
526        exit;
527      }
528 +  if (!(-e $recipeName))
529 +    {
530 +      print "$recipeName does not exist!\n";
531 +      exit;
532 +    }
533 +  move ($release, "/home/hart/public_html/releases/$name.tar.gz") or die "Ntuple releases may only be uploaded on the Tier 3, stopped";
534    open (PY_CONFIG, "<$psetName");
535    my @pset = <PY_CONFIG>;
536    close (PY_CONFIG);
537    my $pset = join ("", @pset);
538 +  open (RECIPE, "<$recipeName");
539 +  my @recipe = <RECIPE>;
540 +  close (RECIPE);
541 +  my $recipe = join ("\n", @recipe);
542  
543    my $query = "select max(id) from ntupleRelease";
544    $db->selectdb ("ntuple");
# Line 527 | Line 553 | uploadRelease
553    $format = addSlashes ($format);
554    $cmsswRelease = addSlashes ($cmsswRelease);
555    $comment = addSlashes ($comment);
556 +  $recipe = addSlashes ($recipe);
557  
558 <  my $query = "insert into ntupleRelease (id, name, pset, user, pending, format, cmsswRelease, comment) values ($id, '$name', '$pset', '$user', 1, '$format', '$cmsswRelease', '$comment')";
558 >  my $query = "insert into ntupleRelease (id, name, pset, user, pending, format, cmsswRelease, comment, recipe) values ($id, '$name', '$pset', '$user', 1, '$format', '$cmsswRelease', '$comment', '$recipe')";
559    $db->selectdb ("ntuple");
560    my $results = $db->query ($query);
561   }
562  
563   sub
564 + downloadRelease
565 + {
566 +  my $release = shift;
567 +  my $pyConfigName = shift;
568 +
569 +  my $query = "select id,pset from ntupleRelease where name='$release'";
570 +  $db->selectdb ("ntuple");
571 +  my $results = $db->query ($query);
572 +  if ($results->numrows () != 1)
573 +    {
574 +      print "Ntuple release \"$release\" not found!\n";
575 +      exit;
576 +    }
577 +  if (!(-e "/home/hart/public_html/releases/$release.tar.gz"))
578 +    {
579 +      print "Release is in the database but no package exists!\n";
580 +      exit;
581 +    }
582 +  if ($pyConfigName)
583 +    {
584 +      my @row = $results->fetchrow ();
585 +      open (PY_CONFIG, ">$pyConfigName");
586 +      print PY_CONFIG $row[1];
587 +      close (PY_CONFIG);
588 +    }
589 +  copy ("/home/hart/public_html/releases/$release.tar.gz", "$release.tar.gz");
590 + }
591 +
592 + sub
593   dbOtherCreate
594   {
595    my $user = shift;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines