IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 28704


Ignore:
Timestamp:
Jul 23, 2010, 12:50:58 PM (16 years ago)
Author:
rhenders
Message:

First commit of new roboczar stuff

Location:
trunk/tools
Files:
8 added
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/czartool.pl

    r28261 r28704  
    33use warnings;
    44use strict;
    5 use PS::IPP::Config 1.01 qw( :standard );
    65use Getopt::Long qw( GetOptions :config auto_help auto_version gnu_getopt );
    7 use Pod::Usage qw( pod2usage );
    8 use IPC::Cmd 0.36 qw( can_run run );
    9 use DBI;
    10 use constant DB_SOCKET => '/var/run/mysqld/mysqld.sock';
    11 use File::Temp qw(tempfile);
     6
     7# local classes
     8use czartool::CzarDb;
     9use czartool::Gpc1Db;
     10use czartool::Pantasks;
     11
     12
     13my $czarDbName = "czardb";
     14my $save_temps = 1;
     15my $interval = undef;
     16
     17GetOptions (
     18        "dbname|d=s" => \$czarDbName,
     19        "interval|i=s" => \$interval,
     20        );
     21
    1222
    1323my @states = ("full", "new", "drop", "wait");
    14 my $db = connectToDb();
    15 
    16 if (!$db) {die;}
    17 
    18 my @stdscienceLabels = `czartool_getLabels.pl -s stdscience`;
    19 my @distributionLabels = `czartool_getLabels.pl -s distribution`;
    20 my @publishingLabels = `czartool_getLabels.pl -s publishing`;
    21 
    22 checkAllLabels("new");
    23 printInstructions();
    24 
    25 poll();
    26 $db->disconnect();
     24my $czarDb = new czartool::CzarDb($czarDbName, "ippdb01", "ipp", "ipp");
     25my $gpc1Db = new czartool::Gpc1Db("gpc1", "ippdb01", "ippuser", "ippuser");
     26my $pantasks = new czartool::Pantasks();
     27$czarDb->setDateFormat("%Y%m%d-%H%i%s");
     28
     29my @stdscienceLabels = undef;
     30my @distributionLabels = undef;
     31my @publishingLabels = undef;
     32
     33my @stages = ("chip", "cam", "fake", "warp", "stack", "diff", "magic", "magicDS", "dist");
     34promptPoll();
     35
    2736
    2837###########################################################################
     
    4150#
    4251###########################################################################
    43 sub poll {
     52sub promptPoll {
     53
     54    @stdscienceLabels = @{$pantasks->getLabels("stdscience")};
     55    @distributionLabels = @{$pantasks->getLabels("distribution")};
     56    @publishingLabels = @{$pantasks->getLabels("publishing")};
     57    checkAllLabels("new");
     58    printInstructions();
    4459
    4560    my $key;
     
    6075###########################################################################
    6176#
    62 # Connects to the database
    63 #
    64 ###########################################################################
    65 sub connectToDb {
    66 
    67     my $dbname = 'gpc1';
    68     my $dbserver = 'ippdb01';
    69     my $dbuser = 'ippuser';
    70     my $dbpass = 'ippuser';
    71     my $db = DBI->connect(
    72             "DBI:mysql:database=${dbname};host=${dbserver};mysql_socket=" .
    73             DB_SOCKET(),${dbuser},${dbpass},
    74             {
    75             RaiseError => 1, AutoCommit => 1}
    76             ) or die "Unable to connect to database $DBI::errstr\n";
    77 
    78     return $db;
    79 }
    80 
    81 ###########################################################################
    82 #
    8377# Compares two arrays and stores the differences
    8478#
     
    120114
    121115        chomp($line);
    122    
     116
    123117        print "$line\n";
    124118    }
     
    163157    chomp($input);
    164158    if ($input =~ m/^([0-9]|[1-9][0-9]|[1-9][0-9][0-9])$/) {
    165        return checkOneLabel($stdscienceLabels[$input]);
     159        return checkOneLabel($stdscienceLabels[$input]);
    166160    }
    167161
     
    179173    chomp($label);
    180174
    181     printf("\n+-------------------------------------------------------------------------------------+\n");
    182     printf("|                        %32s                             |\n", $label);
    183     printf("+------------+-------+-------+-------+-------+-------+-------+-------+--------+-------+\n");
    184     printf("|   state    |  chip |  cam  |  fake | warp  | stack |  diff | magic |destreak|  dist |\n");
    185     printf("+------------+-------+-------+-------+-------+-------+-------+-------+--------+-------+\n");
     175    printf("\n+---------------------------------------------------------------------------------------------------------------------------------+\n");
     176    printf("|                                                  %32s                                               |\n", $label);
     177    printf("+------------+------------+------------+------------+------------+------------+------------+------------+------------+------------+\n");
     178    printf("|   state    |    chip    |    cam     |    fake    |    warp    |   stack    |    diff    |   magic    |  destreak  |    dist    |\n");
     179    printf("+------------+------------+------------+------------+------------+------------+------------+------------+------------+------------+\n");
    186180
    187181    my $state;
     182    my $stage;
    188183    my $i=0;
    189184    foreach $state (@states) {
     
    191186        chomp($label);
    192187        printf("| %10s ", $state);
    193         printf("| %5s ", getStateAndFaults($label, "chipRun", $state, "chip"));
    194         printf("| %5s ", getStateAndFaults($label, "camRun", $state, "cam"));
    195         printf("| %5s ", getStateAndFaults($label, "fakeRun", $state, "fake"));
    196         printf("| %5s ", getStateAndFaults($label, "warpRun", $state, "warp"));
    197         printf("| %5s ", getStateAndFaults($label, "stackRun", $state, "stack"));
    198         printf("| %5s ", getStateAndFaults($label, "diffRun", $state, "diff"));
    199         printf("| %5s ", getStateAndFaults($label, "magicRun", $state, "magic"));
    200         printf("| %6s ", getStateAndFaults($label, "magicDSRun", $state, "magicDS"));
    201         printf("| %5s ", getStateAndFaults($label, "distRun", $state, "dist"));
     188
     189        foreach $stage (@stages) {
     190
     191            printf("| %10s ", getStateAndFaultsString($label, $state, $stage));
     192        }
     193
    202194        printf("|\n");
    203195        $i++;
    204196    }
    205197
    206     printf("+------------+-------+-------+-------+-------+-------+-------+-------+--------+-------+\n");
     198    printf("+------------+------------+------------+------------+------------+------------+------------+------------+------------+------------+\n");
    207199
    208200}
     
    225217    my $distLabel;
    226218    my $pubLabel;
    227     my $i=1;
    228219    my $distributing;
    229220    my $publishing;
     221    my $stage;
     222    my $i=1;
    230223    foreach $stdsLabel (@stdscienceLabels) {
    231224
     
    246239        printf("| %10s    ", $distributing ? "yes" : "NO" );
    247240        printf("| %10s    ", $publishing ? "yes" : "NO" );
    248         printf("| %10s ", getStateAndFaults($stdsLabel, "chipRun", $state, "chip"));
    249         printf("| %10s ", getStateAndFaults($stdsLabel, "camRun", $state, "cam"));
    250         printf("| %10s ", getStateAndFaults($stdsLabel, "fakeRun", $state, "fake"));
    251         printf("| %10s ", getStateAndFaults($stdsLabel, "warpRun", $state, "warp"));
    252         printf("| %10s ", getStateAndFaults($stdsLabel, "stackRun", $state, "stack"));
    253         printf("| %10s ", getStateAndFaults($stdsLabel, "diffRun", $state, "diff"));
    254         printf("| %10s ", getStateAndFaults($stdsLabel, "magicRun", $state, "magic"));
    255         printf("| %10s ", getStateAndFaults($stdsLabel, "magicDSRun", $state, "magicDS"));
    256         printf("| %10s ", getStateAndFaults($stdsLabel, "distRun", $state, "dist"));
     241
     242        foreach $stage (@stages) {
     243
     244            printf("| %10s ", getStateAndFaultsString($stdsLabel, $state, $stage));
     245        }
     246
    257247        printf("|\n");
    258248        $i++;
     
    265255###########################################################################
    266256#
    267 # Returns state and fault-count (if new) as a string
    268 #
    269 ###########################################################################
    270 sub getStateAndFaults {
    271     my ($label, $table, $state, $stage) = @_;
    272 
    273     my $new = checkLabel($label, $table, $state, $stage);
     257# Returns state and fault-count (if new) as a string TODO untidy
     258#
     259###########################################################################
     260sub getStateAndFaultsString {
     261    my ($label, $state, $stage) = @_;
     262
     263    my $new = $gpc1Db->countExposures($label, $stage, $state);
    274264
    275265    if ($state ne "new") {return $new;}
    276266
    277     my $faults = countFaults($label,$table,$stage);
     267    my $faults = $gpc1Db->countFaults($label, $stage);
    278268
    279269    if ($faults < 1) {return $new;}
     
    282272}
    283273
    284 ###########################################################################
    285 #
    286 # Returns count of exposures with this state for this label
    287 #
    288 ###########################################################################
    289 sub checkLabel {
    290     my ($label, $table, $state, $stage) = @_;
    291 
    292     if ($state eq "fault") {return countFaults($label, $table, $stage);}
    293 
    294     my $query = $db->prepare(<<SQL);
    295     SELECT count(state) 
    296         FROM $table
    297         WHERE label LIKE '$label'
    298         AND state = '$state'
    299 
    300 SQL
    301 
    302         $query->execute;
    303     return scalar $query->fetchrow_array();
    304 }
    305 
    306 ###########################################################################
    307 #
    308 # Returns count of faults for this stage and label
    309 #
    310 ###########################################################################
    311 sub countFaults {
    312     my ($label, $table, $stage) = @_;
    313 
    314     my $joinTable;
    315     my $id = $stage."_id";
    316 
    317     if ($stage eq "chip") {$joinTable="chipProcessedImfile";}
    318     elsif ($stage eq "cam") {$joinTable="camProcessedExp";}
    319     elsif ($stage eq "fake") {$joinTable="fakeProcessedImfile";}
    320     elsif ($stage eq "warp") {$joinTable="warpSkyfile";}
    321     elsif ($stage eq "stack") {$joinTable="stackSumSkyfile";}
    322     elsif ($stage eq "diff") {$joinTable="diffSkyfile";}
    323     elsif ($stage eq "magic") {$joinTable="magicNodeResult";}
    324     elsif ($stage eq "magicDS") {$id = "magic_ds_id"; $joinTable="magicDSFile";}
    325     elsif ($stage eq "dist") {$joinTable="distComponent";}
    326     else {return -1;}
    327 
    328     my $faultCol =  $joinTable.".fault";
    329     my $stateCol =  $table.".state";
    330 
    331     my $query = $db->prepare(<<SQL);
    332     SELECT COUNT(DISTINCT $id)
    333         FROM $table
    334         JOIN $joinTable USING ($id)
    335         WHERE label LIKE '$label'
    336         AND $faultCol != 0
    337         AND $stateCol = 'new'
    338 
    339 SQL
    340 
    341         $query->execute;
    342     return scalar $query->fetchrow_array();
    343 }
    344 
     274
Note: See TracChangeset for help on using the changeset viewer.