IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 31015 for trunk/ippToPsps/src


Ignore:
Timestamp:
Mar 23, 2011, 9:33:05 AM (15 years ago)
Author:
rhenders
Message:

New class to encapsulate initialization data

Location:
trunk/ippToPsps/src
Files:
2 added
7 edited

Legend:

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

    r31011 r31015  
    8787    if (this->dvoConfig != NULL) dvoConfigFree(this->dvoConfig);
    8888
     89    // destroy objects
    8990    this->config->destroy(this->config);
     91    this->initData->destroy(this->initData);
    9092
    9193    pmConfigDone();
     
    210212    }
    211213
    212 
    213 
     214    // check we have some input paths
    214215    if (haveFitsInPath && !readInputFilePaths(this)) {
    215216
     
    218219    }
    219220
    220     // create a config object
     221    // create an InitData object and get survey ID
     222    this->initData = new_InitData(configsBaseDir);
     223    if (strlen(this->surveyType) > 0 &&
     224            !this->initData->getSurveyId(this->initData, this->surveyType, &this->surveyID)) {
     225
     226        this->exitCode = PS_EXIT_CONFIG_ERROR;
     227        return false;
     228    }
     229
     230    // create a Config object
    221231    strcat(configsBaseDir, configsDir);
    222232    this->config = new_Config(configsBaseDir);
     
    227237    }
    228238
    229     // get survey ID using config object
    230     if (strlen(this->surveyType) > 0 && !this->config->getSurveyId(this->config, this->surveyType, &this->surveyID)) {
    231 
    232         this->exitCode = PS_EXIT_CONFIG_ERROR;
    233         return false;
    234     }
    235239    // create full FITS out path
    236     sprintf (fitsOutPath, "%s/%s", fitsOutPath, fitsOutFile);
     240    sprintf(fitsOutPath, "%s/%s", fitsOutPath, fitsOutFile);
    237241
    238242    // create an output FITS file
     
    321325    // set up function pointers
    322326    this->parseArguments = parseArguments;
    323     //this->init = init;
    324327    this->print = print;
    325     this->destroy = destroy;
    326 
    327328    this->gotResultsPath = gotResultsPath;
    328329    this->gotFitsInPath = gotFitsInPath;
     
    330331    this->gotConfig = gotConfig;
    331332    this->gotSurveyType = gotSurveyType;
     333    this->destroy = destroy;
    332334
    333335    assert(this);
  • trunk/ippToPsps/src/Batch.h

    r31011 r31015  
    1212#define IPPTOPSPS_BATCH_H
    1313
    14 #include <psmodules.h>
    15 #include <dvo_util.h>
    16 #include "Config.h"
    1714#include <libxml/parser.h>
    1815#include <libxml/tree.h>
    1916
     17#include <psmodules.h>
     18#include <dvo_util.h>
     19
     20#include "Config.h"
    2021#include "Fits.h"
     22#include "InitData.h"
    2123
    2224/**
     
    4244    pmConfig* pmconfig;         // pmConfig
    4345    dvoConfig* dvoConfig;       // dvo database
    44     Config* config;    // config structure
     46    Config* config;             // Config object
     47    InitData* initData;         // InitData object
    4548    char todaysDate[20];        // today's date
    4649    int exitCode;               // ps exit code
  • trunk/ippToPsps/src/Config.c

    r31011 r31015  
    1515
    1616/**
    17    Gets PS type from string
     17   Gets PS type from string TODO FITS types? should be in Fits class
    1818   */
    1919static int ippToPsps_GetDataType(char *typename) {
     
    199199            default:
    200200                break;
    201 
    202201        }
    203202    }
     
    230229}
    231230
    232 /**
    233   Searches through this table and finds attribute value for a provided key
    234   */
    235 static bool getRowAttribute(Config* this, xmlNode* tableNode,
    236         const char* keyName, const char* keyValue,
    237         const char* attName, char* attValue) {
    238 
    239     xmlNode* node = NULL;
    240 
    241     char buffer[100];
    242 
    243     // loop round all available rows for this table
    244     for (node = tableNode->children; node; node = node->next) {
    245         if (node->type == XML_ELEMENT_NODE) {
    246             //psLogMsg("ippToPsps", PS_LOG_INFO, "Node name '%s'",  (const char*)node->name );
    247 
    248             if (strcmp((const char*)node->name, "row")==0) {
    249                 //psLogMsg("ippToPsps", PS_LOG_INFO, " Looking for key '%s'",  keyName );
    250 
    251                 if (!getAttribute(node, keyName, buffer)) continue;
    252                 //psLogMsg("ippToPsps", PS_LOG_INFO, "Found key '%s' value '%s'",  keyName, buffer );
    253 
    254                 if (strcmp(buffer, keyValue) != 0) continue;
    255                 getAttribute(node, attName, attValue);
    256                 //printf("FOUND %s %s %s %s \n", keyName, buffer, attName, attValue );
    257                 return true;
    258 
    259             }
    260         }
    261     }
    262 
    263     psLogMsg("ippToPsps", PS_LOG_INFO, "Could not find value for '%s' for '%s' with value '%s'", attName, keyName, keyValue );
    264     return false;
    265 }
    266 
    267231/*
    268232   opens an XML file and returns the document
     
    283247    xmlCleanupParser();
    284248
    285     return true;
    286 }
    287 
    288 /**
    289   Gets a value from the 'init' data
    290   */
    291 static bool getInitValue(
    292         Config* this,
    293         const char* tableName,
    294         const char* keyName, const char* keyValue,
    295         const char* attName, char* attValue) {
    296 
    297     bool ret = true;
    298 
    299     psString path = NULL;
    300     psStringAppend(&path, "%s/../init/data.xml", this->configsPath); // TODO nasty
    301 
    302     xmlDoc* doc = openXmlFile(path);
    303 
    304     if (doc == NULL) {
    305         psFree(path);
    306         return false;
    307     }
    308     psFree(path);
    309 
    310     xmlNode* rootElement = xmlDocGetRootElement(doc);
    311 
    312     if (strcmp((const char*)rootElement->name, "tabledata")!=0) {
    313         psError(PS_ERR_IO, false, "Root node of XML is not 'tabledata', as it should be");
    314         return false;
    315     }
    316 
    317     xmlNode* node = NULL;
    318     char tempStr[100];
    319 
    320     // loop round all available tables
    321     for (node = rootElement->children; node; node = node->next) {
    322         if (node->type == XML_ELEMENT_NODE) {
    323 
    324             if (strcmp((const char*)node->name, "table")!=0) continue;
    325             if (!getAttribute(node, "name", tempStr)) continue;
    326             if (strcmp(tempStr, tableName)!=0) continue;
    327 
    328             ret = getRowAttribute(this, node, keyName, keyValue, attName, attValue);
    329             break;
    330         }
    331 
    332     }
    333 
    334     closeXmlFile(doc);
    335 
    336     return ret;
    337 }
    338 
    339 /*
    340    Gets survey ID from survey name
    341    */
    342 static bool getSurveyId(Config* this, const char* surveyType, int8_t* surveyId) {
    343 
    344     char buffer[10];
    345     if (!getInitValue(this, "Survey", "name", surveyType, "surveyID", buffer)) {
    346 
    347         *surveyId = -1;
    348         return false;
    349     }
    350 
    351     *surveyId = atoi(buffer);
    352     return true;
    353 }
    354 
    355 /*
    356    Gets filter ID from filter type
    357    */
    358 static bool getFilterId(Config* this, const char* filterType, int8_t* filterId) {
    359 
    360     char tmp[2];
    361     strncpy(tmp,filterType,1);
    362     tmp[1] = '\0';
    363     char buffer[10];
    364     if (!getInitValue(this, "Filter", "filterType", tmp, "filterID", buffer)) {
    365 
    366         *filterId = -1;
    367         return false;
    368     }
    369 
    370     *filterId = atoi(buffer);
    371249    return true;
    372250}
     
    859737static void destroy(Config* this) {
    860738
    861     if (this != NULL ) {
    862 
    863         // TODO check logic here
    864         for (int i=0;i<this->numOfTables;i++)
    865             free(this->tables[i].columns);
    866 
    867         free(this->tables);
    868         psFree(this->configsPath);
    869         free(this);
    870     }
     739    if (this == NULL) return;
     740
     741    // TODO check logic here
     742    for (int i=0;i<this->numOfTables;i++)
     743        free(this->tables[i].columns);
     744
     745    free(this->tables);
     746    psFree(this->configsPath);
     747    free(this);
    871748}
    872749
     
    882759
    883760    // method pointers
    884     this->getFilterId = getFilterId;
    885     this->getSurveyId = getSurveyId;
    886761    this->createAndPopulateTable = createAndPopulateTable;
    887762    this->populateFromFile = populateFromFile;
  • trunk/ippToPsps/src/Config.h

    r31011 r31015  
    5151
    5252    // methods
    53     bool (*getFilterId)();
    54     bool (*getSurveyId)();
    5553    bool (*createAndPopulateTable)();
    5654    bool (*populateFromFile)();
  • trunk/ippToPsps/src/DetectionBatch.c

    r31011 r31015  
    6363    // FrameMeta values
    6464    int8_t filterID = -1;
    65     if (!this->base.config->getFilterId(this->base.config, filterType, &filterID)) {
     65    if (!this->base.initData->getFilterId(this->base.initData, filterType, &filterID)) {
    6666   
    6767        this->base.exitCode = PS_EXIT_DATA_ERROR;
  • trunk/ippToPsps/src/Makefile.am

    r31010 r31015  
    3232        Version.c \
    3333        Fits.c \
     34        InitData.c \
    3435        Config.c
    3536
     
    4243        Version.c \
    4344        Fits.c \
     45        InitData.c \
    4446        Config.c
    4547
     
    5254        Version.c \
    5355        Fits.c \
     56        InitData.c \
    5457        Config.c
    5558
  • trunk/ippToPsps/src/StackBatch.c

    r31011 r31015  
    323323
    324324    int8_t filterID = -1;
    325     if (!this->base.config->getFilterId(this->base.config, filterType, &filterID)) {
     325    if (!this->base.initData->getFilterId(this->base.initData, filterType, &filterID)) {
    326326
    327327        //        this->base.exitCode = PS_EXIT_DATA_ERROR;
Note: See TracChangeset for help on using the changeset viewer.