void Mesh_File_Reader::load( Meshes & final_meshes, const Cell_Target & cells, const URI & circuit_source, bool load_vertices, bool load_triangles, bool load_mapping, bool load_triangle_strips) { Meshes meshes; boost::filesystem::path mvd_file = uri_to_filename(circuit_source); if (mvd_file == "" || boost::filesystem::extension(mvd_file) != ".mvd2") { throw_exception(Bad_Data_Source("Loading meshes: circuit_source '" + circuit_source + "' "), FATAL_LEVEL, __FILE__, __LINE__); } MVD_File_Parser mvd_parser(mvd_file); mvd_parser.parse_file(cells); for (Cell_Target::iterator cell_gid = cells.begin(); cell_gid != cells.end(); ++cell_gid) { MVD_Cell_Index index = mvd_parser.cell_index(*cell_gid); if (index == UNDEFINED_MVD_CELL_INDEX) { std::stringstream msg; msg << "Loading meshes: bad cell target, neuron gid " << *cell_gid << " not in mvd file '" << mvd_file << "'"; throw_exception(Bad_Data(msg.str()), FATAL_LEVEL, __FILE__, __LINE__); } const Label & label = mvd_parser.morphology_names()[index]; if (meshes.find(label) == meshes.end()) { insert_new_or_updated(label, final_meshes, meshes, load_vertices, load_triangles, load_triangle_strips, load_mapping); } } // Final insertion from local container to result for (Meshes::iterator i = meshes.begin(); i != meshes.end(); ++i) { // This insertion replaces old existing meshes with its updated // version also final_meshes.insert(i.label(), i.ptr()); } }
void Neurons::load_from_cell_target_and_microcircuit(const Cell_Target & cell_target, Microcircuit & microcircuit) { _label =cell_target.label(); Neurons & neurons = microcircuit.neurons(); _microcircuit = neurons._microcircuit; for (Cell_Target::const_iterator i = cell_target.begin(); i != cell_target.end(); ++i) { Neurons::iterator neuron = neurons.find(*i); /** \bug This situation may happen in user code quite easily, how do we deal with it? */ bbp_assert(neuron != neurons.end()); insert(neuron); } }
void Compartment_Report_HDF5_File_Reader::update_mapping_and_framesize (const Cell_Target & target) { Cell_Index cell_index = 0; Report_Frame_Index next_compartment_index = 0; Compartment_Report_Mapping_Ptr mapping(new Compartment_Report_Mapping); std::vector<std::vector<Report_Frame_Index> > offset_mapping; offset_mapping.resize(target.size()); for (Cell_Target::iterator cell_ID = target.begin(); cell_ID != target.end(); ++cell_ID, ++cell_index) { H5ID file, dataset; try { open_data_set(*cell_ID, "mapping", file, dataset); } catch (File_Open_Error) { continue; } // Opening the dataspace H5ID space(H5Dget_space(dataset), H5Sclose); int rank = H5Sget_simple_extent_ndims(space); if (rank != 2) { std::string cell_name = "a" + boost::lexical_cast<std::string>(*cell_ID); std::string dataset_name = "/" + cell_name + "/" + (_report_name + "/") + "mapping"; throw_exception( File_Parse_Error("Compartment_Report_HDF5_File_Reader: " "Error, not 2 dimensional array on " + dataset_name), FATAL_LEVEL, __FILE__, __LINE__); } hsize_t dims[2]; H5Sget_simple_extent_dims(space, dims, NULL); boost::shared_array<float> data(new float[dims[1]]); H5Dread(dataset, H5T_NATIVE_FLOAT, H5S_ALL, H5S_ALL, H5P_DEFAULT, data.get()); // Getting the last section id; size_t largest_section_id = 0; for(size_t i = 0; i < dims[1]; ++i) { if (data[i] > largest_section_id) largest_section_id = (size_t) data[i]; } std::vector<Report_Frame_Index> & offsets = offset_mapping[cell_index]; offsets.resize(largest_section_id + 1, UNDEFINED_REPORT_FRAME_INDEX); size_t last_section = UNDEFINED_SECTION_ID; for(size_t i = 0; i < dims[1]; ++i, ++next_compartment_index) { size_t section = (size_t) data[i]; if (last_section != section) { last_section = section; // Storing the start index of a new section with at // least 1 compartment offsets[section] = next_compartment_index; } } } // next_compartment_index contains the total number of compartments _frame_size = next_compartment_index; // Updating internal mapping pointer. mapping->swap_mapping(offset_mapping, next_compartment_index); _mapping = mapping; _current_cell_target = target; }