HooksRegistrar& HooksRegistrar::response_header_data(header_data_t f) { return header_data( Engine::response_header_data, f ); }
HooksRegistrar& HooksRegistrar::request_header_data(header_data_t f) { return header_data( Engine::request_header_data, f ); }
std::size_t header_parser::parse_header_callback(const char *ptr, std::size_t size) { std::string header_data(ptr, size); if (!boost::algorithm::ends_with(header_data, "\r\n")) BOOST_THROW_EXCEPTION(header_parse_error() << header_parse_error::message("Header without CRLF") << header_parse_error::header_data(header_data)); BOOST_ASSERT(header_data.size() >= 2); header_data.resize(header_data.size() - 2); parse(header_data); return size; }
Loader::ResultStatus CIAContainer::Load(const std::string& filepath) { FileUtil::IOFile file(filepath, "rb"); if (!file.IsOpen()) return Loader::ResultStatus::Error; // Load CIA Header std::vector<u8> header_data(sizeof(Header)); if (file.ReadBytes(header_data.data(), sizeof(Header)) != sizeof(Header)) return Loader::ResultStatus::Error; Loader::ResultStatus result = LoadHeader(header_data); if (result != Loader::ResultStatus::Success) return result; // Load Title Metadata std::vector<u8> tmd_data(cia_header.tmd_size); file.Seek(GetTitleMetadataOffset(), SEEK_SET); if (file.ReadBytes(tmd_data.data(), cia_header.tmd_size) != cia_header.tmd_size) return Loader::ResultStatus::Error; result = LoadTitleMetadata(tmd_data); if (result != Loader::ResultStatus::Success) return result; // Load CIA Metadata if (cia_header.meta_size) { std::vector<u8> meta_data(sizeof(Metadata)); file.Seek(GetMetadataOffset(), SEEK_SET); if (file.ReadBytes(meta_data.data(), sizeof(Metadata)) != sizeof(Metadata)) return Loader::ResultStatus::Error; result = LoadMetadata(meta_data); if (result != Loader::ResultStatus::Success) return result; } return Loader::ResultStatus::Success; }
Loader::ResultStatus CIAContainer::Load(const FileBackend& backend) { std::vector<u8> header_data(sizeof(Header)); // Load the CIA Header ResultVal<size_t> read_result = backend.Read(0, sizeof(Header), header_data.data()); if (read_result.Failed() || *read_result != sizeof(Header)) return Loader::ResultStatus::Error; Loader::ResultStatus result = LoadHeader(header_data); if (result != Loader::ResultStatus::Success) return result; // Load Title Metadata std::vector<u8> tmd_data(cia_header.tmd_size); read_result = backend.Read(GetTitleMetadataOffset(), cia_header.tmd_size, tmd_data.data()); if (read_result.Failed() || *read_result != cia_header.tmd_size) return Loader::ResultStatus::Error; result = LoadTitleMetadata(tmd_data); if (result != Loader::ResultStatus::Success) return result; // Load CIA Metadata if (cia_header.meta_size) { std::vector<u8> meta_data(sizeof(Metadata)); read_result = backend.Read(GetMetadataOffset(), sizeof(Metadata), meta_data.data()); if (read_result.Failed() || *read_result != sizeof(Metadata)) return Loader::ResultStatus::Error; result = LoadMetadata(meta_data); if (result != Loader::ResultStatus::Success) return result; } return Loader::ResultStatus::Success; }
void RBEvaluation::read_in_vectors(System& sys, std::vector<NumericVector<Number>*>& vectors, const std::string& directory_name, const std::string& data_name, const bool read_binary_vectors) { START_LOG("read_in_vectors()", "RBEvaluation"); //libMesh::out << "Reading in the basis functions..." << std::endl; // Make sure processors are synced up before we begin this->comm().barrier(); std::ostringstream file_name; const std::string basis_function_suffix = (read_binary_vectors ? ".xdr" : ".dat"); struct stat stat_info; file_name << directory_name << "/" << data_name << "_header" << basis_function_suffix; Xdr header_data(file_name.str(), read_binary_vectors ? DECODE : READ); // set the version number in header_data from io_version_string // (same code as in EquationSystemsIO::_read_impl) std::string io_version_string = get_io_version_string(); std::string::size_type lm_pos = io_version_string.find("libMesh"); std::istringstream iss(io_version_string.substr(lm_pos + 8)); int ver_major = 0, ver_minor = 0, ver_patch = 0; char dot; iss >> ver_major >> dot >> ver_minor >> dot >> ver_patch; header_data.set_version(LIBMESH_VERSION_ID(ver_major, ver_minor, ver_patch)); // We need to call sys.read_header (e.g. to set _written_var_indices properly), // but by setting the read_header argument to false, it doesn't reinitialize the system sys.read_header(header_data, io_version_string, /*read_header=*/false, /*read_additional_data=*/false); // Following EquationSystemsIO::read, we use a temporary numbering (node major) // before writing out the data MeshTools::Private::globally_renumber_nodes_and_elements(sys.get_mesh()); const bool read_legacy_format = false; if (read_legacy_format) { // Use System::read_serialized_data to read in the basis functions // into this->solution and then swap with the appropriate // of basis function. for(unsigned int i=0; i<vectors.size(); i++) { file_name.str(""); // reset the string file_name << directory_name << "/" << data_name << i << basis_function_suffix; // On processor zero check to be sure the file exists if (this->processor_id() == 0) { int stat_result = stat(file_name.str().c_str(), &stat_info); if (stat_result != 0) libmesh_error_msg("File does not exist: " << file_name.str()); } Xdr vector_data(file_name.str(), read_binary_vectors ? DECODE : READ); // The bf_data needs to know which version to read. vector_data.set_version(LIBMESH_VERSION_ID(ver_major, ver_minor, ver_patch)); sys.read_serialized_data(vector_data, false); vectors[i] = NumericVector<Number>::build(sys.comm()).release(); vectors[i]->init (sys.n_dofs(), sys.n_local_dofs(), false, PARALLEL); // No need to copy, just swap // *vectors[i] = *solution; vectors[i]->swap(*sys.solution); } } //------------------------------------------------------ // new implementation else { // Allocate storage for each vector for(unsigned int i=0; i<vectors.size(); i++) { vectors[i] = NumericVector<Number>::build(sys.comm()).release(); vectors[i]->init (sys.n_dofs(), sys.n_local_dofs(), false, PARALLEL); } file_name.str(""); file_name << directory_name << "/" << data_name << "_data" << basis_function_suffix; // On processor zero check to be sure the file exists if (this->processor_id() == 0) { int stat_result = stat(file_name.str().c_str(), &stat_info); if (stat_result != 0) libmesh_error_msg("File does not exist: " << file_name.str()); } Xdr vector_data(file_name.str(), read_binary_vectors ? DECODE : READ); // The vector_data needs to know which version to read. vector_data.set_version(LIBMESH_VERSION_ID(ver_major, ver_minor, ver_patch)); sys.read_serialized_vectors (vector_data, vectors); } //------------------------------------------------------ // Undo the temporary renumbering sys.get_mesh().fix_broken_node_and_element_numbering(); //libMesh::out << "Finished reading in the basis functions..." << std::endl; STOP_LOG("read_in_vectors()", "RBEvaluation"); }
void RBEvaluation::write_out_vectors(System& sys, std::vector<NumericVector<Number>*>& vectors, const std::string& directory_name, const std::string& data_name, const bool write_binary_vectors) { START_LOG("write_out_vectors()", "RBEvaluation"); //libMesh::out << "Writing out the basis functions..." << std::endl; if(this->processor_id() == 0) { // Make a directory to store all the data files mkdir(directory_name.c_str(), 0777); } // Make sure processors are synced up before we begin this->comm().barrier(); std::ostringstream file_name; const std::string basis_function_suffix = (write_binary_vectors ? ".xdr" : ".dat"); file_name << directory_name << "/" << data_name << "_header" << basis_function_suffix; Xdr header_data(file_name.str(), write_binary_vectors ? ENCODE : WRITE); sys.write_header(header_data, get_io_version_string(), /*write_additional_data=*/false); // Following EquationSystemsIO::write, we use a temporary numbering (node major) // before writing out the data MeshTools::Private::globally_renumber_nodes_and_elements(sys.get_mesh()); // // Use System::write_serialized_data to write out the basis functions // // by copying them into this->solution one at a time. // for(unsigned int i=0; i<vectors.size(); i++) // { // // No need to copy, just swap // // *solution = *vectors[i]; // vectors[i]->swap(*sys.solution); // file_name.str(""); // reset the string // file_name << directory_name << "/bf" << i << basis_function_suffix; // Xdr bf_data(file_name.str(), // write_binary_vectors ? ENCODE : WRITE); // // set the current version // bf_data.set_version(LIBMESH_VERSION_ID(LIBMESH_MAJOR_VERSION, // LIBMESH_MINOR_VERSION, // LIBMESH_MICRO_VERSION)); // sys.write_serialized_data(bf_data, false); // // Synchronize before moving on // this->comm().barrier(); // // Swap back // vectors[i]->swap(*sys.solution); // } file_name.str(""); file_name << directory_name << "/" << data_name << "_data" << basis_function_suffix; Xdr bf_data(file_name.str(), write_binary_vectors ? ENCODE : WRITE); // Write all vectors at once. { // Note the API wants pointers to constant vectors, hence this... std::vector<const NumericVector<Number>*> bf_out(vectors.begin(), vectors.end()); // for(unsigned int i=0; i<vectors.size(); i++) // bf_out.push_back(vectors[i]); sys.write_serialized_vectors (bf_data, bf_out); } // set the current version bf_data.set_version(LIBMESH_VERSION_ID(LIBMESH_MAJOR_VERSION, LIBMESH_MINOR_VERSION, LIBMESH_MICRO_VERSION)); // Undo the temporary renumbering sys.get_mesh().fix_broken_node_and_element_numbering(); STOP_LOG("write_out_vectors()", "RBEvaluation"); }
void RBEvaluation::read_in_vectors_from_multiple_files( System& sys, std::vector< std::vector<NumericVector<Number>*>* > multiple_vectors, const std::vector<std::string>& multiple_directory_names, const std::vector<std::string>& multiple_data_names, const bool read_binary_vectors) { START_LOG("read_in_vectors_from_multiple_files()", "RBEvaluation"); unsigned int n_files = multiple_vectors.size(); unsigned int n_directories = multiple_directory_names.size(); unsigned int n_data_names = multiple_data_names.size(); libmesh_assert( (n_files == n_directories) && (n_files == n_data_names) ); if(n_files == 0) { return; } // Make sure processors are synced up before we begin this->comm().barrier(); std::ostringstream file_name; const std::string basis_function_suffix = (read_binary_vectors ? ".xdr" : ".dat"); struct stat stat_info; // Assume that all the headers are the same, hence we can just use the first one. file_name << multiple_directory_names[0] << "/" << multiple_data_names[0] << "_header" << basis_function_suffix; Xdr header_data(file_name.str(), read_binary_vectors ? DECODE : READ); // set the version number in header_data from io_version_string // (same code as in EquationSystemsIO::_read_impl) std::string io_version_string = get_io_version_string(); std::string::size_type lm_pos = io_version_string.find("libMesh"); std::istringstream iss(io_version_string.substr(lm_pos + 8)); int ver_major = 0, ver_minor = 0, ver_patch = 0; char dot; iss >> ver_major >> dot >> ver_minor >> dot >> ver_patch; header_data.set_version(LIBMESH_VERSION_ID(ver_major, ver_minor, ver_patch)); // We need to call sys.read_header (e.g. to set _written_var_indices properly), // but by setting the read_header argument to false, it doesn't reinitialize the system sys.read_header( header_data, io_version_string, /*read_header=*/false, /*read_additional_data=*/false); // Following EquationSystemsIO::read, we use a temporary numbering (node major) // before writing out the data MeshTools::Private::globally_renumber_nodes_and_elements( sys.get_mesh()); for(unsigned int data_index=0; data_index<n_directories; data_index++) { std::vector<NumericVector<Number>*>& vectors = *multiple_vectors[data_index]; // Allocate storage for each vector for(unsigned int i=0; i<vectors.size(); i++) { vectors[i] = NumericVector<Number>::build( sys.comm()).release(); vectors[i]->init ( sys.n_dofs(), sys.n_local_dofs(), false, PARALLEL); } file_name.str(""); file_name << multiple_directory_names[data_index] << "/" << multiple_data_names[data_index] << "_data" << basis_function_suffix; // On processor zero check to be sure the file exists if (this->processor_id() == 0) { int stat_result = stat(file_name.str().c_str(), &stat_info); if (stat_result != 0) { libmesh_error_msg("File does not exist: " << file_name.str()); } } Xdr vector_data(file_name.str(), read_binary_vectors ? DECODE : READ); // The vector_data needs to know which version to read. vector_data.set_version(LIBMESH_VERSION_ID(ver_major, ver_minor, ver_patch)); sys.read_serialized_vectors (vector_data, vectors); } // Undo the temporary renumbering sys.get_mesh().fix_broken_node_and_element_numbering(); STOP_LOG("read_in_vectors_from_multiple_files()", "RBEvaluation"); }