IAP GITLAB

Skip to content
Snippets Groups Projects
Commit 2c26a639 authored by Marvin Gottowik's avatar Marvin Gottowik Committed by Alice Faure
Browse files

add counter and limit number of printouts

parent af4659cd
No related branches found
No related tags found
1 merge request!647Resolve "tweak frequency of print outs in StackInspector"
......@@ -58,51 +58,60 @@ namespace corsika {
if ((E0_ - Etot) < dE_threshold_) return;
std::chrono::system_clock::time_point const now = std::chrono::system_clock::now();
std::chrono::duration<double> const elapsed_seconds = now - StartTime_; // seconds
// Select reference times and energies using either the true start
// or the delayed start to avoid counting overhead in ETA
bool const usePostVals = (energyPostInit_ != HEPEnergyType::zero());
auto const dE = (usePostVals ? energyPostInit_ : E0_) - Etot;
std::chrono::duration<double> const usedSeconds = now - timePostInit_;
double const dT = usedSeconds.count();
double const progress = (E0_ - Etot) / E0_;
// for printout
std::time_t const now_time = std::chrono::system_clock::to_time_t(now);
double const ETA_seconds = (1.0 - progress) * dT * (E0_ / dE);
std::chrono::system_clock::time_point const ETA =
now + std::chrono::seconds((int)ETA_seconds);
// for printout
std::time_t const ETA_time = std::chrono::system_clock::to_time_t(ETA);
int const yday0 = std::localtime(&now_time)->tm_yday;
int const yday1 = std::localtime(&ETA_time)->tm_yday;
int const dyday = yday1 - yday0;
std::stringstream ETA_string;
ETA_string << std::put_time(std::localtime(&ETA_time), "%T %Z");
CORSIKA_LOG_INFO(
"StackInspector: "
" time={}"
", running={:.1f} seconds"
" ( {:.1f}%)"
", nStep={}"
", stackSize={}"
", Estack={:.1f} GeV"
", ETA={}{}",
std::put_time(std::localtime(&now_time), "%T %Z"), elapsed_seconds.count(),
(progress * 100), getStep(), vS.getSize(), Etot / 1_GeV,
(dyday == 0 ? "" : fmt::format("+{}d ", dyday)), ETA_string.str());
// Change reference time once the shower has begin (avoid counting overhead time)
if (progress > 0.02 && energyPostInit_ == HEPEnergyType::zero()) {
energyPostInit_ = Etot;
timePostInit_ = std::chrono::system_clock::now();
// limit number of printouts
if (printoutCounter_ < maxNumberOfPrintouts_) {
std::chrono::system_clock::time_point const now = std::chrono::system_clock::now();
std::chrono::duration<double> const elapsed_seconds = now - StartTime_; // seconds
// Select reference times and energies using either the true start
// or the delayed start to avoid counting overhead in ETA
bool const usePostVals = (energyPostInit_ != HEPEnergyType::zero());
auto const dE = (usePostVals ? energyPostInit_ : E0_) - Etot;
std::chrono::duration<double> const usedSeconds = now - timePostInit_;
double const dT = usedSeconds.count();
double const progress = (E0_ - Etot) / E0_;
// for printout
std::time_t const now_time = std::chrono::system_clock::to_time_t(now);
double const ETA_seconds = (1.0 - progress) * dT * (E0_ / dE);
std::chrono::system_clock::time_point const ETA =
now + std::chrono::seconds((int)ETA_seconds);
std::time_t const ETA_time = std::chrono::system_clock::to_time_t(ETA);
int const yday0 = std::localtime(&now_time)->tm_yday;
int const yday1 = std::localtime(&ETA_time)->tm_yday;
int const dyday = yday1 - yday0;
std::stringstream ETA_string;
ETA_string << std::put_time(std::localtime(&ETA_time), "%T %Z");
CORSIKA_LOG_INFO(
"StackInspector: "
" time={}"
", running={:.1f} seconds"
" ( {:.1f}%)"
", nStep={}"
", stackSize={}"
", Estack={:.1f} GeV"
", ETA={}{}",
std::put_time(std::localtime(&now_time), "%T %Z"), elapsed_seconds.count(),
(progress * 100), getStep(), vS.getSize(), Etot / 1_GeV,
(dyday == 0 ? "" : fmt::format("+{}d ", dyday)), ETA_string.str());
printoutCounter_++;
if (printoutCounter_ == maxNumberOfPrintouts_) {
CORSIKA_LOG_INFO("StackInspector reached allowed maximum of {} lines printout",
maxNumberOfPrintouts_);
}
// Change reference time once the shower has begin (avoid counting overhead time)
if (progress > 0.02 && energyPostInit_ == HEPEnergyType::zero()) {
energyPostInit_ = Etot;
timePostInit_ = std::chrono::system_clock::now();
}
}
}
......
......@@ -46,6 +46,8 @@ namespace corsika {
private:
bool ReportStack_;
int printoutCounter_ = 0;
const int maxNumberOfPrintouts_ = 10;
HEPEnergyType E0_;
const HEPEnergyType dE_threshold_ = 1_eV;
std::chrono::system_clock::time_point StartTime_;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment