IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 28168


Ignore:
Timestamp:
May 28, 2010, 5:39:15 PM (16 years ago)
Author:
heather
Message:

minidvo creation scripts

Location:
branches/haf_branches/ipp.20100512/ippScripts
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/haf_branches/ipp.20100512/ippScripts/Build.PL

    r27504 r28168  
    6161        scripts/magic_destreak_cleanup.pl
    6262        scripts/magic_destreak_defineruns.pl
     63        scripts/minidvodb_createdb.pl
     64        scripts/minidvodb_load.pl
    6365        scripts/ippdb.pl
    6466        scripts/ipp_cleanup.pl
  • branches/haf_branches/ipp.20100512/ippScripts/scripts/minidvodb_createdb.pl

    r28104 r28168  
    44use strict;
    55use Carp;
    6 
     6use DateTime;
     7
     8use DateTime::Format::Strptime;
     9use DateTime::Duration;
    710## report the program and machine
    811use Sys::Hostname;
     
    1215print "Starting script $0 on $host at $date\n\n";
    1316
    14 use DateTime;
     17
    1518my $mjd_start = DateTime->now->mjd;   # MJD of starting script
    1619
     
    3639}
    3740
    38 my (  $outroot, $dbname, $dvodb, $minidvodb_group, $camera,  $verbose, $no_update,
     41my (  $outroot, $dbname, $dvodb,$minidvodb_interval, $minidvodb_group, $camera,  $verbose, $no_update,
    3942     $no_op, $redirect, $save_temps);
    4043GetOptions(   
     
    4447    'outroot|w=s'       => \$outroot, # output file base name
    4548    'dvodb|w=s'         => \$dvodb,  # output DVO database
     49    'interval|w=s'      => \$minidvodb_interval, #interval between creation of minidvodbs (default = 1day)
    4650    'verbose'           => \$verbose,   # Print to stdout
    4751    'no-update'         => \$no_update, # Update the database?
     
    5761          ) unless
    5862    defined $minidvodb_group and
    59     #defined $camera and
    60    #defined $outroot and
     63    defined $camera and
     64    defined $outroot and
    6165    defined $dvodb;
    6266
     
    7276}
    7377
     78
    7479# Recipes to use based on reduction class
    7580
     
    8287
    8388# the camera configurations should define the psastro output to be a single file (MEF), regardless of the inputs
    84 
     89 my $create_new = 0;
    8590# convert supplied DVO database name to UNIX filename
    8691my $dvodbReal;
     
    9398}
    9499
    95 
     100if (!defined $minidvodb_interval) {
     101    $minidvodb_interval = 1;
     102}
    96103
    97104
    98105unless ($no_op) {
    99106   
    100    
    101 
    102 #see if there is already a new_not_ready
     107 
     108
     109#see if there is already one in new state
    103110    my $fpaCommand1 = "$addtool -listminidvodbrun";
    104111    $fpaCommand1 .= " -minidvodb_group '$minidvodb_group'";
    105112    $fpaCommand1 .= " -state 'new'";
    106      $fpaCommand1 .= " -dbname $dbname" if defined $dbname;
    107 
    108     print $fpaCommand1;
     113    $fpaCommand1 .= " -dbname $dbname" if defined $dbname;
     114
     115   
    109116unless ($no_update) {
    110117    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    111118        run(command => $fpaCommand1, verbose => $verbose);
    112     unless ($success) {
    113         $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    114         warn("Unable to list minidvodb database: $error_code\n");
    115         exit($error_code);
    116     }
    117     print "xxx";
    118     print scalar(@{$stdout_buf});
     119   
     120
     121
     122   unless ($success) {
     123       $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     124       warn("Unable to list minidvodb database: $error_code\n");
     125       exit($error_code);
     126    }
     127   
    119128    if (scalar(@{$stdout_buf})) {
    120129        $error_code = 3;
     
    122131        exit($error_code);
    123132    }
     133
     134    my $creation_date;
     135    my $addRun_count;
     136    my $minidvodb_name;
     137#find the active one's date, and find out if it has more than 1 addRun in it   
     138   
     139    my $fpaCommand2 = "$addtool -listminidvodbrun";
     140    $fpaCommand2 .= " -minidvodb_group '$minidvodb_group'";
     141    $fpaCommand2 .= " -state 'active'";
     142    $fpaCommand2 .= " -limit 1";
     143     $fpaCommand2 .= " -dbname $dbname" if defined $dbname;
     144
     145#print $fpaCommand2;
     146
     147   
     148    my ( $success2, $error_code2, $full_buf2, $stdout_buf2, $stderr_buf2 ) =
     149        run(command => $fpaCommand2, verbose => $verbose);
     150    &my_die( "Unable to get listminidvodbrun",$minidvodb_group, $PS_EXIT_SYS_ERROR) unless $success2;
     151  # if it didn't list something in active state (what?) then we definitely need to create a new one
     152    if (defined(@$stdout_buf2)) {
     153  my  $metadata2 = $mdcParser->parse(join "", @$stdout_buf2) or
     154        &my_die("Unable to parse metadata config", $minidvodb_group, $PS_EXIT_PROG_ERROR);
     155   
     156  my   $components2 = parse_md_list($metadata2) or
     157        &my_die("Unable to parse metadata list", $minidvodb_group, $PS_EXIT_PROG_ERROR);
     158  my   $comp2 = $$components2[0];
     159    $minidvodb_name = $comp2->{minidvodb_name};
     160    $creation_date  = $comp2->{creation_date};
     161    if (!defined($minidvodb_name)) {
     162        &my_die("Unable to parse minidvodb_name", $minidvodb_group, $PS_EXIT_PROG_ERROR);
     163    }
     164    if (!defined($creation_date)) {
     165        &my_die("Unable to parse creation_date", $minidvodb_group, $PS_EXIT_PROG_ERROR);
     166    }
     167    } else {
     168        $create_new = 1; #this is to force it to make a new one
     169            }
     170
     171    #find the number of add_ids that have been proccessed
     172    my $fpaCommand3 = "$addtool -checkminidvodbrunaddrun";
     173    $fpaCommand3 .= " -minidvodb_group '$minidvodb_group'";
     174    $fpaCommand3 .= " -state 'active'";
     175    $fpaCommand3 .= " -minidvodb_name '$minidvodb_name'" if defined $minidvodb_name;
     176    $fpaCommand3 .= " -limit 1";
     177    $fpaCommand3 .= " -dbname $dbname" if defined $dbname;
     178
    124179   
    125 
     180my ( $success3, $error_code3, $full_buf3, $stdout_buf3, $stderr_buf3 ) =
     181        run(command => $fpaCommand3, verbose => $verbose);
     182    &my_die( "Unable to get checkminidvodbunaddrun", $minidvodb_group, $PS_EXIT_SYS_ERROR) unless $success3;
     183   
     184    if (defined(@$stdout_buf3)) {  #checkminidvodb returns nothing IF there have been no addruns added to the db yet
     185    my  $metadata3 = $mdcParser->parse(join "", @$stdout_buf3) or
     186        &my_die("Unable to parse metadata config", $minidvodb_group, $PS_EXIT_PROG_ERROR);
     187   
     188    my  $components3 = parse_md_list($metadata3) or
     189        &my_die("Unable to parse metadata list", $minidvodb_group, $PS_EXIT_PROG_ERROR);
     190   my  $comp = $$components3[0];
     191    $addRun_count = $comp->{addRun_count};
     192        }
     193    if (!defined($addRun_count)) {
     194         ## there's nothing to parse if there's nothing
     195        $addRun_count = 0;
     196    }
     197   
     198
     199    if ($addRun_count > 30000) {
     200        #it's too big, create_new
     201        $create_new = 1;
     202   }
     203    if ($create_new == 0) {
     204        my $parser = DateTime::Format::Strptime->new( pattern => '%Y-%m-%dT%H:%M:%S' );
     205        my $creation_dt = $parser->parse_datetime( $creation_date )->mjd;
     206        if ($mjd_start- $creation_dt > $minidvodb_interval && $addRun_count > 0 ) {
     207            #db is old and has stuff in it, want to create_new
     208            $create_new = 1;
     209        }
     210    }
     211   
     212   
    126213}
    127214#create the minidvodb entry (well, the command for it)
     
    129216    $fpaCommand .= " -set_minidvodb_group $minidvodb_group";
    130217    $fpaCommand .= " -set_mergedvodb_path $dvodbReal";
    131      $fpaCommand .= " -dbname $dbname" if defined $dbname;
    132     print $fpaCommand;
    133    # complain if it doesn't work
    134 unless ($no_update) {
    135     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    136         run(command => $fpaCommand, verbose => $verbose);
    137     unless ($success) {
    138         $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    139         warn("Unable to add result to database: $error_code\n");
    140         exit($error_code);
    141     }
    142 } else {
    143     print "skipping command: $fpaCommand\n";
    144 }
     218    $fpaCommand .= " -dbname $dbname" if defined $dbname;
     219   
     220    unless ($no_update or !$create_new) {
     221
     222
     223        my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     224            run(command => $fpaCommand, verbose => $verbose);
     225        unless ($success) {
     226            $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     227            warn("Unable to add result to database: $error_code\n");
     228            exit($error_code);
     229        }
     230    } else {
     231        print "skipping command: $fpaCommand\n";
     232    }
    145233}
    146234
     
    150238    my $minidvodb_group = shift; # Camtool identifier
    151239    my $exit_code = shift; # Exit code to add
    152 
     240   
    153241    $exit_code = $PS_EXIT_PROG_ERROR unless defined $exit_code;
    154 
     242   
    155243    carp($msg);
    156244   
Note: See TracChangeset for help on using the changeset viewer.