18 std::vector<int> thread_gids;
22 std::vector<T> intersection;
24 std::sort(thread_gids.begin(), thread_gids.end());
25 std::sort(target_gids.begin(), target_gids.end());
27 std::set_intersection(thread_gids.begin(),
31 back_inserter(intersection));
40 #ifdef ENABLE_SONATA_REPORTS
41 if (report_config.
start <
t) {
44 report_config.
stop = std::min(report_config.
stop, tstop);
46 for (
const auto& mech: report_config.
mech_names) {
50 std::cerr <<
"[ERROR] mechanism to report: " << report_config.
mech_names[0]
51 <<
" is not mapped in this simulation, cannot report on it \n";
61 const std::vector<int>& nodes_to_gid = map_gids(nt);
63 VarsToReport vars_to_report;
65 switch (report_config.
type) {
69 vars_to_report = get_section_vars_to_report(nt,
76 register_section_report(nt, report_config, vars_to_report, is_soma_target);
80 get_summation_vars_to_report(nt, gids_to_report, report_config, nodes_to_gid);
81 register_custom_report(nt, report_config, vars_to_report);
85 vars_to_report = get_lfp_vars_to_report(
86 nt, gids_to_report, report_config,
mapinfo->_lfp.data(), nodes_to_gid);
89 register_section_report(nt, report_config, vars_to_report, is_soma_target);
93 get_synapse_vars_to_report(nt, gids_to_report, report_config, nodes_to_gid);
94 register_custom_report(nt, report_config, vars_to_report);
96 if (!vars_to_report.empty()) {
97 auto report_event = std::make_unique<ReportEvent>(
dt,
104 m_report_events.push_back(
std::move(report_event));
109 std::cerr <<
"[WARNING] : Reporting is disabled. Please recompile with libsonata.\n";
114 #ifdef ENABLE_SONATA_REPORTS
115 void ReportHandler::register_section_report(
const NrnThread& nt,
117 const VarsToReport& vars_to_report,
118 bool is_soma_target) {
120 std::cerr <<
"[WARNING] : Format '" << config.
format <<
"' in report '"
124 void ReportHandler::register_custom_report(
const NrnThread& nt,
125 const ReportConfiguration& config,
126 const VarsToReport& vars_to_report) {
128 std::cerr <<
"[WARNING] : Format '" << config.format <<
"' in report '"
129 << config.output_path <<
"' not supported.\n";
147 std::cerr <<
"SectionType not handled in getSectionTypeStr" << std::endl;
152 void register_sections_to_report(
const SecMapping* sections,
153 std::vector<VarWithMapping>& to_report,
154 double* report_variable,
155 bool all_compartments) {
156 for (
const auto& section: sections->secmap) {
158 int section_id = section.first;
159 const auto& segment_ids = section.second;
162 if (all_compartments) {
163 for (
const auto& segment_id: segment_ids) {
165 double*
variable = report_variable + segment_id;
166 to_report.emplace_back(VarWithMapping(section_id, variable));
171 const auto segment_id = segment_ids[segment_ids.size() / 2];
172 double*
variable = report_variable + segment_id;
173 to_report.emplace_back(VarWithMapping(section_id, variable));
178 VarsToReport ReportHandler::get_section_vars_to_report(
const NrnThread& nt,
179 const std::vector<int>& gids_to_report,
180 double* report_variable,
182 bool all_compartments)
const {
183 VarsToReport vars_to_report;
184 const auto& section_type_str = getSectionTypeStr(section_type);
185 const auto*
mapinfo =
static_cast<NrnThreadMappingInfo*
>(nt.mapping);
187 std::cerr <<
"[COMPARTMENTS] Error : mapping information is missing for a Cell group "
192 for (
const auto& gid: gids_to_report) {
194 if (cell_mapping ==
nullptr) {
196 <<
"[COMPARTMENTS] Error : Compartment mapping information is missing for gid "
200 std::vector<VarWithMapping> to_report;
201 to_report.reserve(cell_mapping->size());
203 if (section_type_str ==
"All") {
204 const auto& section_mapping = cell_mapping->secmapvec;
205 for (
const auto& sections: section_mapping) {
206 register_sections_to_report(sections, to_report, report_variable, all_compartments);
210 if (cell_mapping->get_seclist_section_count(section_type_str) > 0) {
211 const auto& sections = cell_mapping->get_seclist_mapping(section_type_str);
212 register_sections_to_report(sections, to_report, report_variable, all_compartments);
215 vars_to_report[gid] = to_report;
217 return vars_to_report;
220 VarsToReport ReportHandler::get_summation_vars_to_report(
222 const std::vector<int>& gids_to_report,
223 const ReportConfiguration& report,
224 const std::vector<int>& nodes_to_gids)
const {
225 VarsToReport vars_to_report;
226 const auto*
mapinfo =
static_cast<NrnThreadMappingInfo*
>(nt.mapping);
227 auto& summation_report = nt.summation_report_handler_->summation_reports_[report.output_path];
229 std::cerr <<
"[COMPARTMENTS] Error : mapping information is missing for a Cell group "
234 for (
const auto& gid: gids_to_report) {
235 bool has_imembrane =
false;
238 for (
auto i = 0;
i < report.mech_ids.size(); ++
i) {
239 auto mech_id = report.mech_ids[
i];
240 auto var_name = report.var_names[
i];
241 auto mech_name = report.mech_names[
i];
242 if (mech_name !=
"i_membrane") {
244 if (mech_name ==
"IClamp" || mech_name ==
"SEClamp") {
257 summation_report.currents_[segment_id].push_back(
258 std::make_pair(var_value, scale));
262 has_imembrane =
true;
266 if (cell_mapping ==
nullptr) {
267 std::cerr <<
"[SUMMATION] Error : Compartment mapping information is missing for gid "
271 std::vector<VarWithMapping> to_report;
272 to_report.reserve(cell_mapping->size());
273 summation_report.summation_.resize(nt.
end);
274 double* report_variable = summation_report.summation_.data();
275 const auto& section_type_str = getSectionTypeStr(report.section_type);
277 if (cell_mapping->get_seclist_section_count(section_type_str) > 0) {
278 const auto& sections = cell_mapping->get_seclist_mapping(section_type_str);
279 register_sections_to_report(sections,
282 report.section_all_compartments);
285 const auto& section_mapping = cell_mapping->secmapvec;
286 for (
const auto& sections: section_mapping) {
287 for (
auto& section: sections->secmap) {
289 int section_id = section.first;
290 auto& segment_ids = section.second;
291 for (
const auto& segment_id: segment_ids) {
294 summation_report.currents_[segment_id].push_back(
295 std::make_pair(nt.nrn_fast_imem->nrn_sav_rhs + segment_id, 1));
298 double*
variable = report_variable + segment_id;
299 to_report.emplace_back(VarWithMapping(section_id, variable));
302 summation_report.gid_segments_[gid].push_back(segment_id);
307 vars_to_report[gid] = to_report;
309 return vars_to_report;
312 VarsToReport ReportHandler::get_synapse_vars_to_report(
314 const std::vector<int>& gids_to_report,
315 const ReportConfiguration& report,
316 const std::vector<int>& nodes_to_gids)
const {
317 VarsToReport vars_to_report;
318 for (
const auto& gid: gids_to_report) {
321 auto mech_id = report.mech_ids[0];
322 auto var_name = report.var_names[0];
327 std::vector<VarWithMapping> to_report;
331 double* is_selected =
333 bool report_variable =
false;
337 if (is_selected ==
nullptr) {
338 report_variable =
true;
340 report_variable = *is_selected != 0.;
342 if ((nodes_to_gids[ml->
nodeindices[
j]] == gid) && report_variable) {
347 to_report.emplace_back(
static_cast<int>(*synapse_id), var_value);
350 if (!to_report.empty()) {
351 vars_to_report[gid] = to_report;
354 return vars_to_report;
357 VarsToReport ReportHandler::get_lfp_vars_to_report(
const NrnThread& nt,
358 const std::vector<int>& gids_to_report,
359 ReportConfiguration& report,
360 double* report_variable,
361 const std::vector<int>& nodes_to_gids)
const {
362 const auto*
mapinfo =
static_cast<NrnThreadMappingInfo*
>(nt.mapping);
364 std::cerr <<
"[LFP] Error : mapping information is missing for a Cell group " << nt.
ncell
368 auto& summation_report = nt.summation_report_handler_->summation_reports_[report.output_path];
369 VarsToReport vars_to_report;
370 std::size_t offset_lfp = 0;
371 for (
const auto& gid: gids_to_report) {
373 if (cell_mapping ==
nullptr) {
374 std::cerr <<
"[LFP] Error : Compartment mapping information is missing for gid " << gid
378 std::vector<VarWithMapping> to_report;
379 int num_electrodes = cell_mapping->num_electrodes();
380 for (
int electrode_id = 0; electrode_id < num_electrodes; electrode_id++) {
381 to_report.emplace_back(VarWithMapping(electrode_id, report_variable + offset_lfp));
384 if (!to_report.empty()) {
385 vars_to_report[gid] = to_report;
388 return vars_to_report;
392 std::vector<int> ReportHandler::map_gids(
const NrnThread& nt)
const {
393 std::vector<int> nodes_gid(nt.
end, -1);
395 for (
int i = 0;
i < nt.n_presyn;
i++) {
396 const int gid = nt.presyns[
i].gid_;
397 const int thvar_index = nt.presyns[
i].thvar_index_;
399 if (thvar_index >= 0) {
403 nodes_gid[thvar_index] = gid;
virtual void create_report(ReportConfiguration &config, double dt, double tstop, double delay)
void move(Item *q1, Item *q2, Item *q3)
THIS FILE IS AUTO GENERATED DONT MODIFY IT.
void nrn_abort(int errcode)
double * get_var_location_from_var_name(int mech_id, const char *variable_name, Memb_list *ml, int node_index)
std::vector< T > intersection_gids(const NrnThread &nt, std::vector< T > &target_gids)
int nrn_get_mechtype(const char *name)
Get mechanism type by the mechanism name.
NetCvode * net_cvode_instance
#define nrn_assert(x)
assert()-like macro, independent of NDEBUG status
NrnMappingInfo mapinfo
mapping information
#define SELECTED_VAR_MOD_NAME
#define SYNAPSE_ID_MOD_NAME
name of the variable in mod file used for setting synapse id
A view into a set of mechanism instances.
CellMapping * get_cell_mapping(int gid)
get cell mapping information for given gid if exist otherwise return NULL.
Represent main neuron object computed by single thread.
Section to segment mapping.
NrnFastImem * nrn_fast_imem
Compartment mapping information for NrnThread.
bool section_all_compartments
std::vector< int > target
std::vector< std::string > mech_names
std::vector< int > mech_ids