IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 15728


Ignore:
Timestamp:
Nov 30, 2007, 4:46:27 PM (18 years ago)
Author:
eugene
Message:

working on the dvo_catalog api to support segmented read/write

Location:
branches/eam_branch_20071130/Ohana/src
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branch_20071130/Ohana/src/dvosplit/src/dvosplit.c

    r15722 r15728  
    88  // the output catalog needs to inherit the SKY_DEPTH of the input catalog.
    99  // if the CATDIR/SkyTable.fits is not found, assume the HST layout (old default)
     10
     11  // force the output to have SPLIT mode?
    1012
    1113  // load the sky table for the existing database
     
    2729    // if (current level == out level) skip: no action is needed
    2830    if (skylist[0].regions[i][0].depth >= OUT_DEPTH) continue;
     31    // XXX : we need to copy these files to their new names
    2932
     33    // change outsky.regions[i].depth for these regions
    3034    outlist = SkyListByPatch (outsky, OUT_DEPTH, skylist[0].regions[i]);
    3135
     
    4246
    4347    // skip empty input catalogs
    44     if (!incatalog.Nave_disk) {
     48    if (!incatalog.Naves_disk) {
    4549      dvo_catalog_unlock (&incatalog);
    4650      dvo_catalog_free (&incatalog);
    4751      continue;
    4852    }
    49 
    50     outcatalog = SkyTableSubdivide (&incatalog, &Noutcatalog);
    5153
    5254    // split out the average entries:
     
    6769
    6870        N = -1;
    69         for (n = 0; n < Noutcatalog; n++) {
     71        for (n = 0; n < outlist[0].Nregions; n++) {
    7072          if (inR < outregions[n].Rmin) continue;
    7173          if (inR > outregions[n].Rmax) continue;
  • branches/eam_branch_20071130/Ohana/src/libdvo/doc/dvo-catalogs.txt

    r8328 r15728  
    22// APIs related to the DVO catalogs:
    33
    4 // XXX change name
    5 // XXX add SORTED test to load
    6 // XXX add Nsecfilt test? or add an API?
    74load_catalog (Catalog *catalog, int VERBOSE);
    8 // returns
    9 //   0: failure to lock catalog
    10 //   1: success: file is locked and opened
    11 //   2: success: file is locked but empty
    125
    136dvo_catalog_lock (Catalog *catalog, int lockmode);
     
    2013// layout: RAW, MEF, SPLIT
    2114// mode:   READ, WRITE
     15
     16// returns
     17//   DVO_CAT_OPEN_FAIL:  failure to lock catalog
     18//   DVO_CAT_OPEN_OK:    success: file is locked and opened
     19//   DVO_CAT_OPEN_EMPTY: success: file is locked but empty
     20
     21 the catalog is opened and the data for each of the elements (average,
     22 measure, etc) is loaded if requested.  Whether or not the data is
     23 loaded, the values of catalog.Naves_disk,Naves_off,Naverage are set
     24 to match the segment of data loaded.  this API always loads either
     25 the entire data set, or none.  If none, the offset value is set to
     26 point at the end of the table.
    2227
    2328dvo_catalog_save (Catalog *catalog, int VERBOSE);
     
    4348- open and read an existing catalog / error if missing (can be ignored)
    4449
     50dvo_catalog_open (Catalog *catalog, int mode);
    4551
    46 dvo_catalog_open (Catalog *catalog, int mode);
     52dvo_catalog_load_segment_average (Catalog *catalog, int start, int Nrows)
     53
     54 this function reads in the requested number of rows from the catalog
     55 for the Average and SecFilt tables only.  It is possible within the
     56 DVO framework to examine the average values in slices. 
     57
     58dvo_catalog_load_segment_measure (Catalog *catalog, int start, int Nrows)
     59
     60 this function reads in the requested number of rows from the catalog
     61 for the Measure table only.  It is not guaranteed to be possible to
     62 examine the measure values in slices if reference is needed to their
     63 average values.
     64
     65dvo_catalog_load_segment_missing (Catalog *catalog, int start, int Nrows)
     66
     67 this function reads in the requested number of rows from the catalog
     68 for the Missing table only.  It is not guaranteed to be possible to
     69 examine the missing values in slices if reference is needed to their
     70 average values.
  • branches/eam_branch_20071130/Ohana/src/libdvo/src/dvo_catalog.c

    r15725 r15728  
    235235  if (!status) catalog[0].sorted = TRUE;
    236236
    237   // even if the data is sorted on disk, if we only load the MEAS_META, we are
    238   // treating it as unsorted (eg, append only)
    239   // XXX deprecate this statement?
    240   if (catalog[0].catflags & LOAD_MEAS_META) {
    241       catalog[0].sorted = FALSE;
    242   }
    243 
    244237  // determine catmode
    245238  if (!gfits_scan (&catalog[0].header, "NAXIS", "%d", 1, &Naxis)) {
     
    308301
    309302int dvo_catalog_update (Catalog *catalog, char VERBOSE) {
     303
     304  // even if the data is sorted on disk, if we only load the MEAS_META, we are
     305  // treating it as unsorted (eg, append only)
     306  // XXX deprecate this statement?
     307  XXX:
     308  check on this;
     309  if (catalog[0].catflags & LOAD_MEAS_META) {
     310      catalog[0].sorted = FALSE;
     311  }
    310312
    311313  /* update is only valid for catmode SPLIT */
     
    398400  style  : raw, mef, split, mysql
    399401*/
     402
     403int dvo_catalog_load_segment (Catalog *catalog, int VERBOSE, int start, int Nrows) {
     404 
     405  int Naxis, split, status;
     406  char measure[80];
     407
     408  // catformat determined in dvo_catalog_load_XXX function
     409  catalog[0].catformat = DVO_FORMAT_UNDEF;
     410
     411  switch (catalog[0].catmode) {
     412    case DVO_MODE_RAW:
     413      if (VERBOSE) fprintf (stderr, "reading catalog (mode DVO_MODE_RAW)\n");
     414      fprintf (stderr, "cannot do this in raw mode\n");
     415      // dvo_catalog_load_segment_raw (catalog, VERBOSE, start, Nrows);
     416      break;
     417    case DVO_MODE_MEF:
     418      if (VERBOSE) fprintf (stderr, "reading catalog (mode DVO_MODE_MEF)\n");
     419      dvo_catalog_load_segment_mef (catalog, VERBOSE, start, Nrows);
     420      break;
     421    case DVO_MODE_SPLIT:
     422      if (VERBOSE) fprintf (stderr, "reading catalog (mode DVO_MODE_SPLIT)\n");
     423      dvo_catalog_load_segment_split (catalog, VERBOSE, start, Nrows);
     424      break;
     425    default:
     426      fprintf (stderr, "error getting catalog mode\n");
     427      exit (2);
     428  }
     429  return (TRUE);
     430}
     431
  • branches/eam_branch_20071130/Ohana/src/libdvo/src/dvo_catalog_mef.c

    r15487 r15728  
    2828  if (!gfits_scan (&catalog[0].header, "NSECFILT", "%d", 1, &Nsecfilt)) Nsecfilt = 0;
    2929
     30  /* save the current number so we can do partial updates */
     31  catalog[0].Naves_disk = Naverage;
     32  catalog[0].Nmeas_disk = Nmeasure;
     33  catalog[0].Nmiss_disk = Nmissing;
     34  catalog[0].Nsecf_disk = Naverage * Nsecfilt;
     35
    3036  /**  Nsecfilt is unusual: it does not list the number of data items in the table
    3137       instead, the number of items is Nsecfilt * Naverage.  **/
    3238  catalog[0].Nsecfilt = Nsecfilt;
     39
     40  /* default values, but we will assign these a valid value before we exit (even if empty) */
     41  catalog[0].average = NULL;
     42  catalog[0].measure = NULL;
     43  catalog[0].missing = NULL;
     44  catalog[0].secfilt = NULL;
    3345
    3446  /* validate table mode */
     
    4658    }
    4759    /* old versions of DVO stored one of the average magnitudes in Average. we save this if needed */
    48     catalog[0].average = FtableToAverage (&ftable, &catalog[0].Naverage, &catalog[0].catformat, &primary);
     60    catalog[0].average = FtableToAverage (&ftable, &Naverage, &catalog[0].catformat, &primary);
    4961    if (Naverage != catalog[0].Naverage) {
    50       fprintf (stderr, "Warning: mismatch between Naverage in PHU and Table headers (%d vs %d)\n", Naverage, catalog[0].Naverage);
    51     }
     62      fprintf (stderr, "Warning: mismatch between Naverage in PHU and Table headers (%d vs %d)\n", Naverage, catalog[0].Naves_disk);
     63    }
     64    catalog[0].Naverage = catalog[0].Naves_disk;
     65    catalog[0].Naves_off = 0;
    5266  } else {
    5367    Nbytes = gfits_data_size (&header);
    5468    fseek (f, Nbytes, SEEK_CUR);
     69    ALLOCATE (catalog[0].average, Average, 1);
     70    catalog[0].Naverage = 0;
     71    catalog[0].Naves_off = catalog[0].Naves_disk;
    5572  }
    5673  gfits_free_header (&header);
     
    7289      fprintf (stderr, "Warning: mismatch between Nmeasure in PHU and Table headers (%d vs %d)\n", Nmeasure, catalog[0].Nmeasure);
    7390    }
     91    catalog[0].Nmeasure = catalog[0].Nmeas_disk;
     92    catalog[0].Nmeas_off = 0;
    7493  } else {
    7594    Nbytes = gfits_data_size (&header);
    7695    fseek (f, Nbytes, SEEK_CUR);
     96    ALLOCATE (catalog[0].measure, Measure, 1);
     97    catalog[0].Nmeasure = 0;
     98    catalog[0].Nmeas_off = catalog[0].Nmeas_disk;
    7799  }
    78100
     
    93115      fprintf (stderr, "Warning: mismatch between Nmissing in PHU and Table headers (%d vs %d)\n", Nmissing, catalog[0].Nmissing);
    94116    }
     117    catalog[0].Nmissing = catalog[0].Nmiss_disk;
     118    catalog[0].Nmiss_off = 0;
    95119  } else {
    96120    Nbytes = gfits_data_size (&header);
    97121    fseek (f, Nbytes, SEEK_CUR);
     122    ALLOCATE (catalog[0].missing, Missing, 1);
     123    catalog[0].Nmissing = 0;
     124    catalog[0].Nmiss_off = catalog[0].Nmiss_disk;
    98125  }
    99126
     
    125152      Ntmpfilt = catalog[0].Nsecfilt;
    126153      Nsecfilt = catalog[0].Nsecfilt + 1;
    127       Ntotal = Nsecfilt * catalog[0].Naverage;
     154      Ntotal = Nsecfilt * catalog[0].Naves_disk;
    128155      ALLOCATE (catalog[0].secfilt, SecFilt, Ntotal);
    129       for (i = 0; i < catalog[0].Naverage; i++) {
     156      for (i = 0; i < catalog[0].Naves_disk; i++) {
    130157        catalog[0].secfilt[i*Nsecfilt + 0] = primary[i];
    131158        for (j = 0; j < Ntmpfilt; j++) {
     
    134161      }         
    135162      catalog[0].Nsecfilt = Nsecfilt;
     163      catalog[0].Nsecf_disk = Ntotal;
    136164      free (primary);
    137165    }
    138 
     166    catalog[0].Nsecf_mem = catalog[0].Nsecf_disk;
     167    catalog[0].Nsecf_off = 0;
    139168  } else {
    140169    /* no real need to skip the data array here... */
    141170    Nbytes = gfits_data_size (&header);
    142171    fseek (f, Nbytes, SEEK_CUR);
    143     if (primary != NULL) free (primary);
    144   }
    145 
    146   /* save the current number so we can do partial updates */
    147   catalog[0].Nave_disk  = catalog[0].Naverage;
    148   catalog[0].Nmeas_disk = catalog[0].Nmeasure;
    149   catalog[0].Nmiss_disk = catalog[0].Nmissing;
     172    if (primary != NULL) {
     173      free (primary);
     174      catalog[0].Nsecfilt ++;
     175      catalog[0].Nsecf_disk =  catalog[0].Nsecfilt * catalog[0].Naves_disk;
     176    }
     177    ALLOCATE (catalog[0].secfilt, SecFilt, 1);
     178    catalog[0].Nsecf_mem = 0;
     179    catalog[0].Nsecf_off = catalog[0].Nsecf_disk;
     180  }
    150181
    151182  return (TRUE);
  • branches/eam_branch_20071130/Ohana/src/libdvo/src/dvo_catalog_split.c

    r15725 r15728  
    121121    }
    122122    gfits_free_header (&header);
    123     catalog[0].Naverage = Naverage;
     123    catalog[0].Naverage = catalog[0].Naves_disk;
    124124    catalog[0].Naves_off = 0;
    125125  } else {
    126126    ALLOCATE (catalog[0].average, Average, 1);
    127127    catalog[0].Naverage = 0;
    128     catalog[0].Naves_off = Naverage;
     128    catalog[0].Naves_off = catalog[0].Naves_disk;
    129129  }
    130130
     
    221221      Ntotal = Nsecfilt * catalog[0].Naves_disk;
    222222      ALLOCATE (catalog[0].secfilt, SecFilt, Ntotal);
    223       for (i = 0; i < catalog[0].Naverage; i++) {
     223      for (i = 0; i < catalog[0].Naves_disk; i++) {
    224224        catalog[0].secfilt[i*Nsecfilt + 0] = primary[i];
    225225        for (j = 0; j < Ntmpfilt; j++) {
     
    250250}
    251251
    252 // XXX I either need to always read both average and secfilt at the same time, or
    253 // do something sloppy to carry around the primary secfilt values...
     252// I need to always read both average and secfilt at the same time to correctly manage the
     253// primary secfilt values...
     254
     255// XXX merge these? use the mode to choose which component?
    254256
    255257int dvo_catalog_load_segment_split_average (Catalog *catalog, int start, int Nrows) {
     
    257259  // XXX check the open status of the FILE *f?
    258260
     261  /*** Average (& SecFilt) Table ***/
     262  if (catalog[0].catflags & LOAD_AVES) {
     263
     264    /*** load the Average data ***/
    259265    /* move pointer past header -- must be already read (load_catalog) */
    260266    fseek (catalog[0].f, catalog[0].header.size, SEEK_SET);
     
    290296    catalog[0].Naves_off = start;
    291297
    292     return (TRUE);
    293 }
    294 
    295 int dvo_catalog_load_segment_split_measure (Catalog *catalog, int start, int Nrows) {
    296 
    297   // XXX check the open status of the FILE *f?
    298 
    299   Catalog *subcat = catalog[0].measure_catalog;
    300 
    301   /* move pointer past header -- must be already read (load_catalog) */
    302   fseek (subcat[0].f, subcat[0].header.size, SEEK_SET);
    303   /* matrix should be empty : XXX should we drop this step and skip the data? */
    304   if (!gfits_fread_matrix (subcat[0].f, &matrix, &subcat[0].header)) {
    305     if (VERBOSE) fprintf (stderr, "can't read primary matrix");
    306     return (FALSE);
    307   }
    308   /* read Measure table header */
    309   if (!gfits_fread_header (subcat[0].f, &header)) {
    310     if (VERBOSE) fprintf (stderr, "can't read table measure header");
    311     return (FALSE);
    312   }
    313   /* read Measure table data : format is irrelevant here */
    314   if (!gfits_fread_vtable_range (subcat[0].f, &vtable, start, Nrows)) {
    315     if (VERBOSE) fprintf (stderr, "can't read table measure data");
    316     return (FALSE);
    317   }
    318 
    319   /* convert data format to internal : returns number of row read in Nmeasure */
    320   catalog[0].measure = VtableToMeasure (&vtable, &Nmeasure, &catalog[0].catformat);
    321   if (Nmeasure != Nrows) {
    322     fprintf (stderr, "Warning: mismatch between Nmeasure in PHU and Table headers (%d vs %d)\n", Nmeasure, Nrows);
    323   }
    324   gfits_free_header (&header);
    325   gfits_free_matrix (&matrix);
    326   catalog[0].Nmeasure = Nmeasure;
    327   catalog[0].Nmeas_off = start;
    328   return (TRUE);
    329 }
    330 
    331 int dvo_catalog_load_segment_split_missing (Catalog *catalog, int start, int Nrows) {
    332 
    333   // XXX check the open status of the FILE *f?
    334 
    335   Catalog *subcat = catalog[0].missing_catalog;
    336 
    337   /* move pointer past header -- must be already read (load_catalog) */
    338   fseek (subcat[0].f, subcat[0].header.size, SEEK_SET);
    339   /* matrix should be empty : XXX should we drop this step and skip the data? */
    340   if (!gfits_fread_matrix (subcat[0].f, &matrix, &subcat[0].header)) {
    341     if (VERBOSE) fprintf (stderr, "can't read primary matrix");
    342     return (FALSE);
    343   }
    344   /* read Missing table header */
    345   if (!gfits_fread_header (subcat[0].f, &header)) {
    346     if (VERBOSE) fprintf (stderr, "can't read table missing header");
    347     return (FALSE);
    348   }
    349   /* read Missing table data : format is irrelevant here */
    350   if (!gfits_fread_vtable_range (subcat[0].f, &vtable, start, Nrows)) {
    351     if (VERBOSE) fprintf (stderr, "can't read table missing data");
    352     return (FALSE);
    353   }
    354 
    355   /* convert data format to internal : returns number of row read in Nmissing */
    356   catalog[0].missing = VtableToMissing (&vtable, &Nmissing, &catalog[0].catformat);
    357   if (Nmissing != Nrows) {
    358     fprintf (stderr, "Warning: mismatch between Nmissing in PHU and Table headers (%d vs %d)\n", Nmissing, Nrows);
    359   }
    360   gfits_free_header (&header);
    361   gfits_free_matrix (&matrix);
    362   catalog[0].Nmissing = Nmissing;
    363   catalog[0].Nmiss_off = start;
     298    /*** load the secfilt data ***/
     299    Catalog *subcat = catalog[0].secfilt_catalog;
     300
     301    /* move pointer past header -- must be already read (load_catalog) */
     302    fseek (subcat[0].f, subcat[0].header.size, SEEK_SET);
     303    /* matrix should be empty : XXX should we drop this step and skip the data? */
     304    if (!gfits_fread_matrix (subcat[0].f, &matrix, &subcat[0].header)) {
     305      if (VERBOSE) fprintf (stderr, "can't read primary matrix");
     306      return (FALSE);
     307    }
     308    /* read Measure table header */
     309    if (!gfits_fread_header (subcat[0].f, &header)) {
     310      if (VERBOSE) fprintf (stderr, "can't read table measure header");
     311      return (FALSE);
     312    }
     313    /* read Measure table data : format is irrelevant here */
     314    if (!gfits_fread_vtable_range (subcat[0].f, &vtable, start, Nrows)) {
     315      if (VERBOSE) fprintf (stderr, "can't read table measure data");
     316      return (FALSE);
     317    }
     318
     319    Nexpect = Nrows * Nsecfilt;
     320    catalog[0].secfilt = VtableToSecFilt (&vtable, &Nitems, &catalog[0].catformat);
     321    if (Nitems != Nexpect) {
     322      fprintf (stderr, "Warning: mismatch between Nsecfilt items in PHU and Table headers (%d vs %d)\n", Nitems, catalog[0].Nsecf_disk);
     323    }
     324
     325    /* if primary is defined, we were supplied with one additional average magnitude from Average
     326       we need to interleave these magnitudes with the secfilt entries just loaded */
     327    if (primary != NULL) {
     328      int Ntmpfilt, Ntotal, i, j;
     329      SecFilt *tmpfilt;
     330      tmpfilt  = catalog[0].secfilt;
     331      Ntmpfilt = catalog[0].Nsecfilt;
     332
     333      catalog[0].Nsecfilt ++;
     334      catalog[0].Nsecf_disk = catalog[0].Nsecfilt * catalog[0].Naves_disk;
     335      Nsecfilt = catalog[0].Nsecfilt;
     336
     337      // the loaded average rows correspond to the loaded secfilt rows
     338      // supplement with the loaded primary secfilt data
     339      Nexpect = Nrows * Nsecfilt;
     340      ALLOCATE (catalog[0].secfilt, SecFilt, Nexpect);
     341      for (i = 0; i < Nrows; i++) {
     342        catalog[0].secfilt[i*Nsecfilt + 0] = primary[i];
     343        for (j = 0; j < Ntmpfilt; j++) {
     344          catalog[0].secfilt[i*Nsecfilt + j + 1] = tmpfilt[i*Ntmpfilt + j];
     345        }
     346      }         
     347      free (primary);
     348    }
     349    gfits_free_header (&header);
     350    gfits_free_matrix (&matrix);
     351    catalog[0].Nsecf_mem = Nexpect;
     352    catalog[0].Nsecf_off = start * Nsecfilt;
     353
     354    // CAREFUL: note that Nsecf_disk and Nsecf_off are set to the values if there were no primary data
     355  }
     356
     357  // XXX check the open status of the catalog
     358  if (catalog[0].catflags & LOAD_MEAS) {
     359
     360    Catalog *subcat = catalog[0].measure_catalog;
     361
     362    /* move pointer past header -- must be already read (load_catalog) */
     363    fseek (subcat[0].f, subcat[0].header.size, SEEK_SET);
     364    /* matrix should be empty : XXX should we drop this step and skip the data? */
     365    if (!gfits_fread_matrix (subcat[0].f, &matrix, &subcat[0].header)) {
     366      if (VERBOSE) fprintf (stderr, "can't read primary matrix");
     367      return (FALSE);
     368    }
     369    /* read Measure table header */
     370    if (!gfits_fread_header (subcat[0].f, &header)) {
     371      if (VERBOSE) fprintf (stderr, "can't read table measure header");
     372      return (FALSE);
     373    }
     374    /* read Measure table data : format is irrelevant here */
     375    if (!gfits_fread_vtable_range (subcat[0].f, &vtable, start, Nrows)) {
     376      if (VERBOSE) fprintf (stderr, "can't read table measure data");
     377      return (FALSE);
     378    }
     379
     380    /* convert data format to internal : returns number of row read in Nmeasure */
     381    catalog[0].measure = VtableToMeasure (&vtable, &Nmeasure, &catalog[0].catformat);
     382    if (Nmeasure != Nrows) {
     383      fprintf (stderr, "Warning: mismatch between Nmeasure in PHU and Table headers (%d vs %d)\n", Nmeasure, Nrows);
     384    }
     385    gfits_free_header (&header);
     386    gfits_free_matrix (&matrix);
     387    catalog[0].Nmeasure = Nmeasure;
     388    catalog[0].Nmeas_off = start;
     389  }
     390
     391  // XXX check the open status of the catalog?
     392  if (catalog[0].catflags & LOAD_MISS) {
     393
     394    Catalog *subcat = catalog[0].missing_catalog;
     395
     396    /* move pointer past header -- must be already read (load_catalog) */
     397    fseek (subcat[0].f, subcat[0].header.size, SEEK_SET);
     398    /* matrix should be empty : XXX should we drop this step and skip the data? */
     399    if (!gfits_fread_matrix (subcat[0].f, &matrix, &subcat[0].header)) {
     400      if (VERBOSE) fprintf (stderr, "can't read primary matrix");
     401      return (FALSE);
     402    }
     403    /* read Missing table header */
     404    if (!gfits_fread_header (subcat[0].f, &header)) {
     405      if (VERBOSE) fprintf (stderr, "can't read table missing header");
     406      return (FALSE);
     407    }
     408    /* read Missing table data : format is irrelevant here */
     409    if (!gfits_fread_vtable_range (subcat[0].f, &vtable, start, Nrows)) {
     410      if (VERBOSE) fprintf (stderr, "can't read table missing data");
     411      return (FALSE);
     412    }
     413
     414    /* convert data format to internal : returns number of row read in Nmissing */
     415    catalog[0].missing = VtableToMissing (&vtable, &Nmissing, &catalog[0].catformat);
     416    if (Nmissing != Nrows) {
     417      fprintf (stderr, "Warning: mismatch between Nmissing in PHU and Table headers (%d vs %d)\n", Nmissing, Nrows);
     418    }
     419    gfits_free_header (&header);
     420    gfits_free_matrix (&matrix);
     421    catalog[0].Nmissing = Nmissing;
     422    catalog[0].Nmiss_off = start;
     423  }
    364424  return (TRUE);
    365425}
Note: See TracChangeset for help on using the changeset viewer.