Index: trunk/tools/czartool/CzarDb.pm
===================================================================
--- trunk/tools/czartool/CzarDb.pm	(revision 28715)
+++ trunk/tools/czartool/CzarDb.pm	(revision 28719)
@@ -72,4 +72,23 @@
        $query->execute;
 }
+
+###########################################################################
+#
+# Sets priority for this label
+#
+###########################################################################
+sub setLabelPriority {
+    my ($self, $label, $priority) = @_;
+
+    my $query = $self->{_db}->prepare(<<SQL);
+     UPDATE current_labels 
+         SET priority = $priority 
+         WHERE label LIKE '$label' 
+         AND server LIKE 'stdscience';
+SQL
+
+    $query->execute;
+}
+
 ###########################################################################
 #
@@ -79,4 +98,7 @@
 sub updateCurrentLabels {
     my ($self, $server, $labels) = @_;
+
+    my $size = scalar @{$labels};
+    if ($size < 1) {return;}
 
     my $query = $self->{_db}->prepare(<<SQL);
@@ -181,4 +203,5 @@
 
         my ($timestamp, $pending, $faults, $processed) = @row;
+    #    print  "'$timestamp' '$pending' '$faults' '$processed'\n";
         print $tempFile "$timestamp $pending $faults $processed\n";
     }
@@ -298,5 +321,5 @@
 
     my $currentRevision = -1;
-    my $latestRevision = 6;
+    my $latestRevision = 7;
 
     while ($currentRevision != $latestRevision) {
@@ -311,4 +334,5 @@
         elsif ($currentRevision == 4) {$self->createRevision_5();}
         elsif ($currentRevision == 5) {$self->createRevision_6();}
+        elsif ($currentRevision == 6) {$self->createRevision_7();}
     }
 }
@@ -476,4 +500,24 @@
 #######################################################################################
 # 
+# Create revision 7 of the database 
+#
+#######################################################################################
+sub createRevision_7 {
+    my ($self) = @_;
+
+    print "* Creating revision 7 of '$self->{_dbName}'\n";
+
+    my $query = $self->{_db}->prepare(<<SQL);
+    ALTER TABLE current_labels 
+        ADD COLUMN priority INT NOT NULL DEFAULT 0;
+SQL
+
+    $query->execute;
+
+    $self->setRevision(7);
+}
+
+#######################################################################################
+# 
 # Sets current revision of ippToPsps database
 #
Index: trunk/tools/czartool/Czarplot.pm
===================================================================
--- trunk/tools/czartool/Czarplot.pm	(revision 28719)
+++ trunk/tools/czartool/Czarplot.pm	(revision 28719)
@@ -0,0 +1,249 @@
+#!/usr/bin/perl -w
+package czartool::Czarplot;
+
+use warnings;
+use strict;
+
+use File::Temp qw(tempfile);
+
+my @allStages = ("chip", "cam", "fake", "warp", "stack", "diff", "magic", "magicDS", "dist");
+
+
+###########################################################################
+#
+# Constructor
+#
+###########################################################################
+sub new {
+    my $class = shift;
+    my $self = {
+        _czarDb => shift,
+        _dateFormat => shift,
+        _outputFormat => shift,
+        _outputPath => shift,
+        _save_temps => shift,
+    };
+
+    bless $self, $class;
+    return $self;
+}
+
+###########################################################################
+#
+# Generates a suitable filename for this plot
+#
+###########################################################################
+sub createImageFileName {
+    my ($self, $label, $suffix) = @_;
+
+    my $prefix = $self->{_outputPath} ? $self->{_outputPath} : ".";
+
+    return $prefix . "/czarplot_" . $label . "_$suffix.png";
+}
+
+###########################################################################
+#
+# Plots a time series for all stages for this label
+#
+###########################################################################
+sub createTimeSeries {
+    my ($self, $label, $selectedStage, $beginTime, $endTime) = @_;
+
+    my $outputFile = createImageFileName($self, $label, "t");
+
+    my ($minX, $maxX, $minY, $maxY, $timeDiff);
+    $minX = 999999999;      
+    $maxX = -9999999999;
+    $minY = 999999999;          
+    $maxY = -99999999;
+
+    my $stages = undef;                 
+
+    if (!$selectedStage) {$stages = \@allStages;}
+    else {$stages = ["$selectedStage"]};        
+
+    my %gnuplotFiles;
+    my $stage = undef;
+    foreach $stage (@{$stages}) {
+        $gnuplotFiles{$stage} =  $self->{_czarDb}->createTimeSeriesData($self->{_save_temps}, $label, $stage, $beginTime, $endTime, \$minX, \$maxX, \$minY, \$maxY, \$timeDiff);
+    }                                                           
+
+    if (!$selectedStage) {plotAllStagesTimeSeries($self, $outputFile, $label, $beginTime, $endTime, $maxX, $minX, $maxY, $minY, $timeDiff, \%gnuplotFiles);}                      
+    else {plotSingleTimeSeries($self, $gnuplotFiles{$selectedStage}, $outputFile, $selectedStage, $label, $beginTime, $endTime, $maxX, $minX, $maxY, $minY, $timeDiff);}
+}                                                    
+
+###########################################################################
+#
+# Plots a histogram of stuff processed in provided interval and label for all stages
+#
+###########################################################################
+sub createHistogram {
+    my ($self, $label, $beginTime, $endTime) = @_;
+
+    my $outputFile = createImageFileName($self, $label, "h");
+
+    my ($tempFile, $inputFile) = tempfile( "/tmp/czartool_gnuplot_histogram.XXXX", UNLINK => !$self->{_save_temps});
+    my ($processed, $pending, $faults);
+    my $stage = undef;
+    foreach $stage (@allStages) {
+
+        $self->{_czarDb}->countProcessedPendingAndFaults($label, $stage, $beginTime, $endTime, \$processed, \$pending, \$faults);
+        print $tempFile "$stage $processed, $pending, $faults\n";
+    }
+
+    close($tempFile);
+
+    plotHistogram($self, $inputFile, $outputFile, $label, $beginTime, $endTime);
+}
+
+
+###########################################################################
+#
+# Sets the output path 
+#
+###########################################################################
+sub setOutputFormat {
+    my ($self, $outputFormat) = @_;
+    $self->{_outputFormat} = $outputFormat if defined($outputFormat);
+}           
+
+###########################################################################
+#
+# Sets the output type 
+#
+###########################################################################
+sub setOutputPath {
+    my ($self, $outputPath) = @_;
+    $self->{_outputPath} = $outputPath if defined($outputPath);
+}           
+
+###########################################################################
+#
+# Sets the date format to be used
+#
+###########################################################################
+sub setDateFormat {
+    my ($self, $dateFormat) = @_;
+    $self->{_dateFormat} = $dateFormat if defined($dateFormat);
+    return $self->{_dateFormat};
+}       
+
+###########################################################################
+#
+# Plots a time-series of pending/faults
+#
+###########################################################################
+sub plotAllStagesTimeSeries {
+    my ($self, $outputFile, $label, $fromTime, $toTime, $maxX, $minX, $maxY, $minY, $timeDiff, $gnuplotFiles) = @_;
+
+    $maxY = $maxY + ($maxY/10);
+    $minY = $minY - ($minY/10);
+    if ($maxY == 0) {$maxY = 1;}
+    if ($maxY == 0) {$maxY = 1;}
+    if ($minY == 0) {$minY = -1;}
+
+    my $divX = $timeDiff/2;
+
+    open (GP, "|/usr/bin/gnuplot -persist") or die "no gnuplot";
+    use FileHandle;
+    GP->autoflush(1);
+
+    print GP
+        "set term $self->{_outputFormat};" .
+        "set output \"$outputFile\";" .
+        "set title \"All stages for '$label' since $fromTime\";" .
+        "set key left top;" .
+        "set xdata time;" .
+        "set timefmt \"$self->{_dateFormat}\";" .
+        #"set xrange [\"$minX\":\"$maxX\"];" .
+        #"set yrange [$minY:$maxY];" .
+        "set format x \"%m/%d %H:%M\";" .
+        "set xtics \"$minX\", $divX, \"$maxX\";" .
+        "set grid xtics;" .
+        "set xlabel \"Time\";" .
+        "set ylabel \"Exposures\";" .
+        "plot ";
+
+    my $firstIn = 1;
+    foreach my $stage (keys %$gnuplotFiles) {
+        if (!$firstIn) {print GP ",";}
+        print GP "'" . $gnuplotFiles->{$stage} . "' using 1:4 title \"$stage\" with lines";
+        $firstIn = 0;
+    }
+
+    print GP "\n";
+    close GP;
+}
+
+###########################################################################
+#
+# Plots a time-series of pending/faults
+#
+###########################################################################
+sub plotSingleTimeSeries {
+    my ($self, $inputFile, $outputFile, $stage, $label, $fromTime, $toTime, $maxX, $minX, $maxY, $minY, $timeDiff) = @_;
+
+    $maxY = $maxY + ($maxY/10);
+    $minY = $minY - ($minY/10);
+    if ($maxY == 0) {$maxY = 1;}
+    if ($maxY == 0) {$maxY = 1;}
+    if ($minY == 0) {$minY = -1;}
+
+    my $divX = $timeDiff/2;
+
+    open (GP, "|/usr/bin/gnuplot -persist") or die "no gnuplot";
+    use FileHandle;
+    GP->autoflush(1);
+
+    print GP
+        "set term $self->{_outputFormat};" .
+        "set output \"$outputFile\";" .
+        "set title \"'$stage' stage for '$label' since $fromTime\";" .
+        "set key left top;" .
+        "set xdata time;" .
+        "set timefmt \"$self->{_dateFormat}\";" .
+        "set xrange [\"$minX\":\"$maxX\"];" .
+        "set yrange [$minY:$maxY];" .
+        "set format x \"%m/%d %H:%M\";" .
+        "set xtics \"$minX\", $divX, \"$maxX\";" .
+        "set grid;" .
+        "set xlabel \"Time\";" .
+        "set ylabel \"Exposures\";" .
+        "plot '$inputFile' using 1:4 title \"processed\" with lines lt 2," .
+        "'$inputFile' using 1:2 title \"pending\" with lines lt 3," .
+        "'$inputFile' using 1:3 title \"faults\" with lines lt 1\n";
+    close GP;
+}
+
+###########################################################################
+#
+# Plots a histogram of processed stuff
+#
+###########################################################################
+sub plotHistogram {
+    my ($self, $inputFile, $outputFile, $label, $fromTime, $toTime) = @_;
+
+    open (GP, "|/usr/bin/gnuplot -persist") or die "no gnuplot";
+    use FileHandle;
+    GP->autoflush(1);
+
+    print GP
+        "set term $self->{_outputFormat};" .
+        "set output \"$outputFile\";" .
+        "set title \"Processing status for $label since $fromTime\";" .
+        "set grid;" .
+        "set boxwidth;" .
+        "set style data histogram;" .
+        "set style histogram cluster gap 3;" .
+        "set style fill solid border -1;" .
+#        "set boxwidth 1.5;" .
+        "set bmargin 5;" .
+#        "set xtic rotate by -90;" .
+#        "plot '$inputFile' using 2:xtic(1) notitle\n";
+        "set ylabel \"Exposures\";" .
+        "plot '$inputFile' using 2:xtic(1) title \"Processed\" lt 2, '' using 3 title \"Pending\" lt 3, '' using 4 title \"Faults\" lt 1\n";
+
+    close GP;
+}
+
+1;
Index: trunk/tools/czartool/Gnuplot.pm
===================================================================
--- trunk/tools/czartool/Gnuplot.pm	(revision 28715)
+++ 	(revision )
@@ -1,163 +1,0 @@
-#!/usr/bin/perl -w
-
-use warnings;
-use strict;
-
-package czartool::Gnuplot;
-
-###########################################################################
-#
-# Constructor
-#
-###########################################################################
-sub new {
-    my $class = shift;
-    my $self = {
-        _dateFormat => shift,
-        _outputFormat => shift,
-        _outputPath => shift,
-    };
-
-    bless $self, $class;
-    return $self;
-}
-
-###########################################################################
-#
-# Sets the ouput path to be X11 
-#
-###########################################################################
-sub setOutputFormat {
-    my ($self, $outputFormat, $outputPath) = @_;
-    $self->{_outputFormat} = $outputFormat if defined($outputFormat);
-    $self->{_outputPath} = $outputPath if defined($outputPath);
-}           
-
-###########################################################################
-#
-# Sets the date format to be used
-#
-###########################################################################
-sub setDateFormat {
-    my ($self, $dateFormat) = @_;
-    $self->{_dateFormat} = $dateFormat if defined($dateFormat);
-    return $self->{_dateFormat};
-}       
-
-###########################################################################
-#
-# Plots a time-series of pending/faults
-#
-###########################################################################
-sub plotAllStagesTimeSeries {
-    my ($self, $label, $fromTime, $toTime, $maxX, $minX, $maxY, $minY, $timeDiff, $gnuplotFiles) = @_;
-
-    $maxY = $maxY + ($maxY/10);
-    $minY = $minY - ($minY/10);
-    if ($maxY == 0) {$maxY = 1;}
-    if ($maxY == 0) {$maxY = 1;}
-    if ($minY == 0) {$minY = -1;}
-
-    my $divX = $timeDiff/2;
-
-    open (GP, "|/usr/bin/gnuplot -persist") or die "no gnuplot";
-    use FileHandle;
-    GP->autoflush(1);
-
-    print GP
-        "set term $self->{_outputFormat};" .
-        "set output \"$self->{_outputPath}\";" .
-        "set title \"All stages for '$label' since $fromTime\";" .
-        "set xdata time;" .
-        "set timefmt \"$self->{_dateFormat}\";" .
-        #"set xrange [\"$minX\":\"$maxX\"];" .
-        #"set yrange [$minY:$maxY];" .
-        "set format x \"%m/%d %H:%M\";" .
-        "set xtics \"$minX\", $divX, \"$maxX\";" .
-        "set grid xtics;" .
-        "set xlabel \"Time\";" .
-        "set ylabel \"Exposures\";" .
-        "plot ";
-
-    my $firstIn = 1;
-    foreach my $stage (keys %$gnuplotFiles) {
-        if (!$firstIn) {print GP ",";}
-        print GP "'" . $gnuplotFiles->{$stage} . "' using 1:4 title \"$stage\" with lines";
-        $firstIn = 0;
-    }
-
-    print GP "\n";
-    close GP;
-}
-
-###########################################################################
-#
-# Plots a time-series of pending/faults
-#
-###########################################################################
-sub plotSingleTimeSeries {
-    my ($self, $filePath, $stage, $label, $fromTime, $toTime, $maxX, $minX, $maxY, $minY, $timeDiff) = @_;
-
-    $maxY = $maxY + ($maxY/10);
-    $minY = $minY - ($minY/10);
-    if ($maxY == 0) {$maxY = 1;}
-    if ($maxY == 0) {$maxY = 1;}
-    if ($minY == 0) {$minY = -1;}
-
-    my $divX = $timeDiff/2;
-
-    open (GP, "|/usr/bin/gnuplot -persist") or die "no gnuplot";
-    use FileHandle;
-    GP->autoflush(1);
-
-    print GP
-        "set term $self->{_outputFormat};" .
-        "set output \"$self->{_outputPath}\";" .
-        "set title \"'$stage' stage for '$label' since $fromTime\";" .
-        "set xdata time;" .
-        "set timefmt \"$self->{_dateFormat}\";" .
-        "set xrange [\"$minX\":\"$maxX\"];" .
-        "set yrange [$minY:$maxY];" .
-        "set format x \"%m/%d %H:%M\";" .
-        "set xtics \"$minX\", $divX, \"$maxX\";" .
-        "set grid;" .
-        "set xlabel \"Time\";" .
-        "set ylabel \"Exposures\";" .
-        "plot '$filePath' using 1:4 title \"processed\" with lines lt 2," .
-        "'$filePath' using 1:2 title \"pending\" with lines lt 3," .
-        "'$filePath' using 1:3 title \"faults\" with lines lt 1\n";
-    close GP;
-}
-
-###########################################################################
-#
-# Plots a histogram of processed stuff
-#
-###########################################################################
-sub plotHistogram {
-    my ($self, $filePath, $label, $fromTime, $toTime) = @_;
-
-    open (GP, "|/usr/bin/gnuplot -persist") or die "no gnuplot";
-    use FileHandle;
-    GP->autoflush(1);
-
-    print GP
-        "set term $self->{_outputFormat};" .
-        "set output \"$self->{_outputPath}\";" .
-        "set title \"Processing status for $label since $fromTime\";" .
-        "set grid;" .
-        "set boxwidth;" .
-        "set style data histogram;" .
-        "set style histogram cluster gap 3;" .
-        "set style fill solid border -1;" .
-#        "set boxwidth 1.5;" .
-        "set bmargin 5;" .
-        "set xtic rotate by -90;" .
-#        "plot '$filePath' using 2:xtic(1) notitle\n";
-        "set ylabel \"Exposures\";" .
-        "plot '$filePath' using 2:xtic(1) title \"Processed\" lt 2, '' using 3 title \"Pending\" lt 3, '' using 4 title \"Faults\" lt 1\n";
-
-    close GP;
-}
-
-1;
Index: trunk/tools/czartool/Gpc1Db.pm
===================================================================
--- trunk/tools/czartool/Gpc1Db.pm	(revision 28715)
+++ trunk/tools/czartool/Gpc1Db.pm	(revision 28719)
@@ -73,4 +73,24 @@
 ###########################################################################
 #
+# Returns priority for this label
+#
+###########################################################################
+sub getPriority {
+    my ($self, $label) = @_;
+
+    my $query = $self->{_db}->prepare(<<SQL);
+    SELECT priority 
+        FROM Label 
+        WHERE label LIKE '$label' 
+SQL
+
+        $query->execute;
+    my $priority = scalar $query->fetchrow_array();
+    if (!$priority) {return 50000;} # assume labels not given priority in gpc1 Db have highest priority
+    return $priority;
+}
+
+###########################################################################
+#
 # Returns count of exposures with this state for this label
 #
