IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 34356


Ignore:
Timestamp:
Aug 25, 2012, 11:45:32 AM (14 years ago)
Author:
eugene
Message:

adding dvomerge history code to dvomerge

Location:
branches/eam_branches/ipp-20120805/Ohana/src/dvomerge/src
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20120805/Ohana/src/dvomerge/src/dvomergeImageIDs.c

    r33963 r34356  
    2121    return TRUE;
    2222  }
     23  // this operation reads the PHU header (inDB.header)
    2324  if (!dvo_image_load (&inDB, VERBOSE, TRUE)) {
    2425    Shutdown ("can't read input image catalog %s", inDB.filename);
    2526  }
     27
     28  // read the header for the database ID?
     29  char *indbID = dvomergeHistoryReadID (&inDB);
     30  if (!indbID) {
     31    Shutdown ("this database is missing a DVO database ID; please generate one before merging\n");
     32  }
    2633
    2734  /*** load output/Images.dat ***/
     
    4148  }
    4249
     50  dmhImage *history = dmhImageRead (&outDB);
     51  if (!history) {
     52    Shutdown ("error reading history for output database\n");
     53  }
     54
    4355  // convert database table to internal structure & add to output image db
    4456  dvo_image_merge_dbs(IDmap, &outDB, &inDB);
    4557  dvo_image_unlock (&inDB); // unlock input
     58
     59  // add the new image db to merge history
     60  // (updates header as well as history structure
     61  if (!dmhImageAdd (&outDB, history, indbID)) {
     62    Shutdown ("error reading history for output database\n");
     63  }
     64
     65  // XXX I need to pass the history structure back out somehow...
    4666
    4767  SetProtect (TRUE);
  • branches/eam_branches/ipp-20120805/Ohana/src/dvomerge/src/dvomergeUpdate_catalogs.c

    r34260 r34356  
    3131    outlist = SkyListByBounds (outsky, -1, inlist[0].regions[i][0].Rmin + dPos, inlist[0].regions[i][0].Rmax - dPos, inlist[0].regions[i][0].Dmin + dPos, inlist[0].regions[i][0].Dmax - dPos);
    3232
    33     // there may be more than one output region for a given input region.  are any of these output regions relevant to this machine?
     33    OutputStatus *outstat = OutputStatusInit (outlist->Nregions);
     34
     35    // there may be more than one output region for a given input region. 
     36    // are any of these output regions relevant to this machine?
    3437    int found = FALSE;
    3538    for (j = 0; !found && (j < outlist[0].Nregions); j++) {
    36       found = (found || HostTableTestHost(outlist[0].regions[j], HOST_ID));
     39      outstat[j].valid = HostTableTestHost(outlist[0].regions[j], HOST_ID);
     40      found = (found || outstat[j].valid);
    3741    }
    3842
    3943    // skip this input table for if no output files are on this machine
    4044    if (!found) {
     45      OutputStatusFree (outstat, outlist->Nregions);
    4146      SkyListFree (outlist);
    4247      continue;
    4348    }
    4449
    45     // get the stats on this input file (for comparison with the output headers)
    46     struct stat instats;
    47     int stat_result = stat (inlist[0].filename[i], &instats);
    48     if (stat_result) {
    49       if (errno == ENOENT) continue;
    50       fprintf (stderr, "cannot read stats on input file %s\n", inlist[0].filename[i]);
    51       perror ("stats error message:");
    52       exit (2);
    53     }
    54 
    55     // instats.st_size & instats.st_mtime
    56 
    57     // check if any of the output files have NOT yet received data from this input file
    58 
     50    // get stats for history check
     51    dmhObjectStats *inStats = dmhObjectStatsRead (inlist[0].filename[i]);
     52
     53    // Check if any of the output files have NOT yet received data from this input file
     54    // If none have been missed, we can skip the input file completely
    5955    int missed = FALSE;
    60     for (j = 0; !missed && (j < outlist[0].Nregions); j++) {
    61       if (!HostTableTestHost(outlist[0].regions[j], HOST_ID)) continue;
     56    for (j = 0; j < outlist[0].Nregions; j++) {
     57      if (!outstat[j].valid) continue;
    6258
    6359      // set the parameters which guide catalog open/load/create
     
    6561      snprintf (hostfile, DVO_MAX_PATH, "%s/%s.cpt", HOSTDIR, outlist[0].regions[j]->name);
    6662      char *filename = HOST_ID ? hostfile : outlist[0].filename[j];
    67 
    68       // get the stats on this input file (for comparison with the output headers)
    69       struct stat outstats;
    70       stat_result = stat (filename, &outstats);
    71       if (stat_result) {
    72         if (errno == ENOENT) {
    73           missed = TRUE;
    74           break;
    75         }
    76         fprintf (stderr, "cannot read stats on output file %s\n", filename);
    77         perror ("stats error message:");
    78         exit (2);
    79       }
    80 
    81       FILE *fout = fopen (filename, "r");
    82       if (!fout) {
    83         fprintf (stderr, "problem opening output file to read header %s\n", filename);
    84         perror ("stats error message:");
    85         exit (2);
    86       }
    87 
    88       Header outheader;
    89       if (!gfits_fread_header (fout, &outheader)) {
    90         fprintf (stderr, "problem reading header for output file %s\n", filename);
    91         exit (2);
    92       }
    93      
    94       fclose (fout);
    95 
    96       // XXX note that we are hardwired to v 2
    97       // check the header of output catalog for an existing merge
    98       long long last_size;
    99       char last_moddate[80];
    100       gfits_scan (&outheader, "LMRG_SZ2", "%lld", 1, &last_size);     
    101       gfits_scan (&outheader, "LMRG_DT2", "%s", 1, last_moddate);     
    102 
    103       time_t last_mod = ohana_date_to_sec (last_moddate);
    104 
    105       if (last_size != instats.st_size) {
    106         missed = TRUE;
    107         break;
    108       }
    109      
    110       if (last_mod != instats.st_mtime) {
    111         missed = TRUE;
    112         break;
    113       }
     63      outstat[j].filename = strcreate (filename);
     64
     65      outstat[j].history = dmhObjectRead (outstat[j].filename);
     66
     67      outstat[j].missed = dmhObjectCheck (outstat[j].history, inStats);
     68      missed = (missed || outstat[j].missed);
    11469    }
    11570    if (!missed) {
    11671      fprintf (stderr, "skipping %s, already merged\n", inlist[0].filename[i]);
     72      OutputStatusFree (outstat, outlist->Nregions);
     73      dmhObjectStatsFree (inStats);
     74      SkyListFree (outlist);
    11775      continue;
    11876    }
     
    12583        dvo_catalog_unlock (&incatalog);
    12684        dvo_catalog_free (&incatalog);
     85        OutputStatusFree (outstat, outlist->Nregions);
     86        dmhObjectStatsFree (inStats);
    12787        SkyListFree (outlist);
    12888        continue;
    12989    }
    130 
    131     char *moddate = ohana_sec_to_date (instats.st_mtime);
    13290
    13391    // merge input into the appropriate output tables
    13492    for (j = 0; j < outlist[0].Nregions; j++) {
    13593      // skip tables for which the output files are not on this machine
    136       if (!HostTableTestHost(outlist[0].regions[j], HOST_ID)) continue;
     94      if (!outstat[j].valid) continue;
     95
     96      // skip if we have already done the merge
     97      if (!outstat[j].missed) continue;
    13798
    13899      if (VERBOSE) fprintf (stderr, "output : %s\n", outlist[0].regions[j][0].name);
    139100
    140       // set the parameters which guide catalog open/load/create
    141       char hostfile[DVO_MAX_PATH];
    142       snprintf (hostfile, DVO_MAX_PATH, "%s/%s.cpt", HOSTDIR, outlist[0].regions[j]->name);
    143       outcatalog.filename  = HOST_ID ? hostfile : outlist[0].filename[j];
     101      // the real filename
     102      outcatalog.filename = outstat[j].filename;
    144103
    145104      // load input catalog
     
    151110      outcatalog.catflags = LOAD_AVES | LOAD_MEAS | LOAD_MISS | LOAD_SECF;
    152111
    153 # if (0)
    154       // get the LMRG data from the previous pass
    155       long long last_size;
    156       char last_moddate[80];
    157       int status_size = gfits_scan (&outcatalog.header, "LMRG_SZ", "%lld", 1, &last_size);     
    158       int status_date = gfits_scan (&outcatalog.header, "LMRG_DT", "%s", 1, last_moddate);     
    159 
    160       // save the LMRG data from the previous pass
    161       if (status_size && status_date) {
    162         gfits_modify (&outcatalog.header, "LMRG_SZ1", "%lld", 1, (long long) last_size);     
    163         gfits_modify (&outcatalog.header, "LMRG_DT1", "%s", 1, last_moddate);     
    164       }
    165 
    166       // update header of output catalog
    167       gfits_modify (&outcatalog.header, "LMRG_SZ", "%lld", 1, (long long) instats.st_size);     
    168       gfits_modify (&outcatalog.header, "LMRG_DT", "%s", 1, moddate);     
    169 # endif
    170 
    171       // update header of output catalog
    172       // XXX note that we are hardwired to v 2
    173       gfits_modify (&outcatalog.header, "LMRG_SZ2", "%lld", 1, (long long) instats.st_size);     
    174       gfits_modify (&outcatalog.header, "LMRG_DT2", "%s", 1, moddate);     
     112      dmhObjectAdd (outstat[j].history, &outcatalog.header, inStats);
    175113
    176114      if (!dvo_catalog_backup (&outcatalog, TRUE)) {
     
    196134      fprintf (stderr, "merged %s into %s\n", inlist[0].regions[i][0].name, outlist[0].regions[j][0].name);
    197135    }
     136
     137    OutputStatusFree (outstat, outlist->Nregions);
    198138    SkyListFree (outlist);
    199     free (moddate);
     139    dmhObjectStatsFree (inStats);
    200140
    201141    dvo_catalog_unlock (&incatalog);
Note: See TracChangeset for help on using the changeset viewer.