//------------------------------------------------------------------------------
    ByteBufferUPtr BinaryInputStream::Read(u64 length) noexcept
    {
        CS_ASSERT(IsValid(), "Trying to use an invalid FileStream.");
        
        if(m_fileStream.eof())
        {
            return nullptr;
        }
        
        //Ensure that we never overrun the file stream
        const auto currentPosition = GetReadPosition();
        const auto maxValidLength = std::min(m_length - currentPosition, length);
        
        if(maxValidLength == 0)
        {
            return nullptr;
        }
        
        s8* data = new s8[maxValidLength];
        m_fileStream.read(data, maxValidLength);
        
        CS_ASSERT(!m_fileStream.fail(), "Unexpected error occured in filestream");

        std::unique_ptr<const u8[]> uniqueData(reinterpret_cast<const u8*>(data));
        return ByteBufferUPtr(new ByteBuffer(std::move(uniqueData), u32(maxValidLength)));
    }
Beispiel #2
0
IndexType readAtomNameMapFile (const char * filename,
			       const IndexType numAtom,
			       const char * atomName,
			       TypeType * type,
			       ScalorType * mass,
			       ScalorType * charge)
{
  FILE * fp = fopen (filename, "r");
  if (fp == NULL) throw MDExcptCannotOpenFile ("readAtomNameMapFile", filename);
  char tmpname[StringSize];
  ScalorType tmpmass, tmpcharge;
  TypeType tmptype;
  int tag;
  std::vector<std::string> names;
  std::vector<TypeUnit   > data;

  char line [1024];
  while (fgets(line , 1024, fp) != NULL) {
    IndexType position = 0;
    while (isspace(line[position])) position ++;
    if (line[position] == '#') continue;
    tag = sscanf (line, "%s%d%f%f", 
		  tmpname, &tmptype, &tmpmass, &tmpcharge);
    if (tag == 4){
      TypeUnit tmpunit = TypeUnit (tmptype, tmpmass, tmpcharge);
      names.push_back (std::string(tmpname));
      data .push_back (tmpunit);
    }
  }
  
  std::vector<TypeUnit  > uniqueData (data);
  std::vector<TypeUnit  >::iterator new_end ;
  new_end = std::unique (uniqueData.begin(), uniqueData.end());
  uniqueData.erase (new_end, uniqueData.end());

  for (IndexType i = 0; i < names.size(); ++i){
    std::cout << "# "
	      << names[i] << "\t"
	      << data[i].type << " " 
	      << data[i].mass << " "
	      << data[i].charge << std::endl;
  }
  
  for (IndexType i = 0; i < numAtom; ++i){
    IndexType target = 0;
    for (; target < names.size(); ++target){
      if (names[target] == std::string(&atomName[i*StringSize])){
	type[i] = data[target].type;
	mass[i] = data[target].mass;
	charge[i] = data[target].charge;
	break;
      }
    }
    if (target == names.size()){
      throw MDExcptUndefinedAtomType("readAtomNameMapFile", &atomName[i*StringSize]);
    }
  }

  return uniqueData.size();
}
Beispiel #3
0
CelledBaseChunkReader::CelledBaseChunkReader(
        const Metadata& m,
        PointPool& pool,
        const arbiter::Endpoint& endpoint)
    : BaseChunkReader(m, pool)
{
    DimList dims;
    dims.push_back(DimInfo("TubeId", "unsigned", 8));
    dims.insert(dims.end(), m.schema().dims().begin(), m.schema().dims().end());
    const Schema celledSchema(dims);
    PointPool celledPool(celledSchema, m.delta());

    auto tubedCells(m.storage().deserialize(endpoint, celledPool, m_id));
    Data::PooledStack tubedData(celledPool.dataPool());

    auto dataNodes(m_pool.dataPool().acquire(tubedCells.size()));
    m_cells = m_pool.cellPool().acquire(tubedCells.size());

    const std::size_t celledPointSize(celledSchema.pointSize());
    const std::size_t tubeIdSize(sizeof(uint64_t));
    uint64_t tube(0);
    char* tPos(reinterpret_cast<char*>(&tube));

    BinaryPointTable table(m.schema());
    pdal::PointRef pointRef(table, 0);

    for (auto& cell : m_cells)
    {
        auto tubedCell(tubedCells.popOne());
        const char* src(tubedCell->uniqueData());

        Data::PooledNode data(dataNodes.popOne());

        std::copy(src, src + tubeIdSize, tPos);
        std::copy(src + tubeIdSize, src + celledPointSize, *data);

        table.setPoint(*data);
        cell.set(pointRef, std::move(data));

        m_points.at(tube).emplace_back(cell.point(), cell.uniqueData());

        tubedData.push(tubedCell->acquire());
    }
}