Example #1
0
void  RegionTrackerRecorder::WriteFlowInfo()
{
  vector<hsize_t> flowindex_dims(2);
  flowindex_dims[0] = 2;
  flowindex_dims[1] = numFlows;
  
  // where should this really be handled??
  vector<int> flowBlockIndex(2*numFlows);
  for (int i=0; i<numFlows; i++){
    int j = i+numFlows;
    flowBlockIndex[i] = i % NUMFB;  // within block index indexed by flow
    flowBlockIndex[j] = i/NUMFB;    // block id indexed by flow
  }

  for (int i=0; i<numFlows; i++){
    flowToIndex[i] = flowBlockIndex[i];
    flowToBlockId[i] = flowBlockIndex[i+numFlows];
  }


  H5ReplayRecorder recorder = H5ReplayRecorder(clo, FLOWINDEX);
  recorder.CreateDataset(flowindex_dims);

  // hyperslab layout on disk
  // 2 x numFlows
  // 0, 1, 2, ... NUMFB-1, 0, 1, 2, ...
  // 0, 0, 0, ...    0,    1, 1, 1, ... 
  // start position [0,0]
  vector<hsize_t> offset(2);
  offset[0] = 0;
  offset[1] = 0;

  vector<hsize_t> count(2);
  count[0] = 2;
  count[1] = numFlows;

  // memory layout of slab we write from is 2 x numFlows
  // start position in memory slab is [0,0]
  vector<hsize_t> offset_in(2);
  offset_in[0] = 0;
  offset_in[1] = 0;

  vector<hsize_t> count_in(2);
  count_in[0] = 2;
  count_in[1] = numFlows;

  // fprintf(stdout, "H5 buffer, flow %d, region %d: %f, %f, ...\n", flow, regionIndex, newbuff[0], newbuff[1]);
  recorder.Write(offset, count, offset_in, count_in, &flowBlockIndex[0]);
}
Example #2
0
void *do_subset(void* data)
{
  pthread_detach( pthread_self() );

  struct thread_args *args = (struct thread_args *)data;
  hsize_t row = args->row;
  hsize_t col = args->col;
  vector<hsize_t>chunks( * (args->chunks));
  vector<hsize_t>dims(* (args->dims));
  string h5file_in = string(* (args->h5file_in));
  string source = string( * (args->source));
  string h5file_out = string(* (args->h5file_out));
  string destination = string(* (args->destination));
  hsize_t offset_out_0 = args->offset_out;
  hsize_t count_out_0 = args->count_out;
  vector<size_t>input_positions(* (args->input_positions));
  unsigned int thread_id = args->thread_id;
  unsigned int flowlimit = args->flowlimit;

  H5ReplayReader reader = H5ReplayReader(h5file_in, &source[0]);
  H5ReplayRecorder recorder = H5ReplayRecorder(h5file_out, &destination[0]);

  // read a chunk in
  vector<hsize_t> offset(3);
  offset.At(0) = row;
  offset.At(1) = col;
  offset.At(2) = 0;
      
  vector<hsize_t> count(3);
  count.At(0) = ( row+chunks.At(0) < dims.At(0) ) ? chunks.At(0) : dims.At(0)-row;
  count.At(1) = ( col+chunks.At(1) < dims.At(1) ) ? chunks.At(1) : dims.At(1)-col;
  count.At(2) = dims.At(2);

  vector<float> signal(count.At(0) * count.At(1) * count.At(2));
  vector<float> subset(count_out_0*count.At(2));

  vector<hsize_t> offset_in(1);
  offset_in.At(0) = 0;

  vector<hsize_t> count_in(1, signal.size());
      
  // fprintf(stdout, "thread_id %d reading %d from row=%d (max %d), %d from column=%d (max %d)\n", thread_id, (int)count.At(0), (int)row, (int)dims.At(0), (int)count.At(1), (int)col, (int)dims.At(1));
  reader.Read(offset, count, offset_in, count_in, &signal[0]);

  // now subset well at a time
  size_t ix = 0;
  size_t incr = 0;
  vector<size_t> subset_input_positions(count_out_0);
  for (size_t rr=row; rr<(row+count.At(0)) && ix < input_positions.size(); rr++) {
    for (size_t cc=col; cc<(col+count.At(1)) && ix < input_positions.size(); cc++) {
      size_t pos = input_positions.At(ix);
      size_t chp_indx = RowColToIndex1(rr,cc, dims.At(0), dims.At(1));
      if ( chp_indx < pos)
	continue;

      while ( chp_indx > pos){
	ix++;
	if (ix == input_positions.size())
	  break;
	pos = input_positions.At(ix);
	
      }

      if( chp_indx == pos) {
	size_t array_indx = RowColToIndex1(rr-row,cc-col,count.At(0),count.At(1))*dims.At(2);
	// fprintf(stdout, "thread_id=%d: Position match %lu at chip rr=%lu, rr-row=%d, cc=%lu, cc-col=%d, (array_indx=%lu)/(dims[2]=%llu)=%llu\n", thread_id, pos, rr, (int)(rr-row), cc, (int)(cc-col), array_indx, dims.At(2), array_indx/dims.At(2));
	for(size_t flow=0; flow<flowlimit; flow++)
	  subset.At(incr*dims.At(2) + flow) = signal.At( array_indx + flow);
	assert (incr < count_out_0 );
	subset_input_positions.At(incr) = input_positions.At(ix);
	incr++;
	ix++;
      }
      assert (ix <= input_positions.size() );
    }
  }

  assert (incr == count_out_0 );

  // write the chunk back out
  vector<hsize_t> count_out(2);
  count_out.At(0) = count_out_0;
  count_out.At(1) = dims.At(2);

  vector<hsize_t> offset_out(2);
  offset_out.At(0) = offset_out_0;
  offset_out.At(1) = 0;

  vector<hsize_t> offset_in_subset(1,0);
  vector<hsize_t> count_in_subset(1,subset.size());
  recorder.Write(offset_out, count_out, offset_in_subset, count_in_subset, &subset[0]);
  
  {
    string position = "position";
    H5ReplayRecorder recorder_pos = H5ReplayRecorder(h5file_out, &position[0]);

    vector<hsize_t> offset_pos(1, offset_out.At(0));
    vector<hsize_t> count_pos(1, count_out.At(0));
    recorder_pos.Write(offset_pos, count_pos, offset_in, count_pos, &subset_input_positions[0]);
  }
  
  thread_flags.at(thread_id) = 0;
  int ret = 0;
  pthread_exit(&ret);

  return(NULL);
}  
Example #3
0
void *compute_norm(void* data)
{
  // fprintf(stdout, "Thread count %d\n", thread_count);

  pthread_detach( pthread_self() );

  struct compute_norm_args *args = (struct compute_norm_args *)data;
  hsize_t row = args->row;
  hsize_t col = args->col;
  vector<hsize_t>chunks( * (args->chunks));
  vector<hsize_t>dims(* (args->dims));
  string h5file = string(* (args->h5file));
  string source = string( * (args->source));
  string destination = string(* (args->destination));
  unsigned int thread_id = args->thread_id;
  unsigned int flowlimit = args->flowlimit;

  H5ReplayReader reader = H5ReplayReader(h5file, &source[0]);
  H5ReplayRecorder recorder = H5ReplayRecorder(h5file, &destination[0]);
  
  // read a chunk in
  vector<hsize_t> offset(3);
  offset[0] = row;
  offset[1] = col;
  offset[2] = 0;
      
  vector<hsize_t> count(3);
  count[0] = ( row+chunks[0] < dims[0] ) ? chunks[0] : dims[0]-row;
  count[1] = ( col+chunks[1] < dims[1] ) ? chunks[1] : dims[1]-col;
  count[2] = dims[2];

  vector<float> signal(count[0] * count[1] * count[2], 0);
  vector<float> normed_signal(signal.size(), 0);

  vector<hsize_t> offset_in(1);
  offset_in[0] = 0;

  vector<hsize_t> count_in(1);
  count_in[0] = signal.size();
      
  // fprintf(stdout, "thread_id %d reading %d from row=%d (max %d), %d from column=%d (max %d)\n", thread_id, (int)count[0], (int)row, (int)dims[0], (int)count[1], (int)col, (int)dims[1]);
  reader.Read(offset, count, offset_in, count_in, &signal[0]);

  // now normalize a well at a time
  size_t ix = 0;
  for (size_t rr=0; rr<count[0]; rr++) {
    for (size_t cc=0; cc<count[1]; cc++) {
      size_t wellindex = ix*count[2];
      ix++;
      vector<double> peaks;
      assert (flowlimit <= dims[2] );
      vector<float>dat(signal.begin()+wellindex, signal.begin()+wellindex+flowlimit);
      vector<float>normalized(dat.size(), 0);
      NoKeyCall nkc;
      nkc.SetBeadLocation(cc+col,rr+row);
      nkc.GetPeaks(dat, peaks);
      float failure_to_normalize_value = -1.0f;
      nkc.NormalizeBeadSignal(dat, peaks, normalized, failure_to_normalize_value);
      // vector<float>normalized(dat.size(), 1);
      
      // stick it back in signal
      double v = 0;
      for (size_t fnum = 0; fnum < count[2]; fnum++){
	if (fnum < flowlimit) {
	  *(normed_signal.begin()+wellindex+fnum) = normalized[fnum];
	  v += fabs(normalized[fnum]);
	}
	else {
	  *(normed_signal.begin()+wellindex+fnum) = 0;
	}
      }
      assert(v>0);
    }
  }

  // write the chunk back out
  vector<hsize_t> extension(3);
  extension[0] = row+count[0];
  extension[1] = col+count[1];
  extension[2] = count[2];
  
  recorder.ExtendDataSet(extension); // extend if necessary
  recorder.Write(offset, count, offset_in, count_in, &normed_signal[0]);
  
  thread_flags.at(thread_id) = 0;
  int ret = 0;
  pthread_exit(&ret);

  return(NULL);
}