Import Geant4 11.0.0 source tree
This commit is contained in:
committed by
Ben Morgan
parent
6399a014b6
commit
80e2389dd8
@@ -29,66 +29,33 @@
|
||||
#include "G4CsvAnalysisManager.hh"
|
||||
#include "G4CsvFileManager.hh"
|
||||
#include "G4CsvNtupleFileManager.hh"
|
||||
#include "G4AnalysisVerbose.hh"
|
||||
#include "G4AnalysisManagerState.hh"
|
||||
#include "G4AnalysisUtilities.hh"
|
||||
#include "G4UnitsTable.hh"
|
||||
#include "G4ThreadLocalSingleton.hh"
|
||||
#include "G4Threading.hh"
|
||||
#include "G4AutoLock.hh"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
// mutex in a file scope
|
||||
|
||||
namespace {
|
||||
//Mutex to lock master manager when merging H1 histograms
|
||||
G4Mutex mergeH1Mutex = G4MUTEX_INITIALIZER;
|
||||
//Mutex to lock master manager when merging H1 histograms
|
||||
G4Mutex mergeH2Mutex = G4MUTEX_INITIALIZER;
|
||||
//Mutex to lock master manager when merging H1 histograms
|
||||
G4Mutex mergeH3Mutex = G4MUTEX_INITIALIZER;
|
||||
//Mutex to lock master manager when merging P1 profiles
|
||||
G4Mutex mergeP1Mutex = G4MUTEX_INITIALIZER;
|
||||
//Mutex to lock master manager when merging P2 profiles
|
||||
G4Mutex mergeP2Mutex = G4MUTEX_INITIALIZER;
|
||||
}
|
||||
|
||||
G4CsvAnalysisManager* G4CsvAnalysisManager::fgMasterInstance = nullptr;
|
||||
G4ThreadLocal G4CsvAnalysisManager* G4CsvAnalysisManager::fgInstance = nullptr;
|
||||
using namespace G4Analysis;
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4CsvAnalysisManager* G4CsvAnalysisManager::Instance()
|
||||
{
|
||||
if ( fgInstance == nullptr ) {
|
||||
G4bool isMaster = ! G4Threading::IsWorkerThread();
|
||||
fgInstance = new G4CsvAnalysisManager(isMaster);
|
||||
}
|
||||
|
||||
return fgInstance;
|
||||
static G4ThreadLocalSingleton<G4CsvAnalysisManager> instance;
|
||||
fgIsInstance = true;
|
||||
return instance.Instance();
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4CsvAnalysisManager::IsInstance()
|
||||
{
|
||||
return ( fgInstance != 0 );
|
||||
}
|
||||
return fgIsInstance;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4CsvAnalysisManager::G4CsvAnalysisManager(G4bool isMaster)
|
||||
: G4ToolsAnalysisManager("Csv", isMaster),
|
||||
fFileManager(nullptr),
|
||||
fNtupleFileManager(nullptr)
|
||||
G4CsvAnalysisManager::G4CsvAnalysisManager()
|
||||
: G4ToolsAnalysisManager("Csv")
|
||||
{
|
||||
if ( ( isMaster && fgMasterInstance ) || ( fgInstance ) ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " "
|
||||
<< "G4CsvAnalysisManager already exists."
|
||||
<< "Cannot create another instance.";
|
||||
G4Exception("G4CsvAnalysisManager::G4CsvAnalysisManager()",
|
||||
"Analysis_F001", FatalException, description);
|
||||
}
|
||||
|
||||
if ( isMaster ) fgMasterInstance = this;
|
||||
fgInstance = this;
|
||||
if ( ! G4Threading::IsWorkerThread() ) fgMasterInstance = this;
|
||||
|
||||
// File Manager
|
||||
fFileManager = std::make_shared<G4CsvFileManager>(fState);
|
||||
@@ -102,151 +69,15 @@ G4CsvAnalysisManager::G4CsvAnalysisManager(G4bool isMaster)
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4CsvAnalysisManager::~G4CsvAnalysisManager()
|
||||
{
|
||||
{
|
||||
if ( fState.GetIsMaster() ) fgMasterInstance = nullptr;
|
||||
fgInstance = nullptr;
|
||||
fgIsInstance = false;
|
||||
}
|
||||
|
||||
//
|
||||
// private methods
|
||||
//
|
||||
// protected methods
|
||||
//
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4CsvAnalysisManager::WriteH1()
|
||||
{
|
||||
auto h1Vector = fH1Manager->GetH1Vector();
|
||||
auto hnVector = fH1Manager->GetHnVector();
|
||||
|
||||
if ( ! h1Vector.size() ) return true;
|
||||
|
||||
auto result = true;
|
||||
|
||||
if ( ! G4Threading::IsWorkerThread() ) {
|
||||
result = WriteT(h1Vector, hnVector, "h1");
|
||||
}
|
||||
else {
|
||||
// The worker manager just adds its histograms to the master
|
||||
// This operation needs a lock
|
||||
G4AutoLock lH1(&mergeH1Mutex);
|
||||
fgMasterInstance->fH1Manager->AddH1Vector(h1Vector);
|
||||
lH1.unlock();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4CsvAnalysisManager::WriteH2()
|
||||
{
|
||||
auto h2Vector = fH2Manager->GetH2Vector();
|
||||
auto hnVector = fH2Manager->GetHnVector();
|
||||
|
||||
if ( ! h2Vector.size() ) return true;
|
||||
|
||||
auto result = true;
|
||||
|
||||
if ( ! G4Threading::IsWorkerThread() ) {
|
||||
result = WriteT(h2Vector, hnVector, "h2");
|
||||
}
|
||||
else {
|
||||
// The worker manager just adds its histograms to the master
|
||||
// This operation needs a lock
|
||||
G4AutoLock lH2(&mergeH2Mutex);
|
||||
fgMasterInstance->fH2Manager->AddH2Vector(h2Vector);
|
||||
lH2.unlock();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4CsvAnalysisManager::WriteH3()
|
||||
{
|
||||
auto h3Vector = fH3Manager->GetH3Vector();
|
||||
auto hnVector = fH3Manager->GetHnVector();
|
||||
|
||||
if ( ! h3Vector.size() ) return true;
|
||||
|
||||
auto result = true;
|
||||
|
||||
if ( ! G4Threading::IsWorkerThread() ) {
|
||||
result = WriteT(h3Vector, hnVector, "h3");
|
||||
}
|
||||
else {
|
||||
// The worker manager just adds its histograms to the master
|
||||
// This operation needs a lock
|
||||
G4AutoLock lH3(&mergeH3Mutex);
|
||||
fgMasterInstance->fH3Manager->AddH3Vector(h3Vector);
|
||||
lH3.unlock();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4CsvAnalysisManager::WriteP1()
|
||||
{
|
||||
auto p1Vector = fP1Manager->GetP1Vector();
|
||||
auto hnVector = fP1Manager->GetHnVector();
|
||||
|
||||
if ( ! p1Vector.size() ) return true;
|
||||
|
||||
auto result = true;
|
||||
|
||||
if ( ! G4Threading::IsWorkerThread() ) {
|
||||
result = WriteT(p1Vector, hnVector, "p1");
|
||||
}
|
||||
else {
|
||||
// The worker manager just adds its profiles to the master
|
||||
// This operation needs a lock
|
||||
G4AutoLock lP1(&mergeP1Mutex);
|
||||
fgMasterInstance->fP1Manager->AddP1Vector(p1Vector);
|
||||
lP1.unlock();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4CsvAnalysisManager::WriteP2()
|
||||
{
|
||||
auto p2Vector = fP2Manager->GetP2Vector();
|
||||
auto hnVector = fP2Manager->GetHnVector();
|
||||
|
||||
if ( ! p2Vector.size() ) return true;
|
||||
|
||||
auto result = true;
|
||||
|
||||
if ( ! G4Threading::IsWorkerThread() ) {
|
||||
result = WriteT(p2Vector, hnVector, "p2");
|
||||
}
|
||||
else {
|
||||
// The worker manager just adds its profiles to the master
|
||||
// This operation needs a lock
|
||||
G4AutoLock lP2(&mergeP2Mutex);
|
||||
fgMasterInstance->fP2Manager->AddP2Vector(p2Vector);
|
||||
lP2.unlock();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4CsvAnalysisManager::Reset()
|
||||
{
|
||||
// Reset histograms and ntuple
|
||||
|
||||
auto finalResult = true;
|
||||
|
||||
auto result = G4ToolsAnalysisManager::Reset();
|
||||
finalResult = finalResult && result;
|
||||
|
||||
result = fNtupleFileManager->Reset();
|
||||
finalResult = finalResult && result;
|
||||
|
||||
return finalResult;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4CsvAnalysisManager::OpenFileImpl(const G4String& fileName)
|
||||
{
|
||||
@@ -254,80 +85,43 @@ G4bool G4CsvAnalysisManager::OpenFileImpl(const G4String& fileName)
|
||||
// and set it to base class which takes then their ownership
|
||||
SetNtupleManager(fNtupleFileManager->CreateNtupleManager());
|
||||
|
||||
auto finalResult = true;
|
||||
auto result = true;
|
||||
|
||||
// Save file name in file manager
|
||||
auto result = fFileManager->OpenFile(fileName);
|
||||
finalResult = finalResult && result;
|
||||
result &= fFileManager->OpenFile(fileName);
|
||||
|
||||
// Open ntuple files and create ntuples from bookings
|
||||
result = fNtupleFileManager->ActionAtOpenFile(fFileManager->GetFullFileName());
|
||||
finalResult = finalResult && result;
|
||||
result &= fNtupleFileManager->ActionAtOpenFile(fFileManager->GetFullFileName());
|
||||
|
||||
return finalResult;
|
||||
return result;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4CsvAnalysisManager::WriteImpl()
|
||||
G4bool G4CsvAnalysisManager::WriteImpl()
|
||||
{
|
||||
// nothing to be done for Csv file
|
||||
auto finalResult = true;
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() ) {
|
||||
fState.GetVerboseL4()->Message("write", "files", "");
|
||||
auto result = true;
|
||||
|
||||
Message(kVL4, "write", "files");
|
||||
|
||||
if ( G4Threading::IsWorkerThread() ) {
|
||||
result &= G4ToolsAnalysisManager::Merge();
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
if ( ! fgMasterInstance &&
|
||||
( ( ! fH1Manager->IsEmpty() ) || ( ! fH2Manager->IsEmpty() ) ||
|
||||
( ! fH3Manager->IsEmpty() ) || ( ! fP1Manager->IsEmpty() ) ||
|
||||
( ! fP2Manager->IsEmpty() ) ) ) {
|
||||
|
||||
G4ExceptionDescription description;
|
||||
description
|
||||
<< " " << "No master G4CsvAnalysisManager instance exists."
|
||||
<< G4endl
|
||||
<< " " << "Histogram data will not be merged.";
|
||||
G4Exception("G4CsvAnalysisManager::Write()",
|
||||
"Analysis_W031", JustWarning, description);
|
||||
else {
|
||||
// Write all histograms/profile on master
|
||||
result &= G4ToolsAnalysisManager::WriteImpl();
|
||||
}
|
||||
|
||||
// H1
|
||||
auto result = WriteH1();
|
||||
finalResult = finalResult && result;
|
||||
|
||||
// H2
|
||||
result = WriteH2();
|
||||
finalResult = finalResult && result;
|
||||
|
||||
// H3
|
||||
result = WriteH3();
|
||||
finalResult = finalResult && result;
|
||||
|
||||
// P1
|
||||
result = WriteP1();
|
||||
finalResult = finalResult && result;
|
||||
|
||||
// P2
|
||||
result = WriteP2();
|
||||
finalResult = finalResult && result;
|
||||
|
||||
// Ntuples
|
||||
// Nothing to be done
|
||||
|
||||
// Write ASCII if activated
|
||||
// Not available
|
||||
// Not available
|
||||
//if ( IsAscii() ) {
|
||||
// result = WriteAscii();
|
||||
//}
|
||||
// result &= WriteAscii();
|
||||
//}
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL2() ) {
|
||||
fState.GetVerboseL2()->Message("write", "files", "", finalResult);
|
||||
}
|
||||
#endif
|
||||
Message(kVL3, "write", "files", "", result);
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -335,29 +129,38 @@ G4bool G4CsvAnalysisManager::WriteImpl()
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4CsvAnalysisManager::CloseFileImpl(G4bool reset)
|
||||
{
|
||||
auto finalResult = true;
|
||||
auto result = true;
|
||||
|
||||
// close open files
|
||||
auto result = fFileManager->CloseFiles();
|
||||
finalResult = finalResult && result;
|
||||
|
||||
result &= fFileManager->CloseFiles();
|
||||
|
||||
// Histogram and profile files are created/closed indivudually for each
|
||||
// object in WriteHn{Pn] function
|
||||
|
||||
result = fNtupleFileManager->ActionAtCloseFile(reset);
|
||||
finalResult = finalResult && result;
|
||||
// object in WriteT function
|
||||
|
||||
result &= fNtupleFileManager->ActionAtCloseFile(reset);
|
||||
|
||||
// Reset data
|
||||
if ( reset ) {
|
||||
result = Reset();
|
||||
if ( ! result ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " " << "Resetting data failed";
|
||||
G4Exception("G4CsvAnalysisManager::CloseFile()",
|
||||
"Analysis_W021", JustWarning, description);
|
||||
Warn("Resetting data failed", fkClass, "CloseFileImpl");
|
||||
}
|
||||
}
|
||||
finalResult = finalResult && result;
|
||||
|
||||
return finalResult;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4CsvAnalysisManager::ResetImpl()
|
||||
{
|
||||
// Reset histograms and ntuple
|
||||
|
||||
auto result = true;
|
||||
|
||||
result &= G4ToolsAnalysisManager::ResetImpl();
|
||||
if ( fNtupleFileManager != nullptr ) {
|
||||
result &= fNtupleFileManager->Reset();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user