Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:58:42

0001 //
0002 // ********************************************************************
0003 // * License and Disclaimer                                           *
0004 // *                                                                  *
0005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
0006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
0007 // * conditions of the Geant4 Software License,  included in the file *
0008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
0009 // * include a list of copyright holders.                             *
0010 // *                                                                  *
0011 // * Neither the authors of this software system, nor their employing *
0012 // * institutes,nor the agencies providing financial support for this *
0013 // * work  make  any representation or  warranty, express or implied, *
0014 // * regarding  this  software system or assume any liability for its *
0015 // * use.  Please see the license in the file  LICENSE  and URL above *
0016 // * for the full disclaimer and the limitation of liability.         *
0017 // *                                                                  *
0018 // * This  code  implementation is the result of  the  scientific and *
0019 // * technical work of the GEANT4 collaboration.                      *
0020 // * By using,  copying,  modifying or  distributing the software (or *
0021 // * any work based  on the software)  you  agree  to acknowledge its *
0022 // * use  in  resulting  scientific  publications,  and indicate your *
0023 // * acceptance of all terms of the Geant4 Software license.          *
0024 // ********************************************************************
0025 //
0026 // G4MTcoutDestination
0027 //
0028 // Handling of cout/cerr in multi-threaded mode
0029 
0030 // Authors: M.Asai, A.Dotti (SLAC) - 23 May 2013
0031 // ---------------------------------------------------------------
0032 #ifndef G4MTcoutDestination_hh
0033 #define G4MTcoutDestination_hh
0034 
0035 #include <fstream>
0036 #include <iostream>
0037 #include <sstream>
0038 
0039 #include "G4MulticoutDestination.hh"
0040 #include "G4StateManager.hh"
0041 #include "globals.hh"
0042 
0043 class G4LockcoutDestination;
0044 
0045 class G4MTcoutDestination : public G4MulticoutDestination
0046 {
0047  public:
0048   explicit G4MTcoutDestination(const G4int& threadId);
0049   ~G4MTcoutDestination() override;
0050 
0051   virtual void Reset();
0052 
0053   void SetDefaultOutput(G4bool addMasterDestination = true,
0054                         G4bool formatAlsoMaster     = true);
0055 
0056   void SetCoutFileName(const G4String& fileN = "G4cout.txt",
0057                        G4bool ifAppend       = true);
0058   void AddCoutFileName(const G4String& fileN = "G4cout.txt",
0059                        G4bool ifAppend       = true);
0060   void SetCerrFileName(const G4String& fileN = "G4cerr.txt",
0061                        G4bool ifAppend       = true);
0062   void AddCerrFileName(const G4String& fileN = "G4cerr.txt",
0063                        G4bool ifAppend       = true);
0064 
0065   void EnableBuffering(G4bool flag = true);
0066 
0067   inline void SetPrefixString(const G4String& wd = "G4WT") { prefix = wd; }
0068 
0069   void SetIgnoreCout(G4int tid = 0);
0070   inline void SetIgnoreInit(G4bool val = true) { ignoreInit = val; }
0071 
0072   inline G4String GetPrefixString() const { return prefix; }
0073   inline G4String GetFullPrefixString() const
0074   {
0075     std::stringstream os;
0076     os << prefix << id;
0077     return os.str();
0078   }
0079 
0080  protected:
0081   void AddMasterOutput(G4bool formatAlsoMaster);
0082   void HandleFileCout(const G4String& fileN, G4bool appendFlag,
0083                       G4bool suppressDefault);
0084   void HandleFileCerr(const G4String& fileN, G4bool appendFlag,
0085                       G4bool suppressDefault);
0086 
0087  private:
0088   void DumpBuffer();
0089 
0090  private:
0091   // Reference to the default destination
0092   G4coutDestination* ref_defaultOut = nullptr;
0093 
0094   // Reference to the master destination
0095   G4coutDestination* ref_masterOut = nullptr;
0096   G4bool masterDestinationFlag     = true;
0097   G4bool masterDestinationFmtFlag  = true;
0098 
0099   const G4int id;
0100   G4bool useBuffer  = false;
0101   G4bool ignoreCout = false;
0102   G4bool ignoreInit = true;
0103 
0104   G4String prefix          = "G4WT";
0105   G4StateManager* stateMgr = nullptr;
0106 };
0107 
0108 #endif