Import Geant4 10.4.0.beta source tree

This commit is contained in:
Gabriele Cosmo
2017-06-30 10:49:55 +02:00
parent 3a5407696b
commit 1a1316fea4
2180 changed files with 237880 additions and 59109 deletions
@@ -0,0 +1,86 @@
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
//
// $Id: G4BuffercoutDestination.hh 103582 2017-04-18 17:24:45Z adotti $
//
//
// --------------------------------------------------------------------
// GEANT 4 class header file
//
// Class Description:
//
// A cout destination that buffers received stream in a buffer and
// dumps the buffer only when full.
// Optionally allows for an infinite buffer.
// ---------------- G4BuffercoutDestination ----------------
//
// Author: A.Dotti (SLAC), April 2017
// --------------------------------------------------------------------
#ifndef G4BUFFERCOUTDESTINATION_HH_
#define G4BUFFERCOUTDESTINATION_HH_
#include <sstream>
#include "G4coutDestination.hh"
class G4BuffercoutDestination : public G4coutDestination
{
public:
explicit G4BuffercoutDestination(size_t maxSize = 0);
virtual ~G4BuffercoutDestination();
virtual G4int ReceiveG4cout(const G4String& msg) override;
virtual G4int ReceiveG4cerr(const G4String& msg) override;
// Flush buffer to std output
virtual G4int FlushG4cout();
// Flush buffer to std error
virtual G4int FlushG4cerr();
// Flsuh both buffers
virtual void Finalize();
// Set maximum size of buffer, when buffer grows to specified size,
// it will trigger flush. Dimension in char
void SetMaxSize(size_t max) { m_maxSize = max; }
size_t GetMaxSize() const { return m_maxSize; }
size_t GetCurrentSizeOut() const { return m_currentSize_out; }
size_t GetCurrentSizeErr() const { return m_currentSize_err; }
protected:
void ResetCout();
void ResetCerr();
std::ostringstream m_buffer_out;
std::ostringstream m_buffer_err;
size_t m_currentSize_out;
size_t m_currentSize_err;
size_t m_maxSize;
};
#endif /* G4BUFFERCOUTDESTINATION_HH_ */
@@ -0,0 +1,74 @@
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
//
// $Id: G4FilecoutDestination.hh 103582 2017-04-18 17:24:45Z adotti $
//
//
// --------------------------------------------------------------------
// GEANT 4 class header file
//
// Class Description:
//
// Implements a cout destination to a file.
// ---------------- G4FilecoutDestination ----------------
//
// Author: A.Dotti (SLAC), April 2017
// --------------------------------------------------------------------
#ifndef G4FILECOUTDESTINATION_HH_
#define G4FILECOUTDESTINATION_HH_
#include <fstream>
#include <memory>
#include "G4coutDestination.hh"
class G4FilecoutDestination : public G4coutDestination
{
public:
explicit G4FilecoutDestination(const G4String& fname ,
std::ios_base::openmode mode = std::ios_base::app )
: m_name(fname), m_mode(mode), m_output(nullptr) {}
virtual ~G4FilecoutDestination();
void SetFileName(const G4String& fname) { m_name = fname; }
void Open(std::ios_base::openmode mode=std::ios_base::app);
// By default append to existing file
void Close();
virtual G4int ReceiveG4cout(const G4String& msg) override;
virtual G4int ReceiveG4cerr(const G4String& msg) override;
private:
G4String m_name;
std::ios_base::openmode m_mode;
std::unique_ptr<std::ofstream> m_output;
};
#endif /* G4FILECOUTDESTINATION_HH_ */
@@ -0,0 +1,57 @@
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
//
// $Id: G4LockcoutDestination.hh 103582 2017-04-18 17:24:45Z adotti $
//
//
// --------------------------------------------------------------------
// GEANT 4 class header file
//
// Class Description:
//
// Implements a output destination to std::cout / std::cerr with a
// mutex lock access to the shared resource.
// ---------------- G4LockcoutDestination ----------------
//
// Author: A.Dotti (SLAC), April 2017
// --------------------------------------------------------------------
#ifndef G4LOCKCOUTDESTINATION_HH_
#define G4LOCKCOUTDESTINATION_HH_
#include "G4coutDestination.hh"
class G4LockcoutDestination : public G4coutDestination
{
public:
G4LockcoutDestination() = default;
virtual ~G4LockcoutDestination();
virtual G4int ReceiveG4cout(const G4String& msg) override;
virtual G4int ReceiveG4cerr(const G4String& msg) override;
};
#endif /* G4LOCKCOUTDESTINATION_HH_ */
@@ -36,58 +36,80 @@
#ifndef G4MTcoutDestination_H
#define G4MTcoutDestination_H
#include "globals.hh"
#include "G4coutDestination.hh"
#include <iostream>
#include <sstream>
#include <fstream>
class G4MTcoutDestination : public G4coutDestination
#include "globals.hh"
#include "G4MulticoutDestination.hh"
#include "G4StateManager.hh"
class G4LockcoutDestination;
class G4MTcoutDestination : public G4MulticoutDestination
{
public:
G4MTcoutDestination(const G4int& threadId,
std::ostream& co=std::cout, std::ostream& ce=std::cerr);
virtual ~G4MTcoutDestination();
explicit G4MTcoutDestination(const G4int& threadId);
virtual ~G4MTcoutDestination();
virtual G4int ReceiveG4cout(const G4String&);
virtual G4int ReceiveG4cerr(const G4String&);
virtual void Reset();
void SetDefaultOutput( G4bool addMasterDestination = true ,
G4bool formatAlsoMaster = true );
void SetCoutFileName(const G4String& fileN = "G4cout.txt",
G4bool ifAppend = true);
void AddCoutFileName(const G4String& fileN = "G4cout.txt",
G4bool ifAppend = true);
void SetCerrFileName(const G4String& fileN = "G4cerr.txt",
G4bool ifAppend = true);
void AddCerrFileName(const G4String& fileN = "G4cerr.txt",
G4bool ifAppend = true);
void EnableBuffering(G4bool flag=true);
inline void SetPrefixString(const G4String& wd = "G4WT") { prefix = wd; }
void SetCoutFileName(const G4String& fileN = "G4cout.txt", G4bool ifAppend = true);
void SetCerrFileName(const G4String& fileN = "G4cerr.txt", G4bool ifAppend = true);
void EnableBuffering(G4bool flag=true);
void SetPrefixString(const G4String& wd = "G4WT");
void SetIgnoreCout(G4int tid = 0);
void SetIgnoreInit(G4bool val=true) { ignoreInit = val; }
G4String GetPrefixString() const { return prefix; }
G4String GetFullPrefixString() const {
inline void SetIgnoreInit(G4bool val=true) { ignoreInit = val; }
inline G4String GetPrefixString() const { return prefix; }
inline G4String GetFullPrefixString() const
{
std::stringstream os;
os<<prefix<<id;
return os.str();
}
protected:
void AddMasterOutput( G4bool formatAlsoMaster);
void HandleFileCout( G4String fileN, G4bool appendFlag,
G4bool suppressDefault);
void HandleFileCerr( G4String fileN, G4bool appendFlag,
G4bool suppressDefault);
private:
void CloseCoutFile();
void CloseCerrFile();
void DumpBuffer();
void DumpBuffer();
private:
std::ostream& finalcout;
std::ostream& finalcerr;
const G4int id;
G4bool useBuffer;
G4bool threadCoutToFile;
G4bool threadCerrToFile;
G4bool ignoreCout;
G4bool ignoreInit;
// Reference to the default destination
G4coutDestination* ref_defaultOut;
// Reference to the master destination
G4coutDestination* ref_masterOut;
G4bool masterDestinationFlag;
G4bool masterDestinationFmtFlag;
const G4int id;
G4bool useBuffer;
G4bool ignoreCout;
G4bool ignoreInit;
std::ostringstream cout_buffer;
std::ostringstream cerr_buffer;
std::ofstream coutFile;
std::ofstream cerrFile;
G4String prefix;
G4StateManager* stateMgr;
};
#endif
@@ -0,0 +1,60 @@
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
//
// $Id: G4MasterForwardcoutDestination.hh 103582 2017-04-18 17:24:45Z adotti $
//
//
// --------------------------------------------------------------------
// GEANT 4 class header file
//
// Class description:
//
// This class has the simple role to forward the stream of messages
// to the master thread in a MT application.
// Master thread should implment a G4coutDestination to receive the messages.
// Messages are serialized via a Mutex.
// ---------------- G4LockcoutDestination ----------------
//
// Author: A.Dotti (SLAC), April 2017
// --------------------------------------------------------------------
#ifndef G4MASTERFORWARDCOUTDESTINATION_HH_
#define G4MASTERFORWARDCOUTDESTINATION_HH_
#include <G4coutDestination.hh>
class G4MasterForwardcoutDestination : public G4coutDestination
{
public:
G4MasterForwardcoutDestination() = default;
virtual ~G4MasterForwardcoutDestination();
virtual G4int ReceiveG4cout(const G4String& msg) override;
virtual G4int ReceiveG4cerr(const G4String& msg) override;
};
#endif /* G4MASTERFORWARDCOUTDESTINATION_HH_ */
@@ -0,0 +1,96 @@
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
//
// $Id: G4MulticoutDestination.hh 103582 2017-04-18 17:24:45Z adotti $
//
//
// --------------------------------------------------------------------
// GEANT 4 class header file
//
// G4MulticoutDestination.hh
//
// Class description:
//
// Extends G4coutDestination and allows multiple G4coutDestination objects
// to be chained in the same job.
// Note that formatters can be attached to this destination that will apply
// them before passing over the message to the child destination.
//
// Usage:
// User should create and set-up G4coutDestination objects the usual way
// these should then be added to an instance of this container class
// this class should then be added to the streaming. E.g.
// class MyCout1 : public G4coutDestination {};
// class MyCout2 : public G4coutDestination {};
// auto multi = new G4MulticoutDestination();
// multi->push_back( G4coutDestinationUPtr( new MyCout1 ) );
// multi->push_back( G4coutDestinationUPtr( new MyCout2 ) );
// G4coutbuf.SetDestination( multi ); // or G4cerrbuf
// ---------------- G4MulticoutDestination ----------------
//
// Author: A.Dotti (SLAC), April 2017
// --------------------------------------------------------------------
#ifndef G4MULTICOUTDESTINATION_HH_
#define G4MULTICOUTDESTINATION_HH_
#include <memory>
#include <vector>
#include "G4coutDestination.hh"
using G4coutDestinationUPtr = std::unique_ptr<G4coutDestination>;
using G4coutDestinationVector = std::vector<G4coutDestinationUPtr>;
class G4MulticoutDestination : public G4coutDestination,
public G4coutDestinationVector
{
public:
G4MulticoutDestination() = default;
virtual ~G4MulticoutDestination() {}
// Forward call to contained destination. Note that the message may have
// been modified by formatters attached to this
virtual G4int ReceiveG4cout(const G4String& msg) override
{
G4bool result = true;
std::for_each( begin(), end(),
[&](G4coutDestinationUPtr& e) { result &= (e->ReceiveG4cout_(msg)==0); }
);
return ( result ? 0 : -1);
}
virtual G4int ReceiveG4cerr(const G4String& msg) override
{
G4bool result = true;
std::for_each( begin(), end(),
[&](G4coutDestinationUPtr& e) { result &= (e->ReceiveG4cerr_(msg)==0); }
);
return ( result ? 0 : -1);
}
};
#endif /* G4MULTICOUTDESTINATION_HH_ */
+1 -2
View File
@@ -24,7 +24,7 @@
// ********************************************************************
//
//
// $Id: G4String.hh 102537 2017-02-08 14:02:58Z gcosmo $
// $Id: G4String.hh 102049 2016-12-19 09:04:20Z gcosmo $
//
//
//---------------------------------------------------------------
@@ -55,7 +55,6 @@
#endif
typedef std::string::size_type str_size;
typedef std::string G4SubString;
class G4String : public std::string
{
@@ -24,7 +24,7 @@
// ********************************************************************
//
//
// $Id: G4String.icc 102536 2017-02-08 13:53:34Z gcosmo $
// $Id: G4String.icc 102049 2016-12-19 09:04:20Z gcosmo $
//
//
//---------------------------------------------------------------
@@ -23,20 +23,26 @@
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
//
// $Id:$
//
// ------------------------------------------------------------
// GEANT 4 class header file
//
// Class Description:
//
// Create and hold a pointer to Workspace.
// This class holds a thread-private static instance
// of the template parameter workspace.
//
// The concrete implementation of workspace objects
// are responsible for instantiating a singleton instance
// of this pool.
//
// Recycling of this pool can enable reuse among different
// threads in task-based - or 'on-demand' - simulation.
// Create and hold a pointer to Workspace.
//
// This class holds a thread-private static instance
// of the template parameter workspace.
//
// Note:
// The concrete implementation of workspace objects
// are responsible for instantiating a singleton instance
// of this pool.
//
// This class will be extended to recycle workspaces.
// This can enable their reuse between different threads,
// in task-based - or 'on-demand' - simulation.
// ------------------------------------------------------------
#ifndef G4TWORKSPACEPOOL_HH
#define G4TWORKSPACEPOOL_HH
@@ -47,38 +53,38 @@
template<class T>
class G4TWorkspacePool
{
public:
// For use with simple MT mode - each thread gets a workspace and uses it until end
T* CreateWorkspace();
public:
inline T* CreateWorkspace();
// For use with simple MT mode - each thread gets a workspace
// and uses it until end
void CreateAndUseWorkspace(); // Create it (as above) and use it
inline void CreateAndUseWorkspace();
// Create it (as above) and use it
inline T* FindOrCreateWorkspace();
// For use with 'dynamic' model of threading - workspaces can be recycled
T* FindOrCreateWorkspace();
// Reuse an existing workspace - or create a new one if needed.
// This will never fail, except if system is out of resources
inline T* GetWorkspace() { return fMyWorkspace; }
// Give back the existing, active workspace for my thread / task
//The recycling logic of workspace needs to be implemented
//void Recycle( T * );
// Keep the unused Workspace - for recycling : To be implemented
inline void Recycle( T * myWrkSpace );
// Keep the unused Workspace - for recycling
//void CleanUpAndDestroyAllWorkspaces();
inline void CleanUpAndDestroyAllWorkspaces();
// To be called once at the end of the job
//void ReleaseAndDestroyWorkspace(T*);
// Destroy workspace - after releasing it
public:
public:
G4TWorkspacePool() {}
~G4TWorkspacePool() {}
private:
static G4ThreadLocal T* fMyWorkspace;
// The thread's workspace - if assigned.
private:
static G4ThreadLocal T* fMyWorkspace;
// The thread's workspace - if assigned
};
template<typename T> G4ThreadLocal T* G4TWorkspacePool<T>::fMyWorkspace=0;
@@ -87,17 +93,24 @@ template<class T>
T* G4TWorkspacePool<T>::CreateWorkspace()
{
T* wrk = 0;
if ( !fMyWorkspace ) {
if ( !fMyWorkspace )
{
wrk = new T;
if ( !wrk ) {
G4Exception("G4TWorspacePool<someType>::CreateWorkspace", "Workspace01",
FatalException, "Failed to create workspace.");
} else {
if ( !wrk )
{
G4Exception("G4TWorspacePool<someType>::CreateWorkspace",
"MemoryError", FatalException,
"Failed to create workspace.");
}
else
{
fMyWorkspace = wrk;
}
} else {
G4Exception("ParticlesWorspacePool::CreateWorkspace", "Workspace02",
FatalException,
}
else
{
G4Exception("ParticlesWorspacePool::CreateWorkspace",
"InvalidCondition", FatalException,
"Cannot create workspace twice for the same thread.");
wrk = fMyWorkspace;
}
@@ -114,7 +127,8 @@ template<class T>
T* G4TWorkspacePool<T>::FindOrCreateWorkspace()
{
T* wrk= fMyWorkspace;
if( !wrk ){
if( !wrk )
{
wrk= this->CreateWorkspace();
}
wrk->UseWorkspace();
@@ -123,4 +137,22 @@ T* G4TWorkspacePool<T>::FindOrCreateWorkspace()
return wrk;
}
#endif //G4GEOMETRYWORKSPACEPOOL_HH
template<class T>
void G4TWorkspacePool<T>::Recycle( T * myWrkSpace )
{
myWrkSpace->ReleaseWorkspace();
delete myWrkSpace;
}
template<class T>
void G4TWorkspacePool<T>::CleanUpAndDestroyAllWorkspaces()
{
if (fMyWorkspace)
{
fMyWorkspace->DestroyWorkspace();
delete fMyWorkspace;
fMyWorkspace=0;
}
}
#endif // G4TWORKSPACEPOOL_HH
@@ -139,8 +139,8 @@ G4ThreadLocalSingleton<T>::G4ThreadLocalSingleton() : G4Cache<T*>() {
template<class T>
G4ThreadLocalSingleton<T>::~G4ThreadLocalSingleton() {
G4MUTEXDESTROY(listm);
Clear();
G4MUTEXDESTROY(listm);
}
template<class T>
@@ -24,7 +24,7 @@
// ********************************************************************
//
//
// $Id: G4Tokenizer.hh 102536 2017-02-08 13:53:34Z gcosmo $
// $Id: G4Tokenizer.hh 102049 2016-12-19 09:04:20Z gcosmo $
//
//
//---------------------------------------------------------------
@@ -24,7 +24,7 @@
// ********************************************************************
//
//
// $Id: G4Version.hh 102536 2017-02-08 13:53:34Z gcosmo $
// $Id: G4Version.hh 104933 2017-06-30 08:07:44Z gcosmo $
// GEANT4 tag $Name:$
//
// Version information
@@ -46,11 +46,11 @@
// |--> patch number
#ifndef G4VERSION_NUMBER
#define G4VERSION_NUMBER 1031
#define G4VERSION_NUMBER 1040
#endif
#ifndef G4VERSION_TAG
#define G4VERSION_TAG "$Name: geant4-10-03-patch-01 $"
#define G4VERSION_TAG "$Name: geant4-10-04-beta-01 $"
#endif
// as variables
@@ -58,10 +58,10 @@
#include "G4String.hh"
#ifdef G4MULTITHREADED
static const G4String G4Version = "$Name: geant4-10-03-patch-01 [MT]$";
static const G4String G4Version = "$Name: geant4-10-04-beta-01 [MT]$";
#else
static const G4String G4Version = "$Name: geant4-10-03-patch-01 $";
static const G4String G4Version = "$Name: geant4-10-04-beta-01 $";
#endif
static const G4String G4Date = "(24-February-2017)";
static const G4String G4Date = "(30-June-2017)";
#endif
@@ -24,35 +24,78 @@
// ********************************************************************
//
//
// $Id: G4coutDestination.hh 82279 2014-06-13 14:44:00Z gcosmo $
// $Id: G4coutDestination.hh 103661 2017-04-20 14:57:11Z gcosmo $
//
//
// ---------------------------------------------------------------
// --------------------------------------------------------------------
// GEANT 4 class header file
//
// G4coutDestination.hh
//
// ---------------------------------------------------------------
// --------------------------------------------------------------------
#ifndef G4COUTDESTINATION_HH
#define G4COUTDESTINATION_HH
#include <functional>
#include <vector>
#include <algorithm>
#include <iostream>
#include "globals.hh"
class G4coutDestination
{
public:
G4coutDestination();
G4coutDestination() = default;
virtual ~G4coutDestination();
// Note: limitation on ICC for MIC cannot use 'default';
virtual G4int ReceiveG4cout(const G4String&);
virtual G4int ReceiveG4cerr(const G4String&);
protected:
//For MT: if master G4coutDestination derived
//class wants to intercept the thread outputs
//derived class should set this pointer.
//Needed for some G4UIsession like GUIs
// The type of the functions defining a transformation of the message.
// The function manipulates the input message, for example, to add a prefix:
// G4coutDestination::AddCoutTransformer(
// [](G4String& msg) -> G4bool { msg="PREFIX "+msg; return true; }
// );
// Function should return false if message should not be processed
// anymore and discarded
//
using Transformer=std::function<G4bool(G4String&)>;
void AddCoutTransformer(const Transformer& t)
{ transformersCout.push_back(t); }
void AddCoutTransformer( Transformer&& t)
{ transformersCout.push_back(t); }
void AddCerrTransformer(const Transformer& t)
{ transformersCerr.push_back(t); }
void AddCerrTransformer( Transformer&& t)
{ transformersCerr.push_back(t); }
virtual void ResetTransformers();
// Derived class implements here handling of message.
// For example, streaming on std::cout or file.
// Return 0 for success, -1 otherwise
//
virtual G4int ReceiveG4cout(const G4String& msg);
virtual G4int ReceiveG4cerr(const G4String& msg);
// Methods called by G4strbuf when need to handle a message
//
G4int ReceiveG4cout_(const G4String& msg);
// Transformers cannot remove an error message from stream
//
G4int ReceiveG4cerr_(const G4String& msg);
protected:
// For MT: if master G4coutDestination derived
// class wants to intercept the thread outputs
// derived class should set this pointer.
// Needed for some G4UIsession like GUIs
//
static G4coutDestination* masterG4coutDestination;
std::vector<Transformer> transformersCout;
std::vector<Transformer> transformersCerr;
};
#endif
@@ -0,0 +1,98 @@
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
//
// $Id: G4coutFormatters.hh 103582 2017-04-18 17:24:45Z adotti $
//
//
// --------------------------------------------------------------------
// GEANT 4 header file
//
// Class Description:
//
// Utilities to handle transformations of cout/cerr streams
// ---------------- G4coutFormatters ----------------
//
// Author: A.Dotti (SLAC), April 2017
// --------------------------------------------------------------------
#ifndef G4COUTFORMATTERS_HH
#define G4COUTFORMATTERS_HH
#include <algorithm>
#include <sstream>
#include <vector>
#include <ctime>
#include <iomanip>
#include <functional>
#include <unordered_map>
#include "G4String.hh"
#include "G4ios.hh"
#include "G4strstreambuf.hh"
namespace G4coutFormatters
{
// Static definitions of provided formatters
namespace ID
{
static const G4String SYSLOG = "syslog";
static const G4String DEFAULT= "default";
}
// A function that set ups a style for the destination
// Example for a style that set to all capital the messages
// to G4cerr:
// setupStyle_f myStyle = [](G4coutDestination* dest)->G4int {
// dest->SetCerrTransformer(
// [](G4String& msg){
// msg->toUpper();
// return true; }
// );
// };
using SetupStyle_f = std::function<G4int(G4coutDestination*)>;
using String_V=std::vector<G4String>;
// Return list of formatter names
String_V Names();
// Setup style (by name) to destination
G4int HandleStyle( G4coutDestination* dest , const G4String& style );
// Set name of the style for the master thread
void SetMasterStyle(const G4String& );
G4String GetMasterStyle();
// This function should be called in user application main function
// to setup the style just after setting up RunManager
void SetupStyleGlobally(const G4String& news);
// To be used by user to register by name a new formatter.
// So it can be used via one of the previous functions
void RegisterNewStyle( const G4String& name , SetupStyle_f& formatter);
}
#endif // G4COUTFORMATTERS_HH
@@ -24,7 +24,8 @@
// ********************************************************************
//
//
// $Id: G4strstreambuf.hh 67970 2013-03-13 10:10:06Z gcosmo $
// $Id: G4strstreambuf.hh 103661 2017-04-20 14:57:11Z gcosmo $
//
// ====================================================================
//
// G4strstreambuf
@@ -33,9 +34,10 @@
#ifndef G4_STR_STREAM_BUF_HH
#define G4_STR_STREAM_BUF_HH
#include <streambuf>
#include "globals.hh"
#include "G4coutDestination.hh"
#include <streambuf>
class G4strstreambuf;
@@ -68,6 +70,7 @@ class G4strstreambuf : public std::basic_streambuf<char>
#endif
void SetDestination(G4coutDestination* dest);
inline G4coutDestination* GetDestination() const;
inline G4int ReceiveString ();
private:
@@ -84,4 +87,3 @@ class G4strstreambuf : public std::basic_streambuf<char>
#include "G4strstreambuf.icc"
#endif
@@ -24,7 +24,7 @@
// ********************************************************************
//
//
// $Id: G4strstreambuf.icc 67970 2013-03-13 10:10:06Z gcosmo $
// $Id: G4strstreambuf.icc 103661 2017-04-20 14:57:11Z gcosmo $
// ====================================================================
// G4strstreambuf.icc
//
@@ -119,6 +119,13 @@ inline void G4strstreambuf::SetDestination(G4coutDestination* dest)
destination= dest;
}
///////////////////////////////////////////////////////////////////
inline G4coutDestination* G4strstreambuf::GetDestination() const
{
return destination;
}
///////////////////////////////////////////////////////////////////
/////////////////////////////////////////////
inline G4int G4strstreambuf::ReceiveString ()
@@ -127,21 +134,24 @@ inline G4int G4strstreambuf::ReceiveString ()
G4String stringToSend(buffer);
G4int result= 0;
if(this == &G4coutbuf && destination != 0) {
result= destination-> ReceiveG4cout(stringToSend);
} else if(this == &G4cerrbuf && destination != 0) {
result= destination-> ReceiveG4cerr(stringToSend);
} else if(this == &G4coutbuf && destination == 0) {
if(this == &G4coutbuf && destination != 0)
{
result= destination-> ReceiveG4cout_(stringToSend);
}
else if(this == &G4cerrbuf && destination != 0)
{
result= destination-> ReceiveG4cerr_(stringToSend);
}
else if(this == &G4coutbuf && destination == 0)
{
std::cout << stringToSend << std::flush;
result= 0;
} else if(this == &G4cerrbuf && destination == 0) {
}
else if(this == &G4cerrbuf && destination == 0)
{
std::cerr << stringToSend << std::flush;
result= 0;
}
return result;
}
+1 -13
View File
@@ -24,7 +24,7 @@
// ********************************************************************
//
//
// $Id: templates.hh 67970 2013-03-13 10:10:06Z gcosmo $
// $Id: templates.hh 103661 2017-04-20 14:57:11Z gcosmo $
//
//
// -*- C++ -*-
@@ -148,18 +148,6 @@ inline T sqr(const T& x)
}
#endif
#ifdef G4_ABS_DEFINED
#ifdef abs
#undef abs
#endif
template <class T>
inline T std::abs(const T& a)
{
return a < 0 ? -a : a;
}
#endif
inline int G4lrint(double ad)
{
return (ad>0) ? static_cast<int>(ad+.5) : static_cast<int>(ad-.5);
+1 -1
View File
@@ -44,7 +44,7 @@
# define G4ThreadLocal __thread
#endif
#elif ( (defined(__linux__) || defined(__MACH__)) && \
!defined(__INTEL_COMPILER) && defined(__GNUC__) && (__GNUC__>=4 && __GNUC_MINOR__<9) || __GNUC__>=5 )
!defined(__INTEL_COMPILER) && defined(__GNUC__) && (__GNUC__>=4 && __GNUC_MINOR__<9))
#if defined (G4USE_STD11)
# define G4ThreadLocalStatic static __thread
# define G4ThreadLocal thread_local