Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:54:48

0001 //----------------------------------*-C++-*----------------------------------//
0002 // Copyright 2021-2024 UT-Battelle, LLC, and other Celeritas developers.
0003 // See the top-level COPYRIGHT file for details.
0004 // SPDX-License-Identifier: (Apache-2.0 OR MIT)
0005 //---------------------------------------------------------------------------//
0006 //! \file corecel/io/ScopedTimeAndRedirect.hh
0007 //---------------------------------------------------------------------------//
0008 #pragma once
0009 
0010 #include <memory>
0011 #include <string>
0012 
0013 #include "corecel/Macros.hh"
0014 
0015 #include "ScopedStreamRedirect.hh"
0016 #include "ScopedTimeLog.hh"
0017 
0018 namespace celeritas
0019 {
0020 //---------------------------------------------------------------------------//
0021 /*!
0022  * At end of scope, print elapsed time and captured cout/cerr.
0023  *
0024  * This is designed to prevent other libraries (Geant4,VecGeom) from polluting
0025  * stdout and breaking JSON reading ability.
0026  *
0027  * \code
0028     {
0029         ScopedTimeAndRedirect temp_{"VecGeom"};
0030         vecgeom::DoNoisyAndLongStuff();
0031     }
0032    \endcode
0033  */
0034 class ScopedTimeAndRedirect
0035 {
0036   public:
0037     explicit ScopedTimeAndRedirect(std::string label);
0038     ~ScopedTimeAndRedirect();
0039 
0040     //!@{
0041     //! Prevent copying and moving for RAII class
0042     CELER_DELETE_COPY_MOVE(ScopedTimeAndRedirect);
0043     //!@}
0044 
0045   private:
0046     std::unique_ptr<ScopedStreamRedirect> stdout_;
0047     std::unique_ptr<ScopedStreamRedirect> stderr_;
0048     std::string label_;
0049     ScopedTimeLog scoped_time_;
0050 };
0051 
0052 //---------------------------------------------------------------------------//
0053 }  // namespace celeritas