Ejemplo n.º 1
0
struct peer_profile_t* add_peer()
{
    struct peer_profile_t * p = (struct peer_profile_t *)malloc(sizeof(struct peer_profile_t));
    if(p == NULL)
    {
        ERROR(errno, "add_peer: malloc failed");
        return NULL;
    }
    else
        bzero(p, sizeof(struct peer_profile_t));

    struct sockaddr_in * peeraddr = (struct sockaddr_in *)malloc(sizeof(struct sockaddr_in));
    if(peeraddr == NULL)
    {
        ERROR(errno, "add_peer: malloc failed");
        delete_peer(p);
        return NULL;
    }
    else
    {
        bzero(peeraddr, sizeof(struct sockaddr_in));
        p->peeraddr = peeraddr;
    }

    uint32_t * pkt_index_array_pre = (uint32_t *)malloc(SEQ_LEVEL_1*sizeof(uint32_t));
    if(peeraddr == NULL)
    {
        ERROR(errno, "add_peer: malloc failed");
        delete_peer(p);
        return NULL;
    }
    else
    {
        bzero(pkt_index_array_pre, SEQ_LEVEL_1*sizeof(uint32_t));
        p->pkt_index_array_pre = pkt_index_array_pre;
    }

    uint32_t * pkt_index_array_now = (uint32_t *)malloc(SEQ_LEVEL_1*sizeof(uint32_t));
    if(peeraddr == NULL)
    {
        ERROR(errno, "add_peer: malloc failed");
        delete_peer(p);
        return NULL;
    }
    else
    {
        bzero(pkt_index_array_now, SEQ_LEVEL_1*sizeof(uint32_t));
        p->pkt_index_array_now = pkt_index_array_now;
    }

    p->tcp_info = (struct tcp_info_t *)malloc(TCP_SESSION_CNT * sizeof(struct tcp_info_t));
    if(p->tcp_info == NULL)
    {
        ERROR(errno, "add_peer: malloc failed");
        delete_peer(p);
        return NULL;
    }
    else
        bzero(p->tcp_info, TCP_SESSION_CNT * sizeof(struct tcp_info_t));
    p->tcp_cnt = 0;

    p->timerfd_info = (struct timerfd_info_t *)malloc(sizeof(struct timerfd_info_t));
    if(p->timerfd_info == NULL)
    {
        ERROR(errno, "add_peer: malloc failed");
        delete_peer(p);
        return NULL;
    }
    else
        bzero(p->timerfd_info, sizeof(struct timerfd_info_t));

    p->timerfd_info->fd_max_cnt = TIMER_CNT;
    
    p->timerfd_info->ack_array_size = SEQ_LEVEL_1;

    p->timerfd_info->ack_array_pre = (struct ack_info_t *)malloc((p->timerfd_info->ack_array_size + 1) * sizeof(struct ack_info_t));
    if(p->timerfd_info->ack_array_pre == NULL)
    {
        ERROR(errno, "add_peer: malloc failed");
        delete_peer(p);
        return NULL;
    }
    else
        bzero(p->timerfd_info->ack_array_pre, (p->timerfd_info->ack_array_size + 1) * sizeof(struct ack_info_t));

    p->timerfd_info->ack_array_now = (struct ack_info_t *)malloc((p->timerfd_info->ack_array_size + 1) * sizeof(struct ack_info_t));
    if(p->timerfd_info->ack_array_now == NULL)
    {
        ERROR(errno, "add_peer: malloc failed");
        delete_peer(p);
        return NULL;
    }
    else
        bzero(p->timerfd_info->ack_array_now, (p->timerfd_info->ack_array_size +1 ) * sizeof(struct ack_info_t));

    p->flow_src = (struct flow_profile_t *)malloc(sizeof(struct flow_profile_t));
    if(p->flow_src == NULL)
    {
        ERROR(errno, "add_peer: malloc failed");
        delete_peer(p);
        return NULL;
    }
    else
        bzero(p->flow_src, sizeof(struct flow_profile_t));

    p->flow_src->ba_pre = bit_array_create(SEQ_LEVEL_1);
    if(p->flow_src->ba_pre == NULL)
    {
        ERROR(errno, "add_peer: malloc failed");
        delete_peer(p);
        return NULL;
    }
    else
        bit_array_clearall(p->flow_src->ba_pre);

    p->flow_src->ba_now = bit_array_create(SEQ_LEVEL_1);
    if(p->flow_src->ba_now == NULL)
    {
        ERROR(errno, "add_peer: malloc failed");
        delete_peer(p);
        return NULL;
    }
    else
        bit_array_clearall(p->flow_src->ba_now);

    p->valid = true;

    return p;
}
Ejemplo n.º 2
0
bool RapMapSAIndex<IndexT>::load(const std::string& indDir) {

    auto logger = spdlog::get("stderrLog");
    size_t n{0};

    // This part takes the longest, so do it in it's own asynchronous task
    std::future<std::pair<bool, uint32_t>> loadingHash = std::async(std::launch::async, [this, logger, indDir]() -> std::pair<bool, uint32_t> {
        this->khash.set_empty_key(std::numeric_limits<uint64_t>::max());
        uint32_t k;
        std::ifstream hashStream(indDir + "hash.bin");
        {
            logger->info("Loading Position Hash");
            cereal::BinaryInputArchive hashArchive(hashStream);
            hashArchive(k);
            khash.unserialize(typename google::dense_hash_map<uint64_t,
                    rapmap::utils::SAInterval<IndexT>,
                    rapmap::utils::KmerKeyHasher>::NopointerSerializer(), &hashStream);

            //hashArchive(khash);
        }
        hashStream.close();
        return std::make_pair(true, k);
    });



    std::ifstream saStream(indDir + "sa.bin");
    {
        logger->info("Loading Suffix Array ");
        cereal::BinaryInputArchive saArchive(saStream);
        saArchive(SA);
        //saArchive(LCP);
    }
    saStream.close();

    std::ifstream seqStream(indDir + "txpInfo.bin");
    {
        logger->info("Loading Transcript Info ");
        cereal::BinaryInputArchive seqArchive(seqStream);
        seqArchive(txpNames);
        seqArchive(txpOffsets);
        //seqArchive(positionIDs);
        seqArchive(seq);
    }
    seqStream.close();

    /*
       std::ifstream rsStream(indDir + "rsdSafe.bin", std::ios::binary);
       {
       logger->info("Loading Rank-Select Data");
       rankDictSafe.Load(rsStream);
       }
       rsStream.close();
       */
    std::string rsFileName = indDir + "rsd.bin";
    FILE* rsFile = fopen(rsFileName.c_str(), "r");
    {
        logger->info("Loading Rank-Select Bit Array");
        bitArray.reset(bit_array_create(0));
        if (!bit_array_load(bitArray.get(), rsFile)) {
            logger->error("Couldn't load bit array from {}!", rsFileName);
            std::exit(1);
        }
        logger->info("There were {} set bits in the bit array", bit_array_num_bits_set(bitArray.get()));
        rankDict.reset(new rank9b(bitArray->words, bitArray->num_of_bits));
    }
    fclose(rsFile);

    {
        logger->info("Computing transcript lengths");
        txpLens.resize(txpOffsets.size());
        if (txpOffsets.size() > 1) {
            for(size_t i = 0; i < txpOffsets.size() - 1; ++i) {
                auto nextOffset = txpOffsets[i+1];
                auto currentOffset = txpOffsets[i];
                txpLens[i] = (nextOffset - 1) - currentOffset;
            }
        }
        // The last length is just the length of the suffix array - the last offset
        txpLens[txpOffsets.size()-1] = (SA.size() - 1) - txpOffsets[txpOffsets.size() - 1];
    }

    logger->info("Waiting to finish loading hash");
    loadingHash.wait();
    auto hashLoadRes = loadingHash.get();
    if (!hashLoadRes.first) {
        logger->error("Failed to load hash!");
        std::exit(1);
    }
    rapmap::utils::my_mer::k(hashLoadRes.second);



    logger->info("Done loading index");
    return true;
}