Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-18 09:16:19

0001 //------------------------------- -*- C++ -*- -------------------------------//
0002 // Copyright Celeritas contributors: see top-level COPYRIGHT file for details
0003 // SPDX-License-Identifier: (Apache-2.0 OR MIT)
0004 //---------------------------------------------------------------------------//
0005 //! \file geocel/ScopedGeantLogger.hh
0006 //---------------------------------------------------------------------------//
0007 #pragma once
0008 
0009 #include <memory>
0010 
0011 #include "corecel/Config.hh"
0012 
0013 #include "corecel/Macros.hh"
0014 
0015 class G4coutDestination;
0016 
0017 namespace celeritas
0018 {
0019 class Logger;
0020 //---------------------------------------------------------------------------//
0021 /*!
0022  * Install a Geant output destination during this class's lifetime.
0023  *
0024  * Since the Geant4 output streams are thread-local, this class is as well.
0025  * Multiple geant loggers can be nested, and only the outermost on a given
0026  * thread will "own" the log destination.
0027  */
0028 class ScopedGeantLogger
0029 {
0030   public:
0031     // Enable and disable to avoid recursion with accel/Logger
0032     static bool enabled();
0033     static void enabled(bool);
0034 
0035     // Construct with pointer to the Celeritas logger instance
0036     explicit ScopedGeantLogger(Logger&);
0037 
0038     // Construct using world logger
0039     ScopedGeantLogger();
0040 
0041     // Clear on destruction
0042     ~ScopedGeantLogger();
0043 
0044     //! Prevent copying and moving for RAII class
0045     CELER_DELETE_COPY_MOVE(ScopedGeantLogger);
0046 
0047   private:
0048 #if CELERITAS_USE_GEANT4
0049     std::unique_ptr<G4coutDestination> logger_;
0050 #endif
0051 };
0052 
0053 #if !CELERITAS_USE_GEANT4
0054 //!@{
0055 //! Do nothing if Geant4 is disabled (source file will not be compiled)
0056 inline ScopedGeantLogger::ScopedGeantLogger(Logger&) {}
0057 inline ScopedGeantLogger::ScopedGeantLogger() {}
0058 inline ScopedGeantLogger::~ScopedGeantLogger() {}
0059 //!@}
0060 #endif
0061 
0062 //---------------------------------------------------------------------------//
0063 }  // namespace celeritas