IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 31928


Ignore:
Timestamp:
Jul 25, 2011, 12:31:14 PM (15 years ago)
Author:
rhenders
Message:

takes an argument for DVO database location

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ippToPsps/src/Dvo.c

    r31265 r31928  
    2727  Gets detections for this imageid
    2828  */
    29 static bool getDetections(Dvo* this, int32_t sourceId, int32_t imageId) {
     29static bool getDetections(Dvo* this) {
    3030
    3131    SkyList* skyList = NULL;
    3232    Image* image = NULL;
    33     this->logger->print(this->logger, MSG_INFO, "Dvo", "Getting skylist from DVO database...\n");
    34     skyList = dvoSkyListByExternID(this->dvoConfig, sourceId, imageId, &image);
    35     if (!skyList) {
    36 
    37         this->logger->print(this->logger, MSG_ERROR,
    38                 "Dvo", "Could not find skylist for sourceId=%d and image ID = %d\n",
    39                 sourceId, imageId);
    40 
    41         return false;
    42     }
    43     this->logger->print(this->logger, MSG_INFO, "Dvo", "...done\n");
    44 
    45     // now get detections
    46     this->logger->print(this->logger, MSG_INFO, "Dvo", "Getting detections...\n");
    47     dvoDetection* dvoDetections = NULL;
    48     int32_t maxDetectionId = -1;
    49     int32_t numDetections =
    50         dvoGetDetections(skyList, image->imageID, &dvoDetections, &maxDetectionId);
    51 
    52     this->logger->print(this->logger, MSG_INFO, "Dvo",
    53             "Found %d detections with a max detection ID of %d\n",
    54             numDetections, maxDetectionId);
    55 
    56     if (dvoDetections) dvoFree(dvoDetections);
    57     SkyListFree(skyList);
    58 
    59     this->logger->print(this->logger, MSG_INFO, "Dvo", "Deleting everything from dvo table\n");
    60     mysql_query(this->mysql, "DELETE FROM dvo");
    61 
    62     this->logger->print(this->logger, MSG_INFO, "Dvo", "Inserting IDs into dvo table...\n");
    63    
     33
     34    this->logger->print(this->logger, MSG_INFO, "Dvo", "Deleting everything from the dvoDetection table\n");
     35    mysql_query(this->mysql, "DELETE FROM dvoDetection");
     36
     37    mysql_query(this->mysql, "SELECT sourceID, imageID FROM dvoMeta");
     38    MYSQL_RES* result = mysql_store_result(this->mysql);
     39
     40    // loop through all souceID/imageIDs
     41    MYSQL_ROW row;
    6442    char sql[500];
    65     for (int i=0; i<numDetections; i++) {
     43    int sourceID, imageID;
     44    while ((row = mysql_fetch_row(result))) {
     45
     46        sourceID = atoi(row[0]);
     47        imageID = atoi(row[1]);
     48
     49        this->logger->print(this->logger, MSG_INFO, "Dvo", "---------------------------------------------------------------------\n");
     50        this->logger->print(this->logger, MSG_INFO, "Dvo", "Getting skylist from DVO database for source ID = %d and image ID = %d\n",
     51                sourceID, imageID);
     52        skyList = dvoSkyListByExternID(this->dvoConfig, sourceID, imageID, &image);
     53        if (!skyList) {
     54
     55            this->logger->print(this->logger, MSG_ERROR,
     56                    "Dvo", "Could not find skylist for sourceId=%d and image ID = %d\n",
     57                    sourceID, imageID);
     58
     59            continue;
     60        }
    6661
    6762        sprintf(sql,
    68                 "INSERT INTO dvo (ippDetectID, ippObjID, objID) VALUES (%u, %lu, %lu)",
    69                 dvoDetections[i].meas.detID,
    70                 (uint64_t)dvoDetections[i].ave.catID*1000000000 + (uint64_t)dvoDetections[i].ave.objID,
    71                 dvoDetections[i].ave.extID);
    72 
     63                "UPDATE dvoMeta SET flags = %d, photcode = %d WHERE sourceID = %d AND imageID = %d",
     64                image->flags,
     65                image->photcode,
     66                sourceID,
     67                imageID);
    7368        mysql_query(this->mysql, sql);
    74     }
    75     this->logger->print(this->logger, MSG_INFO, "Dvo", "...done\n");
    76 
    77 #if 0
    78     mysql_query(this->mysql, "SELECT * FROM Filter");
    79     MYSQL_RES* result = mysql_store_result(this->mysql);
    80 
    81     int num_fields = mysql_num_fields(result);
    82 
    83     MYSQL_ROW row;
    84 
    85     while ((row = mysql_fetch_row(result))) {
    86 
    87         for(int i = 0; i < num_fields; i++) {
    88 
    89             printf("%s ", row[i] ? row[i] : "NULL");
     69
     70        // now get detections
     71        this->logger->print(this->logger, MSG_INFO, "Dvo", "Getting detections...\n");
     72        dvoDetection* dvoDetections = NULL;
     73        int32_t maxDetectionId = -1;
     74        int32_t numDetections =
     75            dvoGetDetections(skyList, image->imageID, &dvoDetections, &maxDetectionId);
     76
     77        this->logger->print(this->logger, MSG_INFO, "Dvo",
     78                "Found %d detections with a max detection ID of %d\n",
     79                numDetections, maxDetectionId);
     80
     81
     82        this->logger->print(this->logger, MSG_INFO, "Dvo", "Inserting IDs into dvoDetection table...\n");
     83
     84        uint32_t zeroDvoCount = 0;
     85        for (int i=0; i<maxDetectionId+1; i++) {
     86
     87            if (dvoDetections[i].ave.extID == 0) {
     88                zeroDvoCount++;
     89            }
     90            else {
     91                sprintf(sql,
     92                        "INSERT INTO dvoDetection (sourceID, imageID, ippDetectID, detectID, ippObjID, objID, flags) VALUES (%d, %d, %u, %lu, %lu, %lu, %u)",
     93                        sourceID,   // sourceID
     94                        imageID,    // imageID
     95                        dvoDetections[i].meas.detID,   // ippDetectID
     96                        dvoDetections[i].meas.extID,   // detectID
     97                        (uint64_t)dvoDetections[i].ave.catID*1000000000 + (uint64_t)dvoDetections[i].ave.objID, // ippObjID
     98                        dvoDetections[i].ave.extID, // objID
     99                        dvoDetections[i].meas.dbFlags); // flags
     100
     101                mysql_query(this->mysql, sql);
     102            }
    90103        }
    91         printf("\n");
     104
     105        if (zeroDvoCount) this->logger->print(this->logger, MSG_ERROR, "Dvo", "Found %d 0 object IDs\n", zeroDvoCount);
     106        if (dvoDetections) dvoFree(dvoDetections);
     107        SkyListFree(skyList);
    92108    }
    93109
    94110    mysql_free_result(result);
    95 #endif
     111
    96112    return true;
    97113}
     
    106122    this->logger->print(this->logger, MSG_DEBUG, "Dvo", "Constructor\n");
    107123
    108     const char *configFile = "jython/config.xml";
     124    const char *configFile = "./config.xml"; // TODO hardcoded path to config
    109125    this->logger->print(this->logger, MSG_INFO, "Dvo", "Using config file here '%s'\n", configFile);
    110126    xmlDoc* doc = xmlReadFile(configFile, NULL, 0);
     
    202218}
    203219
    204 
    205220/**
    206221  Main
     
    210225    Logger* logger = new_Logger(NULL, true);
    211226
    212     Dvo * dvo = new_Dvo(logger, "/data/ipp004.0/gpc1/catdirs/ThreePi.V1");
    213     dvo->getDetections(dvo, 33, 8345290);
    214     dvo->destroy(dvo);
     227    if (argc < 2) {
     228
     229        logger->print(logger, MSG_ERROR, "Dvo", "Incorrect arguments\n");
     230        logger->print(logger, MSG_INFO, "Dvo", "Usage: ./dvo <pathToDvo>\n");
     231    }
     232    else {
     233        //Dvo * dvo = new_Dvo(logger, "/data/ipp004.0/gpc1/catdirs/ThreePi.V1");
     234        Dvo * dvo = new_Dvo(logger, argv[1]);
     235        //dvo->getDetections(dvo, 33, 8345290);
     236        dvo->getDetections(dvo);
     237        dvo->destroy(dvo);
     238    }
    215239
    216240    logger->destroy(logger);
Note: See TracChangeset for help on using the changeset viewer.