Changeset 28704
- Timestamp:
- Jul 23, 2010, 12:50:58 PM (16 years ago)
- Location:
- trunk/tools
- Files:
-
- 8 added
- 1 edited
-
czarplot.pl (added)
-
czartool (added)
-
czartool.pl (modified) (11 diffs)
-
czartool/CzarDb.pm (added)
-
czartool/Gnuplot.pm (added)
-
czartool/Gpc1Db.pm (added)
-
czartool/MySQLDb.pm (added)
-
czartool/Pantasks.pm (added)
-
roboczar.pl (added)
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/czartool.pl
r28261 r28704 3 3 use warnings; 4 4 use strict; 5 use PS::IPP::Config 1.01 qw( :standard );6 5 use 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 8 use czartool::CzarDb; 9 use czartool::Gpc1Db; 10 use czartool::Pantasks; 11 12 13 my $czarDbName = "czardb"; 14 my $save_temps = 1; 15 my $interval = undef; 16 17 GetOptions ( 18 "dbname|d=s" => \$czarDbName, 19 "interval|i=s" => \$interval, 20 ); 21 12 22 13 23 my @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(); 24 my $czarDb = new czartool::CzarDb($czarDbName, "ippdb01", "ipp", "ipp"); 25 my $gpc1Db = new czartool::Gpc1Db("gpc1", "ippdb01", "ippuser", "ippuser"); 26 my $pantasks = new czartool::Pantasks(); 27 $czarDb->setDateFormat("%Y%m%d-%H%i%s"); 28 29 my @stdscienceLabels = undef; 30 my @distributionLabels = undef; 31 my @publishingLabels = undef; 32 33 my @stages = ("chip", "cam", "fake", "warp", "stack", "diff", "magic", "magicDS", "dist"); 34 promptPoll(); 35 27 36 28 37 ########################################################################### … … 41 50 # 42 51 ########################################################################### 43 sub poll { 52 sub promptPoll { 53 54 @stdscienceLabels = @{$pantasks->getLabels("stdscience")}; 55 @distributionLabels = @{$pantasks->getLabels("distribution")}; 56 @publishingLabels = @{$pantasks->getLabels("publishing")}; 57 checkAllLabels("new"); 58 printInstructions(); 44 59 45 60 my $key; … … 60 75 ########################################################################### 61 76 # 62 # Connects to the database63 #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 #83 77 # Compares two arrays and stores the differences 84 78 # … … 120 114 121 115 chomp($line); 122 116 123 117 print "$line\n"; 124 118 } … … 163 157 chomp($input); 164 158 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]); 166 160 } 167 161 … … 179 173 chomp($label); 180 174 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"); 186 180 187 181 my $state; 182 my $stage; 188 183 my $i=0; 189 184 foreach $state (@states) { … … 191 186 chomp($label); 192 187 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 202 194 printf("|\n"); 203 195 $i++; 204 196 } 205 197 206 printf("+------------+------- +-------+-------+-------+-------+-------+-------+--------+-------+\n");198 printf("+------------+------------+------------+------------+------------+------------+------------+------------+------------+------------+\n"); 207 199 208 200 } … … 225 217 my $distLabel; 226 218 my $pubLabel; 227 my $i=1;228 219 my $distributing; 229 220 my $publishing; 221 my $stage; 222 my $i=1; 230 223 foreach $stdsLabel (@stdscienceLabels) { 231 224 … … 246 239 printf("| %10s ", $distributing ? "yes" : "NO" ); 247 240 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 257 247 printf("|\n"); 258 248 $i++; … … 265 255 ########################################################################### 266 256 # 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 ########################################################################### 260 sub getStateAndFaultsString { 261 my ($label, $state, $stage) = @_; 262 263 my $new = $gpc1Db->countExposures($label, $stage, $state); 274 264 275 265 if ($state ne "new") {return $new;} 276 266 277 my $faults = countFaults($label,$table,$stage);267 my $faults = $gpc1Db->countFaults($label, $stage); 278 268 279 269 if ($faults < 1) {return $new;} … … 282 272 } 283 273 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.
