Exemple #1
0
bool TraceChunkSerializer::Write(const char *filename, SynchDat &data) {
  data.mInfo.SetValue(SYNCHDATSERIALIZE_VERSION_KEY, SYNCHDATSERIALIZE_VERSION_VALUE);
  int numEntries = data.mInfo.GetCount();
  vector<string> keys(numEntries);
  vector<string> values(numEntries);
  vector<const char *> keysBuff(numEntries);
  vector<const char *> valuesBuff(numEntries);
  for (int i = 0; i < numEntries; i++) {
    data.mInfo.GetEntry(i, keys[i], values[i]);
    keysBuff[i] = keys[i].c_str();
    valuesBuff[i] = values[i].c_str();
  }
  ClockTimer timer;
  H5File h5(filename);
  bool ok = h5.OpenNew();
  openMicroSec = timer.GetMicroSec();
  if (!ok) { return ok; }
  timer.StartTimer();
  h5.WriteStringVector(INFO_KEYS, &keysBuff[0], keysBuff.size());
  h5.WriteStringVector(INFO_VALUES, &valuesBuff[0], keysBuff.size());
  ioMicroSec = timer.GetMicroSec();
  ok =  Write(h5, data.GetMesh());
  timer.StartTimer();
  h5.Close();
  H5garbage_collect();
  ioMicroSec += timer.GetMicroSec();
  return ok;
}
Exemple #2
0
bool TraceChunkSerializer::Read(const char *filename, SynchDat &data) {
  data.Clear();
  if (!H5File::IsH5File(filename)) {
    return false;
  }
  bool result = true;
  try {
    if (!mRecklessAbandon) {
      uint32_t waitTime = mRetryInterval;
      int32_t timeOut = mTotalTimeout;
      //--- Wait up to 3600 seconds for a file to be available
      while ( timeOut > 0 )
        {
          //--- Is the file we want available?
          if ( Image::ReadyToLoad ( filename ) ) {
            break;
          }
          //DEBUG
          fprintf ( stdout, "Waiting to load %s\n", filename );
          sleep ( waitTime );
          timeOut -= waitTime;
        }
    }
    /* Turn off error printing as we're not sure this is actually an hdf5 file. */
    H5File h5(filename);
    result = h5.OpenForReading();

    if (result) {
      h5.SetReadOnly(true);
      result &= Read(h5, data.GetMesh());
      ReadInfo(h5, data);
    }
    h5.Close();
  }
  catch (...) {
    result = false;
  }
  return result;
}