Index: /trunk/ippScripts/scripts/lap_science.pl
===================================================================
--- /trunk/ippScripts/scripts/lap_science.pl	(revision 35791)
+++ /trunk/ippScripts/scripts/lap_science.pl	(revision 35792)
@@ -34,4 +34,5 @@
 my $qstack_threshold     = 0.05; # Only make a quickstack if more than 5% of the exposures require it.
 my $minimum_stack_inputs = 4;    # We can avoid magicking stack inputs if we have more than this number.
+my $do_updates_pv2       = 1;    # Do updates using the calls needed for PV2.  
 
 GetOptions(
@@ -231,9 +232,32 @@
     my $chip = ${ $chips }[0];
     my $chip_magicDS_id = 0;
+    my $chip_cam_id = 0;
     if ($chip) {
 	$chip_magicDS_id = $chip->{magic_ds_id};
+	$chip_cam_id     = $chip->{cam_id};
     }
     if ($chip_magicDS_id == 0) {
 #	return(&remake_this_exposure($exposure));
+    }
+
+    my $do_cam_update = 0;
+    if ($chip_cam_id) {      # If there is no cam_id, we can't look for it.
+	my $camtool_info_cmd = "camtool -processedexp -cam_id $chip_cam_id ";
+	$camtool_info_cmd   .= " -dbname $dbname " if defined $dbname;
+	($success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
+	    run(command => $camtool_info_cmd, verbose => $verbose);
+	unless ($success) {
+	    $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
+	    &my_die("Unable to perform camtool -listrun: $error_code", $exposure->{exp_id}, $data_group);
+	}
+	my $cams = $mdcParser->parse_list(join "", @$stdout_buf) or
+	    &my_die("Unable to parse metadata from camtool -listrun", $exposure->{exp_id}, $data_group);
+	my $cam = ${ $cams }[0];
+	# There can be only one.
+	if ($cam) {
+	    if ($cam->{label} ne $label) {
+		$do_cam_update = 1;
+	    }
+	}
     }
 
@@ -272,7 +296,15 @@
     }
 
+#
+# This is where we launch updates.
+#
     
     my $chiptool_update_cmd = "chiptool -setimfiletoupdate -chip_id $exposure->{chip_id} -set_label $label";
+    if ($do_updates_pv2) {
+	$chiptool_update_cmd   .= " -set_update_mode 1 "; # Use the current config information
+    }
     $chiptool_update_cmd   .= " -dbname $dbname " if defined $dbname;
+    my $camtool_update_cmd .= "camtool -updaterun -set_state update -cam_id $chip_cam_id -set_label $label";
+    $camtool_update_cmd    .= " -dbname $dbname " if defined $dbname;
     my $magicDS_update_cmd  = "magicdstool -setfiletoupdate -magic_ds_id $chip_magicDS_id -set_label $label";
     $magicDS_update_cmd    .= " -dbname $dbname " if defined $dbname;
@@ -289,5 +321,14 @@
                 &my_die("Unable to perform chiptool -setimfiletoupdate: $error_code", $exposure->{exp_id}, $data_group);
             }
-
+	    if ($do_updates_pv2) {     # Are we updating camera stages for PV2?
+		if ($do_cam_update) {  # Is this camRun still set to the old label?
+		    ($success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
+			run(command => $camtool_update_cmd, verbose => $verbose);
+		    unless ($success) {
+			$error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
+			&my_die("Unable to perform camtool -updaterun: $error_code", $exposure->{exp_id}, $data_group);
+		    }
+		}
+	    }
 #             if ($chip_magicDS_id != 0) {    
 # 	        ($success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
