|
|
|||
File indexing completed on 2026-11-08 10:17:25
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 namespace celeritas 0016 { 0017 class Logger; 0018 //---------------------------------------------------------------------------// 0019 /*! 0020 * Redirect Geant4 logging through Celeritas' logger. 0021 * 0022 * This parses messages sent to \c G4cout and \c G4cerr from Geant4. Based on 0023 * the message (whether it starts with warning, error, '!!!', '***') it tries 0024 * to use the appropriate logging level and source context. 0025 * 0026 * Since the Geant4 output streams are thread-local, this class is as well. 0027 * Multiple geant loggers can be nested in scope, but only the outermost on a 0028 * given thread will "own" the log destination. 0029 * 0030 * - When instantiated during setup, this should be constructed with 0031 * \c celeritas::world_logger to avoid printing duplicate messages per 0032 * thread/process. 0033 * - When instantiated during runtime, it should take the 0034 * \c celeritas::self_logger so that only warning/error messages are printed 0035 * for event/track-specific details. 0036 * 0037 */ 0038 class ScopedGeantLogger 0039 { 0040 public: 0041 // Enable and disable to avoid recursion with accel/Logger 0042 static bool enabled(); 0043 static void enabled(bool); 0044 0045 // Construct with pointer to the Celeritas logger instance 0046 explicit ScopedGeantLogger(Logger&); 0047 0048 // Construct using world logger 0049 ScopedGeantLogger(); 0050 0051 // Clear on destruction 0052 ~ScopedGeantLogger(); 0053 0054 //! Prevent copying and moving for RAII class 0055 CELER_DELETE_COPY_MOVE(ScopedGeantLogger); 0056 0057 private: 0058 class StreamDestination; 0059 0060 std::unique_ptr<StreamDestination> logger_; 0061 }; 0062 0063 #if !CELERITAS_USE_GEANT4 0064 // Do nothing if Geant4 is disabled 0065 inline bool ScopedGeantLogger::enabled() 0066 { 0067 return false; 0068 } 0069 inline void ScopedGeantLogger::enabled(bool) {} 0070 inline ScopedGeantLogger::ScopedGeantLogger(Logger&) {} 0071 inline ScopedGeantLogger::ScopedGeantLogger() {} 0072 inline ScopedGeantLogger::~ScopedGeantLogger() {} 0073 class ScopedGeantLogger::StreamDestination 0074 { 0075 }; 0076 #endif 0077 0078 //---------------------------------------------------------------------------// 0079 } // namespace celeritas
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|