diff --git a/corsika/detail/modules/StackInspector.inl b/corsika/detail/modules/StackInspector.inl index 8e6ed5f59207258496f41cfa35d0357a21de22b9..239bae013ed356450c69ad71cdf44d14ba551493 100644 --- a/corsika/detail/modules/StackInspector.inl +++ b/corsika/detail/modules/StackInspector.inl @@ -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_DEBUG( + "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_DEBUG("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(); + } } } diff --git a/corsika/modules/StackInspector.hpp b/corsika/modules/StackInspector.hpp index 79cb8f8ffc9b0b7604c4ff258189fa7a4bd8480b..060723fa726f0ab1c6c8e916fff62c66d35c2334 100644 --- a/corsika/modules/StackInspector.hpp +++ b/corsika/modules/StackInspector.hpp @@ -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_;