示例#1
0
文件: writer.c 项目: BlastTNG/flight
void PreInitialiseDirFile(void)
{
  dtracevoid();

  int j;

  normal_fast = balloc(fatal, (ccFast + 1) * sizeof(struct FieldType));

  for (j = 0; j < FAST_PER_SLOW; ++j) {
    slow_fields[j] = balloc(fatal, slowsPerBi0Frame * sizeof(struct FieldType));
    slow_data[j] = balloc(fatal, slowsPerBi0Frame * sizeof(unsigned int));
  }
}
示例#2
0
void _GD_InitialiseFramework(void)
{
  dtracevoid();
#ifdef USE_MODULES
#ifdef USE_PTHREAD
  pthread_mutex_lock(&_gd_mutex);
#endif
  if (!framework_initialised) {
    framework_initialised = 1;
    lt_dlinit();
  }
#ifdef USE_PTHREAD
  pthread_mutex_unlock(&_gd_mutex);
#endif
#endif
  dreturnvoid();
}
示例#3
0
文件: writer.c 项目: BlastTNG/flight
/* Clean up in preparation for re-initialising dirfile with a new name
 * Close open file descriptors and free allocated memory */
void CleanUp(void)
{
  dtracevoid();
  int j, i, is_bolo = 0;
#if DAS_CARDS > 0
  char first_bolo_buf[16];
#endif

  for (i = 0; i < FAST_PER_SLOW + 10; ++i)
    bfree(fatal, pre_buffer[i]);

  for (i = 0; i < FAST_PER_SLOW; ++i)
    bfree(fatal, fast_frame[i]);

  for(i = 0; i < slowsPerBi0Frame; i++)
    for(j = 0; j < FAST_PER_SLOW; j++) {
      if (slow_fields[j][i].fp != -1)
        defileclose(slow_fields[j][i].fp);
      if (slow_fields[j][i].b)
        bfree(fatal, slow_fields[j][i].b);
      slow_fields[j][i].b = NULL;
    }

#if DAS_CARDS > 0
  sprintf(first_bolo_buf, "n%02dc00lo", DAS_START+1);
#endif
  for(i = 0; i < ccFast; ++i) {
#if DAS_CARDS > 0
    if (strcmp(FastChList[i].field, first_bolo_buf) == 0)
      is_bolo = 1;
    else if (ccDecom > 0 && strcmp(FastChList[i].field,
          DecomChannels[0].field) == 0)
      is_bolo = 0;
#endif

    if (!is_bolo) {
      if (normal_fast[i].fp != -1)
        defileclose(normal_fast[i].fp);
      if (normal_fast[i].b)
        bfree(fatal, normal_fast[i].b);
      normal_fast[i].b = NULL;
    }
  }

  if (defile_field.fp != -1)
    defileclose(defile_field.fp);
  if (defile_field.b)
    bfree(fatal, defile_field.b);
  defile_field.b = NULL;

#if DAS_CARDS > 0
  for (i = 0; i < DAS_CARDS; i++)
    for (j = 0; j < DAS_CHS; j++) {
      if (bolo_fields[i][j].fp != -1)
        defileclose(bolo_fields[i][j].fp);
      if (bolo_fields[i][j].b)
        bfree(fatal, bolo_fields[i][j].b);
      bolo_fields[i][j].b = NULL;
    }
#endif
}
示例#4
0
文件: writer.c 项目: BlastTNG/flight
/* DirFileWriter: separate thread: writes each field to disk */
void DirFileWriter(void)
{
  dtracevoid();
  unsigned short buffer[MAXBUF];
  unsigned int ibuffer[MAXBUF];
  int j, i;
  int i_in, i_out, i_buf;
  int i_in2, i_out2;
  int wrote_count = 0;
  int last_pass = 0;

  while (1) {
    /* slow data */
    for (i = 0; i < slowsPerBi0Frame; i++)
      for (j = 0; j < FAST_PER_SLOW; j++) {
        if (slow_fields[j][i].fp != -1) {
          i_in = slow_fields[j][i].i_in;
          i_out = slow_fields[j][i].i_out;
          i_buf = 0;
          if ((SlowChList[i][j].type == 'U') || (SlowChList[i][j].type == 'I')
              || (SlowChList[i][j].type == 'S'))
          {
            i_in2 = slow_fields[j][i + 1].i_in;
            i_out2 = slow_fields[j][i + 1].i_out;
            while (i_in != i_out && i_in2 != i_out2) {
              ibuffer[i_buf] = (unsigned)
                ((((unsigned short*)slow_fields[j][i + 1].b)[i_out2]) << 16)
                | (unsigned)
                (((unsigned short*)slow_fields[j][i].b)[i_out]);

              if (i == 0 && j == 0)
                wrote_count = ++slow_fields[j][i].nw * FAST_PER_SLOW;
              else if (wrote_count < ++slow_fields[j][i].nw * FAST_PER_SLOW)
                wrote_count = slow_fields[j][i].nw * FAST_PER_SLOW;

              i_out++;
              i_out2++;
              i_buf++;
              if (i_out >= MAXBUF)
                i_out = 0;
              if (i_out2 >= MAXBUF)
                i_out2 = 0;
            }

            WriteField(slow_fields[j][i].fp, i_buf * sizeof(unsigned), ibuffer);
            slow_fields[j][i].i_out = i_out;
            slow_fields[j][i + 1].i_out = i_out2;
          } else {
            while (i_in != i_out) {
              buffer[i_buf] = ((unsigned short*)slow_fields[j][i].b)[i_out];

              if (i == 0 && j == 0)
                wrote_count = ++slow_fields[j][i].nw * FAST_PER_SLOW;
              else if (wrote_count < ++slow_fields[j][i].nw * FAST_PER_SLOW)
                wrote_count = slow_fields[j][i].nw * FAST_PER_SLOW;

              i_out++;
              i_buf++;
              if (i_out >= MAXBUF)
                i_out = 0;
            }

            WriteField(slow_fields[j][i].fp, i_buf * sizeof(unsigned short),
                buffer);
            slow_fields[j][i].i_out = i_out;
          }
        } else if (i == 0 || ((SlowChList[i - 1][j].type != 'U')
              && (SlowChList[i - 1][j].type != 'I') &&
              (SlowChList[i - 1][j].type != 'S'))) {
          slow_fields[j][i].i_out = slow_fields[j][i].i_in;
        }
      }

    /* defile flags */
    i_in = defile_field.i_in;
    i_out = defile_field.i_out;
    i_buf = 0;

    while (i_in != i_out) {
      buffer[i_buf] = ((unsigned short*)defile_field.b)[i_out];

      if (wrote_count < ++defile_field.nw)
        wrote_count = defile_field.nw;

      i_out++;
      i_buf++;
      if (i_out >= MAXBUF)
        i_out = 0;
    }
    WriteField(defile_field.fp, i_buf * sizeof(unsigned short), buffer);
    defile_field.i_out = i_out;

    /**********************
     ** normal fast data **
     **********************/

    /* j = 0 (FASTSAMP) must be writen last if getdata is to return the proper
     * number of frames */
    for (j = 1; j < n_fast; j++) {
      i_in = normal_fast[j].i_in;
      i_out = normal_fast[j].i_out;
      i_buf = 0;
      if (normal_fast[j].size == 2) {
        while (i_in != i_out) {
          ibuffer[i_buf] = ((unsigned int*)normal_fast[j].b)[i_out];

          if (wrote_count < ++normal_fast[j].nw)
            wrote_count = normal_fast[j].nw;

          i_out++;
          i_buf++;
          if (i_out >= MAXBUF)
            i_out = 0;
        }

        WriteField(normal_fast[j].fp, i_buf * sizeof(unsigned), ibuffer);
      } else {
        while (i_in != i_out) {
          buffer[i_buf] = ((unsigned short*)normal_fast[j].b)[i_out];

          if (wrote_count < ++normal_fast[j].nw)
            wrote_count = normal_fast[j].nw;

          i_out++;
          i_buf++;
          if (i_out >= MAXBUF)
            i_out = 0;
        }
        WriteField(normal_fast[j].fp, i_buf * sizeof(unsigned short), buffer);
      }
      normal_fast[j].i_out = i_out;

    }

#if DAS_CARDS > 0
    /** Bolometer data */
    for (i = 0; i < DAS_CARDS; i++) {
      for (j = 0; j < DAS_CHS; j++) {
        i_in = bolo_fields[i][j].i_in;
        i_out = bolo_fields[i][j].i_out;

        i_buf = 0;
        while (i_in != i_out) {
          ibuffer[i_buf] =
            ((unsigned int*)bolo_fields[i][j].b)[i_out];

          if (wrote_count < bolo_fields[i][j].nw)
            wrote_count = bolo_fields[i][j].nw;

          i_out++;
          i_buf++;
          if (i_out >= MAXBUF)
            i_out = 0;
        }
        WriteField(bolo_fields[i][j].fp, i_buf * sizeof(unsigned), ibuffer);
        bolo_fields[i][j].i_out = i_out;
      }
    }
#endif

    /* Write FASTSAMP last */
    i_in = normal_fast[0].i_in;
    i_out = normal_fast[0].i_out;
    i_buf = 0;
    while (i_in != i_out) {
      ibuffer[i_buf] = ((unsigned int*)normal_fast[0].b)[i_out];

      if (wrote_count < ++normal_fast[0].nw)
        wrote_count = normal_fast[0].nw;

      i_out++;
      i_buf++;
      if (i_out >= MAXBUF)
        i_out = 0;
    }
    WriteField(normal_fast[0].fp, i_buf * sizeof(unsigned), ibuffer);
    normal_fast[0].i_out = i_out;

    /* Done writing */
    if (ri.wrote < wrote_count)
      ri.wrote = wrote_count;

    if (ri.reader_done) {
      if (ri.wrote == ri.read || last_pass) {
        ri.writer_done = 1;
        CleanUp();
        return;
      } else
        last_pass = 1;
    }

    usleep(10000);

    /* if dirfile_init is lowered, the reader has noticed a change in the
     * curfile: prepare for cycling the writer. */
    if (ri.dirfile_init == 0) {
      /* perform one last pass to ensure we've written all the data (the reader
       * has certainly stopped by now, so we should be fine with a single
       * last pass */
      if (!last_pass)
        last_pass = 1;
      else {
        /* Clean Up */
        CleanUp();

        bprintf(info, "Defiling `%s'\n    into `%s'\n", rc.chunk, rc.dirfile);
        if (rc.resume_at > 0)
          bprintf(info, "    starting at frame %li\n", rc.resume_at);
        bprintf(info, "\n");

        /* Re-initialise */
        wrote_count = 0;
        ri.read = ri.wrote = ri.old_total = 0;
        ri.frame_rate_reset = 1;
        InitialiseDirFile(1, 0);
        gettimeofday(&ri.last, &rc.tz);
        last_pass = 0;
      }
    }
  }
}