diff --git a/corsika/detail/modules/StackInspector.inl b/corsika/detail/modules/StackInspector.inl index f801abf624705b5bb5891bd34304c3ed0570936b..8e6ed5f59207258496f41cfa35d0357a21de22b9 100644 --- a/corsika/detail/modules/StackInspector.inl +++ b/corsika/detail/modules/StackInspector.inl @@ -27,7 +27,9 @@ namespace corsika { : StackProcess<StackInspector<TStack>>(vNStep) , ReportStack_(vReportStack) , E0_(vE0) - , StartTime_(std::chrono::system_clock::now()) {} + , StartTime_(std::chrono::system_clock::now()) + , energyPostInit_(HEPEnergyType::zero()) + , timePostInit_(std::chrono::system_clock::now()) {} template <typename TStack> inline StackInspector<TStack>::~StackInspector() {} @@ -54,54 +56,53 @@ 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 - auto const dE = E0_ - Etot; - if (dE < dE_threshold_) return; - double const progress = dE / E0_; + // 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); - std::time_t const start_time = std::chrono::system_clock::to_time_t(StartTime_); - - if (progress > 0) { - - double const eta_seconds = elapsed_seconds.count() / progress; - std::chrono::system_clock::time_point const eta = - StartTime_ + 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(&start_time)->tm_yday; - int const yday1 = std::localtime(&eta_time)->tm_yday; - int const dyday = yday1 - yday0; - - CORSIKA_LOG_INFO( - "StackInspector: " - " time={}" - ", running={} seconds" - " ( {:.1f}%)" - ", nStep={}" - ", stackSize={}" - ", Estack={} GeV" - ", ETA={}{}", - std::put_time(std::localtime(&now_time), "%T"), elapsed_seconds.count(), - (progress * 100), getStep(), vS.getSize(), Etot / 1_GeV, - (dyday == 0 ? "" : fmt::format("+{}d ", dyday)), - std::put_time(std::localtime(&eta_time), "%T")); - } else { - CORSIKA_LOG_INFO( - "StackInspector: " - " time={}" - ", running={} seconds" - " ( {:.1f}%)" - ", nStep={}" - ", stackSize={}" - ", Estack={} GeV" - ", ETA={}{}", - std::put_time(std::localtime(&now_time), "%T"), elapsed_seconds.count(), - (progress * 100), getStep(), vS.getSize(), Etot / 1_GeV, "---", "---"); + + 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(); } } diff --git a/corsika/modules/StackInspector.hpp b/corsika/modules/StackInspector.hpp index 6e723a6ced41be1e34a970991d3e55fc40c6af88..79cb8f8ffc9b0b7604c4ff258189fa7a4bd8480b 100644 --- a/corsika/modules/StackInspector.hpp +++ b/corsika/modules/StackInspector.hpp @@ -49,6 +49,8 @@ namespace corsika { HEPEnergyType E0_; const HEPEnergyType dE_threshold_ = 1_eV; std::chrono::system_clock::time_point StartTime_; + HEPEnergyType energyPostInit_; + std::chrono::system_clock::time_point timePostInit_; }; } // namespace corsika