Index: branches/eam_branches/ipp-20101103/tools/czarplot.pl
===================================================================
--- branches/eam_branches/ipp-20101103/tools/czarplot.pl	(revision 29657)
+++ branches/eam_branches/ipp-20101103/tools/czarplot.pl	(revision 29834)
@@ -8,5 +8,7 @@
 
 use czartool::CzarDb;
+use czartool::Gpc1Db;
 use czartool::Plotter;
+use czartool::StageMetrics;
 
 my $czarDbName = "czardb";
@@ -14,5 +16,5 @@
 my $stage = undef;
 my $save_temps = undef;
-my $interval = undef;
+my $timeinpast = undef;
 my $begin = undef;
 my $end = undef;
@@ -23,4 +25,6 @@
 my $timeSeries = undef;
 my $rate = undef;
+my $magicMask = undef;
+my $rateInterval = undef;
 my $deriv = undef;
 my $showCleanup = undef;
@@ -28,4 +32,5 @@
 my $savingToFile = undef;
 my $analysis = undef;
+my $exposureId = undef;
 my $log = undef;
 
@@ -34,5 +39,8 @@
         "label|l=s" => \$label,
         "stage|s=s" => \$stage,
-        "interval|i=s" => \$interval,
+        "timeinpast|p=s" => \$timeinpast,
+        "rateinterval|i=s" => \$rateInterval,
+        "exposureid|x=s" => \$exposureId,
+        "mask|m" => \$magicMask,
         "begin|b=s" => \$begin,
         "end|e=s" => \$end,
@@ -57,10 +65,17 @@
     print "* UNKNKOWN: option                          @ARGV\n";
 }
+if ($analysis && !$stage) {
+    $quit = 1;
+    print "* REQUIRED: choose a stage for analsis      -s <chip|cam|warp|etc>      (default=none)\n";}
 if (!$histogram) {
     print "* OPTIONAL: plot histogram                  -h                          (default=off)\n";}
 if (!$timeSeries) {
     print "* OPTIONAL: plot timeseries                 -t                          (default=on)\n";} 
+if (!$magicMask) {
+    print "* OPTIONAL: plot magic mask for these times -m                          (default=off)\n";} 
+if (!$exposureId) {
+    print "* OPTIONAL: set exposure ID for magic mask  -x                          (default=none)\n";} 
 if (!$rate) {
-    print "* OPTIONAL: plot timeseries of rate         -r                          (default=off)\n";} 
+    print "* OPTIONAL: plot histogram of rate          -r                          (default=off)\n";} 
 if (!$deriv) {
     $deriv = 0;
@@ -74,5 +89,5 @@
 if (!$log) {
     $log = 0;
-    print "* OPTIONAL: use log plots                   -g                          (default=$log\n";}
+    print "* OPTIONAL: use log plots                   -g                          (default=$log)\n";}
 if (!$nebulous) {
     print "* OPTIONAL: plot nebulous disk space        -n                          (default=off)\n";} 
@@ -82,6 +97,8 @@
 if (!$stage) {
     print "* OPTIONAL: choose a stage                  -s <chip|cam|warp|etc>      (default=none)\n";}
-if (!$interval) {
-    print "* OPTIONAL: choose time interval in past    -i <'1 hour'|'1 day'|etc>   (default=none\n";} 
+if (!$timeinpast) {
+    print "* OPTIONAL: choose time interval in past    -p <'1 hour'|'1 day'|etc>   (default=none\n";} 
+if (!$rateInterval) {
+    print "* OPTIONAL: time interval for rate plot     -i <'1 hour'|'1 day'|etc>   (default=depends on time frame)\n";} 
 if (!$begin) {
     print "* OPTIONAL: choose a begin time             -b <datetime>               (default=6:35am this morning)\n";} 
@@ -98,5 +115,5 @@
 
 # default values
-if (!$nebulous && !$histogram && !$timeSeries) {$timeSeries = 1; $histogram = 0;}
+if (!$rate && !$magicMask && !$nebulous && !$histogram && !$analysis && !$timeSeries) {$timeSeries = 1;}
 if (!$verbose) {$verbose = 0;}
 if (!$save_temps) {$save_temps = 0;}
@@ -104,4 +121,5 @@
 else {$savingToFile = 1;}
 
+my $gpc1Db = new czartool::Gpc1Db("gpc1", "ippdb01", "ippuser", "ippuser");
 my $czarDb = new czartool::CzarDb($czarDbName, "ippdb01", "ipp", "ipp", $verbose, $save_temps);
 $czarDb->setDateFormat("%Y%m%d-%H%i%s");
@@ -109,4 +127,5 @@
 
 my $plotter = new czartool::Plotter(
+        $gpc1Db, 
         $czarDb, 
         "%Y%m%d-%H%M%S", 
@@ -121,4 +140,6 @@
     $begin =  "$day 06:35";
     $end = "$day 23:59";
+        print "JKJKJK '$begin' '$end' \n";
+
 }
 else {
@@ -127,5 +148,5 @@
     if (!$begin) {
 
-        if ($interval) {$begin = $czarDb->subtractInterval($end, $interval);}
+        if ($timeinpast) {$begin = $czarDb->subtractInterval($end, $timeinpast);}
         else {$begin =  strftime('%Y-%m-%d 06:35',localtime);}
     }
@@ -134,7 +155,5 @@
 
 if ($rate) {
-
-    if (!$interval) {$interval = "1 HOUR";}
-    $plotter->createRateTimeSeries($label, $stage, $begin, $end, $interval, $log);
+    $plotter->createRateTimeSeries($label, $stage, $begin, $end, $rateInterval, $log);
     exit;
 }
@@ -143,17 +162,14 @@
 if ($nebulous && $timeSeries) {$plotter->plotStorageTimeSeries($begin, $end);}
 elsif ($nebulous) {$plotter->plotDiskUsageHistogram();}
+if ($magicMask) {
+    
+    if ($exposureId) {$plotter->plotMagicMaskFractionForThisExposure($exposureId);}
+    else {$plotter->plotMagicMaskFractionHistogram($begin, $end);}
 
+}
 
 if($analysis) {
 
-    my ($started, $finished, $stuck, $processed, $pending, $faults, $totalTime);
-    $czarDb->runAnalysis($label, $stage, $begin, $end, \$started, \$finished, \$stuck, \$processed, \$pending, \$faults, \$totalTime);
-
-    if (defined $started) {print "* Processing started at $started\n";}
-    if (defined $finished) {print "* Processing finished at $finished and took $totalTime\n";}
-    else {print "* Processing has not finished\n";}
-    if (defined $stuck) {print "* Processing has been stuck since $stuck\n";}
-    print "* $processed exposures have been processed, with $pending pending and $faults faults\n";
-
-    print "*******************************************************************************\n";
+    my $stageMetrics = new czartool::StageMetrics($stage, $label, $begin, $end);
+    if ($czarDb->runAnalysis($stageMetrics)) {$stageMetrics->printMe();}
 }
