Index: /branches/haf_branches/ipp.20100512/ippScripts/scripts/addstar_run.pl
===================================================================
--- /branches/haf_branches/ipp.20100512/ippScripts/scripts/addstar_run.pl	(revision 28033)
+++ /branches/haf_branches/ipp.20100512/ippScripts/scripts/addstar_run.pl	(revision 28034)
@@ -37,5 +37,5 @@
 }
 
-my ( $exp_tag, $add_id, $camera, $outroot, $camroot, $dbname, $reduction, $dvodb, $image_only, $verbose, $no_update,
+my ( $exp_tag, $add_id, $camera, $outroot, $camroot, $dbname, $reduction, $dvodb, $minidvodb, $minidvodb_name, $minidvodb_group, $image_only, $verbose, $no_update,
      $no_op, $redirect, $save_temps);
 GetOptions(
@@ -48,4 +48,7 @@
     'reduction=s'       => \$reduction, # Reduction class
     'dvodb|w=s'         => \$dvodb,  # output DVO database
+    'minidvodb'         => \$minidvodb,  # use minidvodb?
+    'minidvodb_name|w=s'=> \$minidvodb_name,  # miniDVO database name
+    'minidvodb_group|w=s' => \$minidvodb_group, # miniDVO database group
     'image-only'        => \$image_only,   # Print to stdout
     'verbose'           => \$verbose,   # Print to stdout
@@ -58,5 +61,5 @@
 pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV;
 pod2usage(
-          -msg => "Required options: --exp_tag --add_id --camera --outroot",
+          -msg => "Required options: --exp_tag --add_id --camera --outroot --dvodb --camroot",
           -exitval => 3,
           ) unless
@@ -65,6 +68,9 @@
     defined $outroot and
     defined $camroot and
+    defined $dvodb and
     defined $camera;
-
+if ($minidvodb && !defined($minidvodb_group)) {
+		my_die( "missing minidvodb_group", $add_id, 3 );
+	    }
 my $ipprc = PS::IPP::Config->new( $camera ) or my_die( "Unable to set up", $add_id, $PS_EXIT_CONFIG_ERROR ); # IPP configuration
 
@@ -103,6 +109,36 @@
 my $dtime_addstar = 0;
 
+if (defined $dvodbReal) {
+	if ($minidvodb) {
+	    
+	    if (!defined($minidvodb_name)) {
+		#take the active one
+		my $command = "addtool -listminidvodbrun ";
+		$command .= " -minidvodb_group $minidvodb_group" if defined $minidvodb_group;
+		$command .= " -state 'active' -limit 1";
+		$command .= " -dbname $dbname" if defined $dbname;
+		print $command;
+		my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
+		    run(command => $command, verbose => $verbose);
+		&my_die( "Unable to get active minidvodb_name", $add_id, $PS_EXIT_SYS_ERROR) unless $success;
+		my $metadata = $mdcParser->parse(join "", @$stdout_buf) or
+		    &my_die("Unable to parse metadata config", $add_id, $PS_EXIT_PROG_ERROR);
+
+		my $components = parse_md_list($metadata) or
+		    &my_die("Unable to parse metadata list", $add_id, $PS_EXIT_PROG_ERROR);
+		my $comp = $$components[0];
+		$minidvodb_name = $comp->{minidvodb_name};
+		print "herexxxxxxxxxxxxxxxxxx";
+		if (!defined($minidvodb_name)) {
+		    &my_die("Unable to parse minidvodb_name", $add_id, $PS_EXIT_PROG_ERROR);
+		} 
+		
+	    }
+	 
+	    $dvodbReal = $dvodbReal . '/' . $minidvodb_name . '/';
+	    print $dvodbReal;
+	}
 unless ($no_op) {
-    if (defined $dvodbReal) {
+   	    print $dvodbReal;
 
         ## addstar can either save the full set of detections, or just
@@ -142,6 +178,7 @@
 $fpaCommand .= " -path_base $outroot";
 $fpaCommand .= " -dtime_addstar $dtime_addstar";
+$fpaCommand .= " -dvodb_path $dvodbReal";
 $fpaCommand .= " -dbname $dbname" if defined $dbname;
-
+print $fpaCommand;
 # Add the result into the database
 unless ($no_update) {
@@ -171,4 +208,5 @@
         $command .= " -addprocessedexp";
         $command .= " -fault $exit_code";
+	$command .= " -dvodb_path $dvodbReal" if defined $dvodbReal;
         $command .= " -path_base $outroot" if defined $outroot;
         $command .= (" -dtime_addstar " . ((DateTime->now->mjd - $mjd_start) * 86400));
Index: /branches/haf_branches/ipp.20100512/ippScripts/scripts/minidvodb_createdb.pl
===================================================================
--- /branches/haf_branches/ipp.20100512/ippScripts/scripts/minidvodb_createdb.pl	(revision 28034)
+++ /branches/haf_branches/ipp.20100512/ippScripts/scripts/minidvodb_createdb.pl	(revision 28034)
@@ -0,0 +1,176 @@
+#!/usr/bin/env perl
+
+use warnings;
+use strict;
+use Carp;
+
+## report the program and machine
+use Sys::Hostname;
+my $host = hostname();
+my $date = `date`;
+print "\n\n";
+print "Starting script $0 on $host at $date\n\n";
+
+use DateTime;
+my $mjd_start = DateTime->now->mjd;   # MJD of starting script
+
+use vars qw( $VERSION );
+$VERSION = '0.01';
+
+use IPC::Cmd 0.36 qw( can_run run );
+use PS::IPP::Metadata::Config;
+use PS::IPP::Metadata::List qw( parse_md_list );
+use PS::IPP::Config 1.01 qw( :standard );
+use File::Temp qw( tempfile );
+
+use Getopt::Long qw( GetOptions :config auto_help auto_version gnu_getopt );
+use Pod::Usage qw( pod2usage );
+
+# Look for programs we need
+my $missing_tools;
+my $addtool = can_run('addtool') or (warn "Can't find addtool" and $missing_tools = 1);
+my $ppConfigDump = can_run('ppConfigDump') or (warn "Can't find ppConfigDump" and $missing_tools = 1);
+if ($missing_tools) {
+    warn("Can't find required tools.");
+    exit($PS_EXIT_CONFIG_ERROR);
+}
+
+my (  $outroot, $dbname, $dvodb, $minidvodb_group, $camera, $minidvodb_name, $verbose, $no_update,
+     $no_op, $redirect, $save_temps);
+GetOptions(    
+    'camera|c=s'        => \$camera, # Camera
+    'dbname|d=s'        => \$dbname, # Database name
+    'minidvodb_group|w=s'       => \$minidvodb_group, # minidvodb_group.
+    'minidvodb_name|w=s' => \$minidvodb_name , 
+    'outroot|w=s'       => \$outroot, # output file base name
+    'dvodb|w=s'         => \$dvodb,  # output DVO database
+    'verbose'           => \$verbose,   # Print to stdout
+    'no-update'         => \$no_update, # Update the database?
+    'no-op'             => \$no_op, # Don't do any operations?
+    'redirect-output'   => \$redirect,
+    'save-temps'        => \$save_temps, # Save temporary files?
+    ) or pod2usage( 2 );
+
+pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV;
+pod2usage(
+          -msg => "Required options: --camera --minidvodb_group --dvodb --minidvodb_group --minidvodb_name --outroot",
+          -exitval => 3,
+          ) unless
+    defined $minidvodb_group and
+    defined $minidvodb_name and 
+    defined $camera and 
+    defined $outroot and
+    defined $dvodb;
+
+my $ipprc = PS::IPP::Config->new( $camera ) or my_die( "Unable to set up", $minidvodb_name   , $PS_EXIT_CONFIG_ERROR ); # IPP configuration
+
+my $logDest = $ipprc->filename("LOG.EXP", $outroot) or &my_die("Missing entry from camera config", $minidvodb_name, $PS_EXIT_CONFIG_ERROR);
+
+if ($redirect) {
+    $ipprc->redirect_output($logDest) or my_die( "Unable to redirect output", $minidvodb_name, $PS_EXIT_SYS_ERROR );
+    print "\n\n";
+    print "Starting script $0 on $host\n\n";
+    print "COMMAND IS: @ARGV\n\n";
+}
+
+# Recipes to use based on reduction class
+
+# XXX This is now not used: do we still need it?
+
+my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files
+
+# Output products
+$ipprc->outroot_prepare($outroot);
+
+# the camera configurations should define the psastro output to be a single file (MEF), regardless of the inputs
+
+# convert supplied DVO database name to UNIX filename
+my $dvodbReal;
+if (defined $dvodb) {
+    $dvodbReal = $ipprc->dvo_catdir( $dvodb ); # catdir for DVO
+    $dvodbReal = $ipprc->convert_filename_absolute( $dvodbReal );
+} else {
+    warn("dvodb undefined:\n");
+    exit(4);
+}
+
+
+
+
+unless ($no_op) {
+    my $minidvodb_path;
+    if (defined $dvodbReal) {
+	 $minidvodb_path = $dvodbReal . '/' . $minidvodb_name;
+    } else {
+	warn("dvodbReal undefined:\n");
+	exit(4);
+    }
+
+#see if there is already a new_not_ready
+    my $fpaCommand1 = "$addtool -listminidvodbrun";
+    $fpaCommand1 .= " -minidvodb_group '$minidvodb_group'";
+    $fpaCommand1 .= " -state 'new'";
+     $fpaCommand1 .= " -dbname $dbname" if defined $dbname;
+
+    print $fpaCommand1;
+unless ($no_update) {
+    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
+        run(command => $fpaCommand1, verbose => $verbose);
+    unless ($success) {
+        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
+        warn("Unable to list minidvodb database: $error_code\n");
+        exit($error_code);
+    }
+    print "xxx";
+    print scalar(@{$stdout_buf});
+    if (scalar(@{$stdout_buf})) {
+	$error_code = 3;
+	    warn("Unwilling to create minidvodb, one already exists in new state: $error_code\n");
+        exit($error_code);
+    }
+   
+
+}
+#create the minidvodb entry (well, the command for it)
+    my $fpaCommand = "$addtool -addminidvodbrun";
+    $fpaCommand .= " -set_minidvodb_name $minidvodb_name";
+    $fpaCommand .= " -set_minidvodb_path $minidvodb_path";
+    $fpaCommand .= " -set_minidvodb_group $minidvodb_group";
+    $fpaCommand .= " -set_mergedvodb_path $dvodbReal";
+     $fpaCommand .= " -dbname $dbname" if defined $dbname;
+    
+   # complain if it doesn't work
+unless ($no_update) {
+    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
+        run(command => $fpaCommand, verbose => $verbose);
+    unless ($success) {
+        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
+        warn("Unable to add result to database: $error_code\n");
+        exit($error_code);
+    }
+} else {
+    print "skipping command: $fpaCommand\n";
+}
+}
+
+sub my_die
+{#complain if it doesn't work
+    my $msg = shift; # Warning message on die
+    my $minidvodb_name = shift; # Camtool identifier
+    my $exit_code = shift; # Exit code to add
+
+    $exit_code = $PS_EXIT_PROG_ERROR unless defined $exit_code;
+
+    carp($msg);
+    
+    exit $exit_code;
+}
+
+END {
+    my $status = $?;
+    system("sync") == 0
+        or die "failed to execute sync: $!" ;
+    $? = $status;
+}
+
+__END__
Index: /branches/haf_branches/ipp.20100512/ippScripts/scripts/minidvodb_updatenewtoactive.pl
===================================================================
--- /branches/haf_branches/ipp.20100512/ippScripts/scripts/minidvodb_updatenewtoactive.pl	(revision 28034)
+++ /branches/haf_branches/ipp.20100512/ippScripts/scripts/minidvodb_updatenewtoactive.pl	(revision 28034)
@@ -0,0 +1,178 @@
+#!/usr/bin/env perl
+
+use warnings;
+use strict;
+use Carp;
+
+## report the program and machine
+use Sys::Hostname;
+my $host = hostname();
+my $date = `date`;
+print "\n\n";
+print "Starting script $0 on $host at $date\n\n";
+
+use DateTime;
+my $mjd_start = DateTime->now->mjd;   # MJD of starting script
+
+use vars qw( $VERSION );
+$VERSION = '0.01';
+
+use IPC::Cmd 0.36 qw( can_run run );
+use PS::IPP::Metadata::Config;
+use PS::IPP::Metadata::List qw( parse_md_list );
+use PS::IPP::Config 1.01 qw( :standard );
+use File::Temp qw( tempfile );
+
+use Getopt::Long qw( GetOptions :config auto_help auto_version gnu_getopt );
+use Pod::Usage qw( pod2usage );
+
+# Look for programs we need
+my $missing_tools;
+my $addtool = can_run('addtool') or (warn "Can't find addtool" and $missing_tools = 1);
+my $ppConfigDump = can_run('ppConfigDump') or (warn "Can't find ppConfigDump" and $missing_tools = 1);
+if ($missing_tools) {
+    warn("Can't find required tools.");
+    exit($PS_EXIT_CONFIG_ERROR);
+}
+
+my (  $outroot, $dbname, $dvodb, $minidvodb_group, $camera, $minidvodb_name, $verbose, $no_update,
+     $no_op, $redirect, $save_temps);
+GetOptions(    
+    'camera|c=s'        => \$camera, # Camera
+    'dbname|d=s'        => \$dbname, # Database name
+    'minidvodb_group|w=s'       => \$minidvodb_group, # minidvodb_group.
+    'minidvodb_name|w=s' => \$minidvodb_name , 
+    'outroot|w=s'       => \$outroot, # output file base name
+    'dvodb|w=s'         => \$dvodb,  # output DVO database
+    'verbose'           => \$verbose,   # Print to stdout
+    'no-update'         => \$no_update, # Update the database?
+    'no-op'             => \$no_op, # Don't do any operations?
+    'redirect-output'   => \$redirect,
+    'save-temps'        => \$save_temps, # Save temporary files?
+    ) or pod2usage( 2 );
+
+pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV;
+pod2usage(
+          -msg => "Required options: --camera --dvodb --minidvodb_group --minidvodb_name --outroot",
+          -exitval => 3,
+          ) unless
+    defined $minidvodb_group and
+    defined $minidvodb_name and 
+    defined $camera and 
+    defined $outroot and
+    defined $dvodb;
+
+my $ipprc = PS::IPP::Config->new( $camera ) or my_die( "Unable to set up", $minidvodb_name   , $PS_EXIT_CONFIG_ERROR ); # IPP configuration
+
+my $logDest = $ipprc->filename("LOG.EXP", $outroot) or &my_die("Missing entry from camera config", $minidvodb_name, $PS_EXIT_CONFIG_ERROR);
+
+if ($redirect) {
+    $ipprc->redirect_output($logDest) or my_die( "Unable to redirect output", $minidvodb_name, $PS_EXIT_SYS_ERROR );
+    print "\n\n";
+    print "Starting script $0 on $host\n\n";
+    print "COMMAND IS: @ARGV\n\n";
+}
+
+# Recipes to use based on reduction class
+
+# XXX This is now not used: do we still need it?
+
+my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files
+
+# Output products
+$ipprc->outroot_prepare($outroot);
+
+# the camera configurations should define the psastro output to be a single file (MEF), regardless of the inputs
+
+# convert supplied DVO database name to UNIX filename
+my $dvodbReal;
+if (defined $dvodb) {
+    $dvodbReal = $ipprc->dvo_catdir( $dvodb ); # catdir for DVO
+    $dvodbReal = $ipprc->convert_filename_absolute( $dvodbReal );
+} else {
+    warn("dvodb undefined:\n");
+    exit(4);
+}
+
+
+
+
+unless ($no_op) {
+    my $minidvodb_path;
+    if (defined $dvodbReal) {
+	 $minidvodb_path = $dvodbReal . '/' . $minidvodb_name;
+    } else {
+	warn("dvodbReal undefined:\n");
+	exit(4);
+    }
+
+#update active -> waiting for addrun
+    my $fpaCommand1 = "$addtool -updateminidvodbrun";
+    $fpaCommand1 .= " -minidvodb_group '$minidvodb_group'";
+    $fpaCommand1 .= " -state 'active'";
+    $fpaCommand1 .= " -set_state 'waiting_for_addrun'";
+     $fpaCommand1 .= " -dbname $dbname" if defined $dbname;
+
+    print $fpaCommand1;
+unless ($no_update) {
+    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
+        run(command => $fpaCommand1, verbose => $verbose);
+    unless ($success) {
+        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
+        warn("Unable to update minidvodb database (active -> waiting for addrun): $error_code\n");
+        exit($error_code);
+    }
+    print "xxx";
+    print scalar(@{$stdout_buf});
+    if (scalar(@{$stdout_buf})) {
+	$error_code = 3;
+	    warn("Unwilling to create minidvodb, one already exists in new state: $error_code\n");
+        exit($error_code);
+    }
+   
+
+}
+#update new -> active
+   my $fpaCommand1 = "$addtool -updateminidvodbrun";
+    $fpaCommand1 .= " -minidvodb_group '$minidvodb_group'";
+    $fpaCommand1 .= " -state 'new'";
+    $fpaCommand1 .= " -set_state 'active'";
+    $fpaCommand1 .= " -limit 1"; #oops?what if there are more than 1?
+     $fpaCommand1 .= " -dbname $dbname" if defined $dbname;
+
+    
+   # complain if it doesn't work
+unless ($no_update) {
+    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
+        run(command => $fpaCommand, verbose => $verbose);
+    unless ($success) {
+        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
+        warn("Unable to add result to database: $error_code\n");
+        exit($error_code);
+    }
+} else {
+    print "skipping command: $fpaCommand\n";
+}
+}
+
+sub my_die
+{#complain if it doesn't work
+    my $msg = shift; # Warning message on die
+    my $minidvodb_name = shift; # Camtool identifier
+    my $exit_code = shift; # Exit code to add
+
+    $exit_code = $PS_EXIT_PROG_ERROR unless defined $exit_code;
+
+    carp($msg);
+    
+    exit $exit_code;
+}
+
+END {
+    my $status = $?;
+    system("sync") == 0
+        or die "failed to execute sync: $!" ;
+    $? = $status;
+}
+
+__END__
