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.9 by ahart, Fri Aug 24 13:50:50 2012 UTC vs.
Revision 1.14 by ahart, Mon Oct 22 14:45:07 2012 UTC

# Line 12 | Line 12 | sub dbDelete;
12   sub dbDeleteOther;
13   sub addSlashes;
14   sub uploadRelease;
15 + sub downloadRelease;
16   sub datasetExists;
17 + sub uploadConfig;
18  
19   our $db = Mysql->connect ("cmshead.mps.ohio-state.edu", "ntuple", "osuT3User") or die "Failed to connect to Tier 3, stopped";
20  
21   my %opt;
22   Getopt::Long::Configure ("bundling");
23 < 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");
23 > 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");
24   my $argc = @ARGV;
25  
26   printHelp ($ARGV[0]) if $opt{"help"};
27   printHelp () if $argc != 2 && $ARGV[0] ne "createOther";
28 < 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";
28 > 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" && $ARGV[0] ne "uploadConfig";
29   if (($ARGV[0] eq "create" || $ARGV[0] eq "finish") && !$opt{"location"})
30    {
31      print "The directory containing the ntuples must be given!\n";
32      exit;
33    }
34 < if ($ARGV[0] eq "uploadRelease" && !$opt{"pyConfig"} && !$opt{"release"})
34 > if ($ARGV[0] eq "uploadRelease" && (!$opt{"pyConfig"} || !$opt{"release"} || !$opt{"recipe"}))
35    {
36 <    print "Both the Python and the CMSSW release must be given!\n";
36 >    print "The Python config, CMSSW release directory, and recipe file must be given!\n";
37 >    exit;
38 >  }
39 > if ($ARGV[0] eq "uploadConfig" && (!$opt{"pyConfig"} || !$opt{"release"}))
40 >  {
41 >    print "The Python config and ntuple release must be given!\n";
42      exit;
43    }
44   if ($ARGV[0] eq "uploadRelease")
# Line 43 | Line 50 | if ($ARGV[0] eq "uploadRelease")
50      $cmsswRelease =~ s/^.*CMSSW_([^\/]*).*$/CMSSW_$1/;
51      `tar -C $parentDir -czf $ARGV[1].tar.gz $opt{"release"}`;
52      $opt{"format"} = "BEAN" if !$opt{"format"};
53 <    uploadRelease ($opt{"format"}, $cmsswRelease, "$ARGV[1].tar.gz", $opt{"pyConfig"}, $ARGV[1], $ENV{"USER"}, $opt{"comment"});
53 >    uploadRelease ($opt{"format"}, $cmsswRelease, "$ARGV[1].tar.gz", $opt{"pyConfig"}, $ARGV[1], "$ENV{'USER'}", $opt{"comment"}, $opt{"recipe"});
54 >  }
55 > elsif ($ARGV[0] eq "downloadRelease")
56 >  {
57 >    downloadRelease ($ARGV[1], $opt{"pyConfig"});
58 >  }
59 > elsif ($ARGV[0] eq "uploadConfig")
60 >  {
61 >    uploadConfig ($ARGV[1], $ENV{"USER"}, $opt{"pyConfig"}, $opt{"release"}, $opt{"comment"});
62    }
63   elsif ($ARGV[0] eq "createOther")
64    {
# Line 51 | Line 66 | elsif ($ARGV[0] eq "createOther")
66      @listOfFiles = reverse (@listOfFiles);
67      pop (@listOfFiles);
68      @listOfFiles = reverse (@listOfFiles);
69 <    dbOtherCreate ($ENV{"USER"}, \@listOfFiles, $opt{"comment"});
69 >    dbOtherCreate ("$ENV{'USER'}", \@listOfFiles, $opt{"comment"});
70    }
71   else
72    {
# Line 65 | Line 80 | else
80      $status = "" if $ARGV[0] eq "update";
81      $status = "deprecated" if $ARGV[0] eq "deprecate";
82      $opt{"format"} = "BEAN" if $ARGV[0] eq "create" && !$opt{"format"};
83 <    dbUpdate ($id, $fullDataset, $ENV{"USER"}, $opt{"format"}, $opt{"location"}, $opt{"fileList"}, $status, $opt{"comment"}, $opt{"pyConfig"}, $opt{"crabCfg"}, $opt{"jsonFile"}, $opt{"lumiSummary"}, $opt{"release"}) if !$opt{"other"};
84 <    dbUpdateOther ($id, $opt{"comment"}, $ENV{"USER"}) if $opt{"other"};
83 >    dbUpdate ($id, $fullDataset, "$ENV{'USER'}\@$ENV{'HOSTNAME'}", $opt{"format"}, $opt{"location"}, $opt{"fileList"}, $status, $opt{"comment"}, $opt{"pyConfig"}, $opt{"crabCfg"}, $opt{"jsonFile"}, $opt{"lumiSummary"}, $opt{"release"}) if !$opt{"other"};
84 >    dbUpdateOther ($id, $opt{"comment"}, "$ENV{'USER'}\@$ENV{'HOSTNAME'}") if $opt{"other"};
85      dbDelete ($id) if $ARGV[0] eq "deleteEntry" && !$opt{"other"};
86      dbDeleteOther ($id) if $ARGV[0] eq "deleteEntry" && $opt{"other"};
87    }
# Line 394 | Line 409 | printHelp
409    elsif ($command eq "finish")
410      {
411        print "Usage: $exeName -l DIRECTORY finish NAME\n";
397
412        print "Finalizes the database entry for dataset NAME, changing its status to\n";
413        print "\"present\".  This is intended to be the final step in command-line based ntuple\n";
414        print "production.\n";
# Line 420 | Line 434 | printHelp
434      }
435    elsif ($command eq "uploadRelease")
436      {
437 <      print "Usage: $exeName -p FILE -r DIRECTORY [OPTION]... uploadRelease NAME\n";
437 >      print "Usage: $exeName -e FILE -p FILE -r DIRECTORY [OPTION]... uploadRelease NAME\n";
438        print "Copies an ntuple release to the appropriate area on the Tier 3, and creates a\n";
439        print "database entry for it, with NAME being the name of the release. An ntuple\n";
440        print "release is a CMSSW release with all the necessary packages added for creating\n";
# Line 428 | Line 442 | printHelp
442        print "\n";
443        print "Mandatory arguments to long options are mandatory for short options too.\n";
444        printf "%-29s%s\n", "  -c, --comment COMMENT", "comment for the database entry";
445 +      printf "%-29s%s\n", "  -e, --recipe FILE", "file containing the recipe for the release";
446        printf "%-29s%s\n", "  -f, --format FORMAT", "ntuple format (default: BEAN)";
447        printf "%-29s%s\n", "  -p, --pyConfig FILE", "default Python config for the release";
448        printf "%-29s%s\n", "  -r, --release DIRECTORY", "CMSSW release containing ntuple packages";
449      }
450 +  elsif ($command eq "downloadRelease")
451 +    {
452 +      print "Usage: $exeName [OPTION]... downloadRelease NAME\n";
453 +      print "Copies an ntuple release to the current directory on the Tier 3. Optionally\n";
454 +      print "copies the corresponding Python configuration file registered in the database.\n";
455 +      print "\n";
456 +      print "Mandatory arguments to long options are mandatory for short options too.\n";
457 +      printf "%-29s%s\n", "  -p, --pyConfig FILE", "Python configuration file name";
458 +    }
459 +  elsif ($command eq "uploadConfig")
460 +    {
461 +      print "Usage: $exeName -p FILE -r DIRECTORY [OPTION]... uploadConfig NAME\n";
462 +      print "Creates an entry in the database for a customized Python configuration file.\n";
463 +      print "\n";
464 +      print "Mandatory arguments to long options are mandatory for short options too.\n";
465 +      printf "%-29s%s\n", "  -c, --comment COMMENT", "comment for the database entry";
466 +      printf "%-29s%s\n", "  -p, --pyConfig FILE", "Python config file";
467 +      printf "%-29s%s\n", "  -r, --release NAME", "ntuple release with which to use this config";
468 +    }
469    else
470      {
471        print "Usage: $exeName [OPTION]... COMMAND NAME\n";
# Line 443 | Line 477 | printHelp
477        print "\n";
478        print "COMMAND may be one of the following:\n";
479        printf "%-29s%s\n", "  create", "creates the entry";
480 <      printf "%-29s%s\n", "  create", "creates an entry for non-ntuple data";
480 >      printf "%-29s%s\n", "  createOther", "creates an entry for non-ntuple data";
481        printf "%-29s%s\n", "  update", "updates the entry";
482        printf "%-29s%s\n", "  finish", "finalizes the database entry";
483        printf "%-29s%s\n", "  deleteEntry", "removes the database entry";
484        printf "%-29s%s\n", "  deprecate", "marks the dataset for deletion";
485        printf "%-29s%s\n", "  uploadRelease", "upload an ntuple release";
486 +      printf "%-29s%s\n", "  downloadRelease", "download an ntuple release";
487 +      printf "%-29s%s\n", "  uploadConfig", "upload an ntuple config";
488      }
489  
490    exit;
# Line 502 | Line 538 | uploadRelease
538    my $name = shift;
539    my $user = shift;
540    my $comment = shift;
541 +  my $recipeName = shift;
542  
506  move ($release, "/home/hart/public_html/releases/$name.tar.gz") or die "Ntuple releases may only be uploaded on the Tier 3, stopped";
543    if (!(-e $psetName))
544      {
545        print "$psetName does not exist!\n";
546        exit;
547      }
548 +  if (!(-e $recipeName))
549 +    {
550 +      print "$recipeName does not exist!\n";
551 +      exit;
552 +    }
553 +  move ($release, "/home/hart/public_html/releases/$name.tar.gz") or die "Ntuple releases may only be uploaded on the Tier 3, stopped";
554    open (PY_CONFIG, "<$psetName");
555    my @pset = <PY_CONFIG>;
556    close (PY_CONFIG);
557    my $pset = join ("", @pset);
558 +  open (RECIPE, "<$recipeName");
559 +  my @recipe = <RECIPE>;
560 +  close (RECIPE);
561 +  my $recipe = join ("\n", @recipe);
562  
563    my $query = "select max(id) from ntupleRelease";
564    $db->selectdb ("ntuple");
# Line 527 | Line 573 | uploadRelease
573    $format = addSlashes ($format);
574    $cmsswRelease = addSlashes ($cmsswRelease);
575    $comment = addSlashes ($comment);
576 +  $recipe = addSlashes ($recipe);
577  
578 <  my $query = "insert into ntupleRelease (id, name, pset, user, pending, format, cmsswRelease, comment) values ($id, '$name', '$pset', '$user', 1, '$format', '$cmsswRelease', '$comment')";
578 >  my $query = "insert into ntupleRelease (id, name, pset, user, pending, format, cmsswRelease, comment, recipe) values ($id, '$name', '$pset', '$user', 1, '$format', '$cmsswRelease', '$comment', '$recipe')";
579    $db->selectdb ("ntuple");
580    my $results = $db->query ($query);
581   }
582  
583   sub
584 + downloadRelease
585 + {
586 +  my $release = shift;
587 +  my $pyConfigName = shift;
588 +
589 +  my $query = "select id,pset from ntupleRelease where name='$release'";
590 +  $db->selectdb ("ntuple");
591 +  my $results = $db->query ($query);
592 +  if ($results->numrows () != 1)
593 +    {
594 +      print "Ntuple release \"$release\" not found!\n";
595 +      exit;
596 +    }
597 +  if (!(-e "/home/hart/public_html/releases/$release.tar.gz"))
598 +    {
599 +      print "Release is in the database but no package exists!\n";
600 +      exit;
601 +    }
602 +  if ($pyConfigName)
603 +    {
604 +      my @row = $results->fetchrow ();
605 +      open (PY_CONFIG, ">$pyConfigName");
606 +      print PY_CONFIG $row[1];
607 +      close (PY_CONFIG);
608 +    }
609 +  copy ("/home/hart/public_html/releases/$release.tar.gz", "$release.tar.gz");
610 + }
611 +
612 + sub
613   dbOtherCreate
614   {
615    my $user = shift;
# Line 570 | Line 646 | dbOtherCreate
646    $location = addSlashes ($location);
647    $comment = addSlashes ($comment);
648  
649 <  my $query = "insert into other (id, creationTime, lastUpdateTime, lastUpdateUser, user, location, nFiles, sizeInGB, comment) values ($id, now(), now(), '$user', '$user', '$location', $nFiles, $size, '$comment')";
649 >  $query = "insert into other (id, creationTime, lastUpdateTime, lastUpdateUser, user, location, nFiles, sizeInGB, comment) values ($id, now(), now(), '$user', '$user', '$location', $nFiles, $size, '$comment')";
650    $db->selectdb ("ntuple");
651 <  my $results = $db->query ($query);
651 >  $results = $db->query ($query);
652  
653    print "ID $id\n";
654   }
655 +
656 + sub
657 + uploadConfig
658 + {
659 +  my $name = shift;
660 +  my $user = shift;
661 +  my $psetName = shift;
662 +  my $release = shift;
663 +  my $comment = shift;
664 +
665 +  if (!(-e $psetName))
666 +    {
667 +      print "$psetName does not exist!\n";
668 +      exit;
669 +    }
670 +  if ($release)
671 +    {
672 +      my $query = "select id from ntupleRelease where name='$release'";
673 +      $db->selectdb ("ntuple");
674 +      my $results = $db->query ($query);
675 +      if ($results->numrows () != 1)
676 +        {
677 +          print "Ntuple release \"$release\" not found!\n";
678 +          exit;
679 +        }
680 +    }
681 +  open (PSET, "<$psetName");
682 +  my @pset = <PSET>;
683 +  close (PSET);
684 +  my $pset = join ("", @pset);
685 +
686 +  my $query = "select max(id) from ntupleConfig";
687 +  $db->selectdb ("ntuple");
688 +  my $results = $db->query ($query);
689 +  my @row = $results->fetchrow ();
690 +  my $id = 1;
691 +  $id = $row[0] + 1 if $results->numrows ();
692 +
693 +  $name = addSlashes ($name);
694 +  $user = addSlashes ($user);
695 +  $pset = addSlashes ($pset);
696 +  $release = addSlashes ($release);
697 +  $comment = addSlashes ($comment);
698 +
699 +  my $query = "insert into ntupleConfig (id, name, pset, user, pending, ntupleRelease, comment) values ($id, '$name', '$pset', '$user', 1, '$release', '$comment')";
700 +  $db->selectdb ("ntuple");
701 +  $results = $db->query ($query);
702 + }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines