Skip to content

Commit

Permalink
Second (simpler) attempt at fixing duplicate ContextCounters in reports
Browse files Browse the repository at this point in the history
  • Loading branch information
bdutro committed May 1, 2024
1 parent ab292db commit c4d456b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 15 deletions.
8 changes: 3 additions & 5 deletions sparta/sparta/report/Report.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -395,28 +395,26 @@ namespace sparta
* \param si const Reference to existing StatisticInstance to copy
* \param name Name to give this instance within this Report.
* If "" (default) does not give this instance a name.
* \param recurse If true (default), also recursively add any children of si
* \return StatAdder so that multiple calls can be chained following
* an add.
* \throw SpartaException if the given name is not "" and is already used
* by another item immediately in this report (not the name of a
* subreport or item in a subreport)
*/
StatAdder add(const StatisticInstance& si, const std::string& name="", const bool recurse=true);
StatAdder add(const StatisticInstance& si, const std::string& name="");

/*!
* \brief Moves an existing statistic instance into this Report
* \param si rvalue reference to existing StatisticInstance to move
* \param name Name to give this instance within this Report.
* If "" (default) does not give this instance a name.
* \param recurse If true (default), also recursively add any children of si
* \return StatAdder so that multiple calls can be chained following
* an add.
* \throw SpartaException if the given name is not "" and is already used
* by another item immediately in this report (not the name of a
* subreport or item in a subreport)
*/
StatAdder add(StatisticInstance&& si, const std::string& name="", const bool recurse=true);
StatAdder add(StatisticInstance&& si, const std::string& name="");

/*!
* \brief Add a StatisticDef to the report
Expand All @@ -437,7 +435,7 @@ namespace sparta
* \param n The TreeNode to add
* \param name The name of the item in the report
*/
StatAdder add(TreeNode* n, const std::string& name="");
StatAdder add(const TreeNode* n, const std::string& name="");

/*!
* \brief Add a single Expression parsed at the current context for this
Expand Down
16 changes: 6 additions & 10 deletions sparta/src/Report.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1150,7 +1150,7 @@ class ReportFileParserYAML
std::string filename_; //!< For recalling errors
}; // class ReportFileParserYAML

Report::StatAdder Report::add(const StatisticInstance& si, const std::string& name, const bool recurse) {
Report::StatAdder Report::add(const StatisticInstance& si, const std::string& name) {
if(name != "" && stat_names_.find(name) != stat_names_.end()){
throw SpartaException("There is already a statistic instance in this Report (")
<< getName() << ") named \"" << name << "\" pointing to "
Expand All @@ -1164,14 +1164,12 @@ Report::StatAdder Report::add(const StatisticInstance& si, const std::string& na

if(name != ""){ stat_names_.insert(name); }

if(recurse) {
addSubStatistics_(&si);
}
addSubStatistics_(&si);

return Report::StatAdder(*this);
}

Report::StatAdder Report::add(StatisticInstance&& si, const std::string& name, const bool recurse) {
Report::StatAdder Report::add(StatisticInstance&& si, const std::string& name) {
if(name != "" && stat_names_.find(name) != stat_names_.end()){
throw SpartaException("There is already a statistic instance in this Report (")
<< getName() << ") named \"" << name << "\" pointing to "
Expand All @@ -1185,9 +1183,7 @@ Report::StatAdder Report::add(StatisticInstance&& si, const std::string& name, c

if(name != ""){ stat_names_.insert(name); }

if(recurse) {
addSubStatistics_(&si);
}
addSubStatistics_(&si);

return Report::StatAdder(*this);
}
Expand Down Expand Up @@ -1229,7 +1225,7 @@ Report::StatAdder Report::add(CounterBase* ctr, const std::string& name) {
return Report::StatAdder(*this);
}

Report::StatAdder Report::add(TreeNode* n, const std::string& name) {
Report::StatAdder Report::add(const TreeNode* n, const std::string& name) {
sparta_assert(n);
if(name != "" && stat_names_.find(name) != stat_names_.end()){
throw SpartaException("There is already a statistic instance in this Report (")
Expand Down Expand Up @@ -1420,7 +1416,7 @@ void Report::recursAddSubtree_(const TreeNode* n,
//for(auto& s : stats_){
// std::cerr << " Stat " << s.second->stringize() << " " << s.second->getLocation() << std::endl;
//}
add(n, child_stat_prefix + n->getName(), false);
add(n, child_stat_prefix + n->getName());
}
}

Expand Down

0 comments on commit c4d456b

Please sign in to comment.