Beispiel #1
0
void BingoPgSection::readSectionBitsCount(indigo::Array<int>& bits_number) {
   bits_number.resize(_sectionInfo.n_structures);
   bits_number.zerofill();

   if(_bitsCountBuffers.size() == 0)
      _bitsCountBuffers.resize(SECTION_BITSNUMBER_PAGES);
   
   int data_len, str_idx;
   unsigned short* buffer_data;
   for (int buf_idx = 0; buf_idx < SECTION_BITSNUMBER_PAGES; ++buf_idx) {
      if(buf_idx * SECTION_BITS_PER_BLOCK >= _sectionInfo.n_structures)
         break;

      BingoPgBuffer& bits_buffer = _bitsCountBuffers[buf_idx];
      bits_buffer.readBuffer(_index, _offset + buf_idx + SECTION_META_PAGES, BINGO_PG_READ);
      buffer_data = (unsigned short*) bits_buffer.getIndexData(data_len);
      for (int page_str_idx = 0; page_str_idx < SECTION_BITS_PER_BLOCK; ++page_str_idx) {
         str_idx = buf_idx * SECTION_BITS_PER_BLOCK + page_str_idx;
         if (str_idx >= _sectionInfo.n_structures)
            break;
         bits_number[str_idx] = buffer_data[page_str_idx];
      }
      bits_buffer.changeAccess(BINGO_PG_NOLOCK);
   }

   
}
Beispiel #2
0
unsigned short BingoPgBufferCacheBin::writeBin(indigo::Array<char>& bin_buf) {
   /*
    * If read strategy then it is an update so read the buffer in this function also
    */
   if(bin_buf.sizeInBytes() > MAX_SIZE)
      throw Error("internal error: can not add bin to the cache because is not enough space");

   /*
    * Prepare output offset
    */
   unsigned short result = 0;

   /*
    * Prepare new array = size + buf
    */
   indigo::Array<char> out_arr;
   indigo::ArrayOutput ao(out_arr);
   BingoPgCommon::DataProcessing::handleArray(bin_buf, 0, &ao);
   /*
    * Store data with it size
    */
   _cache.copy(out_arr);
   /*
    * If read strategy then it is an update so write the buffer
    */
   if(!_write) {
      _writeCache();
   }
   return result;
}
Beispiel #3
0
void BingoPgIndex::readXyzItem(int section_idx, int mol_idx, indigo::Array<char>& xyz_buf) {
   /*
    * Prepare info for reading
    */
   BingoPgSection& current_section = _jumpToSection(section_idx);
   int map_block_idx = mol_idx / BINGO_MOLS_PER_MAPBLOCK;
   int map_mol_idx = mol_idx % BINGO_MOLS_PER_MAPBLOCK;
   BingoPgBufferCacheMap& map_cache = current_section.getMapBufferCache(map_block_idx);

   elog(DEBUG1, "bingo: index: read xyz: start read structure %d for section = %d", mol_idx, section_idx);

   /*
    * Get xyz item
    */
   ItemPointerData xyz_item;
   map_cache.getXyzItem(map_mol_idx, xyz_item);
   /*
    * Check for correct block num
    */
   dword block_num = ItemPointerGetBlockNumber(&xyz_item);
   if(block_num == InvalidBlockNumber) {
      xyz_buf.clear();
      elog(DEBUG1, "bingo: index: read xyz: xyz is empty for structure %d for section = %d", mol_idx, section_idx);
      return;
   }
   unsigned short block_offset = ItemPointerGetOffsetNumber(&xyz_item);
   /*
    * Read xyz buffer for a given offset
    */
   BingoPgBufferCacheBin& bin_cache = current_section.getBinBufferCache(block_num);
   bin_cache.readBin(block_offset, xyz_buf);
   elog(DEBUG1, "bingo: index: read xyz: successfully read xyz of size %d for block %d offset %d", xyz_buf.size(), block_num, block_offset);
}
Beispiel #4
0
void BingoPgSection::_setBinData(indigo::Array<char>& buf, int& last_buf, ItemPointerData& item_data) {
   if(buf.size() == 0) {
      BINGO_PG_TRY {
         ItemPointerSet(&item_data, InvalidBlockNumber, 0);
      } BINGO_PG_HANDLE(throw Error("internal error: can not set block data: %s", message));
      return;
   }
void RingoPgSearchEngine::_prepareExactQueryStrings(indigo::Array<char>& what_clause_str, indigo::Array<char>& from_clause_str, indigo::Array<char>& where_clause_str) {
   ArrayOutput what_clause(what_clause_str);
   ArrayOutput from_clause(from_clause_str);
   ArrayOutput where_clause(where_clause_str);

   what_clause.printf("b_id");
   from_clause.printf("%s", _shadowRelName.ptr());

   dword ex_hash;
   int bingo_res = ringoGetHash(0, &ex_hash);
   CORE_HANDLE_ERROR(bingo_res, 1, "reaction search engine: error while getting hash", bingoGetError());

   where_clause.printf("ex_hash=%d", ex_hash);

   what_clause_str.push(0);
   from_clause_str.push(0);
   where_clause_str.push(0);

}
void MangoPgSearchEngine::_prepareExactTauStrings(indigo::Array<char>& what_clause_str, indigo::Array<char>& from_clause_str, indigo::Array<char>& where_clause_str) {
   ArrayOutput what_clause(what_clause_str);
   ArrayOutput from_clause(from_clause_str);
   ArrayOutput where_clause(where_clause_str);

   what_clause.printf("b_id");
   from_clause.printf("%s", _shadowRelName.ptr());

   const char* query_gross = mangoTauGetQueryGross();
   if(query_gross == 0)
      CORE_HANDLE_ERROR(0, 1, "molecule seach engine: error while constructing gross string", bingoGetError());
   
   where_clause.printf("gross='%s' OR gross LIKE '%s H%%'", query_gross, query_gross);

   what_clause_str.push(0);
   from_clause_str.push(0);
   where_clause_str.push(0);

}
Beispiel #7
0
void BingoPgIndex::readDictionary(indigo::Array<char>& dictionary) {
   dictionary.clear();
   if(_metaInfo.n_blocks_for_dictionary == 0) 
      return;
   
   
   indigo::Array<char> buffer_dict;
   int block_size = _metaInfo.n_blocks_for_dictionary + _metaInfo.offset_dictionary;
   /*
    * Read all buffers for dictionary
    */
   for (int block_idx = _metaInfo.offset_dictionary; block_idx < block_size; ++block_idx) {
      BingoPgBufferCacheBin buffer_cache(block_idx, _index, false);
      /*
       * Read and concat buffers
       */
      buffer_cache.readBin(0, buffer_dict);
      dictionary.concat(buffer_dict);
   }
}
void MangoPgSearchEngine::_prepareExactQueryStrings(indigo::Array<char>& what_clause_str, indigo::Array<char>& from_clause_str, indigo::Array<char>& where_clause_str) {
   int hash_elements_count, count, bingo_res;
   dword hash;

   ArrayOutput what_clause(what_clause_str);
   ArrayOutput from_clause(from_clause_str);
   ArrayOutput where_clause(where_clause_str);

   what_clause.printf("sh.b_id");

   bingo_res = mangoGetHash(false, -1, &hash_elements_count, &hash);
   CORE_HANDLE_ERROR(bingo_res, 1, "molecule search engine: error while getting hash", bingoGetError());

   if(hash_elements_count > MAX_HASH_ELEMENTS)
      hash_elements_count = MAX_HASH_ELEMENTS;

   from_clause.printf("%s sh", _shadowRelName.ptr());

   for (int i = 0; i < hash_elements_count; i++)
      from_clause.printf(", %s t%d", _shadowHashRelName.ptr(), i);

   /*
    * Create complex WHERE clause
    */

   bool where_was_added = false;
   if (hash_elements_count > 0) {
      where_was_added = true;
      /*
       * molecule ids must be same
       */
      where_clause.printf("sh.b_id = t0.b_id AND ");
      for (int i = 1; i < hash_elements_count; i++)
         where_clause.printf("t%d.b_id = t%d.b_id AND ", i - 1, i);
      /*
       * query components must match target components
       */
      for (int i = 0; i < hash_elements_count; i++) {
         bingo_res = mangoGetHash(false, i, &count, &hash);
         CORE_HANDLE_ERROR(bingo_res, 1, "molecule search engine: error while getting hash", bingoGetError());

         where_clause.printf("t%d.ex_hash = %d AND ", i, hash);
      }

      /*
       * components count mast must target components count
       */
      Array<char> rel;
      bingo_res = mangoExactNeedComponentMatching();
      CORE_HANDLE_ERROR(bingo_res, 0, "molecule search engine: error while getting need matching", bingoGetError());

      if (bingo_res > 0)
         rel.readString(">=", true);
      else
         rel.readString("=", true);

      for (int i = 0; i < hash_elements_count; i++) {
         if (i != 0)
            where_clause.printf("AND ");
         bingo_res = mangoGetHash(false, i, &count, &hash);
         CORE_HANDLE_ERROR(bingo_res, 1, "molecule search engine: error while getting hash", bingoGetError());

         where_clause.printf("t%d.f_count %s %d ", i, rel.ptr(), count);
      }
   }
   bingo_res = mangoExactNeedComponentMatching();
   CORE_HANDLE_ERROR(bingo_res, 0, "molecule search engine: error while getting need matching", bingoGetError());
   if (bingo_res == 0) {
      if (where_was_added)
         where_clause.printf("AND ");

      /*
       * There must be no other components in target
       */
      int query_fragments_count = 0;
      for (int i = 0; i < hash_elements_count; i++) {
         bingo_res = mangoGetHash(false, i, &count, &hash);
         CORE_HANDLE_ERROR(bingo_res, 1, "molecule search engine: error while getting hash", bingoGetError());
         query_fragments_count += count;
      }
      where_clause.printf("sh.fragments = %d", query_fragments_count);
   }
   what_clause_str.push(0);
   from_clause_str.push(0);
   where_clause_str.push(0);

}