diff --git a/src/coreneuron/io/nrn2core_direct.h b/src/coreneuron/io/nrn2core_direct.h index 3039262d13..2aa06be750 100644 --- a/src/coreneuron/io/nrn2core_direct.h +++ b/src/coreneuron/io/nrn2core_direct.h @@ -95,11 +95,18 @@ extern int (*nrn2core_get_dat2_vecplay_inst_)(int tid, extern void (*nrn2core_part2_clean_)(); -extern void (*nrn2core_get_dat3_cell_count)(int&cell_count); +extern void (*nrn2core_get_dat3_cell_count)(int& cell_count); extern void (*nrn2core_get_dat3_cellmapping)(int i, int& gid, int& nsec, int& nseg, int& n_seclist); -extern void (*nrn2core_get_dat3_secmapping)(int i_c, int i_sec, std::string& segname, - int& nsec, int& nseg, size_t& total_lfp_factors, int& n_electrode, - std::vector& data_sec, std::vector& data_seg, std::vector& data_lfp); +extern void (*nrn2core_get_dat3_secmapping)(int i_c, + int i_sec, + std::string& segname, + int& nsec, + int& nseg, + size_t& total_lfp_factors, + int& n_electrode, + std::vector& data_sec, + std::vector& data_seg, + std::vector& data_lfp); /* what variables to send back to NEURON on each time step */ extern void (*nrn2core_get_trajectory_requests_)(int tid, diff --git a/src/coreneuron/io/nrn_setup.cpp b/src/coreneuron/io/nrn_setup.cpp index 044b45dce5..a5cc9b34a4 100644 --- a/src/coreneuron/io/nrn_setup.cpp +++ b/src/coreneuron/io/nrn_setup.cpp @@ -74,9 +74,16 @@ void (*nrn2core_all_weights_return_)(std::vector& weights); void (*nrn2core_get_dat3_cell_count)(int& cell_count); void (*nrn2core_get_dat3_cellmapping)(int i, int& gid, int& nsec, int& nseg, int& n_seclist); -void (*nrn2core_get_dat3_secmapping)(int i_c, int i_sec, std::string& segname, - int& nsec, int& nseg, size_t& total_lfp_factors, int& n_electrode, - std::vector& data_sec, std::vector& data_seg, std::vector& data_lfp); +void (*nrn2core_get_dat3_secmapping)(int i_c, + int i_sec, + std::string& segname, + int& nsec, + int& nseg, + size_t& total_lfp_factors, + int& n_electrode, + std::vector& data_sec, + std::vector& data_seg, + std::vector& data_lfp); // file format defined in cooperation with nrncore/src/nrniv/nrnbbcore_write.cpp // single integers are ascii one per line. arrays are binary int or double // Note that regardless of the gid contents of a group, since all gids are @@ -944,14 +951,23 @@ void read_phase3(NrnThread& nt, UserParams& userParams) { int gid, nsec, nseg, nseclist; nrn2core_get_dat3_cellmapping(i, gid, nsec, nseg, nseclist); CellMapping* cmap = new CellMapping(gid); - for (int j=0; j data_sec; std::vector data_seg; std::vector data_lfp; - nrn2core_get_dat3_secmapping(i, j, segname, n_secsec, n_secseg, total_lfp_factors, n_electrodes, data_sec, data_seg, data_lfp); + nrn2core_get_dat3_secmapping(i, + j, + segname, + n_secsec, + n_secseg, + total_lfp_factors, + n_electrodes, + data_sec, + data_seg, + data_lfp); SecMapping* smap = new SecMapping(); smap->name = segname; int factor_offset = 0; @@ -962,46 +978,44 @@ void read_phase3(NrnThread& nt, UserParams& userParams) { if (total_lfp_factors > 0) { // Abort if the factors contains a NaN nrn_assert(count_if(data_lfp.begin(), data_lfp.end(), [](double d) { - return std::isnan(d); - }) == 0); + return std::isnan(d); + }) == 0); std::vector segment_factors(data_lfp.begin() + factor_offset, - data_lfp.begin() + factor_offset + n_electrodes); + data_lfp.begin() + factor_offset + + n_electrodes); cmap->add_segment_lfp_factor(data_seg[i], segment_factors); + } } + cmap->add_sec_map(smap); } - cmap->add_sec_map(smap); - - } ntmapping->add_cell_mapping(cmap); - - } + } } else { + int count = 0; - int count = 0; + F.read_mapping_cell_count(&count); - F.read_mapping_cell_count(&count); + /** number of cells in mapping file should equal to cells in NrnThread */ + nrn_assert(count == nt.ncell); - /** number of cells in mapping file should equal to cells in NrnThread */ - nrn_assert(count == nt.ncell); + /** for every neuron */ + for (int i = 0; i < nt.ncell; i++) { + int gid, nsec, nseg, nseclist; - /** for every neuron */ - for (int i = 0; i < nt.ncell; i++) { - int gid, nsec, nseg, nseclist; + // read counts + F.read_mapping_count(&gid, &nsec, &nseg, &nseclist); - // read counts - F.read_mapping_count(&gid, &nsec, &nseg, &nseclist); + CellMapping* cmap = new CellMapping(gid); - CellMapping* cmap = new CellMapping(gid); + // read section-segment mapping for every section list + for (int j = 0; j < nseclist; j++) { + SecMapping* smap = new SecMapping(); + F.read_mapping_info(smap, ntmapping, cmap); + cmap->add_sec_map(smap); + } - // read section-segment mapping for every section list - for (int j = 0; j < nseclist; j++) { - SecMapping* smap = new SecMapping(); - F.read_mapping_info(smap, ntmapping, cmap); - cmap->add_sec_map(smap); + ntmapping->add_cell_mapping(cmap); } - - ntmapping->add_cell_mapping(cmap); - } } // make number #cells match with mapping size nrn_assert((int) ntmapping->size() == nt.ncell); diff --git a/src/nrniv/nrncore_write/callbacks/nrncore_callbacks.cpp b/src/nrniv/nrncore_write/callbacks/nrncore_callbacks.cpp index 6f313a6985..04bb5d1d63 100644 --- a/src/nrniv/nrncore_write/callbacks/nrncore_callbacks.cpp +++ b/src/nrniv/nrncore_write/callbacks/nrncore_callbacks.cpp @@ -227,8 +227,7 @@ void nrnthread_dat3_cell_count(int& cell_count) { cell_count = mapinfo.size(); } -void nrnthread_dat3_cellmapping(int i, int& gid, - int& nsec, int& nseg, int& n_seclist) { +void nrnthread_dat3_cellmapping(int i, int& gid, int& nsec, int& nseg, int& n_seclist) { CellMapping* c = mapinfo.mapping[i]; gid = c->gid; nsec = c->num_sections(); @@ -236,12 +235,19 @@ void nrnthread_dat3_cellmapping(int i, int& gid, n_seclist = c->size(); } -void nrnthread_dat3_secmapping(int i_c, int i_sec, std::string& segname, - int& nsec, int& nseg, size_t& total_lfp_factors, int& n_electrodes, - std::vector& data_sec, std::vector& data_seg, std::vector& data_lfp) { +void nrnthread_dat3_secmapping(int i_c, + int i_sec, + std::string& segname, + int& nsec, + int& nseg, + size_t& total_lfp_factors, + int& n_electrodes, + std::vector& data_sec, + std::vector& data_seg, + std::vector& data_lfp) { CellMapping* c = mapinfo.mapping[i_c]; SecMapping* s = c->secmapping[i_sec]; - segname=s->name.c_str(); + segname = s->name.c_str(); nsec = s->nsec; nseg = s->size(); total_lfp_factors = s->seglfp_factors.size(); @@ -249,7 +255,6 @@ void nrnthread_dat3_secmapping(int i_c, int i_sec, std::string& segname, data_sec = s->sections; data_seg = s->segments; data_lfp = s->seglfp_factors; - } // sizes and total data count diff --git a/src/nrniv/nrncore_write/callbacks/nrncore_callbacks.h b/src/nrniv/nrncore_write/callbacks/nrncore_callbacks.h index fa1975b6c8..a278e42f77 100644 --- a/src/nrniv/nrncore_write/callbacks/nrncore_callbacks.h +++ b/src/nrniv/nrncore_write/callbacks/nrncore_callbacks.h @@ -96,9 +96,16 @@ int nrnthread_dat2_vecplay_inst(int tid, int& ubound_index); void nrnthread_dat3_cell_count(int& cell_count); void nrnthread_dat3_cellmapping(int i, int& gid, int& nsec, int& nseg, int& n_seclist); -void nrnthread_dat3_secmapping(int i_c, int i_sec, std::string& segname, - int& nsec, int& nseg, size_t& total_lfp_factors, int& n_electrode, - std::vector& data_sec, std::vector& data_seg, std::vector& data_lfp); +void nrnthread_dat3_secmapping(int i_c, + int i_sec, + std::string& segname, + int& nsec, + int& nseg, + size_t& total_lfp_factors, + int& n_electrode, + std::vector& data_sec, + std::vector& data_seg, + std::vector& data_lfp); int* datum2int(int type, Memb_list* ml,