IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 25870


Ignore:
Timestamp:
Oct 18, 2009, 10:23:28 AM (17 years ago)
Author:
eugene
Message:

updated vysos branch from trunk

Location:
branches/eam_branches/20090820
Files:
2 deleted
163 edited
24 copied

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/20090820

  • branches/eam_branches/20090820/PS-IPP-PStamp/lib/PS/IPP/PStamp/Job.pm

    r25766 r25870  
    108108    } elsif ($req_type eq "bycoord") {
    109109
    110         # run
    111         # regtool -dbname $image_db -processedimfile -time_begin $mjd_min -time_end = $mjd_max -filter $filter
    112         #
    113         my $results = lookup_bycoord($ipprc, $image_db, $x, $y, $dateobs_begin, $dateobs_end, $filter, $verbose);
    114 
    115         # now take the results and lookup byexp
    116         # XXX: This needs work. What stops results from returning multiple images????
    117         # We should loop over the set of images returned building up the full results array
    118         $req_type = "byexp";
    119         $id = $results->{exp_name};
     110        if ($img_type eq "stack") {
     111            print STDERR "Error bycoord lookup not implemented for stage stack yet\n";
     112            return undef;
     113        }
    120114    } elsif ($req_type eq "byskycell") {
    121115        if (($img_type eq "raw") or ($img_type eq "chip")) {
     
    129123    }
    130124
    131     my $results = lookup($ipprc, $image_db, $req_type, $img_type, $id, $tess_id, $component, $need_magic, $dateobs_begin, $dateobs_end, $filter, $label, $verbose);
     125    my $results = lookup($ipprc, $image_db, $req_type, $img_type, $id, $tess_id, $component, $need_magic, $x, $y, $dateobs_begin, $dateobs_end, $filter, $label, $verbose);
    132126
    133127    return $results;
    134128}
    135129
    136 sub lookup {
     130sub lookup
     131{
    137132    my $ipprc    = shift;
    138133    my $image_db = shift;
     
    143138    my $component= shift;
    144139    my $need_magic = shift;
     140    my $x        = shift;
     141    my $y        = shift;
    145142    my $dateobs_begin = shift;
    146143    my $dateobs_end   = shift;
     
    175172
    176173    my $magic_arg = $need_magic ? " -destreaked" : "";
     174    my $component_args;
    177175    if ($img_type eq "raw") {
    178176        $class_id = $component;
    179177        $command = "$regtool -processedimfile -dbname $image_db";
     178        # XXX: for now restrict lookups to type object
     179        # are stamps of detrend exposures interesting?
     180        $command .= " -exp_type object";
    180181        $id_opt = "-exp_id";
    181         $command .= " -class_id $class_id" if $component;
     182        $component_args = " -class_id $class_id" if $component;
    182183        $want_astrom = 1;
    183184        $set_class_id = 1;
     
    185186        $class_id = $component;
    186187        $command = "$chiptool -processedimfile -dbname $image_db";
    187         $command .= " -class_id $class_id" if $class_id;
     188        $component_args = " -class_id $class_id" if $class_id;
    188189        $id_opt = "-chip_id";
    189190        $image_name   = "PPIMAGE.CHIP";
     
    196197        $skycell_id = $component;
    197198        $command = "$warptool -warped -dbname $image_db";
    198         $command .= " -skycell_id $skycell_id" if $skycell_id;
     199        $component_args = " -skycell_id $skycell_id" if $skycell_id;
    199200        $id_opt = "-warp_id";
    200201        $image_name   = "PSWARP.OUTPUT";
     
    205206        $skycell_id = $component;
    206207        $command = "$difftool -diffskyfile -dbname $image_db";
    207         $command .= " -skycell_id $skycell_id" if $skycell_id;
     208        $component_args = " -skycell_id $skycell_id" if $skycell_id;
    208209        $id_opt = "-diff_id";
    209210        $image_name  = "PPSUB.OUTPUT";
     
    212213        $base_name   = "path_base";
    213214    } elsif ($img_type eq "stack") {
     215        $skycell_id = $component;
    214216        $command = "$stacktool -sumskyfile -dbname $image_db";
    215217        $id_opt = "-stack_id";
     218        $component_args = " -skycell_id $skycell_id" if $skycell_id;
    216219
    217220        $image_name  = "PPSTACK.OUTPUT";
     
    225228    if ($req_type eq "byid") {
    226229        $command .= " $id_opt $id";
     230        $command .= $component_args if $component_args;
    227231    } elsif ($req_type eq "byexp") {
    228232        $command .= " -exp_name $id";
     233        $command .= $component_args if $component_args;
    229234    } elsif ($req_type eq "byskycell") {
     235        die "tess_id and component are required for byskycell" if !$tess_id or ! $skycell_id;
    230236        $command .= " -tess_id $tess_id -skycell_id $skycell_id";
     237    } elsif ($req_type eq "bycoord") {
     238        $command .= " -radius 3.0 -ra $x -decl $y";
    231239    } else {
    232240        die "Unknown req_type supplied: $req_type";
     
    289297
    290298        # if uri is nil this will get overridded below
    291         # (this is for raw stage)
     299        # (we do this here for raw stage)
    292300        $out->{image}  = $image->{uri};
    293301        if ($set_class_id) {
     
    295303            $out->{component} = $class_id;
    296304        }
     305        my $stage_id;
     306        if ($img_type eq "raw") {
     307            $stage_id = $image->{exp_id};
     308        } elsif ($img_type eq "chip") {
     309            $stage_id = $image->{chip};
     310        } elsif ($img_type eq "warp") {
     311            $stage_id = $image->{warp_id};
     312        } elsif ($img_type eq "diff") {
     313            $stage_id = $image->{diff_id};
     314        } elsif ($img_type eq "stack") {
     315            $stage_id = $image->{stack_id};
     316        }
     317        $image->{stage_id} = $stage_id;
     318        $image->{stage}    = $img_type;
     319        $image->{image_db} = $image_db;
    297320
    298321        # find the mask and weight images
    299322        if ($base) {
    300             $out->{image}  = $ipprc->filename($image_name,   $base, $class_id) if $image_name;
     323            $out->{image}  = $ipprc->filename($image_name,  $base, $class_id) if $image_name;
    301324            $out->{mask}   = $ipprc->filename($mask_name,   $base, $class_id) if $mask_name;
    302325            $out->{weight} = $ipprc->filename($weight_name, $base, $class_id) if $weight_name;
  • branches/eam_branches/20090820/PS-IPP-PStamp/lib/PS/IPP/PStamp/RequestFile.pm

    r25126 r25870  
    2323                    $PSTAMP_SELECT_WEIGHT
    2424                    $PSTAMP_SELECT_INVERSE
     25                    $PSTAMP_WAIT_FOR_UPDATE
    2526                    $PSTAMP_SUCCESS
    2627                    $PSTAMP_SYSTEM_ERROR
     
    4950
    5051our $PSTAMP_SELECT_INVERSE   = 1024;
     52our $PSTAMP_WAIT_FOR_UPDATE  = 2048;
    5153
    5254# job and result codes
  • branches/eam_branches/20090820/archive/ducttape

    • Property svn:mergeinfo changed (with no actual effect on merging)
  • branches/eam_branches/20090820/catalyst

    • Property svn:mergeinfo changed (with no actual effect on merging)
  • branches/eam_branches/20090820/catalyst/2007.0-specs

    • Property svn:mergeinfo changed (with no actual effect on merging)
  • branches/eam_branches/20090820/catalyst/2008.0-specs

    • Property svn:mergeinfo changed (with no actual effect on merging)
  • branches/eam_branches/20090820/catalyst/2008.0-specs/hardened

    • Property svn:mergeinfo changed (with no actual effect on merging)
  • branches/eam_branches/20090820/dbconfig/add.md

    r25766 r25870  
     1# XXX rename these 'addstarRun', etc... (add_id -> addstar_id)
    12addRun METADATA
    23    add_id          S64     0       # Primary Key AUTO_INCREMENT
    34    cam_id          S64     0       # Key INDEX(add_id,cam_id) fkey(cam_id) ref camRun(cam_id)
    4     state           STR     64      # key
     5    state           STR     64      # Key
    56    workdir         STR     255
    67    workdir_state   STR     64
     8    reduction       STR     64
    79    label           STR     64
     10    data_group      STR     64      # Key
    811    dvodb           STR     255
    9     magicked        S64     0
     12    note            STR     255
     13    image_only      BOOL    f
    1014END
    1115
     
    1317    add_id          S64     0       # Primary Key AUTO_INCREMENT
    1418    dtime_addstar   F32     0.0
    15 
    16     n_stars         S32     0
    17    
    1819    path_base       STR     255
    1920    fault           S16     0       # Key NOT NULL
  • branches/eam_branches/20090820/dbconfig/cam.md

    r24681 r25870  
    66    workdir_state STR       64      # key
    77    label       STR         64      # key
     8    data_group  STR         64      # key
     9    dist_group  STR         64      # key
    810    reduction   STR         64
    911    expgroup    STR         64      # key
     
    1214    end_stage   STR         64      # Key
    1315    magicked    S64         0
     16    note        STR         255
    1417END
    1518
  • branches/eam_branches/20090820/dbconfig/changes.txt

    r25766 r25870  
    13001300
    13011301ALTER TABLE pstampJob ADD COLUMN options BIGINT;
     1302
     1303ALTER TABLE addRun ADD COLUMN reduction VARCHAR(64) AFTER workdir_state;
     1304ALTER TABLE addRun DROP COLUMN magicked;
     1305ALTER TABLE addRun ADD COLUMN image_only tinyint after dvodb;
     1306ALTER TABLE addProcessedExp DROP COLUMN n_stars;
     1307
     1308CREATE TABLE flatcorrAddstarLink (
     1309        corr_id BIGINT,
     1310        cam_id BIGINT,
     1311        add_id BIGINT,
     1312        include TINYINT,
     1313        PRIMARY KEY(corr_id, cam_id, add_id),
     1314        FOREIGN KEY (corr_id)  REFERENCES  flatcorrRun(corr_id),
     1315        FOREIGN KEY (cam_id)  REFERENCES  camRun(cam_id),
     1316        FOREIGN KEY (add_id)  REFERENCES  addRun(add_id)
     1317) ENGINE=innodb DEFAULT CHARSET=latin1;
     1318
     1319ALTER TABLE pstampJob ADD COLUMN dep_id BIGINT;
     1320CREATE TABLE pstampDependent (
     1321        dep_id BIGINT AUTO_INCREMENT,
     1322        state      VARCHAR(64),
     1323        stage      VARCHAR(64),
     1324        stage_id   BIGINT,
     1325        imagedb    VARCHAR(64),
     1326        rlabel     VARCHAR(64),
     1327        no_magic   TINYINT,
     1328        PRIMARY KEY(dep_id)
     1329) ENGINE=innodb DEFAULT CHARSET=latin1;
     1330
     1331
     1332ALTER TABLE chipRun ADD COLUMN data_group VARCHAR(64) AFTER label;
     1333ALTER TABLE chipRun ADD COLUMN dist_group VARCHAR(64) AFTER data_group;
     1334ALTER TABLE chipRun ADD COLUMN note VARCHAR(255) AFTER magicked;
     1335ALTER TABLE chipRun ADD KEY(data_group);
     1336ALTER TABLE chipRun ADD KEY(dist_group);
     1337
     1338UPDATE chipRun SET data_group = label;
     1339UPDATE chipRun SET dist_group = label;
     1340
     1341ALTER TABLE camRun ADD COLUMN data_group VARCHAR(64) AFTER label;
     1342ALTER TABLE camRun ADD COLUMN dist_group VARCHAR(64) AFTER data_group;
     1343ALTER TABLE camRun ADD COLUMN note VARCHAR(255) AFTER magicked;
     1344ALTER TABLE camRun ADD KEY(data_group);
     1345ALTER TABLE camRun ADD KEY(dist_group);
     1346
     1347UPDATE camRun SET data_group = label;
     1348UPDATE camRun SET dist_group = label;
     1349
     1350ALTER TABLE addRun ADD COLUMN data_group VARCHAR(64) AFTER label;
     1351ALTER TABLE addRun ADD COLUMN note VARCHAR(255) AFTER dvodb;
     1352ALTER TABLE addRun ADD KEY(data_group);
     1353
     1354UPDATE addRun SET data_group = label;
     1355
     1356ALTER TABLE fakeRun ADD COLUMN data_group VARCHAR(64) AFTER label;
     1357ALTER TABLE fakeRun ADD COLUMN dist_group VARCHAR(64) AFTER data_group;
     1358ALTER TABLE fakeRun ADD COLUMN note VARCHAR(255) AFTER epoch;
     1359ALTER TABLE fakeRun ADD KEY(data_group);
     1360ALTER TABLE fakeRun ADD KEY(dist_group);
     1361
     1362UPDATE fakeRun SET data_group = label;
     1363UPDATE fakeRun SET dist_group = label;
     1364
     1365ALTER TABLE warpRun ADD COLUMN data_group VARCHAR(64) AFTER label;
     1366ALTER TABLE warpRun ADD COLUMN dist_group VARCHAR(64) AFTER data_group;
     1367ALTER TABLE warpRun ADD COLUMN note VARCHAR(255) AFTER magicked;
     1368ALTER TABLE warpRun ADD KEY(data_group);
     1369ALTER TABLE warpRun ADD KEY(dist_group);
     1370
     1371UPDATE warpRun SET data_group = label;
     1372UPDATE warpRun SET dist_group = label;
     1373
     1374ALTER TABLE stackRun ADD COLUMN data_group VARCHAR(64) AFTER label;
     1375ALTER TABLE stackRun ADD COLUMN dist_group VARCHAR(64) AFTER data_group;
     1376ALTER TABLE stackRun ADD COLUMN note VARCHAR(255) AFTER filter;
     1377ALTER TABLE stackRun ADD KEY(data_group);
     1378ALTER TABLE stackRun ADD KEY(dist_group);
     1379
     1380UPDATE stackRun SET data_group = label;
     1381UPDATE stackRun SET dist_group = label;
     1382
     1383ALTER TABLE diffRun ADD COLUMN data_group VARCHAR(64) AFTER label;
     1384ALTER TABLE diffRun ADD COLUMN dist_group VARCHAR(64) AFTER data_group;
     1385ALTER TABLE diffRun ADD COLUMN note VARCHAR(255) AFTER magicked;
     1386ALTER TABLE diffRun ADD KEY(data_group);
     1387ALTER TABLE diffRun ADD KEY(dist_group);
     1388
     1389UPDATE diffRun SET data_group = label;
     1390UPDATE diffRun SET dist_group = label;
     1391
     1392ALTER TABLE magicRun ADD COLUMN data_group VARCHAR(64) AFTER label;
     1393ALTER TABLE magicRun ADD COLUMN note VARCHAR(255) AFTER fault;
     1394ALTER TABLE magicRun ADD KEY(data_group);
     1395
     1396UPDATE magicRun SET data_group = label;
     1397
     1398ALTER TABLE magicDSRun ADD COLUMN data_group VARCHAR(64) AFTER label;
     1399ALTER TABLE magicDSRun ADD COLUMN fault SMALLINT after remove;
     1400ALTER TABLE magicDSRun ADD COLUMN note VARCHAR(255) AFTER fault;
     1401ALTER TABLE magicDSRun ADD KEY(fault);
     1402ALTER TABLE magicDSRun ADD KEY(data_group);
     1403
     1404UPDATE magicDSRun SET data_group = label;
     1405UPDATE magicDSRun SET fault = 0;
     1406
     1407ALTER TABLE distRun ADD COLUMN note VARCHAR(255) after fault;
     1408
     1409ALTER TABLE distTarget CHANGE COLUMN label dist_group VARCHAR(64);
     1410
     1411ALTER TABLE rcDestination ADD CONSTRAINT UNIQUE(name);
     1412
     1413CREATE TABLE dbversion (
     1414    schema_version VARCHAR(64),
     1415    updated TIMESTAMP DEFAULT CURRENT_TIMESTAMP
     1416) ENGINE=innodb DEFAULT CHARSET=latin1;
     1417
     1418INSERT INTO dbversion VALUES('1.1.56', CURRENT_TIMESTAMP);
     1419
     1420
     1421-- Vesion 1.1.57
     1422
     1423-- add changes for 1.1.57 here. Then uncomment the following before commiting
     1424
     1425-- UPDATE dbversion set schema_version = '1.1.57',  updated= CURRENT_TIMESTAMP();
  • branches/eam_branches/20090820/dbconfig/chip.md

    r24552 r25870  
    66    workdir_state STR       64      # Key
    77    label       STR         64      # Key
     8    data_group  STR         64      # Key
     9    dist_group  STR         64      # Key
    810    reduction   STR         64      # Reduction class
    911    expgroup    STR         64      # Key
     
    1214    end_stage   STR         64      # Key
    1315    magicked    S64         0
     16    note        STR         255
    1417END
    1518
  • branches/eam_branches/20090820/dbconfig/config.md

    r25766 r25870  
    22    pkg_name        STR     ippdb
    33    pkg_namespace   STR     ippdb
    4     pkg_version     STR     1.1.55
     4    pkg_version     STR     1.1.56
    55END
  • branches/eam_branches/20090820/dbconfig/diff.md

    r24552 r25870  
    66    workdir     STR         255
    77    label       STR         64      # Key
     8    data_group  STR         64
     9    dist_group  STR         64
    810    reduction   STR         64      # Reduction class
    911    dvodb       STR         255
     
    1315    exposure    BOOL        f
    1416    magicked    S64         0
     17    note        STR         255
    1518END
    1619
  • branches/eam_branches/20090820/dbconfig/dist.md

    r25766 r25870  
    11distTarget METADATA
    22    target_id   S64        0       # Primary Key
    3     label       STR        64
     3    dist_group  STR        64
    44    filter      STR        64
    55    stage       STR        64
     
    2222    time_stamp  UTC         0001-01-01T00:00:00Z
    2323    fault       S16         0
     24    note        STR         255
    2425END
    2526
  • branches/eam_branches/20090820/dbconfig/fake.md

    r19930 r25870  
    55    workdir     STR         255
    66    label       STR         64      # Key
     7    data_group  STR         64      # Key
     8    dist_group  STR         64      # Key
    79    reduction   STR         64      # Reduction class
    810    expgroup    STR         64      # Key
     
    1113    end_stage   STR         64      # Key
    1214    epoch       UTC         0001-01-01T00:00:00Z
     15    note        STR         255
    1316END
    1417
  • branches/eam_branches/20090820/dbconfig/flatcorr.md

    r20397 r25870  
    3333END
    3434
     35# table of exposures sent to addstar
     36flatcorrAddstarLink METADATA
     37    corr_id     S64         0       # Primary Key fkey(corr_id) ref flatcorrRun(corr_id)
     38    cam_id      S64         0       # Primary Key fkey(chip_id) ref chipRun(chip_id)
     39    add_id      S64         0       # Primary Key fkey(chip_id) ref chipRun(chip_id)
     40    include     BOOL        t
     41END
     42
  • branches/eam_branches/20090820/dbconfig/ipp.m4

    r25766 r25870  
    99dnl include(telescope.md)
    1010dnl include(skycell.md)
     11include(dbversion.md)
    1112include(summitcopy.md)
    1213include(new.md)
  • branches/eam_branches/20090820/dbconfig/magic.md

    r25014 r25870  
    1111    workdir_state STR       255     # Key
    1212    label       STR         64      # key
     13    data_group  STR         64
    1314    dvodb       STR         255
    1415    registered  TAI         NULL
    1516    fault       S16         0       # Key
     17    note        STR         255
    1618END
    1719
     
    5355    cam_id      S64         0
    5456    label       STR         64      # key
     57    data_group  STR         64      # key
    5558    outroot     STR         255
    5659    recoveryroot    STR     255
    5760    re_place    BOOL        f
    5861    remove      BOOL        f
     62    fault       S16         0       # Key
     63    note        STR         255
    5964END
    6065
  • branches/eam_branches/20090820/dbconfig/pstamp.md

    r25766 r25870  
    4040    outputBase  STR         255
    4141    options     S64         64
     42    dep_id      S64         0
    4243END
     44
     45pstampDependent       METADATA
     46    dep_id      S64         0       # Primary Key AUTO_INCREMENT
     47    state       STR         64
     48    stage       STR         64
     49    stage_id    S64         0
     50    imagedb     STR         64
     51    rlabel      STR         64
     52    no_magic    BOOL        f
     53END
  • branches/eam_branches/20090820/dbconfig/stack.md

    r23688 r25870  
    66    workdir     STR         255
    77    label       STR         64      # Key
     8    data_group  STR         64      # Key
     9    dist_group  STR         64      # Key
    810    reduction   STR         64      # Reduction class
    911    dvodb       STR         255
     
    1214    tess_id     STR         64      # Key
    1315    filter      STR         64
     16    note        STR         255
    1417END
    1518
  • branches/eam_branches/20090820/dbconfig/warp.md

    r24552 r25870  
    1717    workdir_state STR       64      # Key
    1818    label       STR         64      # key
     19    data_group  STR         64
     20    dist_group  STR         64
    1921    dvodb       STR         255
    2022    tess_id     STR         64
     
    2325    registered  TAI         NULL
    2426    magicked    S64         0
     27    note        STR         255
    2528END
    2629
  • branches/eam_branches/20090820/extperl

    • Property svn:ignore
      •  

        old new  
         1Abstract-Meta-Class-0.13
        12Apache-DBI-1.06
        23Apache-Test-1.29
         
        1314DBD-mysql-4.006
        1415DBI-1.601
         16DBIx-Connection-0.13
        1517DB_File-1.814
        1618Data-Validate-Domain-0.05
         
        6062Params-Validate-0.87
        6163Params-Validate-0.91
         64Params-Validate-0.92
        6265Parse-RecDescent-1.94
        6366SOAP-Lite-0.69
        6467SQL-Interp-1.06
         68Simple-SAX-Serializer-0.05
        6569Statistics-Descriptive-2.6
        6670Storable-2.15
         
        6872Template-Toolkit-2.16
        6973Test-Cmd-1.05
         74Test-DBUnit-0.20
         75Test-Distribution-2.00
        7076Test-Exception-0.24
        7177Test-Simple-0.74
  • branches/eam_branches/20090820/hardware

    • Property svn:mergeinfo changed (with no actual effect on merging)
  • branches/eam_branches/20090820/ippMonitor/Makefile.in

    r24868 r25870  
    151151$(DESTWWW)/calRun.php \
    152152$(DESTWWW)/flatcorrRun.php \
    153 $(DESTWWW)/flatcorrExp.php
    154 
     153$(DESTWWW)/flatcorrChip.php \
     154$(DESTWWW)/flatcorrCamera.php
    155155
    156156PICTURES = \
  • branches/eam_branches/20090820/ippMonitor/raw/ipp.detrend.dat

    r24868 r25870  
    5353menutop   | menutop      | plain   | Flat Correction              |
    5454menulink  | menuselect   | link    | Flat Corr Runs               | flatcorrRun.php
    55 menulink  | menuselect   | link    | Flat Corr Exp                | flatcorrExp.php
     55menulink  | menuselect   | link    | Flat Corr Chip Runs          | flatcorrChip.php
     56menulink  | menuselect   | link    | Flat Corr Camera Runs        | flatcorrCamera.php
  • branches/eam_branches/20090820/ippMonitor/raw/ipp.php

    r24759 r25870  
    285285  $file = fopen ($source, "r");
    286286
     287  global $DBHOST;
     288  $HOST = $_SERVER['SERVER_NAME'];
     289  echo "<p style=\"font-size:50%\">host: $HOST, db: $DBHOST</p>\n";
    287290  echo "<table class=page cellspacing=10px><tr><td valign=top>\n";
    288291  echo "<table class=menu cellspacing=0px>\n";
  • branches/eam_branches/20090820/ippScripts/Build.PL

    r25766 r25870  
    5959        scripts/magic_destreak.pl
    6060        scripts/magic_destreak_revert.pl
     61        scripts/magic_destreak_cleanup.pl
    6162        scripts/ippdb.pl
    6263        scripts/ipp_cleanup.pl
  • branches/eam_branches/20090820/ippScripts/scripts/addstar_run.pl

    r25766 r25870  
    2828# Look for programs we need
    2929my $missing_tools;
    30 #my $camtool = can_run('camtool') or (warn "Can't find camtool" and $missing_tools = 1);
    3130my $addtool = can_run('addtool') or (warn "Can't find addtool" and $missing_tools = 1);
    32 #my $ppImage = can_run('ppImage') or (warn "Can't find ppImage" and $missing_tools = 1);
    3331my $ppConfigDump = can_run('ppConfigDump') or (warn "Can't find ppConfigDump" and $missing_tools = 1);
    34 #my $ppStatsFromMetadata = can_run('ppStatsFromMetadata') or (warn "Can't find ppStatsFromMetadata" and $missing_tools = 1);
    35 #my $psastro = can_run('psastro') or (warn "Can't find psastro" and $missing_tools = 1);
    3632my $addstar = can_run('addstar') or (warn "Can't find addstar" and $missing_tools = 1);
    3733if ($missing_tools) {
     
    4036}
    4137
    42 my ( $exp_tag, $add_id, $camera, $outroot, $camroot, $recipe, $dbname, $reduction, $dvodb, $verbose, $no_update,
    43      $no_op, $redirect, $save_temps, $run_state);
     38my ( $exp_tag, $add_id, $camera, $outroot, $camroot, $dbname, $reduction, $dvodb, $image_only, $verbose, $no_update,
     39     $no_op, $redirect, $save_temps);
    4440GetOptions(
    4541    'exp_tag=s'          => \$exp_tag, # Exposure identifier
    4642    'add_id=s'          => \$add_id, # Camtool identifier
    47     'recipe=s'          => \$recipe, # Recipe to use
    4843    'camera|c=s'        => \$camera, # Camera
    4944    'dbname|d=s'        => \$dbname, # Database name
     
    5247    'reduction=s'       => \$reduction, # Reduction class
    5348    'dvodb|w=s'         => \$dvodb,  # output DVO database
    54     'run-state=s'       => \$run_state, # 'new' or 'update'
     49    'image-only'        => \$image_only,   # Print to stdout
    5550    'verbose'           => \$verbose,   # Print to stdout
    5651    'no-update'         => \$no_update, # Update the database?
     
    7469my $logDest = $ipprc->filename("LOG.EXP", $outroot) or &my_die("Missing entry from camera config", $add_id, $PS_EXIT_CONFIG_ERROR);
    7570
    76 if (not defined $run_state) { $run_state = 'new'; }
    77 if ($run_state eq 'update') {
    78     $logDest .= '.update';
    79 }
    80 
    8171if ($redirect) {
    8272    $ipprc->redirect_output($logDest) or my_die( "Unable to redirect output", $add_id, $PS_EXIT_SYS_ERROR );
     
    8979$reduction = 'DEFAULT' unless defined $reduction;
    9080
     81# XXX This is now not used: do we still need it?
    9182my $recipe_addstar = $ipprc->reduction($reduction, 'ADDSTAR'); # Recipe to use
    9283&my_die("Unrecognised ADDSTAR recipe", $add_id, $PS_EXIT_CONFIG_ERROR) unless defined $recipe_addstar;
    9384
    94 #my $recipe_psastro = $ipprc->reduction($reduction, 'PSASTRO'); # Recipe to use
    95 #&my_die("Unrecognised PSASTRO recipe", $cam_id, $PS_EXIT_CONFIG_ERROR) unless defined $recipe_psastro;
    96 
    9785my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files
    98 
    99 my $cmdflags;
    100 
    101 # Get list of component files
    102 my $files;                      # Array of component files
    103 {
    104     my $command = "$addtool -pendingexp -add_id $add_id"; # Command to run
    105     $command .= " -dbname $dbname" if defined $dbname;
    106     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    107         run(command => $command, verbose => $verbose);
    108     unless ($success) {
    109         $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    110         &my_die("Unable to perform addtool: $error_code", $add_id, $error_code);
    111     }
    112     my $metadata = $mdcParser->parse(join "", @$stdout_buf) or
    113         &my_die("Unable to parse metadata config doc", $add_id, $PS_EXIT_PROG_ERROR);
    114    
    115     # extract the metadata for the files into a hash list
    116     $files = parse_md_list($metadata) or
    117         &my_die("Unable to parse metadata list", $add_id, $PS_EXIT_PROG_ERROR);   
    118 }
    119 
    120 my $chipObjectsExist = 0;
    12186
    12287# Output products
     
    12691my $fpaObjects = $ipprc->filename("PSASTRO.OUTPUT",     $camroot) or &my_die("Missing entry from camera config", $add_id, $PS_EXIT_CONFIG_ERROR);
    12792my $traceDest  = $ipprc->filename("TRACE.EXP",          $outroot) or &my_die("Missing entry from camera config", $add_id, $PS_EXIT_CONFIG_ERROR);
    128 
    129 if ($run_state eq 'update') {
    130     $traceDest .= '.update';
    131 }
    13293
    13394# convert supplied DVO database name to UNIX filename
     
    141102
    142103unless ($no_op) {
    143     if (defined $dvodbReal and ($run_state eq 'new')) {
    144         ## XXX the camera analysis can either save the full set of
    145         ## detections, or just the image metadata, in the dvodb
     104    if (defined $dvodbReal) {
     105
     106        ## addstar can either save the full set of detections, or just
     107        ## the image metadata, in the dvodb.  this is set in the
     108        ## database table addRun
    146109       
    147         ## get the addstar recipe for this camera and CAMERA reduction
    148         my $command = "$ppConfigDump -camera $camera -recipe ADDSTAR $recipe_addstar -dump-recipe ADDSTAR -";
    149         my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    150             run(command => $command, verbose => $verbose);
    151         unless ($success) {
    152             $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    153             &my_die("Unable to perform ppConfigDump: $error_code", $add_id, $PS_EXIT_SYS_ERROR);
    154         }
    155         my $recipeData = $mdcParser->parse(join "", @$stdout_buf) or
    156             &my_die("Unable to parse metadata config doc", $add_id, $PS_EXIT_SYS_ERROR);
    157        
    158         ## allow the dvodb to save only images, or the full detection set
    159         my $imagesOnly = metadataLookupBool($recipeData, 'IMAGES.ONLY');
    160        
    161         # XXX this construct requires the user to have a valid .ptolemyrc
    162         # XXX which in turn points at ippconfig/dvo.site
     110        # addstar requires the user to have a valid .ptolemyrc which
     111        # in turn points at ippconfig/dvo.site
     112
     113        # get the names for the camera and the real input file
     114        my $camdir = $ipprc->dvo_cameradir(); # Camera directory for addstar
     115        my $realFile = $ipprc->file_resolve($fpaObjects);
     116
    163117        # require a defined output dvo database to run addstar (ie, refuse to use the .ptolemyrc default)
    164         # XXX this needs to be converted to addstar_client...
    165 
    166         my $camdir = $ipprc->dvo_cameradir(); # Camera directory for addstar
    167         $command  = "$addstar -D CAMERA $camdir -update";
    168         $command .= " -image" if $imagesOnly;
     118        my $command  = "$addstar -update"; # XXX optionally set -update?
     119        $command .= " -D CAMERA $camdir";
    169120        $command .= " -D CATDIR $dvodbReal";
    170        
    171         my $realFile = $ipprc->file_resolve($fpaObjects);
    172121        $command .= " $realFile";
     122        $command .= " -use-name $fpaObjects"; # DVO wants the neb-name as a file reference
     123        $command .= " -image" if $image_only;
    173124       
    174125        my $mjd_addstar_start = DateTime->now->mjd;   # MJD of starting script
    175126       
    176         ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     127        my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    177128            run(command => $command, verbose => $verbose);
    178129        unless ($success) {
     
    184135}
    185136
    186 
    187137# This needs to be updated when addtool is written. BROKEN
    188138my $fpaCommand = "$addtool -add_id $add_id";
    189 if ($run_state eq 'new') {
    190     $fpaCommand .= " -addprocessedexp";
    191     $fpaCommand .= " -path_base $outroot";
    192     $fpaCommand .= " $cmdflags";
    193     $fpaCommand .= " -dtime_addstar $dtime_addstar";
    194 } else {
    195     $fpaCommand .= " -updaterun -state full";
    196 }
     139$fpaCommand .= " -addprocessedexp";
     140$fpaCommand .= " -path_base $outroot";
     141$fpaCommand .= " -dtime_addstar $dtime_addstar";
    197142$fpaCommand .= " -dbname $dbname" if defined $dbname;
    198143
     
    223168# This needs to be updated when addtool is written. BROKEN
    224169        my $command = "$addtool -add_id $add_id";
    225         if ($run_state eq 'new') {
    226             $command .= " -addprocessedexp";
    227             $command .= " -uri UNKNOWN";
    228             $command .= " -fault $exit_code";
    229             $command .= " -path_base $outroot";
    230             $command .= " -path_base $outroot" if defined $outroot;
    231             $command .= (" -dtime_script " . ((DateTime->now->mjd - $mjd_start) * 86400));
    232         } else {
    233             $command .= " -updateprocessedexp";
    234             $command .= " -fault $exit_code";
    235         }
     170        $command .= " -addprocessedexp";
     171        $command .= " -fault $exit_code";
     172        $command .= " -path_base $outroot" if defined $outroot;
     173        $command .= (" -dtime_script " . ((DateTime->now->mjd - $mjd_start) * 86400));
    236174        $command .= " -dbname $dbname" if defined $dbname;
    237175        system ($command);
     
    239177    exit $exit_code;
    240178}
    241 
    242179
    243180END {
  • branches/eam_branches/20090820/ippScripts/scripts/camera_exp.pl

    r25766 r25870  
    3939}
    4040
    41 my ( $exp_tag, $cam_id, $camera, $outroot, $recipe, $dbname, $reduction, $dvodb, $verbose, $no_update,
     41my ( $exp_tag, $cam_id, $camera, $outroot, $dbname, $reduction, $dvodb, $verbose, $no_update,
    4242     $no_op, $redirect, $save_temps, $run_state);
    4343GetOptions(
    4444    'exp_tag=s'          => \$exp_tag, # Exposure identifier
    4545    'cam_id=s'          => \$cam_id, # Camtool identifier
    46     'recipe=s'          => \$recipe, # Recipe to use
    4746    'camera|c=s'        => \$camera, # Camera
    4847    'dbname|d=s'        => \$dbname, # Database name
     
    355354#    $fpaCommand .= " -dtime_addstar $dtime_addstar";
    356355} else {
    357     $fpaCommand .= " -updaterun -state full";
     356    $fpaCommand .= " -updaterun -set_state full";
    358357}
    359358$fpaCommand .= " -dbname $dbname" if defined $dbname;
  • branches/eam_branches/20090820/ippScripts/scripts/detrend_process_imfile.pl

    r24764 r25870  
    9494                  'DOMEFLAT'         => 'PPIMAGE.OUTPUT.DETREND',
    9595                  'SKYFLAT'          => 'PPIMAGE.OUTPUT.DETREND',
    96                   'FRINGE'           => undef,
     96                  'FRINGE'           => 'PPIMAGE.OUTPUT.DETREND',
    9797              };
    9898
  • branches/eam_branches/20090820/ippScripts/scripts/dist_make_fileset.pl

    r25766 r25870  
    4040# Parse the command-line arguments
    4141my ($dist_id, $dist_dir, $target_id, $stage, $stage_id, $dest_id, $product_name, $ds_dbhost, $ds_dbname);
    42 my ($label, $filter);
     42my ($label, $dist_group, $filter);
    4343my ($dbname, $save_temps, $verbose, $no_update, $logfile);
    4444
     
    5151           'dest_id=s'      => \$dest_id,    # id for the product
    5252           'product_name=s' => \$product_name,  # location of the data store directory for this product
    53            'label=s'       => \$label,
     53           'label=s'        => \$label,
     54           'dist_group=s'   => \$dist_group,
    5455           'filter=s'      => \$filter,
    5556           'ds_dbhost=s'    => \$ds_dbhost,  # database host for the datastore database
     
    6364
    6465pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV;
    65 pod2usage( -msg => "Required options: --dist_id --dist_dir --target_id --stage --stage_id --label --filter --dest_id --ds_dbhost --ds_dbname",
     66pod2usage( -msg => "Required options: --dist_id --dist_dir --target_id --stage --stage_id --dist_group --filter --dest_id --ds_dbhost --ds_dbname",
    6667           -exitval => 3) unless
    6768    defined $dist_id and
     
    7071    defined $stage and
    7172    defined $stage_id and
    72     defined $label and
     73    defined $dist_group and
    7374    defined $filter and
    7475    defined $dest_id and
     
    161162
    162163    $command .= " --ps0 $target_id --ps1 $stage --ps2 $stage_id --ps3 $prod_col_3";
    163     $command .= " --ps4 $label --ps5 $filter";
     164    $command .= " --ps4 $dist_group --ps5 $filter";
    164165
    165166    $command .= " --dbname $ds_dbname --dbhost $ds_dbhost";
  • branches/eam_branches/20090820/ippScripts/scripts/flatcorr_proc.pl

    r23688 r25870  
    104104my ($DECs, $DECe) = split (",", $coords[1]);
    105105
    106 # Run addstar -resort to ensure the db is indexed
    107 {
    108     my $command = "$addstar -resort";
     106# Run addstar -resort to ensure the db is indexed
     107# XXX addstar should be able to recognize and skip indexed tables
     108{
     109    my $command = "$addstar -resort";
    109110    $command .= " -D CATDIR $dvodb";
    110111    $command .= " -region $RAs $RAe $DECs $DECe";
  • branches/eam_branches/20090820/ippScripts/scripts/ipp_cleanup.pl

    r25766 r25870  
    9191
    9292    # if there are no chipProcessedImfiles (@$stdout_buf == 0), the reset the state to 'new'
     93    # XXX Why? This could just mean there's nothing to cleanup, or that we're trying to rerun an errored run.
    9394    if (@$stdout_buf == 0)  {
    94         my $command = "$chiptool -chip_id $stage_id -updaterun -set_state new";
     95        my $command = "$chiptool -chip_id $stage_id -updaterun -set_state $error_state";
    9596        $command .= " -dbname $dbname" if defined $dbname;
    9697
     
    123124            my $config_file = $ipprc->filename("PPIMAGE.CONFIG", $path_base, $class_id);
    124125
    125 #            if (!$config_file or ! -e $config_file) {
    126126            unless ($ipprc->file_exists($config_file)) {
    127127                print STDERR "skipping cleanup for chipRun $stage_id $class_id "
     
    187187                &my_die("Unable to perform chiptool: $error_code", "chip", $stage_id, $error_code);
    188188            }
     189
     190            # Tell magicdstool that we've cleaned up this data, so it needs to do the same if it needs to do the same.
     191            my $magicdstool = can_run('magicdstool') or die "Can't find magicdstool";
     192            $command = "$magicdstool -dbname gpc1  -stage $stage -stage_id $stage_id -updaterun -set_state goto_cleaned";
     193            ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     194                run(command => $command, verbose => $verbose);
     195            unless ($success) {
     196                $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     197                &my_die("Unable to perform magicdstool: $error_code", "$stage", $stage_id, $error_code);
     198            }
     199
    189200        } else {
    190201
     
    199210                &my_die("Unable to perform chiptool: $error_code", "chip", $stage_id, $error_code);
    200211            }
     212           
     213            # We want to flag the run as well, to avoid attempting to reprocess the same data over and over again.
     214            $command = "$chiptool -chip_id $stage_id -updaterun -set_state $error_state";
     215            $command .= " -dbname $dbname" if defined $dbname;
     216
     217            ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     218                run(command => $command, verbose => $verbose);
     219            unless ($success) {
     220                $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     221                &my_die("Unable to perform chiptool: $error_code", "chip", $stage_id, $error_code);
     222            }
     223
    201224        }
    202225    }
     
    283306            &my_die("Unable to perform camtool: $error_code", "camera", $stage_id, $error_code);
    284307        }
     308
     309        # Tell magicdstool that we've cleaned up this data, so it needs to do the same if it needs to do the same.
     310        my $magicdstool = can_run('magicdstool') or die "Can't find magicdstool";
     311        $command = "$magicdstool -dbname gpc1 -stage $stage -stage_id $stage_id -updaterun -set_state goto_cleaned";
     312        ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     313            run(command => $command, verbose => $verbose);
     314        unless ($success) {
     315            $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     316            &my_die("Unable to perform magicdstool: $error_code", "$stage", $stage_id, $error_code);
     317        }
     318
    285319    } else {
    286320        # since 'camera' has only a single imfile, we can just update the run
     
    296330        exit $PS_EXIT_UNKNOWN_ERROR;
    297331    }
     332
     333
    298334    exit 0;
    299335}
     
    314350        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    315351        &my_die("Unable to perform warptool: $error_code", "warp", $stage_id, $error_code);
     352    }
     353   
     354    if (@$stdout_buf == 0) {
     355        # No skycells were found for some reason.
     356        # Not technically an "error," but a "you told me to do X, and I can't. Please fix this yourself."
     357        my $command = "$warptool -updaterun -warp_id $stage_id -set_state $error_state";
     358        $command .= " -dbname $dbname" if defined $dbname;
     359       
     360        my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     361            run(command => $command, verbose => $verbose);
     362        unless ($success) {
     363            $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     364            &my_die("Unable to perform warptool: $error_code", "warp", $stage_id, $error_code);
     365        }
     366       
     367        exit(0);
    316368    }
    317369    my $metadata = $mdcParser->parse(join "", @$stdout_buf) or
     
    389441                &my_die("Unable to perform warptool: $error_code", "warp", $stage_id, $error_code);
    390442            }
     443
     444            # Tell magicdstool that we've cleaned up this data, so it needs to do the same if it needs to do the same.
     445            my $magicdstool = can_run('magicdstool') or die "Can't find magicdstool";
     446            $command = "$magicdstool -dbname gpc1 -stage $stage -stage_id $stage_id -updaterun -set_state goto_cleaned";
     447            ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     448                run(command => $command, verbose => $verbose);
     449            unless ($success) {
     450                $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     451                &my_die("Unable to perform magicdstool: $error_code", "$stage", $stage_id, $error_code);
     452            }
     453
    391454         } else {
    392455            my $command = "$warptool -updateskyfile -warp_id $stage_id -skycell_id $skycell_id -set_state $error_state";
     
    399462                &my_die("Unable to perform warptool: $error_code", "warp", $stage_id, $error_code);
    400463            }
    401             exit $PS_EXIT_UNKNOWN_ERROR;
     464
     465            #            exit $PS_EXIT_UNKNOWN_ERROR;
    402466        }
    403467    }
     
    407471### added for cleanup, based on warp stage entry
    408472if ($stage eq 'stack') {
    409    
    410473    die "--stage_id required for stage stack\n" if !$stage_id;
    411 
    412474    # this stage uses 'stacktool'
    413475    my $stacktool = can_run('stacktool') or die "Can't find stacktool";
     
    422484        &my_die("Unable to perform stacktool: $error_code", "stack", $stage_id, $error_code);
    423485    }
     486
     487    if (@$stdout_buf == 0) {
     488        # No skycells were found for some reason.
     489        # Not technically an "error," but a "you told me to do X, and I can't. Please fix this yourself."
     490        my $command = "$stacktool -updaterun -stack_id $stage_id -set_state $error_state";
     491        $command .= " -dbname $dbname" if defined $dbname;
     492       
     493        my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     494            run(command => $command, verbose => $verbose);
     495        unless ($success) {
     496            $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     497            &my_die("Unable to perform stacktool: $error_code", "stack", $stage_id, $error_code);
     498        }
     499       
     500        exit(0);
     501    }
     502
    424503    my $metadata = $mdcParser->parse(join "", @{ $stdout_buf }) or
    425504        &my_die("Unable to parse metadata config doc", "stack", $stage_id, $PS_EXIT_PROG_ERROR);
     
    434513
    435514        my $status = 1;
    436         if ($mode eq "goto_cleaned") {
    437             my $config_file = $ipprc->filename("PPSTACK.CONFIG", $path_base, $skycell_id);
    438 
    439             unless ($ipprc->file_exists($config_file)) {
    440                 print STDERR "skipping cleanup for stackRun $stage_id $skycell_id" .
    441                     " because config file is missing\n";
    442                 $status = 0;
    443             }
    444         }
    445         elsif ($mode eq "goto_scrubbed") {
    446             my $config_file = $ipprc->filename("PPSTACK.CONFIG", $path_base, $skycell_id);
    447 
    448             if ($ipprc->file_exists($config_file)) {
    449                 print STDERR "skipping scrubbed for stackRun $stage_id $skycell_id" .
    450                     " because config file is present\n";
    451                 $status = 0;
    452             }
    453         }
     515        if ((!exists($skyfile->{path_base}))||
     516            (!defined($path_base))) {
     517            $status = 0;
     518        }
     519        if ($status) {
     520            if ($mode eq "goto_cleaned") {
     521                my $config_file = $ipprc->filename("PPSTACK.CONFIG", $path_base, $skycell_id);
     522               
     523                unless ($ipprc->file_exists($config_file)) {
     524                    print STDERR "skipping cleanup for stackRun $stage_id $skycell_id" .
     525                        " because config file is missing\n";
     526                    $status = 0;
     527                }
     528            }
     529            elsif ($mode eq "goto_scrubbed") {
     530                my $config_file = $ipprc->filename("PPSTACK.CONFIG", $path_base, $skycell_id);
     531               
     532                if ($ipprc->file_exists($config_file)) {
     533                    print STDERR "skipping scrubbed for stackRun $stage_id $skycell_id" .
     534                        " because config file is present\n";
     535                    $status = 0;
     536                }
     537            }
     538        }
     539
    454540        if ($status) {
    455541            my @files = ();
     
    475561            my $command = "$stacktool -stack_id $stage_id";
    476562            if ($mode eq "goto_purged") {
    477                 $command .= " -updaterun -state purged";
     563                $command .= " -updaterun -set_state purged";
    478564            }
    479565            elsif ($mode eq "goto_cleaned") {
    480                 $command .= " -updaterun -state cleaned";
     566                $command .= " -updaterun -set_state cleaned";
    481567            }
    482568            elsif ($mode eq "goto_scrubbed") {
    483                 $command .= " -updaterun -state scrubbed";
     569                $command .= " -updaterun -set_state scrubbed";
    484570            }
    485571            $command .= " -dbname $dbname" if defined $dbname;
     
    491577                &my_die("Unable to perform stacktool: $error_code", "stack", $stage_id, $error_code);
    492578            }
     579
     580            # Tell magicdstool that we've cleaned up this data, so it needs to do the same if it needs to do the same.
     581            my $magicdstool = can_run('magicdstool') or die "Can't find magicdstool";
     582            $command = "$magicdstool -dbname gpc1  -stage $stage -stage_id $stage_id -updaterun -set_state goto_cleaned";
     583            ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     584                run(command => $command, verbose => $verbose);
     585            unless ($success) {
     586                $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     587                &my_die("Unable to perform magicdstool: $error_code", "$stage", $stage_id, $error_code);
     588            }
     589
    493590        } else {
    494             my $command = "$stacktool -updaterun  -stack_id $stage_id -state $error_state";
     591            my $command = "$stacktool -updaterun  -stack_id $stage_id -set_state $error_state";
    495592            $command .= " -dbname $dbname" if defined $dbname;
    496593           
     
    501598                &my_die("Unable to perform stacktool: $error_code", "stack", $stage_id, $error_code);
    502599            }
    503             exit $PS_EXIT_UNKNOWN_ERROR;
     600#           exit $PS_EXIT_UNKNOWN_ERROR;
    504601        }
    505602    }
     
    523620        &my_die("Unable to perform difftool: $error_code", "diff", $stage_id, $error_code);
    524621    }
     622
     623    if (@$stdout_buf == 0) {
     624        # No skycells were found for some reason.
     625        # Not technically an "error," but a "you told me to do X, and I can't. Please fix this yourself."
     626        my $command = "$difftool -updaterun -diff_id $stage_id -set_state $error_state";
     627        $command .= " -dbname $dbname" if defined $dbname;
     628       
     629        my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     630            run(command => $command, verbose => $verbose);
     631        unless ($success) {
     632            $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     633            &my_die("Unable to perform difftool: $error_code", "diff", $stage_id, $error_code);
     634        }
     635       
     636        exit(0);
     637    }
     638
    525639    my $metadata = $mdcParser->parse(join "", @{ $stdout_buf }) or
    526640        &my_die("Unable to parse metadata config doc", "diff", $stage_id, $PS_EXIT_PROG_ERROR);
     
    535649
    536650        my $status = 1;
    537         if ($mode eq "goto_cleaned") {
    538             my $config_file = $ipprc->filename("PPSUB.CONFIG", $path_base, $skycell_id);
    539 
    540             unless ($ipprc->file_exists($config_file)) {
    541                 print STDERR "skipping cleanup for diffRun $stage_id $skycell_id" .
    542                     " because config file ($config_file) is missing\n";
    543                 $status = 0;
    544             }
    545         }
    546         elsif ($mode eq "goto_scrubbed") {
    547             my $config_file = $ipprc->filename("PPSUB.CONFIG", $path_base, $skycell_id);
    548 
    549             if ($ipprc->file_exists($config_file)) {
    550                 print STDERR "skipping scrubbed for diffRun $stage_id $skycell_id" .
    551                     " because config file ($config_file) is present\n";
    552                 $status = 0;
     651        if ((!exists($skyfile->{path_base}))||
     652            (!defined($path_base))) {
     653            $status = 0;
     654        }
     655        if ($status) {
     656           
     657            if ($mode eq "goto_cleaned") {
     658                my $config_file = $ipprc->filename("PPSUB.CONFIG", $path_base, $skycell_id);
     659               
     660                unless ($ipprc->file_exists($config_file)) {
     661                    print STDERR "skipping cleanup for diffRun $stage_id $skycell_id" .
     662                        " because config file ($config_file) is missing\n";
     663                    $status = 0;
     664                }
     665            }
     666            elsif ($mode eq "goto_scrubbed") {
     667                my $config_file = $ipprc->filename("PPSUB.CONFIG", $path_base, $skycell_id);
     668               
     669                if ($ipprc->file_exists($config_file)) {
     670                    print STDERR "skipping scrubbed for diffRun $stage_id $skycell_id" .
     671                        " because config file ($config_file) is present\n";
     672                    $status = 0;
     673                }
    553674            }
    554675        }
     
    588709#       print STDERR "MY STATUS: $status\n";
    589710        if ($status) {
    590             my $command = "$difftool -diff_id $stage_id";
    591 
    592             if ($mode eq "goto_purged") {
    593                 $command .= " -updaterun -state purged";
     711            my $command = "$difftool -diff_id $stage_id -skycell_id $skycell_id";
     712
     713            if ($mode eq "goto_purged") {
     714                $command .= " -topurgedskyfile";
    594715            }
    595716            elsif ($mode eq "goto_cleaned") {
    596                 $command .= " -updaterun -state cleaned";
     717                $command .= " -tocleanedskyfile";
    597718            }
    598719            elsif ($mode eq "goto_scrubbed") {
    599                 $command .= " -updaterun -state scrubbed";
     720                $command .= " -toscrubbedskyfile";
    600721            }
    601722
     
    608729                &my_die("Unable to perform difftool: $error_code", "diff", $stage_id, $error_code);
    609730            }
     731
     732            # Tell magicdstool that we've cleaned up this data, so it needs to do the same if it needs to do the same.
     733            my $magicdstool = can_run('magicdstool') or die "Can't find magicdstool";
     734            $command = "$magicdstool -dbname gpc1 -stage $stage -stage_id $stage_id -updaterun -set_state goto_cleaned";
     735            ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     736                run(command => $command, verbose => $verbose);
     737            unless ($success) {
     738                $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     739                &my_die("Unable to perform magicdstool: $error_code", "$stage", $stage_id, $error_code);
     740            }
     741
    610742        } else {
    611             my $command = "$difftool -updaterun -diff_id $stage_id -state $error_state";
     743            my $command = "$difftool -updaterun -diff_id $stage_id -set_state $error_state";
    612744
    613745            $command .= " -dbname $dbname" if defined $dbname;
     
    619751                &my_die("Unable to perform difftool: $error_code", "diff", $stage_id, $error_code);
    620752            }
    621             exit $PS_EXIT_UNKNOWN_ERROR;
     753#           exit $PS_EXIT_UNKNOWN_ERROR;
    622754        }
    623755    }
     
    646778    # if there are no fakeProcessedImfiles (@$stdout_buf == 0), the reset the state to 'new'
    647779    if (@$stdout_buf == 0)  {
    648         my $command = "$faketool -fake_id $stage_id -updaterun -set_state new";
     780        my $command = "$faketool -fake_id $stage_id -updaterun -set_state $error_state";
    649781        $command .= " -dbname $dbname" if defined $dbname;
    650782
  • branches/eam_branches/20090820/ippScripts/scripts/magic_destreak_revert.pl

    • Property svn:mergeinfo changed (with no actual effect on merging)
  • branches/eam_branches/20090820/ippScripts/scripts/stack_skycell.pl

    r25766 r25870  
    304304            $command .= (" -dtime_script " . ((DateTime->now->mjd - $mjd_start) * 86400));
    305305        } else {
    306             $mode = "-updaterun -state full";
     306            $mode = "-updaterun -set_state full";
    307307        }
    308308        $command .= " $mode -stack_id $stack_id";
  • branches/eam_branches/20090820/ippTasks/addstar.pro

    r25766 r25870  
    121121    book getword addPendingExp $pageName exp_tag -var EXP_TAG
    122122    book getword addPendingExp $pageName add_id -var ADD_ID
    123     book getword addPendingExp $pageName cam_id -var CAM_ID
     123    book getword addPendingExp $pageName camroot -var CAMROOT
    124124    book getword addPendingExp $pageName workdir -var WORKDIR_TEMPLATE
     125    book getword addPendingExp $pageName reduction -var REDUCTION
    125126    book getword addPendingExp $pageName dvodb  -var DVODB
     127    book getword addPendingExp $pageName image_only -var IMAGE_ONLY
    126128    book getword addPendingExp $pageName dbname -var DBNAME
    127     book getword addPendingExp $pageName reduction -var REDUCTION
    128     book getword addPendingExp $pageName state -var RUN_STATE
    129129
    130130    # specify choice of remote host based on camera and chip (class_id)
     
    144144    ## generate outroot specific to this exposure (& chip)
    145145    sprintf outroot "%s/%s/%s.add.%s" $WORKDIR $EXP_TAG $EXP_TAG $ADD_ID
    146     sprintf camroot "%s/%s/%s.cm.%s" $WORKDIR $EXP_TAG $EXP_TAG $CAM_ID
    147146
    148147    stdout $LOGDIR/addstar.exp.log
    149148    stderr $LOGDIR/addstar.exp.log
    150149
    151     $run = addstar_run.pl --exp_tag $EXP_TAG --add_id $ADD_ID --camera $CAMERA --outroot $outroot --camroot $camroot --redirect-output --run-state $RUN_STATE
     150    $run = addstar_run.pl --exp_tag $EXP_TAG --add_id $ADD_ID --camera $CAMERA --dvodb $DVODB --camroot $CAMROOT --outroot $outroot --redirect-output
    152151    if ("$REDUCTION" != "NULL")
    153152      $run = $run --reduction $REDUCTION
    154153    end
    155     if ("$DVODB" != "NULL")
    156       $run = $run --dvodb $DVODB
    157     end
     154    if ("$IMAGE_ONLY" == "T")
     155      $run = $run --image-only
     156    end
     157   
    158158    add_standard_args run
    159159
  • branches/eam_branches/20090820/ippTasks/destreak.pro

    r25766 r25870  
    1010book init magicToDS
    1111book init magicDSToRevert
     12book init magicDSToCleanup
    1213
    1314### indexes into Database lists
     
    1617$magicDSToRevert_DB = 0
    1718$magicDSCompletedRevert_DB = 0
     19$magicDSToCleanup_DB = 0
    1820
    1921#list of stages
     
    3234    book listbook magicToDS
    3335    book listbook magicDSToRevert
     36    book init magicDSToCleanup
    3437end
    3538
     
    3841    book init magicToDS
    3942    book init magicDSToRevert
     43    book init magicDSToCleanup
    4044end
    4145
     
    7175end
    7276
     77macro destreak.cleanup.on
     78    task destreak.cleanup.load
     79        active true
     80    end
     81    task destreak.cleanup.run
     82        active true
     83    end
     84end
     85
    7386### Turn tasks off
    7487macro destreak.off
     
    92105    end
    93106    task destreak.completed.revert
     107        active false
     108    end
     109end
     110macro destreak.cleanup.off
     111    task destreak.cleanup.load
     112        active false
     113    end
     114    task destreak.cleanup.run
    94115        active false
    95116    end
     
    489510end
    490511
     512task           destreak.cleanup.load
     513  host         local
     514
     515  periods      -poll $LOADPOLL
     516  periods      -exec $LOADEXEC
     517  periods      -timeout 20
     518  npending     1
     519  active       false
     520
     521  stdout NULL
     522  stderr $LOGSUBDIR/destreak.cleanup.load.log
     523
     524  task.exec
     525    $run = magicdstool -tocleanup
     526    if ($DB:n == 0)
     527      option DEFAULT
     528    else
     529
     530      # save the DB name for the exit tasks
     531      option $DB:$magicDSToCleanup_DB
     532      $run = $run -dbname $DB:$magicDSToCleanup_DB
     533
     534      # only bump database number after we have gone through all of the stages
     535      $magicDSToCleanup_DB ++
     536      if ($magicDSToCleanup_DB >= $DB:n) set magicDSToCleanup_DB = 0
     537    end
     538    add_poll_args run
     539    add_poll_labels run
     540    command $run
     541  end
     542
     543  # success
     544  task.exit    0
     545    # convert 'stdout' to book format
     546    ipptool2book stdout magicDSToCleanup -key magic_ds_id -uniq -setword dbname $options:0 -setword pantaskState INIT
     547    if ($VERBOSE > 2)
     548      book listbook magicDSToCleanup
     549    end
     550
     551    # delete existing entries in the appropriate pantaskStates
     552    process_cleanup magicDSToCleanup
     553  end
     554
     555  # locked list
     556  task.exit    default
     557    showcommand failure
     558  end
     559
     560  task.exit    crash
     561    showcommand crash
     562  end
     563
     564  # operation times out?
     565  task.exit    timeout
     566    showcommand timeout
     567  end
     568end
     569
     570task           destreak.cleanup.run
     571  periods      -poll $RUNPOLL
     572  periods      -exec $RUNEXEC
     573  periods      -timeout 60
     574  active       false
     575
     576  task.exec
     577    stdout $LOGSUBDIR/destreak.cleanup.run.log
     578    stderr $LOGSUBDIR/destreak.cleanup.run.log
     579
     580    book npages magicDSToCleanup -var N
     581    if ($N == 0) break
     582    if ($NETWORK == 0) break
     583   
     584    # look for new images (pantaskState == INIT)
     585    book getpage magicDSToCleanup 0 -var pageName -key pantaskState INIT
     586    if ("$pageName" == "NULL") break
     587
     588    book setword magicDSToCleanup $pageName pantaskState RUN
     589    book getword magicDSToCleanup $pageName magic_ds_id -var MAGIC_DS_ID
     590    book getword magicDSToCleanup $pageName camera -var CAMERA
     591    book getword magicDSToCleanup $pageName outroot -var OUTROOT
     592    book getword magicDSToCleanup $pageName dbname -var DBNAME
     593
     594    sprintf logfile "%s/mds.%s.cleanup.log" $OUTROOT $MAGIC_DS_ID
     595
     596    host anyhost
     597
     598    $run = magic_destreak_cleanup.pl --magic_ds_id $MAGIC_DS_ID --camera $CAMERA --logfile $logfile
     599
     600    add_standard_args run
     601
     602    # save the pageName for future reference below
     603    options $pageName
     604
     605    # create the command line
     606    if ($VERBOSE > 1)
     607      echo command $run
     608    end
     609    command $run
     610  end
     611
     612  # default exit status
     613  task.exit    0
     614    process_exit magicDSToCleanup $options:0 $JOB_STATUS
     615   end
     616
     617  # locked list
     618  task.exit    default
     619    showcommand failure
     620    process_exit magicDSToCleanup $options:0 $JOB_STATUS
     621  end
     622
     623  task.exit    crash
     624    showcommand crash
     625    book setword magicDSToCleanup $options:0 pantaskState CRASH
     626  end
     627
     628  # operation timed out?
     629  task.exit    timeout
     630    showcommand timeout
     631    book setword magicDSToCleanup $options:0 pantaskState TIMEOUT
     632  end
     633end
     634
  • branches/eam_branches/20090820/ippTasks/flatcorr.pro

    r24139 r25870  
    22## this file contains the tasks for running the flatcorr stage
    33## these tasks use the book 'flatcorrBook'
    4 
    5 # test for required global variables
    6 check.globals
    7 
    8 book init flatcorrBook
    9 
    10 macro flatcorr.reset
    11   book init flatcorrBook
    12 end
    13 
    14 macro flatcorr.status
    15   book listbook flatcorrBook
    16 end
    17 
    18 macro flatcorr.on
    19   task flatcorr.addcamera
    20     active true
    21   end
    22   task flatcorr.load
    23     active true
    24   end
    25   task flatcorr.run
    26     active true
    27   end
    28 end
    29 
    30 macro flatcorr.off
    31   task flatcorr.addcamera
    32     active false
    33   end
    34   task flatcorr.load
    35     active false
    36   end
    37   task flatcorr.run
    38     active false
    39   end
    40 end
    41 
    42 # these variables will cycle through the known ippdb database names
    43 $flatcorr_addcamera_DB = 0
    44 $flatcorr_pendingprocess_DB = 0
    454
    465# a flat-field correction run is initiated (manually) with a command like:
     
    5514# as the chip analysis progresses, we need to occasionally migrate the
    5615# completed chips to the camera stage by calling:
    57 # flatcorr -addcamera
    58 
    59 # we wait for the completed chip and camera analysis and search for
     16# flatcorr -advancecamera
     17
     18# as the camera analysis progresses, we need to occasionally migrate the
     19# completed exposures to the addstar stage by calling:
     20# flatcorr -advanceaddstar
     21
     22# we wait for the completed addstar jobs and search for
    6023# completed processing analysis with:
    6124# flatcorr -pendingprocess
     
    6730# flatcorr -addprocess -fault N
    6831
     32# test for required global variables
     33check.globals
     34
     35book init flatcorrBook
     36
     37macro flatcorr.reset
     38  book init flatcorrBook
     39end
     40
     41macro flatcorr.status
     42  book listbook flatcorrBook
     43end
     44
     45macro flatcorr.on
     46  task flatcorr.advancecamera
     47    active true
     48  end
     49  task flatcorr.advanceaddstar
     50    active true
     51  end
     52  task flatcorr.load
     53    active true
     54  end
     55  task flatcorr.run
     56    active true
     57  end
     58end
     59
     60macro flatcorr.off
     61  task flatcorr.advancecamera
     62    active false
     63  end
     64  task flatcorr.advanceaddstar
     65    active false
     66  end
     67  task flatcorr.load
     68    active false
     69  end
     70  task flatcorr.run
     71    active false
     72  end
     73end
     74
     75# these variables will cycle through the known ippdb database names
     76$flatcorr_advancecamera_DB = 0
     77$flatcorr_advanceaddstar_DB = 0
     78$flatcorr_pendingprocess_DB = 0
     79
    6980# migrate complete flatcorr chips to the camera stage analysis
    70 task           flatcorr.addcamera
     81task           flatcorr.advancecamera
    7182  host         local
    7283
     
    8091    # define the command (does not depend on previous queries)
    8192    if ($DB:n == 0)
    82       command flatcorr -addcamera
     93      command flatcorr -advancecamera
    8394    else
    8495      # save the DB name for the exit tasks
    8596      # note that this DB name refers to the ippdb, not the dvodb
    86       option $DB:$flatcorr_addcamera_DB
    87       command flatcorr -addcamera -dbname $DB:$flatcorr_addcamera_DB
    88       $flatcorr_addcamera_DB ++
    89       if ($flatcorr_addcamera_DB >= $DB:n) set flatcorr_addcamera_DB = 0
     97      option $DB:$flatcorr_advancecamera_DB
     98      command flatcorr -advancecamera -dbname $DB:$flatcorr_advancecamera_DB
     99      $flatcorr_advancecamera_DB ++
     100      if ($flatcorr_advancecamera_DB >= $DB:n) set flatcorr_advancecamera_DB = 0
     101    end
     102  end
     103
     104  # silently drop stdout
     105  stdout NULL
     106  stderr $LOGDIR/flatcorr.log
     107
     108  # success (no action required)
     109  task.exit $EXIT_SUCCESS
     110  end
     111
     112  # locked list
     113  task.exit    default
     114    showcommand failure
     115  end
     116
     117  task.exit    crash
     118    showcommand crash
     119  end
     120
     121  # operation times out?
     122  task.exit    timeout
     123    showcommand timeout
     124  end
     125end
     126
     127# migrate complete flatcorr exposures to the addstar process
     128task           flatcorr.advanceaddstar
     129  host         local
     130
     131  # check the list of pending flatcorr runs
     132  periods      -poll 5
     133  periods      -exec 30
     134  periods      -timeout 60
     135  npending 1
     136
     137  task.exec
     138    # define the command (does not depend on previous queries)
     139    if ($DB:n == 0)
     140      command flatcorr -advanceaddstar
     141    else
     142      # save the DB name for the exit tasks
     143      # note that this DB name refers to the ippdb, not the dvodb
     144      option $DB:$flatcorr_advanceaddstar_DB
     145      command flatcorr -advanceaddstar -dbname $DB:$flatcorr_advanceaddstar_DB
     146      $flatcorr_advanceaddstar_DB ++
     147      if ($flatcorr_advanceaddstar_DB >= $DB:n) set flatcorr_advanceaddstar_DB = 0
    90148    end
    91149  end
  • branches/eam_branches/20090820/ippTasks/ipphosts.mhpcc.config

    r25766 r25870  
    1212  sky06 STR  ipp012
    1313  sky07 STR  ipp013
    14   sky08 STR  ipp014
     14#  sky08 STR  ipp014
     15  sky08 STR  ipp047
    1516  sky09 STR  ipp015
    1617  sky10 STR  ipp016
     
    5556  camera STR GPC1
    5657
    57   XY01  STR  ipp014
    58   XY02  STR  ipp014
     58#  XY01  STR  ipp014
     59#  XY02  STR  ipp014
     60  XY01  STR  ipp047
     61  XY02  STR  ipp047
    5962  XY03  STR  ipp038
    6063  XY04  STR  ipp038
     
    134137  camera STR gpc1
    135138
    136   ota01  STR  ipp014
    137   ota02  STR  ipp014
     139#  ota01  STR  ipp014
     140#  ota02  STR  ipp014
     141  ota01  STR  ipp047
     142  ota02  STR  ipp047
    138143  ota03  STR  ipp038
    139144  ota04  STR  ipp038
  • branches/eam_branches/20090820/ippTasks/pstamp.pro

    r25766 r25870  
    111111
    112112    task.exec
    113         stdout $LOGSUBDIR/pstamp.request.find.log
     113        stdout NULL
    114114        stderr $LOGSUBDIR/pstamp.request.find.log
    115115        if ($DB:n == 0)
  • branches/eam_branches/20090820/ippTasks/rcserver.pro

    r25766 r25870  
    129129    book getword rcPendingFS $pageName stage -var STAGE
    130130    book getword rcPendingFS $pageName stage_id -var STAGE_ID
    131     book getword rcPendingFS $pageName label -var LABEL
     131    book getword rcPendingFS $pageName dist_group -var DIST_GROUP
    132132    book getword rcPendingFS $pageName filter -var FILTER
    133133    book getword rcPendingFS $pageName dist_dir -var DIST_DIR
     
    149149    book setword rcPendingFS $pageName pantaskState RUN
    150150
    151     $run = dist_make_fileset.pl --dist_id $DIST_ID --target_id $TARGET_ID --stage $STAGE --stage_id $STAGE_ID --label $LABEL --filter $FILTER --dest_id $DEST_ID --product_name $PRODUCT_NAME  --ds_dbhost $DS_DBHOST --ds_dbname $DS_DBNAME --dist_dir $DIST_DIR
     151    $run = dist_make_fileset.pl --dist_id $DIST_ID --target_id $TARGET_ID --stage $STAGE --stage_id $STAGE_ID --dist_group $DIST_GROUP --filter $FILTER --dest_id $DEST_ID --product_name $PRODUCT_NAME  --ds_dbhost $DS_DBHOST --ds_dbname $DS_DBNAME --dist_dir $DIST_DIR
    152152
    153153    add_standard_args run
  • branches/eam_branches/20090820/ippTasks/simtest.basic.auto

    r24174 r25870  
    4747  name       STR OBJECT-i
    4848  check      STR "detselect -dbname @DBNAME@ -search    -inst @CAMERA@ -filter i -det_type FLAT"
    49   launch     STR "chiptool  -dbname @DBNAME@ -updaterun -inst @CAMERA@ -filter i -label wait -set_label proc"
     49  launch     STR "chiptool  -dbname @DBNAME@ -updaterun -inst @CAMERA@ -filter i -label wait -set_label proc -set_data_group simtest_i -set_dist_group simtest"
    5050  block      STR NONE
    5151END
     
    5454  name       STR OBJECT-r
    5555  check      STR "detselect -dbname @DBNAME@ -search    -inst @CAMERA@ -filter r -det_type FLAT"
    56   launch     STR "chiptool  -dbname @DBNAME@ -updaterun -inst @CAMERA@ -filter r -label wait -set_label proc"
     56  launch     STR "chiptool  -dbname @DBNAME@ -updaterun -inst @CAMERA@ -filter r -label wait -set_label proc -set_data_group simtest_r -set_dist_group simtest"
    5757  block      STR NONE
    5858END
     
    6161automate METADATA
    6262  name       STR STACK
    63   regular    STR "stacktool -definebyquery -all -label proc -workdir file://@CWD@/stack -min_new 4 -min_frac 2 -select_good_frac_min 0.2 -dbname @DBNAME@"
     63  regular    STR "stacktool -definebyquery -set_label proc -set_data_group simtest_r -set_dist_group simtest -set_workdir file://@CWD@/stack -min_new 4 -min_frac 2 -select_good_frac_min 0.2 -dbname @DBNAME@"
    6464END
    6565
     
    6767automate METADATA
    6868  name       STR DIFF
    69   regular    STR "difftool -definewarpstack -label proc -workdir file://@CWD@/diff -good_frac 0.2 -dbname @DBNAME@"
     69  regular    STR "difftool -definewarpstack -set_label proc -set_workdir file://@CWD@/diff -good_frac 0.2 -dbname @DBNAME@"
    7070END
    7171
  • branches/eam_branches/20090820/ippTasks/simtest.stack.auto

    r24098 r25870  
    6161automate METADATA
    6262  name       STR STACK
    63   regular    STR "stacktool -definebyquery -all -label proc -workdir file://@CWD@/stack -min_new 4 -min_frac 2 -select_good_frac_min 0.2 -dbname @DBNAME@"
     63  regular    STR "stacktool -definebyquery -label proc -workdir file://@CWD@/stack -min_new 4 -min_frac 2 -select_good_frac_min 0.2 -dbname @DBNAME@"
    6464END
    6565
  • branches/eam_branches/20090820/ippTasks/survey.pro

    r24989 r25870  
    44check.globals
    55
    6 book create SURVEY_DIFF
    7 book create SURVEY_MAGIC
     6book getbook SURVEY_DIFF -var isBook
     7if ("$isBook" == "NULL")
     8  book create SURVEY_DIFF
     9end
     10book getbook SURVEY_MAGIC -var isBook
     11if ("$isBook" == "NULL")
     12  book create SURVEY_MAGIC
     13end
    814
    915$SURVEY_DIFF_DB = 0
  • branches/eam_branches/20090820/ippTests/tap

    • Property svn:mergeinfo changed (with no actual effect on merging)
  • branches/eam_branches/20090820/ippTools/configure.ac

    r25766 r25870  
    11AC_PREREQ(2.61)
    22
    3 AC_INIT([ipptools], [1.1.37], [ipp-support@ifa.hawaii.edu])
     3AC_INIT([ipptools], [1.1.56], [ipp-support@ifa.hawaii.edu])
    44AC_CONFIG_SRCDIR([autogen.sh])
    55
     
    1818PKG_CHECK_MODULES([PSLIB], [pslib >= 1.1.0])
    1919PKG_CHECK_MODULES([PSMODULES], [psmodules >= 1.1.0])
    20 PKG_CHECK_MODULES([IPPDB], [ippdb >= 1.1.55])
     20PKG_CHECK_MODULES([IPPDB], [ippdb >= 1.1.56])
    2121
    2222PXTOOLS_CFLAGS="${PSLIB_CFLAGS=} ${PSMODULES_CFLAGS=} ${IPPDB_CFLAGS=}"
     
    5858CFLAGS="${CFLAGS=} -Wall -Werror"
    5959
     60IPPDB_VERSION=`$PKG_CONFIG --modversion ippdb`
     61AC_DEFINE_UNQUOTED(IPPDB_VERSION, $IPPDB_VERSION, [Version of ippdb])
     62
    6063AC_CONFIG_FILES([
    6164  Makefile
  • branches/eam_branches/20090820/ippTools/share/Makefile.am

    r25766 r25870  
    44
    55dist_pkgdata_DATA = \
     6     addtool_donecleanup.sql \
     7     addtool_find_cam_id.sql \
    68     addtool_find_pendingexp.sql \
     9     addtool_find_processedexp.sql \
     10     addtool_pendingcleanupexp.sql \
     11     addtool_pendingcleanuprun.sql \
    712     addtool_queue_cam_id.sql \
    813     addtool_reset_faulted_runs.sql \
     
    3136     chiptool_revertprocessedimfile.sql \
    3237     chiptool_run.sql \
     38     chiptool_runstate.sql \
    3339     chiptool_export_imfile.sql \
    3440     chiptool_export_processed_imfile.sql \
     
    8490     dettool_toresidimfile.sql \
    8591     dettool_tostacked.sql \
     92     difftool_change_skyfile_data_state.sql \
     93     difftool_change_run_state.sql \
    8694     difftool_completed_runs.sql \
    8795     difftool_definewarpstack_part1.sql \
     
    145153     faketool_unmasked.sql \
    146154     flatcorr_chiprundone.sql \
     155     flatcorr_camerarundone.sql \
    147156     flatcorr_pendingprocess.sql \
    148157     flatcorr_inputimfile.sql \
     
    182191     magicdstool_getskycells.sql \
    183192     magicdstool_revertdestreakedfile.sql \
     193     magicdstool_tocleanup.sql \
    184194     magicdstool_todestreak_camera.sql \
    185195     magicdstool_todestreak_chip.sql \
     
    196206     pstamptool_datastore.sql \
    197207     pstamptool_listjob.sql \
     208     pstamptool_pendingdependent.sql \
    198209     pstamptool_pendingjob.sql \
    199210     pstamptool_pendingreq.sql \
     
    205216     pxadmin_create_mirror_tables.sql \
    206217     pxadmin_drop_tables.sql \
     218     pxadmin_update_version.sql \
    207219     pubtool_definerun.sql \
    208220     pubtool_pending.sql \
     
    263275     warptool_revertoverlap.sql \
    264276     warptool_revertwarped_delete.sql \
     277     warptool_runstate.sql \
    265278     warptool_scmap.sql \
    266279     warptool_tooverlap.sql \
  • branches/eam_branches/20090820/ippTools/share/addtool_find_pendingexp.sql

    r25766 r25870  
    11SELECT
    22    addRun.*,
     3    camProcessedExp.path_base as camroot,
    34    rawExp.exp_tag,
    45    rawExp.exp_id,
     
    1011JOIN camRun
    1112    USING(cam_id)
     13JOIN camProcessedExp
     14    USING(cam_id)
    1215JOIN chipRun
    1316    USING(chip_id)
    14 JOIN chipProcessedImfile
    15     USING(chip_id)
    1617JOIN rawExp
    17     ON chipRun.exp_id = rawExp.exp_id
     18    USING(exp_id)
    1819LEFT JOIN addProcessedExp
    1920    USING(add_id)
     
    2324    camRun.state = 'full'
    2425    AND ((addRun.state = 'new' AND addProcessedExp.add_id IS NULL) OR addRun.state = 'update')
     26    AND addRun.dvodb IS NOT NULL
     27    AND addRun.workdir IS NOT NULL
    2528    AND addMask.label IS NULL
    2629
  • branches/eam_branches/20090820/ippTools/share/addtool_queue_cam_id.sql

    r25766 r25870  
    66        '%s',           -- workdir
    77        '%s',           -- workdir_state
     8        '%s',           -- reduction
    89        '%s',           -- label
     10        '%s',           -- data_group
    911        '%s',           -- dvodb
    10         0               -- magicked
     12        '%s',           -- note
     13        %d              -- image_only
    1114    FROM camRun
    1215    WHERE
  • branches/eam_branches/20090820/ippTools/share/camtool_find_processedexp.sql

    r24512 r25870  
    22    camProcessedExp.*,
    33    camRun.workdir,
     4    camRun.label,
    45    chipRun.chip_id,
    56    rawExp.exp_tag,
  • branches/eam_branches/20090820/ippTools/share/camtool_queue_chip_id.sql

    r24681 r25870  
    99        '%s',           -- workdir_state
    1010        '%s',           -- label
     11        '%s',           -- data_group
     12        '%s',           -- dist_group
    1113        '%s',           -- reduction
    1214        '%s',           -- expgroup
     
    1416        '%s',           -- tess_id
    1517        '%s',           -- end_stage
    16         0               -- magicked
     18        0,              -- magicked
     19        '%s'           -- note
    1720    FROM chipRun
    1821    WHERE
  • branches/eam_branches/20090820/ippTools/share/chiptool_completely_processed_exp.sql

    r23688 r25870  
    77    workdir_state,
    88    label,
     9    data_group,
     10    dist_group,
    911    reduction,
    1012    expgroup,
     
    1214    tess_id,
    1315    end_stage,
    14     all_files_magicked as magicked
     16    all_files_magicked as magicked,
     17    note
    1518FROM
    1619    (SELECT
  • branches/eam_branches/20090820/ippTools/share/chiptool_processedimfile.sql

    r25127 r25870  
    1212    chipRun.state,
    1313    chipRun.workdir,
     14    chipRun.label,
    1415    rawExp.exp_id,
    1516    rawExp.exp_tag,
  • branches/eam_branches/20090820/ippTools/share/chiptool_run.sql

    r18075 r25870  
    22    chipRun.*
    33FROM chipRun
     4JOIN rawExp
     5    USING(exp_id)
  • branches/eam_branches/20090820/ippTools/share/difftool_pendingcleanuprun.sql

    r24186 r25870  
    11-- does this result in too many entries (one for each diffInputSkyfile?)
    22-- all of this is just to get the camera used for the diff run
    3 SELECT
    4     diffRun.diff_id,
    5     rawExp.camera,
    6     diffRun.state
    7 FROM diffRun
    8 JOIN diffInputSkyfile
    9     USING(diff_id)
    10 JOIN warpSkyfile
    11     ON  diffInputSkyfile.warp1    = warpSkyfile.warp_id
    12     AND diffInputSkyfile.skycell_id = warpSkyfile.skycell_id
    13     AND diffInputSkyfile.tess_id    = warpSkyfile.tess_id
    14 JOIN warpRun
    15     ON warpRun.warp_id = warpSkyfile.warp_id
    16 JOIN fakeRun
    17     USING(fake_id)
    18 JOIN camRun
    19     USING(cam_id)
    20 JOIN chipRun
    21     USING(chip_id)
    22 JOIN rawExp
    23     USING(exp_id)
    24 WHERE
    25     (diffRun.state = 'goto_cleaned' OR diffRun.state = 'goto_scrubbed' OR diffRun.state = 'goto_purged')
     3SELECT DISTINCT * FROM
     4   (SELECT
     5            diffRun.diff_id,
     6            rawExp.camera,
     7            diffRun.state,
     8            diffRun.label
     9        FROM diffRun
     10        JOIN diffInputSkyfile
     11            USING(diff_id)
     12        JOIN warpSkyfile
     13            ON  diffInputSkyfile.warp1    = warpSkyfile.warp_id
     14            AND diffInputSkyfile.skycell_id = warpSkyfile.skycell_id
     15            AND diffInputSkyfile.tess_id    = warpSkyfile.tess_id
     16        JOIN warpRun
     17            ON warpRun.warp_id = warpSkyfile.warp_id
     18        JOIN fakeRun
     19            USING(fake_id)
     20        JOIN camRun
     21            USING(cam_id)
     22        JOIN chipRun
     23            USING(chip_id)
     24        JOIN rawExp
     25            USING(exp_id)
     26        WHERE
     27            (diffRun.state = 'goto_cleaned' OR
     28             diffRun.state = 'goto_scrubbed' OR
     29             diffRun.state = 'goto_purged')
     30     UNION
     31     SELECT
     32            diffRun.diff_id,
     33            rawExp.camera,
     34            diffRun.state,
     35            diffRun.label
     36        FROM diffRun
     37        JOIN diffInputSkyfile
     38            USING(diff_id)
     39        JOIN warpSkyfile
     40            ON  diffInputSkyfile.warp2    = warpSkyfile.warp_id
     41            AND diffInputSkyfile.skycell_id = warpSkyfile.skycell_id
     42            AND diffInputSkyfile.tess_id    = warpSkyfile.tess_id
     43        JOIN warpRun
     44            ON warpRun.warp_id = warpSkyfile.warp_id
     45        JOIN fakeRun
     46            USING(fake_id)
     47        JOIN camRun
     48            USING(cam_id)
     49        JOIN chipRun
     50            USING(chip_id)
     51        JOIN rawExp
     52            USING(exp_id)
     53        WHERE
     54            (diffRun.state = 'goto_cleaned' OR
     55             diffRun.state = 'goto_scrubbed' OR
     56             diffRun.state = 'goto_purged')
     57     UNION
     58     SELECT
     59            diffRun.diff_id,
     60            rawExp.camera,
     61            diffRun.state,
     62            diffRun.label
     63        FROM diffRun
     64        JOIN diffInputSkyfile
     65            USING(diff_id)
     66        JOIN stackSumSkyfile
     67            ON  diffInputSkyfile.stack1 = stackSumSkyfile.stack_id
     68        JOIN stackInputSkyfile
     69            ON diffInputSkyfile.stack1 = stackInputSkyfile.stack_id
     70        JOIN warpRun
     71            ON warpRun.warp_id = stackInputSkyfile.warp_id
     72        JOIN fakeRun
     73            USING(fake_id)
     74        JOIN camRun
     75            USING(cam_id)
     76        JOIN chipRun
     77            USING(chip_id)
     78        JOIN rawExp
     79            USING(exp_id)
     80        WHERE
     81            (diffRun.state = 'goto_cleaned' OR
     82             diffRun.state = 'goto_scrubbed' OR
     83             diffRun.state = 'goto_purged')
     84     UNION
     85     SELECT
     86            diffRun.diff_id,
     87            rawExp.camera,
     88            diffRun.state,
     89            diffRun.label
     90        FROM diffRun
     91        JOIN diffInputSkyfile
     92            USING(diff_id)
     93        JOIN stackSumSkyfile
     94            ON  diffInputSkyfile.stack2 = stackSumSkyfile.stack_id
     95        JOIN stackInputSkyfile
     96            ON diffInputSkyfile.stack2 = stackInputSkyfile.stack_id
     97        JOIN warpRun
     98            ON warpRun.warp_id = stackInputSkyfile.warp_id
     99        JOIN fakeRun
     100            USING(fake_id)
     101        JOIN camRun
     102            USING(cam_id)
     103        JOIN chipRun
     104            USING(chip_id)
     105        JOIN rawExp
     106            USING(exp_id)
     107        WHERE
     108            (diffRun.state = 'goto_cleaned' OR
     109             diffRun.state = 'goto_scrubbed' OR
     110             diffRun.state = 'goto_purged')
     111        ) as Foo
     112        WHERE 1
  • branches/eam_branches/20090820/ippTools/share/difftool_skyfile.sql

    r25766 r25870  
    55    diffRun.state,
    66    diffRun.workdir,
     7    diffRun.label,
    78    diffRun.bothways,
    89    warp1,
  • branches/eam_branches/20090820/ippTools/share/disttool_definebyquery_camera.sql

    r25766 r25870  
    44    rawExp.exp_name as run_tag,
    55    camRun.magicked,
    6     distTarget.label,
     6    camRun.label,
     7    distTarget.dist_group,
    78    distTarget.target_id,
    89    distTarget.clean
     
    1213JOIN distTarget ON distTarget.stage = 'camera'
    1314    AND rawExp.filter = distTarget.filter
    14     AND camRun.label  = distTarget.label
     15    AND camRun.dist_group  = distTarget.dist_group
    1516JOIN rcInterest USING(target_id)
    1617LEFT JOIN distRun ON distRun.stage = 'camera'
  • branches/eam_branches/20090820/ippTools/share/disttool_definebyquery_chip.sql

    r25766 r25870  
    55    rawExp.exp_name as run_tag,
    66    chipRun.label,
     7    chipRun.dist_group,
    78    distTarget.target_id,
    89    distTarget.clean
     
    1011JOIN rawExp USING(exp_id)
    1112JOIN distTarget ON distTarget.stage = 'chip'
    12     AND chipRun.label = distTarget.label
     13    AND chipRun.dist_group = distTarget.dist_group
    1314    AND rawExp.filter = distTarget.filter
    1415JOIN rcInterest USING(target_id)
  • branches/eam_branches/20090820/ippTools/share/disttool_definebyquery_diff.sql

    r25766 r25870  
    44    diffRun.magicked,
    55    rawExp.exp_name as run_tag,
    6     distTarget.label,
     6    diffRun.label,
     7    distTarget.dist_group,
    78    distTarget.target_id,
    89    distTarget.clean
     
    1516JOIN rawExp USING(exp_id)
    1617JOIN distTarget ON distTarget.stage = 'diff'
    17     AND diffRun.label = distTarget.label
     18    AND diffRun.dist_group = distTarget.dist_group
    1819    AND distTarget.filter = rawExp.filter
    1920JOIN rcInterest USING(target_id)
  • branches/eam_branches/20090820/ippTools/share/disttool_definebyquery_fake.sql

    r25766 r25870  
    44    CAST(0 AS SIGNED) AS magicked,
    55    rawExp.exp_name as run_tag,
    6     distTarget.label,
     6    fakeRun.label,
     7    distTarget.dist_group,
    78    distTarget.target_id,
    89    distTarget.clean
     
    1112JOIN chipRun USING(chip_id)
    1213JOIN rawExp USING(exp_id)
    13 JOIN distTarget ON distTarget.stage = 'fake' AND fakeRun.label = distTarget.label
     14JOIN distTarget ON distTarget.stage = 'fake' AND fakeRun.dist_group = distTarget.dist_group
    1415    AND rawExp.filter = distTarget.filter
    1516JOIN rcInterest USING(target_id)
  • branches/eam_branches/20090820/ippTools/share/disttool_definebyquery_raw.sql

    r25766 r25870  
    44    rawExp.exp_name AS run_tag,
    55    rawExp.magicked,
    6     distTarget.label,
     6    chipRun.label,
     7    distTarget.dist_group,
    78    distTarget.target_id,
    89    distTarget.clean
    910FROM rawExp
    1011JOIN chipRun USING(exp_id)
    11 JOIN distTarget ON distTarget.label = chipRun.label AND distTarget.stage = 'raw'
     12JOIN distTarget ON distTarget.dist_group = chipRun.dist_group AND distTarget.stage = 'raw'
    1213    AND rawExp.filter = distTarget.filter
    1314JOIN rcInterest USING(target_id)
  • branches/eam_branches/20090820/ippTools/share/disttool_definebyquery_stack.sql

    r25766 r25870  
    55    -- run tag in the form 'stack.$skycell_id.$stack_id'
    66    CONCAT_WS('.', 'stack', stackRun.skycell_id, convert(stackRun.stack_id, CHAR)) as run_tag,
    7     distTarget.label,
     7    stackRun.label,
     8    distTarget.dist_group,
    89    distTarget.target_id,
    910    distTarget.clean
     
    1112JOIN stackSumSkyfile USING(stack_id)
    1213JOIN distTarget ON distTarget.stage = 'stack'
    13     AND stackRun.label = distTarget.label
     14    AND stackRun.dist_group = distTarget.dist_group
    1415    AND stackRun.filter = distTarget.filter
    1516JOIN rcInterest USING(target_id)
  • branches/eam_branches/20090820/ippTools/share/disttool_definebyquery_warp.sql

    r25766 r25870  
    44    warpRun.magicked,
    55    rawExp.exp_name as run_tag,
    6     distTarget.label,
     6    warpRun.label,
     7    distTarget.dist_group,
    78    distTarget.target_id,
    89    distTarget.clean
     
    1314JOIN rawExp USING(exp_id)
    1415JOIN distTarget ON distTarget.stage = 'warp'
    15     AND warpRun.label = distTarget.label
     16    AND warpRun.dist_group = distTarget.dist_group
    1617    AND rawExp.filter = distTarget.filter
    1718JOIN rcInterest USING(target_id)
  • branches/eam_branches/20090820/ippTools/share/disttool_defineinterest.sql

    r25766 r25870  
    11INSERT INTO rcInterest
    2     SELECT 0, dest_id, target_id, '@STATE@'
     2    SELECT 0, rcDestination.dest_id, distTarget.target_id, '@STATE@'
    33    FROM distTarget
    44        JOIN rcDestination
  • branches/eam_branches/20090820/ippTools/share/disttool_pending_camera.sql

    r25766 r25870  
    22    distRun.dist_id,
    33    distRun.label,
     4    distTarget.dist_group,
    45    stage,
    56    stage_id,
     
    1617    chipRun.magicked
    1718FROM distRun
     19JOIN distTarget USING(target_id, stage, clean)
    1820JOIN camRun ON camRun.cam_id = distRun.stage_id
    1921JOIN camProcessedExp USING(cam_id)
  • branches/eam_branches/20090820/ippTools/share/disttool_pending_chip.sql

    r25766 r25870  
    22    distRun.dist_id,
    33    distRun.label,
     4    distTarget.dist_group,
    45    stage,
    56    stage_id,
    67    chipProcessedImfile.class_id AS component,
    7     clean,
     8    distRun.clean,
    89    rawExp.camera,
    910    CONCAT_WS('.', outroot, CONVERT(distRun.dist_id, CHAR)) as outdir,
     
    1617    chipProcessedImfile.magicked
    1718FROM distRun
     19JOIN distTarget USING(target_id, stage, clean)
    1820JOIN chipRun ON chipRun.chip_id = distRun.stage_id
    1921JOIN rawExp using(exp_id)
  • branches/eam_branches/20090820/ippTools/share/disttool_pending_diff.sql

    r25766 r25870  
    22    distRun.dist_id,
    33    distRun.label,
     4    distTarget.dist_group,
    45    stage,
    56    stage_id,
     
    1819    diffSkyfile.magicked
    1920FROM distRun
     21JOIN distTarget USING(target_id, stage, clean)
    2022JOIN diffRun ON stage_id = diff_id
    2123JOIN diffSkyfile using(diff_id)
  • branches/eam_branches/20090820/ippTools/share/disttool_pending_fake.sql

    r25766 r25870  
    22    distRun.dist_id,
    33    distRun.label,
     4    distTarget.dist_group,
    45    stage,
    56    stage_id,
     
    1617    0
    1718FROM distRun
     19JOIN distTarget USING(target_id, stage, clean)
    1820JOIN fakeRun ON fakeRun.fake_id = distRun.stage_id
    1921JOIN fakeProcessedImfile USING(fake_id)
  • branches/eam_branches/20090820/ippTools/share/disttool_pending_raw.sql

    r25766 r25870  
    22    distRun.dist_id,
    33    distRun.label,
     4    distTarget.dist_group,
    45    stage,
    56    stage_id,
     
    1617    rawImfile.magicked
    1718FROM distRun
     19JOIN distTarget USING(target_id, stage, clean)
    1820JOIN rawExp ON rawExp.exp_id = stage_id
    1921JOIN rawImfile USING(exp_id)
     
    3537    distRun.dist_id,
    3638    distRun.label,
     39    distTarget.dist_group,
    3740    stage,
    3841    stage_id,
     
    4952    rawExp.magicked
    5053FROM distRun
     54JOIN distTarget USING(target_id, stage, clean)
    5155JOIN rawExp ON exp_id = stage_id
    5256LEFT JOIN distComponent
  • branches/eam_branches/20090820/ippTools/share/disttool_pending_stack.sql

    r25766 r25870  
    22    distRun.dist_id,
    33    distRun.label,
     4    distTarget.dist_group,
    45    stage,
    56    stage_id,
     
    1819    0 AS magicked
    1920FROM distRun
     21JOIN distTarget USING(target_id, stage, clean)
    2022JOIN stackRun
    2123    ON stage_id = stack_id
  • branches/eam_branches/20090820/ippTools/share/disttool_pending_warp.sql

    r25766 r25870  
    22    distRun.dist_id,
    33    distRun.label,
     4    distTarget.dist_group,
    45    stage,
    56    stage_id,
     
    1617    warpSkyfile.magicked
    1718FROM distRun
     19JOIN distTarget USING(target_id, stage, clean)
    1820JOIN warpRun ON stage_id = warp_id
    1921JOIN warpSkyfile using(warp_id)
  • branches/eam_branches/20090820/ippTools/share/disttool_pendingfileset.sql

    r25766 r25870  
    44    distRun.stage,
    55    stage_id,
    6     distTarget.label,
     6    distTarget.dist_group,
    77    distTarget.filter,
    88    CONCAT_WS('.', distRun.outroot, CONVERT(distRun.dist_id, CHAR)) as dist_dir,
  • branches/eam_branches/20090820/ippTools/share/faketool_completely_processed_exp.sql

    r20608 r25870  
    66    workdir,
    77    label,
     8    data_group,
     9    dist_group,
    810    reduction,
    911    expgroup,
     
    1113    tess_id,
    1214    end_stage,
    13     epoch
     15    epoch,
     16    note
    1417FROM
    1518    (SELECT
  • branches/eam_branches/20090820/ippTools/share/faketool_queue_cam_id.sql

    r19092 r25870  
    66        '%s',           -- workdir
    77        '%s',           -- label
     8        '%s',           -- data_group
     9        '%s',           -- dist_group
    810        '%s',           -- reduction
    911        '%s',           -- expgroup
     
    1113        '%s',           -- tess_id
    1214        '%s',           -- end_stage
    13         NULL            -- epoch
     15        NULL,           -- epoch
     16        '%s'            -- note
    1417    FROM camRun
    1518    WHERE
  • branches/eam_branches/20090820/ippTools/share/flatcorr_chiprundone.sql

    r20397 r25870  
    11SELECT
    22    corr_id,
    3     cam_id,
    43    chipRun.*
    54FROM flatcorrRun
     
    1413    AND flatcorrChipLink.include = 1
    1514    AND chipRun.state = 'full'
    16     AND camRun.cam_id is NULL;
     15    AND camRun.cam_id is NULL
  • branches/eam_branches/20090820/ippTools/share/flatcorr_pendingprocess.sql

    r20397 r25870  
    1010  reduction,
    1111  region,
    12   chip_count,
    13   cam_count
     12  cam_count,
     13  add_count
    1414FROM
    1515  (SELECT
    1616     flatcorrRun.*,
    17      flatcorrChipLink.corr_id as chip_corr_id,
    18      count(flatcorrChipLink.chip_id) as chip_count
     17     flatcorrCamLink.corr_id as cam_corr_id,
     18     count(flatcorrCamLink.cam_id) as cam_count
    1919   FROM flatcorrRun
    20    JOIN flatcorrChipLink
    21      ON flatcorrChipLink.corr_id = flatcorrRun.corr_id
    22   WHERE flatcorrChipLink.include = 1
     20   JOIN flatcorrCamLink
     21  USING (corr_id)
     22  WHERE flatcorrCamLink.include = 1
    2323   GROUP BY
    24      flatcorrChipLink.corr_id) AS t1
     24     flatcorrCamLink.corr_id) AS t1
    2525LEFT JOIN
    2626  (SELECT
    27      flatcorrCamLink.corr_id as cam_corr_id,
    28      count(flatcorrCamLink.cam_id) as cam_count
    29    FROM flatcorrCamLink
    30    JOIN camRun
    31        ON flatcorrCamLink.cam_id = camRun.cam_id
    32    WHERE camRun.state = 'full'
    33      AND flatcorrCamLink.include = 1
     27     flatcorrAddstarLink.corr_id as add_corr_id,
     28     count(flatcorrAddstarLink.add_id) as add_count
     29   FROM flatcorrAddstarLink
     30   JOIN addRun
     31   USING (add_id)
     32   WHERE addRun.state = 'full'
     33     AND flatcorrAddstarLink.include = 1
    3434   GROUP BY
    35        flatcorrCamLink.corr_id) AS t2
    36 ON t1.chip_corr_id = t2.cam_corr_id
    37 WHERE chip_count = cam_count
     35       flatcorrAddstarLink.corr_id) AS t2
     36ON t1.cam_corr_id = t2.add_corr_id
     37WHERE cam_count = add_count
    3838AND state = 'new'
  • branches/eam_branches/20090820/ippTools/share/pstamptool_pendingjob.sql

    r25766 r25870  
    11SELECT pstampJob.*
    22FROM pstampJob
    3     JOIN pstampRequest using(req_id)
     3    JOIN pstampRequest USING(req_id)
     4    LEFT JOIN pstampDependent USING(dep_id)
    45WHERE pstampRequest.state = 'run'
    56    AND pstampRequest.fault = 0
    67    AND pstampJob.state = 'run'
    78    AND pstampJob.fault = 0
     9    AND (dep_id = 0 OR pstampDependent.state = 'full')
  • branches/eam_branches/20090820/ippTools/share/pxadmin_create_tables.sql

    r25766 r25870  
     1CREATE TABLE dbversion (
     2    schema_version VARCHAR(64),
     3    updated TIMESTAMP DEFAULT CURRENT_TIMESTAMP
     4) ENGINE=innodb DEFAULT CHARSET=latin1;
     5
    16CREATE TABLE pzDataStore (
    27    camera VARCHAR(64),
     
    261266    workdir_state VARCHAR(64),
    262267    label VARCHAR(64),
     268    data_group VARCHAR(64),
     269    dist_group VARCHAR(64),
    263270    reduction VARCHAR(64),
    264      expgroup VARCHAR(64),
     271    expgroup VARCHAR(64),
    265272    dvodb VARCHAR(255),
    266273    tess_id VARCHAR(64),
    267274    end_stage VARCHAR(64),
    268275    magicked BIGINT,
     276    note VARCHAR(255),
    269277    PRIMARY KEY(chip_id),
    270278    KEY(chip_id), KEY(exp_id),
     
    272280    KEY(workdir_state),
    273281    KEY(label),
     282    KEY(data_group),
     283    KEY(dist_group),
    274284    KEY(expgroup),
    275285    KEY(end_stage),
     
    367377    workdir_state VARCHAR(64),
    368378    label VARCHAR(64),
     379    data_group VARCHAR(64),
     380    dist_group VARCHAR(64),
    369381    reduction VARCHAR(64),
    370382    expgroup VARCHAR(64),
     
    373385    end_stage VARCHAR(64),
    374386    magicked BIGINT,
     387    note VARCHAR(255),
    375388    PRIMARY KEY(cam_id),
    376389    KEY(cam_id),
     
    379392    KEY(workdir_state),
    380393    KEY(label),
     394    KEY(data_group),
     395    KEY(dist_group),
    381396    KEY(expgroup),
    382397    KEY(end_stage),
     
    464479    workdir VARCHAR(255),
    465480    workdir_state VARCHAR(64),
     481    reduction VARCHAR(64),
    466482    label VARCHAR(64),
     483    data_group VARCHAR(64),
    467484    dvodb VARCHAR(255),
    468     magicked BIGINT,
     485    note  VARCHAR(255),
     486    image_only TINYINT,
    469487    PRIMARY KEY(add_id),
    470488    KEY(add_id),
     
    473491    KEY(workdir_state),
    474492    KEY(label),
     493    KEY(data_group),
    475494    INDEX(add_id, cam_id),
    476495    FOREIGN KEY(cam_id) REFERENCES camRun(cam_id)
     
    480499    add_id BIGINT AUTO_INCREMENT,
    481500    dtime_addstar FLOAT,
    482     n_stars INT,
    483501    path_base VARCHAR(255),
    484502    fault SMALLINT NOT NULL,
     
    498516    workdir VARCHAR(255),
    499517    label VARCHAR(64),
     518    data_group VARCHAR(64),
     519    dist_group VARCHAR(64),
    500520    reduction VARCHAR(64),
    501521    expgroup VARCHAR(64),
     
    504524    end_stage VARCHAR(64),
    505525    epoch TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
     526    note VARCHAR(255),
    506527    PRIMARY KEY(fake_id),
    507528    KEY(cam_id),
    508529    KEY(state),
    509530    KEY(label),
     531    KEY(data_group),
     532    KEY(dist_group),
    510533    KEY(expgroup),
    511534    KEY(end_stage),
     
    834857    workdir_state VARCHAR(64),
    835858    label VARCHAR(64),
     859    data_group VARCHAR(64),
     860    dist_group VARCHAR(64),
    836861    dvodb VARCHAR(255),
    837862    tess_id VARCHAR(64),
     
    840865    registered DATETIME,
    841866    magicked BIGINT,
     867    note VARCHAR(255),
    842868    PRIMARY KEY(warp_id),
    843869    KEY(warp_id),
     
    847873    KEY(workdir_state),
    848874    KEY(label),
     875    KEY(data_group),
     876    KEY(dist_group),
    849877    KEY(end_stage),
    850878    INDEX(warp_id, fake_id),
     
    910938        workdir VARCHAR(255),
    911939        label VARCHAR(64),
     940        data_group VARCHAR(64),
     941        dist_group VARCHAR(64),
    912942        reduction VARCHAR(64),
    913943        dvodb VARCHAR(255),
     
    916946        tess_id VARCHAR(64),
    917947        filter VARCHAR(64),
     948        note VARCHAR(255),
    918949        PRIMARY KEY(stack_id),
    919950        KEY(stack_id),
     
    921952        KEY(skycell_id),
    922953        KEY(tess_id),
    923         KEY(label)
     954        KEY(label),
     955        KEY(data_group),
     956        KEY(dist_group)
    924957) ENGINE=innodb DEFAULT CHARSET=latin1;
    925958
     
    9731006        workdir VARCHAR(255),
    9741007        label VARCHAR(64),
     1008        data_group VARCHAR(64),
     1009        dist_group VARCHAR(64),
    9751010        reduction VARCHAR(64),
    9761011        dvodb VARCHAR(255),
     
    9801015        exposure TINYINT DEFAULT 0,
    9811016        magicked BIGINT,
     1017        note VARCHAR(255),
    9821018        PRIMARY KEY(diff_id),
    9831019        KEY(diff_id),
    9841020        KEY(state),
    9851021        KEY(tess_id),
    986         KEY(label)
     1022        KEY(label),
     1023        KEY(data_group),
     1024        KEY(dist_group)
    9871025) ENGINE=innodb DEFAULT CHARSET=latin1;
    9881026
     
    10551093        workdir_state VARCHAR(255),
    10561094        label VARCHAR(64),
     1095        data_group VARCHAR(64),
    10571096        dvodb VARCHAR(255),
    10581097        registered DATETIME,
    10591098        fault SMALLINT,
     1099        note VARCHAR(255),
    10601100        PRIMARY KEY(magic_id),
    10611101        KEY(magic_id),
     
    10631103        KEY(workdir_state),
    10641104        KEY(label),
     1105        KEY(data_group),
    10651106        KEY(fault),
    10661107        FOREIGN KEY(exp_id)  REFERENCES rawExp(exp_id),
     
    11181159        cam_id BIGINT,
    11191160        label VARCHAR(64),
     1161        data_group VARCHAR(64),
    11201162        outroot VARCHAR(255),
    11211163        recoveryroot VARCHAR(255),
    11221164        re_place TINYINT,
    11231165        remove TINYINT,
     1166        fault SMALLINT,
     1167        note VARCHAR(255),
    11241168        PRIMARY KEY(magic_ds_id),
    11251169        KEY(magic_ds_id),
     
    11271171        KEY(magic_id),
    11281172        KEY(label),
     1173        KEY(fault),
    11291174        FOREIGN KEY(magic_id) REFERENCES magicRun(magic_id),
    11301175        FOREIGN KEY(inv_magic_id) REFERENCES magicRun(magic_id)
     
    11821227) ENGINE=innodb DEFAULT CHARSET=latin1;
    11831228
    1184 -- these two tables link the flatcorrRun to the associated chip and camera runs
     1229-- these three tables link the flatcorrRun to the associated chip, camera, and addstar runs
    11851230CREATE TABLE flatcorrChipLink (
    11861231        corr_id BIGINT,
     
    12011246        FOREIGN KEY(chip_id) REFERENCES chipRun(chip_id),
    12021247        FOREIGN KEY(cam_id) REFERENCES camRun(cam_id)
     1248) ENGINE=innodb DEFAULT CHARSET=latin1;
     1249
     1250CREATE TABLE flatcorrAddstarLink (
     1251        corr_id BIGINT,
     1252        cam_id BIGINT,
     1253        add_id BIGINT,
     1254        include TINYINT,
     1255        PRIMARY KEY(corr_id, cam_id, add_id),
     1256        FOREIGN KEY (corr_id)  REFERENCES  flatcorrRun(corr_id),
     1257        FOREIGN KEY (cam_id)  REFERENCES  camRun(cam_id),
     1258        FOREIGN KEY (add_id)  REFERENCES  addRun(add_id)
    12031259) ENGINE=innodb DEFAULT CHARSET=latin1;
    12041260
     
    12501306        outputBase VARCHAR(255),
    12511307        options BIGINT,
     1308        dep_id BIGINT,
    12521309        PRIMARY KEY(job_id, req_id),
    12531310        KEY(job_id),
     
    12551312) ENGINE=innodb DEFAULT CHARSET=latin1;
    12561313
     1314CREATE TABLE pstampDependent (
     1315        dep_id BIGINT AUTO_INCREMENT,
     1316        state      VARCHAR(64),
     1317        stage      VARCHAR(64),
     1318        stage_id   BIGINT,
     1319        imagedb    VARCHAR(64),
     1320        rlabel     VARCHAR(64),
     1321        no_magic   TINYINT,
     1322        PRIMARY KEY(dep_id)
     1323) ENGINE=innodb DEFAULT CHARSET=latin1;
     1324
    12571325CREATE TABLE distTarget (
    12581326    target_id   BIGINT AUTO_INCREMENT,
    1259     label       VARCHAR(64),
     1327    dist_group  VARCHAR(64),
    12601328    filter      VARCHAR(64),
    12611329    stage       VARCHAR(64),
     
    12641332    comment     VARCHAR(255),
    12651333    PRIMARY KEY(target_id),
    1266     CONSTRAINT UNIQUE (label, filter, stage, clean)
     1334    CONSTRAINT UNIQUE (dist_group, filter, stage, clean)
    12671335)  ENGINE=innodb DEFAULT CHARSET=latin1;
    12681336
     
    12801348    time_stamp  TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    12811349    fault       SMALLINT,
     1350    note        VARCHAR(255),
    12821351    PRIMARY KEY(dist_id),
    12831352    KEY(state),
  • branches/eam_branches/20090820/ippTools/share/pxadmin_drop_tables.sql

    r25766 r25870  
    11SET FOREIGN_KEY_CHECKS=0;
    22
     3DROP TABLE IF EXISTS dbversion;
    34DROP TABLE IF EXISTS pzDataStore;
    45DROP TABLE IF EXISTS summitExp;
     
    5960DROP TABLE IF EXISTS flatcorrChipLink;
    6061DROP TABLE IF EXISTS flatcorrCamLink;
     62DROP TABLE IF EXISTS flatcorrAddstarLink;
    6163DROP TABLE IF EXISTS pstampDataStore;
    6264DROP TABLE IF EXISTS pstampProject;
     
    7880DROP TABLE IF EXISTS publishRun;
    7981DROP TABLE IF EXISTS publishDone;
     82DROP TABLE IF EXISTS pstampDependent;
    8083
    8184SET FOREIGN_KEY_CHECKS=1
  • branches/eam_branches/20090820/ippTools/share/warptool_warped.sql

    r24112 r25870  
    33    warpRun.state,
    44    warpRun.workdir,
     5    warpRun.label,
    56    warpImfile.warp_skyfile_id,
    67    rawExp.exp_id,
  • branches/eam_branches/20090820/ippTools/src/Makefile.am

    r25766 r25870  
    3434        pxmagic.h \
    3535        pxregister.h \
     36        pxspace.h \
    3637        pxtag.h \
    3738        pxtools.h \
     
    7879        pxmagic.c \
    7980        pxregister.c \
     81        pxspace.c \
    8082        pxtag.c \
    8183        pxtools.c \
  • branches/eam_branches/20090820/ippTools/src/addtool.c

    r25766 r25870  
    4040static bool maskedMode(pxConfig *config);
    4141static bool unblockMode(pxConfig *config);
    42 static bool pendingcleanuprunMode(pxConfig *config);
    43 static bool pendingcleanupexpMode(pxConfig *config);
    44 static bool donecleanupMode(pxConfig *config);
    45 static bool exportrunMode(pxConfig *config);
    46 static bool importrunMode(pxConfig *config);
    4742
    4843# define MODECASE(caseName, func) \
     
    7469        MODECASE(ADDTOOL_MODE_MASKED,               maskedMode);
    7570        MODECASE(ADDTOOL_MODE_UNBLOCK,              unblockMode);
    76         MODECASE(ADDTOOL_MODE_PENDINGCLEANUPRUN,    pendingcleanuprunMode);
    77         MODECASE(ADDTOOL_MODE_PENDINGCLEANUPEXP,    pendingcleanupexpMode);
    78         MODECASE(ADDTOOL_MODE_DONECLEANUP,          donecleanupMode);
    79         MODECASE(ADDTOOL_MODE_EXPORTRUN,            exportrunMode);
    80         MODECASE(ADDTOOL_MODE_IMPORTRUN,            importrunMode);
    8171        default:
    8272            psAbort("invalid option (this should not happen)");
     
    10696
    10797    psMetadata *where = psMetadataAlloc();
    108     pxaddGetSearchArgs (config, where);
    109     pxAddLabelSearchArgs (config, where, "-label", "addRun.label", "==");
    110     PXOPT_COPY_STR(config->args, where, "-reduction", "addRun.reduction", "==");
     98    pxcamGetSearchArgs (config, where);
     99    PXOPT_COPY_S64(config->args, where,  "-cam_id",    "camRun.cam_id", "==");
     100    pxAddLabelSearchArgs (config, where, "-label",     "camRun.label", "==");
     101    PXOPT_COPY_STR(config->args, where,  "-reduction", "camRun.reduction", "==");
    111102
    112103    if (!psListLength(where->list) &&
     
    117108    }
    118109
    119     PXOPT_LOOKUP_STR(workdir, config->args, "-set_workdir", false, false);
    120     PXOPT_LOOKUP_STR(label, config->args, "-set_label", false, false);
    121     PXOPT_LOOKUP_STR(reduction, config->args, "-set_reduction", false, false);
    122     PXOPT_LOOKUP_STR(dvodb, config->args, "-set_dvodb", false, false);
     110    PXOPT_LOOKUP_STR(workdir,     config->args, "-set_workdir", false, false);
     111    PXOPT_LOOKUP_STR(dvodb,       config->args, "-set_dvodb", false, false);
     112    PXOPT_LOOKUP_STR(label,       config->args, "-set_label", false, false);
     113    PXOPT_LOOKUP_STR(data_group,  config->args, "-set_data_group", false, false);
     114    PXOPT_LOOKUP_STR(reduction,   config->args, "-set_reduction", false, false);
     115    PXOPT_LOOKUP_STR(note,        config->args, "-set_note", false, false);
     116    PXOPT_LOOKUP_BOOL(image_only, config->args, "-image_only", false);
     117    PXOPT_LOOKUP_BOOL(pretend,    config->args, "-pretend", false);
     118    PXOPT_LOOKUP_BOOL(simple,     config->args, "-simple", false);
    123119
    124120    // find the cam_id of all the exposures that we want to queue up.
     
    130126    }
    131127
    132     // use psDBGenerateWhereSQL because the SQL yields an intermediate table
     128    // use psDBGenerateWhereConditionSQL because the SQL ends in a WHERE
    133129    if (where && psListLength(where->list)) {
    134130        psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
     
    136132        psFree(whereClause);
    137133    }
    138 
    139134    psFree(where);
    140135
     
    155150        psFree(output);
    156151        return true;
     152    }
     153
     154    if (pretend) {
     155        // negative simple so the default is true
     156        if (!ippdbPrintMetadatas(stdout, output, "addRun", !simple)) {
     157            psError(PS_ERR_UNKNOWN, false, "failed to print array");
     158            psFree(output);
     159            return false;
     160        }
     161        psFree(output);
     162        return true;
     163    }
     164
     165    // loop over our list of camRun rows to check the supplied and selected dvodb and workdir values:
     166    for (long i = 0; i < psArrayLength(output); i++) {
     167        psMetadata *md = output->data[i];
     168
     169        camRunRow *row = camRunObjectFromMetadata(md);
     170        if (!row) {
     171            psError(PS_ERR_UNKNOWN, false, "failed to convert metadata into camRun");
     172            psFree(output);
     173            return false;
     174        }
     175
     176        if (!dvodb && !row->dvodb) {
     177            psError(PS_ERR_UNKNOWN, false, "cannot queue addstar run without a defined dvodb: label: %s, cam_id %" PRId64, row->label, row->cam_id);
     178            psFree(output);
     179            return false;
     180        }
     181        if (!workdir && !row->workdir) {
     182            psError(PS_ERR_UNKNOWN, false, "cannot queue addstar run without a defined workdir: label: %s, cam_id %" PRId64, row->label, row->cam_id);
     183            psFree(output);
     184            return false;
     185        }
     186
     187        psFree(row);
    157188    }
    158189
     
    170201    // old values in place (i.e., passing the values through).
    171202
    172 
    173     // loop over our list of addRun rows
     203    // loop over our list of camRun rows
    174204    for (long i = 0; i < psArrayLength(output); i++) {
    175205        psMetadata *md = output->data[i];
    176206
    177         addRunRow *row = addRunObjectFromMetadata(md);
     207        camRunRow *row = camRunObjectFromMetadata(md);
    178208        if (!row) {
    179             psError(PS_ERR_UNKNOWN, false, "failed to convert metadata into addRun");
     209            psError(PS_ERR_UNKNOWN, false, "failed to convert metadata into camRun");
    180210            psFree(output);
    181211            return false;
     
    186216                               row->cam_id,
    187217                               workdir     ? workdir   : row->workdir,
     218                               reduction   ? reduction : row->reduction,
    188219                               label       ? label     : row->label,
    189                                "RECIPE",
    190                                dvodb       ? dvodb     : row->dvodb
    191                                
     220                               data_group  ? data_group : (label ? label : row->label),
     221                               dvodb       ? dvodb     : row->dvodb,
     222                               note        ? note      : NULL,
     223                               image_only
    192224        )) {
    193225            if (!psDBRollback(config->dbh)) {
     
    218250
    219251    psMetadata *where = psMetadataAlloc();
    220     pxaddGetSearchArgs (config, where);
    221252    PXOPT_COPY_S64(config->args, where, "-add_id",    "addRun.add_id", "==");
     253    PXOPT_COPY_S64(config->args, where, "-cam_id",    "camRun.cam_id", "==");
     254    pxcamGetSearchArgs (config, where); // most search arguments based on camera
    222255    PXOPT_COPY_STR(config->args, where, "-label",     "addRun.label", "==");
    223256    PXOPT_COPY_STR(config->args, where, "-state",     "addRun.state", "==");
    224257    PXOPT_COPY_STR(config->args, where, "-reduction", "addRun.reduction", "==");
    225258
    226     if (!psListLength(where->list)
    227         && !psMetadataLookupBool(NULL, config->args, "-all")) {
     259    if (!psListLength(where->list)) {
    228260        psFree(where);
    229261        psError(PXTOOLS_ERR_DATA, false, "search parameters are required");
     
    231263    }
    232264
     265    psString query = psStringCopy("UPDATE addRun JOIN camRun USING(cam_id) JOIN chipRun USING(chip_id) JOIN rawExp USING(exp_id)");
     266
     267    // pxUpdateRun gets parameters from config->args and runs the update query
     268    bool result = pxUpdateRun(config, where, &query, "addRun", false);
     269
     270    psFree(query);
     271    psFree(where);
     272
     273    return result;
     274
     275
     276#ifdef notdef
    233277    PXOPT_LOOKUP_STR(state, config->args, "-set_state", false, false);
    234278    PXOPT_LOOKUP_STR(label, config->args, "-set_label", false, false);
     
    259303
    260304    return true;
     305#endif
    261306}
    262307
     
    267312
    268313    psMetadata *where = psMetadataAlloc();
    269     pxaddGetSearchArgs (config, where);
    270314    PXOPT_COPY_S64(config->args, where, "-add_id",    "addRun.add_id", "==");
     315    PXOPT_COPY_S64(config->args, where, "-cam_id",    "camRun.cam_id", "==");
     316    pxcamGetSearchArgs (config, where);
    271317    pxAddLabelSearchArgs (config, where, "-label", "addRun.label", "==");
    272318    PXOPT_COPY_STR(config->args, where, "-reduction", "addRun.reduction", "==");
    273 
    274319    PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
    275320    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
     
    325370}
    326371
    327 /* static bool pendingimfileMode(pxConfig *config) */
    328 /* { */
    329 /*     PS_ASSERT_PTR_NON_NULL(config, false); */
    330 
    331 /*     psMetadata *where = psMetadataAlloc(); */
    332 /*     pxaddGetSearchArgs (config, where); */
    333 /*     PXOPT_COPY_S64(config->args, where, "-add_id",    "addRun.add_id",                "=="); */
    334 /*     pxAddLabelSearchArgs (config, where, "-label",    "addRun.label",                 "=="); */
    335 /*     PXOPT_COPY_STR(config->args, where, "-reduction", "addRun.reduction",             "=="); */
    336 /*     PXOPT_COPY_S64(config->args, where, "-chip_id",   "addRun.chip_id",              "=="); */
    337 /*     PXOPT_COPY_STR(config->args, where, "-class_id",  "addProcessedExp.class_id", "=="); */
    338 
    339 /*     PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); */
    340 
    341 /*     psString query = pxDataGet("addtool_find_pendingimfile.sql"); */
    342 /*     if (!query) { */
    343 /*         psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement"); */
    344 /*         return false; */
    345 /*     } */
    346 
    347 /*     // use psDBGenerateWhereSQL because the SQL yields an intermediate table */
    348 /*     if (psListLength(where->list)) { */
    349 /*         psString whereClause = psDBGenerateWhereConditionSQL(where, NULL); */
    350 /*         psStringAppend(&query, " AND %s", whereClause); */
    351 /*         psFree(whereClause); */
    352 /*     } */
    353 /*     psFree(where); */
    354 
    355 /*     if (!p_psDBRunQuery(config->dbh, query)) { */
    356 /*         psError(PS_ERR_UNKNOWN, false, "database error"); */
    357 /*         psFree(query); */
    358 /*         return false; */
    359 /*     } */
    360 /*     psFree(query); */
    361 
    362 /*     psArray *output = p_psDBFetchResult(config->dbh); */
    363 /*     if (!output) { */
    364 /*         psError(PS_ERR_UNKNOWN, false, "database error"); */
    365 /*         return false; */
    366 /*     } */
    367 /*     if (!psArrayLength(output)) { */
    368 /*         psTrace("addtool", PS_LOG_INFO, "no rows found"); */
    369 /*         psFree(output); */
    370 /*         return true; */
    371 /*     } */
    372 
    373 /*     // negate simple so the default is true */
    374 /*     if (!ippdbPrintMetadatas(stdout, output, "addProcessedExp", !simple)) { */
    375 /*         psError(PS_ERR_UNKNOWN, false, "failed to print array"); */
    376 /*         psFree(output); */
    377 /*         return false; */
    378 /*     } */
    379 
    380 /*     psFree(output); */
    381 
    382 /*     return true; */
    383 /* } */
    384 
    385372static bool addprocessedexpMode(pxConfig *config)
    386373{
     
    391378
    392379    // optional
    393     PXOPT_LOOKUP_F32(dtime_addstar, config->args,  "-dtime_addstar", false, false);
    394 
    395     PXOPT_LOOKUP_S32(n_stars, config->args,        "-n_stars", false, false);
    396 
    397     PXOPT_LOOKUP_STR(path_base, config->args, "-path_base", false, false);
    398 
    399     PXOPT_LOOKUP_S64(magicked, config->args, "-magicked", false, false);
     380    PXOPT_LOOKUP_STR(path_base,     config->args, "-path_base", false, false);
     381    PXOPT_LOOKUP_F32(dtime_addstar, config->args, "-dtime_addstar", false, false);
     382    PXOPT_LOOKUP_S16(fault,         config->args, "-fault", false, false);
    400383
    401384    // generate restrictions
     
    446429        pendingRow->add_id,
    447430        dtime_addstar,
    448         n_stars,
    449431        path_base,
    450         0
     432        fault
    451433        );
    452434
     
    463445
    464446    // since there is only one exp per 'new' set addRun.state = 'full'
    465     if (!pxaddRunSetState(config, row->add_id, "full", magicked)) {
     447    if (!pxaddRunSetState(config, row->add_id, "full")) {
    466448        psError(PS_ERR_UNKNOWN, false, "failed to change addRun.state for add_id: %" PRId64, row->add_id);
    467449        psFree(row);
     
    469451        return false;
    470452    }
    471 
    472     // NULL for end_stage means go as far as possible
    473     // EAM : skip here if fault != 0
    474     // Also, we can run fake even if tess_id is not defined
    475 /*     if (fault || (pendingRow->end_stage && psStrcasestr(pendingRow->end_stage, "add"))) { */
    476 /*         psFree(row); */
    477 /*         psFree(pendingRow); */
    478 /*         if (!psDBCommit(config->dbh)) { */
    479 /*             psError(PS_ERR_UNKNOWN, false, "database error"); */
    480 /*             return false; */
    481 /*         } */
    482 /*         return true; */
    483 /*     } */
    484453    psFree(row);
    485     // else continue on...
    486 
    487 /*     if (!pxfakeQueueByAddID(config, */
    488 /*             pendingRow->add_id, */
    489 /*             pendingRow->workdir, */
    490 /*             pendingRow->label, */
    491 /*             pendingRow->reduction, */
    492 /*             pendingRow->expgroup, */
    493 /*             pendingRow->dvodb, */
    494 /*             pendingRow->tess_id, */
    495 /*             pendingRow->end_stage */
    496 /*     )) { */
    497 /*         // rollback */
    498 /*         if (!psDBRollback(config->dbh)) { */
    499 /*             psError(PS_ERR_UNKNOWN, false, "database error"); */
    500 /*         } */
    501 /*         psError(PS_ERR_UNKNOWN, false, "failed to queue new fakeRun"); */
    502 /*         psFree(pendingRow); */
    503 /*         return false; */
    504 /*     } */
    505454    psFree(pendingRow);
    506455
     
    517466{
    518467    PS_ASSERT_PTR_NON_NULL(config, false);
     468
     469    // generate restrictions
     470    psMetadata *where = psMetadataAlloc();
     471    PXOPT_COPY_S64(config->args, where, "-add_id",    "addRun.add_id",    "==");
     472    PXOPT_COPY_S64(config->args, where, "-cam_id",    "camRun.cam_id",    "==");
     473    pxcamGetSearchArgs (config, where);
     474    pxAddLabelSearchArgs (config, where, "-label",    "addRun.label",     "==");
     475    PXOPT_COPY_STR(config->args, where, "-reduction", "addRun.reduction", "==");
    519476
    520477    PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
    521478    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
    522479    PXOPT_LOOKUP_BOOL(faulted, config->args, "-faulted", false);
    523 
    524     // generate restrictions
    525     psMetadata *where = psMetadataAlloc();
    526     pxaddGetSearchArgs (config, where);
    527     PXOPT_COPY_S64(config->args, where, "-add_id",    "addRun.add_id",    "==");
    528     pxAddLabelSearchArgs (config, where, "-label",    "addRun.label",     "==");
    529     PXOPT_COPY_STR(config->args, where, "-reduction", "addRun.reduction", "==");
    530480
    531481    if (!psListLength(where->list) &&
     
    613563
    614564    psMetadata *where = psMetadataAlloc();
    615     pxaddGetSearchArgs (config, where);
    616565    PXOPT_COPY_S64(config->args, where, "-add_id",    "addRun.add_id",         "==");
     566    PXOPT_COPY_S64(config->args, where, "-cam_id",    "camRun.cam_id",         "==");
     567    pxcamGetSearchArgs (config, where);
    617568    pxAddLabelSearchArgs (config, where, "-label",    "addRun.label",     "==");
    618569    PXOPT_COPY_STR(config->args, where, "-reduction", "addRun.reduction",      "==");
    619 /*     PXOPT_COPY_S16(config->args, where, "-fault", "addProcessedExp.fault", "=="); */
    620570
    621571    if (!psListLength(where->list) && !psMetadataLookupBool(NULL, config->args, "-all")) {
     
    705655    PS_ASSERT_PTR_NON_NULL(config, false);
    706656
    707     PXOPT_LOOKUP_S16(fault, config->args, "-fault", true, false);
    708 
    709657    psMetadata *where = psMetadataAlloc();
    710658    PXOPT_COPY_S64(config->args, where, "-add_id",   "add_id",   "==");
    711659    PXOPT_COPY_S64(config->args, where, "-cam_id",  "cam_id",  "==");
    712 /*     PXOPT_COPY_STR(config->args, where, "-class",    "class",    "=="); */
    713 /*     PXOPT_COPY_STR(config->args, where, "-class_id", "class_id", "=="); */
     660    PXOPT_LOOKUP_S16(fault, config->args, "-fault", true, false);
    714661
    715662    if (!pxSetFaultCode(config->dbh, "addProcessedExp", where, fault)) {
     
    777724}
    778725
    779 
    780726static bool unblockMode(pxConfig *config)
    781727{
     
    793739    return true;
    794740}
    795 
    796 static bool pendingcleanuprunMode(pxConfig *config)
    797 {
    798     PS_ASSERT_PTR_NON_NULL(config, NULL);
    799 
    800     PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
    801     PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
    802 
    803     psMetadata *where = psMetadataAlloc();
    804     pxAddLabelSearchArgs (config, where, "-label", "addRun.label", "==");
    805 
    806     psString query = pxDataGet("addtool_pendingcleanuprun.sql");
    807     if (!query) {
    808         psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
    809         return false;
    810     }
    811 
    812     if (where && psListLength(where->list)) {
    813         psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
    814         psStringAppend(&query, " AND %s", whereClause);
    815         psFree(whereClause);
    816     }
    817     psFree(where);
    818 
    819     // treat limit == 0 as "no limit"
    820     if (limit) {
    821         psString limitString = psDBGenerateLimitSQL(limit);
    822         psStringAppend(&query, " %s", limitString);
    823         psFree(limitString);
    824     }
    825 
    826     if (!p_psDBRunQuery(config->dbh, query)) {
    827         psError(PS_ERR_UNKNOWN, false, "database error");
    828         psFree(query);
    829         return false;
    830     }
    831     psFree(query);
    832 
    833     psArray *output = p_psDBFetchResult(config->dbh);
    834     if (!output) {
    835         psError(PS_ERR_UNKNOWN, false, "database error");
    836         return false;
    837     }
    838     if (!psArrayLength(output)) {
    839         psTrace("addtool", PS_LOG_INFO, "no rows found");
    840         psFree(output);
    841         return true;
    842     }
    843 
    844     // negative simple so the default is true
    845     if (!ippdbPrintMetadatas(stdout, output, "addPendingCleanupRun", !simple)) {
    846         psError(PS_ERR_UNKNOWN, false, "failed to print array");
    847         psFree(output);
    848         return false;
    849     }
    850 
    851     psFree(output);
    852 
    853     return true;
    854 }
    855 
    856 
    857 static bool pendingcleanupexpMode(pxConfig *config)
    858 {
    859     PS_ASSERT_PTR_NON_NULL(config, NULL);
    860 
    861     PXOPT_LOOKUP_S64(add_id, config->args, "-add_id", false, false);
    862     PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
    863     PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
    864 
    865     psMetadata *where = psMetadataAlloc();
    866     if (add_id) {
    867         PXOPT_COPY_S64(config->args, where, "-add_id", "add_id", "==");
    868     }
    869     pxAddLabelSearchArgs (config, where, "-label", "label", "==");
    870 
    871     psString query = pxDataGet("addtool_pendingcleanupexp.sql");
    872     if (!query) {
    873         psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
    874         return false;
    875     }
    876 
    877     if (where && psListLength(where->list)) {
    878         psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
    879         psStringAppend(&query, " AND %s", whereClause);
    880         psFree(whereClause);
    881     }
    882     psFree(where);
    883 
    884     // treat limit == 0 as "no limit"
    885     if (limit) {
    886         psString limitString = psDBGenerateLimitSQL(limit);
    887         psStringAppend(&query, " %s", limitString);
    888         psFree(limitString);
    889     }
    890 
    891     if (!p_psDBRunQuery(config->dbh, query)) {
    892         psError(PS_ERR_UNKNOWN, false, "database error");
    893         psFree(query);
    894         return false;
    895     }
    896     psFree(query);
    897 
    898     psArray *output = p_psDBFetchResult(config->dbh);
    899     if (!output) {
    900         psError(PS_ERR_UNKNOWN, false, "database error");
    901         return false;
    902     }
    903     if (!psArrayLength(output)) {
    904         psTrace("chiptool", PS_LOG_INFO, "no rows found");
    905         psFree(output);
    906         return true;
    907     }
    908 
    909     // negative simple so the default is true
    910     if (!ippdbPrintMetadatas(stdout, output, "addPendingCleanupExp", !simple)) {
    911         psError(PS_ERR_UNKNOWN, false, "failed to print array");
    912         psFree(output);
    913         return false;
    914     }
    915 
    916     psFree(output);
    917 
    918     return true;
    919 }
    920 
    921 
    922 static bool donecleanupMode(pxConfig *config)
    923 {
    924     PS_ASSERT_PTR_NON_NULL(config, NULL);
    925 
    926     PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
    927     PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
    928 
    929     psMetadata *where = psMetadataAlloc();
    930     PXOPT_COPY_STR(config->args, where, "-label", "label", "==");
    931 
    932     psString query = pxDataGet("addtool_donecleanup.sql");
    933     if (!query) {
    934         psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
    935         return false;
    936     }
    937 
    938     if (where && psListLength(where->list)) {
    939         psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
    940         psStringAppend(&query, " AND %s", whereClause);
    941         psFree(whereClause);
    942     }
    943     psFree(where);
    944 
    945     // treat limit == 0 as "no limit"
    946     if (limit) {
    947         psString limitString = psDBGenerateLimitSQL(limit);
    948         psStringAppend(&query, " %s", limitString);
    949         psFree(limitString);
    950     }
    951 
    952     if (!p_psDBRunQuery(config->dbh, query)) {
    953         psError(PS_ERR_UNKNOWN, false, "database error");
    954         psFree(query);
    955         return false;
    956     }
    957     psFree(query);
    958 
    959     psArray *output = p_psDBFetchResult(config->dbh);
    960     if (!output) {
    961         psError(PS_ERR_UNKNOWN, false, "database error");
    962         return false;
    963     }
    964     if (!psArrayLength(output)) {
    965         psTrace("addtool", PS_LOG_INFO, "no rows found");
    966         psFree(output);
    967         return true;
    968     }
    969 
    970     // negative simple so the default is true
    971     if (!ippdbPrintMetadatas(stdout, output, "addDoneCleanup", !simple)) {
    972         psError(PS_ERR_UNKNOWN, false, "failed to print array");
    973         psFree(output);
    974         return false;
    975     }
    976 
    977     psFree(output);
    978 
    979     return true;
    980 }
    981 
    982 bool exportrunMode(pxConfig *config)
    983 {
    984   typedef struct ExportTable {
    985     char tableName[80];
    986     char sqlFilename[80];
    987   } ExportTable;
    988 
    989   int numExportTables = 2;
    990 
    991   PS_ASSERT_PTR_NON_NULL(config, NULL);
    992 
    993   PXOPT_LOOKUP_S64(det_id, config->args, "-add_id", true,  false);
    994   PXOPT_LOOKUP_STR(outfile, config->args, "-outfile", true,  false);
    995   PXOPT_LOOKUP_U64(limit,   config->args, "-limit",   false, false);
    996   PXOPT_LOOKUP_BOOL(clean, config->args, "-clean", false);
    997 
    998   FILE *f = fopen (outfile, "w");
    999   if (f == NULL) {
    1000     psError(PS_ERR_UNKNOWN, false, "failed to open output file");
    1001     return false;
    1002   }
    1003 
    1004   psMetadata *where = psMetadataAlloc();
    1005   PXOPT_COPY_S64(config->args, where, "-add_id", "add_id", "==");
    1006 
    1007   ExportTable tables [] = {
    1008     {"addRun", "addtool_export_run.sql"},
    1009     {"addProcessedExp", "addtool_export_processed_exp.sql"},
    1010   };
    1011 
    1012   for (int i=0; i < numExportTables; i++) {
    1013     psString query = pxDataGet(tables[i].sqlFilename);
    1014     if (!query) {
    1015       psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
    1016       return false;
    1017     }
    1018 
    1019     if (where && psListLength(where->list)) {
    1020       psString whereClause = psDBGenerateWhereSQL(where, NULL);
    1021       psStringAppend(&query, " %s", whereClause);
    1022       psFree(whereClause);
    1023     }
    1024 
    1025     // treat limit == 0 as "no limit"
    1026     if (limit) {
    1027       psString limitString = psDBGenerateLimitSQL(limit);
    1028       psStringAppend(&query, " %s", limitString);
    1029       psFree(limitString);
    1030     }
    1031 
    1032     if (!p_psDBRunQuery(config->dbh, query)) {
    1033       psError(PS_ERR_UNKNOWN, false, "database error");
    1034       psFree(query);
    1035       return false;
    1036     }
    1037     psFree(query);
    1038 
    1039     psArray *output = p_psDBFetchResult(config->dbh);
    1040     if (!output) {
    1041       psError(PS_ERR_UNKNOWN, false, "database error");
    1042       return false;
    1043     }
    1044     if (!psArrayLength(output)) {
    1045       psError(PS_ERR_UNKNOWN, true, "no rows found");
    1046       psFree(output);
    1047       return false;
    1048     }
    1049 
    1050     if (clean) {
    1051         if (!strcmp(tables[i].tableName, "addRun")) {
    1052             if (!pxSetStateCleaned("addRun", "state", output)) {
    1053                 psFree(output);
    1054                 psError(PS_ERR_UNKNOWN, false, "pxSetStateClean failed for table %s",  tables[i].tableName);
    1055                 return false;
    1056             }
    1057         }
    1058     }
    1059 
    1060     // we must write the export table in non-simple (true) format
    1061     if (!ippdbPrintMetadatas(f, output, tables[i].tableName, true)) {
    1062       psError(PS_ERR_UNKNOWN, false, "failed to print array");
    1063       psFree(output);
    1064       return false;
    1065     }
    1066     psFree(output);
    1067   }
    1068 
    1069   fclose (f);
    1070 
    1071   return true;
    1072 }
    1073 
    1074 bool importrunMode(pxConfig *config)
    1075 {
    1076   unsigned int nFail;
    1077 
    1078   PS_ASSERT_PTR_NON_NULL(config, NULL);
    1079 
    1080   PXOPT_LOOKUP_STR(infile, config->args, "-infile", true,  false);
    1081 
    1082   psMetadata *input = psMetadataConfigRead (NULL, &nFail, infile, false);
    1083 
    1084   fprintf (stdout, "---- input ----\n");
    1085   psMetadataPrint (stderr, input, 1);
    1086 
    1087   psMetadataItem *item = psMetadataLookup (input, "addRun");
    1088   psAssert (item, "entry not in input?");
    1089   psAssert (item->type == PS_DATA_METADATA_MULTI, "entry not multi?");
    1090 
    1091   psMetadataItem *entry = psListGet (item->data.list, 0);
    1092   assert (entry);
    1093   assert (entry->type == PS_DATA_METADATA);
    1094   addRunRow *addRun = addRunObjectFromMetadata (entry->data.md);
    1095   addRunInsertObject (config->dbh, addRun);
    1096 
    1097   // fprintf (stdout, "---- add run ----\n");
    1098   // psMetadataPrint (stderr, entry->data.md, 1);
    1099 
    1100   item = psMetadataLookup (input, "addProcessedExp");
    1101   psAssert (item, "entry not in input?");
    1102   psAssert (item->type == PS_DATA_METADATA_MULTI, "entry not multi?");
    1103 
    1104   for (int i = 0; i < item->data.list->n; i++) {
    1105     psMetadataItem *entry = psListGet (item->data.list, i);
    1106     assert (entry);
    1107     assert (entry->type == PS_DATA_METADATA);
    1108     addProcessedExpRow *addProcessedExp = addProcessedExpObjectFromMetadata (entry->data.md);
    1109     addProcessedExpInsertObject (config->dbh, addProcessedExp);
    1110 
    1111     // fprintf (stdout, "---- row %d ----\n", i);
    1112     // psMetadataPrint (stderr, entry->data.md, 1);
    1113   }
    1114 
    1115   return true;
    1116 }
  • branches/eam_branches/20090820/ippTools/src/addtoolConfig.c

    r25766 r25870  
    4848
    4949    // -definebyquery
    50     // XXX need to allow multiple chip_ids
    51     // XXX need to allow multiple exp_ids
    5250    psMetadata *definebyqueryArgs = psMetadataAlloc();
     51    psMetadataAddS64(definebyqueryArgs, PS_LIST_TAIL, "-cam_id",             0, "search by cam_id", 0);
    5352    pxcamSetSearchArgs(definebyqueryArgs);
    54     psMetadataAddStr(definebyqueryArgs, PS_LIST_TAIL, "-label", PS_META_DUPLICATE_OK, "search by chipRun label", NULL);
    55     psMetadataAddStr(definebyqueryArgs, PS_LIST_TAIL, "-reduction",          0, "search by chipRun reduction class", NULL);
     53    psMetadataAddStr(definebyqueryArgs, PS_LIST_TAIL, "-label", PS_META_DUPLICATE_OK, "search by camRun label", NULL);
     54    psMetadataAddStr(definebyqueryArgs, PS_LIST_TAIL, "-reduction",          0, "search by camRun reduction class", NULL);
    5655
    5756    psMetadataAddStr(definebyqueryArgs, PS_LIST_TAIL, "-set_workdir",        0, "define workdir", NULL);
     
    5958    psMetadataAddStr(definebyqueryArgs, PS_LIST_TAIL, "-set_reduction",      0, "define reduction class", NULL);
    6059    psMetadataAddStr(definebyqueryArgs, PS_LIST_TAIL, "-set_dvodb",          0, "define DVO db", NULL);
     60    psMetadataAddBool(definebyqueryArgs, PS_LIST_TAIL, "-image_only",        0, "addstar image metadata but not detections", false);
     61    psMetadataAddBool(definebyqueryArgs, PS_LIST_TAIL, "-pretend",           0, "do not actually modify the database", false);
     62    psMetadataAddBool(definebyqueryArgs, PS_LIST_TAIL, "-simple",            0, "use the simple output format", false);
     63
     64    psMetadataAddStr(definebyqueryArgs, PS_LIST_TAIL, "-set_data_group", 0,   "define new data_group", NULL);
     65    psMetadataAddStr(definebyqueryArgs, PS_LIST_TAIL, "-set_dist_group", 0,   "define new dist_group", NULL);
     66    psMetadataAddStr(definebyqueryArgs, PS_LIST_TAIL, "-set_note", 0,         "define new note", NULL);
    6167    psMetadataAddBool(definebyqueryArgs, PS_LIST_TAIL, "-all",               0, "allow everything to be queued without search terms", false);
    6268
    6369    // -updaterun
    64     // XXX need to allow multiple add_ids
    65     // XXX need to allow multiple chip_ids
    66     // XXX need to allow multiple exp_ids
    6770    psMetadata *updaterunArgs = psMetadataAlloc();
     71    psMetadataAddS64(updaterunArgs, PS_LIST_TAIL, "-add_id",                 0, "search by add_id", 0);
     72    psMetadataAddS64(updaterunArgs, PS_LIST_TAIL, "-cam_id",                 0, "search by cam_id", 0);
    6873    pxcamSetSearchArgs(updaterunArgs);
    69     psMetadataAddS64(updaterunArgs, PS_LIST_TAIL, "-add_id",             0, "search by add_id", 0);
    70     psMetadataAddStr(updaterunArgs, PS_LIST_TAIL, "-label",              0, "search by camRun label", NULL);
    71     psMetadataAddStr(updaterunArgs, PS_LIST_TAIL, "-state",              0, "search by camRun state", NULL);
    72     psMetadataAddStr(updaterunArgs, PS_LIST_TAIL, "-reduction",          0, "search by camRun reduction class", NULL);
    73     psMetadataAddBool(updaterunArgs, PS_LIST_TAIL, "-all",               0, "allow everything to be queued without search terms", false);
    74     psMetadataAddStr(updaterunArgs, PS_LIST_TAIL, "-set_state",          0, "set state", NULL);
    75     psMetadataAddStr(updaterunArgs, PS_LIST_TAIL, "-set_label",          0, "set label", NULL);
    76 
     74    psMetadataAddStr(updaterunArgs, PS_LIST_TAIL, "-label",                  0, "search by addRun label", NULL);
     75    psMetadataAddStr(updaterunArgs, PS_LIST_TAIL, "-state",                  0, "search by addRun state", NULL);
     76    psMetadataAddStr(updaterunArgs, PS_LIST_TAIL, "-reduction",              0, "search by addRun reduction class", NULL);
     77    psMetadataAddBool(updaterunArgs, PS_LIST_TAIL, "-all",                   0, "allow everything to be queued without search terms", false);
     78    psMetadataAddStr(updaterunArgs, PS_LIST_TAIL, "-set_state",              0, "set state", NULL);
     79    psMetadataAddStr(updaterunArgs, PS_LIST_TAIL, "-set_label",              0, "set label", NULL);
     80    psMetadataAddStr(updaterunArgs, PS_LIST_TAIL, "-set_data_group", 0,   "define new data_group", NULL);
     81    psMetadataAddStr(updaterunArgs, PS_LIST_TAIL, "-set_dist_group", 0,   "define new dist_group", NULL);
     82    psMetadataAddStr(updaterunArgs, PS_LIST_TAIL, "-set_note", 0,         "define new note", NULL);
    7783    // -pendingexp
    7884    psMetadata *pendingexpArgs = psMetadataAlloc();
    79     pxcamSetSearchArgs(pendingexpArgs);
    8085    psMetadataAddS64(pendingexpArgs, PS_LIST_TAIL, "-add_id",            0, "search by add_id", 0);
    8186    psMetadataAddS64(pendingexpArgs, PS_LIST_TAIL, "-cam_id",            0, "search by cam_id", 0);
    82     psMetadataAddStr(pendingexpArgs, PS_LIST_TAIL, "-label", PS_META_DUPLICATE_OK, "search by camRun label", NULL);
    83     psMetadataAddStr(pendingexpArgs, PS_LIST_TAIL, "-reduction",         0, "search by camRun reduction class", NULL);
     87    pxcamSetSearchArgs(pendingexpArgs);
     88    psMetadataAddStr(pendingexpArgs, PS_LIST_TAIL, "-label", PS_META_DUPLICATE_OK, "search by addRun label", NULL);
     89    psMetadataAddStr(pendingexpArgs, PS_LIST_TAIL, "-reduction",         0, "search by addRun reduction class", NULL);
    8490    psMetadataAddU64(pendingexpArgs, PS_LIST_TAIL, "-limit",             0, "limit result set to N items", 0);
    8591    psMetadataAddBool(pendingexpArgs, PS_LIST_TAIL, "-simple",           0, "use the simple output format", false);
    86 
    87     // XXX is this used? psMetadataAddStr(pendingimfileArgs, PS_LIST_TAIL, "-class",    0,            "search by class", NULL);
    8892
    8993    // -addprocessedexp
    9094    psMetadata *addprocessedexpArgs = psMetadataAlloc();
    9195    psMetadataAddS64(addprocessedexpArgs, PS_LIST_TAIL, "-add_id", 0,            "define addtool ID (required)", 0);
     96    psMetadataAddStr(addprocessedexpArgs, PS_LIST_TAIL, "-path_base", 0,            "define base output location", NULL);
     97    psMetadataAddF32(addprocessedexpArgs, PS_LIST_TAIL, "-dtime_addstar", 0, "define elapsed time for DVO insertion (seconds)", NAN);
     98    psMetadataAddS16(addprocessedexpArgs, PS_LIST_TAIL, "-fault",  0,            "set fault code", 0);
    9299
    93     psMetadataAddF32(addprocessedexpArgs, PS_LIST_TAIL, "-dtime_addstar", 0, "define elapsed time for DVO insertion (seconds)", NAN);
    94     psMetadataAddS32(addprocessedexpArgs, PS_LIST_TAIL, "-n_stars", 0,            "define number of stars", 0);
    95 
    96     psMetadataAddStr(addprocessedexpArgs, PS_LIST_TAIL, "-path_base", 0,            "define base output location", NULL);
    97     psMetadataAddS64(addprocessedexpArgs, PS_LIST_TAIL, "-magicked", 0,             "set magicked", 0);
    98100    // -processedexp
    99101    psMetadata *processedexpArgs = psMetadataAlloc();
     102    psMetadataAddS64(processedexpArgs, PS_LIST_TAIL, "-add_id",   0,            "search by add_id", 0);
     103    psMetadataAddS64(processedexpArgs, PS_LIST_TAIL, "-cam_id",   0,            "search by cam_id", 0);
    100104    pxcamSetSearchArgs(processedexpArgs);
    101     psMetadataAddS64(processedexpArgs, PS_LIST_TAIL, "-add_id",   0,            "search by add_id", 0);
    102105    psMetadataAddStr(processedexpArgs, PS_LIST_TAIL, "-label", PS_META_DUPLICATE_OK, "search by addRun label", NULL);
    103106    psMetadataAddStr(processedexpArgs, PS_LIST_TAIL, "-reduction",0,            "search by addRun reduction class", NULL);
    104107
    105108    psMetadataAddU64(processedexpArgs, PS_LIST_TAIL, "-limit",    0,            "limit result set to N items", 0);
     109    psMetadataAddBool(processedexpArgs, PS_LIST_TAIL, "-simple",  0,            "use the simple output format", false);
     110    psMetadataAddBool(processedexpArgs, PS_LIST_TAIL, "-faulted", 0,            "only return imfiles with a fault status set", false);
    106111    psMetadataAddBool(processedexpArgs, PS_LIST_TAIL, "-all",     0,            "list everything without restriction", false);
    107     psMetadataAddBool(processedexpArgs, PS_LIST_TAIL, "-simple",  0,            "use the simple output format", false);
    108 /*     psMetadataAddBool(processedexpArgs, PS_LIST_TAIL, "-faulted", 0,            "only return imfiles with a fault status set", false); */
    109112
    110113    // -revertprocessedexp
    111     // XXX need to allow multiple add_ids
    112     // XXX need to allow multiple chip_ids
    113     // XXX need to allow multiple exp_ids
    114114    psMetadata *revertprocessedexpArgs = psMetadataAlloc();
     115    psMetadataAddS64(revertprocessedexpArgs, PS_LIST_TAIL, "-add_id",   0,            "search by add_id", 0);
     116    psMetadataAddS64(revertprocessedexpArgs, PS_LIST_TAIL, "-cam_id",   0,            "search by cam_id", 0);
    115117    pxcamSetSearchArgs(revertprocessedexpArgs);
    116     psMetadataAddS64(revertprocessedexpArgs, PS_LIST_TAIL, "-add_id",   0,            "search by add_id", 0);
    117118    psMetadataAddStr(revertprocessedexpArgs, PS_LIST_TAIL, "-label",    PS_META_DUPLICATE_OK, "search by addRun label", NULL);
    118119    psMetadataAddStr(revertprocessedexpArgs, PS_LIST_TAIL, "-reduction",0,            "search by addRun reduction class", NULL);
     
    121122
    122123    // -updateprocessedexp
    123     // XXX allow full search options?
    124124    psMetadata *updateprocessedexpArgs = psMetadataAlloc();
    125125    psMetadataAddS64(updateprocessedexpArgs, PS_LIST_TAIL, "-add_id", 0,            "search by addtool ID", 0);
    126126    psMetadataAddS64(updateprocessedexpArgs, PS_LIST_TAIL, "-cam_id",  0,            "search by camtool ID", 0);
     127    psMetadataAddS16(updateprocessedexpArgs, PS_LIST_TAIL, "-fault",  0,            "set fault code", 0);
    127128
    128129    // -block
     
    137138    psMetadata *unblockArgs = psMetadataAlloc();
    138139    psMetadataAddStr(unblockArgs, PS_LIST_TAIL, "-label",  0,            "name of a label to unmask (required)", NULL);
    139 
    140     // -pendingcleanuprun
    141     // XXX allow full search options?
    142     psMetadata *pendingcleanuprunArgs = psMetadataAlloc();
    143     psMetadataAddStr(pendingcleanuprunArgs, PS_LIST_TAIL, "-label", PS_META_DUPLICATE_OK, "list blocks for specified label", NULL);
    144     psMetadataAddBool(pendingcleanuprunArgs, PS_LIST_TAIL, "-simple",  0,            "use the simple output format", false);
    145     psMetadataAddU64(pendingcleanuprunArgs, PS_LIST_TAIL, "-limit",  0,            "limit result set to N items", 0);
    146 
    147     // -pendingcleanupexp
    148     // XXX allow full search options?
    149     psMetadata *pendingcleanupexpArgs = psMetadataAlloc();
    150     psMetadataAddStr(pendingcleanupexpArgs, PS_LIST_TAIL, "-label", PS_META_DUPLICATE_OK, "list blocks for specified label", NULL);
    151     psMetadataAddS64(pendingcleanupexpArgs, PS_LIST_TAIL, "-add_id", 0,            "search by addstar ID", 0);
    152     psMetadataAddBool(pendingcleanupexpArgs, PS_LIST_TAIL, "-simple",  0,            "use the simple output format", false);
    153     psMetadataAddU64(pendingcleanupexpArgs, PS_LIST_TAIL, "-limit",  0,            "limit result set to N items", 0);
    154 
    155     // -donecleanup
    156     psMetadata *donecleanupArgs = psMetadataAlloc();
    157     psMetadataAddStr(donecleanupArgs, PS_LIST_TAIL, "-label",  0,            "list blocks for specified label", NULL);
    158     psMetadataAddBool(donecleanupArgs, PS_LIST_TAIL, "-simple",  0,            "use the simple output format", false);
    159     psMetadataAddU64(donecleanupArgs, PS_LIST_TAIL, "-limit",  0,            "limit result set to N items", 0);
    160 
    161     // -exportrun
    162     psMetadata *exportrunArgs = psMetadataAlloc();
    163     psMetadataAddS64(exportrunArgs, PS_LIST_TAIL, "-add_id", 0,          "export this addstar ID (required)", 0);
    164     psMetadataAddStr(exportrunArgs, PS_LIST_TAIL, "-outfile", 0,          "export to this file (required)", NULL);
    165     psMetadataAddU64(exportrunArgs, PS_LIST_TAIL, "-limit",   0,          "limit result set to N items", 0);
    166     psMetadataAddBool(exportrunArgs, PS_LIST_TAIL, "-clean",  0,          "export tables as cleaned", false);
    167 
    168     // -importrun
    169     psMetadata *importrunArgs = psMetadataAlloc();
    170     psMetadataAddStr(importrunArgs, PS_LIST_TAIL, "-infile",  0,          "import from this file (required)", NULL);
    171 
    172140
    173141    psMetadata *argSets = psMetadataAlloc();
     
    184152    PXOPT_ADD_MODE("-masked",               "show blocked labels",                  ADDTOOL_MODE_MASKED,        maskedArgs);
    185153    PXOPT_ADD_MODE("-unblock",              "remove a label block",                 ADDTOOL_MODE_UNBLOCK,       unblockArgs);
    186     PXOPT_ADD_MODE("-pendingcleanuprun",    "show runs that need to be cleaned up", ADDTOOL_MODE_PENDINGCLEANUPRUN, pendingcleanuprunArgs);
    187     PXOPT_ADD_MODE("-pendingcleanupexp",    "show exps for cleanup runs",           ADDTOOL_MODE_PENDINGCLEANUPEXP, pendingcleanupexpArgs);
    188     PXOPT_ADD_MODE("-donecleanup",          "show runs that have been cleaned",     ADDTOOL_MODE_DONECLEANUP,       donecleanupArgs);
    189     PXOPT_ADD_MODE("-exportrun",            "export run for import on other database", ADDTOOL_MODE_EXPORTRUN, exportrunArgs);
    190     PXOPT_ADD_MODE("-importrun",            "import run from metadata file",           ADDTOOL_MODE_IMPORTRUN, importrunArgs);
    191154
    192155    if (!pxGetOptions(stderr, argc, argv, config, modes, argSets)) {
  • branches/eam_branches/20090820/ippTools/src/camtool.c

    r25766 r25870  
    121121    PXOPT_LOOKUP_STR(workdir, config->args, "-set_workdir", false, false);
    122122    PXOPT_LOOKUP_STR(label, config->args, "-set_label", false, false);
     123    PXOPT_LOOKUP_STR(data_group, config->args, "-set_data_group", false, false);
     124    PXOPT_LOOKUP_STR(dist_group, config->args, "-set_dist_group", false, false);
    123125    PXOPT_LOOKUP_STR(reduction, config->args, "-set_reduction", false, false);
    124126    PXOPT_LOOKUP_STR(expgroup, config->args, "-set_expgroup", false, false);
     
    126128    PXOPT_LOOKUP_STR(tess_id, config->args, "-set_tess_id", false, false);
    127129    PXOPT_LOOKUP_STR(end_stage, config->args, "-set_end_stage", false, false);
     130    PXOPT_LOOKUP_STR(note, config->args, "-set_note", false, false);
    128131
    129132    // find the exp_id of all the exposures that we want to queue up.
     
    212215                    workdir     ? workdir   : row->workdir,
    213216                    label       ? label     : row->label,
     217                    data_group  ? data_group: row->data_group,
     218                    dist_group  ? dist_group: row->dist_group,
    214219                    reduction   ? reduction : row->reduction,
    215220                    expgroup    ? expgroup  : row->expgroup,
    216221                    dvodb       ? dvodb     : row->dvodb,
    217222                    tess_id     ? tess_id   : row->tess_id,
    218                     end_stage   ? end_stage : row->end_stage
     223                    end_stage   ? end_stage : row->end_stage,
     224                    note
    219225        )) {
    220226            if (!psDBRollback(config->dbh)) {
     
    251257    PXOPT_COPY_STR(config->args, where, "-reduction", "camRun.reduction", "==");
    252258
    253     if (!psListLength(where->list)
    254         && !psMetadataLookupBool(NULL, config->args, "-all")) {
     259    if (!psListLength(where->list)) {
    255260        psFree(where);
    256261        psError(PXTOOLS_ERR_DATA, false, "search parameters are required");
    257262        return false;
    258263    }
    259 
    260     PXOPT_LOOKUP_STR(state, config->args, "-set_state", false, false);
    261     PXOPT_LOOKUP_STR(label, config->args, "-set_label", false, false);
    262 
    263     if ((!state) && (!label)) {
    264         psError(PXTOOLS_ERR_DATA, false, "parameters are required");
    265         psFree(where);
    266         return false;
    267     }
    268 
    269     if (state) {
    270         // set camRun.state to state
    271         if (!pxcamRunSetStateByQuery(config, where, state)) {
    272             psFree(where);
    273             return false;
    274         }
    275     }
    276 
    277     if (label) {
    278         // set camRun.label to label
    279         if (!pxcamRunSetLabelByQuery(config, where, label)) {
    280             psFree(where);
    281             return false;
    282         }
    283     }
    284 
     264    psString query = psStringCopy("UPDATE camRun JOIN chipRun USING(chip_id) JOIN rawExp USING(exp_id)");
     265
     266    // pxUpdateRun gets parameters from config->args and updates
     267    bool result = pxUpdateRun(config, where, &query, "camRun", true);
     268    if (!result) {
     269        psError(PXTOOLS_ERR_DATA, false, "pxUpdateRun failed");
     270    }
     271
     272    psFree(query);
    285273    psFree(where);
    286274
    287     return true;
     275    return result;
    288276}
    289277
     
    642630            pendingRow->workdir,
    643631            pendingRow->label,
     632            pendingRow->data_group,
     633            pendingRow->dist_group,
    644634            pendingRow->reduction,
    645635            pendingRow->expgroup,
    646636            pendingRow->dvodb,
    647637            pendingRow->tess_id,
    648             pendingRow->end_stage
     638            pendingRow->end_stage,
     639            NULL    // note does not propagate
    649640    )) {
    650641        // rollback
     
    656647        return false;
    657648    }
    658 
    659 /*     if (!pxaddQueueByCamID(config, */
    660 /*                         pendingRow->cam_id, */
    661 /*                         pendingRow->workdir, */
    662 /*                         pendingRow->label, */
    663 /*                         pendingRow->reduction, */
    664 /*                         pendingRow->dvodb */
    665 /*     )) { */
    666 /*         // rollback */
    667 /*         if (!psDBRollback(config->dbh)) { */
    668 /*             psError(PS_ERR_UNKNOWN, false, "database error"); */
    669 /*         } */
    670 /*         psError(PS_ERR_UNKNOWN, false, "failed to queue new addRun"); */
    671 /*         psFree(pendingRow); */
    672 /*         return false; */
    673 /*     } */
    674649
    675650    psFree(pendingRow);
     
    11721147  }
    11731148
     1149  if (!pxExportVersion(config, f)) {
     1150    psError(PS_ERR_UNKNOWN, false, "failed to write dbversion output file");
     1151    return false;
     1152  }
     1153
    11741154  psMetadata *where = psMetadataAlloc();
    11751155  PXOPT_COPY_S64(config->args, where, "-cam_id", "cam_id", "==");
     
    12521232  psMetadata *input = psMetadataConfigRead (NULL, &nFail, infile, false);
    12531233
    1254   fprintf (stdout, "---- input ----\n");
     1234#ifdef notdef
     1235  fprintf (stderr, "---- input ----\n");
    12551236  psMetadataPrint (stderr, input, 1);
     1237#endif
     1238
     1239  if (!pxCheckImportVersion(config, input)) {
     1240      psError(PS_ERR_UNKNOWN, false, "pxCheckImportVersion failed");
     1241      return false;
     1242  }
    12561243
    12571244  psMetadataItem *item = psMetadataLookup (input, "camRun");
  • branches/eam_branches/20090820/ippTools/src/camtoolConfig.c

    r24681 r25870  
    6262    psMetadataAddStr(definebyqueryArgs, PS_LIST_TAIL, "-set_tess_id",        0, "define tess ID", NULL);
    6363    psMetadataAddStr(definebyqueryArgs, PS_LIST_TAIL, "-set_end_stage",      0, "define end stage", NULL);
    64     psMetadataAddBool(definebyqueryArgs, PS_LIST_TAIL, "-all",               0, "allow everything to be queued without search terms", false);
     64    psMetadataAddStr(definebyqueryArgs, PS_LIST_TAIL, "-set_data_group",     0, "define data group", NULL);
     65    psMetadataAddStr(definebyqueryArgs, PS_LIST_TAIL, "-set_dist_group",     0, "define dist group", NULL);
     66    psMetadataAddStr(definebyqueryArgs, PS_LIST_TAIL, "-set_note",           0, "define note", NULL);
    6567
    6668    // -updaterun
     
    7779    psMetadataAddStr(updaterunArgs, PS_LIST_TAIL, "-set_state",          0, "set state", NULL);
    7880    psMetadataAddStr(updaterunArgs, PS_LIST_TAIL, "-set_label",          0, "set label", NULL);
    79 
     81    psMetadataAddStr(updaterunArgs, PS_LIST_TAIL, "-set_data_group", 0,   "define new data_group", NULL);
     82    psMetadataAddStr(updaterunArgs, PS_LIST_TAIL, "-set_dist_group", 0,   "define new dist_group", NULL);
     83    psMetadataAddStr(updaterunArgs, PS_LIST_TAIL, "-set_note", 0,         "define new note", NULL);
    8084    // -pendingexp
    8185    psMetadata *pendingexpArgs = psMetadataAlloc();
  • branches/eam_branches/20090820/ippTools/src/chiptool.c

    r25766 r25870  
    5757static bool exportrunMode(pxConfig *config);
    5858static bool importrunMode(pxConfig *config);
     59static bool runstateMode(pxConfig *config);
    5960
    6061# define MODECASE(caseName, func) \
     
    9798        MODECASE(CHIPTOOL_MODE_EXPORTRUN,               exportrunMode);
    9899        MODECASE(CHIPTOOL_MODE_IMPORTRUN,               importrunMode);
     100        MODECASE(CHIPTOOL_MODE_RUNSTATE,                runstateMode);
    99101        default:
    100102            psAbort("invalid option (this should not happen)");
     
    144146    PXOPT_LOOKUP_STR(tess_id, config->args, "-set_tess_id", false, false);
    145147    PXOPT_LOOKUP_STR(end_stage, config->args, "-set_end_stage", false, false);
     148    PXOPT_LOOKUP_STR(dist_group, config->args, "-set_dist_group", false, false);
     149    PXOPT_LOOKUP_STR(data_group, config->args, "-set_data_group", false, false);
     150    PXOPT_LOOKUP_STR(note, config->args, "-set_note", false, false);
    146151
    147152    // default
     
    263268                                 workdir     ? workdir   : raw_workdir,
    264269                                 label       ? label     : raw_label,
     270                                 data_group  ? data_group : (label ? label : raw_label),
     271                                 dist_group,
    265272                                 reduction   ? reduction : raw_reduction,
    266273                                 // expgroup    ? expgroup  : raw_expgroup,
     
    269276                                 dvodb       ? dvodb     : raw_dvodb,
    270277                                 tess_id     ? tess_id   : raw_tess_id,
    271                                  end_stage   ? end_stage : raw_end_stage
     278                                 end_stage   ? end_stage : raw_end_stage,
     279                                 note
    272280                                 )) {
    273281            if (!psDBRollback(config->dbh)) {
     
    301309    PXOPT_COPY_STR(config->args,  where, "-label",   "chipRun.label",   "==");
    302310    PXOPT_COPY_STR(config->args,  where, "-state",   "chipRun.state",   "==");
    303 
    304     if (!psListLength(where->list) &&
    305         !psMetadataLookupBool(NULL, config->args, "-all")) {
     311    PXOPT_COPY_STR(config->args,  where, "-data_group", "chipRun.data_group",   "==");
     312    PXOPT_COPY_STR(config->args,  where, "-dist_group", "chipRun.dist_group",   "==");
     313
     314    if (!psListLength(where->list)) {
    306315        psFree(where);
    307         where = NULL;
    308316        psError(PXTOOLS_ERR_DATA, false, "search parameters are required");
    309317        return false;
    310318    }
    311 
    312     PXOPT_LOOKUP_STR(state, config->args, "-set_state", false, false);
    313     PXOPT_LOOKUP_STR(label, config->args, "-set_label", false, false);
    314 
    315     if ((!state) && (!label)) {
    316         psError(PXTOOLS_ERR_DATA, false, "parameters are required");
    317         psFree(where);
    318         return false;
    319     }
    320 
    321     if (state) {
    322         // set chipRun.state to state
    323         if (!pxchipRunSetStateByQuery(config, where, state)) {
    324             psFree(where);
    325             return false;
    326         }
    327     }
    328 
    329     if (label) {
    330         // set chipRun.label to label
    331         if (!pxchipRunSetLabelByQuery(config, where, label)) {
    332             psFree(where);
    333             return false;
    334         }
    335     }
    336 
     319    psString query = psStringCopy("UPDATE chipRun JOIN rawExp USING(exp_id)");
     320
     321    // pxUpdateRun gets parameters from config->args and updates
     322    bool result = pxUpdateRun(config, where, &query, "chipRun", true);
     323    if (!result) {
     324        psError(PXTOOLS_ERR_DATA, false, "pxUpdateRun failed");
     325    }
     326
     327    psFree(query);
    337328    psFree(where);
    338329
    339     return true;
     330    return result;
    340331}
    341332
     
    605596    PXOPT_COPY_S64(config->args, where, "-magicked", "chipProcessedImfile.magicked", "==");
    606597
    607     PXOPT_LOOKUP_U64(magicked, config->args, "-magicked", false, false);
    608     PXOPT_LOOKUP_BOOL(destreaked, config->args,     "-destreaked", false);
    609     PXOPT_LOOKUP_BOOL(not_destreaked, config->args, "-not_destreaked", false);
    610 
    611     if (!psListLength(where->list) &&
    612         !psMetadataLookupBool(NULL, config->args, "-all")) {
    613         psFree(where);
    614         psError(PXTOOLS_ERR_DATA, false, "search parameters (or -all) are required");
     598    psString where2 = NULL;
     599    pxmagicAddWhere(config, &where2, "chipProcessedImfile");
     600    // add cuts on ra and decl if supplied
     601    if (!pxspaceAddWhere(config, &where2, "rawExp")) {
     602        psError(PXTOOLS_ERR_DATA, false, "pxSpaceAddWhere failed");
    615603        return false;
    616604    }
     
    622610    }
    623611
    624     if (where && psListLength(where->list)) {
     612    if (psListLength(where->list)) {
    625613        psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
    626614        psStringAppend(&query, " WHERE %s", whereClause);
    627615        psFree(whereClause);
     616    } else if (psMetadataLookupBool(NULL, config->args, "-all") || (faulted || where2)) {
     617        psStringAppend(&query, " WHERE chipRun.chip_id IS NOT NULL %s", where2 ? where2 : "");
     618    } else {
     619        psFree(where);
     620        psError(PXTOOLS_ERR_DATA, false, "search parameters (or -all) are required");
     621        return false;
    628622    }
    629623    psFree(where);
     
    635629        // don't list faulted rows
    636630        psStringAppend(&query, " %s", "AND chipProcessedImfile.fault = 0");
    637     }
    638     if (not_destreaked) {
    639         if (destreaked) {
    640             psError(PXTOOLS_ERR_DATA, true, "providing -not_destreaked and -destreaked makes no sense");
    641             return false;
    642         }
    643         if (magicked) {
    644             psError(PXTOOLS_ERR_DATA, true, "providing -not_destreaked and -magicked makes no sense");
    645             return false;
    646         }
    647         psStringAppend(&query, " AND chipProcessedImfile.magicked = 0");
    648     }
    649     if (destreaked) {
    650         psStringAppend(&query, " AND chipProcessedImfile.magicked != 0");
    651631    }
    652632
     
    739719    PXOPT_COPY_S64(config->args, where, "-chip_id", "chip_id", "==");
    740720    PXOPT_COPY_STR(config->args, where, "-class_id", "class_id", "==");
    741     PXOPT_LOOKUP_S16(fault, config->args, "-fault", true, false);
    742 
    743     if (!pxSetFaultCode(config->dbh, "chipProcessedImfile", where, fault)) {
     721    PXOPT_LOOKUP_STR(state, config->args, "-set_state", false, NULL);
     722       
     723    if (!state) {
     724      PXOPT_LOOKUP_S16(fault, config->args, "-fault", true, false);
     725     
     726      if (!pxSetFaultCode(config->dbh, "chipProcessedImfile", where, fault)) {
    744727        psError(PS_ERR_UNKNOWN, false, "failed to set set fault flag");
    745728        return false;
    746     }
    747     psFree(where);
    748 
     729      }
     730      psFree(where);
     731    }
     732    else {
     733      if (!pxchipProcessedImfileSetStateByQuery(config,where,state)) {
     734        psError(PS_ERR_UNKNOWN, false, "failed to set chipProcessedImfile state");
     735        return(false);
     736      }
     737    }
     738
     739     
    749740    return true;
    750741}
     
    11141105
    11151106    psMetadata *where = psMetadataAlloc();
     1107    pxchipGetSearchArgs (config, where); // chipRun, chipProcessedImfile, rawExp
     1108    PXOPT_COPY_S64(config->args, where, "-chip_id", "chipRun.chip_id", "==");
     1109    PXOPT_COPY_STR(config->args, where, "-reduction", "chipRun.reduction", "==");
    11161110    pxAddLabelSearchArgs (config, where, "-label", "label", "==");
    11171111    PXOPT_COPY_STR(config->args, where, "-state", "state", "==");
     
    12531247                    chipRun->workdir,
    12541248                    chipRun->label,
     1249                    chipRun->data_group,
     1250                    chipRun->dist_group,
    12551251                    chipRun->reduction,
    12561252                    chipRun->expgroup,
    12571253                    chipRun->dvodb,
    12581254                    chipRun->tess_id,
    1259                     chipRun->end_stage
     1255                    chipRun->end_stage,
     1256                    NULL    // note does not propagate
    12601257        )) {
    12611258           if (!psDBRollback(config->dbh)) {
     
    13801377  }
    13811378
     1379  if (!pxExportVersion(config, f)) {
     1380    psError(PS_ERR_UNKNOWN, false, "failed to write dbversion output file");
     1381    return false;
     1382  }
     1383
    13821384  psMetadata *where = psMetadataAlloc();
    13831385  PXOPT_COPY_S64(config->args, where, "-chip_id", "chip_id", "==");
     
    14711473    psVector *identifiers = psVectorAllocEmpty(16, PS_TYPE_U64); // Identifiers inserted
    14721474
     1475    psMetadataIterator *iter = psMetadataIteratorAlloc(input, PS_LIST_HEAD, NULL);       // Iterator
     1476
     1477    if (!pxCheckImportVersion(config, input)) {
     1478        psError(PS_ERR_UNKNOWN, false, "pxCheckImportVersion failed");
     1479        return false;
     1480    }
     1481    // first item is the dbversion, skip it
     1482    psMetadataItem *dbversion =  psMetadataGetAndIncrement(iter);
     1483    (void) dbversion;
     1484
    14731485    if (!psDBTransaction(config->dbh)) {
    14741486        psError(PS_ERR_UNKNOWN, false, "database error");
     
    14761488    }
    14771489
    1478     psMetadataIterator *iter = psMetadataIteratorAlloc(input, PS_LIST_HEAD, NULL);       // Iterator
    14791490    psMetadataItem *item;               // Item from iteration
    14801491    while ((item = psMetadataGetAndIncrement(iter))) {
     
    15051516    return true;
    15061517}
     1518
     1519static bool runstateMode(pxConfig *config)
     1520{
     1521    PS_ASSERT_PTR_NON_NULL(config, false);
     1522
     1523    psMetadata *where = psMetadataAlloc();
     1524    PXOPT_COPY_S64(config->args, where, "-chip_id",    "chipRun.chip_id", "==");
     1525    PXOPT_COPY_S64(config->args, where, "-exp_id",     "rawExp.exp_id", "==");
     1526    PXOPT_COPY_STR(config->args, where, "-exp_name",   "rawExp.exp_name", "==");
     1527    pxAddLabelSearchArgs (config, where, "-label",     "chipRun.label", "LIKE");
     1528
     1529//    PXOPT_LOOKUP_BOOL(all, config->args, "-all", false);
     1530    PXOPT_LOOKUP_BOOL(no_magic, config->args, "-no_magic", false);
     1531
     1532    PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
     1533    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
     1534
     1535    psString query = pxDataGet("chiptool_runstate.sql");
     1536    if (!query) {
     1537        psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
     1538        return false;
     1539    }
     1540
     1541    if (psListLength(where->list)) {
     1542        psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
     1543        psStringAppend(&query, " WHERE %s", whereClause);
     1544        psFree(whereClause);
     1545    } else {
     1546        psError(PXTOOLS_ERR_DATA, true, "search parameters or -all are required");
     1547        return false;
     1548    }
     1549    psFree(where);
     1550
     1551    // treat limit == 0 as "no limit"
     1552    if (limit) {
     1553        psString limitString = psDBGenerateLimitSQL(limit);
     1554        psStringAppend(&query, " %s", limitString);
     1555        psFree(limitString);
     1556    }
     1557
     1558    if (!p_psDBRunQuery(config->dbh, query)) {
     1559        psError(PS_ERR_UNKNOWN, false, "database error");
     1560        psFree(query);
     1561        return false;
     1562    }
     1563    psFree(query);
     1564
     1565    psArray *output = p_psDBFetchResult(config->dbh);
     1566    if (!output) {
     1567        psErrorCode err = psErrorCodeLast();
     1568        switch (err) {
     1569            case PS_ERR_DB_CLIENT:
     1570                psError(PXTOOLS_ERR_SYS, false, "database error");
     1571            case PS_ERR_DB_SERVER:
     1572                psError(PXTOOLS_ERR_PROG, false, "database error");
     1573            default:
     1574                psError(PXTOOLS_ERR_PROG, false, "unknown error");
     1575        }
     1576
     1577        return false;
     1578    }
     1579    if (!psArrayLength(output)) {
     1580        psTrace("chiptool", PS_LOG_INFO, "no rows found");
     1581        psFree(output);
     1582        return true;
     1583    }
     1584
     1585    if (psArrayLength(output)) {
     1586        // negative simple so the default is true
     1587        if (!ippdbPrintMetadatas(stdout, output, "chipRunState", !simple)) {
     1588            psError(PS_ERR_UNKNOWN, false, "failed to print array");
     1589            psFree(output);
     1590            return false;
     1591        }
     1592    }
     1593
     1594    psFree(output);
     1595
     1596    return true;
     1597}
  • branches/eam_branches/20090820/ippTools/src/chiptool.h

    r25766 r25870  
    4747    CHIPTOOL_MODE_TOSCRUBBEDIMFILE,
    4848    CHIPTOOL_MODE_EXPORTRUN,
    49     CHIPTOOL_MODE_IMPORTRUN
     49    CHIPTOOL_MODE_IMPORTRUN,
     50    CHIPTOOL_MODE_RUNSTATE
    5051} chiptoolMode;
    5152
  • branches/eam_branches/20090820/ippTools/src/chiptoolConfig.c

    r25766 r25870  
    5858    psMetadataAddStr(definebyqueryArgs, PS_LIST_TAIL, "-set_tess_id",  0,            "define tessellation identifier", NULL);
    5959    psMetadataAddStr(definebyqueryArgs, PS_LIST_TAIL, "-set_end_stage",  0,            "define end stage", NULL);
     60    psMetadataAddStr(definebyqueryArgs, PS_LIST_TAIL, "-set_data_group",  0,      "define data group", NULL);
     61    psMetadataAddStr(definebyqueryArgs, PS_LIST_TAIL, "-set_dist_group",  0,      "define distribution group", NULL);
     62    psMetadataAddStr(definebyqueryArgs, PS_LIST_TAIL, "-set_note",  0,           "define note", NULL);
    6063    psMetadataAddBool(definebyqueryArgs, PS_LIST_TAIL, "-pretend",  0,            "do not actually modify the database", false);
    6164    psMetadataAddBool(definebyqueryArgs, PS_LIST_TAIL, "-simple",  0,            "use the simple output format", false);
    62     psMetadataAddBool(definebyqueryArgs, PS_LIST_TAIL, "-all",  0,            "allow everything to be queued without search terms", false);
    6365
    6466    // -updaterun
     
    6769    psMetadataAddS64(updaterunArgs, PS_LIST_TAIL, "-chip_id",              0,            "search by chip ID", 0);
    6870    psMetadataAddStr(updaterunArgs, PS_LIST_TAIL, "-state", 0,            "search by state", NULL);
    69     psMetadataAddStr(updaterunArgs, PS_LIST_TAIL, "-label",  0,          "search by label", NULL);
     71    psMetadataAddStr(updaterunArgs, PS_LIST_TAIL, "-label",  0,           "search by label", NULL);
     72    psMetadataAddStr(updaterunArgs, PS_LIST_TAIL, "-data_group",  0,      "search by data_group", NULL);
     73    psMetadataAddStr(updaterunArgs, PS_LIST_TAIL, "-dist_group",  0,      "search by dist_group", NULL);
    7074    psMetadataAddStr(updaterunArgs, PS_LIST_TAIL, "-set_state", 0,        "set state", NULL);
    7175    psMetadataAddStr(updaterunArgs, PS_LIST_TAIL, "-set_label", 0,        "set label", NULL);
    72     psMetadataAddBool(updaterunArgs, PS_LIST_TAIL, "-all",  0,            "allow everything to be queued without search terms", false);
     76    psMetadataAddStr(updaterunArgs, PS_LIST_TAIL, "-set_data_group", 0,   "set data group", NULL);
     77    psMetadataAddStr(updaterunArgs, PS_LIST_TAIL, "-set_dist_group", 0,   "set dist group", NULL);
     78    psMetadataAddStr(updaterunArgs, PS_LIST_TAIL, "-set_note", 0,         "set note", NULL);
    7379
    7480    // -pendingimfile
     
    158164    psMetadataAddStr(processedimfileArgs,  PS_LIST_TAIL, "-reduction",          0, "search by reduction class", NULL);
    159165    psMetadataAddStr(processedimfileArgs,  PS_LIST_TAIL, "-label",  PS_META_DUPLICATE_OK, "search by chipRun label (LIKE comparison)", NULL);
    160 
    161     psMetadataAddBool(processedimfileArgs, PS_LIST_TAIL, "-destreaked",  0,      "search for destreaked images", false);
    162     psMetadataAddBool(processedimfileArgs, PS_LIST_TAIL, "-not_destreaked",  0,  "search for images that have not been destreaked", false);
    163     psMetadataAddS64(processedimfileArgs, PS_LIST_TAIL, "-magicked",  0,        "search by magicked value", 0);
     166    pxmagicAddArguments(processedimfileArgs);
     167
    164168    psMetadataAddU64(processedimfileArgs,  PS_LIST_TAIL, "-limit",  0,           "limit result set to N items", 0);
    165169    psMetadataAddBool(processedimfileArgs, PS_LIST_TAIL, "-all",  0,            "list everything without search terms", false);
    166170    psMetadataAddBool(processedimfileArgs, PS_LIST_TAIL, "-faulted",  0,        "only return imfiles with a fault status set", false);
    167171    psMetadataAddBool(processedimfileArgs, PS_LIST_TAIL, "-simple",  0,         "use the simple output format", false);
     172
     173    pxspaceAddArguments(processedimfileArgs);
    168174
    169175    // -revertprocessedimfile
     
    182188    psMetadataAddStr(updateprocessedimfileArgs,  PS_LIST_TAIL, "-class_id",           0, "search by class ID", NULL);
    183189    psMetadataAddS16(updateprocessedimfileArgs, PS_LIST_TAIL, "-fault",  0,            "set fault code (required)", 0);
    184 
     190    psMetadataAddStr(updateprocessedimfileArgs, PS_LIST_TAIL, "-set_state", 0,         "set state", NULL);
    185191    // -block
    186192    psMetadata *blockArgs = psMetadataAlloc();
     
    229235    psMetadataAddU64(runArgs, PS_LIST_TAIL, "-limit",  0,       "limit result set to N items", 0);
    230236    psMetadataAddStr(runArgs, PS_LIST_TAIL, "-state", 0,        "search by state (required)", NULL);
     237    pxchipSetSearchArgs(runArgs);
     238    psMetadataAddS64(runArgs, PS_LIST_TAIL, "-chip_id",  0,         "search by  chip ID", 0);
     239    psMetadataAddStr(runArgs,  PS_LIST_TAIL, "-reduction",          0, "search by reduction class", NULL);
    231240
    232241    // -advanceexp
     
    268277    psMetadataAddStr(importrunArgs, PS_LIST_TAIL, "-infile",  0,          "import from this file (required)", NULL);
    269278
     279    // -runstate
     280    psMetadata *runstateArgs = psMetadataAlloc();
     281    psMetadataAddS64(runstateArgs, PS_LIST_TAIL, "-chip_id", 0,           "search by chip ID", 0);
     282    psMetadataAddS64(runstateArgs, PS_LIST_TAIL, "-exp_id", 0,            "search by exposure tag", 0);
     283    psMetadataAddStr(runstateArgs, PS_LIST_TAIL, "-exp_name", 0,          "search by exposure tag", 0);
     284    psMetadataAddStr(runstateArgs, PS_LIST_TAIL,  "-label",  PS_META_DUPLICATE_OK, "search by warpRun label", NULL);
     285    psMetadataAddBool(runstateArgs, PS_LIST_TAIL, "-no_magic",  0,        "magic is not necessary for result", false);
     286
     287    psMetadataAddU64(runstateArgs, PS_LIST_TAIL, "-limit",  0,            "limit result set to N items", 0);
     288    psMetadataAddBool(runstateArgs, PS_LIST_TAIL, "-simple",  0,          "use the simple output format", false);
     289
    270290    psMetadata *argSets = psMetadataAlloc();
    271291    psMetadata *modes = psMetadataAlloc();
     
    278298    PXOPT_ADD_MODE("-updateprocessedimfile","change procesed imfile properties",    CHIPTOOL_MODE_UPDATEPROCESSEDIMFILE,updateprocessedimfileArgs);
    279299    PXOPT_ADD_MODE("-revertprocessedimfile","undo a processed imfile",              CHIPTOOL_MODE_REVERTPROCESSEDIMFILE,revertprocessedimfileArgs);
     300    PXOPT_ADD_MODE("-runstate",             "list the states of chip run",          CHIPTOOL_MODE_RUNSTATE,             runstateArgs);
    280301    PXOPT_ADD_MODE("-advanceexp",           "advance completed exposures",          CHIPTOOL_MODE_ADVANCEEXP,           advanceexpArgs);
    281302    PXOPT_ADD_MODE("-block",                "set a label block",                    CHIPTOOL_MODE_BLOCK,                blockArgs);
  • branches/eam_branches/20090820/ippTools/src/difftool.c

    r25766 r25870  
    5151
    5252static bool setdiffRunState(pxConfig *config, psS64 diff_id, const char *state, psS64 magicked);
     53static bool change_skyfile_data_state(pxConfig *config, psString data_state, psString run_state);
     54static bool tocleanedskyfileMode(pxConfig *config);
     55static bool topurgedskyfileMode(pxConfig *config);
     56static bool toscrubbedskyfileMode(pxConfig *config);
     57
     58
    5359
    5460# define MODECASE(caseName, func) \
     
    8894        MODECASE(DIFFTOOL_MODE_EXPORTRUN,             exportrunMode);
    8995        MODECASE(DIFFTOOL_MODE_IMPORTRUN,             importrunMode);
     96        MODECASE(DIFFTOOL_MODE_TOCLEANEDSKYFILE,   tocleanedskyfileMode);
     97        MODECASE(DIFFTOOL_MODE_TOPURGEDSKYFILE,    topurgedskyfileMode);
     98        MODECASE(DIFFTOOL_MODE_TOSCRUBBEDSKYFILE,  toscrubbedskyfileMode);
     99
    90100        default:
    91101            psAbort("invalid option (this should not happen)");
     
    115125
    116126    // required options
    117     PXOPT_LOOKUP_STR(workdir, config->args, "-workdir", true, false);
     127    PXOPT_LOOKUP_STR(workdir, config->args, "-set_workdir", true, false);
    118128    PXOPT_LOOKUP_STR(tess_id, config->args, "-tess_id", true, false);
    119129    PXOPT_LOOKUP_BOOL(bothways, config->args, "-bothways", false);
    120130    PXOPT_LOOKUP_BOOL(exposure, config->args, "-exposure", false);
    121     PXOPT_LOOKUP_STR(label, config->args, "-label", false, false);
    122     PXOPT_LOOKUP_STR(reduction, config->args, "-reduction", false, false);
     131    PXOPT_LOOKUP_STR(label, config->args, "-set_label", false, false);
     132    PXOPT_LOOKUP_STR(data_group, config->args, "-set_data_group", false, false);
     133    PXOPT_LOOKUP_STR(dist_group, config->args, "-set_dist_group", false, false);
     134    PXOPT_LOOKUP_STR(reduction, config->args, "-rset_eduction", false, false);
     135    PXOPT_LOOKUP_STR(note, config->args, "-set_note", false, false);
    123136
    124137    // default
     
    131144            workdir,
    132145            label,
     146            data_group ? data_group : label,
     147            dist_group,
    133148            reduction,
    134149            NULL,       // dvodb
     
    137152            bothways,
    138153            exposure,
    139             false
     154            false,
     155            note
    140156    );
    141157    if (!run) {
     
    168184    PS_ASSERT_PTR_NON_NULL(config, false);
    169185
     186    psMetadata *where = psMetadataAlloc();
     187
     188    PXOPT_COPY_S64(config->args, where, "-diff_id",  "stack_id",   "==");
     189    PXOPT_COPY_STR(config->args, where, "-label",     "label",     "==");
     190    PXOPT_COPY_STR(config->args, where, "-state",     "state",     "==");
     191    if (!psListLength(where->list)) {
     192        psFree(where);
     193        psError(PXTOOLS_ERR_DATA, false, "search parameters are required");
     194        return false;
     195    }
     196
     197    psString query = psStringCopy("UPDATE diffRun");
     198
     199    // pxUpdateRun gets parameters from config->args and updates
     200    bool result = pxUpdateRun(config, where, &query, "diffRun", true);
     201
     202    psFree(query);
     203    psFree(where);
     204
     205    return result;
     206
     207#ifdef notdef
    170208    // required options
    171     PXOPT_LOOKUP_S64(diff_id, config->args, "-diff_id", true, false);
     209    PXOPT_LOOKUP_S64(diff_id, config->args, "-diff_id", false, false);
    172210    PXOPT_LOOKUP_STR(state, config->args, "-state", true, false);
    173 
    174     if (state) {
     211    PXOPT_LOOKUP_STR(label, config->args, "-label", false, false);
     212   
     213    // Copy of my hacky work around from stacktool.c
     214    if ((state)&&(diff_id)) {
    175215        // set detRun.state to state
    176216        return setdiffRunState(config, diff_id, state, false);
    177217    }
    178218
    179     return true;
     219    if ((state)&&(label)) {
     220      return setdiffRunStateByLabel(config, label, state);
     221    }
     222
     223    psError(PS_ERR_UNKNOWN, false, "Required options not found.");
     224
     225    return false;
     226#endif
    180227}
    181228
     
    692739    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
    693740
    694     PXOPT_LOOKUP_U64(magicked, config->args,        "-magicked", false, false);
    695     PXOPT_LOOKUP_BOOL(destreaked, config->args,     "-destreaked", false);
    696     PXOPT_LOOKUP_BOOL(not_destreaked, config->args, "-not_destreaked", false);
    697 
     741
     742    psString where2 = NULL;
     743    pxmagicAddWhere(config, &where2, "diffSkyfile");
     744    pxspaceAddWhere(config, &where2, template ? "rawTemplate" : "rawInput");
    698745    psString query = pxDataGet("difftool_skyfile.sql");
    699746    if (!query) {
     
    706753        psStringAppend(&query, " WHERE %s", whereClause);
    707754        psFree(whereClause);
     755    } else if (where2) {
     756        psStringAppend(&query, " WHERE diffRun.diff_id is not null %s", where2);
    708757    } else if (!all) {
    709758        psError(PXTOOLS_ERR_DATA, true, "search parameters or -all are required");
     759        return false;
    710760    }
    711761    psFree(where);
    712 
    713     if (not_destreaked) {
    714         if (destreaked) {
    715             psError(PXTOOLS_ERR_DATA, true, "providing -not_destreaked and -destreaked makes no sense");
    716             return false;
    717         }
    718         if (magicked) {
    719             psError(PXTOOLS_ERR_DATA, true, "providing -not_destreaked and -magicked makes no sense");
    720             return false;
    721         }
    722         psStringAppend(&query, " AND diffSkyfile.magicked = 0");
    723     }
    724     if (destreaked) {
    725         psStringAppend(&query, " AND diffSkyfile.magicked != 0");
    726     }
    727 
    728762
    729763    // treat limit == 0 as "no limit"
     
    878912    }
    879913
    880     char *query = "UPDATE diffRun SET state = '%s', magicked = %" PRId64 " WHERE diff_id = %"PRId64;
    881 
    882     if (!p_psDBRunQueryF(config->dbh, query, state, magicked, diff_id)) {
     914    if (magicked) {
     915      char *query = "UPDATE diffRun SET state = '%s', magicked = %" PRId64 " WHERE diff_id = %"PRId64;
     916     
     917      if (!p_psDBRunQueryF(config->dbh, query, state, magicked, diff_id)) {
    883918        psError(PS_ERR_UNKNOWN, false,
    884919                "failed to change state for diff_id %"PRId64, diff_id);
    885920        return false;
    886     }
    887 
     921      }
     922    }
     923    else {
     924      char *query = "UPDATE diffRun SET state = '%s' WHERE diff_id = %"PRId64;
     925     
     926      if (!p_psDBRunQueryF(config->dbh, query, state, diff_id)) {
     927        psError(PS_ERR_UNKNOWN, false,
     928                "failed to change state for diff_id %"PRId64, diff_id);
     929        return false;
     930      }
     931    }
     932   
    888933    return true;
    889934}
     935
     936
     937#ifdef notdef
     938static bool setdiffRunStateByLabel(pxConfig *config, const char *label, const char *state) {
     939  PS_ASSERT_PTR_NON_NULL(state,false);
     940
     941  // check that state is a valid string value
     942  if (!pxIsValidState(state)) {
     943    psError(PS_ERR_UNKNOWN, false, "invalid diffRun state: %s", state);
     944    return false;
     945  }
     946
     947  char *query = "UPDATE diffRun SET state = '%s' WHERE label = '%s'";
     948  if (!p_psDBRunQueryF(config->dbh,query,state,label)) {
     949    psError(PS_ERR_UNKNOWN, false,
     950            "failed to change state for label %s", label);
     951    return(false);
     952  }
     953
     954  return true;
     955}
     956#endif
    890957
    891958// Generate a single populated run
     
    895962                         const char *tess_id, // Tessellation identifier
    896963                         const char *label, // label
     964                         const char *data_group, // data_group
     965                         const char *dist_group, // dist_group
    897966                         const char *reduction, // reduction
     967                         const char *note,      // note
    898968                         psS64 input_warp_id, // Warp identifier for input image, PS_MAX_S64 for none
    899969                         psS64 input_stack_id, // Stack identifier for input image, PS_MAX_S64 for none
     
    926996            workdir,
    927997            label,
     998            data_group ? data_group : label,
     999            dist_group,
    9281000            reduction,
    9291001            NULL,       // dvodb
     
    9321004            false,
    9331005            false,
    934             0       // magicked
     1006            0,       // magicked
     1007            note
    9351008    );
    9361009
     
    10061079    PXOPT_LOOKUP_STR(tess_id, config->args, "-tess_id", true, false); // required options
    10071080    PXOPT_LOOKUP_STR(label, config->args, "-label", false, false);
     1081    PXOPT_LOOKUP_STR(data_group, config->args, "-set_data_group", false, false);
     1082    PXOPT_LOOKUP_STR(dist_group, config->args, "-set_dist_group", false, false);
    10081083    PXOPT_LOOKUP_STR(reduction, config->args, "-reduction", false, false);
    10091084    PXOPT_LOOKUP_S64(template_warp_id, config->args, "-template_warp_id", false, false);
     
    10121087    PXOPT_LOOKUP_S64(input_stack_id, config->args, "-input_stack_id", false, false);
    10131088    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
     1089    PXOPT_LOOKUP_STR(note, config->args, "-set_note", false, false);
    10141090
    10151091    if (template_stack_id && template_warp_id) {
     
    10351111    psArray *list = psArrayAllocEmpty(16); // List of runs, to print
    10361112
    1037     if (!populatedrun(list, workdir, skycell_id, tess_id, label, reduction,
     1113    if (!populatedrun(list, workdir, skycell_id, tess_id, label, data_group ? data_group : label, dist_group, reduction, note,
    10381114                      input_warp_id ? input_warp_id : PS_MAX_S64,
    10391115                      input_stack_id ? input_stack_id : PS_MAX_S64,
     
    10741150    PXOPT_COPY_STR(config->args, stackWhere, "-stack_label", "stackRun.label", "==");
    10751151
    1076     PXOPT_LOOKUP_STR(workdir, config->args, "-workdir", true, false); // required options
    1077     PXOPT_LOOKUP_STR(reduction, config->args, "-reduction", false, false); // option
    1078     PXOPT_LOOKUP_STR(label, config->args, "-label", false, false); // option
    1079     PXOPT_LOOKUP_TIME(registered, config->args, "-registered", false, false);
     1152    PXOPT_LOOKUP_STR(workdir, config->args, "-set_workdir", true, false); // required option
     1153    PXOPT_LOOKUP_STR(reduction, config->args, "-set_reduction", false, false); // option
     1154    PXOPT_LOOKUP_STR(label, config->args, "-set_label", false, false); // option
     1155    PXOPT_LOOKUP_STR(data_group, config->args, "-set_data_group", false, false);
     1156    PXOPT_LOOKUP_STR(dist_group, config->args, "-set_dist_group", false, false);
     1157    PXOPT_LOOKUP_STR(note, config->args, "-set_note", false, false);
     1158    PXOPT_LOOKUP_TIME(registered, config->args, "-set_registered", false, false);
     1159
    10801160    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
    10811161    PXOPT_LOOKUP_BOOL(newTemplates, config->args, "-new-templates", false);
     
    13131393                workdir,
    13141394                label,
     1395                data_group ? data_group : label,
     1396                dist_group,
    13151397                reduction,
    13161398                NULL,       // dvodb
     
    13191401                false,                  // bothways
    13201402                true,                   // exposure
    1321                 0       // magicked
     1403                0,       // magicked
     1404                note
    13221405        );
    13231406
     
    13881471    }
    13891472
    1390     if (!diffRunPrintObjects(stdout, list, !simple)) {
     1473    if (numGood && !diffRunPrintObjects(stdout, list, !simple)) {
    13911474        psError(PS_ERR_UNKNOWN, false, "failed to print object");
    13921475        psFree(list);
     
    14691552
    14701553    // Settings to apply to defined run
    1471     PXOPT_LOOKUP_STR(workdir, config->args, "-workdir", true, false); // required options
    1472     PXOPT_LOOKUP_STR(reduction, config->args, "-reduction", false, false); // option
    1473     PXOPT_LOOKUP_STR(label, config->args, "-label", false, false); // option
    1474     PXOPT_LOOKUP_TIME(registered, config->args, "-registered", false, false);
     1554    PXOPT_LOOKUP_STR(workdir, config->args, "-set_workdir", true, false); // required options
     1555    PXOPT_LOOKUP_STR(reduction, config->args, "-set_reduction", false, false); // option
     1556    PXOPT_LOOKUP_STR(label, config->args, "-set_label", false, false); // option
     1557    PXOPT_LOOKUP_STR(data_group, config->args, "-set_data_group", false, false); // option
     1558    PXOPT_LOOKUP_STR(dist_group, config->args, "-set_dist_group", false, false); // option
     1559    PXOPT_LOOKUP_STR(note, config->args, "-set_note", false, false); // option
     1560    PXOPT_LOOKUP_TIME(registered, config->args, "-set_registered", false, false);
     1561
    14751562    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
    14761563    PXOPT_LOOKUP_BOOL(pretend, config->args, "-pretend", false);
     
    16561743        }
    16571744
    1658         diffRunRow *run = diffRunRowAlloc(0, "reg", workdir, label, reduction, NULL, registered,
    1659                                           tess_id, true, true, false); // Run to insert
     1745        diffRunRow *run = diffRunRowAlloc(0, "reg", workdir, label, data_group ? data_group : label, dist_group, reduction, NULL, registered,
     1746                                          tess_id, true, true, false, note); // Run to insert
    16601747        if (!diffRunInsertObject(config->dbh, run)) {
    16611748            psError(PS_ERR_UNKNOWN, false, "database error");
     
    17381825
    17391826    psMetadata *where = psMetadataAlloc();
    1740     pxAddLabelSearchArgs (config, where, "-label", "diffRun.label", "==");
     1827    pxAddLabelSearchArgs (config, where, "-label", "label", "==");
    17411828
    17421829    psString query = pxDataGet("difftool_pendingcleanuprun.sql");
     
    17601847    }
    17611848
     1849    //    fprintf(stderr,"%s",query);
    17621850    if (!p_psDBRunQuery(config->dbh, query)) {
    17631851        psError(PS_ERR_UNKNOWN, false, "database error");
     
    19312019
    19322020    return true;
     2021}
     2022
     2023static bool change_skyfile_data_state(pxConfig *config, psString data_state, psString run_state) {
     2024  PS_ASSERT_PTR_NON_NULL(config, false);
     2025
     2026  // diff_id, skycell_id are required
     2027  PXOPT_LOOKUP_S64(diff_id, config->args, "-diff_id", true, false);
     2028  PXOPT_LOOKUP_STR(skycell_id, config->args, "-skycell_id", true, false);
     2029
     2030  psString query = pxDataGet("difftool_change_skyfile_data_state.sql");
     2031
     2032  if (!psDBTransaction(config->dbh)) {
     2033    psError(PS_ERR_UNKNOWN, false, "database error");
     2034    return(false);
     2035  }
     2036
     2037  // Uses the unconstrained (diffRun.state [NEED NOT EQUAL] run_state) version from warptool.c
     2038
     2039  if (!p_psDBRunQueryF(config->dbh, query, data_state, diff_id, skycell_id)) {
     2040    psError(PS_ERR_UNKNOWN, false, "database error");
     2041    // rollback
     2042    if (!psDBRollback(config->dbh)) {
     2043      psError(PS_ERR_UNKNOWN, false, "database error");
     2044    }
     2045    psError(PS_ERR_UNKNOWN, false, "database error");
     2046    return(false);
     2047  }
     2048  psFree(query);
     2049
     2050  query = pxDataGet("difftool_change_run_state.sql");
     2051  if (!p_psDBRunQueryF(config->dbh, query, data_state, diff_id, data_state)) {
     2052    // rollback
     2053    if (!psDBRollback(config->dbh)) {
     2054      psError(PS_ERR_UNKNOWN, false, "database error");
     2055    }
     2056    psError(PS_ERR_UNKNOWN, false, "database error");
     2057    return(false);
     2058  }
     2059
     2060  if (!psDBCommit(config->dbh)) {
     2061    psError(PS_ERR_UNKNOWN, false, "database error");
     2062    return(false);
     2063  }
     2064 
     2065  return(true);
     2066}
     2067
     2068static bool tocleanedskyfileMode(pxConfig *config) {
     2069  return change_skyfile_data_state(config, "cleaned","goto_cleaned");
     2070}
     2071static bool topurgedskyfileMode(pxConfig *config) {
     2072  return change_skyfile_data_state(config, "purged", "goto_purged");
     2073}
     2074static bool toscrubbedskyfileMode(pxConfig *config) {
     2075  return change_skyfile_data_state(config, "scrubbed", "goto_scrubbed");
    19332076}
    19342077
     
    19562099  }
    19572100
     2101  if (!pxExportVersion(config, f)) {
     2102    psError(PS_ERR_UNKNOWN, false, "failed to write dbversion output file");
     2103    return false;
     2104  }
    19582105  psMetadata *where = psMetadataAlloc();
    19592106  PXOPT_COPY_S64(config->args, where, "-diff_id", "diff_id", "==");
     
    20472194  psMetadata *input = psMetadataConfigRead (NULL, &nFail, infile, false);
    20482195
    2049   fprintf (stdout, "---- input ----\n");
     2196#ifdef notdef
     2197  fprintf (stderr, "---- input ----\n");
    20502198  psMetadataPrint (stderr, input, 1);
    2051 
     2199#endif
     2200
     2201  if (!pxCheckImportVersion(config, input)) {
     2202      psError(PS_ERR_UNKNOWN, false, "pxCheckImportVersion failed");
     2203      return false;
     2204  }
    20522205  psMetadataItem *item = psMetadataLookup (input, "diffRun");
    20532206  psAssert (item, "entry not in input?");
  • branches/eam_branches/20090820/ippTools/src/difftool.h

    r25766 r25870  
    4242    DIFFTOOL_MODE_UPDATEDIFFSKYFILE,
    4343    DIFFTOOL_MODE_EXPORTRUN,
    44     DIFFTOOL_MODE_IMPORTRUN
     44    DIFFTOOL_MODE_IMPORTRUN,
     45    DIFFTOOL_MODE_TOCLEANEDSKYFILE,
     46    DIFFTOOL_MODE_TOPURGEDSKYFILE,
     47    DIFFTOOL_MODE_TOSCRUBBEDSKYFILE
     48   
    4549} difftoolMode;
    4650
  • branches/eam_branches/20090820/ippTools/src/difftoolConfig.c

    r25766 r25870  
    4747    // -definerun
    4848    psMetadata *definerunArgs = psMetadataAlloc();
    49     psMetadataAddStr(definerunArgs, PS_LIST_TAIL, "-workdir", 0,            "define workdir (required)", NULL);
     49    psMetadataAddStr(definerunArgs, PS_LIST_TAIL, "-set_workdir", 0,         "define workdir (required)", NULL);
    5050    psMetadataAddStr(definerunArgs, PS_LIST_TAIL, "-tess_id",  0,            "define tessellation ID (required)", NULL);
    51     psMetadataAddBool(definerunArgs, PS_LIST_TAIL, "-bothways",  0,            "do the subtraction both ways?", false);
    52     psMetadataAddBool(definerunArgs, PS_LIST_TAIL, "-exposure",  0,            "subtraction for entire exposure?", false);
    53     psMetadataAddStr(definerunArgs, PS_LIST_TAIL, "-label",  0,            "define label", NULL);
    54     psMetadataAddStr(definerunArgs, PS_LIST_TAIL, "-reduction",  0,            "define reduction class", NULL);
    55     psMetadataAddTime(definerunArgs, PS_LIST_TAIL, "-registered",  0,            "time detrend run was registered", now);
     51    psMetadataAddBool(definerunArgs, PS_LIST_TAIL, "-bothways",  0,          "do the subtraction both ways?", false);
     52    psMetadataAddBool(definerunArgs, PS_LIST_TAIL, "-exposure",  0,          "subtraction for entire exposure?", false);
     53    psMetadataAddStr(definerunArgs, PS_LIST_TAIL, "-set_label",  0,          "define label", NULL);
     54    psMetadataAddStr(definerunArgs, PS_LIST_TAIL, "-set_reduction",  0,      "define reduction class", NULL);
     55    psMetadataAddTime(definerunArgs, PS_LIST_TAIL, "-set_registered",  0,    "time detrend run was registered", now);
     56    psMetadataAddStr(definerunArgs, PS_LIST_TAIL, "-set_data_group",  0,     "define data group", NULL);
     57    psMetadataAddStr(definerunArgs, PS_LIST_TAIL, "-set_dist_group",  0,     "define dist group", NULL);
     58    psMetadataAddStr(definerunArgs, PS_LIST_TAIL, "-set_note",  0,           "define note", NULL);
    5659    psMetadataAddBool(definerunArgs, PS_LIST_TAIL, "-simple",  0,            "use the simple output format", false);
    5760
    5861    // -updaterun
    5962    psMetadata *updaterunArgs = psMetadataAlloc();
    60     psMetadataAddS64(updaterunArgs, PS_LIST_TAIL, "-diff_id", 0,            "define diff ID (required)", 0);
    61     psMetadataAddStr(updaterunArgs, PS_LIST_TAIL, "-state", 0,            "set state (required)", NULL);
     63    psMetadataAddS64(updaterunArgs, PS_LIST_TAIL, "-diff_id", 0,          "define diff ID", 0);
     64    psMetadataAddStr(updaterunArgs, PS_LIST_TAIL, "-state", 0,            "set state", NULL);
     65    psMetadataAddStr(updaterunArgs, PS_LIST_TAIL, "-label", 0,            "define by label instead of diff ID", 0);
     66    psMetadataAddStr(updaterunArgs, PS_LIST_TAIL, "-set_label", 0,        "define new value for label", 0);
     67    psMetadataAddStr(updaterunArgs, PS_LIST_TAIL, "-set_state", 0,        "define new state", NULL);
     68    psMetadataAddStr(updaterunArgs, PS_LIST_TAIL, "-set_data_group", 0,   "define new data_group", NULL);
     69    psMetadataAddStr(updaterunArgs, PS_LIST_TAIL, "-set_dist_group", 0,   "define new dist_group", NULL);
     70    psMetadataAddStr(updaterunArgs, PS_LIST_TAIL, "-set_note", 0,         "define new note", NULL);
    6271
    6372    // -addinputskyfile
     
    134143    psMetadataAddTime(diffskyfileArgs, PS_LIST_TAIL, "-dateobs_end", 0,      "search for exposures by time (<=)", NULL);
    135144    psMetadataAddStr(diffskyfileArgs, PS_LIST_TAIL,  "-filter", 0,           "search for filter", NULL);
    136     psMetadataAddS64(diffskyfileArgs, PS_LIST_TAIL,  "-magicked", 0,         "search by magicked value", 0);
    137     psMetadataAddBool(diffskyfileArgs, PS_LIST_TAIL, "-destreaked",  0,      "search for destreaked images", false);
    138     psMetadataAddBool(diffskyfileArgs, PS_LIST_TAIL, "-not_destreaked",  0,  "search for images that are not destreaked", false);
    139145    psMetadataAddStr(diffskyfileArgs,  PS_LIST_TAIL, "-label",  PS_META_DUPLICATE_OK, "search by diffRun label (LIKE comparison)", NULL);
    140146    psMetadataAddS16(diffskyfileArgs, PS_LIST_TAIL,  "-fault",  0,           "search by fault code", 0);
     147    pxmagicAddArguments(diffskyfileArgs);
     148    pxspaceAddArguments(diffskyfileArgs);
    141149
    142150    psMetadataAddBool(diffskyfileArgs, PS_LIST_TAIL, "-all",  0,             "search without arguments", false);
     
    175183    psMetadataAddStr(definewarpstackArgs, PS_LIST_TAIL, "-warp_label", 0, "search by warp label", NULL);
    176184    psMetadataAddF32(definewarpstackArgs, PS_LIST_TAIL, "-good_frac", 0, "minimum good fraction of skycell", NAN);
    177     psMetadataAddStr(definewarpstackArgs, PS_LIST_TAIL, "-workdir", 0, "define workdir (required)", NULL);
    178     psMetadataAddStr(definewarpstackArgs, PS_LIST_TAIL, "-label",  0, "define label", NULL);
    179     psMetadataAddStr(definewarpstackArgs, PS_LIST_TAIL, "-reduction",  0, "define reduction class", NULL);
    180     psMetadataAddTime(definewarpstackArgs, PS_LIST_TAIL, "-registered", 0, "time detrend run was registered", now);
     185    psMetadataAddStr(definewarpstackArgs, PS_LIST_TAIL, "-set_workdir", 0, "define workdir (required)", NULL);
     186    psMetadataAddStr(definewarpstackArgs, PS_LIST_TAIL, "-set_label",  0, "define label", NULL);
     187    psMetadataAddStr(definewarpstackArgs, PS_LIST_TAIL, "-set_reduction",  0, "define reduction class", NULL);
     188    psMetadataAddTime(definewarpstackArgs, PS_LIST_TAIL, "-set_registered", 0, "time detrend run was registered", now);
     189    psMetadataAddStr(definewarpstackArgs, PS_LIST_TAIL, "-set_data_group",  0,     "define data group", NULL);
     190    psMetadataAddStr(definewarpstackArgs, PS_LIST_TAIL, "-set_dist_group",  0,     "define dist group", NULL);
     191    psMetadataAddStr(definewarpstackArgs, PS_LIST_TAIL, "-set_note",  0,           "define note", NULL);
    181192    psMetadataAddBool(definewarpstackArgs, PS_LIST_TAIL, "-new-templates", 0, "also search for diffs with new template", false);
    182193    psMetadataAddBool(definewarpstackArgs, PS_LIST_TAIL, "-rerun", 0, "define new run even if one exists", false);
     
    198209    psMetadataAddStr(definewarpwarpArgs, PS_LIST_TAIL, "-template_label", 0, "search by warp label for template", NULL);
    199210    psMetadataAddF32(definewarpwarpArgs, PS_LIST_TAIL, "-good_frac", 0, "minimum good fraction of skycell", NAN);
    200     psMetadataAddStr(definewarpwarpArgs, PS_LIST_TAIL, "-workdir", 0, "define workdir (required)", NULL);
    201     psMetadataAddStr(definewarpwarpArgs, PS_LIST_TAIL, "-label",  0, "define label", NULL);
    202     psMetadataAddStr(definewarpwarpArgs, PS_LIST_TAIL, "-reduction",  0, "define reduction class", NULL);
    203     psMetadataAddTime(definewarpwarpArgs, PS_LIST_TAIL, "-registered", 0, "time detrend run was registered", now);
     211    psMetadataAddStr(definewarpwarpArgs, PS_LIST_TAIL, "-set_workdir", 0, "define workdir (required)", NULL);
     212    psMetadataAddStr(definewarpwarpArgs, PS_LIST_TAIL, "-set_label",  0, "define label", NULL);
     213    psMetadataAddStr(definewarpwarpArgs, PS_LIST_TAIL, "-set_reduction",  0, "define reduction class", NULL);
     214    psMetadataAddTime(definewarpwarpArgs, PS_LIST_TAIL, "-set_registered", 0, "time detrend run was registered", now);
     215    psMetadataAddStr(definewarpwarpArgs, PS_LIST_TAIL, "-set_data_group",  0,     "define data group", NULL);
     216    psMetadataAddStr(definewarpwarpArgs, PS_LIST_TAIL, "-set_dist_group",  0,     "define dist group", NULL);
     217    psMetadataAddStr(definewarpwarpArgs, PS_LIST_TAIL, "-set_note",  0,           "define note", NULL);
    204218    psMetadataAddBool(definewarpwarpArgs, PS_LIST_TAIL, "-rerun", 0, "define new run even if one exists", false);
    205219    psMetadataAddBool(definewarpwarpArgs, PS_LIST_TAIL, "-available", 0, "define new run even if warpRun has some faults", false);
     
    259273    psMetadataAddS16(updatediffskyfileArgs, PS_LIST_TAIL, "-fault", 0,         "set fault code (required)", 0);
    260274
     275    // -tocleanedskyfile
     276    psMetadata *tocleanedskyfileArgs = psMetadataAlloc();
     277    psMetadataAddS64(tocleanedskyfileArgs, PS_LIST_TAIL, "-diff_id", 0, "difftool ID to update", 0);
     278    psMetadataAddStr(tocleanedskyfileArgs, PS_LIST_TAIL, "-skycell_id", 0, "skycell ID to update", NULL);
     279
     280    // -topurgedskyfile
     281    psMetadata *topurgedskyfileArgs = psMetadataAlloc();
     282    psMetadataAddS64(topurgedskyfileArgs, PS_LIST_TAIL, "-diff_id", 0,    "difftool ID to update", 0);
     283    psMetadataAddStr(topurgedskyfileArgs, PS_LIST_TAIL, "-skycell_id", 0, "skycell ID to update", NULL);
     284
     285    // -toscrubbedskyfile
     286    psMetadata *toscrubbedskyfileArgs = psMetadataAlloc();
     287    psMetadataAddS64(toscrubbedskyfileArgs, PS_LIST_TAIL, "-diff_id", 0, "difftool ID to update", 0);
     288    psMetadataAddStr(toscrubbedskyfileArgs, PS_LIST_TAIL, "-skycell_id", 0, "skycell ID to update", NULL);
     289
    261290    // -exportrun
    262291    psMetadata *exportrunArgs = psMetadataAlloc();
     
    296325    PXOPT_ADD_MODE("-importrun",            "import run from metadata file",           DIFFTOOL_MODE_IMPORTRUN, importrunArgs);
    297326
     327    PXOPT_ADD_MODE("-tocleanedskyfile", "set skyfile as cleaned", DIFFTOOL_MODE_TOCLEANEDSKYFILE, tocleanedskyfileArgs);
     328    PXOPT_ADD_MODE("-topurgedskyfile", "set skyfile as purged", DIFFTOOL_MODE_TOPURGEDSKYFILE, topurgedskyfileArgs);
     329    PXOPT_ADD_MODE("-toscrubbedskyfile", "set skyfile as scrubbed", DIFFTOOL_MODE_TOSCRUBBEDSKYFILE, toscrubbedskyfileArgs);
     330   
    298331    if (!pxGetOptions(stderr, argc, argv, config, modes, argSets)) {
    299332        psError(PS_ERR_UNKNOWN, true, "option parsing failed");
  • branches/eam_branches/20090820/ippTools/src/disttool.c

    r25766 r25870  
    3232
    3333static bool definebyqueryMode(pxConfig *config);
    34 static bool definerunMode(pxConfig *config);
    3534static bool updaterunMode(pxConfig *config);
    3635static bool revertrunMode(pxConfig *config);
     
    7978    switch (config->mode) {
    8079        MODECASE(DISTTOOL_MODE_DEFINEBYQUERY, definebyqueryMode);
    81         MODECASE(DISTTOOL_MODE_DEFINERUN, definerunMode);
    8280        MODECASE(DISTTOOL_MODE_UPDATERUN, updaterunMode);
    8381        MODECASE(DISTTOOL_MODE_REVERTRUN, revertrunMode);
     
    123121}
    124122
    125 static bool definerunMode(pxConfig *config)
    126 {
    127     PS_ASSERT_PTR_NON_NULL(config, false);
    128 
    129     // required
    130     PXOPT_LOOKUP_STR(stage, config->args, "-stage", true, false);
    131     PXOPT_LOOKUP_S64(stage_id, config->args, "-stage_id",  true, false);
    132     PXOPT_LOOKUP_STR(outroot, config->args, "-outroot", true, false);
    133     PXOPT_LOOKUP_S64(target_id, config->args, "-target_id",  true, false);
    134 
    135     // optional
    136     PXOPT_LOOKUP_BOOL(clean, config->args, "-clean", false);
    137     PXOPT_LOOKUP_BOOL(no_magic, config->args, "-no_magic", false);
    138     PXOPT_LOOKUP_STR(set_label, config->args, "-set_label", false, false);
    139 
    140     // TODO: check that stage has an expected value
    141     // XXX: all of the following concerns will be managed properly by definebyquery
    142 
    143     // TODO: should we check that stage_id actually exists for stage
    144     // in magicdstool we queue off of a magic_id so the stage_id, exp_id, and cam_id get looked up
    145     // when the run is queued
    146 
    147     if (!distRunInsert(config->dbh,
    148             0,          // dist_id
    149             target_id,
    150             stage,
    151             stage_id,
    152             0,
    153             set_label,
    154             outroot,
    155             clean,
    156             no_magic,
    157             "new",
    158             NULL,       // time_stamp
    159             0           // fault
    160             )) {
    161         psError(PS_ERR_UNKNOWN, false, "database error");
    162         return false;
    163     }
    164 
    165     return true;
    166 }
    167123
    168124static bool definebyqueryMode(pxConfig *config)
     
    178134    PXOPT_LOOKUP_BOOL(no_magic, config->args, "-no_magic", false);
    179135    PXOPT_LOOKUP_STR(set_label, config->args, "-set_label", false, false);
     136    PXOPT_LOOKUP_STR(set_note, config->args, "-set_note", false, false);
     137
    180138    PXOPT_LOOKUP_S64(limit, config->args, "-limit", false, false);
    181139    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
     
    191149
    192150    PXOPT_LOOKUP_STR(label, config->args, "-label", false, false);
     151    PXOPT_LOOKUP_STR(dist_group, config->args, "-dist_group", false, false);
    193152
    194153    psString query = NULL;
     
    209168            psStringAppend(&query, " AND (chipRun.label = '%s')", label);
    210169        }
     170        if (dist_group) {
     171            psStringAppend(&query, " AND (chipRun.dist_group = '%s')", dist_group);
     172        }
    211173    } else if (!strcmp(stage, "chip")) {
    212174        magicRunType = "chipRun";
     
    222184            psStringAppend(&query, " AND (chipRun.label = '%s')", label);
    223185        }
     186        if (dist_group) {
     187            psStringAppend(&query, " AND (chipRun.dist_group = '%s')", dist_group);
     188        }
    224189    } else if (!strcmp(stage, "camera")) {
    225190        magicRunType = "camRun";    // This is used below to set the magicked business
     
    235200            psStringAppend(&query, " AND (camRun.label = '%s')", label);
    236201        }
     202        if (dist_group) {
     203            psStringAppend(&query, " AND (camRun.dist_group = '%s')", dist_group);
     204        }
    237205    } else if (!strcmp(stage, "fake")) {
    238206        magicRunType = "fakeRun";
     
    246214        if (label) {
    247215            psStringAppend(&query, " AND (fakeRun.label = '%s')", label);
     216        }
     217        if (dist_group) {
     218            psStringAppend(&query, " AND (fakeRun.dist_group = '%s')", dist_group);
    248219        }
    249220        // fake stage doesn't require magic
     
    262233            psStringAppend(&query, " AND (warpRun.label = '%s')", label);
    263234        }
     235        if (dist_group) {
     236            psStringAppend(&query, " AND (warpRun.dist_group = '%s')", dist_group);
     237        }
    264238
    265239    } else if (!strcmp(stage, "diff")) {
     
    276250            psStringAppend(&query, " AND (diffRun.label = '%s')", label);
    277251        }
     252        if (dist_group) {
     253            psStringAppend(&query, " AND (diffRun.dist_group = '%s')", dist_group);
     254        }
    278255
    279256    } else if (!strcmp(stage, "stack")) {
     
    288265        if (label) {
    289266            psStringAppend(&query, " AND (stackRun.label = '%s')", label);
     267        }
     268        if (dist_group) {
     269            psStringAppend(&query, " AND (stackRun.dist_group = '%s')", dist_group);
    290270        }
    291271        // stack stage doesn't require magic
     
    371351        psS64 magic_ds_id = psMetadataLookupS64(NULL, md, "magicked");
    372352        psS64 target_id = psMetadataLookupS64(NULL, md, "target_id");
    373         psString target_label = psMetadataLookupStr(NULL, md, "label");
     353        psString stage_label = psMetadataLookupStr(NULL, md, "label");
    374354        bool clean = psMetadataLookupBool(NULL, md, "clean");
    375355
     
    381361            new_label = set_label;
    382362        } else {
    383             new_label = target_label;
     363            new_label = stage_label;
    384364        }
    385365        distRunRow *row = distRunRowAlloc(
     
    395375                "new",
    396376                NULL,   // time_stamp
    397                 0       // fault
     377                0,       // fault
     378                set_note    // note does not propagate
    398379                );
    399380
     
    12391220
    12401221    // required
    1241     PXOPT_LOOKUP_STR(label, config->args, "-label", true, false);
     1222    PXOPT_LOOKUP_STR(dist_group, config->args, "-dist_group", true, false);
    12421223    PXOPT_LOOKUP_STR(filter, config->args, "-filter", true, false);
    12431224    PXOPT_LOOKUP_STR(stage, config->args, "-stage", true, false);
     
    12501231    distTargetRow *row = distTargetRowAlloc(
    12511232            0,          // target_id
    1252             label,
     1233            dist_group,
    12531234            filter,
    12541235            stage,
     
    12871268    psMetadata *where = psMetadataAlloc();
    12881269    PXOPT_COPY_S64(config->args, where, "-target_id", "target_id", "==");
    1289     PXOPT_COPY_STR(config->args, where, "-label", "label", "==");
     1270    PXOPT_COPY_STR(config->args, where, "-dist_group", "dist_group", "==");
    12901271    PXOPT_COPY_STR(config->args, where, "-filter", "filter", "==");
    12911272    PXOPT_COPY_STR(config->args, where, "-stage", "stage", "==");
     
    13231304    psMetadata *where = psMetadataAlloc();
    13241305    PXOPT_COPY_S64(config->args, where, "-target_id", "target_id", "==");
    1325     PXOPT_COPY_STR(config->args, where, "-label", "label", "==");
     1306    PXOPT_COPY_STR(config->args, where, "-dist_group", "dist_group", "LIKE");
    13261307    PXOPT_COPY_STR(config->args, where, "-filter", "filter", "==");
    13271308    PXOPT_COPY_STR(config->args, where, "-stage", "stage", "==");
     
    15181499    PXOPT_LOOKUP_S64(target_id, config->args,    "-target_id", false, false);
    15191500    PXOPT_LOOKUP_STR(stage, config->args,        "-stage", false, false);
    1520     PXOPT_LOOKUP_STR(label, config->args,        "-label", false, false);
     1501    PXOPT_LOOKUP_STR(dist_group, config->args,   "-dist_group", false, false);
    15211502    PXOPT_LOOKUP_STR(filter, config->args,       "-filter", false, false);
    15221503    PXOPT_LOOKUP_BOOL(clean, config->args,       "-clean", false);
     
    15281509            error = true;
    15291510        }
    1530         if (!label) {
    1531             psError(PS_ERR_UNKNOWN, !error, "label is required if target_id is not supplied");
     1511        if (!dist_group) {
     1512            psError(PS_ERR_UNKNOWN, !error, "dist_group is required if target_id is not supplied");
    15321513            error = true;
    15331514        }
     
    15391520    // optional
    15401521    PXOPT_LOOKUP_S64(limit, config->args, "-limit", false, false);
    1541     PXOPT_LOOKUP_STR(state, config->args,        "-set_state", false, false);
     1522    PXOPT_LOOKUP_STR(state, config->args,  "-set_state", false, false);
    15421523    if (state) {
    15431524        if (strcmp(state, "enabled") && strcmp(state, "disabled")) {
     
    15551536    PXOPT_COPY_STR(config->args, where, "-dest_name", "rcDestination.name", "==");
    15561537    PXOPT_COPY_S64(config->args, where, "-target_id", "target_id", "==");
    1557     PXOPT_COPY_STR(config->args, where, "-label", "label", "LIKE");
     1538    PXOPT_COPY_STR(config->args, where, "-dist_group", "dist_group", "LIKE");
    15581539    PXOPT_COPY_STR(config->args, where, "-filter", "filter", "LIKE");
    15591540    PXOPT_COPY_STR(config->args, where, "-stage", "stage", "==");
     
    16581639    PXOPT_COPY_S64(config->args, where, "-target_id", "target_id", "==");
    16591640    PXOPT_COPY_STR(config->args, where, "-stage", "stage", "==");
    1660     PXOPT_COPY_STR(config->args, where, "-label", "label", "LIKE");
     1641    PXOPT_COPY_STR(config->args, where, "-dist_group", "dist_group", "LIKE");
    16611642    PXOPT_COPY_STR(config->args, where, "-filter", "filter", "LIKE");
    16621643    PXOPT_COPY_STR(config->args, where, "-state", "state", "==");
  • branches/eam_branches/20090820/ippTools/src/disttool.h

    r25766 r25870  
    2626    DISTTOOL_MODE_NONE      = 0x0,
    2727    DISTTOOL_MODE_DEFINEBYQUERY,
    28     DISTTOOL_MODE_DEFINERUN,
    2928    DISTTOOL_MODE_UPDATERUN,
    3029    DISTTOOL_MODE_REVERTRUN,
  • branches/eam_branches/20090820/ippTools/src/disttoolConfig.c

    r25766 r25870  
    5050    psMetadataAddBool(definebyqueryArgs, PS_LIST_TAIL, "-no_magic", 0, "magic is not needed", false);
    5151    psMetadataAddStr(definebyqueryArgs, PS_LIST_TAIL, "-set_label",    0, "define label for run", NULL);
     52    psMetadataAddStr(definebyqueryArgs, PS_LIST_TAIL, "-set_note",    0, "select by dist_group", NULL);
    5253
    5354    psMetadataAddBool(definebyqueryArgs, PS_LIST_TAIL, "-dry_run", 0, "don't queue runs just display what would be selected", false);
     
    5859    psMetadataAddS64(definebyqueryArgs, PS_LIST_TAIL, "-chip_id",       0, "define chip_id", 0);
    5960    psMetadataAddS64(definebyqueryArgs, PS_LIST_TAIL, "-magic_ds_id",   0, "define chip_id", 0);
    60     psMetadataAddStr(definebyqueryArgs, PS_LIST_TAIL, "-label",         0, "select by label", NULL);
     61    psMetadataAddStr(definebyqueryArgs, PS_LIST_TAIL, "-label",         0, "select by run label", NULL);
     62    psMetadataAddStr(definebyqueryArgs, PS_LIST_TAIL, "-dist_group",    0, "select by dist_group", NULL);
    6163
    6264    psMetadataAddU64(definebyqueryArgs, PS_LIST_TAIL, "-limit",  0,  "limit result set to N items", 0);
    6365    psMetadataAddBool(definebyqueryArgs, PS_LIST_TAIL, "-simple", 0, "use the simple output format", false);
    64 
    65     // -definerun
    66     psMetadata *definerunArgs = psMetadataAlloc();
    67     psMetadataAddStr(definerunArgs, PS_LIST_TAIL, "-stage",         0, "define stage for bundle (required)", NULL);
    68     psMetadataAddS64(definerunArgs, PS_LIST_TAIL, "-stage_id", 0, "define stage_id (required)", 0);
    69     psMetadataAddStr(definerunArgs, PS_LIST_TAIL, "-outroot",  0, "define output destination (required)", NULL);
    70     psMetadataAddS64(definerunArgs, PS_LIST_TAIL, "-target_id", 0, "define target_id (required)", 0);
    71     psMetadataAddBool(definerunArgs, PS_LIST_TAIL, "-clean", 0,   "build clean distribution bundle", false);
    72     psMetadataAddBool(definerunArgs, PS_LIST_TAIL, "-no_magic", 0, "magic is not needed", false);
    73     psMetadataAddStr(definerunArgs, PS_LIST_TAIL, "-set_label",    0, "define label for run", NULL);
    7466
    7567    // -updaterun
     
    139131    psMetadataAddS64(pendingfilesetArgs, PS_LIST_TAIL, "-dist_id", 0, "define dist_id", 0);
    140132    psMetadataAddStr(pendingfilesetArgs, PS_LIST_TAIL, "-label",   PS_META_DUPLICATE_OK, "limit results to label", NULL);
     133    psMetadataAddStr(pendingfilesetArgs, PS_LIST_TAIL, "-dist_group",   PS_META_DUPLICATE_OK, "limit results to dist_group", NULL);
    141134    psMetadataAddStr(pendingfilesetArgs, PS_LIST_TAIL, "-stage",   0, "limit results to runs for stage", NULL);
    142135    psMetadataAddU64(pendingfilesetArgs, PS_LIST_TAIL, "-limit",   0,  "limit result set to N items", 0);
     
    219212    // -definetarget
    220213    psMetadata *definetargetArgs = psMetadataAlloc();
    221     psMetadataAddStr(definetargetArgs, PS_LIST_TAIL, "-label",     0, "define label (required)", NULL);
     214    psMetadataAddStr(definetargetArgs, PS_LIST_TAIL, "-dist_group", 0, "define dist_group (required)", NULL);
    222215    psMetadataAddStr(definetargetArgs, PS_LIST_TAIL, "-filter",     0, "define filter (required)", NULL);
    223216    psMetadataAddStr(definetargetArgs, PS_LIST_TAIL, "-stage",     0, "define stage (required)", NULL);
     
    230223    psMetadataAddS64(updatetargetArgs, PS_LIST_TAIL, "-target_id", 0, "define target_id", 0);
    231224    psMetadataAddStr(updatetargetArgs, PS_LIST_TAIL, "-stage",     0, "define stage", NULL);
    232     psMetadataAddStr(updatetargetArgs, PS_LIST_TAIL, "-set_state", 0, "define state", NULL);
    233     psMetadataAddStr(updatetargetArgs, PS_LIST_TAIL, "-label",     0, "define label", NULL);
     225    psMetadataAddStr(updatetargetArgs, PS_LIST_TAIL, "-dist_group", 0, "define dist_group", NULL);
    234226    psMetadataAddStr(updatetargetArgs, PS_LIST_TAIL, "-filter",    0, "define filter", NULL);
     227
     228    psMetadataAddStr(updatetargetArgs, PS_LIST_TAIL, "-set_state", 0, "define new state", NULL);
    235229
    236230    // -listtarget
    237231    psMetadata *listtargetArgs = psMetadataAlloc();
    238232    psMetadataAddS64(listtargetArgs, PS_LIST_TAIL, "-target_id", 0, "list target with target_id", 0);
    239     psMetadataAddStr(listtargetArgs, PS_LIST_TAIL, "-label",  0, "list targets for label", NULL);
     233    psMetadataAddStr(listtargetArgs, PS_LIST_TAIL, "-dist_group",  0, "list targets for dist_group", NULL);
    240234    psMetadataAddStr(listtargetArgs, PS_LIST_TAIL, "-filter",    0, "define filter", NULL);
    241235    psMetadataAddStr(listtargetArgs, PS_LIST_TAIL, "-stage",     0, "list targets for stage", NULL);
     
    252246    psMetadataAddS64(defineinterestArgs, PS_LIST_TAIL, "-target_id", 0, "define target_id", 0);
    253247    psMetadataAddStr(defineinterestArgs, PS_LIST_TAIL, "-stage",     0, "define stage", NULL);
    254     psMetadataAddStr(defineinterestArgs, PS_LIST_TAIL, "-label",     0, "define label", NULL);
     248    psMetadataAddStr(defineinterestArgs, PS_LIST_TAIL, "-dist_group",     0, "define dist_group", NULL);
    255249    psMetadataAddStr(defineinterestArgs, PS_LIST_TAIL, "-filter",    0, "define filter (LIKE comparison)", NULL);
    256250    psMetadataAddBool(defineinterestArgs, PS_LIST_TAIL,"-clean",     0, "list clean targets", false);
     
    271265    psMetadataAddS64(listinterestsArgs, PS_LIST_TAIL, "-int_id", 0, "list interests with int_id", 0);
    272266    psMetadataAddStr(listinterestsArgs, PS_LIST_TAIL, "-dest_name",  0, "list interests for destinationn name)", NULL);
    273     psMetadataAddStr(listinterestsArgs, PS_LIST_TAIL, "-label",  0, "list interests for label (LIKE comparison)", NULL);
     267    psMetadataAddStr(listinterestsArgs, PS_LIST_TAIL, "-dist_group",  0, "list interests for dist_group (LIKE comparison)", NULL);
    274268    psMetadataAddStr(listinterestsArgs, PS_LIST_TAIL, "-filter",    0, "list interests by filter (LIKE comparison)", NULL);
    275269    psMetadataAddStr(listinterestsArgs, PS_LIST_TAIL, "-stage",     0, "list interests for stage", NULL);
     
    284278
    285279    PXOPT_ADD_MODE("-definebyquery",    "", DISTTOOL_MODE_DEFINEBYQUERY, definebyqueryArgs);
    286     PXOPT_ADD_MODE("-definerun",    "", DISTTOOL_MODE_DEFINERUN, definerunArgs);
    287280    PXOPT_ADD_MODE("-updaterun",    "", DISTTOOL_MODE_UPDATERUN, updaterunArgs);
    288281    PXOPT_ADD_MODE("-revertrun",    "", DISTTOOL_MODE_REVERTRUN, revertrunArgs);
  • branches/eam_branches/20090820/ippTools/src/faketool.c

    r25766 r25870  
    177177    PXOPT_LOOKUP_STR(tess_id, config->args, "-set_tess_id", false, false);
    178178    PXOPT_LOOKUP_STR(end_stage, config->args, "-set_end_stage", false, false);
     179    PXOPT_LOOKUP_STR(data_group, config->args, "-set_data_group", false, false);
     180    PXOPT_LOOKUP_STR(dist_group, config->args, "-set_dist_group", false, false);
     181    PXOPT_LOOKUP_STR(note, config->args, "-set_note", false, false);
    179182
    180183    // default
     
    265268
    266269        // queue the exp
    267         if (!pxfakeQueueByCamID(config, cam_id, workdir, label, reduction, expgroup, dvodb, tess_id, end_stage)) {
     270        if (!pxfakeQueueByCamID(config, cam_id, workdir, label, data_group ? data_group : label, dist_group, reduction, expgroup, dvodb, tess_id, end_stage, note)) {
    268271            if (!psDBRollback(config->dbh)) {
    269272                psError(PS_ERR_UNKNOWN, false, "database error");
     
    330333    PXOPT_COPY_F32(config->args, where, "-sun_angle_max", "sun_angle", "<");
    331334    PXOPT_COPY_STR(config->args, where, "-label", "fakeRun.label", "==");
    332 
    333     if (!psListLength(where->list)
    334         && !psMetadataLookupBool(NULL, config->args, "-all")) {
     335    PXOPT_COPY_STR(config->args, where, "-data_group", "fakeRun.data_group", "==");
     336    PXOPT_COPY_STR(config->args, where, "-dist_group", "fakeRun.dist_group", "==");
     337
     338    if (!psListLength(where->list)) {
    335339        psFree(where);
    336340        where = NULL;
     
    339343    }
    340344
    341     PXOPT_LOOKUP_STR(state, config->args, "-set_state", false, false);
    342     PXOPT_LOOKUP_STR(label, config->args, "-set_label", false, false);
    343 
    344     if ((!state) && (!label)) {
    345         psError(PXTOOLS_ERR_DATA, false, "parameters are required");
    346         psFree(where);
    347         return false;
    348     }
    349 
    350     if (state) {
    351         // set fakeRun.state to state
    352         if (!pxfakeRunSetStateByQuery(config, where, state)) {
    353             psFree(where);
    354             return false;
    355         }
    356     }
    357 
    358     if (label) {
    359         // set fakeRun.label to label
    360         if (!pxfakeRunSetLabelByQuery(config, where, label)) {
    361             psFree(where);
    362             return false;
    363         }
    364     }
    365 
     345    psString query = psStringCopy("UPDATE fakeRun JOIN camRun USING(cam_id) JOIN chipRun USING(chip_id) JOIN rawExp USING(exp_id)");
     346
     347    // pxUpdateRun gets parameters from config->args and updates
     348    bool result = pxUpdateRun(config, where, &query, "fakeRun", true);
     349    if (!result) {
     350        psError(PXTOOLS_ERR_DATA, false, "pxUpdateRun failed");
     351    }
     352
     353    psFree(query);
    366354    psFree(where);
    367355
    368     return true;
     356    return result;
    369357}
    370358
     
    11621150                                 fakeRun->workdir,
    11631151                                 fakeRun->label,
     1152                                 fakeRun->data_group,
     1153                                 fakeRun->dist_group,
    11641154                                 fakeRun->dvodb,
    11651155                                 fakeRun->tess_id,
    11661156                                 fakeRun->reduction,
    1167                                  fakeRun->end_stage
     1157                                 fakeRun->end_stage,
     1158                                 NULL // note does not propagate
    11681159        )) {
    11691160            psError(PS_ERR_UNKNOWN, false, "failed to queue warpRun");
     
    12791270    return false;
    12801271  }
    1281 
     1272  if (!pxExportVersion(config, f)) {
     1273    psError(PS_ERR_UNKNOWN, false, "failed to write dbversion output file");
     1274    return false;
     1275  }
    12821276  psMetadata *where = psMetadataAlloc();
    12831277  PXOPT_COPY_S64(config->args, where, "-fake_id", "fake_id", "==");
     
    13601354  psMetadata *input = psMetadataConfigRead (NULL, &nFail, infile, false);
    13611355
    1362   fprintf (stdout, "---- input ----\n");
     1356#ifdef notdef
     1357  fprintf (stderr, "---- input ----\n");
    13631358  psMetadataPrint (stderr, input, 1);
    1364 
     1359#endif
     1360
     1361  if (!pxCheckImportVersion(config, input)) {
     1362      psError(PS_ERR_UNKNOWN, false, "pxCheckImportVersion failed");
     1363      return false;
     1364  }
    13651365  psMetadataItem *item = psMetadataLookup (input, "fakeRun");
    13661366  psAssert (item, "entry not in input?");
  • branches/eam_branches/20090820/ippTools/src/faketoolConfig.c

    r25766 r25870  
    9393    psMetadataAddStr(queueArgs, PS_LIST_TAIL, "-set_tess_id",  0,            "define tessellation identifier", NULL);
    9494    psMetadataAddStr(queueArgs, PS_LIST_TAIL, "-set_end_stage",  0,            "define end stage", NULL);
     95    psMetadataAddStr(queueArgs, PS_LIST_TAIL, "-set_dist_group",  0,           "define dist group", NULL);
     96    psMetadataAddStr(queueArgs, PS_LIST_TAIL, "-set_data_group",  0,           "define data group", NULL);
     97    psMetadataAddStr(queueArgs, PS_LIST_TAIL, "-set_note",  0,                 "define note", NULL);
    9598    psMetadataAddBool(queueArgs, PS_LIST_TAIL, "-pretend",  0,            "do not actually modify the database", false);
    9699    psMetadataAddBool(queueArgs, PS_LIST_TAIL, "-all",  0,            "allow everything to be queued without search terms", false);
     
    139142    psMetadataAddF32(updaterunArgs, PS_LIST_TAIL, "-sun_angle_min",  0,            "define min solar angle", NAN);
    140143    psMetadataAddF32(updaterunArgs, PS_LIST_TAIL, "-sun_angle_max",  0,            "define max solar angle", NAN);
     144    psMetadataAddStr(updaterunArgs, PS_LIST_TAIL, "-state", 0, "search by state", NULL);
    141145    psMetadataAddStr(updaterunArgs, PS_LIST_TAIL, "-label", 0, "search by label", NULL);
     146    psMetadataAddStr(updaterunArgs, PS_LIST_TAIL, "-data_group", 0, "search by data_group", NULL);
     147    psMetadataAddStr(updaterunArgs, PS_LIST_TAIL, "-dist_group", 0, "search by data_group", NULL);
    142148
    143149    psMetadataAddStr(updaterunArgs, PS_LIST_TAIL, "-set_state", 0,            "set state", NULL);
    144150    psMetadataAddStr(updaterunArgs, PS_LIST_TAIL, "-set_label", 0,            "set label", NULL);
    145     psMetadataAddBool(updaterunArgs, PS_LIST_TAIL, "-all",  0,            "allow everything to be queued without search terms", false);
     151    psMetadataAddStr(updaterunArgs, PS_LIST_TAIL, "-set_data_group", 0,   "define new data_group", NULL);
     152    psMetadataAddStr(updaterunArgs, PS_LIST_TAIL, "-set_dist_group", 0,   "define new dist_group", NULL);
     153    psMetadataAddStr(updaterunArgs, PS_LIST_TAIL, "-set_note", 0,         "define new note", NULL);
    146154
    147155    // -pendingexp
  • branches/eam_branches/20090820/ippTools/src/flatcorr.c

    r24140 r25870  
    3333#include "pxtools.h"
    3434#include "pxchip.h"
     35#include "pxcam.h"
     36#include "pxadd.h"
    3537#include "flatcorr.h"
    3638
     
    3840static bool definerunMode(pxConfig *config);
    3941static bool addchipMode(pxConfig *config);
     42static bool dropchipMode(pxConfig *config);
    4043static bool addcameraMode(pxConfig *config);
    41 static bool dropchipMode(pxConfig *config);
    4244static bool dropcameraMode(pxConfig *config);
     45static bool advancecameraMode(pxConfig *config);
     46static bool advanceaddstarMode(pxConfig *config);
    4347static bool pendingprocessMode(pxConfig *config);
    4448static bool addprocessMode(pxConfig *config);
     
    4650static bool inputexpMode(pxConfig *config);
    4751static bool inputimfileMode(pxConfig *config);
    48 static bool exportrunMode(pxConfig *config);
    49 static bool importrunMode(pxConfig *config);
    5052
    5153static bool setflatcorrRunState(pxConfig *config, psS64 corr_id, const char *state);
     
    7274        MODECASE(FLATCORR_MODE_DEFINERUN,      definerunMode);
    7375        MODECASE(FLATCORR_MODE_ADDCHIP,        addchipMode);
     76        MODECASE(FLATCORR_MODE_DROPCHIP,       dropchipMode);
    7477        MODECASE(FLATCORR_MODE_ADDCAMERA,      addcameraMode);
    75         MODECASE(FLATCORR_MODE_DROPCHIP,       dropchipMode);
    7678        MODECASE(FLATCORR_MODE_DROPCAMERA,     dropcameraMode);
     79        MODECASE(FLATCORR_MODE_ADVANCECAMERA,  advancecameraMode);
     80        MODECASE(FLATCORR_MODE_ADVANCEADDSTAR, advanceaddstarMode);
    7781        MODECASE(FLATCORR_MODE_PENDINGPROCESS, pendingprocessMode);
    7882        MODECASE(FLATCORR_MODE_ADDPROCESS,     addprocessMode);
     
    8084        MODECASE(FLATCORR_MODE_INPUTEXP,       inputexpMode);
    8185        MODECASE(FLATCORR_MODE_INPUTIMFILE,    inputimfileMode);
    82         MODECASE(FLATCORR_MODE_EXPORTRUN,      exportrunMode);
    83         MODECASE(FLATCORR_MODE_IMPORTRUN,      importrunMode);
    8486        default:
    8587            psAbort("invalid option (this should not happen)");
     
    131133    PXOPT_LOOKUP_STR(tess_id, config->args, "-set_tess_id", false, false);
    132134    PXOPT_LOOKUP_STR(region, config->args, "-set_region", false, false);
     135    PXOPT_LOOKUP_STR(note, config->args, "-set_note", false, false);
    133136
    134137    PXOPT_LOOKUP_BOOL(pretend, config->args, "-pretend", false);
     
    233236
    234237        // queue the exp : force this to stop at the chip stage
    235         psS64 chip_id = pxchipQueueByExpTag(config, exp_id, workdir, label, reduction, expgroup, dvodb, tess_id, "chip");
     238        psS64 chip_id = pxchipQueueByExpTag(config, exp_id, workdir, label, label, NULL, reduction, expgroup, dvodb, tess_id, "chip", note);
    236239        if (!chip_id) {
    237240            if (!psDBRollback(config->dbh)) {
     
    297300    // start a transaction so we don't end up with an exp without any associted
    298301    // imfiles
    299     if (!psDBTransaction(config->dbh)) {
    300         psError(PS_ERR_UNKNOWN, false, "database error");
    301         return false;
    302     }
     302    // if (!psDBTransaction(config->dbh)) {
     303    //     psError(PS_ERR_UNKNOWN, false, "database error");
     304    //     return false;
     305    // }
    303306
    304307    // create a new flatcorrRun
     
    333336    row->corr_id = corr_id;
    334337
     338    // if (!psDBCommit(config->dbh)) {
     339    //     psError(PS_ERR_UNKNOWN, false, "database error");
     340    //     return false;
     341    // }
     342
    335343    flatcorrRunPrintObject (stdout, row, !simple);
    336344    return true;
     
    378386}
    379387
     388static bool addcameraMode(pxConfig *config)
     389{
     390    PS_ASSERT_PTR_NON_NULL(config, false);
     391
     392    // required
     393    PXOPT_LOOKUP_S64(corr_id, config->args, "-corr_id", true, false);
     394    PXOPT_LOOKUP_S64(chip_id, config->args, "-chip_id", true, false);
     395    PXOPT_LOOKUP_S64(cam_id, config->args, "-cam_id", true, false);
     396
     397    // add a flatcorrCamLink (initial state has include = TRUE)
     398    // XXX should add checks that the chip_id and corr_id are in ChipLink
     399    if (!flatcorrCamLinkInsert(config->dbh, corr_id, chip_id, cam_id, 1)) {
     400        psError(PS_ERR_UNKNOWN, false, "database error");
     401        return false;
     402    }
     403
     404    return true;
     405}
     406
     407static bool dropcameraMode(pxConfig *config)
     408{
     409    PS_ASSERT_PTR_NON_NULL(config, false);
     410
     411    // required
     412    PXOPT_LOOKUP_S64(corr_id, config->args, "-corr_id", true, false);
     413    PXOPT_LOOKUP_S64(cam_id, config->args, "-cam_id", true, false);
     414
     415    // UPDATE flatcorrCamLink set include = 0 where corr_id = %lld AND cam_id = %lld
     416    psString query = pxDataGet("flatcorr_dropcamera.sql");
     417    if (!query) {
     418        psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
     419        return false;
     420    }
     421
     422    if (!p_psDBRunQueryF(config->dbh, query, (long long) corr_id, (long long) cam_id)) {
     423        psError(PS_ERR_UNKNOWN, false, "database error");
     424        psFree(query);
     425        return false;
     426    }
     427
     428    return true;
     429}
     430
    380431// select the flatcorr chip runs that have completed and for which there is no camera entry
    381432// queue a new camera run for them
    382 static bool addcameraMode(pxConfig *config)
     433static bool advancecameraMode(pxConfig *config)
    383434{
    384435    PS_ASSERT_PTR_NON_NULL(config, false);
     
    387438    PXOPT_LOOKUP_BOOL(limit,   config->args, "-limit",   false);
    388439    PXOPT_LOOKUP_BOOL(pretend, config->args, "-pretend", false);
     440
     441    psMetadata *where = psMetadataAlloc();
     442    pxAddLabelSearchArgs (config, where, "-label", "flatcorrRun.label", "==");
    389443
    390444    psString query = pxDataGet("flatcorr_chiprundone.sql");
     
    393447        return false;
    394448    }
     449
     450    if (where && psListLength(where->list)) {
     451        psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
     452        psStringAppend(&query, " AND %s", whereClause);
     453        psFree(whereClause);
     454    }
     455    psFree(where);
    395456
    396457    // treat limit == 0 as "no limit"
     
    463524                row->workdir,
    464525                row->label,
     526                row->data_group,
     527                row->dist_group,
    465528                row->reduction,
    466529                row->expgroup,
    467530                row->dvodb,
    468531                row->tess_id,
    469                 "camera")) {
     532                "camera",
     533                NULL // note does not propragate
     534                )) {
    470535            if (!psDBRollback(config->dbh)) {
    471536                psError(PS_ERR_UNKNOWN, false, "database error");
     
    502567}
    503568
    504 static bool dropcameraMode(pxConfig *config)
    505 {
    506     PS_ASSERT_PTR_NON_NULL(config, false);
    507 
    508     // required
    509     PXOPT_LOOKUP_S64(corr_id, config->args, "-corr_id", true, false);
    510     PXOPT_LOOKUP_S64(cam_id, config->args, "-cam_id", true, false);
    511 
    512     // UPDATE flatcorrCamLink set include = 0 where corr_id = %lld AND cam_id = %lld
    513     psString query = pxDataGet("flatcorr_dropcamera.sql");
    514     if (!query) {
    515         psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
    516         return false;
    517     }
    518 
    519     if (!p_psDBRunQueryF(config->dbh, query, (long long) corr_id, (long long) cam_id)) {
    520         psError(PS_ERR_UNKNOWN, false, "database error");
    521         psFree(query);
    522         return false;
    523     }
    524 
    525     return true;
    526 }
    527 
    528 // select the flatcorr chip runs that have completed and for which there is no camera entry
    529 // queue a new camera run for them
    530 static bool pendingprocessMode(pxConfig *config)
     569// Select the flatcorr camera runs that have completed and for which there is no addstar
     570// entry.  Queue a new addstar run for them
     571static bool advanceaddstarMode(pxConfig *config)
    531572{
    532573    PS_ASSERT_PTR_NON_NULL(config, false);
     
    534575    PXOPT_LOOKUP_BOOL(simple,  config->args, "-simple",  false);
    535576    PXOPT_LOOKUP_BOOL(limit,   config->args, "-limit",   false);
     577    PXOPT_LOOKUP_BOOL(pretend, config->args, "-pretend", false);
    536578
    537579    psMetadata *where = psMetadataAlloc();
    538     pxAddLabelSearchArgs (config, where, "-label", "label", "==");
    539 
    540     psString query = pxDataGet("flatcorr_pendingprocess.sql");
     580    pxAddLabelSearchArgs (config, where, "-label", "flatcorrRun.label", "==");
     581
     582    psString query = pxDataGet("flatcorr_camerarundone.sql");
    541583    if (!query) {
    542584        psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
     
    575617    }
    576618
     619    if (pretend) {
     620        // negative simple so the default is true
     621        if (!ippdbPrintMetadatas(stdout, output, "flatcorr_addcamera", !simple)) {
     622            psError(PS_ERR_UNKNOWN, false, "failed to print array");
     623            psFree(output);
     624            return false;
     625        }
     626    }
     627
     628    // start a transaction so we don't end up with an exp without any associted
     629    // imfiles
     630    if (!psDBTransaction(config->dbh)) {
     631        psError(PS_ERR_UNKNOWN, false, "database error");
     632        psFree(output);
     633        return false;
     634    }
     635
     636    // loop over our list of chipRun rows
     637    for (long i = 0; i < psArrayLength(output); i++) {
     638        psMetadata *md = output->data[i];
     639
     640        bool status;
     641        psS64 corr_id = psMetadataLookupS64(&status, md, "corr_id");
     642        if (!status) {
     643            if (!psDBRollback(config->dbh)) {
     644                psError(PS_ERR_UNKNOWN, false, "database error");
     645            }
     646            psError(PS_ERR_UNKNOWN, false, "failed to lookup value for corr_id");
     647            psFree(output);
     648            return false;
     649        }
     650
     651        camRunRow *row = camRunObjectFromMetadata(md);
     652        if (!row) {
     653            psError(PS_ERR_UNKNOWN, false, "failed to convert metadata into chipRun");
     654            psFree(output);
     655            return false;
     656        }
     657
     658        // queue the exp : force image_only to be false (flatcorr is meaningless with just image info)
     659        if (!pxaddQueueByCamID(
     660                config,
     661                row->cam_id,
     662                row->workdir,
     663                row->reduction,
     664                row->label,
     665                row->data_group,
     666                row->dvodb,
     667                NULL,       // note is not propagated
     668                0)) {
     669            if (!psDBRollback(config->dbh)) {
     670                psError(PS_ERR_UNKNOWN, false, "database error");
     671            }
     672            psError(PS_ERR_UNKNOWN, false,
     673                    "failed to trying to queue cam_id: %" PRId64, row->cam_id);
     674            psFree(row);
     675            psFree(output);
     676            return false;
     677        }
     678
     679        // figure out the ID of the flatcorrRun we just created
     680        psS64 add_id = psDBLastInsertID(config->dbh);
     681
     682        // add the addRun entry to the flatcorrAddstarLink table (include is TRUE)
     683        if (!flatcorrAddstarLinkInsert(config->dbh, corr_id, row->cam_id, add_id, 1)) {
     684            if (!psDBRollback(config->dbh)) {
     685                psError(PS_ERR_UNKNOWN, false, "database error");
     686            }
     687            psError(PS_ERR_UNKNOWN, false, "database error");
     688            return false;
     689        }
     690        psFree(row);
     691    }
     692    psFree(output);
     693
     694    if (!psDBCommit(config->dbh)) {
     695        psError(PS_ERR_UNKNOWN, false, "database error");
     696        return false;
     697    }
     698
     699    return false;
     700}
     701
     702// select the flatcorr chip runs that have completed and for which there is no camera entry
     703// queue a new camera run for them
     704static bool pendingprocessMode(pxConfig *config)
     705{
     706    PS_ASSERT_PTR_NON_NULL(config, false);
     707
     708    PXOPT_LOOKUP_BOOL(simple,  config->args, "-simple",  false);
     709    PXOPT_LOOKUP_BOOL(limit,   config->args, "-limit",   false);
     710
     711    psMetadata *where = psMetadataAlloc();
     712    pxAddLabelSearchArgs (config, where, "-label", "label", "==");
     713
     714    psString query = pxDataGet("flatcorr_pendingprocess.sql");
     715    if (!query) {
     716        psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
     717        return false;
     718    }
     719
     720    if (where && psListLength(where->list)) {
     721        psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
     722        psStringAppend(&query, " AND %s", whereClause);
     723        psFree(whereClause);
     724    }
     725    psFree(where);
     726
     727    // treat limit == 0 as "no limit"
     728    if (limit) {
     729        psString limitString = psDBGenerateLimitSQL(limit);
     730        psStringAppend(&query, " %s", limitString);
     731        psFree(limitString);
     732    }
     733
     734    if (!p_psDBRunQuery(config->dbh, query)) {
     735        psError(PS_ERR_UNKNOWN, false, "database error");
     736        psFree(query);
     737        return false;
     738    }
     739
     740    psArray *output = p_psDBFetchResult(config->dbh);
     741    if (!output) {
     742        psError(PS_ERR_UNKNOWN, false, "database error");
     743        return false;
     744    }
     745    if (!psArrayLength(output)) {
     746        psTrace("flatcorr", PS_LOG_INFO, "no rows found");
     747        psFree(output);
     748        return true;
     749    }
     750
    577751    if (!ippdbPrintMetadatas(stdout, output, "flatcorrPending", !simple)) {
    578752        psError(PS_ERR_UNKNOWN, false, "failed to print array");
    579753        psFree(output);
    580754        return false;
     755    }
     756
     757    return true;
     758}
     759
     760// XXX need a fault state
     761static bool addprocessMode(pxConfig *config)
     762{
     763    PS_ASSERT_PTR_NON_NULL(config, false);
     764
     765    PXOPT_LOOKUP_S64(corr_id, config->args, "-corr_id", true, false);
     766    PXOPT_LOOKUP_STR(hostname, config->args, "-hostname", false, false);
     767    PXOPT_LOOKUP_S16(code, config->args, "-code", false, false);
     768
     769    char *query = "UPDATE flatcorrRun SET state = 'full', hostname = '%s', fault = '%hd' WHERE corr_id = %" PRId64;
     770
     771    if (!p_psDBRunQueryF(config->dbh, query, hostname, code, corr_id)) {
     772        psError(PS_ERR_UNKNOWN, false, "failed to change state for corr_id %" PRId64, corr_id);
     773        return false;
     774    }
     775
     776    return true;
     777}
     778
     779static bool updaterunMode(pxConfig *config)
     780{
     781    PS_ASSERT_PTR_NON_NULL(config, false);
     782
     783    PXOPT_LOOKUP_S64(corr_id, config->args, "-corr_id", true, false);
     784    PXOPT_LOOKUP_STR(state, config->args, "-state", true, false);
     785
     786    if (!setflatcorrRunState(config, corr_id, state)) {
     787        if (!psDBRollback(config->dbh)) {
     788            psError(PS_ERR_UNKNOWN, false, "database error");
     789        }
     790        psError(PS_ERR_UNKNOWN, false, "failed to set run state");
     791        return false;
    581792    }
    582793
     
    688899}
    689900
    690 // XXX need a fault state
    691 static bool addprocessMode(pxConfig *config)
    692 {
    693     PS_ASSERT_PTR_NON_NULL(config, false);
    694 
    695     PXOPT_LOOKUP_S64(corr_id, config->args, "-corr_id", true, false);
    696     PXOPT_LOOKUP_STR(hostname, config->args, "-hostname", false, false);
    697     PXOPT_LOOKUP_S16(code, config->args, "-code", false, false);
    698 
    699     char *query = "UPDATE flatcorrRun SET state = 'full', hostname = '%s', fault = '%hd' WHERE corr_id = %" PRId64;
    700 
    701     if (!p_psDBRunQueryF(config->dbh, query, hostname, code, corr_id)) {
    702         psError(PS_ERR_UNKNOWN, false, "failed to change state for corr_id %" PRId64, corr_id);
    703         return false;
    704     }
    705 
    706     return true;
    707 }
    708 
    709 static bool updaterunMode(pxConfig *config)
    710 {
    711     PS_ASSERT_PTR_NON_NULL(config, false);
    712 
    713     PXOPT_LOOKUP_S64(corr_id, config->args, "-corr_id", true, false);
    714     PXOPT_LOOKUP_STR(state, config->args, "-state", true, false);
    715 
    716     if (!setflatcorrRunState(config, corr_id, state)) {
    717         if (!psDBRollback(config->dbh)) {
    718             psError(PS_ERR_UNKNOWN, false, "database error");
    719         }
    720         psError(PS_ERR_UNKNOWN, false, "failed to set run state");
    721         return false;
    722     }
    723 
    724     return true;
    725 }
    726 
    727901static bool setflatcorrRunState(pxConfig *config, psS64 corr_id, const char *state)
    728902{
     
    748922    return true;
    749923}
    750 
    751 bool exportrunMode(pxConfig *config)
    752 {
    753   typedef struct ExportTable {
    754     char tableName[80];
    755     char sqlFilename[80];
    756   } ExportTable;
    757  
    758   int numExportTables = 3;
    759 
    760   PS_ASSERT_PTR_NON_NULL(config, NULL);
    761 
    762   PXOPT_LOOKUP_S64(det_id, config->args, "-corr_id", true,  false);
    763   PXOPT_LOOKUP_STR(outfile, config->args, "-outfile", true,  false);
    764   PXOPT_LOOKUP_U64(limit,   config->args, "-limit",   false, false);
    765 
    766   FILE *f = fopen (outfile, "w");
    767   if (f == NULL) {
    768     psError(PS_ERR_UNKNOWN, false, "failed to open output file");
    769     return false;
    770   }
    771 
    772   psMetadata *where = psMetadataAlloc();
    773   PXOPT_COPY_S64(config->args, where, "-corr_id", "corr_id", "==");
    774 
    775   ExportTable tables [] = {
    776     {"flatcorrRun", "flatcorr_export_run.sql"},
    777     {"flatcorrCamLink", "flatcorr_export_cam_link.sql"},
    778     {"flatcorrChipLink", "flatcorr_export_chip_link.sql"},
    779   };
    780 
    781   for (int i=0; i < numExportTables; i++) {
    782     psString query = pxDataGet(tables[i].sqlFilename);
    783     if (!query) {
    784       psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
    785       return false;
    786     }
    787 
    788     if (where && psListLength(where->list)) {
    789       psString whereClause = psDBGenerateWhereSQL(where, NULL);
    790       psStringAppend(&query, " %s", whereClause);
    791       psFree(whereClause);
    792     }
    793 
    794     // treat limit == 0 as "no limit"
    795     if (limit) {
    796       psString limitString = psDBGenerateLimitSQL(limit);
    797       psStringAppend(&query, " %s", limitString);
    798       psFree(limitString);
    799     }
    800 
    801     if (!p_psDBRunQuery(config->dbh, query)) {
    802       psError(PS_ERR_UNKNOWN, false, "database error");
    803       psFree(query);
    804       return false;
    805     }
    806     psFree(query);
    807 
    808     psArray *output = p_psDBFetchResult(config->dbh);
    809     if (!output) {
    810       psError(PS_ERR_UNKNOWN, false, "database error");
    811       return false;
    812     }
    813     if (!psArrayLength(output)) {
    814       psTrace("regtool", PS_LOG_INFO, "no rows found");
    815       psFree(output);
    816       return true;
    817     }
    818 
    819     // we must write the export table in non-simple (true) format
    820     if (!ippdbPrintMetadatas(f, output, tables[i].tableName, true)) {
    821       psError(PS_ERR_UNKNOWN, false, "failed to print array");
    822       psFree(output);
    823       return false;
    824     }
    825     psFree(output);
    826   }
    827 
    828     fclose (f);
    829 
    830     return true;
    831 }
    832 
    833 bool importrunMode(pxConfig *config)
    834 {
    835   unsigned int nFail;
    836   psMetadataItem *item, *entry;
    837  
    838   int numImportTables = 3;
    839  
    840   char tables[3] [80] = {"flatcorrRun", "flatcorrCamLink", "flatcorrChipLink"};
    841 
    842   PS_ASSERT_PTR_NON_NULL(config, NULL);
    843  
    844   PXOPT_LOOKUP_STR(infile, config->args, "-infile", true,  false);
    845 
    846   psMetadata *input = psMetadataConfigRead (NULL, &nFail, infile, false);
    847 
    848   fprintf (stdout, "---- input ----\n");
    849   psMetadataPrint (stderr, input, 1);
    850 
    851   for (int i = 0; i < numImportTables; i++) {
    852     item = psMetadataLookup (input, tables[i]);
    853     psAssert (item, "entry not in input?");
    854     psAssert (item->type == PS_DATA_METADATA_MULTI, "entry not multi?");
    855    
    856     entry = psListGet (item->data.list, 0);
    857     assert (entry);
    858     assert (entry->type == PS_DATA_METADATA);
    859  
    860     switch (i) {
    861       case 0:
    862       {
    863         flatcorrRunRow *flatcorrRun = flatcorrRunObjectFromMetadata (entry->data.md);
    864         flatcorrRunInsertObject (config->dbh, flatcorrRun);
    865 
    866         // fprintf (stdout, "---- flatcorr run ----\n");
    867         // psMetadataPrint (stderr, entry->data.md, 1);
    868         break;
    869       }
    870       case 1:
    871       {
    872         flatcorrCamLinkRow *flatcorrCamLink = flatcorrCamLinkObjectFromMetadata (entry->data.md);
    873         flatcorrCamLinkInsertObject (config->dbh, flatcorrCamLink);
    874 
    875         // fprintf (stdout, "---- flatcorr cam link ----\n");
    876         // psMetadataPrint (stderr, entry->data.md, 1);
    877         break;
    878       }
    879       case 2:
    880       {
    881         flatcorrChipLinkRow *flatcorrChipLink = flatcorrChipLinkObjectFromMetadata (entry->data.md);
    882         flatcorrChipLinkInsertObject (config->dbh, flatcorrChipLink);
    883 
    884         // fprintf (stdout, "---- flatcorr chip link ----\n");
    885         // psMetadataPrint (stderr, entry->data.md, 1);
    886         break;
    887       }
    888     }
    889   }
    890   return true;
    891 }
  • branches/eam_branches/20090820/ippTools/src/flatcorr.h

    r23310 r25870  
    2828    FLATCORR_MODE_DEFINERUN,
    2929    FLATCORR_MODE_ADDCHIP,
     30    FLATCORR_MODE_DROPCHIP,
    3031    FLATCORR_MODE_ADDCAMERA,
    31     FLATCORR_MODE_DROPCHIP,
    3232    FLATCORR_MODE_DROPCAMERA,
     33    FLATCORR_MODE_ADVANCECAMERA,
     34    FLATCORR_MODE_ADVANCEADDSTAR,
    3335    FLATCORR_MODE_PENDINGPROCESS,
    3436    FLATCORR_MODE_ADDPROCESS,
     
    3638    FLATCORR_MODE_INPUTEXP,
    3739    FLATCORR_MODE_INPUTIMFILE,
    38     FLATCORR_MODE_EXPORTRUN,
    39     FLATCORR_MODE_IMPORTRUN
    4040} flatcorrMode;
    4141
  • branches/eam_branches/20090820/ippTools/src/flatcorrConfig.c

    r24140 r25870  
    6565    // -definerun
    6666    psMetadata *definerunArgs = psMetadataAlloc();
     67    psMetadataAddStr(definerunArgs, PS_LIST_TAIL, "-inst", 0, "define camera", NULL);
     68    psMetadataAddStr(definerunArgs, PS_LIST_TAIL, "-telescope", 0, "define telescope", NULL);
    6769    psMetadataAddStr(definerunArgs, PS_LIST_TAIL, "-det_type",     0,            "define detrend type to be generated", NULL);
    6870    psMetadataAddStr(definerunArgs, PS_LIST_TAIL, "-set_workdir",  0,            "define workdir", NULL);
     
    8890    // -addcamera
    8991    psMetadata *addcameraArgs = psMetadataAlloc();
    90     psMetadataAddU64 (addcameraArgs, PS_LIST_TAIL, "-limit",   0, "limit result set to N items", 0);
    91     psMetadataAddBool(addcameraArgs, PS_LIST_TAIL, "-simple",  0, "use the simple output format", false);
    92     psMetadataAddBool(addcameraArgs, PS_LIST_TAIL, "-pretend", 0, "use the simple output format", false);
     92    psMetadataAddS64(addcameraArgs, PS_LIST_TAIL, "-corr_id", 0,            "define Flat Correction ID (required)", 0);
     93    psMetadataAddS64(addcameraArgs, PS_LIST_TAIL, "-chip_id", 0,            "define Chip ID (required)", 0);
     94    psMetadataAddS64(addcameraArgs, PS_LIST_TAIL, "-cam_id", 0,             "define Camera ID (required)", 0);
    9395
    9496    // -dropcamera
     
    9698    psMetadataAddS64(dropcameraArgs, PS_LIST_TAIL, "-corr_id", 0,      "define Flat Correction ID (required)", 0);
    9799    psMetadataAddS64(dropcameraArgs, PS_LIST_TAIL, "-cam_id", 0,       "define Camera ID (required)", 0);
     100
     101    // -advancecamera
     102    psMetadata *advancecameraArgs = psMetadataAlloc();
     103    psMetadataAddU64 (advancecameraArgs, PS_LIST_TAIL, "-limit",   0, "limit result set to N items", 0);
     104    psMetadataAddBool(advancecameraArgs, PS_LIST_TAIL, "-simple",  0, "use the simple output format", false);
     105    psMetadataAddBool(advancecameraArgs, PS_LIST_TAIL, "-pretend", 0, "use the simple output format", false);
     106    psMetadataAddStr(advancecameraArgs,  PS_LIST_TAIL, "-label",  PS_META_DUPLICATE_OK, "search by label", NULL);
     107
     108    // -advanceaddstar
     109    psMetadata *advanceaddstarArgs = psMetadataAlloc();
     110    psMetadataAddU64 (advanceaddstarArgs, PS_LIST_TAIL, "-limit",   0, "limit result set to N items", 0);
     111    psMetadataAddBool(advanceaddstarArgs, PS_LIST_TAIL, "-simple",  0, "use the simple output format", false);
     112    psMetadataAddBool(advanceaddstarArgs, PS_LIST_TAIL, "-pretend", 0, "use the simple output format", false);
     113    psMetadataAddStr(advanceaddstarArgs,  PS_LIST_TAIL, "-label",  PS_META_DUPLICATE_OK, "search by label", NULL);
    98114
    99115    // -pendingprocess
     
    142158    psMetadata *modes = psMetadataAlloc();
    143159
    144     PXOPT_ADD_MODE("-definebyquery",  "create a new, populated flat correction run",       FLATCORR_MODE_DEFINEBYQUERY,  definebyqueryArgs);
    145     PXOPT_ADD_MODE("-definerun",      "create a new, empty flat correction run",           FLATCORR_MODE_DEFINERUN,      definerunArgs);
    146     PXOPT_ADD_MODE("-addchip",        "add a chip to a flat correction run",               FLATCORR_MODE_ADDCHIP,        addchipArgs);
    147     PXOPT_ADD_MODE("-addcamera",      "migrate completed chips to camera stage analysis", FLATCORR_MODE_ADDCAMERA,      addcameraArgs);
    148     PXOPT_ADD_MODE("-dropchip",       "drop a chip from a flat correction run",            FLATCORR_MODE_DROPCHIP,       dropchipArgs);
    149     PXOPT_ADD_MODE("-dropcamera",     "drop an exposure (camera stage analysis)",          FLATCORR_MODE_DROPCAMERA,     dropcameraArgs);
    150     PXOPT_ADD_MODE("-pendingprocess", "show flat correction runs needing to be processed", FLATCORR_MODE_PENDINGPROCESS, pendingprocessArgs);
    151     PXOPT_ADD_MODE("-addprocess",     "report completed flat correction analysis",         FLATCORR_MODE_ADDPROCESS,     addprocessArgs);
    152     PXOPT_ADD_MODE("-updaterun",      "change a flat calibration run's state",             FLATCORR_MODE_UPDATERUN,      updaterunArgs);
    153     PXOPT_ADD_MODE("-inputexp",       "list exposures for a correction run",               FLATCORR_MODE_INPUTEXP,       inputexpArgs);
    154     PXOPT_ADD_MODE("-inputimfile",    "list imfiles for a chip run",                       FLATCORR_MODE_INPUTIMFILE,    inputimfileArgs);
    155     PXOPT_ADD_MODE("-exportrun",            "export run for import on other database", FLATCORR_MODE_EXPORTRUN, exportrunArgs);
    156     PXOPT_ADD_MODE("-importrun",            "import run from metadata file",           FLATCORR_MODE_IMPORTRUN, importrunArgs);
     160    PXOPT_ADD_MODE("-definebyquery",  "create a new, populated flat correction run",         FLATCORR_MODE_DEFINEBYQUERY,  definebyqueryArgs);
     161    PXOPT_ADD_MODE("-definerun",      "create a new, empty flat correction run",             FLATCORR_MODE_DEFINERUN,      definerunArgs);
     162    PXOPT_ADD_MODE("-addchip",        "add an existing chip run to a flat correction run",   FLATCORR_MODE_ADDCHIP,        addchipArgs);
     163    PXOPT_ADD_MODE("-addcamera",      "add an existing camera run to a flat correction run", FLATCORR_MODE_ADDCAMERA,      addcameraArgs);
     164    PXOPT_ADD_MODE("-advancecamera",  "migrate completed chips to camera stage analysis",    FLATCORR_MODE_ADVANCECAMERA,  advancecameraArgs);
     165    PXOPT_ADD_MODE("-advanceaddstar", "migrate completed exposures to addstar processing",   FLATCORR_MODE_ADVANCEADDSTAR,  advanceaddstarArgs);
     166    PXOPT_ADD_MODE("-dropchip",       "drop a chip from a flat correction run",              FLATCORR_MODE_DROPCHIP,       dropchipArgs);
     167    PXOPT_ADD_MODE("-dropcamera",     "drop an exposure (camera stage analysis)",            FLATCORR_MODE_DROPCAMERA,     dropcameraArgs);
     168    PXOPT_ADD_MODE("-pendingprocess", "show flat correction runs needing to be processed",   FLATCORR_MODE_PENDINGPROCESS, pendingprocessArgs);
     169    PXOPT_ADD_MODE("-addprocess",     "report completed flat correction analysis",           FLATCORR_MODE_ADDPROCESS,     addprocessArgs);
     170    PXOPT_ADD_MODE("-updaterun",      "change a flat calibration run's state",               FLATCORR_MODE_UPDATERUN,      updaterunArgs);
     171    PXOPT_ADD_MODE("-inputexp",       "list exposures for a correction run",                 FLATCORR_MODE_INPUTEXP,       inputexpArgs);
     172    PXOPT_ADD_MODE("-inputimfile",    "list imfiles for a chip run",                         FLATCORR_MODE_INPUTIMFILE,    inputimfileArgs);
    157173
    158174    if (!pxGetOptions(stderr, argc, argv, config, modes, argSets)) {
  • branches/eam_branches/20090820/ippTools/src/magicdstool.c

    r25766 r25870  
    3333
    3434static bool definebyqueryMode(pxConfig *config);
    35 static psS64 definerunMode(pxConfig *config);
    3635static bool updaterunMode(pxConfig *config);
    3736static bool todestreakMode(pxConfig *config);
     
    4342static bool torevertMode(pxConfig *config);
    4443static bool completedrevertMode(pxConfig *config);
    45 
    46 static bool setmagicDSRunState(pxConfig *config, psS64 magic_id, const char *state);
    47 static bool magicDSGetIDs(pxConfig *config, psString stage, psS64 magic_id, psS64 *stage_id, psS64 *cam_id);
     44static bool tocleanupMode(pxConfig *config);
     45
     46static bool setmagicDSRunState(pxConfig *config, psS64 magic_id, psMetadata *where, const char *state);
    4847
    4948# define MODECASE(caseName, func) \
     
    6665    switch (config->mode) {
    6766        MODECASE(MAGICDSTOOL_MODE_DEFINEBYQUERY,       definebyqueryMode);
    68         MODECASE(MAGICDSTOOL_MODE_DEFINERUN,           definerunMode);
    6967        MODECASE(MAGICDSTOOL_MODE_UPDATERUN,           updaterunMode);
    7068        MODECASE(MAGICDSTOOL_MODE_TODESTREAK,          todestreakMode);
     
    7674        MODECASE(MAGICDSTOOL_MODE_TOREVERT,            torevertMode);
    7775        MODECASE(MAGICDSTOOL_MODE_COMPLETEDREVERT,     completedrevertMode);
     76        MODECASE(MAGICDSTOOL_MODE_TOCLEANUP,           tocleanupMode);
    7877        default:
    7978            psAbort("invalid option (this should not happen)");
     
    108107    PXOPT_LOOKUP_BOOL(noreplace, config->args, "-noreplace", false);
    109108    PXOPT_LOOKUP_STR(set_label, config->args, "-set_label", false, false);
     109    PXOPT_LOOKUP_STR(set_data_group, config->args, "-set_data_group", false, false);
     110    PXOPT_LOOKUP_STR(note, config->args, "-set_note", false, false);
    110111    PXOPT_LOOKUP_BOOL(rerun, config->args, "-rerun", false);
    111112    PXOPT_LOOKUP_BOOL(dry_run, config->args, "-dry_run", false);
     
    246247        psS64 cam_id = psMetadataLookupS64(NULL, row, "cam_id");
    247248        psString magicRunLabel = psMetadataLookupStr(NULL, row, "label");
     249        psString magicRunDataGroup = psMetadataLookupStr(NULL, row, "data_group");
    248250        psString magicRunWorkdir = psMetadataLookupStr(NULL, row, "workdir");
    249251       
     
    267269                cam_id,
    268270                set_label ? set_label : magicRunLabel,
     271                set_data_group ? set_data_group : magicRunDataGroup,
    269272                outroot,
    270273                recoveryroot,
    271274                noreplace ? 0 :1,   // re_place
    272                 0); // remove
     275                0,      // remove
     276                0,      // fault
     277                note);  // remove
    273278
    274279        psFree(outroot);
     
    313318}
    314319
    315 static psS64 definerunMode(pxConfig *config)
     320
     321static bool updaterunMode(pxConfig *config)
    316322{
    317323    PS_ASSERT_PTR_NON_NULL(config, false);
    318324
    319325    // required
    320     PXOPT_LOOKUP_S64(magic_id, config->args, "-magic_id", true, false);
    321     PXOPT_LOOKUP_STR(stage, config->args, "-stage", true, false);
    322     PXOPT_LOOKUP_STR(outroot, config->args, "-outroot", true, false);
    323 
    324     // optional
    325     PXOPT_LOOKUP_STR(recoveryroot, config->args, "-recoveryroot", false, false);
    326     PXOPT_LOOKUP_BOOL(re_place, config->args, "-replace", false);
    327     PXOPT_LOOKUP_BOOL(remove, config->args, "-remove", false);
    328     PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
    329     PXOPT_LOOKUP_STR(label, config->args, "-label", false, false);
    330 
    331     psS64 stage_id = 0, cam_id = 0;
    332 
    333     if (!magicDSGetIDs(config, stage, magic_id, &stage_id, &cam_id)) {
    334         psError(PS_ERR_UNKNOWN, false, "failed to get ids");
    335         return false;
    336     }
    337 
    338     magicDSRunRow *run = magicDSRunRowAlloc(
    339             0,          // ID
    340             magic_id,
    341             0,          // inv_magic_id
    342             "new",      // state
    343             stage,
    344             stage_id,
    345             cam_id,
    346             label,
    347             outroot,
    348             recoveryroot,
    349             re_place,
    350             remove
    351     );
    352 
    353     if (!run) {
    354         psError(PS_ERR_UNKNOWN, false, "failed to alloc magicRun object");
    355         return false;
    356     }
    357     if (!magicDSRunInsertObject(config->dbh, run)) {
    358         psError(PS_ERR_UNKNOWN, false, "database error");
    359         psFree(run);
    360         return false;
    361     }
    362 
    363     psS64 magic_ds_id = psDBLastInsertID(config->dbh);
    364     run->magic_ds_id = magic_ds_id;
    365 
    366     if (!magicDSRunPrintObject(stdout, run, !simple)) {
    367             psError(PS_ERR_UNKNOWN, false, "failed to print object");
    368             psFree(run);
    369             return false;
    370     }
    371 
    372     psFree(run);
    373 
    374     return magic_id;
    375 }
    376 
    377 
    378 static bool updaterunMode(pxConfig *config)
    379 {
    380     PS_ASSERT_PTR_NON_NULL(config, false);
    381 
    382     // required
    383     PXOPT_LOOKUP_S64(magic_ds_id, config->args, "-magic_ds_id", true, false);
    384     PXOPT_LOOKUP_STR(state, config->args, "-state", true, false);
    385 
    386     if (state) {
    387         // set detRun.state to state
    388         return setmagicDSRunState(config, magic_ds_id, state);
    389     }
    390 
    391     return true;
     326    PXOPT_LOOKUP_STR(state, config->args, "-set_state", true, false);
     327
     328    PXOPT_LOOKUP_S64(magic_ds_id, config->args, "-magic_ds_id", false, false);
     329    if (magic_ds_id) {
     330
     331        return setmagicDSRunState(config, magic_ds_id, NULL, state);
     332
     333    } else if (!strcmp(state, "full")) {
     334        psError(PS_ERR_UNKNOWN, true, "magic_ds_id is required to update run state to full");
     335        return false;
     336    }
     337    // we can transition by query as well
     338
     339    psMetadata *where = psMetadataAlloc();
     340    PXOPT_COPY_STR(config->args, where, "-label", "label", "==");
     341    PXOPT_COPY_S64(config->args, where, "-stage_id", "stage_id", "==");
     342    PXOPT_COPY_STR(config->args, where, "-stage", "stage", "==");
     343
     344
     345    if (psListLength(where->list) < 2) {
     346        psError(PS_ERR_UNKNOWN, true, "at least 2 search arguments are required");
     347        return false;
     348    }
     349
     350
     351    PXOPT_LOOKUP_BOOL(noreplace, config->args, "-noreplace", false);
     352    if (!noreplace) {
     353        psMetadataAddS32(where, PS_LIST_TAIL, "re_place", 0, ">", 0);
     354    }
     355    bool result = setmagicDSRunState(config, magic_ds_id, where, state);
     356    psFree(where);
     357
     358    return result;
    392359}
    393360
     
    670637}
    671638
    672 static bool magicDSGetIDs(pxConfig *config, psString stage, psS64 magic_id, psS64 *stage_id, psS64 *cam_id)
    673 {
    674     PS_ASSERT_PTR_NON_NULL(config, false);
    675     PS_ASSERT_PTR_NON_NULL(stage, false);
    676     PS_ASSERT_PTR_NON_NULL(stage_id, false);
    677     PS_ASSERT_PTR_NON_NULL(cam_id, false);
    678 
    679     int stageNum = ippStringToStage(stage);;
    680     if (stageNum == IPP_STAGE_NONE) {
    681         psError(PXTOOLS_ERR_DATA, false, "%s is not a valid value for stage", stage);
    682         return false;
    683     }
    684 
    685     psString query = pxDataGet("magicdstool_getrunids.sql");
    686     if (!query) {
    687         psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
    688         return false;
    689     }
    690 
    691     if (!p_psDBRunQueryF(config->dbh, query, magic_id)) {
    692         psError(PS_ERR_UNKNOWN, false, "database error");
    693         psFree(query);
    694         return false;
    695     }
    696     psFree(query);
    697 
    698     psArray *output = p_psDBFetchResult(config->dbh);
    699     if (!output) {
    700         psError(PS_ERR_UNKNOWN, false, "database error");
    701         return false;
    702     }
    703     if (!psArrayLength(output)) {
    704         psTrace("magicdstool", PS_LOG_INFO, "no rows found");
    705         psFree(output);
    706         return true;
    707     }
    708     if (psArrayLength(output) > 1) {
    709         psError(PS_ERR_UNKNOWN, true, "unexpected number of rows found %ld for magic_id %" PRId64,
    710             psArrayLength(output), magic_id);
    711         return false;
    712     }
    713     psMetadata *row = output->data[0];
    714 
    715     *cam_id = psMetadataLookupS64(NULL, row, "cam_id");
    716     switch (stageNum) {
    717     case IPP_STAGE_RAW:
    718         *stage_id = psMetadataLookupS64(NULL, row, "exp_id");
    719         break;
    720     case IPP_STAGE_CHIP:
    721         *stage_id = psMetadataLookupS64(NULL, row, "chip_id");
    722         break;
    723     case IPP_STAGE_CAMERA:
    724         *stage_id = *cam_id;
    725         return true;
    726     case IPP_STAGE_WARP:
    727         *stage_id = psMetadataLookupS64(NULL, row, "warp_id");
    728         break;
    729     case IPP_STAGE_DIFF:
    730         *stage_id = psMetadataLookupS64(NULL, row, "diff_id");
    731         break;
    732     }
    733 
    734     return true;
    735 }
    736639
    737640static bool advancerunMode(pxConfig *config)
     
    796699
    797700        // set magicDSRun.state to 'full'
    798         if (!setmagicDSRunState(config, magic_ds_id, "full")) {
     701        if (!setmagicDSRunState(config, magic_ds_id, NULL, "full")) {
    799702            psError(PS_ERR_UNKNOWN, false, "failed to change magicDSRun.state for magic_ds_id: %" PRId64,
    800703                magic_ds_id);
     
    994897}
    995898
    996 static bool setmagicDSRunState(pxConfig *config, psS64 magic_ds_id, const char *state)
    997 {
    998     PS_ASSERT_PTR_NON_NULL(state, false);
    999 
    1000     // check that state is a valid string value
     899static bool validDSRunState(const char *state)
     900{
    1001901    if (!((strcmp(state, "new") == 0) ||
    1002902          (strcmp(state, "full") == 0) ||
    1003903          (strcmp(state, "restored") == 0) ||
    1004904          (strcmp(state, "censored") == 0) ||
    1005           (strcmp(state, "purged") == 0) ||
     905          (strcmp(state, "cleaned") == 0) ||
    1006906          (strcmp(state, "goto_restored") == 0) ||
    1007907          (strcmp(state, "goto_censored") == 0) ||
    1008           (strcmp(state, "goto_purged") == 0))
     908          (strcmp(state, "goto_cleaned") == 0))
    1009909        ) {
     910        return false;
     911    } else {
     912        return true;
     913    }
     914}
     915
     916static bool setmagicDSRunState(pxConfig *config, psS64 magic_ds_id, psMetadata *where, const char *state)
     917{
     918    PS_ASSERT_PTR_NON_NULL(state, false);
     919
     920    if (!validDSRunState(state)) {
    1010921        psError(PS_ERR_UNKNOWN, false,
    1011922                "invalid magicDSRun state: %s", state);
     
    1013924    }
    1014925
    1015     char *query = "UPDATE magicDSRun SET state = '%s' WHERE magic_ds_id = %" PRId64;
    1016     if (!p_psDBRunQueryF(config->dbh, query, state, magic_ds_id)) {
     926    psString query = psStringCopy("UPDATE magicDSRun SET state = '%s'");
     927    if (magic_ds_id) {
     928        psStringAppend(&query, " WHERE magic_ds_id = %" PRId64, magic_ds_id);
     929    } else if (where && psListLength(where->list)) {
     930        psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
     931        psStringAppend(&query, " WHERE %s", whereClause);
     932        psFree(whereClause);
     933    } else {
     934        psError(PS_ERR_UNKNOWN, true, "search arugments are required");
     935        return false;
     936    }
     937
     938    if (!p_psDBRunQueryF(config->dbh, query, state)) {
    1017939        psError(PS_ERR_UNKNOWN, false,
    1018940                "failed to change state for magic_id %" PRId64, magic_ds_id);
     
    11781100
    11791101
     1102static bool tocleanupMode(pxConfig *config)
     1103{
     1104    PS_ASSERT_PTR_NON_NULL(config, false);
     1105
     1106    psMetadata *where = psMetadataAlloc();
     1107
     1108    PXOPT_COPY_S64(config->args, where, "-stage", "stage", "==");
     1109    PXOPT_COPY_S64(config->args, where, "-magic_ds_id", "magic_ds_id", "==");
     1110    PXOPT_COPY_S64(config->args, where, "-magic_id", "magic_id", "==");
     1111    pxAddLabelSearchArgs (config, where, "-label", "magicDSRun.label", "==");
     1112
     1113    PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
     1114    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
     1115
     1116    psString query = pxDataGet("magicdstool_tocleanup.sql");
     1117    if (!query) {
     1118        psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
     1119        return false;
     1120    }
     1121
     1122    if (psListLength(where->list)) {
     1123        psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
     1124        psStringAppend(&query, " AND %s", whereClause);
     1125        psFree(whereClause);
     1126    }
     1127    psFree(where);
     1128
     1129    // treat limit == 0 as "no limit"
     1130    if (limit) {
     1131        psString limitString = psDBGenerateLimitSQL(limit);
     1132        psStringAppend(&query, " %s", limitString);
     1133        psFree(limitString);
     1134    }
     1135
     1136    if (!p_psDBRunQuery(config->dbh, query)) {
     1137        psError(PS_ERR_UNKNOWN, false, "database error");
     1138        psFree(query);
     1139        return false;
     1140    }
     1141    psFree(query);
     1142
     1143    psArray *output = p_psDBFetchResult(config->dbh);
     1144    if (!output) {
     1145        psErrorCode err = psErrorCodeLast();
     1146        switch (err) {
     1147            case PS_ERR_DB_CLIENT:
     1148                psError(PXTOOLS_ERR_SYS, false, "database error");
     1149            case PS_ERR_DB_SERVER:
     1150                psError(PXTOOLS_ERR_PROG, false, "database error");
     1151            default:
     1152                psError(PXTOOLS_ERR_PROG, false, "unknown error");
     1153        }
     1154
     1155        return false;
     1156    }
     1157    if (!psArrayLength(output)) {
     1158        psTrace("magicdstool", PS_LOG_INFO, "no rows found");
     1159        psFree(output);
     1160        return true;
     1161    }
     1162
     1163    if (psArrayLength(output)) {
     1164        // negative simple so the default is true
     1165        if (!ippdbPrintMetadatas(stdout, output, "tocleanup", !simple)) {
     1166            psError(PS_ERR_UNKNOWN, false, "failed to print array");
     1167            psFree(output);
     1168            return false;
     1169        }
     1170    }
     1171
     1172    psFree(output);
     1173
     1174    return true;
     1175}
  • branches/eam_branches/20090820/ippTools/src/magicdstool.h

    r25766 r25870  
    2626    MAGICDSTOOL_MODE_NONE           = 0x0,
    2727    MAGICDSTOOL_MODE_DEFINEBYQUERY,
    28     MAGICDSTOOL_MODE_DEFINERUN,
    2928    MAGICDSTOOL_MODE_UPDATERUN,
    3029    MAGICDSTOOL_MODE_TODESTREAK,
     
    3635    MAGICDSTOOL_MODE_TOREVERT,
    3736    MAGICDSTOOL_MODE_COMPLETEDREVERT,
     37    MAGICDSTOOL_MODE_TOCLEANUP,
    3838} MAGICDStoolMode;
    3939
  • branches/eam_branches/20090820/ippTools/src/magicdstoolConfig.c

    r25766 r25870  
    5454    psMetadataAddBool(definebyqueryArgs, PS_LIST_TAIL, "-noreplace", 0, "do not replace input files with the destreaked versions", false);
    5555    psMetadataAddStr(definebyqueryArgs, PS_LIST_TAIL, "-set_label",    0, "define label", NULL);
     56    psMetadataAddStr(definebyqueryArgs, PS_LIST_TAIL, "-set_data_group", 0, "define data_group", NULL);
     57    psMetadataAddStr(definebyqueryArgs, PS_LIST_TAIL, "-set_note", 0, "define note", NULL);
    5658
    5759    psMetadataAddStr(definebyqueryArgs, PS_LIST_TAIL, "-label", PS_META_DUPLICATE_OK, "search by magicRun.label", NULL);
     
    6971    psMetadataAddU64(definebyqueryArgs, PS_LIST_TAIL, "-limit", 0, "limit result set to N items", 0);
    7072
    71     // -definerun
    72     psMetadata *definerunArgs = psMetadataAlloc();
    73     psMetadataAddS64(definerunArgs, PS_LIST_TAIL, "-magic_id", 0, "define magic_id (required)", 0);
    74     psMetadataAddStr(definerunArgs, PS_LIST_TAIL, "-stage", 0, "define stage for run (required)", NULL);
    75     psMetadataAddStr(definerunArgs, PS_LIST_TAIL, "-outroot", 0, "define output directory (required)", NULL);
    76     psMetadataAddStr(definerunArgs, PS_LIST_TAIL, "-recoveryroot", 0, "define recovery directory", NULL);
    77     psMetadataAddBool(definerunArgs, PS_LIST_TAIL, "-noreplace", 0, "do not replace the input wit with the destreaked versions", false);
    78 //    psMetadataAddBool(definerunArgs, PS_LIST_TAIL, "-remove", 0, "use the simple output format", false);
    79     psMetadataAddStr(definerunArgs, PS_LIST_TAIL, "-label", 0, "define label", NULL);
    80     psMetadataAddBool(definerunArgs, PS_LIST_TAIL, "-simple", 0, "use the simple output format", false);
    81 
    8273    // -updaterun
    8374    psMetadata *updaterunArgs = psMetadataAlloc();
    84     psMetadataAddS64(updaterunArgs, PS_LIST_TAIL, "-magic_ds_id", 0, "define magictool ID (required)", 0);
    85     psMetadataAddStr(updaterunArgs, PS_LIST_TAIL, "-state", 0, "set state (required)", NULL);
     75    psMetadataAddStr(updaterunArgs, PS_LIST_TAIL, "-set_state", 0, "set state (required)", NULL);
     76    psMetadataAddS64(updaterunArgs, PS_LIST_TAIL, "-magic_ds_id", 0, "define magictool ID", 0);
     77    psMetadataAddStr(updaterunArgs, PS_LIST_TAIL, "-stage",     0, "define stage", NULL);
     78    psMetadataAddS64(updaterunArgs, PS_LIST_TAIL, "-stage_id", 0, "define stage_id", 0);
     79    psMetadataAddStr(updaterunArgs, PS_LIST_TAIL, "-label",     0, "define label", NULL);
     80    psMetadataAddBool(updaterunArgs, PS_LIST_TAIL, "-noreplace", 0, "only update runs with replace not set", false);
    8681
    8782    // -addinputskyfile
     
    153148    psMetadataAddU64(advancerunArgs, PS_LIST_TAIL, "-limit", 0, "limit result set to N items", 0);
    154149
     150    // -tocleanup
     151    psMetadata *tocleanupArgs = psMetadataAlloc();
     152    psMetadataAddS64(tocleanupArgs, PS_LIST_TAIL, "-magic_ds_id", 0, "search by magic Destreak ID", 0);
     153    psMetadataAddS64(tocleanupArgs, PS_LIST_TAIL, "-magic_id", 0, "search by magic ID", 0);
     154    psMetadataAddStr(tocleanupArgs, PS_LIST_TAIL, "-stage", 0, "define output directory", NULL);
     155    psMetadataAddStr(tocleanupArgs, PS_LIST_TAIL, "-label", PS_META_DUPLICATE_OK, "define label", NULL);
     156    psMetadataAddU64(tocleanupArgs, PS_LIST_TAIL, "-limit", 0, "limit result set to N items", 0);
     157    psMetadataAddBool(tocleanupArgs, PS_LIST_TAIL, "-simple", 0, "use the simple output format", false);
    155158    psFree(now);
    156159
     
    160163    PXOPT_ADD_MODE("-definebyquery",       "create magic de-streak runs from magic runs",
    161164                    MAGICDSTOOL_MODE_DEFINEBYQUERY,     definebyqueryArgs);
    162     PXOPT_ADD_MODE("-definerun",           "create one magic de-streak run for one magic run",
    163                     MAGICDSTOOL_MODE_DEFINERUN,         definerunArgs);
    164165    PXOPT_ADD_MODE("-updaterun",           "update state of magic de-streak run",
    165166                    MAGICDSTOOL_MODE_UPDATERUN,         updaterunArgs);
     
    181182    PXOPT_ADD_MODE("-completedrevert", "change state for runs that have finished reverting",
    182183                    MAGICDSTOOL_MODE_COMPLETEDREVERT, completedrevertArgs);
     184    PXOPT_ADD_MODE("-tocleanup", "destreak runs to clean up",
     185                    MAGICDSTOOL_MODE_TOCLEANUP, tocleanupArgs);
    183186
    184187
  • branches/eam_branches/20090820/ippTools/src/magictool.c

    r25766 r25870  
    117117    // Optional
    118118    PXOPT_LOOKUP_STR(label, config->args, "-label", false, false);
     119    PXOPT_LOOKUP_STR(data_group, config->args, "-data_group", false, false);
     120    PXOPT_LOOKUP_STR(note, config->args, "-note", false, false);
    119121    PXOPT_LOOKUP_STR(dvodb, config->args, "-dvodb", false, false);
    120122    PXOPT_LOOKUP_TIME(registered, config->args, "-registered", false, false);
     
    236238
    237239        // create a new magicRun for this group
    238         magicRunRow *run = magicRunRowAlloc(0, exp_id, diff_id, inverse, "new", workdir, "dirty", label,
    239                                             dvodb, registered, 0);
     240        magicRunRow *run = magicRunRowAlloc(0,
     241                                            exp_id,
     242                                            diff_id,
     243                                            inverse,
     244                                            "new",      // state
     245                                            workdir,
     246                                            "dirty",    // workdir_state
     247                                            label,
     248                                            data_group ? data_group : label,
     249                                            dvodb,
     250                                            registered,
     251                                            0,          // fault
     252                                            note);
    240253        if (!run) {
    241254            psAbort("failed to alloc magicRun object");
     
    331344            "dirty",    // workdir_state
    332345            label,
     346            NULL,       // data_group
    333347            dvodb,
    334348            registered,
    335             0
     349            0,          // fault
     350            NULL
    336351    );
    337352
     
    14491464    // Now queue any destreaked files to be re-verted
    14501465
    1451     // note: on failure magicRestoreStage issues the rollback
    1452     if (!magicRestoreStage(config, "raw", whereClause, "goto_censored")) {
     1466    // note: on failure pxmagicRestoreStage issues the rollback
     1467    if (!pxmagicRestoreStage(config, "raw", whereClause, "goto_censored")) {
    14531468        psFree(whereClause);
    14541469        return false;
    14551470    }
    1456     if (!magicRestoreStage(config, "chip", whereClause, "goto_censored")) {
     1471    if (!pxmagicRestoreStage(config, "chip", whereClause, "goto_censored")) {
    14571472        psFree(whereClause);
    14581473        return false;
    14591474    }
    1460     if (!magicRestoreStage(config, "camera", whereClause, "goto_censored")) {
     1475    if (!pxmagicRestoreStage(config, "camera", whereClause, "goto_censored")) {
    14611476        psFree(whereClause);
    14621477        return false;
    14631478    }
    1464     if (!magicRestoreStage(config, "warp", whereClause, "goto_censored")) {
     1479    if (!pxmagicRestoreStage(config, "warp", whereClause, "goto_censored")) {
    14651480        psFree(whereClause);
    14661481        return false;
    14671482    }
    1468     if (!magicRestoreStage(config, "diff", whereClause, "goto_censored")) {
     1483    if (!pxmagicRestoreStage(config, "diff", whereClause, "goto_censored")) {
    14691484        psFree(whereClause);
    14701485        return false;
  • branches/eam_branches/20090820/ippTools/src/pstamptool.c

    r25766 r25870  
    4848static bool projectMode(pxConfig *config);
    4949static bool modprojectMode(pxConfig *config);
     50static bool getdependentMode(pxConfig *config);
     51static bool pendingdependentMode(pxConfig *config);
     52static bool updatedependentMode(pxConfig *config);
    5053
    5154# define MODECASE(caseName, func) \
     
    8588        MODECASE(PSTAMPTOOL_MODE_MODPROJECT, modprojectMode);
    8689        MODECASE(PSTAMPTOOL_MODE_PROJECT, projectMode);
     90        MODECASE(PSTAMPTOOL_MODE_GETDEPENDENT, getdependentMode);
     91        MODECASE(PSTAMPTOOL_MODE_PENDINGDEPENDENT, pendingdependentMode);
     92        MODECASE(PSTAMPTOOL_MODE_UPDATEDEPENDENT, updatedependentMode);
    8793        default:
    8894            psAbort("invalid option (this should not happen)");
     
    545551    PXOPT_LOOKUP_S64(exp_id,      config->args, "-exp_id",     false, false);
    546552    PXOPT_LOOKUP_S64(options,     config->args, "-options",     false, false);
     553    PXOPT_LOOKUP_S64(dep_id,      config->args, "-dep_id",     false, false);
    547554
    548555    // unless the job is being inserted with stop state require outputBase
     
    570577            exp_id,
    571578            outputBase,
    572             options
     579            options,
     580            dep_id
    573581            )) {
    574582        psError(PS_ERR_UNKNOWN, false, "database error");
     
    896904}
    897905
     906static bool getdependentMode(pxConfig *config)
     907{
     908    PS_ASSERT_PTR_NON_NULL(config, false);
     909
     910    PXOPT_LOOKUP_STR(stage,       config->args, "-stage",   true, false);
     911    PXOPT_LOOKUP_S64(stage_id,    config->args, "-stage_id", true, false);
     912    PXOPT_LOOKUP_STR(imagedb,     config->args, "-imagedb",  true, false);
     913    PXOPT_LOOKUP_STR(rlabel,      config->args, "-rlabel",  false, false);
     914    PXOPT_LOOKUP_BOOL(no_magic,   config->args, "-no_magic", false);
     915    PXOPT_LOOKUP_BOOL(no_create,  config->args, "-no_create", false);
     916
     917    psString query = pxDataGet("pstamptool_pendingdependent.sql");
     918    if (!query) {
     919        psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
     920        return false;
     921    }
     922    if (!p_psDBRunQuery(config->dbh, query)) {
     923        psError(PS_ERR_UNKNOWN, false, "database error");
     924        psFree(query);
     925        return false;
     926    }
     927    psFree(query);
     928
     929    psArray *output = p_psDBFetchResult(config->dbh);
     930    if (!output) {
     931        psError(PS_ERR_UNKNOWN, false, "database error");
     932        return false;
     933    }
     934    if (psArrayLength(output)) {
     935        psMetadata *dep = output->data[0];
     936        psS64 dep_id = psMetadataLookupS64(NULL, dep, "dep_id");
     937        if (!dep_id) {
     938            psError(PS_ERR_UNKNOWN, false, "database error");
     939            return false;
     940        }
     941        printf("%" PRId64 "\n", dep_id);
     942        return true;
     943    }
     944    if (no_create) {
     945        return true;
     946    }
     947    // no existing dependent that matches, insert one
     948
     949    if (!pstampDependentInsert(
     950        config->dbh,
     951        0,              // dep_id
     952        "new",          // state
     953        stage,
     954        stage_id,
     955        imagedb,
     956        rlabel,
     957        no_magic
     958        )) {
     959        psError(PS_ERR_UNKNOWN, false, "failed to insert pstampDependent");
     960        return false;
     961    }
     962
     963    psS64 dep_id = psDBLastInsertID(config->dbh);
     964
     965    printf("%" PRId64 "\n", dep_id);
     966
     967    return true;
     968}
     969
     970static bool pendingdependentMode(pxConfig *config)
     971{
     972    PS_ASSERT_PTR_NON_NULL(config, false);
     973
     974    psMetadata *where = psMetadataAlloc();
     975
     976    PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
     977    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
     978
     979    psString query = pxDataGet("pstamptool_pendingdependent.sql");
     980    if (!query) {
     981        psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
     982        return false;
     983    }
     984
     985    if (psListLength(where->list)) {
     986        psString whereClause = psDBGenerateWhereConditionSQL(where, "pstampDependent");
     987        psStringAppend(&query, " AND %s", whereClause);
     988        psFree(whereClause);
     989    }
     990    psFree(where);
     991
     992    // treat limit == 0 as "no limit"
     993    if (limit) {
     994        psString limitString = psDBGenerateLimitSQL(limit);
     995        psStringAppend(&query, " %s", limitString);
     996        psFree(limitString);
     997    }
     998
     999    if (!p_psDBRunQuery(config->dbh, query)) {
     1000        psError(PS_ERR_UNKNOWN, false, "database error");
     1001        psFree(query);
     1002        return false;
     1003    }
     1004    psFree(query);
     1005
     1006    psArray *output = p_psDBFetchResult(config->dbh);
     1007    if (!output) {
     1008        psError(PS_ERR_UNKNOWN, false, "database error");
     1009        return false;
     1010    }
     1011    if (!psArrayLength(output)) {
     1012        psTrace("pstamptool", PS_LOG_INFO, "no rows found");
     1013        psFree(output);
     1014        return true;
     1015    }
     1016
     1017    // negative simple so the default is true
     1018    if (!ippdbPrintMetadatas(stdout, output, "pstampDependent", !simple)) {
     1019        psError(PS_ERR_UNKNOWN, false, "failed to print array");
     1020        psFree(output);
     1021        return false;
     1022    }
     1023
     1024    psFree(output);
     1025
     1026    return true;
     1027}
     1028static bool updatedependentMode(pxConfig *config)
     1029{
     1030    PS_ASSERT_PTR_NON_NULL(config, false);
     1031
     1032    PXOPT_LOOKUP_S64(dep_id,    config->args, "-dep_id", true, false);
     1033    PXOPT_LOOKUP_STR(state,     config->args, "-set_state",  true, false);
     1034
     1035    char *query ="UPDATE pstampDependent"
     1036        " SET state = '%s'"
     1037        " WHERE dep_id = %" PRId64;
     1038   
     1039    if (!p_psDBRunQueryF(config->dbh, query, state, dep_id)) {
     1040        psError(PS_ERR_UNKNOWN, false, "database error");
     1041        psFree(query);
     1042        return false;
     1043    }
     1044
     1045    psU64 affected = psDBAffectedRows(config->dbh);
     1046    if (affected != 1) {
     1047        psError(PS_ERR_UNKNOWN, false, "should have affected one row but %"
     1048                                        PRIu64 " rows were modified", affected);
     1049        return false;
     1050    }
     1051
     1052    return true;
     1053}
  • branches/eam_branches/20090820/ippTools/src/pstamptool.h

    r25766 r25870  
    4343    PSTAMPTOOL_MODE_MODPROJECT,
    4444    PSTAMPTOOL_MODE_PROJECT,
     45    PSTAMPTOOL_MODE_GETDEPENDENT,
     46    PSTAMPTOOL_MODE_PENDINGDEPENDENT,
     47    PSTAMPTOOL_MODE_UPDATEDEPENDENT,
    4548} pstamptoolMode;
    4649
  • branches/eam_branches/20090820/ippTools/src/pstamptoolConfig.c

    r25766 r25870  
    112112    psMetadataAddS64(addjobArgs, PS_LIST_TAIL, "-exp_id", 0,           "define exposure id", 0);
    113113    psMetadataAddS64(addjobArgs, PS_LIST_TAIL, "-options", 0,          "define options", 0);
     114    psMetadataAddS64(addjobArgs, PS_LIST_TAIL, "-dep_id", 0,           "define job dep_id", 0);
    114115    psMetadataAddS16(addjobArgs, PS_LIST_TAIL, "-fault", 0,            "define job result", 0);
    115116
     
    143144    psMetadataAddBool(revertjobArgs, PS_LIST_TAIL, "-all", 0,       "revert all faulted jobs", false);
    144145    psMetadataAddU64(revertjobArgs, PS_LIST_TAIL, "-limit", 0,      "limit result set to N items", 0);
     146
     147    // -getdependent
     148    psMetadata *getdependentArgs = psMetadataAlloc();
     149    psMetadataAddS64(getdependentArgs, PS_LIST_TAIL, "-stage_id", 0, "define id for dependent run (required)", 0);
     150    psMetadataAddStr(getdependentArgs, PS_LIST_TAIL, "-stage", 0,    "define stage for dependent run (required)", NULL);
     151    psMetadataAddStr(getdependentArgs, PS_LIST_TAIL, "-imagedb", 0,  "define imagedb for depenent run (required)", NULL);
     152    psMetadataAddStr(getdependentArgs, PS_LIST_TAIL, "-rlabel", 0,   "define label for dependent run", NULL);
     153    psMetadataAddBool(getdependentArgs,PS_LIST_TAIL, "-no_magic", 0, "define no_magic", false);
     154    psMetadataAddBool(getdependentArgs,PS_LIST_TAIL, "-no_create", 0, "if no run exists do not create one", false);
     155
     156    // -updatedependent
     157    psMetadata *updatedependentArgs = psMetadataAlloc();
     158    psMetadataAddS64(updatedependentArgs, PS_LIST_TAIL, "-dep_id", 0, "define id for dependent run (required)", 0);
     159    psMetadataAddStr(updatedependentArgs, PS_LIST_TAIL, "-set_state", 0, "new value for state (required)", NULL);
     160
     161    // -pendingdependent
     162    psMetadata *pendingdependentArgs = psMetadataAlloc();
     163    psMetadataAddS64(pendingdependentArgs, PS_LIST_TAIL, "-stage_id", 0, "define id for dependent run", 0);
     164    psMetadataAddStr(pendingdependentArgs, PS_LIST_TAIL, "-stage", 0,    "define stage for dependent run", NULL);
     165    psMetadataAddStr(pendingdependentArgs, PS_LIST_TAIL, "-imagedb", 0,  "define imagedb for depenent run", NULL);
     166    psMetadataAddStr(pendingdependentArgs, PS_LIST_TAIL, "-rlabel", 0,   "define label for dependent run", NULL);
     167    psMetadataAddBool(pendingdependentArgs,PS_LIST_TAIL, "-no_magic", 0, "define no_magic", false);
     168    psMetadataAddBool(pendingdependentArgs,PS_LIST_TAIL, "-no_create", 0, "if no run exists do not create one", false);
     169    psMetadataAddU64(pendingdependentArgs, PS_LIST_TAIL, "-limit",  0,    "limit result set to N items", 0);
     170    psMetadataAddBool(pendingdependentArgs, PS_LIST_TAIL, "-simple", 0,   "use the simple output format", false);
    145171
    146172    // -addproject
     
    189215    PXOPT_ADD_MODE("-moddatastore",    "", PSTAMPTOOL_MODE_MODDATASTORE, moddatastoreArgs);
    190216
     217    PXOPT_ADD_MODE("-getdependent",    "", PSTAMPTOOL_MODE_GETDEPENDENT, getdependentArgs);
     218    PXOPT_ADD_MODE("-updatedependent", "", PSTAMPTOOL_MODE_UPDATEDEPENDENT, updatedependentArgs);
     219    PXOPT_ADD_MODE("-pendingdependent","", PSTAMPTOOL_MODE_PENDINGDEPENDENT, pendingdependentArgs);
     220
    191221    PXOPT_ADD_MODE("-addproject",      "", PSTAMPTOOL_MODE_ADDPROJECT, addprojectArgs);
    192222    PXOPT_ADD_MODE("-modproject",      "", PSTAMPTOOL_MODE_MODPROJECT, modprojectArgs);
  • branches/eam_branches/20090820/ippTools/src/pxadd.c

    r25766 r25870  
    2929#include "pxadd.h"
    3030
    31 bool pxaddSetSearchArgs (psMetadata *md) {
    32 
    33     psMetadataAddS64(md,  PS_LIST_TAIL, "-add_id",            0, "search by add_id", 0);
    34     psMetadataAddS64(md,  PS_LIST_TAIL, "-cam_id",             0, "search by cam_id", 0);
    35 
    36 /*     psMetadataAddStr(md,  PS_LIST_TAIL, "-exp_name",           0, "search by exp_name", NULL); */
    37 /*     psMetadataAddStr(md,  PS_LIST_TAIL, "-inst",               0, "search for camera", NULL); */
    38 /*     psMetadataAddStr(md,  PS_LIST_TAIL, "-telescope",          0, "search for telescope", NULL); */
    39 /*     psMetadataAddTime(md, PS_LIST_TAIL, "-dateobs_begin",      0, "search for exposures by time (>=)", NULL); */
    40 /*     psMetadataAddTime(md, PS_LIST_TAIL, "-dateobs_end",        0, "search for exposures by time (<)", NULL); */
    41 /*     psMetadataAddStr(md,  PS_LIST_TAIL, "-exp_tag",            0, "search by exp_tag", NULL); */
    42 /*     psMetadataAddStr(md,  PS_LIST_TAIL, "-exp_type",           0, "search by exp_type", NULL); */
    43 /*     psMetadataAddStr(md,  PS_LIST_TAIL, "-comment",            0, "search by comment", NULL); */
    44 /*     psMetadataAddStr(md,  PS_LIST_TAIL, "-filelevel",          0, "search by filelevel", NULL); */
    45 /*     psMetadataAddStr(md,  PS_LIST_TAIL, "-filter",             0, "search for filter", NULL); */
    46 /*     psMetadataAddF64(md,  PS_LIST_TAIL, "-airmass_min",        0, "define min airmass", NAN); */
    47 /*     psMetadataAddF64(md,  PS_LIST_TAIL, "-airmass_max",        0, "define max airmass", NAN); */
    48 /*     psMetadataAddF64(md,  PS_LIST_TAIL, "-ra_min",             0, "define min RA (degrees) ", NAN); */
    49 /*     psMetadataAddF64(md,  PS_LIST_TAIL, "-ra_max",             0, "define max RA (degrees) ", NAN); */
    50 /*     psMetadataAddF64(md,  PS_LIST_TAIL, "-decl_min",           0, "define min DEC (degrees)", NAN); */
    51 /*     psMetadataAddF64(md,  PS_LIST_TAIL, "-decl_max",           0, "define max DEC (degrees)", NAN); */
    52 /*     psMetadataAddF32(md,  PS_LIST_TAIL, "-exp_time_min",       0, "define min exposure time", NAN); */
    53 /*     psMetadataAddF32(md,  PS_LIST_TAIL, "-exp_time_max",       0, "define max exposure time", NAN); */
    54 /*     psMetadataAddF32(md,  PS_LIST_TAIL, "-sat_pixel_frac_min", 0, "define max fraction of saturated pixels", NAN); */
    55 /*     psMetadataAddF32(md,  PS_LIST_TAIL, "-sat_pixel_frac_max", 0, "define max fraction of saturated pixels", NAN); */
    56 /*     psMetadataAddF64(md,  PS_LIST_TAIL, "-bg_min",             0, "define min background", NAN); */
    57 /*     psMetadataAddF64(md,  PS_LIST_TAIL, "-bg_max",             0, "define max background", NAN); */
    58 /*     psMetadataAddF64(md,  PS_LIST_TAIL, "-bg_stdev_min",       0, "define min background standard deviation", NAN); */
    59 /*     psMetadataAddF64(md,  PS_LIST_TAIL, "-bg_stdev_max",       0, "define max background standard deviation", NAN); */
    60 /*     psMetadataAddF64(md,  PS_LIST_TAIL, "-bg_mean_stdev_min",  0, "define min background mean standard deviation (across imfiles)", NAN); */
    61 /*     psMetadataAddF64(md,  PS_LIST_TAIL, "-bg_mean_stdev_max",  0, "define max background mean standard deviation (across imfiles)", NAN); */
    62 /*     psMetadataAddF64(md,  PS_LIST_TAIL, "-alt_min",            0, "define min altitude", NAN); */
    63 /*     psMetadataAddF64(md,  PS_LIST_TAIL, "-alt_max",            0, "define max altitude", NAN); */
    64 /*     psMetadataAddF64(md,  PS_LIST_TAIL, "-az_min",             0, "define min azimuth ", NAN); */
    65 /*     psMetadataAddF64(md,  PS_LIST_TAIL, "-az_max",             0, "define max azimuth ", NAN); */
    66 /*     psMetadataAddF32(md,  PS_LIST_TAIL, "-ccd_temp_min",       0, "define min ccd tempature", NAN); */
    67 /*     psMetadataAddF32(md,  PS_LIST_TAIL, "-ccd_temp_max",       0, "define max ccd tempature", NAN); */
    68 /*     psMetadataAddF64(md,  PS_LIST_TAIL, "-posang_min",         0, "define min rotator position angle", NAN); */
    69 /*     psMetadataAddF64(md,  PS_LIST_TAIL, "-posang_max",         0, "define max rotator position angle", NAN); */
    70 /*     psMetadataAddStr(md,  PS_LIST_TAIL, "-object",             0, "search by exposure object", NULL); */
    71 /*     psMetadataAddF32(md,  PS_LIST_TAIL, "-sun_angle_min",      0, "define min solar angle", NAN); */
    72 /*     psMetadataAddF32(md,  PS_LIST_TAIL, "-sun_angle_max",      0, "define max solar angle", NAN); */
    73 
    74     return true;
    75 }
    76 
    77 bool pxaddGetSearchArgs (pxConfig *config, psMetadata *where) {
    78 
    79     PXOPT_COPY_S64(config->args,     where, "-add_id",             "addRun.add_id",        "==");
    80 /*     PXOPT_COPY_S64(config->args,     where, "-cam_id",             "camRun.cam_id",        "=="); */
    81 /*     PXOPT_COPY_S64(config->args,   where, "-chip_id",            "chipRun.chip_id",   "=="); */
    82 /*     PXOPT_COPY_S64(config->args,   where, "-exp_id",             "rawExp.exp_id",     "=="); */
    83 /*     PXOPT_COPY_STR(config->args,   where, "-exp_name",           "rawExp.exp_name",   "=="); */
    84 /*     PXOPT_COPY_STR(config->args,   where, "-inst",               "rawExp.camera",     "=="); */
    85 /*     PXOPT_COPY_STR(config->args,   where, "-telescope",          "rawExp.telescope",  "=="); */
    86 /*     PXOPT_COPY_TIME(config->args,  where, "-dateobs_begin",      "rawExp.dateobs",    ">="); */
    87 /*     PXOPT_COPY_TIME(config->args,  where, "-dateobs_end",        "rawExp.dateobs",    "<="); */
    88 /*     PXOPT_COPY_STR(config->args,   where, "-exp_tag",            "rawExp.exp_tag",    "=="); */
    89 /*     PXOPT_COPY_STR(config->args,   where, "-exp_type",           "rawExp.exp_type",   "=="); */
    90 /*     PXOPT_COPY_STR(config->args,   where, "-comment",            "rawExp.comment",    "LIKE"); */
    91 /*     PXOPT_COPY_STR(config->args,   where, "-filelevel",          "rawExp.filelevel",  "=="); */
    92 /*     PXOPT_COPY_STR(config->args,   where, "-filter",             "rawExp.filter",         "=="); */
    93 /*     PXOPT_COPY_F64(config->args,   where, "-airmass_min",        "rawExp.airmass",        ">="); */
    94 /*     PXOPT_COPY_F64(config->args,   where, "-airmass_max",        "rawExp.airmass",        "<"); */
    95 /*     PXOPT_COPY_RADEC(config->args, where, "-ra_min",             "rawExp.ra",             ">="); */
    96 /*     PXOPT_COPY_RADEC(config->args, where, "-ra_max",             "rawExp.ra",             "<"); */
    97 /*     PXOPT_COPY_RADEC(config->args, where, "-decl_min",           "rawExp.decl",           ">="); */
    98 /*     PXOPT_COPY_RADEC(config->args, where, "-decl_max",           "rawExp.decl",           "<"); */
    99 /*     PXOPT_COPY_F32(config->args,   where, "-exp_time_min",       "rawExp.exp_time",       ">="); */
    100 /*     PXOPT_COPY_F32(config->args,   where, "-exp_time_max",       "rawExp.exp_time",       "<"); */
    101 /*     PXOPT_COPY_F32(config->args,   where, "-sat_pixel_frac_min", "rawExp.sat_pixel_frac", ">="); */
    102 /*     PXOPT_COPY_F32(config->args,   where, "-sat_pixel_frac_max", "rawExp.sat_pixel_frac", "<"); */
    103 /*     PXOPT_COPY_F64(config->args,   where, "-bg_min",             "rawExp.bg",             ">="); */
    104 /*     PXOPT_COPY_F64(config->args,   where, "-bg_max",             "rawExp.bg",             "<"); */
    105 /*     PXOPT_COPY_F64(config->args,   where, "-bg_stdev_min",       "rawExp.bg_stdev",       ">="); */
    106 /*     PXOPT_COPY_F64(config->args,   where, "-bg_stdev_max",       "rawExp.bg_stdev",       "<"); */
    107 /*     PXOPT_COPY_F64(config->args,   where, "-bg_mean_stdev_min",  "rawExp.bg_mean_stdev",  ">="); */
    108 /*     PXOPT_COPY_F64(config->args,   where, "-bg_mean_stdev_max",  "rawExp.bg_mean_stdev",  "<"); */
    109 /*     PXOPT_COPY_F64(config->args,   where, "-alt_min",            "rawExp.alt",            ">="); */
    110 /*     PXOPT_COPY_F64(config->args,   where, "-alt_max",            "rawExp.alt",            "<"); */
    111 /*     PXOPT_COPY_F64(config->args,   where, "-az_min",             "rawExp.az",             ">="); */
    112 /*     PXOPT_COPY_F64(config->args,   where, "-az_max",             "rawExp.az",             "<"); */
    113 /*     PXOPT_COPY_F32(config->args,   where, "-ccd_temp_min",       "rawExp.ccd_temp",       ">="); */
    114 /*     PXOPT_COPY_F32(config->args,   where, "-ccd_temp_max",       "rawExp.ccd_temp",       "<"); */
    115 /*     PXOPT_COPY_F64(config->args,   where, "-posang_min",         "rawExp.posang",         ">="); */
    116 /*     PXOPT_COPY_F64(config->args,   where, "-posang_max",         "rawExp.posang",         "<"); */
    117 /*     PXOPT_COPY_STR(config->args,   where, "-object",             "rawExp.object",         "=="); */
    118 /*     PXOPT_COPY_F32(config->args,   where, "-sun_angle_min",      "rawExp.sun_angle",      ">="); */
    119 /*     PXOPT_COPY_F32(config->args,   where, "-sun_angle_max",      "rawExp.sun_angle",      "<"); */
    120 
    121     return true;
    122 }
    123 
    124 bool pxaddRunSetState(pxConfig *config, psS64 add_id, const char *state, psS64 magicked)
     31bool pxaddRunSetState(pxConfig *config, psS64 add_id, const char *state)
    12532{
    12633    PS_ASSERT_PTR_NON_NULL(config, false);
     
    13441    }
    13542
    136     char *query = "UPDATE addRun SET state = '%s', magicked = %" PRId64 " WHERE add_id = %" PRId64;
    137     if (!p_psDBRunQueryF(config->dbh, query, state, magicked, add_id)) {
    138         psError(PS_ERR_UNKNOWN, false,
    139                 "failed to change state for add_id %" PRId64, add_id);
     43    char *query = "UPDATE addRun SET state = '%s' WHERE add_id = %" PRId64;
     44    if (!p_psDBRunQueryF(config->dbh, query, state, add_id)) {
     45        psError(PS_ERR_UNKNOWN, false, "failed to change state for add_id %" PRId64, add_id);
    14046        return false;
    14147    }
     
    216122}
    217123
    218 // Need to think more about this to see what we want it to do. BROKEN
    219124bool pxaddQueueByCamID(pxConfig *config,
    220125                       psS64 cam_id,
    221126                       char *workdir,
     127                       char *reduction,
    222128                       char *label,
    223                        char *recipe,
    224                        char *dvodb)
     129                       char *data_group,
     130                       char *dvodb,
     131                       char *note,
     132                       bool image_only)
    225133{
    226134    PS_ASSERT_PTR_NON_NULL(config, false);
     
    236144        }
    237145    }
    238     //    fprintf(stderr,"%s",query);
     146
    239147    // queue the exp
    240     // XXX chip_id is being cast here work around psS64 have a different type
    241     // different on 32/64
     148    // Note: cam_id is being cast here work around psS64 have a different type different
     149    // on 32/64
    242150    if (!p_psDBRunQueryF(config->dbh, query,
    243151                         "new", // state
    244                          workdir  ? workdir  : "NULL",
     152                         workdir  ? workdir   : "NULL",
    245153                         "dirty", //workdir_state
    246                          label    ? label    : "NULL",
    247                          dvodb    ? dvodb    : "NULL",
    248                          (long long)cam_id
     154                         reduction? reduction : "NULL",
     155                         label    ? label     : "NULL",
     156                         data_group ? data_group     : "NULL",
     157                         dvodb    ? dvodb     : "NULL",
     158                         note     ? note     : "NULL",
     159                         image_only,
     160                         (long long) cam_id
    249161    )) {
    250162        psError(PS_ERR_UNKNOWN, false, "database error");
  • branches/eam_branches/20090820/ippTools/src/pxadd.h

    r25766 r25870  
    2525#include "pxtools.h"
    2626
    27 bool pxaddRunSetState(pxConfig *config, psS64 add_id, const char *state, psS64 magicked);
     27bool pxaddRunSetState(pxConfig *config, psS64 add_id, const char *state);
    2828bool pxaddRunSetStateByQuery(pxConfig *config, psMetadata *where, const char *state);
    2929bool pxaddRunSetLabel(pxConfig *config, psS64 add_id, const char *label);
    3030bool pxaddRunSetLabelByQuery(pxConfig *config, psMetadata *where, const char *label);
    3131
    32 bool pxaddSetSearchArgs (psMetadata *md);
    33 bool pxaddGetSearchArgs (pxConfig *config, psMetadata *where);
    34 
    35 // Likely BROKEN
    3632bool pxaddQueueByCamID(pxConfig *config,
    37                         psS64 cam_id,
    38                         char *workdir,
    39                         char *label,
    40                         char *recipe,
    41                         char *dvodb);
    42 
     33                       psS64 cam_id,
     34                       char *workdir,
     35                       char *reduction,
     36                       char *label,
     37                       char *data_group,
     38                       char *dvodb,
     39                       char *note,
     40                       bool image_only);
    4341
    4442#endif // PXADD_H
  • branches/eam_branches/20090820/ippTools/src/pxadmin.c

    r23310 r25870  
    22 * pxadmin.c
    33 *
    4  * Copyright (C) 2006-2008  Joshua Hoblitt
     4 * Copyright (C) 2006-2009  Joshua Hoblitt
    55 *
    66 * This program is free software; you can redistribute it and/or modify it
     
    3131bool createMirrorMode(pxConfig *config);
    3232bool deleteMode(pxConfig *config);
     33static bool insert_dbversion(pxConfig * config, const char *versionString);
    3334static bool runMultipleStatments(pxConfig *config, const char *query);
    3435
     
    113114    psFree(query);
    114115
     116    if (!insert_dbversion(config, PACKAGE_VERSION)) {
     117        psError(PS_ERR_UNKNOWN, false, "failed to set database version");
     118        return false;
     119    }
     120
    115121    // COMMIT
    116122    if (!psDBCommit(config->dbh)) {
     
    148154    }
    149155    psFree(query);
     156
     157    if (!insert_dbversion(config, PACKAGE_VERSION)) {
     158        psError(PS_ERR_UNKNOWN, false, "failed to set database version");
     159        return false;
     160    }
    150161
    151162    // COMMIT
     
    262273    return true;
    263274}
     275
     276#ifdef notdef
     277static bool update_dbversion(pxConfig * config, const char *versionString)
     278{
     279    psString query = pxDataGet("pxadmin_update_version.sql");
     280    if (!query) {
     281        psError(PS_ERR_UNKNOWN, false, "failed to retrieve SQL statement");
     282        psFree(query);
     283        return false;
     284    }
     285    if (!p_psDBRunQueryF(config->dbh, query, versionString)) {
     286        psError(PS_ERR_UNKNOWN, false, "database error");
     287        psFree(query);
     288        return false;
     289    }
     290    return true;
     291}
     292#endif
     293static bool insert_dbversion(pxConfig * config, const char *versionString)
     294{
     295    psString query = "INSERT INTO dbversion VALUES('%s', CURRENT_TIMESTAMP())";
     296    if (!query) {
     297        psError(PS_ERR_UNKNOWN, false, "failed to retrieve SQL statement");
     298        psFree(query);
     299        return false;
     300    }
     301    if (!p_psDBRunQueryF(config->dbh, query, versionString)) {
     302        psError(PS_ERR_UNKNOWN, false, "database error");
     303        psFree(query);
     304        return false;
     305    }
     306    return true;
     307}
  • branches/eam_branches/20090820/ippTools/src/pxcam.c

    r24866 r25870  
    141141}
    142142
    143 
    144 bool pxcamRunSetStateByQuery(pxConfig *config, psMetadata *where, const char *state)
    145 {
    146     PS_ASSERT_PTR_NON_NULL(config, false);
    147     PS_ASSERT_PTR_NON_NULL(state, false);
    148 
    149     // check that state is a valid string value
    150     if (!pxIsValidState(state)) {
    151         psError(PS_ERR_UNKNOWN, false,
    152                 "invalid chipRun state: %s", state);
    153         return false;
    154     }
    155 
    156     psString query = psStringCopy("UPDATE camRun JOIN chipRun USING(chip_id) JOIN rawExp USING(exp_id) SET camRun.state = '%s'");
    157 
    158     if (where) {
    159         psString whereClause = psDBGenerateWhereSQL(where, NULL);
    160         psStringAppend(&query, " %s", whereClause);
    161         psFree(whereClause);
    162     }
    163 
    164     if (!p_psDBRunQueryF(config->dbh, query, state)) {
    165         psFree(query);
    166         psError(PS_ERR_UNKNOWN, false, "database error");
    167         return false;
    168     }
    169 
    170     psFree(query);
    171 
    172     return true;
    173 }
    174 
    175 
    176 bool pxcamRunSetLabel(pxConfig *config, psS64 cam_id, const char *label)
    177 {
    178     PS_ASSERT_PTR_NON_NULL(config, false);
    179     // note label == NULL should be explicitly allowed
    180 
    181     char *query = "UPDATE camRun SET camRun.label = '%s' WHERE cam_id = %" PRId64;
    182     if (!p_psDBRunQueryF(config->dbh, query, label, cam_id)) {
    183         psError(PS_ERR_UNKNOWN, false,
    184                 "failed to change state for cam_id %" PRId64, cam_id);
    185         return false;
    186     }
    187 
    188     return true;
    189 }
    190 
    191 bool pxcamRunSetLabelByQuery(pxConfig *config, psMetadata *where, const char *label)
    192 {
    193     PS_ASSERT_PTR_NON_NULL(config, false);
    194     // note label == NULL should be explicitly allowed
    195 
    196     psString query = psStringCopy("UPDATE camRun JOIN chipRun USING(chip_id) JOIN rawExp USING(exp_id) SET camRun.label = '%s'");
    197 
    198     if (where) {
    199         psString whereClause = psDBGenerateWhereSQL(where, NULL);
    200         psStringAppend(&query, " %s", whereClause);
    201         psFree(whereClause);
    202     }
    203 
    204     if (!p_psDBRunQueryF(config->dbh, query, label)) {
    205         psFree(query);
    206         psError(PS_ERR_UNKNOWN, false, "database error");
    207         return false;
    208     }
    209 
    210     psFree(query);
    211 
    212     return true;
    213 }
    214 
    215 
    216143bool pxcamQueueByChipID(pxConfig *config,
    217144                    psS64 chip_id,
    218145                    char *workdir,
    219146                    char *label,
     147                    char *data_group,
     148                    char *dist_group,
    220149                    char *recipe,
    221150                    char *expgroup,
    222151                    char *dvodb,
    223152                    char *tess_id,
    224                     char *end_stage)
     153                    char *end_stage,
     154                    char *note)
    225155{
    226156    PS_ASSERT_PTR_NON_NULL(config, false);
     
    245175                "dirty", //workdir_state
    246176                label    ? label    : "NULL",
     177                data_group ? data_group : "NULL",
     178                dist_group ? dist_group : "NULL",
    247179                recipe   ? recipe   : "NULL",
    248180                expgroup ? expgroup : "NULL",
     
    250182                tess_id  ? tess_id  : "NULL",
    251183                end_stage ? end_stage : "NULL",
     184                note     ? note     : "NULL",
    252185                (long long)chip_id
    253186    )) {
  • branches/eam_branches/20090820/ippTools/src/pxcam.h

    r24681 r25870  
    2626
    2727bool pxcamRunSetState(pxConfig *config, psS64 cam_id, const char *state, psS64 magicked);
    28 bool pxcamRunSetStateByQuery(pxConfig *config, psMetadata *where, const char *state);
    29 bool pxcamRunSetLabel(pxConfig *config, psS64 cam_id, const char *label);
    30 bool pxcamRunSetLabelByQuery(pxConfig *config, psMetadata *where, const char *label);
    31 
    3228bool pxcamSetSearchArgs (psMetadata *md);
    3329bool pxcamGetSearchArgs (pxConfig *config, psMetadata *where);
     
    3733                        char *workdir,
    3834                        char *label,
     35                        char *data_group,
     36                        char *dist_group,
    3937                        char *recipe,
    4038                        char *expgroup,
    4139                        char *dvodb,
    4240                        char *tess_id,
    43                         char *end_stage);
     41                        char *end_stage,
     42                        char *note);
    4443
    4544#endif // PXCAM_H
  • branches/eam_branches/20090820/ippTools/src/pxchip.c

    r24866 r25870  
    192192}
    193193
    194 
    195 bool pxchipRunSetLabel(pxConfig *config, psS64 chip_id, const char *label)
     194bool pxchipProcessedImfileSetStateByQuery(pxConfig *config, psMetadata *where, const char *state)
    196195{
    197196    PS_ASSERT_PTR_NON_NULL(config, false);
    198     // note label == NULL should be explicitly allowed
    199 
    200     char *query = "UPDATE chipRun SET label = '%s' WHERE chip_id = %" PRId64;
    201     if (!p_psDBRunQueryF(config->dbh, query, label, chip_id)) {
    202         psError(PS_ERR_UNKNOWN, false,
    203                 "failed to change state for chip_id %" PRId64, chip_id);
    204         return false;
    205     }
    206 
    207     return true;
    208 }
    209 
    210 
    211 bool pxchipRunSetLabelByQuery(pxConfig *config, psMetadata *where, const char *label)
    212 {
    213     PS_ASSERT_PTR_NON_NULL(config, false);
    214     // note label == NULL should be explicitly allowed
    215 
    216     psString query = psStringCopy("UPDATE chipRun JOIN rawExp USING(exp_id) SET label = '%s'");
     197    PS_ASSERT_PTR_NON_NULL(state, false);
     198
     199    // check that state is a valid string value
     200    if (!pxIsValidState(state)) {
     201        psError(PS_ERR_UNKNOWN, false, "invalid chipProcessedImfile state: %s", state);
     202        return false;
     203    }
     204
     205/*     if (!strcmp(state, "full")) { */
     206/*         // There are states that need to be met for a run to be set to full that we don't */
     207/*         // check here. */
     208/*         // for example all of the run's Imfiles must have chipProcessedImfile.data_state == "full" */
     209/*         // chipRun.magicked = (SUM(!chipProcessedImfile.magicked) = 0) */
     210/*         // so don't do allow setting the state to full */
     211/*         psError(PS_ERR_UNKNOWN, true, "cannot use -updaterun so set chipRun state to full"); */
     212/*         return false; */
     213/*     } */
     214
     215    psString query = psStringCopy("UPDATE chipProcessedImfile JOIN chipRun USING(chip_id) JOIN rawExp ON chipRun.exp_id = rawExp.exp_id SET state = '%s'");
    217216
    218217    if (where && psListLength(where->list) > 0) {
     
    222221    }
    223222
    224     if (!p_psDBRunQueryF(config->dbh, query, label)) {
     223    if (!p_psDBRunQueryF(config->dbh, query, state)) {
    225224        psFree(query);
    226225        psError(PS_ERR_UNKNOWN, false, "database error");
     
    232231    return true;
    233232}
    234 
    235233
    236234psS64 pxchipQueueByExpTag(pxConfig *config,
     
    238236                         const char *workdir,
    239237                         const char *label,
     238                         const char *data_group,
     239                         const char *dist_group,
    240240                         const char *reduction,
    241241                         const char *expgroup,
    242242                         const char *dvodb,
    243243                         const char *tess_id,
    244                          const char *end_stage)
     244                         const char *end_stage,
     245                         const char *note)
    245246{
    246247    PS_ASSERT_PTR_NON_NULL(config, false);
     
    260261            "dirty",    // workdir_state
    261262            label,
     263            data_group,
     264            dist_group,
    262265            reduction,
    263266            expgroup,
     
    265268            tess_id,
    266269            end_stage,
    267             0           // magicked
     270            0,          // magicked
     271            note
    268272            )
    269273    ) {
  • branches/eam_branches/20090820/ippTools/src/pxchip.h

    r23381 r25870  
    2525#include "pxtools.h"
    2626
     27
     28
    2729bool pxchipRunSetState(pxConfig *config, psS64 chip_id, const char *state, const bool magicked);
    28 bool pxchipRunSetStateByQuery(pxConfig *config, psMetadata *where, const char *state);
    29 bool pxchipRunSetLabel(pxConfig *config, psS64 chip_id, const char *label);
    30 bool pxchipRunSetLabelByQuery(pxConfig *config, psMetadata *where, const char *label);
     30bool pxchipProcessedImfileSetStateByQuery(pxConfig *config, psMetadata *where, const char *state);
    3131
    3232psS64 pxchipQueueByExpTag(pxConfig *config,
     
    3434                         const char *workdir,
    3535                         const char *label,
     36                         const char *data_group,
     37                         const char *dist_group,
    3638                         const char *reduction,
    3739                         const char *expgroup,
    3840                         const char *dvodb,
    3941                         const char *tess_id,
    40                          const char *end_stage);
     42                         const char *end_stage,
     43                         const char *note);
    4144
    4245
  • branches/eam_branches/20090820/ippTools/src/pxfake.c

    r21402 r25870  
    5151}
    5252
    53 
    54 bool pxfakeRunSetStateByQuery(pxConfig *config, psMetadata *where, const char *state)
    55 {
    56     PS_ASSERT_PTR_NON_NULL(config, false);
    57     PS_ASSERT_PTR_NON_NULL(state, false);
    58 
    59     // check that state is a valid string value
    60     if (!pxIsValidState(state)) {
    61         psError(PS_ERR_UNKNOWN, false,
    62                 "invalid fakeRun state: %s", state);
    63         return false;
    64     }
    65 
    66     psString query = psStringCopy("UPDATE fakeRun JOIN camRun USING(cam_id) JOIN chipRun USING(chip_id) JOIN rawExp USING(exp_id) SET fakeRun.state = '%s'");
    67 
    68     if (where) {
    69         psString whereClause = psDBGenerateWhereSQL(where, NULL);
    70         psStringAppend(&query, " %s", whereClause);
    71         psFree(whereClause);
    72     }
    73 
    74     if (!p_psDBRunQueryF(config->dbh, query, state)) {
    75         psFree(query);
    76         psError(PS_ERR_UNKNOWN, false, "database error");
    77         return false;
    78     }
    79 
    80     psFree(query);
    81 
    82     return true;
    83 }
    84 
    85 
    86 bool pxfakeRunSetLabel(pxConfig *config, psS64 fake_id, const char *label)
    87 {
    88     PS_ASSERT_PTR_NON_NULL(config, false);
    89     // note label == NULL should be explicitly allowed
    90 
    91     char *query = "UPDATE fakeRun SET fakeRun.label = '%s' WHERE fake_id = %" PRId64;
    92     if (!p_psDBRunQueryF(config->dbh, query, label, fake_id)) {
    93         psError(PS_ERR_UNKNOWN, false,
    94                 "failed to change state for fake_id %" PRId64, fake_id);
    95         return false;
    96     }
    97 
    98     return true;
    99 }
    100 
    101 
    102 bool pxfakeRunSetLabelByQuery(pxConfig *config, psMetadata *where, const char *label)
    103 {
    104     PS_ASSERT_PTR_NON_NULL(config, false);
    105     // note label == NULL should be explicitly allowed
    106 
    107     psString query = psStringCopy("UPDATE fakeRun JOIN camRun USING(cam_id) JOIN chipRun USING(chip_id) JOIN rawExp USING(exp_id) SET fakeRun.label = '%s'");
    108 
    109     if (where) {
    110         psString whereClause = psDBGenerateWhereSQL(where, NULL);
    111         psStringAppend(&query, " %s", whereClause);
    112         psFree(whereClause);
    113     }
    114 
    115     if (!p_psDBRunQueryF(config->dbh, query, label)) {
    116         psFree(query);
    117         psError(PS_ERR_UNKNOWN, false, "database error");
    118         return false;
    119     }
    120 
    121     psFree(query);
    122 
    123     return true;
    124 }
    125 
    126 
    12753psS64 pxfakeQueueByCamID(pxConfig *config,
    12854                    psS64 cam_id,
    12955                    char *workdir,
    13056                    char *label,
     57                    char *data_group,
     58                    char *dist_group,
    13159                    char *reduction,
    13260                    char *expgroup,
    13361                    char *dvodb,
    13462                    char *tess_id,
    135                     char *end_stage)
     63                    char *end_stage,
     64                    char *note)
    13665{
    13766    PS_ASSERT_PTR_NON_NULL(config, false);
     
    15786                workdir  ? workdir  : "NULL",
    15887                label    ? label    : "NULL",
     88                data_group ? data_group : "NULL",
     89                dist_group ? dist_group : "NULL",
    15990                reduction? reduction: "NULL",
    16091                expgroup ? expgroup : "NULL",
     
    16293                tess_id  ? tess_id  : "NULL",
    16394                end_stage ? end_stage : "NULL",
     95                note     ? note     : "NULL",
    16496                (long long)cam_id
    16597    )) {
  • branches/eam_branches/20090820/ippTools/src/pxfake.h

    r17938 r25870  
    2626
    2727bool pxfakeRunSetState(pxConfig *config, psS64 fake_id, const char *state);
    28 bool pxfakeRunSetStateByQuery(pxConfig *config, psMetadata *where, const char *state);
    29 bool pxfakeRunSetLabel(pxConfig *config, psS64 fake_id, const char *label);
    30 bool pxfakeRunSetLabelByQuery(pxConfig *config, psMetadata *where, const char *label);
    31 
    3228
    3329psS64 pxfakeQueueByCamID(pxConfig *config,
     
    3531                    char *workdir,
    3632                    char *label,
     33                    char *data_group,
     34                    char *dist_group,
    3735                    char *reduction,
    3836                    char *expgroup,
    3937                    char *dvodb,
    4038                    char *tess_id,
    41                     char *end_stage);
     39                    char *end_stage,
     40                    char *note);
    4241
    4342
  • branches/eam_branches/20090820/ippTools/src/pxmagic.c

    r25766 r25870  
    2929#include "pxmagic.h"
    3030
    31 bool magicRestoreStage(pxConfig *config, psString stage, psString whereClause, psString newState)
     31bool pxmagicRestoreStage(pxConfig *config, psString stage, psString whereClause, psString newState)
    3232{
    3333    psString queryFile = NULL;
     
    6666    return true;
    6767}
     68
     69bool pxmagicAddWhere(pxConfig *config, psString *out, psString table)
     70{
     71    PXOPT_LOOKUP_U64(magicked, config->args, "-magicked", false, false);
     72    PXOPT_LOOKUP_BOOL(destreaked, config->args,     "-destreaked", false);
     73    PXOPT_LOOKUP_BOOL(not_destreaked, config->args, "-not_destreaked", false);
     74
     75    if (not_destreaked) {
     76        if (destreaked) {
     77            psError(PXTOOLS_ERR_DATA, true, "providing -not_destreaked and -destreaked makes no sense");
     78            return false;
     79        }
     80        if (magicked) {
     81            psError(PXTOOLS_ERR_DATA, true, "providing -not_destreaked and -magicked makes no sense");
     82            return false;
     83        }
     84        psStringAppend(out, " AND %s.magicked = 0", table);
     85    }
     86    if (destreaked) {
     87        psStringAppend(out, " AND %s.magicked != 0", table);
     88    }
     89    return true;
     90}
     91
     92void pxmagicAddArguments(psMetadata *md)
     93{
     94    psMetadataAddBool(md, PS_LIST_TAIL, "-destreaked",  0,      "search for destreaked images", false);
     95    psMetadataAddBool(md, PS_LIST_TAIL, "-not_destreaked",  0,  "search for images that have not been destreaked", false);
     96    psMetadataAddS64(md, PS_LIST_TAIL,  "-magicked", 0,         "search by magicked value", 0);
     97}
  • branches/eam_branches/20090820/ippTools/src/pxmagic.h

    r25766 r25870  
    2525#include "pxtools.h"
    2626
    27 extern bool magicRestoreStage(pxConfig *config, psString stage, psString whereClause, psString newState);
     27extern bool pxmagicRestoreStage(pxConfig *config, psString stage, psString whereClause, psString newState);
     28
     29extern bool pxmagicAddWhere(pxConfig *config, psString *string, psString table);
     30extern void pxmagicAddArguments(psMetadata *md);
    2831
    2932#endif // PXMAGIC_H
  • branches/eam_branches/20090820/ippTools/src/pxtools.c

    r25766 r25870  
    108108    return true;
    109109}
     110
     111// shared code for updating the various strings for a Run
     112bool pxUpdateRun(pxConfig *config, psMetadata *where, psString *pQuery, psString table, bool has_dist_group)
     113{
     114    PS_ASSERT_PTR_NON_NULL(config, false);
     115    PS_ASSERT_PTR_NON_NULL(where, false);
     116    PS_ASSERT_PTR_NON_NULL(pQuery, false);
     117    PS_ASSERT_PTR_NON_NULL(*pQuery, false);
     118
     119    // make sure that -state is not the only selection parameter
     120    PXOPT_LOOKUP_STR(where_state, config->args, "-state", false, false);
     121    if (where_state && (psListLength(where->list) < 2)) {
     122        psError(PXTOOLS_ERR_DATA, true, "selection by -state alone is not allowed");
     123        return false;
     124    }
     125
     126    PXOPT_LOOKUP_STR(state, config->args,       "-set_state", false, false);
     127    PXOPT_LOOKUP_STR(label, config->args,       "-set_label", false, false);
     128    PXOPT_LOOKUP_STR(data_group, config->args,  "-set_data_group", false, false);
     129    PXOPT_LOOKUP_STR(note, config->args,        "-set_note", false, false);
     130
     131    psString dist_group = NULL;
     132    if (has_dist_group) {
     133        PXOPT_LOOKUP_STR(tmp_dist_group, config->args,  "-set_dist_group", false, false);
     134        dist_group = tmp_dist_group;
     135    }
     136
     137    if ((!state) && (!label) && (!data_group) && (has_dist_group && !dist_group) && !(note)) {
     138        psError(PXTOOLS_ERR_DATA, false, "parameters are required");
     139        return false;
     140    }
     141
     142    if (state && ! pxIsValidState(state)) {
     143        psError(PXTOOLS_ERR_DATA, false, "pxIsValidState failed");
     144        return false;
     145    }
     146
     147    // first paramter is added with "SET param = 'value'"
     148    // subseqent ones with ", param = 'value'"
     149    char *separator = " SET ";
     150    char *comma = ",";
     151
     152#   define addColumn(_tab, _val) \
     153        do { \
     154            if (_val) { \
     155                psStringAppend(pQuery, "%s %s.%s = '%s'", separator, _tab, #_val, _val); \
     156                separator = comma; \
     157            } \
     158        } while (0)
     159
     160    addColumn(table, state);
     161    addColumn(table, data_group);
     162    if (has_dist_group) {
     163        addColumn(table, dist_group);
     164    }
     165    addColumn(table, note);
     166    addColumn(table, label);
     167
     168    psString whereClause =  psDBGenerateWhereSQL(where, NULL);
     169    psStringAppend(pQuery, " %s", whereClause);
     170    psFree(whereClause);
     171
     172    if (!p_psDBRunQuery(config->dbh, *pQuery)) {
     173        psError(PS_ERR_UNKNOWN, false, "database error");
     174        return false;
     175    }
     176
     177    return true;
     178}
     179
     180bool pxLookupVersion(pxConfig *config, psArray **pArray)
     181{
     182    const char *query = "SELECT * FROM dbversion";
     183
     184    if (!p_psDBRunQuery(config->dbh, query)) {
     185        psError(PS_ERR_UNKNOWN, false, "database error");
     186        return false;
     187    }
     188
     189    psArray *output = p_psDBFetchResult(config->dbh);
     190    if (!output) {
     191        psError(PS_ERR_UNKNOWN, false, "database error");
     192        return false;
     193    }
     194    if (!psArrayLength(output)) {
     195        psFree(output);
     196        psError(PS_ERR_UNKNOWN, true, "no rows in dbversion");
     197        return false;
     198    }
     199    if (psArrayLength(output) > 1) {
     200        psError(PS_ERR_UNKNOWN, true, "unexpected number of rows found in dbversion: %" PRId64,
     201                psArrayLength(output));
     202        return false;
     203    }
     204    *pArray = output;
     205
     206    return true;
     207}
     208
     209psString pxGetDBVersion(pxConfig *config)
     210{
     211    PS_ASSERT_PTR_NON_NULL(config, NULL);
     212
     213    psArray *array = NULL;
     214    if (!pxLookupVersion(config, &array)) {
     215        psError(PS_ERR_UNKNOWN, false, "pxLookupVersion failed");
     216        return NULL;
     217    }
     218    psMetadata *md = array->data[0];
     219    if (!md) {
     220        psError(PS_ERR_UNKNOWN, true, "output of pxLookupVersion is null");
     221        return NULL;
     222    }
     223   
     224    psString version = psMetadataLookupStr(NULL, md, "schema_version");
     225
     226    return version;
     227}
     228
     229bool pxExportVersion(pxConfig *config, FILE *file)
     230{
     231    PS_ASSERT_PTR_NON_NULL(config, NULL);
     232    PS_ASSERT_PTR_NON_NULL(file, NULL);
     233
     234    psArray *array = NULL;
     235    if (!pxLookupVersion(config, &array) || !array) {
     236        psError(PS_ERR_UNKNOWN, false, "pxLookupVersion failed");
     237        return false;
     238    }
     239    if (!ippdbPrintMetadatas(file, array, "dbversion", true)) {
     240        psError(PS_ERR_UNKNOWN, false, "failed to print array");
     241        psFree(array);
     242        return false;
     243    }
     244    return true;
     245}
     246
     247bool pxCheckImportVersion(pxConfig *config, psMetadata *input)
     248{
     249    PS_ASSERT_PTR_NON_NULL(config, NULL);
     250    PS_ASSERT_PTR_NON_NULL(input, NULL);
     251
     252    // This code was adapted from the way camtool parses the structures.
     253    // Is this really the way to do it?
     254    psMetadataItem *multi_item =  psMetadataLookup(input, "dbversion");
     255    if (!multi_item || (multi_item->type != PS_DATA_METADATA_MULTI)) {
     256        psError(PS_ERR_UNKNOWN, true, "dbversion multi not found in input");
     257        return false;
     258    }
     259   
     260    psMetadataItem *dbversion = psListGet(multi_item->data.list, 0);
     261    if (!dbversion) {
     262        psError(PS_ERR_UNKNOWN, true, "dbversion not found in input");
     263        return false;
     264    }
     265
     266    if (!strcmp(dbversion->name, "dbversion")) {
     267        // horray
     268        psMetadata *md = dbversion->data.md;
     269        psString schema_version = pxGetDBVersion(config);
     270        if (!schema_version) {
     271            psError(PS_ERR_UNKNOWN, false, "pxGetDBVersion failed");
     272            return false;
     273        }
     274       
     275        psString import_version = psMetadataLookupStr(NULL, md, "schema_version");
     276        if (import_version && strcmp(import_version, schema_version)) {
     277            psError(PS_ERR_UNKNOWN, true, "input file schema_version: %s does not match data base: %s",
     278                import_version, schema_version);
     279            return false;
     280        } else if (!import_version) {
     281            psError(PS_ERR_UNKNOWN, true, "input file schema_version is NULL");
     282            return false;
     283        } else {
     284            // YIPPEE this file is the same version
     285        }
     286    } else {
     287        psError(PS_ERR_UNKNOWN, true, "Unexpected config dump format");
     288        return false;
     289    }
     290
     291    return true;
     292}
  • branches/eam_branches/20090820/ippTools/src/pxtools.h

    r25766 r25870  
    4747#include "pxtree.h"
    4848#include "pxmagic.h"
     49#include "pxspace.h"
    4950
    5051# define MAX_ROWS 10e9
     
    5657
    5758bool pxSetFaultCode(psDB *dbh, const char *tableName, psMetadata *where, psS16 code);
     59bool pxExportVersion(pxConfig *config, FILE *f);
     60bool pxCheckImportVersion(pxConfig *config, psMetadata *md);
    5861
    5962psExit pxerrorGetExitStatus(void);
     
    6164void pxUsage(FILE *stream, int argc, char **argv, const char *modeName, psMetadata *argSet);
    6265bool pxGetOptions(FILE *stream, int argc, char **argv, pxConfig *config, psMetadata *modes, psMetadata *argSets);
     66
     67bool pxUpdateRun(pxConfig *config, psMetadata *where, psString *pQuery, psString table, bool has_dist_group);
    6368
    6469#define PXOPT_ADD_MODE(option, comment, modeval, argset) \
  • branches/eam_branches/20090820/ippTools/src/pxwarp.c

    r24487 r25870  
    2929#include "pxwarp.h"
    3030
    31 bool pxwarpRunSetState(pxConfig *config, psS64 warp_id, const char *state)
    32 {
    33     PS_ASSERT_PTR_NON_NULL(config, false);
    34     PS_ASSERT_PTR_NON_NULL(state, false);
    35 
    36     // check that state is a valid string value
    37     if (!pxIsValidState(state)) {
    38         psError(PS_ERR_UNKNOWN, false, "invalid warpRun state: %s", state);
    39         return false;
    40     }
    41 
    42     char *query = "UPDATE warpRun SET state = '%s' WHERE warp_id = %" PRId64;
    43     if (!p_psDBRunQueryF(config->dbh, query, state, warp_id)) {
    44         psError(PS_ERR_UNKNOWN, false,
    45                 "failed to change state for warp_id %" PRId64, warp_id);
    46         return false;
    47     }
    48 
    49     return true;
    50 }
    51 
    52 
    53 bool pxwarpRunSetStateByQuery(pxConfig *config, psMetadata *where, const char *state)
    54 {
    55     PS_ASSERT_PTR_NON_NULL(config, false);
    56     PS_ASSERT_PTR_NON_NULL(state, false);
    57 
    58     // check that state is a valid string value
    59     if (!pxIsValidState(state)) {
    60         psError(PS_ERR_UNKNOWN, false, "invalid warpRun state: %s", state);
    61         return false;
    62     }
    63 
    64     psString query = psStringCopy("UPDATE warpRun JOIN fakeRun USING(fake_id) JOIN camRun USING(cam_id) JOIN chipRun USING(chip_id) JOIN rawExp USING(exp_id) SET warpRun.state = '%s'");
    65 
    66     if (where) {
    67         psString whereClause = psDBGenerateWhereSQL(where, NULL);
    68         if (whereClause && strlen(whereClause) > 0) {
    69             psStringAppend(&query, " %s", whereClause);
    70         }
    71         psFree(whereClause);
    72     }
    73 
    74     if (!p_psDBRunQueryF(config->dbh, query, state)) {
    75         psFree(query);
    76         psError(PS_ERR_UNKNOWN, false, "database error");
    77         return false;
    78     }
    79 
    80     psFree(query);
    81 
    82     return true;
    83 }
    84 
    85 
    86 bool pxwarpRunSetLabel(pxConfig *config, psS64 warp_id, const char *label)
    87 {
    88     PS_ASSERT_PTR_NON_NULL(config, false);
    89     // note label == NULL should be explicitly allowed
    90 
    91     char *query = "UPDATE warpRun SET warpRun.label = '%s' WHERE warp_id = %" PRId64;
    92     if (!p_psDBRunQueryF(config->dbh, query, label, warp_id)) {
    93         psError(PS_ERR_UNKNOWN, false,
    94                 "failed to change label for warp_id %" PRId64, warp_id);
    95         return false;
    96     }
    97 
    98     return true;
    99 }
    100 
    101 
    102 bool pxwarpRunSetLabelByQuery(pxConfig *config, psMetadata *where, const char *label)
    103 {
    104     PS_ASSERT_PTR_NON_NULL(config, false);
    105     // note label == NULL should be explicitly allowed
    106 
    107     psString query = psStringCopy("UPDATE warpRun JOIN fakeRun USING(fake_id) JOIN camRun USING(cam_id) JOIN chipRun USING(chip_id) JOIN rawExp USING(exp_id) SET warpRun.label = '%s'");
    108 
    109     if (where) {
    110         psString whereClause = psDBGenerateWhereSQL(where, NULL);
    111         psStringAppend(&query, " %s", whereClause);
    112         psFree(whereClause);
    113     }
    114 
    115     if (!p_psDBRunQueryF(config->dbh, query, label)) {
    116         psFree(query);
    117         psError(PS_ERR_UNKNOWN, false, "database error");
    118         return false;
    119     }
    120 
    121     psFree(query);
    122 
    123     return true;
    124 }
    125 
    126 
    12731bool pxwarpQueueByFakeID(pxConfig *config,
    12832                         psS64 fake_id,
    12933                         const char *workdir,
    13034                         const char *label,
     35                         const char *data_group,
     36                         const char *dist_group,
    13137                         const char *dvodb,
    13238                         const char *tess_id,
    13339                         const char *reduction,
    134                          const char *end_stage)
     40                         const char *end_stage,
     41                         const char *note)
    13542{
    13643    PS_ASSERT_PTR_NON_NULL(config, false);
     
    14552        "dirty",    // workdir_state
    14653        label,
     54        data_group,
     55        dist_group,
    14756        dvodb,
    14857        tess_id,
    149                        reduction,
     58        reduction,
    15059        end_stage,
    15160        NULL,      // registered
    152         0          // magicked zero when created will get updated when warpRun goes to 'full'
     61        0,         // magicked set to zero when created may get updated when warpRun goes to 'full'
     62        NULL        // note
    15363    )) {
    15464        psError(PS_ERR_UNKNOWN, false, "database error");
  • branches/eam_branches/20090820/ippTools/src/pxwarp.h

    r24487 r25870  
    2525#include "pxtools.h"
    2626
    27 bool pxwarpRunSetState(pxConfig *config, psS64 warp_id, const char *state);
    28 bool pxwarpRunSetStateByQuery(pxConfig *config, psMetadata *where, const char *state);
    29 bool pxwarpRunSetLabel(pxConfig *config, psS64 warp_id, const char *label);
    30 bool pxwarpRunSetLabelByQuery(pxConfig *config, psMetadata *where, const char *label);
    31 
    3227bool pxwarpQueueByFakeID(pxConfig *config,
    3328                         psS64 fake_id,
    3429                         const char *workdir,
    3530                         const char *label,
     31                         const char *data_group,
     32                         const char *dist_group,
    3633                         const char *dvodb,
    3734                         const char *tess_id,
    3835                         const char *reduction,
    39                          const char *end_stage);
     36                         const char *end_stage,
     37                         const char *note);
    4038
    4139#endif // PXWARP_H
  • branches/eam_branches/20090820/ippTools/src/regtool.c

    r25766 r25870  
    334334    PXOPT_COPY_TIME(config->args, where, "-dateobs_end",   "dateobs",  "<=");
    335335    PXOPT_COPY_STR(config->args, where,  "-filter",        "filter", "==");
     336    PXOPT_COPY_STR(config->args, where,  "-exp_type",      "exp_type", "==");
     337    PXOPT_COPY_STR(config->args, where,  "-obs_mode",      "obs_mode", "==");
    336338    PXOPT_COPY_S64(config->args, where,  "-magicked",      "magicked", "==");
    337 
    338     PXOPT_LOOKUP_S64(magicked, config->args, "-magicked", false, false);
    339     PXOPT_LOOKUP_BOOL(destreaked, config->args,     "-destreaked", false);
    340     PXOPT_LOOKUP_BOOL(not_destreaked, config->args, "-not_destreaked", false);
    341339
    342340    PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
    343341    PXOPT_LOOKUP_BOOL(faulted, config->args, "-faulted", false);
    344342    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
     343    PXOPT_LOOKUP_BOOL(all, config->args, "-all", false);
    345344    PXOPT_LOOKUP_BOOL(ordered_by_date, config->args, "-ordered_by_date", false);
     345
     346    // build where string for some parameters that don't fit PXOPT_COPY*
     347    psString where2 = NULL;
     348    if (!pxmagicAddWhere(config, &where2, "rawImfile")) {
     349        psError(PXTOOLS_ERR_DATA, false, "pxSpaceAddWhere failed");
     350        return false;
     351    }
     352    if (!pxspaceAddWhere(config, &where2, "rawImfile")) {
     353        psError(PXTOOLS_ERR_DATA, false, "pxSpaceAddWhere failed");
     354        return false;
     355    }
    346356
    347357    psString query = pxDataGet("regtool_processedimfile.sql");
     
    356366        psStringAppend(&query, " AND %s", whereClause);
    357367        psFree(whereClause);
     368    } else if (!all && !where2) {
     369        psError(PXTOOLS_ERR_DATA, false, "search parameters are required");
     370        return false;
    358371    }
    359372    psFree(where);
     373    if (where2) {
     374        psStringAppend(&query, " %s", where2);
     375        psFree(where2);
     376    }
    360377
    361378    if (faulted) {
     
    366383        psStringAppend(&query, " %s", "AND rawImfile.fault = 0");
    367384    }
    368 
    369     if (not_destreaked) {
    370         if (destreaked) {
    371             psError(PXTOOLS_ERR_DATA, true, "providing -not_destreaked and -destreaked makes no sense");
    372             return false;
    373         }
    374         if (magicked) {
    375             psError(PXTOOLS_ERR_DATA, true, "providing -not_destreaked and -magicked makes no sense");
    376             return false;
    377         }
    378         psStringAppend(&query, " AND rawImfile.magicked = 0");
    379     }
    380     if (destreaked) {
    381         psStringAppend(&query, " AND rawImfile.magicked != 0");
    382     }
    383 
    384385
    385386    // add the ORDER BY statement if desired
     
    884885                workdir,
    885886                label,
     887                NULL,       // data_group
     888                NULL,       // dist_group
    886889                reduction,
    887                 NULL, // expgroup
     890                NULL,       // expgroup
    888891                dvodb,
    889892                tess_id,
    890                 end_stage
     893                end_stage,
     894                NULL        // note
    891895    )) {
    892896        // rollback
  • branches/eam_branches/20090820/ippTools/src/regtoolConfig.c

    r25766 r25870  
    137137    ADD_OPT(Str,  processedimfileArgs, "-class_id",  "search by class ID",                    NULL);
    138138    ADD_OPT(Str,  processedimfileArgs, "-filter",  "search by filter",                        NULL);
     139    ADD_OPT(Str,  processedimfileArgs, "-obs_mode",  "search by obs_mod",                        NULL);
     140    ADD_OPT(Str,  processedimfileArgs, "-exp_type",  "search by exposure type",                        NULL);
    139141    ADD_OPT(Time, processedimfileArgs, "-dateobs_begin", "search for exposures by time (>=)", NULL);
    140142    ADD_OPT(Time, processedimfileArgs, "-dateobs_end", "search for exposures by time (<)", NULL);
    141     ADD_OPT(S64,  processedimfileArgs, "-magicked",    "search by magicked value",            0);
    142     ADD_OPT(Bool, processedimfileArgs, "-destreaked",   "only return imfiles that have been destreaked", false);
    143     ADD_OPT(Bool, processedimfileArgs, "-not_destreaked", "only return imfiles that have not been destreaked", false);
    144143    ADD_OPT(U64,  processedimfileArgs, "-limit",     "limit result set to N items",           0);
    145144    ADD_OPT(Bool, processedimfileArgs, "-faulted",   "only return imfiles with a fault status set", false);
     145    ADD_OPT(Bool, processedimfileArgs, "-all",   "list without search arguments", false);
    146146    ADD_OPT(Bool, processedimfileArgs, "-simple",    "use the simple output format",          false);
    147147    ADD_OPT(Bool, processedimfileArgs, "-ordered_by_date", "force output to be in DATE order", false);
     148    pxspaceAddArguments(processedimfileArgs);
     149    pxmagicAddArguments(processedimfileArgs);
    148150
    149151    // -revertprocessedimfile
  • branches/eam_branches/20090820/ippTools/src/stacktool.c

    r25766 r25870  
    109109
    110110    // required options
    111     PXOPT_LOOKUP_STR(workdir, config->args, "-workdir", true, false);
    112     PXOPT_LOOKUP_STR(label, config->args, "-label", false, false);
    113     PXOPT_LOOKUP_STR(reduction, config->args, "-reduction", false, false);
    114     PXOPT_LOOKUP_STR(dvodb, config->args, "-dvodb", false, false);
     111    PXOPT_LOOKUP_STR(workdir, config->args, "-set_workdir", true, false);
     112
     113    // optional
     114    PXOPT_LOOKUP_STR(label, config->args, "-set_label", false, false);
     115    PXOPT_LOOKUP_STR(data_group, config->args, "-set_data_group", false, false);
     116    PXOPT_LOOKUP_STR(dist_group, config->args, "-set_dist_group", false, false);
     117    PXOPT_LOOKUP_STR(reduction, config->args, "-set_reduction", false, false);
     118    PXOPT_LOOKUP_STR(dvodb, config->args, "-set_dvodb", false, false);
     119    PXOPT_LOOKUP_STR(note, config->args, "-set_note", false, false);
     120    PXOPT_LOOKUP_TIME(registered, config->args, "-set_registered", false, false);
    115121
    116122    psMetadata *where = psMetadataAlloc();
     
    160166    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
    161167    PXOPT_LOOKUP_BOOL(pretend, config->args, "-pretend", false);
    162     PXOPT_LOOKUP_TIME(registered, config->args, "-registered", false, false);
    163 
    164     if (!psListLength(where->list) &&
    165         !psMetadataLookupBool(NULL, config->args, "-all")) {
     168
     169    if (!psListLength(where->list)) {
    166170        psFree(where);
    167171        psError(PXTOOLS_ERR_DATA, false, "search parameters are required");
     
    345349            workdir,
    346350            label,
     351            data_group ? data_group : label,
     352            dist_group,
    347353            reduction,
    348354            dvodb,
     
    350356            skycell_id,
    351357            tess_id,
    352             filter);
     358            filter,
     359            note);
    353360
    354361        if (!stackRunInsertObject(config->dbh, run)) {
     
    468475
    469476    // required options
    470     PXOPT_LOOKUP_STR(workdir, config->args, "-workdir", true, false);
     477    PXOPT_LOOKUP_STR(workdir, config->args, "-set_workdir", true, false);
    471478    PXOPT_LOOKUP_STR(skycell_id, config->args, "-skycell_id", true, false);
    472479    PXOPT_LOOKUP_STR(tess_id, config->args, "-tess_id", true, false);
     
    475482    // default
    476483    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
    477     PXOPT_LOOKUP_TIME(registered, config->args, "-registered", false, false);
     484    PXOPT_LOOKUP_TIME(registered, config->args, "-set_registered", false, false);
    478485
    479486    // options
    480     PXOPT_LOOKUP_STR(label, config->args, "-label", false, false);
    481     PXOPT_LOOKUP_STR(reduction, config->args, "-reduction", false, false);
    482     PXOPT_LOOKUP_STR(dvodb, config->args, "-dvodb", false, false);
     487    PXOPT_LOOKUP_STR(label, config->args, "-set_label", false, false);
     488    PXOPT_LOOKUP_STR(data_group, config->args, "-set_data_group", false, false);
     489    PXOPT_LOOKUP_STR(dist_group, config->args, "-set_dist_group", false, false);
     490    PXOPT_LOOKUP_STR(note, config->args, "-set_note", false, false);
     491    PXOPT_LOOKUP_STR(reduction, config->args, "-set_reduction", false, false);
     492    PXOPT_LOOKUP_STR(dvodb, config->args, "-set_dvodb", false, false);
    483493
    484494    // we have to support multipe exp_ids
     
    495505        workdir,
    496506        label,
     507        data_group ? data_group : label,
     508        dist_group,
    497509        reduction,
    498510        dvodb,
     
    500512        skycell_id,
    501513        tess_id,
    502         filter);
     514        filter,
     515        note);
    503516
    504517    if (!run) {
     
    569582    PS_ASSERT_PTR_NON_NULL(config, false);
    570583
    571     PXOPT_LOOKUP_S64(stack_id, config->args, "-stack_id", true, false);
     584#ifdef notdef
     585    PXOPT_LOOKUP_S64(stack_id, config->args, "-stack_id", false, false);
    572586    PXOPT_LOOKUP_STR(state, config->args, "-state", true, false);
    573 
    574     if (state) {
     587    PXOPT_LOOKUP_STR(label, config->args, "-label", false, false);
     588#endif
     589    psMetadata *where = psMetadataAlloc();
     590    PXOPT_COPY_S64(config->args, where, "-stack_id",  "stack_id",   "==");
     591    PXOPT_COPY_STR(config->args, where, "-label",     "label",     "==");
     592    PXOPT_COPY_STR(config->args, where, "-state",     "state",     "==");
     593    if (!psListLength(where->list)) {
     594        psFree(where);
     595        psError(PXTOOLS_ERR_DATA, false, "search parameters are required");
     596        return false;
     597    }
     598
     599    psString query = psStringCopy("UPDATE stackRun");
     600
     601    // pxUpdateRun gets parameters from config->args and updates
     602    bool result = pxUpdateRun(config, where, &query, "stackRun", true);
     603
     604    psFree(query);
     605    psFree(where);
     606
     607    return result;
     608
     609#ifdef notdef
     610    // Hack-y work around to make stacktool more like the other tools, without breaking other stuff (hopefully).
     611
     612    if ((state)&&(stack_id)) {
    575613        // set detRun.state to state
    576614        return setstackRunState(config, stack_id, state);
    577615    }
    578616
    579     return true;
     617    if ((state)&&(label)) {
     618      return setstackRunStateByLabel(config, label, state);
     619    }
     620
     621    psError(PS_ERR_UNKNOWN, false, "Required options not found.");
     622    return false;
     623#endif
    580624}
    581625
     
    10061050}
    10071051
     1052#ifdef notdef
     1053static bool setstackRunStateByLabel(pxConfig *config, const char *label, const char *state)
     1054{
     1055    PS_ASSERT_PTR_NON_NULL(state, false);
     1056
     1057    // check that state is a valid string value
     1058    if (!pxIsValidState(state)) {
     1059        psError(PS_ERR_UNKNOWN, false, "invalid stackRun state: %s", state);
     1060        return false;
     1061    }
     1062
     1063    char *query = "UPDATE stackRun SET state = '%s' WHERE label = '%s'";
     1064    if (!p_psDBRunQueryF(config->dbh, query, state, label)) {
     1065        psError(PS_ERR_UNKNOWN, false,
     1066                "failed to change state for label %s", label);
     1067        return false;
     1068    }
     1069
     1070    return true;
     1071}
     1072#endif
     1073
    10081074static bool pendingcleanuprunMode(pxConfig *config)
    10091075{
     
    12311297  }
    12321298
     1299  if (!pxExportVersion(config, f)) {
     1300    psError(PS_ERR_UNKNOWN, false, "failed to write dbversion output file");
     1301    return false;
     1302  }
    12331303  psMetadata *where = psMetadataAlloc();
    12341304  PXOPT_COPY_S64(config->args, where, "-stack_id", "stack_id", "==");
     
    13171387  psMetadata *input = psMetadataConfigRead (NULL, &nFail, infile, false);
    13181388
    1319   fprintf (stdout, "---- input ----\n");
     1389#ifdef notdef
     1390  fprintf (stderr, "---- input ----\n");
    13201391  psMetadataPrint (stderr, input, 1);
    1321 
     1392#endif
     1393
     1394  if (!pxCheckImportVersion(config, input)) {
     1395      psError(PS_ERR_UNKNOWN, false, "pxCheckImportVersion failed");
     1396      return false;
     1397  }
    13221398  psMetadataItem *item = psMetadataLookup (input, "stackRun");
    13231399  psAssert (item, "entry not in input?");
  • branches/eam_branches/20090820/ippTools/src/stacktoolConfig.c

    r25766 r25870  
    4747    // -definebyquery
    4848    psMetadata *definebyqueryArgs = psMetadataAlloc();
    49     psMetadataAddStr(definebyqueryArgs, PS_LIST_TAIL, "-workdir", 0, "define workdir (required)", NULL);
    50     psMetadataAddStr(definebyqueryArgs, PS_LIST_TAIL, "-label", 0, "define label", NULL);
    51     psMetadataAddStr(definebyqueryArgs, PS_LIST_TAIL, "-reduction", 0, "define reduction", NULL);
    52     psMetadataAddStr(definebyqueryArgs, PS_LIST_TAIL, "-dvodb", 0, "define dvodb", NULL);
    53     psMetadataAddTime(definebyqueryArgs, PS_LIST_TAIL, "-registered", 0, "time detrend run was registered", now);
     49    psMetadataAddStr(definebyqueryArgs, PS_LIST_TAIL, "-set_workdir", 0, "define workdir (required)", NULL);
     50    psMetadataAddStr(definebyqueryArgs, PS_LIST_TAIL, "-set_label", 0, "define label", NULL);
     51    psMetadataAddStr(definebyqueryArgs, PS_LIST_TAIL, "-set_data_group", 0, "define data group", NULL);
     52    psMetadataAddStr(definebyqueryArgs, PS_LIST_TAIL, "-set_dist_group", 0, "define dist group", NULL);
     53    psMetadataAddStr(definebyqueryArgs, PS_LIST_TAIL, "-set_note", 0, "define note", NULL);
     54    psMetadataAddStr(definebyqueryArgs, PS_LIST_TAIL, "-set_reduction", 0, "define reduction", NULL);
     55    psMetadataAddStr(definebyqueryArgs, PS_LIST_TAIL, "-set_dvodb", 0, "define dvodb", NULL);
     56    psMetadataAddTime(definebyqueryArgs, PS_LIST_TAIL, "-set_registered", 0, "time detrend run was registered", now);
    5457    psMetadataAddStr(definebyqueryArgs, PS_LIST_TAIL, "-select_skycell_id", 0, "search for skycell_id", NULL);
    5558    psMetadataAddF32(definebyqueryArgs, PS_LIST_TAIL, "-select_good_frac_min", 0, "define min good_frac", 0.0);
     
    8487    psMetadataAddF64(definebyqueryArgs, PS_LIST_TAIL, "-select_iq_m4_max", 0, "define max iq_m4", NAN);
    8588    psMetadataAddS32(definebyqueryArgs, PS_LIST_TAIL, "-random", 0, "use this number of random elements", 0);
    86     psMetadataAddBool(definebyqueryArgs, PS_LIST_TAIL, "-all", 0, "allow everything to be queued without search terms", false);
    8789    psMetadataAddS32(definebyqueryArgs, PS_LIST_TAIL, "-min_num", 0, "minimum number of inputs", 0);
    8890    psMetadataAddS32(definebyqueryArgs, PS_LIST_TAIL, "-min_new", 0, "minimum number of new inputs", 0);
     
    9395    // -definerun
    9496    psMetadata *definerunArgs = psMetadataAlloc();
    95     psMetadataAddStr(definerunArgs, PS_LIST_TAIL, "-workdir", 0,            "define workdir (required)", NULL);
    96     psMetadataAddStr(definerunArgs, PS_LIST_TAIL, "-label", 0, "define label", NULL);
    97     psMetadataAddStr(definerunArgs, PS_LIST_TAIL, "-reduction", 0, "define reduction", NULL);
    98     psMetadataAddStr(definerunArgs, PS_LIST_TAIL, "-dvodb", 0, "define dvodb", NULL);
    99     psMetadataAddTime(definerunArgs, PS_LIST_TAIL, "-registered",  0,            "time detrend run was registered", now);
     97    psMetadataAddStr(definerunArgs, PS_LIST_TAIL, "-set_workdir", 0,            "define workdir (required)", NULL);
     98    psMetadataAddStr(definerunArgs, PS_LIST_TAIL, "-set_label", 0, "define label", NULL);
     99    psMetadataAddStr(definerunArgs, PS_LIST_TAIL, "-set_reduction", 0, "define reduction", NULL);
     100    psMetadataAddStr(definerunArgs, PS_LIST_TAIL, "-set_dvodb", 0, "define dvodb", NULL);
     101    psMetadataAddTime(definerunArgs, PS_LIST_TAIL, "-set_registered",  0,            "time detrend run was registered", now);
    100102    psMetadataAddStr(definerunArgs, PS_LIST_TAIL, "-skycell_id",  0,            "define skycell ID (required)", NULL);
    101103    psMetadataAddStr(definerunArgs, PS_LIST_TAIL, "-tess_id",  0,            "define tessellation ID (required)", NULL);
     
    106108    // -updaterun
    107109    psMetadata *updaterunArgs = psMetadataAlloc();
    108     psMetadataAddS64(updaterunArgs, PS_LIST_TAIL, "-stack_id", 0,            "define stack ID (required)", 0);
    109     psMetadataAddStr(updaterunArgs, PS_LIST_TAIL, "-state", 0,            "set state (required)", NULL);
    110 
     110    psMetadataAddS64(updaterunArgs, PS_LIST_TAIL, "-stack_id", 0,         "search by stack ID", 0);
     111    psMetadataAddStr(updaterunArgs, PS_LIST_TAIL, "-state", 0,            "search by state", NULL);
     112    psMetadataAddStr(updaterunArgs, PS_LIST_TAIL, "-label", 0,            "search by label", 0);
     113    psMetadataAddStr(updaterunArgs, PS_LIST_TAIL, "-set_label", 0,        "define new value for label", 0);
     114    psMetadataAddStr(updaterunArgs, PS_LIST_TAIL, "-set_state", 0,        "define new state", NULL);
     115    psMetadataAddStr(updaterunArgs, PS_LIST_TAIL, "-set_data_group", 0,   "define new data_group", NULL);
     116    psMetadataAddStr(updaterunArgs, PS_LIST_TAIL, "-set_dist_group", 0,   "define new dist_group", NULL);
     117    psMetadataAddStr(updaterunArgs, PS_LIST_TAIL, "-set_note", 0,         "define new note", NULL);
     118   
    111119    // -addinputskyfile
    112120    psMetadata *addinputskyfileArgs = psMetadataAlloc();
  • branches/eam_branches/20090820/ippTools/src/warptool.c

    r25766 r25870  
    5858static bool exportrunMode(pxConfig *config);
    5959static bool importrunMode(pxConfig *config);
     60static bool runstateMode(pxConfig *config);
    6061
    6162static bool parseAndInsertSkyCellMap(pxConfig *config, const char *mapfile);
     
    108109        MODECASE(WARPTOOL_MODE_EXPORTRUN,          exportrunMode);
    109110        MODECASE(WARPTOOL_MODE_IMPORTRUN,          importrunMode);
     111        MODECASE(WARPTOOL_MODE_RUNSTATE,           runstateMode);
    110112
    111113        default:
     
    139141    PXOPT_LOOKUP_STR(workdir, config->args, "-workdir", true, false); // required
    140142    PXOPT_LOOKUP_STR(label, config->args, "-label", false, false);
     143    PXOPT_LOOKUP_STR(data_group, config->args, "-data_group", false, false);
     144    PXOPT_LOOKUP_STR(dist_group, config->args, "-dist_group", false, false);
     145    PXOPT_LOOKUP_STR(note, config->args, "-note", false, false);
    141146    PXOPT_LOOKUP_STR(dvodb, config->args, "-dvodb", false, false);
    142147    PXOPT_LOOKUP_STR(tess_id, config->args, "-tess_id", true, false); // required (no default TESS)
     
    160165            "dirty",    // workdir_state
    161166            label,
     167            data_group ? data_group : label,
     168            dist_group,
    162169            dvodb,
    163170            tess_id,
     
    165172            end_stage,
    166173            registered,
    167             0       // magicked
     174            0,       // magicked
     175            note
    168176    );
    169177    if (!warpRun) {
     
    251259    PXOPT_LOOKUP_STR(workdir, config->args, "-set_workdir", false, false);
    252260    PXOPT_LOOKUP_STR(label, config->args, "-set_label", false, false);
     261    PXOPT_LOOKUP_STR(data_group, config->args, "-set_data_group", false, false);
     262    PXOPT_LOOKUP_STR(dist_group, config->args, "-set_dist_group", false, false);
    253263    PXOPT_LOOKUP_STR(dvodb, config->args, "-set_dvodb", false, false);
    254264    PXOPT_LOOKUP_STR(tess_id, config->args, "-set_tess_id", false, false);
    255265    PXOPT_LOOKUP_STR(reduction, config->args, "-set_reduction", false, false);
    256266    PXOPT_LOOKUP_STR(end_stage, config->args, "-set_end_stage", false, false);
     267    PXOPT_LOOKUP_STR(note, config->args, "-set_note", false, false);
    257268
    258269    PXOPT_LOOKUP_TIME(registered, config->args, "-registered", false, false);
     
    340351                                 workdir     ? workdir   : row->workdir,
    341352                                 label       ? label     : row->label,
     353                                 data_group  ? data_group: row->data_group,
     354                                 dist_group  ? dist_group: row->dist_group,
    342355                                 dvodb       ? dvodb     : row->dvodb,
    343356                                 tess_id     ? tess_id   : row->tess_id,
    344357                                 reduction   ? reduction : row->reduction,
    345                                  end_stage   ? end_stage : row->end_stage))
     358                                 end_stage   ? end_stage : row->end_stage,
     359                                 note))
    346360          {
    347361            psError(PS_ERR_UNKNOWN, false, "failed to trying to queue fake_id: %" PRId64, row->fake_id);
     
    371385    PXOPT_COPY_STR(config->args, where, "-label",     "warpRun.label",     "==");
    372386    PXOPT_COPY_STR(config->args, where, "-state",     "warpRun.state",     "==");
    373 
    374     if (!psListLength(where->list)
    375         && !psMetadataLookupBool(NULL, config->args, "-all")) {
     387    PXOPT_COPY_STR(config->args, where, "-data_group","warpRun.data_group",     "==");
     388    PXOPT_COPY_STR(config->args, where, "-dist_group","warpRun.dist_group",     "==");
     389
     390    if (!psListLength(where->list)) {
    376391        psFree(where);
    377         where = NULL;
    378392        psError(PXTOOLS_ERR_DATA, false, "search parameters are required");
    379393        return false;
    380394    }
    381 
    382     PXOPT_LOOKUP_STR(state, config->args, "-set_state", false, false);
    383     PXOPT_LOOKUP_STR(label, config->args, "-set_label", false, false);
    384 
    385     if ((!state) && (!label)) {
    386         psError(PXTOOLS_ERR_DATA, false, "parameters (-state or -label) are required");
    387         psFree(where);
    388         return false;
    389     }
    390 
    391     if (state) {
    392         // set warpRun.state to state
    393         if (!pxwarpRunSetStateByQuery(config, where, state)) {
    394             psFree(where);
    395             return false;
    396         }
    397     }
    398 
    399     if (label) {
    400         // set chipRun.label to label
    401         if (!pxwarpRunSetLabelByQuery(config, where, label)) {
    402             psFree(where);
    403             return false;
    404         }
    405     }
    406 
     395   
     396    psString query = psStringCopy("UPDATE warpRun JOIN fakeRun USING(fake_id) JOIN camRun USING(cam_id) JOIN chipRun USING(chip_id) JOIN rawExp USING(exp_id)");
     397
     398    // pxUpdateRun gets parameters from config->args and updates
     399    bool result = pxUpdateRun(config, where, &query, "warpRun", true);
     400
     401    psFree(query);
    407402    psFree(where);
    408403
    409     return true;
    410 }
    411 
     404    return result;
     405}
    412406
    413407static bool expMode(pxConfig *config)
     
    12041198    pxAddLabelSearchArgs (config, where, "-label",   "warpRun.label", "LIKE");
    12051199
    1206     PXOPT_LOOKUP_U64(magicked, config->args, "-magicked", false, false);
    1207     PXOPT_LOOKUP_BOOL(destreaked, config->args,     "-destreaked", false);
    1208     PXOPT_LOOKUP_BOOL(not_destreaked, config->args, "-not_destreaked", false);
    1209 
    12101200    PXOPT_LOOKUP_BOOL(all, config->args, "-all", false);
    12111201
     
    12201210    }
    12211211
     1212    // generate where strings for arguments that require extra processing
     1213    // beyond PXOPT_COPY*
     1214    psString where2 = NULL;
     1215    if (!pxmagicAddWhere(config, &where2, "warpSkyfile")) {
     1216        psError(PXTOOLS_ERR_DATA, false, "pxMagicAddWhere failed");
     1217        return false;
     1218    }
     1219    if (!pxspaceAddWhere(config, &where2, "rawExp")) {
     1220        psError(PXTOOLS_ERR_DATA, false, "pxSpaceAddWhere failed");
     1221        return false;
     1222    }
     1223
    12221224    if (psListLength(where->list)) {
    12231225        psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
    12241226        psStringAppend(&query, " AND %s", whereClause);
    12251227        psFree(whereClause);
    1226     } else if (!all) {
     1228    } else if (!all && !where2) {
    12271229        psError(PXTOOLS_ERR_DATA, true, "search parameters or -all are required");
    12281230        return false;
     
    12301232    psFree(where);
    12311233
    1232     if (not_destreaked) {
    1233         if (destreaked) {
    1234             psError(PXTOOLS_ERR_DATA, true, "providing -not_destreaked and -destreaked makes no sense");
    1235             return false;
    1236         }
    1237         if (magicked) {
    1238             psError(PXTOOLS_ERR_DATA, true, "providing -not_destreaked and -magicked makes no sense");
    1239             return false;
    1240         }
    1241         psStringAppend(&query, " AND warpSkyfile.magicked = 0");
    1242     }
    1243     if (destreaked) {
    1244         psStringAppend(&query, " AND warpSkyfile.magicked != 0");
     1234    if (where2) {
     1235        psStringAppend(&query, " %s", where2);
    12451236    }
    12461237
     
    17121703    PXOPT_LOOKUP_STR(skycell_id, config->args, "-skycell_id", true, false);
    17131704    PXOPT_LOOKUP_S16(fault, config->args, "-fault", false, false);
    1714 
    1715     psString query = pxDataGet("warptool_updateskyfile.sql");
    1716 
    1717     if (!p_psDBRunQueryF(config->dbh, query, fault, warp_id, skycell_id)) {
    1718         psError(PS_ERR_UNKNOWN, false, "database error");
    1719         return false;
    1720     }
    1721     psFree(query);
     1705    PXOPT_LOOKUP_STR(state, config->args, "-set_state", false, false);
     1706
     1707    if (!state) {
     1708      psString query = pxDataGet("warptool_updateskyfile.sql");
     1709     
     1710      if (!p_psDBRunQueryF(config->dbh, query, fault, warp_id, skycell_id)) {
     1711        psError(PS_ERR_UNKNOWN, false, "database error");
     1712        return false;
     1713      }
     1714      psFree(query);
     1715    }
     1716    else {
     1717      if (strcmp(state,"error_cleaned") == 0) {
     1718        change_skyfile_data_state(config,"error_cleaned","goto_cleaned");
     1719      }
     1720      else if (strcmp(state, "error_scrubbed") == 0) {
     1721        change_skyfile_data_state(config,"error_scrubbed","goto_scrubbed");
     1722      }
     1723      else if (strcmp(state, "error_purged") == 0) {
     1724        change_skyfile_data_state(config,"error_purged","goto_purged");
     1725      }
     1726      else {
     1727        psError(PS_ERR_UNKNOWN, false, "unhandled state given");
     1728        return(false);
     1729      }
     1730    }
    17221731
    17231732    return true;
     
    17441753    }
    17451754
     1755    if (!pxExportVersion(config, f)) {
     1756        psError(PS_ERR_UNKNOWN, false, "failed to write dbversion output file");
     1757        return false;
     1758    }
    17461759    psMetadata *where = psMetadataAlloc();
    17471760    PXOPT_COPY_S64(config->args, where, "-warp_id", "warp_id", "==");
     
    18361849  psMetadata *input = psMetadataConfigRead (NULL, &nFail, infile, false);
    18371850
    1838   fprintf (stdout, "---- input ----\n");
     1851#ifdef notdef
     1852  fprintf (stderr, "---- input ----\n");
    18391853  psMetadataPrint (stderr, input, 1);
     1854#endif
     1855
     1856  if (!pxCheckImportVersion(config, input)) {
     1857      psError(PS_ERR_UNKNOWN, false, "pxCheckImportVersion failed");
     1858      return false;
     1859  }
    18401860
    18411861  psMetadataItem *item = psMetadataLookup (input, "warpRun");
     
    19001920  return true;
    19011921}
     1922
     1923static bool runstateMode(pxConfig *config)
     1924{
     1925    PS_ASSERT_PTR_NON_NULL(config, false);
     1926
     1927    psMetadata *where = psMetadataAlloc();
     1928    PXOPT_COPY_S64(config->args, where, "-warp_id",    "warpRun.warp_id", "==");
     1929    PXOPT_COPY_S64(config->args, where, "-exp_id",     "rawExp.exp_id", "==");
     1930    PXOPT_COPY_STR(config->args, where, "-exp_name",   "rawExp.exp_name", "==");
     1931    pxAddLabelSearchArgs (config, where, "-label",     "warpRun.label", "LIKE");
     1932
     1933//    PXOPT_LOOKUP_BOOL(all, config->args, "-all", false);
     1934    PXOPT_LOOKUP_BOOL(no_magic, config->args, "-no_magic", false);
     1935
     1936    PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
     1937    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
     1938
     1939    psString query = pxDataGet("warptool_runstate.sql");
     1940    if (!query) {
     1941        psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
     1942        return false;
     1943    }
     1944
     1945    if (psListLength(where->list)) {
     1946        psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
     1947        psStringAppend(&query, " WHERE %s", whereClause);
     1948        psFree(whereClause);
     1949    } else {
     1950        psError(PXTOOLS_ERR_DATA, true, "search parameters or -all are required");
     1951        return false;
     1952    }
     1953    psFree(where);
     1954
     1955    // treat limit == 0 as "no limit"
     1956    if (limit) {
     1957        psString limitString = psDBGenerateLimitSQL(limit);
     1958        psStringAppend(&query, " %s", limitString);
     1959        psFree(limitString);
     1960    }
     1961
     1962    if (!p_psDBRunQuery(config->dbh, query)) {
     1963        psError(PS_ERR_UNKNOWN, false, "database error");
     1964        psFree(query);
     1965        return false;
     1966    }
     1967    psFree(query);
     1968
     1969    psArray *output = p_psDBFetchResult(config->dbh);
     1970    if (!output) {
     1971        psErrorCode err = psErrorCodeLast();
     1972        switch (err) {
     1973            case PS_ERR_DB_CLIENT:
     1974                psError(PXTOOLS_ERR_SYS, false, "database error");
     1975            case PS_ERR_DB_SERVER:
     1976                psError(PXTOOLS_ERR_PROG, false, "database error");
     1977            default:
     1978                psError(PXTOOLS_ERR_PROG, false, "unknown error");
     1979        }
     1980
     1981        return false;
     1982    }
     1983    if (!psArrayLength(output)) {
     1984        psTrace("warptool", PS_LOG_INFO, "no rows found");
     1985        psFree(output);
     1986        return true;
     1987    }
     1988
     1989    if (psArrayLength(output)) {
     1990        // negative simple so the default is true
     1991        if (!ippdbPrintMetadatas(stdout, output, "warpRunState", !simple)) {
     1992            psError(PS_ERR_UNKNOWN, false, "failed to print array");
     1993            psFree(output);
     1994            return false;
     1995        }
     1996    }
     1997
     1998    psFree(output);
     1999
     2000    return true;
     2001}
  • branches/eam_branches/20090820/ippTools/src/warptool.h

    r25766 r25870  
    5353    WARPTOOL_MODE_UPDATESKYFILE,
    5454    WARPTOOL_MODE_EXPORTRUN,
    55     WARPTOOL_MODE_IMPORTRUN
     55    WARPTOOL_MODE_IMPORTRUN,
     56    WARPTOOL_MODE_RUNSTATE,
    5657} warptoolMode;
    5758
  • branches/eam_branches/20090820/ippTools/src/warptoolConfig.c

    r25766 r25870  
    100100    psMetadataAddStr(definebyqueryArgs, PS_LIST_TAIL, "-set_reduction",      0, "define reduction class", NULL);
    101101    psMetadataAddStr(definebyqueryArgs, PS_LIST_TAIL, "-set_end_stage",      0, "define end stage", NULL);
    102     psMetadataAddBool(definebyqueryArgs, PS_LIST_TAIL, "-all",               0, "allow everything to be queued without search terms", false);
     102    psMetadataAddStr(definebyqueryArgs, PS_LIST_TAIL, "-set_data_group",     0, "define data group", NULL);
     103    psMetadataAddStr(definebyqueryArgs, PS_LIST_TAIL, "-set_dist_group",     0, "define dist group", NULL);
     104    psMetadataAddStr(definebyqueryArgs, PS_LIST_TAIL, "-set_note",           0, "define note", NULL);
    103105
    104106    psMetadataAddTime(definebyqueryArgs, PS_LIST_TAIL, "-registered",  0,            "time detrend run was registered", now);
     
    117119    psMetadataAddTime(definerunArgs, PS_LIST_TAIL, "-registered",  0,            "time detrend run was registered", now);
    118120    psMetadataAddBool(definerunArgs, PS_LIST_TAIL, "-simple",  0,            "use the simple output format", false);
     121    psMetadataAddStr(definerunArgs, PS_LIST_TAIL, "-set_end_stage",      0, "define end stage", NULL);
     122    psMetadataAddStr(definerunArgs, PS_LIST_TAIL, "-set_data_group",     0, "define data group", NULL);
     123    psMetadataAddStr(definerunArgs, PS_LIST_TAIL, "-set_dist_group",     0, "define dist group", NULL);
     124    psMetadataAddStr(definerunArgs, PS_LIST_TAIL, "-set_note",           0, "define note", NULL);
    119125
    120126    // -updaterun
     
    128134    psMetadataAddStr(updaterunArgs, PS_LIST_TAIL, "-state", 0,      "search by warpRun state", NULL);
    129135    psMetadataAddStr(updaterunArgs, PS_LIST_TAIL, "-label", 0,      "search by warpRun label", NULL);
    130     psMetadataAddBool(updaterunArgs, PS_LIST_TAIL, "-all",  0,      "allow everything to be queued without search terms", false);
    131     psMetadataAddStr(updaterunArgs, PS_LIST_TAIL, "-set_state", 0,  "set state", NULL);
    132     psMetadataAddStr(updaterunArgs, PS_LIST_TAIL, "-set_label", 0,  "set label", NULL);
    133 
     136    psMetadataAddStr(updaterunArgs, PS_LIST_TAIL, "-data_group", 0, "search by warpRun data_group", NULL);
     137    psMetadataAddStr(updaterunArgs, PS_LIST_TAIL, "-dist_group", 0, "search by warpRun dist_group", NULL);
     138
     139    psMetadataAddStr(updaterunArgs, PS_LIST_TAIL, "-set_state", 0,        "define new state", NULL);
     140    psMetadataAddStr(updaterunArgs, PS_LIST_TAIL, "-set_label", 0,        "define new value for label", 0);
     141    psMetadataAddStr(updaterunArgs, PS_LIST_TAIL, "-set_data_group", 0,   "define new data_group", NULL);
     142    psMetadataAddStr(updaterunArgs, PS_LIST_TAIL, "-set_dist_group", 0,   "define new dist_group", NULL);
     143    psMetadataAddStr(updaterunArgs, PS_LIST_TAIL, "-set_note", 0,         "define new note", NULL);
    134144    // -exp
    135145    psMetadata *expArgs = psMetadataAlloc();
     
    218228    psMetadataAddTime(warpedArgs, PS_LIST_TAIL, "-dateobs_end", 0,      "search for exposures by time (<=)", NULL);
    219229    psMetadataAddStr(warpedArgs, PS_LIST_TAIL,  "-filter", 0,           "search for exposures by filter", NULL);
    220     psMetadataAddBool(warpedArgs, PS_LIST_TAIL, "-destreaked",  0,      "search for destreaked images", false);
    221     psMetadataAddBool(warpedArgs, PS_LIST_TAIL, "-not_destreaked",  0,  "search for images that have not been destreaked", false);
    222     psMetadataAddS64(warpedArgs, PS_LIST_TAIL,  "-magicked", 0,         "search by magicked value", 0);
    223230    psMetadataAddS16(warpedArgs, PS_LIST_TAIL,  "-fault",  0,           "search by fault code", 0);
    224231    psMetadataAddStr(warpedArgs, PS_LIST_TAIL,  "-label",  PS_META_DUPLICATE_OK, "search by warpRun label", NULL);
     232    // add magic related arguments
     233    pxmagicAddArguments(warpedArgs);
     234    // add arguments for spatial search
     235    pxspaceAddArguments(warpedArgs);
    225236
    226237    psMetadataAddBool(warpedArgs, PS_LIST_TAIL, "-all",  0,             "search without arguments", false);
     
    304315    psMetadataAddStr(updateskyfileArgs, PS_LIST_TAIL, "-skycell_id", 0, "skycell ID to update", NULL);
    305316    psMetadataAddS16(updateskyfileArgs, PS_LIST_TAIL, "-fault",  0,      "new fault code", 0);
    306 
     317    psMetadataAddStr(updateskyfileArgs, PS_LIST_TAIL, "-set_state", 0,   "set state", 0);
     318   
    307319    // -exportrun
    308320    psMetadata *exportrunArgs = psMetadataAlloc();
     
    315327    psMetadata *importrunArgs = psMetadataAlloc();
    316328    psMetadataAddStr(importrunArgs, PS_LIST_TAIL, "-infile",  0,          "import from this file (required)", NULL);
     329
     330    // -runstate
     331    psMetadata *runstateArgs = psMetadataAlloc();
     332    psMetadataAddS64(runstateArgs, PS_LIST_TAIL, "-warp_id", 0,           "search by warptool ID", 0);
     333//    psMetadataAddStr(runstateArgs, PS_LIST_TAIL, "-tess_id",  0,          "search by tessellation ID", NULL);
     334    psMetadataAddS64(runstateArgs, PS_LIST_TAIL, "-exp_id", 0,            "search by exposure tag", 0);
     335    psMetadataAddStr(runstateArgs, PS_LIST_TAIL, "-exp_name", 0,          "search by exposure tag", 0);
     336    psMetadataAddStr(runstateArgs, PS_LIST_TAIL,  "-label",  PS_META_DUPLICATE_OK, "search by warpRun label", NULL);
     337    psMetadataAddBool(runstateArgs, PS_LIST_TAIL, "-no_magic",  0,        "magic is not necessary for result", false);
     338
     339    psMetadataAddU64(runstateArgs, PS_LIST_TAIL, "-limit",  0,            "limit result set to N items", 0);
     340    psMetadataAddBool(runstateArgs, PS_LIST_TAIL, "-simple",  0,          "use the simple output format", false);
    317341
    318342
     
    334358    PXOPT_ADD_MODE("-advancerun",      "", WARPTOOL_MODE_ADVANCERUN,     advancerunArgs);
    335359    PXOPT_ADD_MODE("-warped",          "", WARPTOOL_MODE_WARPED,         warpedArgs);
     360    PXOPT_ADD_MODE("-runstate",        "", WARPTOOL_MODE_RUNSTATE,       runstateArgs);
    336361    PXOPT_ADD_MODE("-revertwarped",    "", WARPTOOL_MODE_REVERTWARPED,   revertwarpedArgs);
    337362    PXOPT_ADD_MODE("-block",                 "set a label block",                    WARPTOOL_MODE_BLOCK,          blockArgs);
  • branches/eam_branches/20090820/ippconfig/gpc1/ppImage.config

    r24919 r25870  
    1717# use the deburned image instead of the raw, if it exists
    1818USE.DEBURNED.IMAGE      BOOL    TRUE           # use burntool-repaired image?
     19USE.BEST.BURNTOOL       BOOL    TRUE           # require the best burntooled data
     20MASK.BURNTOOL           BOOL    FALSE           # Mask potential burntool trails
    1921TILTYSTREAK.APPLY       BOOL    FALSE          # apply the 'tiltystreak' tool
    2022NOISEMAP                BOOL    FALSE          # Apply read noise map
     
    151153  FLAT             BOOL    TRUE            # Flat-field normalisation
    152154  MASK             BOOL    TRUE            # Mask bad pixels
     155  MASK.BURNTOOL      BOOL    TRUE            # Mask potential burntool trails
    153156  PATTERN          BOOL    TRUE            # Subtract pattern noise
    154157  FRINGE           BOOL    FALSE           # Fringe subtraction
     
    177180  FLAT               BOOL    TRUE            # Flat-field normalisation
    178181  MASK               BOOL    TRUE            # Mask bad pixels
     182  MASK.BURNTOOL      BOOL    TRUE            # Mask potential burntool trails
    179183  FRINGE             BOOL    FALSE           # Fringe subtraction
    180184  BIN1.FITS          BOOL    TRUE            # Save 1st binned chip image?
     
    204208  FLAT               BOOL    TRUE            # Flat-field normalisation
    205209  MASK               BOOL    TRUE            # Mask bad pixels
     210  MASK.BURNTOOL      BOOL    TRUE            # Mask potential burntool trails
    206211  FRINGE             BOOL    FALSE           # Fringe subtraction
    207212  BIN1.FITS          BOOL    TRUE            # Save 1st binned chip image?
     
    329334  FLAT             BOOL    TRUE            # Flat-field normalisation
    330335  MASK             BOOL    TRUE            # Mask bad pixels
     336  MASK.BURNTOOL      BOOL    TRUE            # Mask potential burntool trails
    331337  FRINGE           BOOL    FALSE           # Fringe subtraction
    332338  BIN1.FITS        BOOL    TRUE            # Save 1st binned chip image?
     
    949955  FLAT               BOOL    TRUE            # Flat-field normalisation
    950956  MASK               BOOL    TRUE            # Mask bad pixels
     957  MASK.BURNTOOL      BOOL    TRUE            # Mask potential burntool trails
    951958  FRINGE             BOOL    FALSE           # Fringe subtraction
    952959  BIN1.FITS          BOOL    TRUE            # Save 1st binned chip image?
  • branches/eam_branches/20090820/ippconfig/megacam/ppImage.config

    r24893 r25870  
    2121# megacam needs fringe subtraction
    2222FRINGE          BOOL    TRUE            # Fringe subtraction
     23
     24USE.DEBURNED.IMAGE      BOOL    FALSE  # Skip burntool
    2325
    2426# this table lists extra constraints which should be applied when
  • branches/eam_branches/20090820/ippconfig/recipes/addstar.config

    r24141 r25870  
    11# configurable options for addstar
     2# the IMAGES.ONLY option has been deprecated: set it when defining an addstar run with addtool -image-only
     3# it is not clear we still need an addstar recipe.
    24
    3 IMAGES.ONLY  BOOL  TRUE
     5# IMAGES.ONLY  BOOL  TRUE
    46
    5 FLATCORR METADATA
    6     # IMAGES.ONLY  BOOL  FALSE
    7     IMAGES.ONLY  BOOL  TRUE
    8 END
    9 
    10 ADDSTAR METADATA
    11     IMAGES.ONLY  BOOL  TRUE
    12 END
     7# FLATCORR METADATA
     8#     # IMAGES.ONLY  BOOL  FALSE
     9#     IMAGES.ONLY  BOOL  TRUE
     10# END
     11#
     12# ADDSTAR       METADATA
     13#     IMAGES.ONLY  BOOL  TRUE
     14# END
  • branches/eam_branches/20090820/ippconfig/recipes/filerules-split.mdc

    r25766 r25870  
    228228PPSTAMP.OUTPUT.MASK     OUTPUT {OUTPUT}.mk.fits                  MASK      COMP_MASK  FPA        TRUE      NONE
    229229PPSTAMP.OUTPUT.VARIANCE OUTPUT {OUTPUT}.wt.fits                  VARIANCE  COMP_WT    FPA        TRUE      NONE
     230# mosaic image used for making stamps of raw images. Not saved.
    230231PPSTAMP.CHIP            OUTPUT {OUTPUT}.ch.fits                  IMAGE     NONE       CHIP       FALSE     MEF
     232PPSTAMP.OUTPUT.JPEG1    OUTPUT {OUTPUT}.jpg                      JPEG      NONE       FPA        TRUE      NONE
    231233                                                                                                       
    232234PPSIM.OUTPUT            OUTPUT {OUTPUT}.{CHIP.NAME}.fits         IMAGE     NONE       CHIP       TRUE      SPLIT
  • branches/eam_branches/20090820/ippconfig/recipes/ppImage.config

    r25766 r25870  
    2626CHECK.CTE          BOOL    FALSE           # measure CTE errors?
    2727USE.DEBURNED.IMAGE BOOL    FALSE           # use burntool-repaired image?
    28 USE.BEST.BURNTOOL  BOOL    TRUE            # require the best burntooled data
     28USE.BEST.BURNTOOL  BOOL    FALSE           # require the best burntooled data
    2929TILTYSTREAK.APPLY  BOOL    FALSE           # apply the 'tiltystreak' tool
    3030
     
    5858
    5959# Which regions identified by burntool to mask. 0x01 : only unfit trails, 0x02 "up" trails, 0x04 "down" trails
    60 BURNTOOL.TRAILS     U16 0x01
     60BURNTOOL.TRAILS     U16 0x07
    6161
    6262# Non-linearity correction
     
    150150  FLAT               BOOL    TRUE            # Flat-field normalisation
    151151  MASK               BOOL    TRUE            # Mask bad pixels
    152   MASK.BURNTOOL      BOOL    TRUE            # Mask potential burntool trails
    153152  FRINGE             BOOL    TRUE            # Fringe subtraction
    154153  BIN1.FITS          BOOL    TRUE            # Save 1st binned chip image?
     
    174173  FLAT               BOOL    TRUE            # Flat-field normalisation
    175174  MASK               BOOL    TRUE            # Mask bad pixels
    176   MASK.BURNTOOL      BOOL    TRUE            # Mask potential burntool trails
    177175  FRINGE             BOOL    TRUE            # Fringe subtraction
    178176  BIN1.FITS          BOOL    TRUE            # Save 1st binned chip image?
     
    198196  FLAT               BOOL    TRUE            # Flat-field normalisation
    199197  MASK               BOOL    TRUE            # Mask bad pixels
    200   MASK.BURNTOOL      BOOL    TRUE            # Mask potential burntool trails
    201198  FRINGE             BOOL    TRUE            # Fringe subtraction
    202199  BIN1.FITS          BOOL    TRUE            # Save 1st binned chip image?
     
    565562  FLAT               BOOL    TRUE            # Flat-field normalisation
    566563  MASK               BOOL    TRUE            # Mask bad pixels
    567   MASK.BURNTOOL      BOOL    TRUE            # Mask potential burntool trails
    568564  FRINGE             BOOL    TRUE            # Fringe subtraction
    569565  BIN1.FITS          BOOL    TRUE            # Save 1st binned chip image?
     
    17261722  FLAT               BOOL    TRUE            # Flat-field normalisation
    17271723  MASK               BOOL    TRUE            # Mask bad pixels
    1728   MASK.BURNTOOL      BOOL    TRUE            # Mask potential burntool trails
    17291724  PATTERN            BOOL    TRUE            # Subtract pattern noise?
    17301725  FRINGE             BOOL    TRUE            # Fringe subtraction
  • branches/eam_branches/20090820/ippconfig/recipes/psphot.config

    r25766 r25870  
    300300        BACKGROUND.YBIN         S32     2400
    301301        IMSTATS_NPIX            S32     50000
    302 END
     302        BREAK_POINT             STR   ENSEMBLE     
     303        PEAKS_NMAX              S32   1000            # on first pass, only keep NMAX peaks (0 == all)
     304END
  • branches/eam_branches/20090820/ippconfig/sdssmosaic/addstar.config

    r21045 r25870  
    1 IMAGES.ONLY  BOOL  FALSE
    2 
    3 ADDSTAR METADATA
    4     IMAGES.ONLY  BOOL  FALSE
    5 END
     1# IMAGES.ONLY  BOOL  FALSE
     2#
     3# ADDSTAR       METADATA
     4#     IMAGES.ONLY  BOOL  FALSE
     5# END
  • branches/eam_branches/20090820/ippconfig/simtest/ppStack.config

    r23976 r25870  
    11PSF.MODEL       STR     PS_MODEL_GAUSS  # Model for PSF generation
    22DECONV.LIMIT    F32     1.5             # Deconvolution fraction for rejecting entire image
     3IMAGE.REJ       F32     0.3             # Rejected pixel fraction threshold for rejecting entire image
  • branches/eam_branches/20090820/ppImage/src/ppImageLoop.c

    r25164 r25870  
    5151        }
    5252
    53         // crosstalk measurement needs to be done on the entire chip at once, and before
    54         // signal levels are modified by the detrending.  If crosstalk measurement is
    55         // requested, the read-level for the images is set to CHIP.
    56         if (!ppImageMeasureCrosstalk(config, options, view)) {
    57           ESCAPE("Unable to perform crosstalk correction");
    58         }
    59 
    60         // crosstalk correction needs to be done on the entire chip at once, and before
    61         // signal levels are modified by the detrending.  If crosstalk correction is
    62         // requested, the read-level for the images is set to CHIP.
    63         if (!ppImageCorrectCrosstalk(config, options, view)) {
    64           ESCAPE("Unable to perform crosstalk correction");
    65         }
     53        // crosstalk measurement needs to be done on the entire chip at once, and before
     54        // signal levels are modified by the detrending.  If crosstalk measurement is
     55        // requested, the read-level for the images is set to CHIP.
     56        if (!ppImageMeasureCrosstalk(config, options, view)) {
     57          ESCAPE("Unable to perform crosstalk correction");
     58        }
     59
     60        // crosstalk correction needs to be done on the entire chip at once, and before
     61        // signal levels are modified by the detrending.  If crosstalk correction is
     62        // requested, the read-level for the images is set to CHIP.
     63        if (!ppImageCorrectCrosstalk(config, options, view)) {
     64          ESCAPE("Unable to perform crosstalk correction");
     65        }
    6666
    6767        psTimerStart(TIMER_DETREND);
     
    259259    psString dump_file = psMetadataLookupStr(&status, config->arguments, "DUMP_CONFIG");
    260260    if (dump_file) {
    261         pmConfigDump(config, dump_file);
     261        if (!pmConfigDump(config, dump_file)) {
     262            ESCAPE("Unable to dump configuration.");
     263        }
    262264    }
    263265
  • branches/eam_branches/20090820/ppImage/src/ppImageSetMaskBits.c

    r25766 r25870  
    3838    psAssert (options->lowMask, "low mask not set");
    3939
    40     // mask for suspect regions due to burntool
    41     options->burntoolMask = pmConfigMaskGet("BURNTOOL",config);
    42     psAssert (options->burntoolMask, "burntool mask not set");
     40    // mask for suspect regions due to burntool if we need to.
     41    if (options->doMaskBurntool) {
     42      options->burntoolMask = pmConfigMaskGet("BURNTOOL",config);
     43      psAssert (options->burntoolMask, "burntool mask not set");
     44    }
    4345   
    4446    // save MASK and MARK on the PSPHOT recipe
  • branches/eam_branches/20090820/ppMerge/src/ppMergeLoop.c

    r24908 r25870  
    104104            goto ERROR;
    105105        }
    106         // the zeros vector is passed to pmReadoutCombine for each set of inputs per cell
    107         zeros = psVectorAlloc(zeroSet->numRows, PS_TYPE_F32);
     106        // the zeros vector is passed to pmReadoutCombine for each set of inputs per cell
     107        zeros = psVectorAlloc(zeroSet->numRows, PS_TYPE_F32);
    108108        // Flow through
    109109      case PPMERGE_TYPE_FLAT:
     
    150150        goto ERROR;
    151151    }
     152
     153
     154    // Average concepts across inputs
     155    {
     156        psList *inFPAs = psListAlloc(NULL); ///< List of FPAs
     157        for (int i = 0; i < numFiles; i++) {
     158            pmFPAfile *input = inputs->data[i]; ///< Input file
     159            psListAdd(inFPAs, PS_LIST_TAIL, input->fpa);
     160        }
     161        if (!pmConceptsAverageFPAs(output->fpa, inFPAs)) {
     162            psError(PS_ERR_UNKNOWN, false, "Unable to average FPA concepts.");
     163            psFree(inFPAs);
     164            goto ERROR;
     165        }
     166        psFree(inFPAs);
     167    }
     168
    152169    pmChip *outChip;                    ///< Chip of interest
    153170    while ((outChip = pmFPAviewNextChip(view, outFPA, 1))) {
     
    158175            goto ERROR;
    159176        }
     177
     178        // Average concepts across inputs
     179        {
     180            psList *inChips = psListAlloc(NULL);
     181            for (int i=0; i < numFiles; i++) {
     182                pmChip *chip = pmFPAviewThisChip(view, ((pmFPAfile *)inputs->data[i])->fpa);
     183                psListAdd(inChips, PS_LIST_TAIL, chip);
     184            }
     185            if (!pmConceptsAverageChips(outChip, inChips, true)) {
     186                psError(PS_ERR_UNKNOWN, false, "Unable to average Chip concepts.");
     187                psFree(inChips);
     188                goto ERROR;
     189            }
     190            psFree(inChips);
     191        }
     192
    160193        pmCell *outCell;                ///< Cell of interest
    161194
    162         // XXX TEST : force a single loop
     195        // XXX TEST : force a single loop
    163196        // outCell = pmFPAviewNextCell(view, outFPA, 1); {
    164197
    165198        while ((outCell = pmFPAviewNextCell(view, outFPA, 1))) {
    166             if (!outCell->process || !outCell->file_exists) {
    167                 continue;
    168             }
     199            if (!outCell->process || !outCell->file_exists) {
     200                continue;
     201            }
    169202            if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) {
    170203                goto ERROR;
     
    206239            }
    207240
    208             if (zeroSet) {
    209               for (int i = 0; i < zeroSet->numRows; i++) {
    210                 zeros->data.F32[i] = zeroSet->data.F32[i][cellNum];
    211               }
    212             }
    213 
    214             int rows = psMetadataLookupS32(NULL, config->arguments, "ROWS"); // Number of rows to read per chunk
    215             if (!rows && nThreads) {
    216               psError(PS_ERR_UNKNOWN, false, "Invalid combination of threads > 0 and ROWS == 0 (ie, multiple threads working on the full array...)");
    217               goto ERROR;
    218             }
     241            if (zeroSet) {
     242              for (int i = 0; i < zeroSet->numRows; i++) {
     243                zeros->data.F32[i] = zeroSet->data.F32[i][cellNum];
     244              }
     245            }
     246
     247            int rows = psMetadataLookupS32(NULL, config->arguments, "ROWS"); // Number of rows to read per chunk
     248            if (!rows && nThreads) {
     249              psError(PS_ERR_UNKNOWN, false, "Invalid combination of threads > 0 and ROWS == 0 (ie, multiple threads working on the full array...)");
     250              goto ERROR;
     251            }
    219252
    220253            ppMergeFileGroup *fileGroup = NULL;
     
    227260                    pmFPAfile *input = pmFPAfileSelectSingle(config->files, "PPMERGE.INPUT", j);
    228261                    pmCell *inCell = pmFPAviewThisCell(view, input->fpa); ///< Input cell
    229                     pmReadout *readout = pmReadoutAlloc(inCell);
    230                     readout->process = true; // until proven otherwise, attempt to process this readout
     262                    pmReadout *readout = pmReadoutAlloc(inCell);
     263                    readout->process = true; // until proven otherwise, attempt to process this readout
    231264                    readouts->data[j] = readout;
    232265                }
     
    361394
    362395            psFree(fileGroups);
    363             psFree(zeros);
     396            psFree(zeros);
    364397
    365398            // XXX eventually need to keep both the shutter and the pattern, as we do with dark
     
    424457            // Put the new readout into the cell after the existing readouts.
    425458            if (type == PPMERGE_TYPE_FRINGE && outRO) {
    426                 if (fringeSmooth) {
    427                     if (outRO->mask) {
    428                         psImage *smoothed = psImageSmoothMask (NULL, outRO->image, outRO->mask, maskVal, fringeSmoothSigma, 3, 0.2);
    429                         psFree (outRO->image);
    430                         outRO->image = smoothed;
    431                     } else {
    432                         psImageSmooth (outRO->image, fringeSmoothSigma, 3);
    433                     }
    434                 }
     459                if (fringeSmooth) {
     460                    if (outRO->mask) {
     461                        psImage *smoothed = psImageSmoothMask (NULL, outRO->image, outRO->mask, maskVal, fringeSmoothSigma, 3, 0.2);
     462                        psFree (outRO->image);
     463                        outRO->image = smoothed;
     464                    } else {
     465                        psImageSmooth (outRO->image, fringeSmoothSigma, 3);
     466                    }
     467                }
    435468
    436469                pmFringeRegions *regions = pmFringeRegionsAlloc(fringeNum, fringeSize, fringeSize, fringeSmoothX, fringeSmoothY);
     
    447480
    448481                // XXX replaced this : pmFringesFormat(outCell, NULL, fringes);
    449                 if (!psMetadataAdd(outCell->analysis, PS_LIST_TAIL, "FRINGE.MEASUREMENTS", PS_DATA_ARRAY, "Fringes", fringes)) {
    450                     psError(PS_ERR_UNKNOWN, false, "Unable to add fringe to analysis metadata\n");
    451                     goto ERROR;
    452                 }
     482                if (!psMetadataAdd(outCell->analysis, PS_LIST_TAIL, "FRINGE.MEASUREMENTS", PS_DATA_ARRAY, "Fringes", fringes)) {
     483                    psError(PS_ERR_UNKNOWN, false, "Unable to add fringe to analysis metadata\n");
     484                    goto ERROR;
     485                }
    453486                psFree(fringes);        // Drop reference
    454487            }
     
    472505                psImageMaskType cteMaskValue = pmConfigMaskGet(cteMaskName, config);
    473506
    474                 if (0) {
    475                   psFits *fits = NULL;
    476                   fits = psFitsOpen ("combine.fits", "w");
    477                   psFitsWriteImage (fits, NULL, outRO->image, 0, NULL);
    478                   psFitsClose (fits);
    479 
    480                   fits = psFitsOpen ("inmask.fits", "w");
    481                   psFitsWriteImage (fits, NULL, outRO->mask, 0, NULL);
    482                   psFitsClose (fits);
    483                 }
     507                if (0) {
     508                  psFits *fits = NULL;
     509                  fits = psFitsOpen ("combine.fits", "w");
     510                  psFitsWriteImage (fits, NULL, outRO->image, 0, NULL);
     511                  psFitsClose (fits);
     512
     513                  fits = psFitsOpen ("inmask.fits", "w");
     514                  psFitsWriteImage (fits, NULL, outRO->mask, 0, NULL);
     515                  psFitsClose (fits);
     516                }
    484517
    485518                psF32 **outputImage = outRO->image->data.F32;
     
    493526                }
    494527
    495                 if (0) {
    496                   psFits *fits = NULL;
    497                   fits = psFitsOpen ("otmask.fits", "w");
    498                   psFitsWriteImage (fits, NULL, outRO->mask, 0, NULL);
    499                   psFitsClose (fits);
    500                 }
     528                if (0) {
     529                  psFits *fits = NULL;
     530                  fits = psFitsOpen ("otmask.fits", "w");
     531                  psFitsWriteImage (fits, NULL, outRO->mask, 0, NULL);
     532                  psFitsClose (fits);
     533                }
    501534
    502535            }
     
    510543        }
    511544
    512         if (outChip->data_exists) {
    513             psList *inChips = psListAlloc(NULL);
    514             for (int i=0; i < numFiles; i++) {
    515                 pmChip *chip = pmFPAviewThisChip(view, ((pmFPAfile *)inputs->data[i])->fpa);
    516                 psListAdd(inChips, PS_LIST_TAIL, chip);
    517             }
    518             if (!pmConceptsAverageChips(outChip, inChips, true)) {
    519                 psError(PS_ERR_UNKNOWN, false, "Unable to average Chip concepts.");
    520                 psFree(inChips);
    521                 goto ERROR;
    522             }
    523             psFree(inChips);
    524         }
    525545        if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) {
    526546            goto ERROR;
    527547        }
    528548    }
    529 
    530     // Get list of FPAs for concepts averaging
    531     psList *inFPAs = psListAlloc(NULL); ///< List of FPAs
    532     for (int i = 0; i < numFiles; i++) {
    533         pmFPAfile *input = inputs->data[i]; ///< Input file
    534         psListAdd(inFPAs, PS_LIST_TAIL, input->fpa);
    535     }
    536     if (!pmConceptsAverageFPAs(output->fpa, inFPAs)) {
    537         psError(PS_ERR_UNKNOWN, false, "Unable to average FPA concepts.");
    538         psFree(inFPAs);
    539         goto ERROR;
    540     }
    541     psFree(inFPAs);
    542 
    543549
    544550    if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) {
  • branches/eam_branches/20090820/ppStack/src/ppStackFinish.c

    r23753 r25870  
    6666    psString dump = psMetadataLookupStr(&mdok, config->arguments, "DUMP_CONFIG"); // File for config
    6767    if (dump) {
    68         pmConfigDump(config, dump);
     68        if (!pmConfigDump(config, dump)) {
     69            psError(PS_ERR_IO, false, "Unable to dump configuration.");
     70            return false;
     71        }
    6972    }
    7073
  • branches/eam_branches/20090820/ppSub/src/ppSub.c

    r23753 r25870  
    7676    psTimerStop();
    7777
     78    psString dump_file = psMetadataLookupStr(NULL, data->config->arguments, "-dumpconfig");
     79    if (dump_file) {
     80        if (!pmConfigDump(data->config, dump_file)) {
     81            psErrorStackPrint(stderr, "Unable to dump configuration.\n");
     82            exitValue = PS_EXIT_SYS_ERROR;
     83        }
     84    }
    7885    psFree(data);
    7986
  • branches/eam_branches/20090820/ppSub/src/ppSubData.c

    r23753 r25870  
    2929    psFree(data->stats);
    3030
    31     psString dump_file = psMetadataLookupStr(NULL, data->config->arguments, "-dumpconfig");
    32     if (dump_file) {
    33         pmConfigDump(data->config, dump_file);
    34     }
    3531    psFree(data->config);
    3632
  • branches/eam_branches/20090820/psModules/src/camera/pmFPAfileFitsIO.c

    r25168 r25870  
    179179          pmChip *chip = pmFPAviewThisChip(view, fpa); // Chip of interest, or NULL
    180180          pmCell *cell = pmFPAviewThisCell(view, fpa); // Cell of interest, or NULL
    181           if (!pmFPAUpdateNames(fpa, chip, cell, file->imageId, file->sourceId)) {
    182               psError(PS_ERR_UNKNOWN, false, "Unable to update names in header.");
    183               return false;
    184           }
    185 
    186181          if (cell) {
    187182              if (!pmConceptsWriteCell(cell, true, config)) {
     
    196191          } else if (!pmConceptsWriteFPA(fpa, true, config)) {
    197192              psError(PS_ERR_IO, false, "Unable to write concepts for FPA.\n");
     193              return false;
     194          }
     195
     196          if (!pmFPAUpdateNames(fpa, chip, cell, file->imageId, file->sourceId)) {
     197              psError(PS_ERR_UNKNOWN, false, "Unable to update names in header.");
    198198              return false;
    199199          }
  • branches/eam_branches/20090820/psModules/src/camera/pmReadoutFake.c

    • Property svn:mergeinfo changed (with no actual effect on merging)
  • branches/eam_branches/20090820/psModules/src/config/pmConfigMask.c

    r25766 r25870  
    1616    { "BLANK",     "DETECTOR", 0x01, true  }, // Pixel doesn't contain valid data
    1717    { "CTE",       "DETECTOR", 0x01, true  }, // Pixel has poor CTE
     18    { "BURNTOOL",  NULL,       0x04, false }, // Pixel has been touched by burntool
    1819    // Invalid signal ranges
    1920    { "SAT",       NULL,       0x02, true  }, // Pixel is saturated or non-linear
  • branches/eam_branches/20090820/psModules/src/objects/pmPSF_IO.c

    r21183 r25870  
    321321        pmPSFClump psfClump;
    322322
    323         // we now save clump parameters for each region : need to save all of those
    324         int nRegions = psMetadataLookupS32 (&status, recipe, "PSF.CLUMP.NREGIONS");
    325         psMetadataAddS32 (header, PS_LIST_TAIL, "PSF_CLN", PS_META_REPLACE, "number of psf clump regions", nRegions);
    326         for (int i = 0; i < nRegions; i++) {
    327             char regionName[64];
    328             snprintf (regionName, 64, "PSF.CLUMP.REGION.%03d", i);
    329             psMetadata *regionMD = psMetadataLookupPtr (&status, recipe, regionName);
    330 
    331             psfClump.X  = psMetadataLookupF32 (&status, regionMD, "PSF.CLUMP.X");   assert (status);
    332             psfClump.Y  = psMetadataLookupF32 (&status, regionMD, "PSF.CLUMP.Y");   assert (status);
    333             psfClump.dX = psMetadataLookupF32 (&status, regionMD, "PSF.CLUMP.DX");  assert (status);
    334             psfClump.dY = psMetadataLookupF32 (&status, regionMD, "PSF.CLUMP.DY");  assert (status);
    335 
    336             char key[16];
    337             snprintf (key, 9, "CLX_%03d", i);
    338             psMetadataAddF32 (header, PS_LIST_TAIL, key, PS_META_REPLACE, "psf clump center", psfClump.X);
    339             snprintf (key, 9, "CLY_%03d", i);
    340             psMetadataAddF32 (header, PS_LIST_TAIL, key, PS_META_REPLACE, "psf clump center", psfClump.Y);
    341             snprintf (key, 9, "CLDX_%03d", i);
    342             psMetadataAddF32 (header, PS_LIST_TAIL, key, PS_META_REPLACE, "psf clump size", psfClump.dX);
    343             snprintf (key, 9, "CLDY_%03d", i);
    344             psMetadataAddF32 (header, PS_LIST_TAIL, key, PS_META_REPLACE, "psf clump size", psfClump.dY);
    345         }
     323        // we now save clump parameters for each region : need to save all of those
     324        int nRegions = psMetadataLookupS32 (&status, analysis, "PSF.CLUMP.NREGIONS");
     325        psMetadataAddS32 (header, PS_LIST_TAIL, "PSF_CLN", PS_META_REPLACE, "number of psf clump regions", nRegions);
     326        for (int i = 0; i < nRegions; i++) {
     327            char regionName[64];
     328            snprintf (regionName, 64, "PSF.CLUMP.REGION.%03d", i);
     329            psMetadata *regionMD = psMetadataLookupPtr (&status, analysis, regionName);
     330
     331            psfClump.X  = psMetadataLookupF32 (&status, regionMD, "PSF.CLUMP.X");   assert (status);
     332            psfClump.Y  = psMetadataLookupF32 (&status, regionMD, "PSF.CLUMP.Y");   assert (status);
     333            psfClump.dX = psMetadataLookupF32 (&status, regionMD, "PSF.CLUMP.DX");  assert (status);
     334            psfClump.dY = psMetadataLookupF32 (&status, regionMD, "PSF.CLUMP.DY");  assert (status);
     335
     336            char key[16];
     337            snprintf (key, 9, "CLX_%03d", i);
     338            psMetadataAddF32 (header, PS_LIST_TAIL, key, PS_META_REPLACE, "psf clump center", psfClump.X);
     339            snprintf (key, 9, "CLY_%03d", i);
     340            psMetadataAddF32 (header, PS_LIST_TAIL, key, PS_META_REPLACE, "psf clump center", psfClump.Y);
     341            snprintf (key, 9, "CLDX_%03d", i);
     342            psMetadataAddF32 (header, PS_LIST_TAIL, key, PS_META_REPLACE, "psf clump size", psfClump.dX);
     343            snprintf (key, 9, "CLDY_%03d", i);
     344            psMetadataAddF32 (header, PS_LIST_TAIL, key, PS_META_REPLACE, "psf clump size", psfClump.dY);
     345        }
    346346
    347347        // save the dimensions of each parameter
     
    667667    int nRegions = psMetadataLookupS32 (&status, header, "PSF_CLN");
    668668    if (!status) {
    669         // read old-style psf clump data
    670 
    671         char regionName[64];
    672         snprintf (regionName, 64, "PSF.CLUMP.REGION.000");
    673         psMetadataAddS32 (recipe, PS_LIST_TAIL, "PSF.CLUMP.NREGIONS",  PS_META_REPLACE, "psf clump regions", 1);
    674 
    675         psMetadata *regionMD = psMetadataLookupPtr (&status, recipe, regionName);
    676         if (!regionMD) {
    677             regionMD = psMetadataAlloc();
    678             psMetadataAddMetadata (recipe, PS_LIST_TAIL, regionName, PS_META_REPLACE, "psf clump region", regionMD);
    679             psFree (regionMD);
    680         }
    681 
    682         // psf clump data
    683         pmPSFClump psfClump;
    684 
    685         psfClump.X  = psMetadataLookupF32 (&status, header, "PSF_CLX" );  assert(status);
    686         psfClump.Y  = psMetadataLookupF32 (&status, header, "PSF_CLY" );  assert(status);
    687         psfClump.dX = psMetadataLookupF32 (&status, header, "PSF_CLDX");  assert(status);
    688         psfClump.dY = psMetadataLookupF32 (&status, header, "PSF_CLDY");  assert(status);
    689 
    690         psMetadataAddF32 (regionMD, PS_LIST_TAIL, "PSF.CLUMP.X",  PS_META_REPLACE, "psf clump center", psfClump.X);
    691         psMetadataAddF32 (regionMD, PS_LIST_TAIL, "PSF.CLUMP.Y",  PS_META_REPLACE, "psf clump center", psfClump.Y);
    692         psMetadataAddF32 (regionMD, PS_LIST_TAIL, "PSF.CLUMP.DX", PS_META_REPLACE, "psf clump center", psfClump.dX);
    693         psMetadataAddF32 (regionMD, PS_LIST_TAIL, "PSF.CLUMP.DY", PS_META_REPLACE, "psf clump center", psfClump.dY);
     669        // read old-style psf clump data
     670
     671        char regionName[64];
     672        snprintf (regionName, 64, "PSF.CLUMP.REGION.000");
     673        psMetadataAddS32 (analysis, PS_LIST_TAIL, "PSF.CLUMP.NREGIONS",  PS_META_REPLACE, "psf clump regions", 1);
     674
     675        psMetadata *regionMD = psMetadataLookupPtr (&status, analysis, regionName);
     676        if (!regionMD) {
     677            regionMD = psMetadataAlloc();
     678            psMetadataAddMetadata (analysis, PS_LIST_TAIL, regionName, PS_META_REPLACE, "psf clump region", regionMD);
     679            psFree (regionMD);
     680        }
     681
     682        // psf clump data
     683        pmPSFClump psfClump;
     684
     685        psfClump.X  = psMetadataLookupF32 (&status, header, "PSF_CLX" );  assert(status);
     686        psfClump.Y  = psMetadataLookupF32 (&status, header, "PSF_CLY" );  assert(status);
     687        psfClump.dX = psMetadataLookupF32 (&status, header, "PSF_CLDX");  assert(status);
     688        psfClump.dY = psMetadataLookupF32 (&status, header, "PSF_CLDY");  assert(status);
     689
     690        psMetadataAddF32 (regionMD, PS_LIST_TAIL, "PSF.CLUMP.X",  PS_META_REPLACE, "psf clump center", psfClump.X);
     691        psMetadataAddF32 (regionMD, PS_LIST_TAIL, "PSF.CLUMP.Y",  PS_META_REPLACE, "psf clump center", psfClump.Y);
     692        psMetadataAddF32 (regionMD, PS_LIST_TAIL, "PSF.CLUMP.DX", PS_META_REPLACE, "psf clump center", psfClump.dX);
     693        psMetadataAddF32 (regionMD, PS_LIST_TAIL, "PSF.CLUMP.DY", PS_META_REPLACE, "psf clump center", psfClump.dY);
    694694    } else {
    695         psMetadataAddS32 (recipe, PS_LIST_TAIL, "PSF.CLUMP.NREGIONS",  PS_META_REPLACE, "psf clump regions", nRegions);
    696 
    697         for (int i = 0; i < nRegions; i++) {
    698             char key[10];
    699             char regionName[64];
    700             snprintf (regionName, 64, "PSF.CLUMP.REGION.%03d", i);
    701 
    702             psMetadata *regionMD = psMetadataLookupPtr (&status, recipe, regionName);
    703             if (!regionMD) {
    704                 regionMD = psMetadataAlloc();
    705                 psMetadataAddMetadata (recipe, PS_LIST_TAIL, regionName, PS_META_REPLACE, "psf clump region", regionMD);
    706                 psFree (regionMD);
    707             }
    708 
    709             // psf clump data
    710             pmPSFClump psfClump;
    711 
    712             snprintf (key, 9, "CLX_%03d", i);
    713             psfClump.X  = psMetadataLookupF32 (&status, header, key);  assert(status);
    714             snprintf (key, 9, "CLY_%03d", i);
    715             psfClump.Y  = psMetadataLookupF32 (&status, header, key);  assert(status);
    716             snprintf (key, 9, "CLDX_%03d", i);
    717             psfClump.dX = psMetadataLookupF32 (&status, header, key);  assert(status);
    718             snprintf (key, 9, "CLDY_%03d", i);
    719             psfClump.dY = psMetadataLookupF32 (&status, header, key);  assert(status);
    720 
    721             psMetadataAddF32 (regionMD, PS_LIST_TAIL, "PSF.CLUMP.X",  PS_META_REPLACE, "psf clump center", psfClump.X);
    722             psMetadataAddF32 (regionMD, PS_LIST_TAIL, "PSF.CLUMP.Y",  PS_META_REPLACE, "psf clump center", psfClump.Y);
    723             psMetadataAddF32 (regionMD, PS_LIST_TAIL, "PSF.CLUMP.DX", PS_META_REPLACE, "psf clump center", psfClump.dX);
    724             psMetadataAddF32 (regionMD, PS_LIST_TAIL, "PSF.CLUMP.DY", PS_META_REPLACE, "psf clump center", psfClump.dY);
    725         }
     695        psMetadataAddS32 (recipe, PS_LIST_TAIL, "PSF.CLUMP.NREGIONS",  PS_META_REPLACE, "psf clump regions", nRegions);
     696
     697        for (int i = 0; i < nRegions; i++) {
     698            char key[10];
     699            char regionName[64];
     700            snprintf (regionName, 64, "PSF.CLUMP.REGION.%03d", i);
     701
     702            psMetadata *regionMD = psMetadataLookupPtr (&status, analysis, regionName);
     703            if (!regionMD) {
     704                regionMD = psMetadataAlloc();
     705                psMetadataAddMetadata (analysis, PS_LIST_TAIL, regionName, PS_META_REPLACE, "psf clump region", regionMD);
     706                psFree (regionMD);
     707            }
     708
     709            // psf clump data
     710            pmPSFClump psfClump;
     711
     712            snprintf (key, 9, "CLX_%03d", i);
     713            psfClump.X  = psMetadataLookupF32 (&status, header, key);  assert(status);
     714            snprintf (key, 9, "CLY_%03d", i);
     715            psfClump.Y  = psMetadataLookupF32 (&status, header, key);  assert(status);
     716            snprintf (key, 9, "CLDX_%03d", i);
     717            psfClump.dX = psMetadataLookupF32 (&status, header, key);  assert(status);
     718            snprintf (key, 9, "CLDY_%03d", i);
     719            psfClump.dY = psMetadataLookupF32 (&status, header, key);  assert(status);
     720
     721            psMetadataAddF32 (regionMD, PS_LIST_TAIL, "PSF.CLUMP.X",  PS_META_REPLACE, "psf clump center", psfClump.X);
     722            psMetadataAddF32 (regionMD, PS_LIST_TAIL, "PSF.CLUMP.Y",  PS_META_REPLACE, "psf clump center", psfClump.Y);
     723            psMetadataAddF32 (regionMD, PS_LIST_TAIL, "PSF.CLUMP.DX", PS_META_REPLACE, "psf clump center", psfClump.dX);
     724            psMetadataAddF32 (regionMD, PS_LIST_TAIL, "PSF.CLUMP.DY", PS_META_REPLACE, "psf clump center", psfClump.dY);
     725        }
    726726    }
    727727
     
    871871            psFitsReadImageBuffer(psf->residuals->Ry, file->fits, fullImage, 2); // Desired pixels
    872872        }
    873         // XXX notice that we are not saving the resid->mask
     873        // XXX notice that we are not saving the resid->mask
    874874    }
    875875
  • branches/eam_branches/20090820/psModules/src/objects/pmPSFtryModel.c

    r25766 r25870  
    7070        psFree(psfTry);
    7171        return NULL;
    72     }     
    73 
    74     int orderMin = (options->psfTrendMode == PM_TREND_MAP) ? 1 : 0;
     72    }
     73
     74    // XXX set the min number of needed source more carefully (depends on psfTrendMode?)
    7575    int orderMax = PS_MAX (options->psfTrendNx, options->psfTrendNy);
    76 
    77     // XXX set the min number of needed source more carefully (depends on psfTrendMode?)
    7876    if ((sources->n < 15) && (orderMax >= 3)) orderMax = 2;
    7977    if ((sources->n < 11) && (orderMax >= 2)) orderMax = 1;
    8078    if ((sources->n <  8) && (orderMax >= 1)) orderMax = 0;
    8179    if ((sources->n <  3)) {
    82         psError (PS_ERR_UNKNOWN, true, "failed to determine PSF parameters");
    83         return NULL;
     80        psError (PS_ERR_UNKNOWN, true, "failed to determine PSF parameters");
     81        return NULL;
     82    }
     83
     84    int orderMin;
     85    if (options->psfTrendMode == PM_TREND_MAP) {
     86        orderMin = 1;
     87        orderMax = PS_MAX(orderMax, 1);
     88    } else {
     89        orderMin = 0;
    8490    }
    8591
     
    8793    psVector *srcMask = psVectorCopy (NULL, psfTry->mask, PS_TYPE_VECTOR_MASK);
    8894
    89     // we will save the PSF with the best fit (min systematic error) 
     95    // we will save the PSF with the best fit (min systematic error)
    9096    pmPSF *minPSF = NULL;
    9197    psVector *minMask = NULL;
     
    96102    int Ny = options->psfTrendNy;
    97103    for (int i = orderMin; i <= orderMax; i++) {
    98        
    99         if (Nx > Ny) {
    100             options->psfTrendNx = i;
    101             options->psfTrendNy = PS_MAX (orderMin, (int)(i * (Ny / Nx) + 0.5));
    102         } else {
    103             options->psfTrendNy = i;
    104             options->psfTrendNx = PS_MAX (orderMin, (int)(i * (Nx / Ny) + 0.5));
    105         }
    106 
    107         // free existing data, if any
    108         psFree(psfTry->psf);
    109         psFree(psfTry->mask);
    110 
    111         // allocate a mask and a psf model using the current Nx,Ny order values;
    112         psfTry->psf = pmPSFAlloc (options);
    113         psfTry->mask = psVectorCopy (NULL, srcMask, PS_TYPE_VECTOR_MASK);
    114 
    115         // stage 2: construct a psf (pmPSF) from this collection of model fits, including the 2D variation
    116         if (!pmPSFtryMakePSF (psfTry)) {
    117             psError(PS_ERR_UNKNOWN, false, "failed to construct a psf model from collection of sources");
    118             psFree(psfTry);
    119             return NULL;
    120         }
    121 
    122         // stage 3: refit with fixed shape parameters, measure pmPSFtry->metric
    123         if (!pmPSFtryFitPSF (psfTry, options, maskVal, markVal)) {
    124             psError(PS_ERR_UNKNOWN, false, "failed to construct a psf model from collection of sources");
    125             psFree(psfTry);
    126             return NULL;
    127         }
    128 
    129         // stage 4: measure systematic error in pmPSFtry->metric
    130         if (!pmPSFtryMetric (psfTry)) {
    131             psError(PS_ERR_UNKNOWN, false, "failed to measure systematic error of metric");
    132             psFree(psfTry);
    133             return NULL;
    134         }
    135 
    136         if (!minPSF) {
    137             minPSF = psMemIncrRefCounter(psfTry->psf);
    138             minMask = psMemIncrRefCounter(psfTry->mask);
    139         }
    140 
    141         if (psfTry->psf->dApResid < minPSF->dApResid) {
    142             psFree (minPSF);
    143             psFree (minMask);
    144             minPSF = psMemIncrRefCounter(psfTry->psf);
    145             minMask = psMemIncrRefCounter(psfTry->mask);
    146         }
     104
     105        if (Nx > Ny) {
     106            options->psfTrendNx = i;
     107            options->psfTrendNy = PS_MAX (orderMin, (int)(i * (Ny / Nx) + 0.5));
     108        } else {
     109            options->psfTrendNy = i;
     110            options->psfTrendNx = PS_MAX (orderMin, (int)(i * (Nx / Ny) + 0.5));
     111        }
     112
     113        // free existing data, if any
     114        psFree(psfTry->psf);
     115        psFree(psfTry->mask);
     116
     117        // allocate a mask and a psf model using the current Nx,Ny order values;
     118        psfTry->psf = pmPSFAlloc (options);
     119        psfTry->mask = psVectorCopy (NULL, srcMask, PS_TYPE_VECTOR_MASK);
     120
     121        // stage 2: construct a psf (pmPSF) from this collection of model fits, including the 2D variation
     122        if (!pmPSFtryMakePSF (psfTry)) {
     123            psError(PS_ERR_UNKNOWN, false, "failed to construct a psf model from collection of sources");
     124            psFree(psfTry);
     125            return NULL;
     126        }
     127
     128        // stage 3: refit with fixed shape parameters, measure pmPSFtry->metric
     129        if (!pmPSFtryFitPSF (psfTry, options, maskVal, markVal)) {
     130            psError(PS_ERR_UNKNOWN, false, "failed to construct a psf model from collection of sources");
     131            psFree(psfTry);
     132            return NULL;
     133        }
     134
     135        // stage 4: measure systematic error in pmPSFtry->metric
     136        if (!pmPSFtryMetric (psfTry)) {
     137            psError(PS_ERR_UNKNOWN, false, "failed to measure systematic error of metric");
     138            psFree(psfTry);
     139            return NULL;
     140        }
     141
     142        if (!minPSF) {
     143            minPSF = psMemIncrRefCounter(psfTry->psf);
     144            minMask = psMemIncrRefCounter(psfTry->mask);
     145        }
     146
     147        if (psfTry->psf->dApResid < minPSF->dApResid) {
     148            psFree (minPSF);
     149            psFree (minMask);
     150            minPSF = psMemIncrRefCounter(psfTry->psf);
     151            minMask = psMemIncrRefCounter(psfTry->mask);
     152        }
    147153    }
    148154    psFree (srcMask);
     
    153159    psfTry->psf = minPSF;
    154160    psfTry->mask = minMask;
    155    
     161
    156162    // XXXXX this is probably not used any more.  Are the chisq of the fits so bad? can we
    157163    // fix them by softening the errors on the brightest pixels?
  • branches/eam_branches/20090820/psconfig/pscheckperl

    r24670 r25870  
    99for (; @ARGV > 0; ) {
    1010    if ($ARGV[0] eq "-version") {
    11         $version = $ARGV[1];
     11        $version = $ARGV[1];
    1212        shift; shift; next;
    1313    }
    1414    if ($ARGV[0] eq "-build") {
    15         $build = 1;
     15        $build = 1;
    1616        shift; next;
    1717    }
    1818    if ($ARGV[0] eq "-force") {
    19         $force{$ARGV[1]} = 1;
    20         shift; shift; next;
     19        $force{$ARGV[1]} = 1;
     20        shift; shift; next;
    2121    }
    2222    if ($ARGV[0] eq "-h")     { &usage (); }
     
    3131if ( @ARGV > 1) { &usage(); }
    3232
    33 if ( @ARGV == 0) { 
     33if ( @ARGV == 0) {
    3434    @list = <$tagsets/*.perl>;
    3535    $file = $list[-1];
     
    7979    ($N, $module, $tarball, $modver, $prompts) = split (" ", $line);
    8080
    81     if ($modver eq "") { $modver = 0; } 
     81    if ($modver eq "") { $modver = 0; }
    8282    system ("pscheckmods $module $modver");
    83     if (($? == 0) and not defined $force{$module} and not defined $force{'all'}) { 
    84         # print "$module: found\n";
    85         next;
     83    if (($? == 0) and not defined $force{$module} and not defined $force{'all'}) {
     84        # print "$module: found\n";
     85        next;
    8686    }
    8787
    8888    if (defined $force{$module}) {
    89         print "$module: force\n";
     89        print "$module: force\n";
    9090    } else {
    91         print "$module: missing\n";
     91        print "$module: missing\n";
    9292    }
    93     unless ($build or defined $force{$module} or defined $force{'all'}) { 
    94         $Nmissing ++;
    95         push @missing, $module;
    96         next;
     93    unless ($build or defined $force{$module} or defined $force{'all'}) {
     94        $Nmissing ++;
     95        push @missing, $module;
     96        next;
    9797    }
    9898
     
    102102    print "extract $module from $tarball\n";
    103103    vsystem ("tar xvzf $tarball");
    104    
     104
    105105    ($tardir) = $tarball =~ m|(\S*).tar.gz|;
    106106    print "tardir: $tardir\n";
     
    108108    chdir $tardir;
    109109
    110     # build the MakeMaker makefile, setting the output directories
    111     if ($prompts) {
    112         @answers = split (",", $prompts);
    113         open (PIPE, "|perl Makefile.PL PREFIX=$prefix LIB=$perldir");
    114         foreach $answer (@answers) {
    115             print PIPE "$answer\n";
    116         }
    117         close (PIPE);
     110    if (-e "Build.PL") {
     111        vsystem("psbuildperl");
     112        vsystem("Build");
     113        vsystem("Build install");
    118114    } else {
    119         vsystem ("perl Makefile.PL PREFIX=$prefix LIB=$perldir");
     115        # build the MakeMaker makefile, setting the output directories
     116        if ($prompts) {
     117            @answers = split (",", $prompts);
     118            open (PIPE, "|perl Makefile.PL PREFIX=$prefix LIB=$perldir");
     119            foreach $answer (@answers) {
     120                print PIPE "$answer\n";
     121            }
     122            close (PIPE);
     123        } else {
     124            vsystem ("perl Makefile.PL PREFIX=$prefix LIB=$perldir");
     125        }
     126
     127        vsystem ("make < /dev/null");
     128        vsystem ("make install");
    120129    }
    121    
    122     vsystem ("make < /dev/null");
    123     vsystem ("make install");
    124130
    125131    chdir $homedir;
     
    127133if (!$build) {
    128134    if ($Nmissing > 0) {
    129         print "The following $Nmissing perl modules are missing from your system\n";
    130         foreach $name (@missing) {
    131             print "  $name\n";
    132         }
    133         print "you may install them in your local path by re-running pscheckperl with -build\n";
     135        print "The following $Nmissing perl modules are missing from your system\n";
     136        foreach $name (@missing) {
     137            print "  $name\n";
     138        }
     139        print "you may install them in your local path by re-running pscheckperl with -build\n";
    134140    } else {
    135         print "no perl modules are missing from your system\n";
     141        print "no perl modules are missing from your system\n";
    136142    }
    137143}
     
    152158    @list = <$tagsets/*.perl>;
    153159    foreach $line (@list) {
    154         chomp $line;
    155         ($dist) = $line =~ m|$tagsets/(\S*).perl|;
    156         print STDERR "$dist\n";
     160        chomp $line;
     161        ($dist) = $line =~ m|$tagsets/(\S*).perl|;
     162        print STDERR "$dist\n";
    157163    }
    158164    exit 2;
  • branches/eam_branches/20090820/psconfig/tagsets/ipp-2.9.perl

    r25766 r25870  
    22  00    Getopt::Long                   Getopt-Long-2.36.tar.gz                  2.3            n
    33  00    Module::Build                  Module-Build-0.2806.tar.gz               0.2806
    4   01    ExtUtils::MakeMaker            ExtUtils-MakeMaker-6.31.tar.gz           0
     4  01    ExtUtils::MakeMaker            ExtUtils-MakeMaker-6.54.tar.gz           0
    55  02    Params::Validate               Params-Validate-0.92.tar.gz              0.92
    66#  02    Apache::Test                   Apache-Test-1.29.tar.gz                  1.29
  • branches/eam_branches/20090820/psphot/doc/efficiency.txt

    • Property svn:mergeinfo changed (with no actual effect on merging)
  • branches/eam_branches/20090820/psphot/src/psphot.h

    r25766 r25870  
    182182bool psphotVisualShowFootprints (pmDetections *detections);
    183183bool psphotVisualShowMoments (psArray *sources);
    184 bool psphotVisualPlotMoments (psMetadata *recipe, psArray *sources);
     184bool psphotVisualPlotMoments (psMetadata *recipe, psMetadata *analysis, psArray *sources);
    185185bool psphotVisualShowRoughClass (psArray *sources);
    186186bool psphotVisualShowPSFStars (psMetadata *recipe, pmPSF *psf, psArray *sources);
     
    193193bool psphotVisualShowResidualImage (pmReadout *readout);
    194194bool psphotVisualPlotApResid (psArray *sources, float mean, float error);
    195 bool psphotVisualPlotSourceSize (psMetadata *recipe, psArray *sources);
     195bool psphotVisualPlotSourceSize (psMetadata *recipe, psMetadata *analysis, psArray *sources);
    196196bool psphotVisualShowPetrosians (psArray *sources);
    197197
     
    212212// bool psphotPetrosianVisualProfileRadii (psVector *radius, psVector *flux, psVector *radiusBin, psVector *fluxBin, float peakFlux, float RadiusRef);
    213213// bool psphotPetrosianVisualEllipticalContour (pmPetrosian *petrosian);
    214 // bool psphotPetrosianVisualStats (psVector *radBin, psVector *fluxBin, 
    215 //                               psVector *refRadius, psVector *meanSB,
    216 //                               psVector *petRatio, psVector *petRatioErr, psVector *fluxSum,
    217 //                               float petRadius, float ratioForRadius,
    218 //                               float petFlux, float radiusForFlux);
     214// bool psphotPetrosianVisualStats (psVector *radBin, psVector *fluxBin,
     215//                               psVector *refRadius, psVector *meanSB,
     216//                               psVector *petRatio, psVector *petRatioErr, psVector *fluxSum,
     217//                               float petRadius, float ratioForRadius,
     218//                               float petFlux, float radiusForFlux);
    219219
    220220bool psphotImageQuality (psMetadata *recipe, psArray *sources);
  • branches/eam_branches/20090820/psphot/src/psphotFake.c

    • Property svn:mergeinfo changed (with no actual effect on merging)
  • branches/eam_branches/20090820/psphot/src/psphotRoughClass.c

    r25766 r25870  
    11# include "psphotInternal.h"
    22
    3 # define CHECK_STATUS(S,MSG) {                                          \
    4         if (!status) {                                                  \
    5             psError(PSPHOT_ERR_CONFIG, false, "missing PSF Clump entry: %s\n", MSG); \
    6             return false;                                               \
    7         } }
     3# define CHECK_STATUS(S,MSG) {                                          \
     4        if (!status) {                                                  \
     5            psError(PSPHOT_ERR_CONFIG, false, "missing PSF Clump entry: %s\n", MSG); \
     6            return false;                                               \
     7        } }
    88
    9 bool psphotRoughClassRegion (int nRegion, psRegion *region, psArray *sources, psMetadata *recipe, const bool havePSF);
     9bool psphotRoughClassRegion (int nRegion, psRegion *region, psArray *sources, psMetadata *target, psMetadata *recipe, const bool havePSF);
    1010
    1111// 2006.02.02 : no leaks
     
    2424    int nRegion = 0;
    2525    for (int ix = 0; ix < NX; ix ++) {
    26         for (int iy = 0; iy < NY; iy ++) {
     26        for (int iy = 0; iy < NY; iy ++) {
    2727
    28             psRegion *region = psRegionAlloc (ix*dX, (ix + 1)*dX, iy*dY, (iy + 1)*dY);
    29             if (!psphotRoughClassRegion (nRegion, region, sources, recipe, havePSF)) {
    30                 psLogMsg ("psphot", 4, "Failed to determine rough classification for region %f,%f - %f,%f\n",
    31                         region->x0, region->y0, region->x1, region->y1);
    32                 psFree (region);
    33                 continue;
    34             }
    35             psFree (region);
    36             nRegion ++;
    37         }
     28            psRegion *region = psRegionAlloc (ix*dX, (ix + 1)*dX, iy*dY, (iy + 1)*dY);
     29            if (!psphotRoughClassRegion (nRegion, region, sources, readout->analysis, recipe, havePSF)) {
     30                psLogMsg ("psphot", 4, "Failed to determine rough classification for region %f,%f - %f,%f\n",
     31                        region->x0, region->y0, region->x1, region->y1);
     32                psFree (region);
     33                continue;
     34            }
     35            psFree (region);
     36            nRegion ++;
     37        }
    3838    }
    3939    psMetadataAddS32 (recipe, PS_LIST_TAIL, "PSF.CLUMP.NREGIONS",  PS_META_REPLACE, "psf clump regions", nRegion);
     
    4444    psLogMsg ("psphot.roughclass", PS_LOG_INFO, "rough classification: %f sec\n", psTimerMark ("psphot.rough"));
    4545
    46     psphotVisualPlotMoments (recipe, sources);
     46    psphotVisualPlotMoments (recipe, readout->analysis, sources);
    4747    psphotVisualShowRoughClass (sources);
    4848    // XXX better visualization: psphotVisualShowFlags (sources);
     
    5151}
    5252
    53 bool psphotRoughClassRegion (int nRegion, psRegion *region, psArray *sources, psMetadata *recipe, const bool havePSF) {
     53bool psphotRoughClassRegion (int nRegion, psRegion *region, psArray *sources, psMetadata *target, psMetadata *recipe, const bool havePSF) {
    5454
    5555    bool status;
     
    6262
    6363    snprintf (regionName, 64, "PSF.CLUMP.REGION.%03d", nRegion);
    64     psMetadata *regionMD = psMetadataLookupPtr (&status, recipe, regionName);
     64    psMetadata *regionMD = psMetadataLookupPtr (&status, target, regionName);
    6565    if (!regionMD) {
    66         // allocate the region metadata folder and add this region to it.
    67         regionMD = psMetadataAlloc();
    68         psMetadataAddMetadata (recipe, PS_LIST_TAIL, regionName, PS_META_REPLACE, "psf clump region", regionMD);
    69         psFree (regionMD);
     66        // allocate the region metadata folder and add this region to it.
     67        regionMD = psMetadataAlloc();
     68        psMetadataAddMetadata (target, PS_LIST_TAIL, regionName, PS_META_REPLACE, "psf clump region", regionMD);
     69        psFree (regionMD);
    7070    }
    7171    psMetadataAddPtr (regionMD, PS_LIST_TAIL, "REGION", PS_DATA_REGION | PS_META_REPLACE, "psf clump region", region);
    7272
    7373    if (!havePSF) {
    74         // determine the PSF parameters from the source moment values
    75         // XXX why not save the psfClump as a PTR?
    76         psfClump = pmSourcePSFClump (region, sources, recipe);
    77         psMetadataAddF32 (regionMD, PS_LIST_TAIL, "PSF.CLUMP.X",  PS_META_REPLACE, "psf clump center", psfClump.X);
    78         psMetadataAddF32 (regionMD, PS_LIST_TAIL, "PSF.CLUMP.Y",  PS_META_REPLACE, "psf clump center", psfClump.Y);
    79         psMetadataAddF32 (regionMD, PS_LIST_TAIL, "PSF.CLUMP.DX", PS_META_REPLACE, "psf clump center", psfClump.dX);
    80         psMetadataAddF32 (regionMD, PS_LIST_TAIL, "PSF.CLUMP.DY", PS_META_REPLACE, "psf clump center", psfClump.dY);
     74        // determine the PSF parameters from the source moment values
     75        // XXX why not save the psfClump as a PTR?
     76        psfClump = pmSourcePSFClump (region, sources, target);
     77        psMetadataAddF32 (regionMD, PS_LIST_TAIL, "PSF.CLUMP.X",  PS_META_REPLACE, "psf clump center", psfClump.X);
     78        psMetadataAddF32 (regionMD, PS_LIST_TAIL, "PSF.CLUMP.Y",  PS_META_REPLACE, "psf clump center", psfClump.Y);
     79        psMetadataAddF32 (regionMD, PS_LIST_TAIL, "PSF.CLUMP.DX", PS_META_REPLACE, "psf clump center", psfClump.dX);
     80        psMetadataAddF32 (regionMD, PS_LIST_TAIL, "PSF.CLUMP.DY", PS_META_REPLACE, "psf clump center", psfClump.dY);
    8181    } else {
    82         // pull FWHM_X,Y from the recipe, use to define psfClump.X,Y
    83         psfClump.X  = psMetadataLookupF32 (&status, regionMD, "PSF.CLUMP.X");
    84         if (!status) {
    85             psLogMsg ("psphot", 4, "No PSF clump defined for region %f,%f - %f,%f\n", region->x0, region->y0, region->x1, region->y1);
    86             return false;
    87         }           
    88         psfClump.Y  = psMetadataLookupF32 (&status, regionMD, "PSF.CLUMP.Y");   psAssert (status, "missing PSF.CLUMP.Y");
    89         psfClump.dX = psMetadataLookupF32 (&status, regionMD, "PSF.CLUMP.DX");  psAssert (status, "missing PSF.CLUMP.DX");
    90         psfClump.dY = psMetadataLookupF32 (&status, regionMD, "PSF.CLUMP.DY");  psAssert (status, "missing PSF.CLUMP.DY");
     82        // pull FWHM_X,Y from the recipe, use to define psfClump.X,Y
     83        psfClump.X  = psMetadataLookupF32 (&status, regionMD, "PSF.CLUMP.X");
     84        if (!status) {
     85            psLogMsg ("psphot", 4, "No PSF clump defined for region %f,%f - %f,%f\n", region->x0, region->y0, region->x1, region->y1);
     86            return false;
     87        }
     88        psfClump.Y  = psMetadataLookupF32 (&status, regionMD, "PSF.CLUMP.Y");   psAssert (status, "missing PSF.CLUMP.Y");
     89        psfClump.dX = psMetadataLookupF32 (&status, regionMD, "PSF.CLUMP.DX");  psAssert (status, "missing PSF.CLUMP.DX");
     90        psfClump.dY = psMetadataLookupF32 (&status, regionMD, "PSF.CLUMP.DY");  psAssert (status, "missing PSF.CLUMP.DY");
    9191    }
    9292
    9393    if (psfClump.X < 0) {
    94         psError(PSPHOT_ERR_PROG, false, "programming error calling pmSourcePSFClump");
    95         return false;
     94        psError(PSPHOT_ERR_PROG, false, "programming error calling pmSourcePSFClump");
     95        return false;
    9696    }
    9797    if (!psfClump.X || !psfClump.Y || isnan(psfClump.X) || isnan(psfClump.Y)) {
    98         psLogMsg ("psphot", 4, "Failed to find a valid PSF clump for region %f,%f - %f,%f\n", region->x0, region->y0, region->x1, region->y1);
    99         return false;
     98        psLogMsg ("psphot", 4, "Failed to find a valid PSF clump for region %f,%f - %f,%f\n", region->x0, region->y0, region->x1, region->y1);
     99        return false;
    100100    }
    101101    psLogMsg ("psphot", 3, "psf clump  X,  Y: %f, %f\n", psfClump.X, psfClump.Y);
     
    104104    // group into STAR, COSMIC, EXTENDED, SATURATED, etc.
    105105    if (!pmSourceRoughClass (region, sources, recipe, psfClump, maskSat)) {
    106         psError(PSPHOT_ERR_PROG, false, "programming error calling pmSourceRoughClass");
    107         return false;
     106        psError(PSPHOT_ERR_PROG, false, "programming error calling pmSourceRoughClass");
     107        return false;
    108108    }
    109109
  • branches/eam_branches/20090820/psphot/src/psphotSourceSize.c

    r25766 r25870  
    8383    psLogMsg ("psphot.size", PS_LOG_INFO, "measure source sizes for %ld sources: %f sec\n", sources->n - first, psTimerMark ("psphot.size"));
    8484
    85     psphotVisualPlotSourceSize (recipe, sources);
     85    psphotVisualPlotSourceSize (recipe, readout->analysis, sources);
    8686    psphotVisualShowSourceSize (readout, sources);
    8787    psphotVisualPlotApResid (sources, options.ApResid, options.ApSysErr);
     
    103103    pmFootprint *footprint = peak->footprint;
    104104    if (!footprint) {
    105         // if we have not footprint, use the old code to mask by isophot
    106         psphotMaskCosmicRayIsophot (source, maskVal, crMask);
    107         return true;
     105        // if we have not footprint, use the old code to mask by isophot
     106        psphotMaskCosmicRayIsophot (source, maskVal, crMask);
     107        return true;
    108108    }
    109109
    110110    if (!footprint->spans) {
    111         // if we have no footprint, use the old code to mask by isophot
    112         psphotMaskCosmicRayIsophot (source, maskVal, crMask);
    113         return true;
     111        // if we have no footprint, use the old code to mask by isophot
     112        psphotMaskCosmicRayIsophot (source, maskVal, crMask);
     113        return true;
    114114    }
    115115
    116116    // mask all of the pixels covered by the spans of the footprint
    117117    for (int j = 1; j < footprint->spans->n; j++) {
    118         pmSpan *span1 = footprint->spans->data[j];
    119 
    120         int iy = span1->y;
    121         int xs = span1->x0;
    122         int xe = span1->x1;
    123 
    124         for (int ix = xs; ix < xe; ix++) {
    125             mask->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix] |= crMask;
    126         }
     118        pmSpan *span1 = footprint->spans->data[j];
     119
     120        int iy = span1->y;
     121        int xs = span1->x0;
     122        int xe = span1->x1;
     123
     124        for (int ix = xs; ix < xe; ix++) {
     125            mask->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix] |= crMask;
     126        }
    127127    }
    128128    return true;
     
    147147    // mark the pixels in this row to the left, then the right
    148148    for (int ix = xo; ix >= 0; ix--) {
    149         float SN = pixels->data.F32[yo][ix] / sqrt(variance->data.F32[yo][ix]);
    150         if (SN > SN_LIMIT) {
    151             mask->data.PS_TYPE_IMAGE_MASK_DATA[yo][ix] |= crMask;
    152         }
     149        float SN = pixels->data.F32[yo][ix] / sqrt(variance->data.F32[yo][ix]);
     150        if (SN > SN_LIMIT) {
     151            mask->data.PS_TYPE_IMAGE_MASK_DATA[yo][ix] |= crMask;
     152        }
    153153    }
    154154    for (int ix = xo + 1; ix < pixels->numCols; ix++) {
    155         float SN = pixels->data.F32[yo][ix] / sqrt(variance->data.F32[yo][ix]);
    156         if (SN > SN_LIMIT) {
    157             mask->data.PS_TYPE_IMAGE_MASK_DATA[yo][ix] |= crMask;
    158         }
     155        float SN = pixels->data.F32[yo][ix] / sqrt(variance->data.F32[yo][ix]);
     156        if (SN > SN_LIMIT) {
     157            mask->data.PS_TYPE_IMAGE_MASK_DATA[yo][ix] |= crMask;
     158        }
    159159    }
    160160
     
    162162    // first go up:
    163163    for (int iy = PS_MIN(yo, mask->numRows-2); iy >= 0; iy--) {
    164         // mark the pixels in this row to the left, then the right
    165         for (int ix = 0; ix < pixels->numCols; ix++) {
    166             float SN = pixels->data.F32[iy][ix] / sqrt(variance->data.F32[iy][ix]);
    167             if (SN < SN_LIMIT) continue;
    168 
    169             bool valid = false;
    170             valid |= (mask->data.PS_TYPE_IMAGE_MASK_DATA[iy+1][ix] & crMask);
    171             valid |= (ix > 0) ? (mask->data.PS_TYPE_IMAGE_MASK_DATA[iy+1][ix-1] & crMask) : 0;
    172             valid |= (ix <= mask->numCols) ? (mask->data.PS_TYPE_IMAGE_MASK_DATA[iy+1][ix+1] & crMask) : 0;
    173 
    174             if (!valid) continue;
    175             mask->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix] |= crMask;
    176         }
     164        // mark the pixels in this row to the left, then the right
     165        for (int ix = 0; ix < pixels->numCols; ix++) {
     166            float SN = pixels->data.F32[iy][ix] / sqrt(variance->data.F32[iy][ix]);
     167            if (SN < SN_LIMIT) continue;
     168
     169            bool valid = false;
     170            valid |= (mask->data.PS_TYPE_IMAGE_MASK_DATA[iy+1][ix] & crMask);
     171            valid |= (ix > 0) ? (mask->data.PS_TYPE_IMAGE_MASK_DATA[iy+1][ix-1] & crMask) : 0;
     172            valid |= (ix <= mask->numCols) ? (mask->data.PS_TYPE_IMAGE_MASK_DATA[iy+1][ix+1] & crMask) : 0;
     173
     174            if (!valid) continue;
     175            mask->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix] |= crMask;
     176        }
    177177    }
    178178    // next go down:
    179179    for (int iy = PS_MIN(yo+1, mask->numRows-1); iy < pixels->numRows; iy++) {
    180         // mark the pixels in this row to the left, then the right
    181         for (int ix = 0; ix < pixels->numCols; ix++) {
    182             float SN = pixels->data.F32[iy][ix] / sqrt(variance->data.F32[iy][ix]);
    183             if (SN < SN_LIMIT) continue;
    184 
    185             bool valid = false;
    186             valid |= (mask->data.PS_TYPE_IMAGE_MASK_DATA[iy-1][ix] & crMask);
    187             valid |= (ix > 0) ? (mask->data.PS_TYPE_IMAGE_MASK_DATA[iy-1][ix-1] & crMask) : 0;
    188             valid |= (ix <= mask->numCols) ? (mask->data.PS_TYPE_IMAGE_MASK_DATA[iy-1][ix+1] & crMask) : 0;
    189 
    190             if (!valid) continue;
    191             mask->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix] |= crMask;
    192         }
     180        // mark the pixels in this row to the left, then the right
     181        for (int ix = 0; ix < pixels->numCols; ix++) {
     182            float SN = pixels->data.F32[iy][ix] / sqrt(variance->data.F32[iy][ix]);
     183            if (SN < SN_LIMIT) continue;
     184
     185            bool valid = false;
     186            valid |= (mask->data.PS_TYPE_IMAGE_MASK_DATA[iy-1][ix] & crMask);
     187            valid |= (ix > 0) ? (mask->data.PS_TYPE_IMAGE_MASK_DATA[iy-1][ix-1] & crMask) : 0;
     188            valid |= (ix <= mask->numCols) ? (mask->data.PS_TYPE_IMAGE_MASK_DATA[iy-1][ix+1] & crMask) : 0;
     189
     190            if (!valid) continue;
     191            mask->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix] |= crMask;
     192        }
    193193    }
    194194    return true;
     
    201201    psVector *Ap = psVectorAllocEmpty (100, PS_TYPE_F32);
    202202    psVector *ApErr = psVectorAllocEmpty (100, PS_TYPE_F32);
    203    
     203
    204204    psImageMaskType maskVal = options->maskVal | options->markVal;
    205205
     
    208208
    209209    for (int i = 0; i < sources->n; i++) {
    210         pmSource *source = sources->data[i];
    211         if (!(source->mode & PM_SOURCE_MODE_PSFSTAR)) continue;
     210        pmSource *source = sources->data[i];
     211        if (!(source->mode & PM_SOURCE_MODE_PSFSTAR)) continue;
    212212
    213213        // replace object in image
     
    216216        }
    217217
    218         // clear the mask bit and set the circular mask pixels
    219         psImageMaskPixels (source->maskObj, "AND", PS_NOT_IMAGE_MASK(options->markVal));
    220         psImageKeepCircle (source->maskObj, source->peak->x, source->peak->y, source->apRadius, "OR", options->markVal);
    221 
    222         // XXX can we test if psfMag is set and calculate only if needed?
    223         pmSourceMagnitudes (source, psf, photMode, maskVal); // maskVal includes markVal
    224        
    225         // clear the mask bit
    226         psImageMaskPixels (source->maskObj, "AND", PS_NOT_IMAGE_MASK(options->markVal));
     218        // clear the mask bit and set the circular mask pixels
     219        psImageMaskPixels (source->maskObj, "AND", PS_NOT_IMAGE_MASK(options->markVal));
     220        psImageKeepCircle (source->maskObj, source->peak->x, source->peak->y, source->apRadius, "OR", options->markVal);
     221
     222        // XXX can we test if psfMag is set and calculate only if needed?
     223        pmSourceMagnitudes (source, psf, photMode, maskVal); // maskVal includes markVal
     224
     225        // clear the mask bit
     226        psImageMaskPixels (source->maskObj, "AND", PS_NOT_IMAGE_MASK(options->markVal));
    227227
    228228        // re-subtract the object, leave local sky
    229229        pmSourceSub (source, PM_MODEL_OP_FULL, options->maskVal);
    230230
    231         float apMag = -2.5*log10(source->moments->Sum);
    232         float dMag = source->psfMag - apMag;
    233        
    234         psVectorAppend (Ap, 100, dMag);
    235         psVectorAppend (ApErr, 100, source->errMag);
     231        float apMag = -2.5*log10(source->moments->Sum);
     232        float dMag = source->psfMag - apMag;
     233
     234        psVectorAppend (Ap, 100, dMag);
     235        psVectorAppend (ApErr, 100, source->errMag);
    236236    }
    237237
     
    242242    psVector *dAp = psVectorAlloc (Ap->n, PS_TYPE_F32);
    243243    for (int i = 0; i < Ap->n; i++) {
    244         dAp->data.F32[i] = Ap->data.F32[i] - stats->robustMedian;
     244        dAp->data.F32[i] = Ap->data.F32[i] - stats->robustMedian;
    245245    }
    246246
     
    266266    psLogMsg("psModules.objects", PS_LOG_INFO, "Source Size classifications: %4s %4s %4s %4s %4s %4s", "Npsf", "Next", "Nsat", "Ncr", "Nmiss", "Nskip");
    267267
    268     int nRegions = psMetadataLookupS32 (&status, recipe, "PSF.CLUMP.NREGIONS");
     268    int nRegions = psMetadataLookupS32 (&status, readout->analysis, "PSF.CLUMP.NREGIONS");
    269269    for (int i = 0; i < nRegions; i ++) {
    270         snprintf (regionName, 64, "PSF.CLUMP.REGION.%03d", i);
    271         psMetadata *regionMD = psMetadataLookupPtr (&status, recipe, regionName);
    272         psAssert (regionMD, "regions must be defined by earlier call to psphotRoughClassRegion");
    273 
    274         psRegion *region = psMetadataLookupPtr (&status, regionMD, "REGION");
    275         psAssert (region, "regions must be defined by earlier call to psphotRoughClassRegion");
    276 
    277         // pull FWHM_X,Y from the recipe, use to define psfClump.X,Y
    278         psfClump.X  = psMetadataLookupF32 (&status, regionMD, "PSF.CLUMP.X");   psAssert (status, "missing PSF.CLUMP.X");
    279         psfClump.Y  = psMetadataLookupF32 (&status, regionMD, "PSF.CLUMP.Y");   psAssert (status, "missing PSF.CLUMP.Y");
    280         psfClump.dX = psMetadataLookupF32 (&status, regionMD, "PSF.CLUMP.DX");  psAssert (status, "missing PSF.CLUMP.DX");
    281         psfClump.dY = psMetadataLookupF32 (&status, regionMD, "PSF.CLUMP.DY");  psAssert (status, "missing PSF.CLUMP.DY");
    282 
    283         if ((psfClump.X < 0) || (psfClump.Y < 0) || !psfClump.X || !psfClump.Y || isnan(psfClump.X) || isnan(psfClump.Y)) {
    284             psLogMsg ("psphot", 4, "Failed to find a valid PSF clump for region %f,%f - %f,%f\n", region->x0, region->y0, region->x1, region->y1);
    285             continue;
    286         }
    287        
    288         if (!psphotSourceClassRegion (region, &psfClump, sources, recipe, psf, options)) {
    289             psLogMsg ("psphot", 4, "Failed to determine source classification for region %f,%f - %f,%f\n", region->x0, region->y0, region->x1, region->y1);
    290             continue;
    291         }
    292     }   
     270        snprintf (regionName, 64, "PSF.CLUMP.REGION.%03d", i);
     271        psMetadata *regionMD = psMetadataLookupPtr (&status, readout->analysis, regionName);
     272        psAssert (regionMD, "regions must be defined by earlier call to psphotRoughClassRegion");
     273
     274        psRegion *region = psMetadataLookupPtr (&status, regionMD, "REGION");
     275        psAssert (region, "regions must be defined by earlier call to psphotRoughClassRegion");
     276
     277        // pull FWHM_X,Y from the recipe, use to define psfClump.X,Y
     278        psfClump.X  = psMetadataLookupF32 (&status, regionMD, "PSF.CLUMP.X");   psAssert (status, "missing PSF.CLUMP.X");
     279        psfClump.Y  = psMetadataLookupF32 (&status, regionMD, "PSF.CLUMP.Y");   psAssert (status, "missing PSF.CLUMP.Y");
     280        psfClump.dX = psMetadataLookupF32 (&status, regionMD, "PSF.CLUMP.DX");  psAssert (status, "missing PSF.CLUMP.DX");
     281        psfClump.dY = psMetadataLookupF32 (&status, regionMD, "PSF.CLUMP.DY");  psAssert (status, "missing PSF.CLUMP.DY");
     282
     283        if ((psfClump.X < 0) || (psfClump.Y < 0) || !psfClump.X || !psfClump.Y || isnan(psfClump.X) || isnan(psfClump.Y)) {
     284            psLogMsg ("psphot", 4, "Failed to find a valid PSF clump for region %f,%f - %f,%f\n", region->x0, region->y0, region->x1, region->y1);
     285            continue;
     286        }
     287
     288        if (!psphotSourceClassRegion (region, &psfClump, sources, recipe, psf, options)) {
     289            psLogMsg ("psphot", 4, "Failed to determine source classification for region %f,%f - %f,%f\n", region->x0, region->y0, region->x1, region->y1);
     290            continue;
     291        }
     292    }
    293293
    294294    return true;
     
    314314    for (psS32 i = 0 ; i < sources->n ; i++) {
    315315
    316         pmSource *source = (pmSource *) sources->data[i];
    317 
    318         // psfClumps are found for image subregions:
    319         // skip sources not in this region
    320         if (source->peak->x <  region->x0) continue;
    321         if (source->peak->x >= region->x1) continue;
    322         if (source->peak->y <  region->y0) continue;
    323         if (source->peak->y >= region->y1) continue;
    324 
    325         // skip source if it was already measured
    326         if (source->tmpFlags & PM_SOURCE_TMPF_SIZE_MEASURED) {
    327             psTrace("psphot", 7, "Not calculating source size since it has already been measured\n");
    328             continue;
    329         }
    330 
    331         // source must have been subtracted
    332         if (!(source->tmpFlags & PM_SOURCE_TMPF_SUBTRACTED)) {
    333             source->mode |= PM_SOURCE_MODE_SIZE_SKIPPED;
    334             psTrace("psphot", 7, "Not calculating source size since source is not subtracted\n");
    335             continue;
    336         }
    337 
    338         // we are basically classifying by moments; use the default if not found
    339         psAssert (source->moments, "why is this source missing moments?");
    340         if (source->mode & noMoments) {
    341             Nskip ++;
    342             continue;
    343         }
    344 
    345         psF32 Mxx = source->moments->Mxx;
    346         psF32 Myy = source->moments->Myy;
     316        pmSource *source = (pmSource *) sources->data[i];
     317
     318        // psfClumps are found for image subregions:
     319        // skip sources not in this region
     320        if (source->peak->x <  region->x0) continue;
     321        if (source->peak->x >= region->x1) continue;
     322        if (source->peak->y <  region->y0) continue;
     323        if (source->peak->y >= region->y1) continue;
     324
     325        // skip source if it was already measured
     326        if (source->tmpFlags & PM_SOURCE_TMPF_SIZE_MEASURED) {
     327            psTrace("psphot", 7, "Not calculating source size since it has already been measured\n");
     328            continue;
     329        }
     330
     331        // source must have been subtracted
     332        if (!(source->tmpFlags & PM_SOURCE_TMPF_SUBTRACTED)) {
     333            source->mode |= PM_SOURCE_MODE_SIZE_SKIPPED;
     334            psTrace("psphot", 7, "Not calculating source size since source is not subtracted\n");
     335            continue;
     336        }
     337
     338        // we are basically classifying by moments; use the default if not found
     339        psAssert (source->moments, "why is this source missing moments?");
     340        if (source->mode & noMoments) {
     341            Nskip ++;
     342            continue;
     343        }
     344
     345        psF32 Mxx = source->moments->Mxx;
     346        psF32 Myy = source->moments->Myy;
    347347
    348348        // replace object in image
     
    351351        }
    352352
    353         // clear the mask bit and set the circular mask pixels
    354         psImageMaskPixels (source->maskObj, "AND", PS_NOT_IMAGE_MASK(options->markVal));
    355         psImageKeepCircle (source->maskObj, source->peak->x, source->peak->y, source->apRadius, "OR", options->markVal);
    356 
    357         // XXX can we test if psfMag is set and calculate only if needed?
    358         pmSourceMagnitudes (source, psf, photMode, maskVal); // maskVal includes markVal
    359 
    360         // clear the mask bit
    361         psImageMaskPixels (source->maskObj, "AND", PS_NOT_IMAGE_MASK(options->markVal));
     353        // clear the mask bit and set the circular mask pixels
     354        psImageMaskPixels (source->maskObj, "AND", PS_NOT_IMAGE_MASK(options->markVal));
     355        psImageKeepCircle (source->maskObj, source->peak->x, source->peak->y, source->apRadius, "OR", options->markVal);
     356
     357        // XXX can we test if psfMag is set and calculate only if needed?
     358        pmSourceMagnitudes (source, psf, photMode, maskVal); // maskVal includes markVal
     359
     360        // clear the mask bit
     361        psImageMaskPixels (source->maskObj, "AND", PS_NOT_IMAGE_MASK(options->markVal));
    362362
    363363        // re-subtract the object, leave local sky
    364364        pmSourceSub (source, PM_MODEL_OP_FULL, options->maskVal);
    365365
    366         float apMag = -2.5*log10(source->moments->Sum);
    367         float dMag = source->psfMag - apMag;
    368         float nSigma = (dMag - options->ApResid) / hypot(source->errMag, options->ApSysErr);
    369 
    370         source->extNsigma = nSigma;
    371         source->tmpFlags |= PM_SOURCE_TMPF_SIZE_MEASURED;
    372 
    373         // Anything within this region is a probably PSF-like object. Saturated stars may land
    374         // in this region, but are detected elsewhere on the basis of their peak value.
    375         bool isPSF = (fabs(nSigma) < options->nSigmaApResid) && (fabs(Mxx - psfClump->X) < options->nSigmaMoments*psfClump->dX) && (fabs(Myy - psfClump->Y) < options->nSigmaMoments*psfClump->dY);
    376         if (isPSF) {
    377             Npsf ++;
    378             continue;
    379         }
    380 
    381         // Defects may not always match CRs from peak curvature analysis
    382         // Defects may also be marked as SATSTAR -- XXX deactivate this flag?
    383         // XXX this rule is not great
    384         if ((Mxx < psfClump->X) || (Myy < psfClump->Y)) {
    385             source->mode |= PM_SOURCE_MODE_DEFECT;
    386             Ncr ++;
    387             continue;
    388         }
    389 
    390         // saturated star (determined in PSF fit).  These may also be saturated galaxies, or
    391         // just large saturated regions.
    392         if (source->mode & PM_SOURCE_MODE_SATSTAR) {
    393             Nsat ++;
    394             continue;
    395         }
    396 
    397         // XXX allow the Mxx, Myy to be less than psfClump->X,Y (by some nSigma)?
    398         bool isEXT = (nSigma > options->nSigmaApResid) || ((Mxx > psfClump->X) && (Myy > psfClump->Y));
    399         if (isEXT) {
    400             source->mode |= PM_SOURCE_MODE_EXT_LIMIT;
    401             Next ++;
    402             continue;
    403         }
    404 
    405         psWarning ("sourse size was missed for %f,%f : %f %f -- %f\n", source->peak->xf, source->peak->yf, Mxx, Myy, nSigma);
    406         Nmiss ++;
     366        float apMag = -2.5*log10(source->moments->Sum);
     367        float dMag = source->psfMag - apMag;
     368        float nSigma = (dMag - options->ApResid) / hypot(source->errMag, options->ApSysErr);
     369
     370        source->extNsigma = nSigma;
     371        source->tmpFlags |= PM_SOURCE_TMPF_SIZE_MEASURED;
     372
     373        // Anything within this region is a probably PSF-like object. Saturated stars may land
     374        // in this region, but are detected elsewhere on the basis of their peak value.
     375        bool isPSF = (fabs(nSigma) < options->nSigmaApResid) && (fabs(Mxx - psfClump->X) < options->nSigmaMoments*psfClump->dX) && (fabs(Myy - psfClump->Y) < options->nSigmaMoments*psfClump->dY);
     376        if (isPSF) {
     377            Npsf ++;
     378            continue;
     379        }
     380
     381        // Defects may not always match CRs from peak curvature analysis
     382        // Defects may also be marked as SATSTAR -- XXX deactivate this flag?
     383        // XXX this rule is not great
     384        if ((Mxx < psfClump->X) || (Myy < psfClump->Y)) {
     385            source->mode |= PM_SOURCE_MODE_DEFECT;
     386            Ncr ++;
     387            continue;
     388        }
     389
     390        // saturated star (determined in PSF fit).  These may also be saturated galaxies, or
     391        // just large saturated regions.
     392        if (source->mode & PM_SOURCE_MODE_SATSTAR) {
     393            Nsat ++;
     394            continue;
     395        }
     396
     397        // XXX allow the Mxx, Myy to be less than psfClump->X,Y (by some nSigma)?
     398        bool isEXT = (nSigma > options->nSigmaApResid) || ((Mxx > psfClump->X) && (Myy > psfClump->Y));
     399        if (isEXT) {
     400            source->mode |= PM_SOURCE_MODE_EXT_LIMIT;
     401            Next ++;
     402            continue;
     403        }
     404
     405        psWarning ("sourse size was missed for %f,%f : %f %f -- %f\n", source->peak->xf, source->peak->yf, Mxx, Myy, nSigma);
     406        Nmiss ++;
    407407    }
    408408
     
    417417// no longer used by psphot.
    418418float psphotModelContour(const psImage *image, const psImage *variance, const psImage *mask,
    419                         psImageMaskType maskVal, const pmModel *model, float Ro)
     419                        psImageMaskType maskVal, const pmModel *model, float Ro)
    420420{
    421421    psF32 *PAR = model->params->data.F32; // Model parameters
     
    432432    float Q = Ro * PS_SQR(sxx) / (1.0 - PS_SQR(sxx * syy * sxy) / 4.0);
    433433    if (Q < 0.0) {
    434         // ellipse is imaginary
    435         return NAN;
     434        // ellipse is imaginary
     435        return NAN;
    436436    }
    437437
     
    441441
    442442    for (int x = -radius; x <= radius; x++) {
    443         // Polynomial coefficients
    444         // XXX Should we be using the centre of the pixel as x or x+0.5?
    445         float A = PS_SQR (1.0 / syy);
    446         float B = x * sxy;
    447         float C = PS_SQR (x / sxx) - Ro;
    448         float T = PS_SQR(B) - 4*A*C;
    449         if (T < 0.0) {
    450             continue;
    451         }
    452 
    453         // y position in source frame
    454         float yP = (-B + sqrt (T)) / (2.0 * A);
    455         float yM = (-B - sqrt (T)) / (2.0 * A);
    456 
    457         // Get the closest pixel positions (image frame)
    458         int xPix  = x  + PAR[PM_PAR_XPOS] - image->col0 + 0.5;
    459         int yPixM = yM + PAR[PM_PAR_YPOS] - image->row0 + 0.5;
    460         int yPixP = yP + PAR[PM_PAR_YPOS] - image->row0 + 0.5;
    461 
    462         if (xPix < 0 || xPix >= image->numCols) {
    463             continue;
    464         }
    465 
    466         if (yPixM >= 0 && yPixM < image->numRows &&
    467             !(mask && (mask->data.PS_TYPE_IMAGE_MASK_DATA[yPixM][xPix] & maskVal))) {
    468             float dSigma = image->data.F32[yPixM][xPix] / sqrtf(variance->data.F32[yPixM][xPix]);
    469             nSigma += dSigma;
    470             nPts++;
    471         }
    472 
    473         if (yPixM == yPixP) {
    474             continue;
    475         }
    476 
    477         if (yPixP >= 0 && yPixP < image->numRows &&
    478             !(mask && (mask->data.PS_TYPE_IMAGE_MASK_DATA[yPixP][xPix] & maskVal))) {
    479             float dSigma = image->data.F32[yPixP][xPix] / sqrtf(variance->data.F32[yPixP][xPix]);
    480             nSigma += dSigma;
    481             nPts++;
    482         }
     443        // Polynomial coefficients
     444        // XXX Should we be using the centre of the pixel as x or x+0.5?
     445        float A = PS_SQR (1.0 / syy);
     446        float B = x * sxy;
     447        float C = PS_SQR (x / sxx) - Ro;
     448        float T = PS_SQR(B) - 4*A*C;
     449        if (T < 0.0) {
     450            continue;
     451        }
     452
     453        // y position in source frame
     454        float yP = (-B + sqrt (T)) / (2.0 * A);
     455        float yM = (-B - sqrt (T)) / (2.0 * A);
     456
     457        // Get the closest pixel positions (image frame)
     458        int xPix  = x  + PAR[PM_PAR_XPOS] - image->col0 + 0.5;
     459        int yPixM = yM + PAR[PM_PAR_YPOS] - image->row0 + 0.5;
     460        int yPixP = yP + PAR[PM_PAR_YPOS] - image->row0 + 0.5;
     461
     462        if (xPix < 0 || xPix >= image->numCols) {
     463            continue;
     464        }
     465
     466        if (yPixM >= 0 && yPixM < image->numRows &&
     467            !(mask && (mask->data.PS_TYPE_IMAGE_MASK_DATA[yPixM][xPix] & maskVal))) {
     468            float dSigma = image->data.F32[yPixM][xPix] / sqrtf(variance->data.F32[yPixM][xPix]);
     469            nSigma += dSigma;
     470            nPts++;
     471        }
     472
     473        if (yPixM == yPixP) {
     474            continue;
     475        }
     476
     477        if (yPixP >= 0 && yPixP < image->numRows &&
     478            !(mask && (mask->data.PS_TYPE_IMAGE_MASK_DATA[yPixP][xPix] & maskVal))) {
     479            float dSigma = image->data.F32[yPixP][xPix] / sqrtf(variance->data.F32[yPixP][xPix]);
     480            nSigma += dSigma;
     481            nPts++;
     482        }
    483483    }
    484484    nSigma /= nPts;
     
    491491    // XXX use an internal flag to mark sources which have already been measured
    492492    for (int i = 0; i < sources->n; i++) {
    493         pmSource *source = sources->data[i];
    494 
    495         // skip source if it was already measured
    496         if (source->tmpFlags & PM_SOURCE_TMPF_SIZE_MEASURED) {
    497             psTrace("psphot", 7, "Not calculating source size since it has already been measured\n");
    498             continue;
    499         }
    500 
    501         // source must have been subtracted
    502         if (!(source->tmpFlags & PM_SOURCE_TMPF_SUBTRACTED)) {
    503             source->mode |= PM_SOURCE_MODE_SIZE_SKIPPED;
    504             psTrace("psphot", 7, "Not calculating source size since source is not subtracted\n");
    505             continue;
    506         }
    507 
    508         psF32 **resid  = source->pixels->data.F32;
    509         psF32 **variance = source->variance->data.F32;
    510         psImageMaskType **mask = source->maskObj->data.PS_TYPE_IMAGE_MASK_DATA;
    511 
    512         // Integer position of peak
    513         int xPeak = source->peak->xf - source->pixels->col0 + 0.5;
    514         int yPeak = source->peak->yf - source->pixels->row0 + 0.5;
    515 
    516         // Skip sources which are too close to a boundary.  These are mostly caught as DEFECT
    517         if (xPeak < 1 || xPeak > source->pixels->numCols - 2 ||
    518             yPeak < 1 || yPeak > source->pixels->numRows - 2) {
    519             psTrace("psphot", 7, "Not calculating crNsigma due to edge\n");
    520             continue;
    521         }
    522 
    523         // Skip sources with masked pixels.  These are mostly caught as DEFECT
    524         bool keep = true;
    525         for (int iy = -1; (iy <= +1) && keep; iy++) {
    526             for (int ix = -1; (ix <= +1) && keep; ix++) {
    527                 if (mask[yPeak+iy][xPeak+ix] & options->maskVal) {
    528                     keep = false;
    529                 }
    530             }
    531         }
    532         if (!keep) {
    533             psTrace("psphot", 7, "Not calculating crNsigma due to masked pixels\n");
    534             continue;
    535         }
    536 
    537         // Compare the central pixel with those on either side, for the four possible lines through it.
    538 
    539         // Soften variances (add systematic error)
    540         float softening = options->soft * PS_SQR(source->peak->flux); // Softening for variances
    541 
    542         // Across the middle: y = 0
    543         float cX = 2*resid[yPeak][xPeak]   - resid[yPeak+0][xPeak-1]  - resid[yPeak+0][xPeak+1];
    544         float dcX = 4*variance[yPeak][xPeak] + variance[yPeak+0][xPeak-1] + variance[yPeak+0][xPeak+1];
    545         float nX = cX / sqrtf(dcX + softening);
    546 
    547         // Up the centre: x = 0
    548         float cY = 2*resid[yPeak][xPeak]   - resid[yPeak-1][xPeak+0]  - resid[yPeak+1][xPeak+0];
    549         float dcY = 4*variance[yPeak][xPeak] + variance[yPeak-1][xPeak+0] + variance[yPeak+1][xPeak+0];
    550         float nY = cY / sqrtf(dcY + softening);
    551 
    552         // Diagonal: x = y
    553         float cL = 2*resid[yPeak][xPeak]   - resid[yPeak-1][xPeak-1]  - resid[yPeak+1][xPeak+1];
    554         float dcL = 4*variance[yPeak][xPeak] + variance[yPeak-1][xPeak-1] + variance[yPeak+1][xPeak+1];
    555         float nL = cL / sqrtf(dcL + softening);
    556 
    557         // Diagonal: x = - y
    558         float cR = 2*resid[yPeak][xPeak]   - resid[yPeak+1][xPeak-1]  - resid[yPeak-1][xPeak+1];
    559         float dcR = 4*variance[yPeak][xPeak] + variance[yPeak+1][xPeak-1] + variance[yPeak-1][xPeak+1];
    560         float nR = cR / sqrtf(dcR + softening);
    561 
    562         // P(chisq > chisq_obs; Ndof) = gamma_Q (Ndof/2, chisq/2)
    563         // Ndof = 4 ? (four measurements, no free parameters)
    564         // XXX this value is going to be biased low because of systematic errors.
    565         // we need to calibrate it somehow
    566         // source->psfProb = gsl_sf_gamma_inc_Q (2, 0.5*chisq);
    567 
    568         // not strictly accurate: overcounts the chisq contribution from the center pixel (by
    569         // factor of 4); also biases a bit low if any pixels are masked
    570         // XXX I am not sure I want to keep this value...
    571         source->psfChisq = PS_SQR(nX) + PS_SQR(nY) + PS_SQR(nL) + PS_SQR(nR);
    572 
    573         float fCR = 0.0;
    574         int nCR = 0;
    575         if (nX > 0.0) {
    576             fCR += nX;
    577             nCR ++;
    578         }
    579         if (nY > 0.0) {
    580             fCR += nY;
    581             nCR ++;
    582         }
    583         if (nL > 0.0) {
    584             fCR += nL;
    585             nCR ++;
    586         }
    587         if (nR > 0.0) {
    588             fCR += nR;
    589             nCR ++;
    590         }
    591         source->crNsigma  = (nCR > 0)  ? fCR / nCR : 0.0;
    592         source->tmpFlags |= PM_SOURCE_TMPF_SIZE_MEASURED;
    593 
    594         if (!isfinite(source->crNsigma)) {
    595             continue;
    596         }
    597 
    598         // this source is thought to be a cosmic ray.  flag the detection and mask the pixels
    599         if (source->crNsigma > options->nSigmaCR) {
    600             source->mode |= PM_SOURCE_MODE_CR_LIMIT;
    601             // XXX still testing... : psphotMaskCosmicRay (readout->mask, source, maskVal, crMask);
    602             // XXX acting strange... psphotMaskCosmicRay_Old (source, maskVal, crMask);
    603         }
     493        pmSource *source = sources->data[i];
     494
     495        // skip source if it was already measured
     496        if (source->tmpFlags & PM_SOURCE_TMPF_SIZE_MEASURED) {
     497            psTrace("psphot", 7, "Not calculating source size since it has already been measured\n");
     498            continue;
     499        }
     500
     501        // source must have been subtracted
     502        if (!(source->tmpFlags & PM_SOURCE_TMPF_SUBTRACTED)) {
     503            source->mode |= PM_SOURCE_MODE_SIZE_SKIPPED;
     504            psTrace("psphot", 7, "Not calculating source size since source is not subtracted\n");
     505            continue;
     506        }
     507
     508        psF32 **resid  = source->pixels->data.F32;
     509        psF32 **variance = source->variance->data.F32;
     510        psImageMaskType **mask = source->maskObj->data.PS_TYPE_IMAGE_MASK_DATA;
     511
     512        // Integer position of peak
     513        int xPeak = source->peak->xf - source->pixels->col0 + 0.5;
     514        int yPeak = source->peak->yf - source->pixels->row0 + 0.5;
     515
     516        // Skip sources which are too close to a boundary.  These are mostly caught as DEFECT
     517        if (xPeak < 1 || xPeak > source->pixels->numCols - 2 ||
     518            yPeak < 1 || yPeak > source->pixels->numRows - 2) {
     519            psTrace("psphot", 7, "Not calculating crNsigma due to edge\n");
     520            continue;
     521        }
     522
     523        // Skip sources with masked pixels.  These are mostly caught as DEFECT
     524        bool keep = true;
     525        for (int iy = -1; (iy <= +1) && keep; iy++) {
     526            for (int ix = -1; (ix <= +1) && keep; ix++) {
     527                if (mask[yPeak+iy][xPeak+ix] & options->maskVal) {
     528                    keep = false;
     529                }
     530            }
     531        }
     532        if (!keep) {
     533            psTrace("psphot", 7, "Not calculating crNsigma due to masked pixels\n");
     534            continue;
     535        }
     536
     537        // Compare the central pixel with those on either side, for the four possible lines through it.
     538
     539        // Soften variances (add systematic error)
     540        float softening = options->soft * PS_SQR(source->peak->flux); // Softening for variances
     541
     542        // Across the middle: y = 0
     543        float cX = 2*resid[yPeak][xPeak]   - resid[yPeak+0][xPeak-1]  - resid[yPeak+0][xPeak+1];
     544        float dcX = 4*variance[yPeak][xPeak] + variance[yPeak+0][xPeak-1] + variance[yPeak+0][xPeak+1];
     545        float nX = cX / sqrtf(dcX + softening);
     546
     547        // Up the centre: x = 0
     548        float cY = 2*resid[yPeak][xPeak]   - resid[yPeak-1][xPeak+0]  - resid[yPeak+1][xPeak+0];
     549        float dcY = 4*variance[yPeak][xPeak] + variance[yPeak-1][xPeak+0] + variance[yPeak+1][xPeak+0];
     550        float nY = cY / sqrtf(dcY + softening);
     551
     552        // Diagonal: x = y
     553        float cL = 2*resid[yPeak][xPeak]   - resid[yPeak-1][xPeak-1]  - resid[yPeak+1][xPeak+1];
     554        float dcL = 4*variance[yPeak][xPeak] + variance[yPeak-1][xPeak-1] + variance[yPeak+1][xPeak+1];
     555        float nL = cL / sqrtf(dcL + softening);
     556
     557        // Diagonal: x = - y
     558        float cR = 2*resid[yPeak][xPeak]   - resid[yPeak+1][xPeak-1]  - resid[yPeak-1][xPeak+1];
     559        float dcR = 4*variance[yPeak][xPeak] + variance[yPeak+1][xPeak-1] + variance[yPeak-1][xPeak+1];
     560        float nR = cR / sqrtf(dcR + softening);
     561
     562        // P(chisq > chisq_obs; Ndof) = gamma_Q (Ndof/2, chisq/2)
     563        // Ndof = 4 ? (four measurements, no free parameters)
     564        // XXX this value is going to be biased low because of systematic errors.
     565        // we need to calibrate it somehow
     566        // source->psfProb = gsl_sf_gamma_inc_Q (2, 0.5*chisq);
     567
     568        // not strictly accurate: overcounts the chisq contribution from the center pixel (by
     569        // factor of 4); also biases a bit low if any pixels are masked
     570        // XXX I am not sure I want to keep this value...
     571        source->psfChisq = PS_SQR(nX) + PS_SQR(nY) + PS_SQR(nL) + PS_SQR(nR);
     572
     573        float fCR = 0.0;
     574        int nCR = 0;
     575        if (nX > 0.0) {
     576            fCR += nX;
     577            nCR ++;
     578        }
     579        if (nY > 0.0) {
     580            fCR += nY;
     581            nCR ++;
     582        }
     583        if (nL > 0.0) {
     584            fCR += nL;
     585            nCR ++;
     586        }
     587        if (nR > 0.0) {
     588            fCR += nR;
     589            nCR ++;
     590        }
     591        source->crNsigma  = (nCR > 0)  ? fCR / nCR : 0.0;
     592        source->tmpFlags |= PM_SOURCE_TMPF_SIZE_MEASURED;
     593
     594        if (!isfinite(source->crNsigma)) {
     595            continue;
     596        }
     597
     598        // this source is thought to be a cosmic ray.  flag the detection and mask the pixels
     599        if (source->crNsigma > options->nSigmaCR) {
     600            source->mode |= PM_SOURCE_MODE_CR_LIMIT;
     601            // XXX still testing... : psphotMaskCosmicRay (readout->mask, source, maskVal, crMask);
     602            // XXX acting strange... psphotMaskCosmicRay_Old (source, maskVal, crMask);
     603        }
    604604    }
    605605
    606606    // now that we have masked pixels associated with CRs, we can grow the mask
    607607    if (options->grow > 0) {
    608         bool oldThreads = psImageConvolveSetThreads(true); // Old value of threading for psImageConvolveMask
    609         psImage *newMask = psImageConvolveMask(NULL, readout->mask, options->crMask, options->crMask, -options->grow, options->grow, -options->grow, options->grow);
    610         psImageConvolveSetThreads(oldThreads);
    611         if (!newMask) {
    612             psError(PS_ERR_UNKNOWN, false, "Unable to grow CR mask");
    613             return false;
    614         }
    615         psFree(readout->mask);
    616         readout->mask = newMask;
     608        bool oldThreads = psImageConvolveSetThreads(true); // Old value of threading for psImageConvolveMask
     609        psImage *newMask = psImageConvolveMask(NULL, readout->mask, options->crMask, options->crMask, -options->grow, options->grow, -options->grow, options->grow);
     610        psImageConvolveSetThreads(oldThreads);
     611        if (!newMask) {
     612            psError(PS_ERR_UNKNOWN, false, "Unable to grow CR mask");
     613            return false;
     614        }
     615        psFree(readout->mask);
     616        readout->mask = newMask;
    617617    }
    618618    return true;
  • branches/eam_branches/20090820/psphot/src/psphotSourceStats.c

    r25766 r25870  
    11# include "psphotInternal.h"
    22
    3 bool psphotSetMomentsWindow (psMetadata *recipe, psArray *sources);
     3bool psphotSetMomentsWindow (psMetadata *recipe, psMetadata *analysis, psArray *sources);
    44
    55psArray *psphotSourceStats (pmConfig *config, pmReadout *readout, pmDetections *detections, bool setWindow) {
     
    6868
    6969    if (setWindow) {
    70         if (!psphotSetMomentsWindow(recipe, sources)) {
    71             psError(PS_ERR_UNEXPECTED_NULL, false, "Failed to determine Moments Window!");
    72             return NULL;
    73         }
     70        if (!psphotSetMomentsWindow(recipe, readout->analysis, sources)) {
     71            psError(PS_ERR_UNEXPECTED_NULL, false, "Failed to determine Moments Window!");
     72            return NULL;
     73        }
    7474    }
    7575
     
    242242
    243243// this function attempts to iteratively determine the best value for sigma of the moments weighting Gaussian
    244 bool psphotSetMomentsWindow (psMetadata *recipe, psArray *sources) {
     244bool psphotSetMomentsWindow (psMetadata *recipe, psMetadata *analysis, psArray *sources) {
    245245
    246246    bool status;
     
    259259    for (int i = 0; i < 4; i++) {
    260260
    261         // XXX move max source number to config
    262         for (int j = 0; (j < sources->n) && (j < 400); j++) {
    263  
    264             pmSource *source = sources->data[j];
    265             psAssert (source->moments, "force moments to exist");
    266             source->moments->nPixels = 0;
    267 
    268             // skip faint sources for moments measurement
    269             if (source->peak->SN < MIN_SN) {
    270                 continue;
    271             }
    272 
    273             // measure basic source moments (no S/N clipping on input pixels)
    274             status = pmSourceMoments (source, 4*sigma[i], sigma[i], 0.0);
    275         }
    276 
    277         // choose a grid scale that is a fixed fraction of the psf sigma^2
    278         psMetadataAddF32(recipe, PS_LIST_TAIL, "PSF_CLUMP_GRID_SCALE", PS_META_REPLACE, "clump grid", 0.1*PS_SQR(sigma[i]));
    279         psMetadataAddF32(recipe, PS_LIST_TAIL, "MOMENTS_SX_MAX", PS_META_REPLACE, "moments limit", 2.0*PS_SQR(sigma[i]));
    280         psMetadataAddF32(recipe, PS_LIST_TAIL, "MOMENTS_SY_MAX", PS_META_REPLACE, "moments limit", 2.0*PS_SQR(sigma[i]));
    281 
    282         // determine the PSF parameters from the source moment values
    283         pmPSFClump psfClump = pmSourcePSFClump (NULL, sources, recipe);
    284         psLogMsg ("psphot", 3, "radius %.1f, nStars: %d, nSigma: %5.2f, X,  Y: %f, %f (%f, %f)\n", sigma[i], psfClump.nStars, psfClump.nSigma, psfClump.X, psfClump.Y, sqrt(psfClump.X) / sigma[i], sqrt(psfClump.Y) / sigma[i]);
    285 
    286         psMetadataAddS32 (recipe, PS_LIST_TAIL, "PSF.CLUMP.NREGIONS",  PS_META_REPLACE, "psf clump regions", 1);
    287         psMetadata *regionMD = psMetadataLookupPtr (&status, recipe, "PSF.CLUMP.REGION.000");
    288         if (!regionMD) {
    289             regionMD = psMetadataAlloc();
    290             psMetadataAddMetadata (recipe, PS_LIST_TAIL, "PSF.CLUMP.REGION.000", PS_META_REPLACE, "psf clump region", regionMD);
    291             psFree (regionMD);
    292         }
    293         psMetadataAddF32 (regionMD, PS_LIST_TAIL, "PSF.CLUMP.X",  PS_META_REPLACE, "psf clump center", psfClump.X);
    294         psMetadataAddF32 (regionMD, PS_LIST_TAIL, "PSF.CLUMP.Y",  PS_META_REPLACE, "psf clump center", psfClump.Y);
    295         psMetadataAddF32 (regionMD, PS_LIST_TAIL, "PSF.CLUMP.DX", PS_META_REPLACE, "psf clump center", psfClump.dX);
    296         psMetadataAddF32 (regionMD, PS_LIST_TAIL, "PSF.CLUMP.DY", PS_META_REPLACE, "psf clump center", psfClump.dY);
    297            
    298         // psphotVisualPlotMoments (recipe, sources);
    299 
    300         Sout[i] = sqrt(0.5*(psfClump.X + psfClump.Y)) / sigma[i];
     261        // XXX move max source number to config
     262        for (int j = 0; (j < sources->n) && (j < 400); j++) {
     263
     264            pmSource *source = sources->data[j];
     265            psAssert (source->moments, "force moments to exist");
     266            source->moments->nPixels = 0;
     267
     268            // skip faint sources for moments measurement
     269            if (source->peak->SN < MIN_SN) {
     270                continue;
     271            }
     272
     273            // measure basic source moments (no S/N clipping on input pixels)
     274            status = pmSourceMoments (source, 4*sigma[i], sigma[i], 0.0);
     275        }
     276
     277        // choose a grid scale that is a fixed fraction of the psf sigma^2
     278        psMetadataAddF32(recipe, PS_LIST_TAIL, "PSF_CLUMP_GRID_SCALE", PS_META_REPLACE, "clump grid", 0.1*PS_SQR(sigma[i]));
     279        psMetadataAddF32(recipe, PS_LIST_TAIL, "MOMENTS_SX_MAX", PS_META_REPLACE, "moments limit", 2.0*PS_SQR(sigma[i]));
     280        psMetadataAddF32(recipe, PS_LIST_TAIL, "MOMENTS_SY_MAX", PS_META_REPLACE, "moments limit", 2.0*PS_SQR(sigma[i]));
     281
     282        // determine the PSF parameters from the source moment values
     283        pmPSFClump psfClump = pmSourcePSFClump (NULL, sources, recipe);
     284        psLogMsg ("psphot", 3, "radius %.1f, nStars: %d, nSigma: %5.2f, X,  Y: %f, %f (%f, %f)\n", sigma[i], psfClump.nStars, psfClump.nSigma, psfClump.X, psfClump.Y, sqrt(psfClump.X) / sigma[i], sqrt(psfClump.Y) / sigma[i]);
     285
     286        psMetadataAddS32 (analysis, PS_LIST_TAIL, "PSF.CLUMP.NREGIONS",  PS_META_REPLACE, "psf clump regions", 1);
     287        psMetadata *regionMD = psMetadataLookupPtr (&status, analysis, "PSF.CLUMP.REGION.000");
     288        if (!regionMD) {
     289            regionMD = psMetadataAlloc();
     290            psMetadataAddMetadata (analysis, PS_LIST_TAIL, "PSF.CLUMP.REGION.000", PS_META_REPLACE, "psf clump region", regionMD);
     291            psFree (regionMD);
     292        }
     293        psMetadataAddF32 (regionMD, PS_LIST_TAIL, "PSF.CLUMP.X",  PS_META_REPLACE, "psf clump center", psfClump.X);
     294        psMetadataAddF32 (regionMD, PS_LIST_TAIL, "PSF.CLUMP.Y",  PS_META_REPLACE, "psf clump center", psfClump.Y);
     295        psMetadataAddF32 (regionMD, PS_LIST_TAIL, "PSF.CLUMP.DX", PS_META_REPLACE, "psf clump center", psfClump.dX);
     296        psMetadataAddF32 (regionMD, PS_LIST_TAIL, "PSF.CLUMP.DY", PS_META_REPLACE, "psf clump center", psfClump.dY);
     297
     298        // psphotVisualPlotMoments (recipe, sources);
     299
     300        Sout[i] = sqrt(0.5*(psfClump.X + psfClump.Y)) / sigma[i];
    301301    }
    302302
     
    307307    float maxS = Sout[0];
    308308    for (int i = 0; i < 4; i++) {
    309         minS = PS_MIN(Sout[i], minS);
    310         maxS = PS_MAX(Sout[i], maxS);
     309        minS = PS_MIN(Sout[i], minS);
     310        maxS = PS_MAX(Sout[i], maxS);
    311311    }
    312312    if (minS > 0.65) Sigma = sigma[3];
     
    314314
    315315    for (int i = 0; i < 3; i++) {
    316         if ((Sout[i] > 0.65) && (Sout[i+1] > 0.65)) continue;
    317         if ((Sout[i] < 0.65) && (Sout[i+1] < 0.65)) continue;
    318         Sigma = sigma[i] + (0.65 - Sout[i])*(sigma[i+1] - sigma[i])/(Sout[i+1] - Sout[i]);
     316        if ((Sout[i] > 0.65) && (Sout[i+1] > 0.65)) continue;
     317        if ((Sout[i] < 0.65) && (Sout[i+1] < 0.65)) continue;
     318        Sigma = sigma[i] + (0.65 - Sout[i])*(sigma[i+1] - sigma[i])/(Sout[i+1] - Sout[i]);
    319319    }
    320320    psAssert (isfinite(Sigma), "did we miss a case?");
    321        
     321
    322322    // choose a grid scale that is a fixed fraction of the psf sigma^2
    323323    psMetadataAddF32(recipe, PS_LIST_TAIL, "PSF_CLUMP_GRID_SCALE", PS_META_REPLACE, "clump grid", 0.1*PS_SQR(Sigma));
  • branches/eam_branches/20090820/psphot/src/psphotVisual.c

    r25766 r25870  
    2828    switch (channel) {
    2929      case 1:
    30         if (kapa1 == -1) {
    31             kapa1 = KapaOpenNamedSocket ("kapa", "psphot:images");
    32             if (kapa1 == -1) {
    33                 fprintf (stderr, "failure to open kapa; visual mode disabled\n");
    34                 pmVisualSetVisual(false);
    35             }
    36         }
    37         return kapa1;
     30        if (kapa1 == -1) {
     31            kapa1 = KapaOpenNamedSocket ("kapa", "psphot:images");
     32            if (kapa1 == -1) {
     33                fprintf (stderr, "failure to open kapa; visual mode disabled\n");
     34                pmVisualSetVisual(false);
     35            }
     36        }
     37        return kapa1;
    3838      case 2:
    39         if (kapa2 == -1) {
    40             kapa2 = KapaOpenNamedSocket ("kapa", "psphot:plots");
    41             if (kapa2 == -1) {
    42                 fprintf (stderr, "failure to open kapa; visual mode disabled\n");
    43                 pmVisualSetVisual(false);
    44             }
    45         }
    46         return kapa2;
     39        if (kapa2 == -1) {
     40            kapa2 = KapaOpenNamedSocket ("kapa", "psphot:plots");
     41            if (kapa2 == -1) {
     42                fprintf (stderr, "failure to open kapa; visual mode disabled\n");
     43                pmVisualSetVisual(false);
     44            }
     45        }
     46        return kapa2;
    4747      case 3:
    48         if (kapa3 == -1) {
    49             kapa3 = KapaOpenNamedSocket ("kapa", "psphot:stamps");
    50             if (kapa3 == -1) {
    51                 fprintf (stderr, "failure to open kapa; visual mode disabled\n");
    52                 pmVisualSetVisual(false);
    53             }
    54         }
    55         return kapa3;
     48        if (kapa3 == -1) {
     49            kapa3 = KapaOpenNamedSocket ("kapa", "psphot:stamps");
     50            if (kapa3 == -1) {
     51                fprintf (stderr, "failure to open kapa; visual mode disabled\n");
     52                pmVisualSetVisual(false);
     53            }
     54        }
     55        return kapa3;
    5656      default:
    57         psAbort ("unknown kapa channel");
     57        psAbort ("unknown kapa channel");
    5858    }
    5959    psAbort ("unknown kapa channel");
     
    315315
    316316        // draw the top
    317         // XXX need to allow top (and bottom) to have more than one span
     317        // XXX need to allow top (and bottom) to have more than one span
    318318        span = footprint->spans->data[0];
    319319        overlay[Noverlay].type = KII_OVERLAY_LINE;
     
    448448}
    449449
    450 bool psphotVisualPlotMoments (psMetadata *recipe, psArray *sources) {
     450bool psphotVisualPlotMoments (psMetadata *recipe, psMetadata *analysis, psArray *sources) {
    451451
    452452    bool status;
     
    469469    float Ymin = 1000.0, Ymax = 0.0;
    470470    {
    471         int nRegions = psMetadataLookupS32 (&status, recipe, "PSF.CLUMP.NREGIONS");
     471        int nRegions = psMetadataLookupS32 (&status, analysis, "PSF.CLUMP.NREGIONS");
    472472        for (int n = 0; n < nRegions; n++) {
    473473
    474474            char regionName[64];
    475475            snprintf (regionName, 64, "PSF.CLUMP.REGION.%03d", n);
    476             psMetadata *regionMD = psMetadataLookupPtr (&status, recipe, regionName);
    477 
    478             float psfX = psMetadataLookupF32 (&status, regionMD, "PSF.CLUMP.X");
     476            psMetadata *regionMD = psMetadataLookupPtr (&status, analysis, regionName);
     477
     478            float psfX = psMetadataLookupF32 (&status, regionMD, "PSF.CLUMP.X");
    479479            float psfY = psMetadataLookupF32 (&status, regionMD, "PSF.CLUMP.Y");
    480480            float psfdX = psMetadataLookupF32 (&status, regionMD, "PSF.CLUMP.DX");
    481481            float psfdY = psMetadataLookupF32 (&status, regionMD, "PSF.CLUMP.DY");
    482482
    483             float X0 = psfX - 4.0*psfdX;
    484             float X1 = psfX + 4.0*psfdX;
    485             float Y0 = psfY - 4.0*psfdY;
    486             float Y1 = psfY + 4.0*psfdY;
    487 
    488             if (isfinite(X0)) { Xmin = PS_MIN(Xmin, X0); }
    489             if (isfinite(X1)) { Xmax = PS_MAX(Xmax, X1); }
    490             if (isfinite(Y0)) { Ymin = PS_MIN(Ymin, Y0); }
    491             if (isfinite(Y1)) { Ymax = PS_MAX(Ymax, Y1); }
    492         }
    493     }
    494     Xmin = PS_MAX(Xmin, -0.1); 
    495     Ymin = PS_MAX(Ymin, -0.1); 
     483            float X0 = psfX - 4.0*psfdX;
     484            float X1 = psfX + 4.0*psfdX;
     485            float Y0 = psfY - 4.0*psfdY;
     486            float Y1 = psfY + 4.0*psfdY;
     487
     488            if (isfinite(X0)) { Xmin = PS_MIN(Xmin, X0); }
     489            if (isfinite(X1)) { Xmax = PS_MAX(Xmax, X1); }
     490            if (isfinite(Y0)) { Ymin = PS_MIN(Ymin, Y0); }
     491            if (isfinite(Y1)) { Ymax = PS_MAX(Ymax, Y1); }
     492        }
     493    }
     494    Xmin = PS_MAX(Xmin, -0.1);
     495    Ymin = PS_MAX(Ymin, -0.1);
    496496
    497497    // storage vectors for data to be plotted
     
    653653        psVector *yLimit  = psVectorAlloc (120, PS_TYPE_F32);
    654654
    655         int nRegions = psMetadataLookupS32 (&status, recipe, "PSF.CLUMP.NREGIONS");
    656         float PSF_CLUMP_NSIGMA = psMetadataLookupF32 (&status, recipe, "PSF_CLUMP_NSIGMA");
     655        int nRegions = psMetadataLookupS32 (&status, analysis, "PSF.CLUMP.NREGIONS");
     656        float PSF_CLUMP_NSIGMA = psMetadataLookupF32 (&status, analysis, "PSF_CLUMP_NSIGMA");
    657657
    658658        graphdata.color = KapaColorByName ("blue");
    659659        graphdata.style = 0;
    660660
    661         graphdata.xmin = Xmin;
    662         graphdata.ymin = Ymin;
    663         graphdata.xmax = Xmax;
    664         graphdata.ymax = Ymax;
    665         KapaSetLimits (myKapa, &graphdata);
     661        graphdata.xmin = Xmin;
     662        graphdata.ymin = Ymin;
     663        graphdata.xmax = Xmax;
     664        graphdata.ymax = Ymax;
     665        KapaSetLimits (myKapa, &graphdata);
    666666
    667667        for (int n = 0; n < nRegions; n++) {
     
    669669            char regionName[64];
    670670            snprintf (regionName, 64, "PSF.CLUMP.REGION.%03d", n);
    671             psMetadata *regionMD = psMetadataLookupPtr (&status, recipe, regionName);
     671            psMetadata *regionMD = psMetadataLookupPtr (&status, analysis, regionName);
    672672
    673673            float psfX  = psMetadataLookupF32 (&status, regionMD, "PSF.CLUMP.X");
     
    926926            if (Xo == 0) {
    927927                // place source alone on this row
    928                 bool subtracted = (source->tmpFlags & PM_SOURCE_TMPF_SUBTRACTED);
    929                 if (subtracted) pmSourceAdd (source, PM_MODEL_OP_FULL, maskVal);
     928                bool subtracted = (source->tmpFlags & PM_SOURCE_TMPF_SUBTRACTED);
     929                if (subtracted) pmSourceAdd (source, PM_MODEL_OP_FULL, maskVal);
    930930                psphotMosaicSubimage (outpos, source, Xo, Yo, DX, DY, true);
    931931
    932                 pmSourceSub (source, PM_MODEL_OP_FULL, maskVal);
     932                pmSourceSub (source, PM_MODEL_OP_FULL, maskVal);
    933933                psphotMosaicSubimage (outsub, source, Xo, Yo, DX, DY, true);
    934934
    935                 if (!subtracted) pmSourceAdd (source, PM_MODEL_OP_FULL, maskVal);
     935                if (!subtracted) pmSourceAdd (source, PM_MODEL_OP_FULL, maskVal);
    936936
    937937                Yo += DY;
     
    943943                Xo = 0;
    944944
    945                 bool subtracted = (source->tmpFlags & PM_SOURCE_TMPF_SUBTRACTED);
    946                 if (subtracted) pmSourceAdd (source, PM_MODEL_OP_FULL, maskVal);
     945                bool subtracted = (source->tmpFlags & PM_SOURCE_TMPF_SUBTRACTED);
     946                if (subtracted) pmSourceAdd (source, PM_MODEL_OP_FULL, maskVal);
    947947                psphotMosaicSubimage (outpos, source, Xo, Yo, DX, DY, true);
    948948
    949                 pmSourceSub (source, PM_MODEL_OP_FULL, maskVal);
     949                pmSourceSub (source, PM_MODEL_OP_FULL, maskVal);
    950950                psphotMosaicSubimage (outsub, source, Xo, Yo, DX, DY, true);
    951951
    952                 if (!subtracted) pmSourceAdd (source, PM_MODEL_OP_FULL, maskVal);
     952                if (!subtracted) pmSourceAdd (source, PM_MODEL_OP_FULL, maskVal);
    953953
    954954                Xo = DX;
     
    957957        } else {
    958958            // extend this row
    959             bool subtracted = (source->tmpFlags & PM_SOURCE_TMPF_SUBTRACTED);
    960             if (subtracted) pmSourceAdd (source, PM_MODEL_OP_FULL, maskVal);
     959            bool subtracted = (source->tmpFlags & PM_SOURCE_TMPF_SUBTRACTED);
     960            if (subtracted) pmSourceAdd (source, PM_MODEL_OP_FULL, maskVal);
    961961            psphotMosaicSubimage (outpos, source, Xo, Yo, DX, DY, true);
    962962
    963             pmSourceSub (source, PM_MODEL_OP_FULL, maskVal);
     963            pmSourceSub (source, PM_MODEL_OP_FULL, maskVal);
    964964            psphotMosaicSubimage (outsub, source, Xo, Yo, DX, DY, true);
    965             if (!subtracted) pmSourceAdd (source, PM_MODEL_OP_FULL, maskVal);
     965            if (!subtracted) pmSourceAdd (source, PM_MODEL_OP_FULL, maskVal);
    966966
    967967            Xo += DX;
     
    10201020        pmSource *source = sources->data[i];
    10211021
    1022         // only show "real" saturated stars (not defects)
     1022        // only show "real" saturated stars (not defects)
    10231023        if (!(source->mode & PM_SOURCE_MODE_SATSTAR)) continue;;
    10241024        if (source->mode & PM_SOURCE_MODE_DEFECT) continue;;
     
    10651065        pmSource *source = sources->data[i];
    10661066
    1067         // only show "real" saturated stars (not defects)
     1067        // only show "real" saturated stars (not defects)
    10681068        if (!(source->mode & PM_SOURCE_MODE_SATSTAR)) continue;;
    10691069        if (source->mode & PM_SOURCE_MODE_DEFECT) continue;;
    1070         nSAT ++;
     1070        nSAT ++;
    10711071
    10721072        if (Xo + DX > NX) {
     
    10741074            if (Xo == 0) {
    10751075                // place source alone on this row
    1076                 bool subtracted = (source->tmpFlags & PM_SOURCE_TMPF_SUBTRACTED);
    1077                 if (subtracted) pmSourceAdd (source, PM_MODEL_OP_FULL, maskVal);
     1076                bool subtracted = (source->tmpFlags & PM_SOURCE_TMPF_SUBTRACTED);
     1077                if (subtracted) pmSourceAdd (source, PM_MODEL_OP_FULL, maskVal);
    10781078                psphotMosaicSubimage (outsat, source, Xo, Yo, DX, DY, false);
    1079                 if (subtracted) pmSourceSub (source, PM_MODEL_OP_FULL, maskVal);
     1079                if (subtracted) pmSourceSub (source, PM_MODEL_OP_FULL, maskVal);
    10801080
    10811081                Yo += DY;
     
    10871087                Xo = 0;
    10881088
    1089                 bool subtracted = (source->tmpFlags & PM_SOURCE_TMPF_SUBTRACTED);
    1090                 if (subtracted) pmSourceAdd (source, PM_MODEL_OP_FULL, maskVal);
     1089                bool subtracted = (source->tmpFlags & PM_SOURCE_TMPF_SUBTRACTED);
     1090                if (subtracted) pmSourceAdd (source, PM_MODEL_OP_FULL, maskVal);
    10911091                psphotMosaicSubimage (outsat, source, Xo, Yo, DX, DY, false);
    1092                 if (subtracted) pmSourceSub (source, PM_MODEL_OP_FULL, maskVal);
     1092                if (subtracted) pmSourceSub (source, PM_MODEL_OP_FULL, maskVal);
    10931093
    10941094                Xo = DX;
     
    10971097        } else {
    10981098            // extend this row
    1099             bool subtracted = (source->tmpFlags & PM_SOURCE_TMPF_SUBTRACTED);
    1100             if (subtracted) pmSourceAdd (source, PM_MODEL_OP_FULL, maskVal);
     1099            bool subtracted = (source->tmpFlags & PM_SOURCE_TMPF_SUBTRACTED);
     1100            if (subtracted) pmSourceAdd (source, PM_MODEL_OP_FULL, maskVal);
    11011101            psphotMosaicSubimage (outsat, source, Xo, Yo, DX, DY, false);
    1102             if (subtracted) pmSourceSub (source, PM_MODEL_OP_FULL, maskVal);
     1102            if (subtracted) pmSourceSub (source, PM_MODEL_OP_FULL, maskVal);
    11031103
    11041104            Xo += DX;
     
    14061406
    14071407        // if (source->type != type) continue;
    1408         if (mode) {
    1409             if (keep) {
    1410                 if (!(source->mode & mode)) continue;
    1411             } else {
    1412                 if (source->mode & mode) continue;
    1413             }
    1414         }
     1408        if (mode) {
     1409            if (keep) {
     1410                if (!(source->mode & mode)) continue;
     1411            } else {
     1412                if (source->mode & mode) continue;
     1413            }
     1414        }
    14151415
    14161416        pmMoments *moments = source->moments;
     
    14631463}
    14641464
    1465 bool psphotVisualPlotSourceSize (psMetadata *recipe, psArray *sources) {
     1465bool psphotVisualPlotSourceSize (psMetadata *recipe, psMetadata *analysis, psArray *sources) {
    14661466
    14671467    bool status;
     
    14821482    float Ymin = 1000.0, Ymax = 0.0;
    14831483    {
    1484         int nRegions = psMetadataLookupS32 (&status, recipe, "PSF.CLUMP.NREGIONS");
     1484        int nRegions = psMetadataLookupS32 (&status, analysis, "PSF.CLUMP.NREGIONS");
    14851485        for (int n = 0; n < nRegions; n++) {
    14861486
    14871487            char regionName[64];
    14881488            snprintf (regionName, 64, "PSF.CLUMP.REGION.%03d", n);
    1489             psMetadata *regionMD = psMetadataLookupPtr (&status, recipe, regionName);
    1490 
    1491             float psfX = psMetadataLookupF32 (&status, regionMD, "PSF.CLUMP.X");
     1489            psMetadata *regionMD = psMetadataLookupPtr (&status, analysis, regionName);
     1490
     1491            float psfX = psMetadataLookupF32 (&status, regionMD, "PSF.CLUMP.X");
    14921492            float psfY = psMetadataLookupF32 (&status, regionMD, "PSF.CLUMP.Y");
    14931493            float psfdX = psMetadataLookupF32 (&status, regionMD, "PSF.CLUMP.DX");
    14941494            float psfdY = psMetadataLookupF32 (&status, regionMD, "PSF.CLUMP.DY");
    14951495
    1496             float X0 = psfX - 10.0*psfdX;
    1497             float X1 = psfX + 10.0*psfdX;
    1498             float Y0 = psfY - 10.0*psfdY;
    1499             float Y1 = psfY + 10.0*psfdY;
    1500 
    1501             if (isfinite(X0)) { Xmin = PS_MIN(Xmin, X0); }
    1502             if (isfinite(X1)) { Xmax = PS_MAX(Xmax, X1); }
    1503             if (isfinite(Y0)) { Ymin = PS_MIN(Ymin, Y0); }
    1504             if (isfinite(Y1)) { Ymax = PS_MAX(Ymax, Y1); }
    1505         }
    1506     }
    1507     Xmin = PS_MAX(Xmin, -0.1); 
    1508     Ymin = PS_MAX(Ymin, -0.1); 
     1496            float X0 = psfX - 10.0*psfdX;
     1497            float X1 = psfX + 10.0*psfdX;
     1498            float Y0 = psfY - 10.0*psfdY;
     1499            float Y1 = psfY + 10.0*psfdY;
     1500
     1501            if (isfinite(X0)) { Xmin = PS_MIN(Xmin, X0); }
     1502            if (isfinite(X1)) { Xmax = PS_MAX(Xmax, X1); }
     1503            if (isfinite(Y0)) { Ymin = PS_MIN(Ymin, Y0); }
     1504            if (isfinite(Y1)) { Ymax = PS_MAX(Ymax, Y1); }
     1505        }
     1506    }
     1507    Xmin = PS_MAX(Xmin, -0.1);
     1508    Ymin = PS_MAX(Ymin, -0.1);
    15091509
    15101510    // storage vectors for data to be plotted
     
    15441544        if (source->moments == NULL) continue;
    15451545
    1546         if (source->mode & PM_SOURCE_MODE_CR_LIMIT) {
    1547             xCR->data.F32[nCR] = source->moments->Mxx;
    1548             yCR->data.F32[nCR] = source->moments->Myy;
    1549             mCR->data.F32[nCR] = -2.5*log10(source->moments->Sum);
    1550             sCR->data.F32[nCR] = source->extNsigma;
    1551             nCR++;
    1552         }
    1553         if (source->mode & PM_SOURCE_MODE_SATSTAR) {
    1554             xSAT->data.F32[nSAT] = source->moments->Mxx;
    1555             ySAT->data.F32[nSAT] = source->moments->Myy;
    1556             mSAT->data.F32[nSAT] = -2.5*log10(source->moments->Sum);
    1557             sSAT->data.F32[nSAT] = source->extNsigma;
    1558             nSAT++;
    1559         }
    1560         if (source->mode & PM_SOURCE_MODE_EXT_LIMIT) {
    1561             xEXT->data.F32[nEXT] = source->moments->Mxx;
    1562             yEXT->data.F32[nEXT] = source->moments->Myy;
    1563             mEXT->data.F32[nEXT] = -2.5*log10(source->moments->Sum);
    1564             sEXT->data.F32[nEXT] = source->extNsigma;
    1565             nEXT++;
    1566             continue;
    1567         }
    1568         if (source->mode & PM_SOURCE_MODE_DEFECT) {
    1569             xDEF->data.F32[nDEF] = source->moments->Mxx;
    1570             yDEF->data.F32[nDEF] = source->moments->Myy;
    1571             mDEF->data.F32[nDEF] = -2.5*log10(source->moments->Sum);
    1572             sDEF->data.F32[nDEF] = source->extNsigma;
    1573             nDEF++;
    1574             continue;
    1575         }
    1576         if ((source->mode & PM_SOURCE_MODE_CR_LIMIT) || (source->mode & PM_SOURCE_MODE_SATSTAR)) {
    1577             continue;
    1578         }
    1579         xPSF->data.F32[nPSF] = source->moments->Mxx;
    1580         yPSF->data.F32[nPSF] = source->moments->Myy;
    1581         mPSF->data.F32[nPSF] = -2.5*log10(source->moments->Sum);
    1582         sPSF->data.F32[nPSF] = source->extNsigma;
    1583         nPSF++;
     1546        if (source->mode & PM_SOURCE_MODE_CR_LIMIT) {
     1547            xCR->data.F32[nCR] = source->moments->Mxx;
     1548            yCR->data.F32[nCR] = source->moments->Myy;
     1549            mCR->data.F32[nCR] = -2.5*log10(source->moments->Sum);
     1550            sCR->data.F32[nCR] = source->extNsigma;
     1551            nCR++;
     1552        }
     1553        if (source->mode & PM_SOURCE_MODE_SATSTAR) {
     1554            xSAT->data.F32[nSAT] = source->moments->Mxx;
     1555            ySAT->data.F32[nSAT] = source->moments->Myy;
     1556            mSAT->data.F32[nSAT] = -2.5*log10(source->moments->Sum);
     1557            sSAT->data.F32[nSAT] = source->extNsigma;
     1558            nSAT++;
     1559        }
     1560        if (source->mode & PM_SOURCE_MODE_EXT_LIMIT) {
     1561            xEXT->data.F32[nEXT] = source->moments->Mxx;
     1562            yEXT->data.F32[nEXT] = source->moments->Myy;
     1563            mEXT->data.F32[nEXT] = -2.5*log10(source->moments->Sum);
     1564            sEXT->data.F32[nEXT] = source->extNsigma;
     1565            nEXT++;
     1566            continue;
     1567        }
     1568        if (source->mode & PM_SOURCE_MODE_DEFECT) {
     1569            xDEF->data.F32[nDEF] = source->moments->Mxx;
     1570            yDEF->data.F32[nDEF] = source->moments->Myy;
     1571            mDEF->data.F32[nDEF] = -2.5*log10(source->moments->Sum);
     1572            sDEF->data.F32[nDEF] = source->extNsigma;
     1573            nDEF++;
     1574            continue;
     1575        }
     1576        if ((source->mode & PM_SOURCE_MODE_CR_LIMIT) || (source->mode & PM_SOURCE_MODE_SATSTAR)) {
     1577            continue;
     1578        }
     1579        xPSF->data.F32[nPSF] = source->moments->Mxx;
     1580        yPSF->data.F32[nPSF] = source->moments->Myy;
     1581        mPSF->data.F32[nPSF] = -2.5*log10(source->moments->Sum);
     1582        sPSF->data.F32[nPSF] = source->extNsigma;
     1583        nPSF++;
    15841584    }
    15851585    xSAT->n = nSAT;
     
    18611861        psVector *yLimit  = psVectorAlloc (120, PS_TYPE_F32);
    18621862
    1863         int nRegions = psMetadataLookupS32 (&status, recipe, "PSF.CLUMP.NREGIONS");
    1864         float PSF_CLUMP_NSIGMA = psMetadataLookupF32 (&status, recipe, "PSF_CLUMP_NSIGMA");
     1863        int nRegions = psMetadataLookupS32 (&status, analysis, "PSF.CLUMP.NREGIONS");
     1864        float PSF_CLUMP_NSIGMA = psMetadataLookupF32 (&status, analysis, "PSF_CLUMP_NSIGMA");
    18651865
    18661866        graphdata.color = KapaColorByName ("blue");
    18671867        graphdata.style = 0;
    18681868
    1869         graphdata.xmin = Xmin;
    1870         graphdata.ymin = Ymin;
    1871         graphdata.xmax = Xmax;
    1872         graphdata.ymax = Ymax;
    1873         KapaSetLimits (myKapa, &graphdata);
     1869        graphdata.xmin = Xmin;
     1870        graphdata.ymin = Ymin;
     1871        graphdata.xmax = Xmax;
     1872        graphdata.ymax = Ymax;
     1873        KapaSetLimits (myKapa, &graphdata);
    18741874
    18751875        for (int n = 0; n < nRegions; n++) {
     
    18771877            char regionName[64];
    18781878            snprintf (regionName, 64, "PSF.CLUMP.REGION.%03d", n);
    1879             psMetadata *regionMD = psMetadataLookupPtr (&status, recipe, regionName);
     1879            psMetadata *regionMD = psMetadataLookupPtr (&status, analysis, regionName);
    18801880
    18811881            float psfX  = psMetadataLookupF32 (&status, regionMD, "PSF.CLUMP.X");
     
    20692069
    20702070    for (int i = 0; i < sources->n; i++) {
    2071         pmSource *source = sources->data[i];
    2072 
    2073         if (!source) continue;
    2074         if (!source->extpars) continue;
    2075         if (!source->extpars->profile) continue;
    2076         if (!source->extpars->petrosian_80) continue;
    2077 
    2078         pmSourceRadialProfile *profile = source->extpars->profile;
    2079         pmSourceExtendedFlux *petrosian = source->extpars->petrosian_80;
    2080 
    2081         overlay[Noverlay].type = KII_OVERLAY_CIRCLE;
    2082         overlay[Noverlay].x = source->peak->xf;
    2083         overlay[Noverlay].y = source->peak->yf;
    2084         overlay[Noverlay].dx = 2.0*petrosian->radius;
    2085         overlay[Noverlay].dy = 2.0*petrosian->radius*profile->axes.minor/profile->axes.major;
    2086         overlay[Noverlay].angle = profile->axes.theta * PS_DEG_RAD;
    2087         overlay[Noverlay].text = NULL;
    2088         Noverlay ++;
     2071        pmSource *source = sources->data[i];
     2072
     2073        if (!source) continue;
     2074        if (!source->extpars) continue;
     2075        if (!source->extpars->profile) continue;
     2076        if (!source->extpars->petrosian_80) continue;
     2077
     2078        pmSourceRadialProfile *profile = source->extpars->profile;
     2079        pmSourceExtendedFlux *petrosian = source->extpars->petrosian_80;
     2080
     2081        overlay[Noverlay].type = KII_OVERLAY_CIRCLE;
     2082        overlay[Noverlay].x = source->peak->xf;
     2083        overlay[Noverlay].y = source->peak->yf;
     2084        overlay[Noverlay].dx = 2.0*petrosian->radius;
     2085        overlay[Noverlay].dy = 2.0*petrosian->radius*profile->axes.minor/profile->axes.major;
     2086        overlay[Noverlay].angle = profile->axes.theta * PS_DEG_RAD;
     2087        overlay[Noverlay].text = NULL;
     2088        Noverlay ++;
    20892089        CHECK_REALLOCATE (overlay, KiiOverlay, NOVERLAY, Noverlay, 100);
    20902090
    2091         overlay[Noverlay].type = KII_OVERLAY_CIRCLE;
    2092         overlay[Noverlay].x = source->peak->xf;
    2093         overlay[Noverlay].y = source->peak->yf;
    2094         overlay[Noverlay].dx = 4.0*petrosian->radius;
    2095         overlay[Noverlay].dy = 4.0*petrosian->radius*profile->axes.minor/profile->axes.major;
    2096         overlay[Noverlay].angle = profile->axes.theta * PS_DEG_RAD;
    2097         overlay[Noverlay].text = NULL;
    2098         Noverlay ++;
     2091        overlay[Noverlay].type = KII_OVERLAY_CIRCLE;
     2092        overlay[Noverlay].x = source->peak->xf;
     2093        overlay[Noverlay].y = source->peak->yf;
     2094        overlay[Noverlay].dx = 4.0*petrosian->radius;
     2095        overlay[Noverlay].dy = 4.0*petrosian->radius*profile->axes.minor/profile->axes.major;
     2096        overlay[Noverlay].angle = profile->axes.theta * PS_DEG_RAD;
     2097        overlay[Noverlay].text = NULL;
     2098        Noverlay ++;
    20992099        CHECK_REALLOCATE (overlay, KiiOverlay, NOVERLAY, Noverlay, 100);
    21002100    }
  • branches/eam_branches/20090820/pstamp/scripts/pstampparse.pl

    r25766 r25870  
    7272}
    7373
     74# just deal with these arguments once and for all
     75$pstamptool .= " -dbname $dbname" if $dbname;
     76$pstamptool .= " -dbserver $dbserver" if $dbserver;
     77
    7478# list_job is a deugging mode
    7579$no_update = 1 if $mode eq "list_job";
     
    105109if ($req_id and !$no_update) {
    106110    my $command = "$pstamptool -listreq  -name $req_name -not_req_id $req_id";
    107     $command .= " -dbname $dbname" if $dbname;
    108     $command .= " -dbserver $dbserver" if $dbserver;
    109111    # no verbose so that error message about request not found doesn't appear in parse_error.txt
    110112    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     
    127129    my $command = "$pstamptool -updatereq -req_id $req_id  -name $req_name";
    128130    $command .= " -outProduct $product";
    129     $command .= " -dbname $dbname" if $dbname;
    130     $command .= " -dbserver $dbserver" if $dbserver;
    131131    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    132132        run(command => $command, verbose => $verbose);
     
    195195    my $mjd_max = $row->{MJD_MAX};
    196196    my $label   = $row->{LABEL};
     197    my $x       = $row->{CENTER_X};
     198    my $y       = $row->{CENTER_Y};
    197199
    198200    my $option_mask= $row->{OPTION_MASK};
     
    205207   
    206208    if (!$skycenter and !$search_component) {
    207         print STDERR "COMPONENT must be specified for pixel coordinate ROI\n" if $verbose;
     209        print STDERR "COMPONENT must be specified for pixel coordinate ROI center\n" if $verbose;
    208210        insertFakeJobForRow($row, 1, $PSTAMP_INVALID_REQUEST);
    209211        $num_jobs++;
     
    213215    $search_component = "" if $search_component eq "all";
    214216
    215     if (($job_type eq "stamp") and ! validROI($row)) {
     217    if ((($job_type eq "stamp") or ($req_type eq "bycoord")) and ! validROI($row)) {
    216218        print STDERR "invalid ROI for row $rownum\n" if $verbose;
    217219        insertFakeJobForRow($row, 1, $PSTAMP_INVALID_REQUEST);
     
    262264            next;
    263265        }
    264         print STDERR "lookup bycoord is not yet implemented" if $verbose;
    265         insertFakeJobForRow($row, 1, $PSTAMP_NOT_IMPLEMENTED);
    266         $num_jobs++;
    267         next;
    268     } else {
    269         # Call PS::IPP::PStamp::Job locate_images subroutine to get the images for this
    270         # request specification. An array reference is returned.
    271         my ($x, $y);
    272 
    273         $imageList = locate_images($ipprc, $image_db, $req_type, $stage, $id, $tess_id, $search_component,
     266        if ($stage eq "stack") {
     267            print STDERR "lookup bycoord is not yet implemented for stage stack" if $verbose;
     268            insertFakeJobForRow($row, 1, $PSTAMP_NOT_IMPLEMENTED);
     269            $num_jobs++;
     270            next;
     271        }
     272    }
     273    # Call PS::IPP::PStamp::Job locate_images subroutine to get the images for this
     274    # request specification. An array reference is returned.
     275    $imageList = locate_images($ipprc, $image_db, $req_type, $stage, $id, $tess_id, $search_component,
    274276                $inverse, $need_magic, $x, $y, $mjd_min, $mjd_max, $filter, $label, $verbose);
    275277
    276         if (!$imageList or !@$imageList) {
    277             print STDERR "no matching images found for row $rownum\n" if $verbose;
    278             # note in this case queueJobs inserts the fake job for these rows
    279         }
    280         $row->{need_magic} = $need_magic;
    281         push @rowList, $row;
    282     }
     278    if (!$imageList or !@$imageList) {
     279        print STDERR "no matching images found for row $rownum\n" if $verbose;
     280        # note in this case queueJobs inserts the fake job for these rows
     281    }
     282    $row->{need_magic} = $need_magic;
     283    push @rowList, $row;
    283284}
    284285
     
    397398        my $newState = "run";
    398399        my $fault = 0;
    399 
    400         if (($stage ne 'stack') and ($stage ne 'raw')) {
    401             if (($image->{state} eq 'goto_purged') or ($image->{data_state} eq 'purged')) {
     400        my $dep_id;
     401
     402        if ($stage ne 'raw') {
     403            my $run_state = $image->{state};
     404            my $data_state = $image->{data_state};
     405            $data_state = $run_state if $stage eq "stack";
     406            if (($run_state eq 'goto_purged') or ($data_state eq 'purged') or
     407                ($run_state eq 'goto_scrubbed') or ($data_state eq 'scrubbed')) {
     408                # image is gone and it's not coming back
    402409                $newState = 'stop';
    403410                $fault = $PSTAMP_GONE;
    404             } elsif (($image->{data_state} ne 'full') or ($image->{state} ne 'full' )) {
    405                 # XXX here is where we need to queue an update job
    406                 # for now just say that the image is not available
    407                 $newState = 'stop';
    408                 $fault = $PSTAMP_NOT_AVAILABLE;
     411            } elsif (($data_state ne 'full') or ($run_state ne 'full' )) {
     412                # don't wait for update unless the caller asks us to
     413                if (!($option_mask & $PSTAMP_WAIT_FOR_UPDATE)) {
     414                    $newState = 'stop';
     415                    $fault = $PSTAMP_NOT_AVAILABLE;
     416                } else {
     417                    # cause the image to be re-made
     418                    # set up to queue an update run
     419                    queue_update_run(\$newState, \$fault, \$dep_id, $image->{image_db},
     420                        $run_state, $stage, $image->{stage_id}, $need_magic, $image->{label});
     421                }
    409422            }
    410423        }
     
    415428        $command .= " -fault $fault" if $fault;
    416429        $command .= " -exp_id $exp_id" if $exp_id;
    417         $command .= " -dbname $dbname" if $dbname;
    418         $command .= " -dbserver $dbserver" if $dbserver;
     430        $command .= " -dep_id $dep_id" if $dep_id;
    419431
    420432        if ($mode eq "list_job") {
     
    593605    my $command = "$pstamptool -addjob  -req_id $req_id -job_type $job_type"
    594606                        . " -rownum $rownum -state stop -fault $fault";
    595     $command .= " -dbname $dbname" if $dbname;
    596     $command .= " -dbserver $dbserver" if $dbserver;
    597607
    598608    if ($mode eq "list_job") {
     
    717727}
    718728
     729sub queue_update_run
     730{
     731    my ($r_jobState, $r_fault, $r_dep_id, $imagedb, $state, $stage, $stage_id, $need_magic, $label) = @_;
     732
     733    if (($state ne 'cleaned') and ($state ne 'update') and ($state ne 'goto_cleaned')) {
     734        my_die("$stage $stage_id is in unexpected state $state", $PS_EXIT_PROG_ERROR);
     735    }
     736
     737    my $dep_id;
     738    my $command = "$pstamptool -getdependent -stage $stage -stage_id $stage_id -imagedb $imagedb";
     739    $command .= " -rlabel $label" if $label;
     740    $command .= " -no_magic" if !$need_magic;
     741    if (!$no_update) {
     742        my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     743            run(command => $command, verbose => $verbose);
     744        unless ($success) {
     745            my_die("$command failed", $PS_EXIT_UNKNOWN_ERROR);
     746        }
     747        my $output = join "", @$stdout_buf;
     748        chomp $output;
     749        $dep_id = $output;
     750        my_die("pstamptool -getdependent returned invalid dep_id", $PS_EXIT_PROG_ERROR) if !$dep_id;
     751    } else {
     752        print STDERR "skipping $command\n";
     753        $dep_id = 42;
     754    }
     755   
     756    $$r_dep_id = $dep_id;
     757    $r_fault = 0;
     758    $r_jobState = 'blocked';
     759}
     760
    719761sub my_die
    720762{
  • branches/eam_branches/20090820/pstamp/src/ppstampMakeStamp.c

    r25766 r25870  
    157157        return NULL;
    158158    }
     159    if (copyWidth > width) {
     160        copyWidth = width;
     161    }
    159162
    160163    psImage *output = psImageAlloc(width, height, image->type.type);
  • branches/eam_branches/20090820/pstamp/test/byskycell.txt

    r25766 r25870  
    1515# subsequent lines define the rows in the table
    1616
    17 ################################ OLD Format
    18 #
    19 # ROWNUM PROJECT JOB_TYPE OPTION_MASK REQ_TYPE IMG_TYPE    ID      TESS_ID COMPONENT   COORD_MASK CENTER_X   CENTER_Y WIDTH HEIGHT REQFILT MJD_MIN MJD_MAX
    20 # warps from various epochs for one of the SN candidates. Specifiying the skycell speeds up processing
    21 # 1         gpc1   stamp      1        byskycell    warp     null   MD07 skycell.044 2 214.509667604725 52.5181290488877  200 200 null 55009 55011
    22 
    23 
    24 
    2517# If ROWNUM is set to zero, pstamp_request_file will set insert a value for each row beginning with 1
    26 # If a later input row reuses a value an error occurs
     18# If a later input row reuses a value an error is preported
    2719
    2820# ID    |     ROI Specification                   |  JOB Specification | Images of interest specification
  • branches/eam_branches/20090820/pswarp/src/pswarpLoop.c

    r25766 r25870  
    488488    psString dump_file = psMetadataLookupStr(&status, config->arguments, "DUMP_CONFIG");
    489489    if (dump_file) {
    490         pmConfigDump(config, dump_file);
     490        if (!pmConfigDump(config, dump_file)) {
     491            psError(PS_ERR_IO, false, "Unable to dump configuration");
     492            return false;
     493        }
    491494    }
    492495
  • branches/eam_branches/20090820/tools/ipp_apply_burntool.pl

    r25766 r25870  
    5353my $burntool = can_run('burntool') or (warn "Can't find burntool" and $missing_tools = 1);
    5454my $ppConfigDump = can_run('ppConfigDump') or (warn "Can't find ppConfigDump" and $missing_tools = 1);
     55my $nebXattr = can_run('neb-xattr') or (warn "Can't find neb-xattr" and $missing_tools = 1);
    5556#my $fpack    = can_run('fpack')    or (warn "Can't find fpack" and $missing_tools = 1);
    5657if ($missing_tools) {
     
    190191        }
    191192       
     193        $status = vsystem ("$neb-xattr --write $outTable user.copies:2");
    192194        $status = vsystem ("$regtool -dbname $dbname -updateprocessedimfile -exp_id $exp_id -class_id $class_id -burntool_state $outState", $REALRUN);
    193195        if ($status) {
  • branches/eam_branches/20090820/tools/warp_outputs.pl

    r24236 r25870  
    1616                             'VARIANCE' => '.wt.fits', # Variance
    1717                             'SOURCES' => '.cmf', # Sources
     18                             'PSF' => '.psf', # Point-Spread Function
    1819                         };
    1920
Note: See TracChangeset for help on using the changeset viewer.