IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Sep 21, 2007, 4:23:03 PM (19 years ago)
Author:
jhoblitt
Message:

remove unneeded sanity checking and transaction from addresidimfileMode() as it is unneeded because of foregin key constraints

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ippTools/src/dettool.c

    r14978 r14981  
    9595static detNormalizedStatImfileRow *detStackedToDetNormalizedStatImfile(pxConfig *config, detStackedImfileRow *stackedImfile);
    9696static  detNormalizedImfileRow *detNormalizedStatToDetNormalizedmfile(pxConfig *config, detNormalizedStatImfileRow *statImfile);
    97 static  detResidImfileRow *detNormalizedToDetResidImfile(pxConfig *config, detNormalizedImfileRow *normalizedImfile);
    9897static detResidExpRow *mdToDetResidExp(pxConfig *config, psMetadata *row);
    9998static detRunSummaryRow *mdToDetRunSummary(pxConfig *config, psMetadata *row);
     
    46534652    PS_ASSERT_PTR_NON_NULL(config, false);
    46544653
    4655     // make sure that there is a coresponding entry in detNormalizedImfile
    4656     // and the exp_id specified is valid
    4657     // select * from detNormalizedImfile
    4658     // by det_id, iteration, class_id
    4659     // where det_id, iteration, class_id is not in detResidImfile
    4660     psString query = psStringCopy(
    4661         " SELECT * FROM ("
    4662         "SELECT\n"
    4663         "   detNormalizedImfile.*\n"
    4664         " FROM detRun\n"
    4665         " JOIN detInputExp\n"
    4666         "   USING(det_id, iteration)\n"
    4667         " JOIN detNormalizedImfile\n"
    4668         "   USING(det_id, iteration)\n"
    4669         " LEFT JOIN detResidImfile\n"
    4670         "   ON detRun.det_id = detResidImfile.det_id\n"
    4671         "   AND detRun.iteration = detResidImfile.iteration\n"
    4672         "   AND detInputExp.exp_id = detResidImfile.exp_id\n"
    4673         "   AND detNormalizedImfile.class_id = detResidImfile.class_id\n"
    4674         " WHERE\n"
    4675         "  detRun.state = 'run'\n"
    4676         "  AND detRun.mode= 'master'\n"
    4677         "  AND detResidImfile.det_id IS NULL\n"
    4678         "  AND detResidImfile.iteration IS NULL\n"
    4679         "  AND detResidImfile.exp_id IS NULL\n"
    4680         "  AND detResidImfile.class_id IS NULL\n"
    4681         " UNION\n"
    4682         " SELECT\n"
    4683         "   detRun.det_id,\n"
    4684         "   detRun.iteration,\n"
    4685         "   rawImfile.class_id,\n"
    4686         "   rawImfile.uri,\n"
    4687         "   0.0 as bg,\n"
    4688         "   0.0 as bg_stdev,\n"
    4689         "   0.0 as bg_mean_stdev,\n"
    4690         "   0.0 as user_1,\n"
    4691         "   0.0 as user_2,\n"
    4692         "   0.0 as user_3,\n"
    4693         "   0.0 as user_4,\n"
    4694         "   0.0 as user_5,\n"
    4695         "   'NULL' as path_base,\n"
    4696         "    0 as fault\n"
    4697         " FROM detRun\n"
    4698         " JOIN detInputExp\n"
    4699         "    USING(det_id, iteration)\n"
    4700         " JOIN rawExp\n"
    4701         "    ON detInputExp.exp_id = rawExp.exp_id\n"
    4702         " JOIN rawImfile\n"
    4703         "    ON detInputExp.exp_id = rawImfile.exp_id\n"
    4704         " LEFT JOIN detResidImfile\n"
    4705         "   ON detRun.det_id = detResidImfile.det_id\n"
    4706         "   AND detRun.iteration = detResidImfile.iteration\n"
    4707         "   AND rawImfile.exp_id = detResidImfile.exp_id\n"
    4708         "   AND rawImfile.class_id = detResidImfile.class_id\n"
    4709         " WHERE\n"
    4710         "   detRun.state = 'run'\n"
    4711         "   AND detRun.mode = 'verify'\n"
    4712         "   AND detResidImfile.det_id IS NULL\n"
    4713         "   AND detResidImfile.iteration IS NULL\n"
    4714         "   AND detResidImfile.exp_id IS NULL\n"
    4715         "   AND detResidImfile.class_id IS NULL\n"
    4716         "   AND detInputExp.exp_id = '%1$s'\n"
    4717         ") AS foo\n"
    4718         "  %2$s"
    4719     );
    4720 
    4721     // build a query to search by det_id, iteration, class_id
    4722     psMetadata *where = psMetadataAlloc();
    47234654    bool status = false;
    47244655    psString det_id = psMetadataLookupStr(&status, config->args, "-det_id");
    47254656    if (!status) {
    47264657        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -det_id");
    4727         psFree(where);
    4728         psFree(query);
    4729         return false;
    4730     }
    4731     if (det_id) {
    4732         if (!psMetadataAddStr(where, PS_LIST_TAIL, "det_id", 0, "==", det_id)) {
    4733             psError(PS_ERR_UNKNOWN, false, "failed to add item det_id");
    4734             psFree(where);
    4735             psFree(query);
    4736             return false;
    4737         }
    4738     }
    4739 
     4658        return false;
     4659    }
     4660    if (!det_id) {
     4661        psError(PS_ERR_UNKNOWN, true, "-det_id is required");
     4662        return false;
     4663    }
     4664
     4665    // defaults to 0
    47404666    psS32 iteration = psMetadataLookupS32(&status, config->args, "-iteration");
    47414667    if (!status) {
    47424668        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -iteration");
    4743         psFree(where);
    4744         psFree(query);
    4745         return false;
    4746     }
    4747     // always set iteration
    4748     if (!psMetadataAddS32(where, PS_LIST_TAIL, "iteration", 0, "==", iteration)) {
    4749         psError(PS_ERR_UNKNOWN, false, "failed to add item iteration");
    4750         psFree(where);
    4751         psFree(query);
    47524669        return false;
    47534670    }
     
    47564673    if (!status) {
    47574674        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -class_id");
    4758         psFree(where);
    4759         psFree(query);
    4760         return false;
    4761     }
    4762     if (class_id) {
    4763         if (!psMetadataAddStr(where, PS_LIST_TAIL, "class_id", 0, "==", class_id)) {
    4764             psError(PS_ERR_UNKNOWN, false, "failed to add item class_id");
    4765             psFree(where);
    4766             psFree(query);
    4767             return false;
    4768         }
    4769     }
    4770 
    4771     psString whereClause = psDBGenerateWhereSQL(where, NULL);
    4772     psFree(where);
    4773 
    4774     // exp_id is manadatory to cross check that this is a exp_id for this
    4775     // detRun
    4776     psString exp_id = psMetadataLookupStr(&status, config->args, "-exp_id");
    4777     if (!status) {
    4778         psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -exp_id");
    4779         psFree(whereClause);
    4780         psFree(query);
    4781         return false;
    4782     }
    4783     if (!exp_id) {
    4784         psError(PS_ERR_UNKNOWN, true, "-exp_id is required");
    4785         psFree(whereClause);
    4786         psFree(query);
    4787         return false;
    4788     }
    4789 
    4790     if (!p_psDBRunQuery(config->dbh, query, exp_id, whereClause)) {
    4791         psError(PS_ERR_UNKNOWN, false, "database error");
    4792         psFree(whereClause);
    4793         psFree(query);
    4794         return false;
    4795     }
    4796     psFree(whereClause);
    4797     psFree(query);
    4798 
    4799     psArray *output = p_psDBFetchResult(config->dbh);
    4800     if (!output) {
    4801         psError(PS_ERR_UNKNOWN, false, "database error");
    4802         return false;
    4803     }
    4804     if (!psArrayLength(output)) {
    4805         psError(PS_ERR_UNKNOWN, false, "no pending detNormalizedImfile rows found");
    4806         psFree(output);
    4807         return false;
    4808     }
    4809 
    4810     // start a transaction so it's all rows or nothing
    4811     if (!psDBTransaction(config->dbh)) {
    4812         psError(PS_ERR_UNKNOWN, false, "database error");
    4813         psFree(output);
    4814         return false;
    4815     }
    4816 
    4817     for (long i = 0; i < psArrayLength(output); i++) {
    4818         psMetadata *row = output->data[i];
    4819         // convert metadata into a detNormalizedImfile object
    4820         detNormalizedImfileRow *normalizedImfile = detNormalizedImfileObjectFromMetadata(row);
    4821         // convert detNormalizedImfile object into a detResidImfile
    4822         detResidImfileRow *residImfile  = detNormalizedToDetResidImfile(config, normalizedImfile);
    4823         psFree(normalizedImfile);
    4824         if (!residImfile) {
    4825             if (!psDBRollback(config->dbh)) {
    4826                 psError(PS_ERR_UNKNOWN, false, "database error");
    4827             }
    4828             psError(PS_ERR_UNKNOWN, false, "failed to convert detNormalizedImfile to detResidImfile");
    4829             psFree(output);
    4830             return false;
    4831         }
    4832         // insert detResidImfile object into the database
    4833         if (!detResidImfileInsertObject(config->dbh, residImfile)) {
    4834             if (!psDBRollback(config->dbh)) {
    4835                 psError(PS_ERR_UNKNOWN, false, "database error");
    4836             }
    4837             psError(PS_ERR_UNKNOWN, false, "database error");
    4838             psFree(residImfile);
    4839             psFree(output);
    4840             return false;
    4841         }
    4842         psFree(residImfile);
    4843     }
    4844 
    4845     psFree(output);
    4846 
    4847     if (!psDBCommit(config->dbh)) {
    4848         psError(PS_ERR_UNKNOWN, false, "database error");
    4849         return false;
    4850     }
    4851 
    4852     return true;
    4853 }
    4854 
    4855 static  detResidImfileRow *detNormalizedToDetResidImfile(pxConfig *config, detNormalizedImfileRow *normalizedImfile)
    4856 {
    4857     PS_ASSERT_PTR_NON_NULL(config, NULL);
    4858     PS_ASSERT_PTR_NON_NULL(normalizedImfile, NULL);
    4859 
    4860     bool status = false;
     4675        return false;
     4676    }
     4677    if (!class_id) {
     4678        psError(PS_ERR_UNKNOWN, false, "-class_id is required");
     4679        return false;
     4680    }
     4681
    48614682    psString exp_id = psMetadataLookupStr(&status, config->args, "-exp_id");
    48624683    if (!status) {
     
    49994820
    50004821    // create a new detResidImfileRow and insert it
    5001     return detResidImfileRowAlloc(
    5002             normalizedImfile->det_id,
    5003             normalizedImfile->iteration,
     4822    if (!detResidImfileInsert(
     4823            config->dbh,
     4824            (psS64)atoll(det_id),
     4825            iteration,
    50044826            (psS64)atoll(exp_id),
    5005             normalizedImfile->class_id,
     4827            class_id,
    50064828            uri,
    50074829            recipe,
     
    50254847            path_base,
    50264848            code
    5027         );
     4849    )) {
     4850        psError(PS_ERR_UNKNOWN, false, "database error");
     4851        return false;
     4852    }
     4853
     4854    return true;
    50284855}
    50294856
Note: See TracChangeset for help on using the changeset viewer.