Exemple #1
0
int test_main( int /* argc */, char* /* argv */[] )
{
    const char * testfile = boost::archive::tmpnam(NULL);
    BOOST_REQUIRE(NULL != testfile);

    // test array of objects
    std::deque<A> adeque, adeque1;
    {   
        test_ostream os(testfile, TEST_STREAM_FLAGS);
        test_oarchive oa(os, TEST_ARCHIVE_FLAGS);
        oa << boost::serialization::make_nvp("adeque",adeque);
    }
    {
        test_istream is(testfile, TEST_STREAM_FLAGS);
        test_iarchive ia(is, TEST_ARCHIVE_FLAGS);
        ia >> boost::serialization::make_nvp("adeque",adeque1);
    }
    BOOST_CHECK(adeque == adeque1);
    
    std::remove(testfile);
    return EXIT_SUCCESS;
}
Exemple #2
0
// construct the classifier
Classifier::Classifier(const ClassifierOptions &options )
{
    kmerSize_ = options.kmerSize;
    numThreads_ = options.numThreads;
    numBootstrap_ = options.numBootstrap;
    subsampleSize_ = options.subsample;
    kmerizer_.setKmerSize(kmerSize_);
    outputAmbiguous_ = options.dumpAmbiguous;
    
    std::stringstream s;
    s << options.dbFilename << ".idx_" << kmerSize_;
    try {
        // load cached index
        std::ifstream ifs(s.str().c_str());
        boost::archive::binary_iarchive ia(ifs);
        ScopedTimer tim;
        std::cerr << "Loading cached index from " << s.str();
        ia >> referenceData_;
        std::cerr << " done. ";
    }
    catch (boost::archive::archive_exception &) {
        // create index from raw sequences
        referenceData_.load(options.dbFilename, kmerizer_, numThreads_);
        
        // save index for future use
        if (options.saveIndex)
        {
            std::ofstream ofs(s.str().c_str());
            boost::archive::binary_oarchive oa(ofs);
            ScopedTimer tim;
            std::cerr << "Writing cached index to " << s.str();
            save_to(oa, referenceData_);
            std::cerr << " done. ";
        }
    }
    
    numRefSeqs_ = referenceData_.numSequences();
}
bool
NameServiceClient::register_service( const std::string &in_service_name,
                                int32_t in_port ) {
    if( !m_client || !m_client->get_is_connected() ) {
        throw SemanticError()
                <<errinfo_errorid( ErrorID::SEMANTIC_ERR_NOT_CONNECTED);
    }
    char hostname[NAME_MAX];
    if( -1 == gethostname( hostname, NAME_MAX ) ) {
            throw SyscallError() <<boost::errinfo_errno(errno)
                    << boost::errinfo_api_function("gethostname");
    }
    ServiceRequestData request;
    request.m_service_name = in_service_name;
    request.m_hostname = hostname;
    request.m_port = in_port;
    std::ostringstream sout;
    {
        boost::archive::text_oarchive oa( sout );
        oa & request;
    }
    DataServiceMessage message( DATA_SERVICE_REGISTER );
    std::strncpy( message.m_data, sout.str().c_str(), sout.str().size());
    MemInfo data( reinterpret_cast<char *>( &message ),
                    sizeof(DataServiceMessage));
    m_client->send_data( data );
    std::unique_lock<std::mutex> l( m_mutex );
    while( !m_stop && !m_response_ready ) {
        m_response_ready_cond.wait( l );
    }
    if( m_stop ) {
        return false;
    }
    bool status = m_status;
    m_status = false;
    m_response_ready = false;
    return status;
}
// This test passes
void test_passes(){
	std::stringstream ss;
	{
		boost::shared_ptr<Derived> d(new Derived());
		d->m_base = 1;
		d->m_derived = 2;

		// Get a raw pointer to Derived
		Derived* raw_d = d.get();

		// Verify base and derived members
		BOOST_CHECK(raw_d->m_base==1);
		BOOST_CHECK(raw_d->m_derived==2);

		// verify shared_from_this
		BOOST_CHECK(d == raw_d->SharedPtr());

		boost::archive::text_oarchive oa(ss);
		oa & BOOST_SERIALIZATION_NVP(d);
	}
	{
		// Deserialize it back into a vector of shared_ptr<Derived>
		boost::shared_ptr<Derived> d;
		ss.seekg(0);
		boost::archive::text_iarchive ia(ss);
		ia & BOOST_SERIALIZATION_NVP(d);

		// Get a raw pointer to Derived
		Derived* raw_d = d.get();

		// Verify base and derived members
		BOOST_CHECK(raw_d->m_base==1);
		BOOST_CHECK(raw_d->m_derived==2);

		// verify shared_from_this
		BOOST_CHECK(d == raw_d->SharedPtr());
	}	
}
int test2(){
    const char * testfile = boost::archive::tmpnam(NULL);
    BOOST_REQUIRE(NULL != testfile);

    J *j1 = new J;
    j1->j = j1;
    J *j2 = reinterpret_cast<J *>(0xBAADF00D);
    {
        test_ostream os(testfile, TEST_STREAM_FLAGS);
        test_oarchive oa(os, TEST_ARCHIVE_FLAGS);
        oa << BOOST_SERIALIZATION_NVP(j1);
    }
    {
        // try to read the archive
        test_istream is(testfile, TEST_STREAM_FLAGS);
        test_iarchive ia(is, TEST_ARCHIVE_FLAGS);
        ia >> BOOST_SERIALIZATION_NVP(j2);
    }
    BOOST_CHECK(*j1 == *j2);
    BOOST_CHECK(j2 == j2->j);
    std::remove(testfile);
    return EXIT_SUCCESS;
}
Exemple #6
0
bool writeResumeDataOne(std::ofstream& fs, const libed2k::save_resume_data_alert* p)
{
    try
    {
        QED2KHandle h(p->m_handle);
        if (h.is_valid() && p->resume_data)
        {
            std::vector<char> out;
            libed2k::bencode(back_inserter(out), *p->resume_data);
            libed2k::transfer_resume_data trd(p->m_handle.hash(), p->m_handle.name(), p->m_handle.size(), p->m_handle.is_seed(), out);
            libed2k::archive::ed2k_oarchive oa(fs);
            oa << trd;
            return true;
        }
    }
    catch(const libed2k::libed2k_exception& e)
    {
        qDebug() << "error on write resume data " << misc::toQStringU(e.what());
        return false;
    }

    return false;
}
Exemple #7
0
void
test_set(){
    const char * testfile = boost::archive::tmpnam(NULL);
    BOOST_REQUIRE(NULL != testfile);

    // test array of objects
    std::set<A> aset;
    aset.insert(A());
    aset.insert(A());
    {
        test_ostream os(testfile, TEST_STREAM_FLAGS);
        test_oarchive oa(os, TEST_ARCHIVE_FLAGS);
        oa << boost::serialization::make_nvp("aset", aset);
    }
    std::set<A> aset1;
    {
        test_istream is(testfile, TEST_STREAM_FLAGS);
        test_iarchive ia(is, TEST_ARCHIVE_FLAGS);
        ia >> boost::serialization::make_nvp("aset", aset1);
    }
    BOOST_CHECK(aset == aset1);
    std::remove(testfile);
}
Exemple #8
0
// simple class with polymorphic archive compiled in dll
void
test2(){
    const char * testfile = boost::archive::tmpnam(NULL);
    BOOST_REQUIRE(NULL != testfile);

    const A a;
    A a1;
    {   
        test_ostream os(testfile, TEST_STREAM_FLAGS);
        boost::archive::polymorphic_text_oarchive oa(os, TEST_ARCHIVE_FLAGS);
        boost::archive::polymorphic_oarchive & poa(oa);
        poa << boost::serialization::make_nvp("a", a);
    }
    {
        test_istream is(testfile, TEST_STREAM_FLAGS);
        boost::archive::polymorphic_text_iarchive ia(is, TEST_ARCHIVE_FLAGS);
        boost::archive::polymorphic_iarchive & pia(ia);
        pia >> boost::serialization::make_nvp("a", a1);
    }
    BOOST_CHECK_EQUAL(a, a1);

    std::remove(testfile);
}
int main() {
    kmeans("./dataset", "./result");
    Forecast forecast("./result");
    HMM hmm = HMM("./dataset", "./dictionnary.txt", forecast);

    hmm.print();
    {
        cout << "Save" << endl;
        std::ofstream ofs("hmm_save");
        boost::archive::text_oarchive oa(ofs);
        oa << hmm;
    }
    
    HMM hmm2 = HMM();
    {
        cout << "Load" << endl;
        std::ifstream ifs("hmm_save");
        boost::archive::text_iarchive ia(ifs);
        ia >> hmm2;
    }
    hmm2.print();    
    return (EXIT_SUCCESS);
}
Exemple #10
0
void
test_multimap(){
    const char * testfile = boost::archive::tmpnam(NULL);
    BOOST_REQUIRE(NULL != testfile);

    BOOST_MESSAGE("multimap");
    std::multimap<random_key, A> amultimap;
    amultimap.insert(std::make_pair(random_key(), A()));
    amultimap.insert(std::make_pair(random_key(), A()));
    {   
        test_ostream os(testfile, TEST_STREAM_FLAGS);
        test_oarchive oa(os, TEST_ARCHIVE_FLAGS);
        oa << boost::serialization::make_nvp("amultimap", amultimap);
    }
    std::multimap<random_key, A> amultimap1;
    {
        test_istream is(testfile, TEST_STREAM_FLAGS);
        test_iarchive ia(is, TEST_ARCHIVE_FLAGS);
        ia >> boost::serialization::make_nvp("amultimap", amultimap1);
    }
    BOOST_CHECK(amultimap == amultimap1);
    std::remove(testfile);
}
Exemple #11
0
void SmafeStoreDB::storeFeatureSegRecord(const long segmentnr, const long track_id,
		long featurevectortype_id,
		const SmafeAbstractFeatureVector* fv,
		const long file_id,
		const long startsample,
		const long length) {

	std::string ss_enc;

	std::stringstream ss(std::stringstream::in | std::stringstream::out);
	{
		boost::archive::text_oarchive oa(ss);
		//boost::archive::xml_oarchive oa(ss);
		oa << BOOST_SERIALIZATION_NVP(fv);
	}

	// encryption
	ss_enc = encryptString(ss.str().c_str());

	// call db specific method
	storeFeatureSegRecord(segmentnr, track_id, featurevectortype_id,
			ss_enc.c_str(), ss_enc.size(), file_id, startsample, length);
}
Exemple #12
0
int test_main( int /* argc */, char* /* argv */[] )
{
    const char * testfile = boost::archive::tmpnam(NULL);
    BOOST_REQUIRE(NULL != testfile);
    A* a = new A(5);

    {
        test_ostream os(testfile, TEST_STREAM_FLAGS);
        test_oarchive oa(os, TEST_ARCHIVE_FLAGS);
        oa << BOOST_SERIALIZATION_NVP(a);
    }

    A* a_new;

    {
        test_istream is(testfile, TEST_STREAM_FLAGS);
        test_iarchive ia(is, TEST_ARCHIVE_FLAGS);
        ia >> BOOST_SERIALIZATION_NVP(a_new);
    }
    delete a;
    delete a_new;
    return EXIT_SUCCESS;
}
int test_main( int /* argc */, char* /* argv */[] )
{
    const char * testfile = boost::archive::tmpnam(NULL);  
    BOOST_REQUIRE(NULL != testfile);

    B * tb = new B;
    B * tb1 = NULL;

    {   
        test_ostream os(testfile, TEST_STREAM_FLAGS);
        test_oarchive oa(os);
        oa << boost::serialization::make_nvp("tb", tb);
    }
    {
        test_istream is(testfile, TEST_STREAM_FLAGS);
        test_iarchive ia(is);
        ia >> boost::serialization::make_nvp("tb",tb1);
    }
    BOOST_CHECK(tb != tb1);
    BOOST_CHECK(*tb == *tb1);
    std::remove(testfile);
    return boost::exit_success;
}
/** @brief Serialization Test */
TEST(Serialization, Pointer)
{
	// filename
	std::string strFileName("Bus_Route.text");

	// create class instance
	Bus_Route_Pointer br1;
	br1[0] = Bus_Stop(GPS_Position(35, 59, 24.567f), GPS_Position(12, 53, 24.657f));
	br1[1] = Bus_Stop(GPS_Position(13, 42, 42.165f), GPS_Position(42, 84, 95.624f));
	br1[2] = Bus_Stop(GPS_Position(63, 79, 96.135f), GPS_Position(35, 25, 65.134f));
	
	// save data to archive
	{
		// create and open a character archive for output
		std::ofstream ofs(strFileName);
		boost::archive::text_oarchive oa(ofs);

		// write class instance to archive
      oa << br1;
		
		// archive and stream closed when destructors are called
	}
	
	// load data from archive
	Bus_Route_Pointer br2;
	{
		// create and open a character archive for input
		std::ifstream ifs(strFileName);
		boost::archive::text_iarchive ia(ifs);
		
		// read class state from archive
		ia >> br2;
		// archive and stream closed when destructors are called
	}

	EXPECT_EQ(br1, br2);
}
  void SerializedMap<T,A>::set(::boost::uint64_t id, const T & value)
  {  
    
    int result;
    try {
      // Step 1 is to serialize the object. There is no way to know how big the object will be
      // so unfortunately, this will incur an extra copy.
      
      // The binary flag is important here.
      std::ostringstream oss(std::ios_base::binary);
      oarchive_t oa(oss);
      oa << value;
	
      //std::cout << "Saving " << oss.str().size() << " bytes\n";
      // Step 2 is to bind the frameId and data to the insert statement.
      // http://sqlite.org/c3ref/bind_blob.html
      result = sqlite3_bind_int64(_iStmt, 1, id);
      SM_ASSERT_EQ(SqlException, result, SQLITE_OK, "Unable to bind id " << id << " to INSERT statement: " << sqlite3_errmsg(_db->db()));
      result = static_cast<int>(sqlite3_bind_blob(_iStmt, 2, oss.str().c_str(), oss.str().size(), SQLITE_TRANSIENT));
      SM_ASSERT_EQ(SqlException, result, SQLITE_OK, "Unable to bind blob of size " << oss.str().size() << " to INSERT statement: " << sqlite3_errmsg(_db->db()));
      // Finally, we execute the bound insert statement.
      result = sqlite3_step(_iStmt);
      SM_ASSERT_EQ(SqlException, result, SQLITE_DONE, "Unable to execute INSERT statement for id " << id << " and blob of size " << oss.str().size() << ": " << sqlite3_errmsg(_db->db()));
	
    }
    catch(const SqlException & e)
      {
	sqlite3_reset(_iStmt);
	throw;
      }

    // After executing, we have to reset the statement
    // http://www.sqlite.org/c3ref/step.html
    result = sqlite3_reset(_iStmt);
    SM_ASSERT_EQ(SqlException, result, SQLITE_OK, "Unable to reset the INSERT  statement: " << sqlite3_errmsg(_db->db()));
  }
int test_main( int /* argc */, char* /* argv */[] )
{
    const char * testfile = boost::archive::tmpnam(NULL);
    
    BOOST_REQUIRE(NULL != testfile);

    A *ta = new A();
    A *ta1 = NULL;

    {   
        test_ostream os(testfile, TEST_STREAM_FLAGS);
        test_oarchive oa(os);
        oa << boost::serialization::make_nvp("ta", ta);
    }
    {
        test_istream is(testfile, TEST_STREAM_FLAGS);
        test_iarchive ia(is);
        ia >> boost::serialization::make_nvp("ta", ta1);
    }
    BOOST_CHECK(ta != ta1);
    BOOST_CHECK(*ta == *ta1);
    std::remove(testfile);
    return EXIT_SUCCESS;
}
TEST_F(UUIDTest, test5)
{
    UUID uuid;
    const fs::path tmpfile(FileUtils::create_temp_file(FileUtils::temp_path(),
                                                       "serialization.txt"));
    ALWAYS_CLEANUP_FILE(tmpfile);

    {

        fs::ofstream ofs(tmpfile);
        boost::archive::xml_oarchive oa(ofs);
        oa << BOOST_SERIALIZATION_NVP(uuid);

    }

    UUID uuid2;

    fs::ifstream ifs(tmpfile);
    boost::archive::xml_iarchive ia(ifs);
    ia >>BOOST_SERIALIZATION_NVP(uuid2);


    ASSERT_TRUE(uuid == uuid2);
}
int test_vector(T)
{
    const char * testfile = boost::archive::tmpnam(NULL);
    BOOST_REQUIRE(NULL != testfile);

    // test array of objects
    std::vector<T> avector;
    avector.push_back(T());
    avector.push_back(T());
    {   
        test_ostream os(testfile, TEST_STREAM_FLAGS);
        test_oarchive oa(os, TEST_ARCHIVE_FLAGS);
        oa << boost::serialization::make_nvp("avector", avector);
    }
    std::vector<T> avector1;
    {
        test_istream is(testfile, TEST_STREAM_FLAGS);
        test_iarchive ia(is, TEST_ARCHIVE_FLAGS);
        ia >> boost::serialization::make_nvp("avector", avector1);
    }
    BOOST_CHECK(avector == avector1);
    std::remove(testfile);
    return EXIT_SUCCESS;
}
Exemple #19
0
void SaveGame(const std::string& filename, const ServerSaveGameData& server_save_game_data,
              const std::vector<PlayerSaveGameData>& player_save_game_data,
              const Universe& universe, const EmpireManager& empire_manager,
              const SpeciesManager& species_manager, const CombatLogManager& combat_log_manager)
{
    GetUniverse().EncodingEmpire() = ALL_EMPIRES;

    std::map<int, SaveGameEmpireData> empire_save_game_data = CompileSaveGameEmpireData(empire_manager);

    try {
#ifdef FREEORION_WIN32
        // convert UTF-8 file name to UTF-16
        fs::path::string_type file_name_native;
        utf8::utf8to16(filename.begin(), filename.end(), std::back_inserter(file_name_native));
        fs::path path = fs::path(file_name_native);
#else
        fs::path path = fs::path(filename);
#endif
        fs::ofstream ofs(path, std::ios_base::binary);

        if (!ofs)
            throw std::runtime_error(UNABLE_TO_OPEN_FILE);

        FREEORION_OARCHIVE_TYPE oa(ofs);
        oa << BOOST_SERIALIZATION_NVP(server_save_game_data);
        oa << BOOST_SERIALIZATION_NVP(player_save_game_data);
        oa << BOOST_SERIALIZATION_NVP(empire_save_game_data);
        oa << BOOST_SERIALIZATION_NVP(empire_manager);
        oa << BOOST_SERIALIZATION_NVP(species_manager);
        oa << BOOST_SERIALIZATION_NVP(combat_log_manager);
        Serialize(oa, universe);
    } catch (const std::exception& e) {
        Logger().errorStream() << UserString("UNABLE_TO_WRITE_SAVE_FILE") << " SaveGame exception: " << ": " << e.what();
        throw e;
    }
}
Exemple #20
0
// save derived polymorphic class
void save_derived(const char *testfile)
{
    test_ostream os(testfile, TEST_STREAM_FLAGS);
    test_oarchive oa(os);

    polymorphic_derived1 *rd1 = new polymorphic_derived1;
    polymorphic_derived2 *rd2 = new polymorphic_derived2;

    std::cout << "saving polymorphic_derived1 (no_rtti)\n";
    oa << BOOST_SERIALIZATION_NVP(rd1);

    std::cout << "saving polymorphic_derived2\n";
    oa << BOOST_SERIALIZATION_NVP(rd2);

    const polymorphic_base *rb1 =  rd1;
    polymorphic_base *rb2 =  rd2;
    std::cout << "saving polymorphic_derived1 (no_rtti) through base (no_rtti)\n";
    oa << BOOST_SERIALIZATION_NVP(rb1);
    std::cout << "saving polymorphic_derived2 through base\n";
    oa << BOOST_SERIALIZATION_NVP(rb2);

    delete rd1;
    delete rd2;
}
TEST_F(UUIDTest, test6)
{
    std::list<UUID> vec1(20);

    const fs::path tmpfile(FileUtils::create_temp_file(FileUtils::temp_path(),
                                                       "serialization.txt"));

    ALWAYS_CLEANUP_FILE(tmpfile);

    {

        fs::ofstream ofs(tmpfile);
        boost::archive::xml_oarchive oa(ofs);
        oa << BOOST_SERIALIZATION_NVP(vec1);
    }

    std::list<UUID> vec2;

    fs::ifstream ifs(tmpfile);
    boost::archive::xml_iarchive ia(ifs);
    ia >> BOOST_SERIALIZATION_NVP(vec2);

    ASSERT_TRUE(vec1 == vec2);
}
// serialize
void
ReadGroupStatsSet::
save(
    const char* filename) const
{
    assert(NULL != filename);
    std::ofstream ofs(filename);
    boost::archive::xml_oarchive oa(ofs);

    const unsigned numGroups(size());
    oa << boost::serialization::make_nvp("numGroups", numGroups);
    ReadGroupStatsExporter se;
    for (unsigned i(0); i<numGroups; ++i)
    {
        const KeyType& key(getKey(i));
        se.bamFile = key.bamLabel;
        se.readGroup = key.rgLabel;
        se.groupStats = getStats(i);

        std::ostringstream oss;
        oss << "groupStats_" << i;
        oa << boost::serialization::make_nvp(oss.str().c_str(), se);
    }
}
Exemple #23
0
void YASHE::writeToFile(std::string filename) {
  std::ofstream ofs(filename);
  boost::archive::text_oarchive oa(ofs);
  oa << *this;
}
void saveMat(cv::Mat& m, std::string filename) {
    std::ofstream ofs(filename.c_str());
	boost::archive::binary_oarchive oa(ofs);
	//boost::archive::text_oarchive oa(ofs);
	oa << m;
}
//int main(int argc,const char** argv){
int main_combine(int argc,const char** argv){
	const unsigned block_size=BLOCK_SIZE_CAO;
	const unsigned thread_count=4;
	const unsigned expander_buffer=4;
	std::vector<column_type> column_list,column_list_;
	column_list.push_back(column_type(t_int));

	Schema* schema=new SchemaFix(column_list);
	ExpandableBlockStreamSingleColumnScan::State ebssc_state1("/home/imdb/temp/Uniform_0_99.column",schema,block_size);
	BlockStreamIteratorBase* ebssc1=new ExpandableBlockStreamSingleColumnScan(ebssc_state1);
	ExpandableBlockStreamSingleColumnScan::State ebssc_state2("/home/imdb/temp/Uniform_0_99.column",schema,block_size);
	BlockStreamIteratorBase* ebssc2=new ExpandableBlockStreamSingleColumnScan(ebssc_state2);

	std::vector<Schema *> inputs;
	inputs.push_back(schema);
	inputs.push_back(schema);

	column_list_.push_back(column_type(t_int));
	column_list_.push_back(column_type(t_int));
	Schema* output=new SchemaFix(column_list_);

	std::vector<BlockStreamIteratorBase *> children_;
	children_.push_back(ebssc1);
	children_.push_back(ebssc2);

	BlockStreamCombinedIterator::State bsci_state(inputs,output,children_);
	BlockStreamCombinedIterator *bsc=new BlockStreamCombinedIterator(bsci_state);

	BlockStreamExpander::State bse_state(schema,bsc,thread_count,block_size,expander_buffer);
	BlockStreamIteratorBase* bse=new BlockStreamExpander(bse_state);

	BlockStreamBase *block=new BlockStreamFix(block_size,8);
	int choice=0;


	std::ostringstream ostr;
	boost::archive::text_oarchive oa(ostr);
	oa.register_type(static_cast<BlockStreamCombinedIterator *>(NULL));
	oa.register_type(static_cast<BlockStreamExpander *>(NULL));
	oa.register_type(static_cast<ExpandableBlockStreamSingleColumnScan *>(NULL));
	Register_Schemas<boost::archive::text_oarchive>(oa);
//	Register_Iterators(oa);
	oa<<bse;

	std::cout<<"Serialization Result:"<<ostr.str()<<std::endl;

	std::istringstream istr(ostr.str());
	boost::archive::text_iarchive ia(istr);
	BlockStreamIteratorBase* des;

	ia.register_type(static_cast<BlockStreamCombinedIterator *>(NULL));
	ia.register_type(static_cast<BlockStreamExpander *>(NULL));
	ia.register_type(static_cast<ExpandableBlockStreamSingleColumnScan *>(NULL));
	Register_Schemas<boost::archive::text_iarchive>(ia);
	ia>>des;
//	return 1;
	while(choice==0){


//		bsf->open();
		des->open();
		cout<<"after open!"<<endl;
		unsigned long long int start=curtick();

		cout<<"ready for the next"<<endl;

		unsigned tuple_count=0;
		while(des->next(block)){
			BlockStreamBase::BlockStreamTraverseIterator* it=block->createIterator();
			while(it->nextTuple()){
				tuple_count++;
			}
			block->setEmpty();
		}
		printf("Time=%f Throughput=%f.\n tuple=%d",getSecond(start),1024/getSecond(start),tuple_count);
		des->close();
		printf("Continue(0) or Not(1) ?\n");

		scanf("%d",&choice);

	}

}
void
mpi_process_group::send_batch(process_id_type dest, 
                              outgoing_messages& outgoing) const
{
  impl_->free_sent_batches();
  process_id_type id = process_id(*this);

  // clear the batch
#ifdef DEBUG
  std::cerr << "Sending batch: " << id << " -> "  << dest << std::endl;
#endif
  // we increment the number of batches sent
  ++impl_->number_sent_batches[dest];
  // and send the batch
  BOOST_ASSERT(outgoing.headers.size() <= impl_->batch_header_number);
  if (id != dest) {
#ifdef NO_ISEND_BATCHES
    impl::batch_request req;
#else
#ifdef PREALLOCATE_BATCHES
    while (impl_->free_batches.empty()) {
      impl_->free_sent_batches();
      poll();
    }
    impl::batch_request& req = impl_->batch_pool[impl_->free_batches.top()];
    impl_->free_batches.pop();
#else
    impl_->sent_batches.push_back(impl::batch_request());
    impl::batch_request& req = impl_->sent_batches.back();
#endif
#endif
    boost::mpi::packed_oarchive oa(impl_->comm,req.buffer);
    oa << outgoing;

    int tag = msg_batch;
    
#ifdef IRECV_BATCH
    if (oa.size() > impl_->batch_message_size)
      tag = msg_large_batch;
#endif

#ifndef NDEBUG // Prevent uninitialized variable warning with NDEBUG is on
    int result =
#endif // !NDEBUG
      MPI_Isend(const_cast<void*>(oa.address()), oa.size(),
                MPI_PACKED, dest, tag, impl_->comm,
                &req.request);
    BOOST_ASSERT(result == MPI_SUCCESS);
    impl_->max_sent = (std::max)(impl_->max_sent,impl_->sent_batches.size());
#ifdef NO_ISEND_BATCHES
    int done=0;
    do {                                                        
        poll();                                                
        MPI_Test(&req.request,&done,MPI_STATUS_IGNORE);               
       } while (!done);                                            
#else
#ifdef MAX_BATCHES
    while (impl_->sent_batches.size() >= MAX_BATCHES-1) {
      impl_->free_sent_batches();
      poll();
    }
#endif
#endif
  }
  else
    receive_batch(id,outgoing);
}
void DisplayGroupManager::calibrateTimestampOffset()
{
    // can't calibrate timestamps unless we have at least 2 processes
    if(g_mpiSize < 2)
    {
        put_flog(LOG_DEBUG, "cannot calibrate with g_mpiSize == %i", g_mpiSize);
        return;
    }

    // synchronize all processes
    MPI_Barrier(g_mpiRenderComm);

    // get current timestamp immediately after
    boost::posix_time::ptime timestamp(boost::posix_time::microsec_clock::universal_time());

    // rank 1: send timestamp to rank 0
    if(g_mpiRank == 1)
    {
        // serialize state
        std::ostringstream oss(std::ostringstream::binary);

        // brace this so destructor is called on archive before we use the stream
        {
            boost::archive::binary_oarchive oa(oss);
            oa << timestamp;
        }

        // serialized data to string
        std::string serializedString = oss.str();
        int size = serializedString.size();

        // send the header and the message
        MessageHeader mh;
        mh.size = size;

        MPI_Send((void *)&mh, sizeof(MessageHeader), MPI_BYTE, 0, 0, MPI_COMM_WORLD);
        MPI_Send((void *)serializedString.data(), size, MPI_BYTE, 0, 0, MPI_COMM_WORLD);
    }
    // rank 0: receive timestamp from rank 1
    else if(g_mpiRank == 0)
    {
        MessageHeader messageHeader;

        MPI_Status status;
        MPI_Recv((void *)&messageHeader, sizeof(MessageHeader), MPI_BYTE, 1, 0, MPI_COMM_WORLD, &status);

        // receive serialized data
        char * buf = new char[messageHeader.size];

        // read message into the buffer
        MPI_Recv((void *)buf, messageHeader.size, MPI_BYTE, 1, 0, MPI_COMM_WORLD, &status);

        // de-serialize...
        std::istringstream iss(std::istringstream::binary);

        if(iss.rdbuf()->pubsetbuf(buf, messageHeader.size) == NULL)
        {
            put_flog(LOG_FATAL, "rank %i: error setting stream buffer", g_mpiRank);
            exit(-1);
        }

        // read to a new timestamp
        boost::posix_time::ptime rank1Timestamp;

        boost::archive::binary_iarchive ia(iss);
        ia >> rank1Timestamp;

        // free mpi buffer
        delete [] buf;

        // now, calculate and store the timestamp offset
        timestampOffset_ = rank1Timestamp - timestamp;

        put_flog(LOG_DEBUG, "timestamp offset = %s", (boost::posix_time::to_simple_string(timestampOffset_)).c_str());
    }
Exemple #28
0
void History::removeChatMementoSession(IMChatSession * imchatSession) {
	int chatSessionID = imchatSession->getId();

	HistoryMementoCollection * collection = NULL;
	if((collection = _chatSessionsMementos[chatSessionID]) != NULL){
		//seek for history chat
		int nbhistory = 0;
		HistoryMap::iterator ithm;
		for (ithm = collection->begin(); ithm != collection->end(); ++ithm) {
			HistoryMemento* hm = ithm->second;

			// duration -1 means it is an history message
			if( hm->getDuration() != -1 ) {
				break;
			}
			++nbhistory;
		}
		////

		// don't save empty chat history
		int size = collection->size() - nbhistory;
		if(size>0) {
			//save chat log
			Date saveDate;
			Time saveTime;
			std::string peer = "";
			std::string filechat =	String::fromNumber(saveDate.getYear(), 2) + String::fromNumber(saveDate.getMonth(), 2) + 
									String::fromNumber(saveDate.getDay(), 2) + String::fromNumber(saveTime.getHour(), 2) + 
									String::fromNumber(saveTime.getMinute(), 2) + String::fromNumber(saveTime.getSecond(), 2)+
									"_" + String::fromNumber(chatSessionID);
			Config & config = ConfigManager::getInstance().getCurrentConfig();
			std::string saverep = File::convertPathSeparators( 
				config.getConfigDir() + "chatlogs" + File::getPathSeparator() 
				+ _userProfile.getName() + File::getPathSeparator() 
			);
			File::createPath(saverep);
			//save file should be unique
			while(File::exists(saverep + filechat + ".xml")) {
				filechat += "_f";
			}
			////
			FileWriter file(saverep + filechat+".xml");
			std::stringstream ss;
			bool serializedSuccessfully = false;
			try {
				boost::archive::xml_oarchive oa(ss);

				//constructs list of login per peer
				std::map<std::string, std::vector<std::string>*> aliasMap;
				IMContactSet contactSet = imchatSession->getIMContactSet();
				for (IMContactSet::const_iterator itc = contactSet.begin(); itc != contactSet.end(); ++itc) {
					Contact * thecontact = _userProfile.getContactList().findContactThatOwns(*itc);
					std::string cuuid = "unrecognized";
					if(thecontact) {
//						cuuid = thecontact->getUUID();
						cuuid = thecontact->getKey();	//VOXOX - JRT - 2009.04.28 
					}	

					if(aliasMap[cuuid] == NULL) {
						aliasMap[cuuid] = new std::vector<std::string>;
					}
//					aliasMap[cuuid]->push_back(itc->cleanContactId());	//VOXOX - JRT - 2009.04.10 
					aliasMap[cuuid]->push_back(itc->getCleanContactId());
				}
				////

				// saves number of peer in this chat
				int nbcontact = aliasMap.size();
				oa << BOOST_SERIALIZATION_NVP(nbcontact);
				////

				//links all peers to this chat
				for(std::map<std::string, std::vector<std::string>*>::const_iterator itam = aliasMap.begin();
					itam != aliasMap.end(); ++itam) {
				
					/** links peer -> chat */

					//filechat
					std::string tobewritten = "<chat>\n\t<id>"+filechat+"</id>\n";

					//different login used by this peer during this chat
					for(std::vector<std::string>::const_iterator itv = itam->second->begin(); itv != itam->second->end(); ++itv) {
						tobewritten += "\t<alias>" + (*itv) + "</alias>\n";
						
						peer += "," + (*itv);
					}
					
					////

					tobewritten += "</chat>\n";
					/////
	
					std::string cuuid = itam->first;
					FileWriter contactFile( saverep + cuuid + ".xml" );
					contactFile.setAppendMode(true);
					contactFile.write(tobewritten);

					/** links chat -> peer */
					oa << BOOST_SERIALIZATION_NVP(cuuid);
				}
				////

				// saves user login for this chat
				IMAccount * imAccount =
					_userProfile.getIMAccountManager().getIMAccount(imchatSession->getIMChat().getIMAccountId());
				std::string userlogin;
				if (imAccount) {
					userlogin = imAccount->getLogin();
					OWSAFE_DELETE(imAccount);
				} else {
					LOG_ERROR("cannot find the IMAccount");
				}
				oa << BOOST_SERIALIZATION_NVP(userlogin);
				////

				// saves size
				oa << BOOST_SERIALIZATION_NVP(size);

				// save all historymementos i.e. all message
				for (;ithm != collection->end(); ++ithm) {
					HistoryMemento* hm = ithm->second;

					//
					//	more compact serialization
					//
					//std::string date = hm->getDate().toString() + " " + hm->getTime().toString();
					//oa << BOOST_SERIALIZATION_NVP(date);
					//std::string peer = hm->getPeer();
					//oa << BOOST_SERIALIZATION_NVP(peer);
					//std::string data = hm->getData();
					//oa << BOOST_SERIALIZATION_NVP(data);

					hm->save(oa,HistoryMemento::SERIALIZATION_VERSION);

				}
				serializedSuccessfully = true;
			} catch (boost::archive::archive_exception & e) {
				LOG_DEBUG(e.what());
				file.write(String::null);
			}

			if (serializedSuccessfully) {
				// xml_oarchive write the end of the xml in its destructor.
				// This is why we do not write inside the try {} catch block
				// because we would write before the xml_oarchive object is
				// deleted.
				file.write(ss.str());
			}
			
			if (peer.size() > 1) {
				peer = peer.substr(1);
			}
			
			HistoryMemento * historyMemento = new HistoryMemento(HistoryMemento::ChatSession, saveDate, saveTime, peer, -1, filechat);
			historyMemento->updateDuration(0);
			_userProfile.getHistory().addMemento(historyMemento);
		}
		_chatSessionsMementos.erase(chatSessionID);
		delete collection;
	}
}
void Prefab::Init(const GameObject* const gObj)
{
	name = gObj->GetName();

#ifndef NOSERIALIZE
	try
	{
#ifdef TIMEPOPDROP
		DWORD startTime = timeGetTime();
#endif
		//if you broke here, this prefab was initialized twice somehow
		assert(dormantObject == 0);

#ifdef _DEBUG

		//recheck the validity of the original object
		GameObject::ConstCompIter iter = gObj->mComponents.begin();
		for (; iter != gObj->mComponents.end(); ++iter)
			assert((*iter)->gameObject == gObj);
#endif	

		//start this object as a dormant, don't call on start (we only care about non-transient data)
		dormantObject = new GameObject();
		dormantObject->isDormant = true;
		dormantObject->CopyFrom(gObj, false);
		dormantObject->SetName("Dormant Prefab Object");

#ifdef _DEBUG
		{
		//recheck the validity of the original object
		GameObject::ConstCompIter iter = gObj->mComponents.begin();
		for (; iter != gObj->mComponents.end(); ++iter)
			assert((*iter)->gameObject == gObj);
		}
#endif	

		std::function<void(const GameObject*, GameObject*)> lamba_recursedormantchild
			= [&](const GameObject* active_gobj, GameObject* dormant_obj) {
			//force link dummy children objects
			for (CTransform* active_child : active_gobj->transform->children)
			{
				//create and copy
				GameObject* dormant_child = new GameObject();
				dormant_child->isDormant = true;
				dormant_child->CopyFrom(active_child->gameObject, false);

				//link transforms
				dormant_obj->transform->children.push_back(dormant_child->transform);
				dormant_child->transform->mParent = dormant_obj->transform;

				lamba_recursedormantchild(active_child->gameObject, dormant_child);
			}
		};

		lamba_recursedormantchild(gObj, dormantObject);


		if (!isTransient)
		{
			filename = "Assets\\Prefabs\\" + name + ".prefab";
			std::stringbuf fb;
			std::ostream ofs(&fb);
			boost::archive::xml_oarchive oa(ofs);
			const GameObject& g = *gObj;
			oa << BOOST_SERIALIZATION_NVP(g);
			stringBuf = fb.str();
			std::ofstream ffs(filename);
			ffs << stringBuf;
			ffs.close();
			LogVerbose("Wrote gameObject prefab to " + filename, LogEntry::Command);
		}
#ifdef TIMEPOPDROP
		std::cout << "Save Time: " << timeGetTime() - startTime << std::endl;
#endif
	}
	catch (std::exception const& e)
	{
		Log("ERROR occurred during prefab creation: " + std::string(e.what()), LogEntry::Error);
	}
#endif
}
Exemple #30
0
int main(int argc, char* argv[])
{
    directory_structure_t ds;

    vector<object_trj_t> good_trlet_list;
    {
	std::string name = ds.workspace+"good_trlet_list.xml";
	std::ifstream fin(name.c_str());
	boost::archive::xml_iarchive ia(fin);
	ia >> BOOST_SERIALIZATION_NVP(good_trlet_list);
    }

    matrix<int> Tff;
    {
	std::string name = ds.workspace+"Tff.txt";
	std::ifstream fin(name.c_str());
	fin>>Tff;
	fin.close();
    }

    matrix<float> Aff;
    {
	std::string name = ds.workspace+"Aff.txt";
	std::ifstream fin(name.c_str());
	fin>>Aff;
	fin.close();
    }

    matrix<float> Ocff;
    {
	std::string name = ds.workspace+"Ocff.txt";
	std::ifstream fin(name.c_str());
	fin>>Ocff;
	fin.close();
    }

    matrix<object_trj_t> gap_trlet_list;
    {
	std::string name = ds.workspace+"gap_trlet_list.xml";
	std::ifstream fin(name.c_str());
	boost::archive::xml_iarchive ia(fin);
	ia >> BOOST_SERIALIZATION_NVP(gap_trlet_list);
    }


//////////////////////////////////////////////////////////////////////////
    vector<std::vector<std::string> > seq(2);
    read_sequence_list(ds.prefix, seq);
    int T = seq[0].size();
    int Ncam = 2;

    array<std::size_t, 2> img_size = {768, 1024};
    geometric_info_t gi;
    gi.load(ds, img_size);

    parameter_t P;

    //load_part_model(model, P.head_wid_ratio, P.head_hi_ratio, P.torso_hi_ratio);


    real_timer_t timer2;

    matrix<int> LMat;
    matrix<int> links;

    matrix<float> Aff2(Aff+Ocff*0.2);
    solve_linprog(Tff, Aff2, LMat, links);

    std::cout<<"LP time: "<<timer2.elapsed()/1000.0f<<std::endl;

    std::cout<<"Lv="<<links<<std::endl;

    vector<object_trj_t> final_trj_list;
    vector<vector<int> > final_trj_index;
    matrix<int> final_state_list;

    finalize_trajectory(Ncam, T, 
			links, good_trlet_list, gap_trlet_list,
			final_trj_list, final_trj_index, final_state_list);


    {
	std::string name = ds.workspace+"final_trj_list.xml";
	std::ofstream fout(name.c_str());
	boost::archive::xml_oarchive oa(fout);
	oa << BOOST_SERIALIZATION_NVP(final_trj_list);
    }

    {
	std::string name = ds.workspace+"final_state_list.txt";
	std::ofstream fout(name.c_str());
	fout<<final_state_list;
	fout.close();
    }

    {
	std::string name = ds.workspace+"final_trj_index.txt";
	std::ofstream fout(name.c_str());
	fout << final_trj_index;
	fout.close();
    }

    return 0;

}