Import Geant4 11.3.0.beta source tree
This commit is contained in:
@@ -27,10 +27,11 @@
|
||||
// Author: Ivana Hrivnacova, 21/11/2018 (ivana@ipno.in2p3.fr)
|
||||
|
||||
#include "G4RootMpiAnalysisManager.hh"
|
||||
|
||||
#include "G4AnalysisUtilities.hh"
|
||||
#include "G4RootMpiNtupleFileManager.hh"
|
||||
#include "G4RootMpiNtupleManager.hh"
|
||||
#include "G4RootMpiPNtupleManager.hh"
|
||||
#include "G4AnalysisUtilities.hh"
|
||||
|
||||
#include <tools/impi>
|
||||
|
||||
@@ -43,8 +44,7 @@ G4RootMpiAnalysisManager* G4RootMpiAnalysisManager::Instance()
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4RootMpiAnalysisManager::G4RootMpiAnalysisManager(G4bool /*isMaster*/)
|
||||
: G4RootAnalysisManager()
|
||||
G4RootMpiAnalysisManager::G4RootMpiAnalysisManager(G4bool /*isMaster*/) : G4RootAnalysisManager()
|
||||
{
|
||||
fgInstance = this;
|
||||
|
||||
@@ -69,9 +69,8 @@ G4RootMpiAnalysisManager::~G4RootMpiAnalysisManager()
|
||||
//
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void G4RootMpiAnalysisManager::SetMpiNtupleMerging(tools::impi* impi,
|
||||
G4int mpiRank, G4int mpiSize,
|
||||
G4int nofNtupleFiles)
|
||||
void G4RootMpiAnalysisManager::SetMpiNtupleMerging(tools::impi* impi, G4int mpiRank, G4int mpiSize,
|
||||
G4int nofNtupleFiles)
|
||||
{
|
||||
// G4cout << "SetMpiNtupleMerging: "
|
||||
// << impi << ", "
|
||||
@@ -83,20 +82,20 @@ void G4RootMpiAnalysisManager::SetMpiNtupleMerging(tools::impi* impi,
|
||||
->SetMpiNtupleMerging(impi, mpiRank, mpiSize, nofNtupleFiles);
|
||||
}
|
||||
|
||||
//
|
||||
//
|
||||
// protected methods
|
||||
//
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4RootMpiAnalysisManager::OpenFileImpl(const G4String& fileName)
|
||||
{
|
||||
if ( fNtupleFileManager->GetMergeMode() == G4NtupleMergeMode::kNone ) {
|
||||
if (fNtupleFileManager->GetMergeMode() == G4NtupleMergeMode::kNone) {
|
||||
return G4ToolsAnalysisManager::OpenFileImpl(fileName);
|
||||
}
|
||||
|
||||
// Create ntuple manager(s)
|
||||
// and set it to base class which takes then their ownership
|
||||
if ( ! fVNtupleManager ) {
|
||||
if (!fVNtupleManager) {
|
||||
SetNtupleManager(fNtupleFileManager->CreateNtupleManager());
|
||||
}
|
||||
|
||||
@@ -110,12 +109,11 @@ G4bool G4RootMpiAnalysisManager::OpenFileImpl(const G4String& fileName)
|
||||
result &= fNtupleFileManager->ActionAtOpenFile(fFileManager->GetFullFileName());
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4RootMpiAnalysisManager::WriteImpl()
|
||||
G4bool G4RootMpiAnalysisManager::WriteImpl()
|
||||
{
|
||||
|
||||
auto result = true;
|
||||
|
||||
// Call base class method
|
||||
@@ -123,7 +121,7 @@ G4bool G4RootMpiAnalysisManager::WriteImpl()
|
||||
|
||||
// Write file also on Slave
|
||||
// (skipped in base class)
|
||||
if ( fNtupleFileManager->GetMergeMode() == G4NtupleMergeMode::kSlave ) {
|
||||
if (fNtupleFileManager->GetMergeMode() == G4NtupleMergeMode::kSlave) {
|
||||
// write all open files
|
||||
result &= fFileManager->WriteFiles();
|
||||
}
|
||||
@@ -136,8 +134,8 @@ G4bool G4RootMpiAnalysisManager::WriteImpl()
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4RootMpiAnalysisManager::CloseFileImpl(G4bool reset)
|
||||
{
|
||||
// Cannot call base class function, as we need to close files also
|
||||
// on slave; an option in the base class can be added for this in future
|
||||
// Cannot call base class function, as we need to close files also
|
||||
// on slave; an option in the base class can be added for this in future
|
||||
|
||||
Message(kVL4, "close", "files");
|
||||
|
||||
@@ -150,21 +148,21 @@ G4bool G4RootMpiAnalysisManager::CloseFileImpl(G4bool reset)
|
||||
// - the conditoon used in the base class is commented out
|
||||
// if ( (fVNtupleFileManager == nullptr) ||
|
||||
// (fVNtupleFileManager->GetMergeMode() != G4NtupleMergeMode::kSlave) ) {
|
||||
if ( ! fVFileManager->CloseFiles() ) {
|
||||
Warn("Closing files failed", fkClass, "CloseFileImpl");
|
||||
result = false;
|
||||
}
|
||||
if (!fVFileManager->CloseFiles()) {
|
||||
Warn("Closing files failed", fkClass, "CloseFileImpl");
|
||||
result = false;
|
||||
}
|
||||
// }
|
||||
|
||||
// delete empty files
|
||||
if ( ! fVFileManager->DeleteEmptyFiles() ) {
|
||||
if (!fVFileManager->DeleteEmptyFiles()) {
|
||||
Warn("Deleting empty files failed", fkClass, "CloseFileImpl");
|
||||
result = false;
|
||||
}
|
||||
|
||||
// reset histograms
|
||||
if ( reset ) {
|
||||
if ( ! Reset() ) {
|
||||
if (reset) {
|
||||
if (!Reset()) {
|
||||
Warn("Resetting data failed", fkClass, "CloseFileImpl");
|
||||
result = false;
|
||||
}
|
||||
|
||||
@@ -27,9 +27,10 @@
|
||||
// Author: Ivana Hrivnacova, 21/11/2018 (ivana@ipno.in2p3.fr)
|
||||
|
||||
#include "G4RootMpiNtupleFileManager.hh"
|
||||
|
||||
#include "G4AnalysisUtilities.hh"
|
||||
#include "G4RootMpiNtupleManager.hh"
|
||||
#include "G4RootMpiPNtupleManager.hh"
|
||||
#include "G4AnalysisUtilities.hh"
|
||||
|
||||
#include <tools/impi>
|
||||
|
||||
@@ -38,58 +39,56 @@ using std::make_shared;
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4RootMpiNtupleFileManager::G4RootMpiNtupleFileManager(const G4AnalysisManagerState& state)
|
||||
: G4RootNtupleFileManager(state),
|
||||
fImpi(nullptr),
|
||||
fMpiRank(-1),
|
||||
fMpiSize(0),
|
||||
fMpiSlaveNtupleManager(nullptr),
|
||||
fNtupleBooked(false)
|
||||
: G4RootNtupleFileManager(state),
|
||||
fImpi(nullptr),
|
||||
fMpiRank(-1),
|
||||
fMpiSize(0),
|
||||
fMpiSlaveNtupleManager(nullptr),
|
||||
fNtupleBooked(false)
|
||||
{}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4RootMpiNtupleFileManager::~G4RootMpiNtupleFileManager()
|
||||
{}
|
||||
G4RootMpiNtupleFileManager::~G4RootMpiNtupleFileManager() {}
|
||||
|
||||
//
|
||||
//
|
||||
// private methods
|
||||
//
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void G4RootMpiNtupleFileManager::SetMpiNtupleMergingMode(
|
||||
G4int nofNtupleFiles)
|
||||
void G4RootMpiNtupleFileManager::SetMpiNtupleMergingMode(G4int nofNtupleFiles)
|
||||
{
|
||||
Message(kVL2, "set", "mpi ntuple merging mode");
|
||||
|
||||
auto canMerge = true;
|
||||
|
||||
// Illegal situations
|
||||
if ( fMpiSize < 2 ) {
|
||||
if (fMpiSize < 2) {
|
||||
G4ExceptionDescription description;
|
||||
description
|
||||
<< "Merging ntuples is not applicable on a single rank." << G4endl
|
||||
<< "Setting was ignored.";
|
||||
G4Exception("G4RootMpiNtupleFileManager::SetMpiNtupleMergingMode()",
|
||||
"Analysis_W013", JustWarning, description);
|
||||
canMerge = false;
|
||||
description << "Merging ntuples is not applicable on a single rank." << G4endl
|
||||
<< "Setting was ignored.";
|
||||
G4Exception("G4RootMpiNtupleFileManager::SetMpiNtupleMergingMode()", "Analysis_W013",
|
||||
JustWarning, description);
|
||||
canMerge = false;
|
||||
}
|
||||
|
||||
G4String mergingMode;
|
||||
if ( ! canMerge ) {
|
||||
if (!canMerge) {
|
||||
fNtupleMergeMode = G4NtupleMergeMode::kNone;
|
||||
mergingMode = "G4NtupleMergeMode::kNone";
|
||||
mergingMode = "G4NtupleMergeMode::kNone";
|
||||
}
|
||||
else {
|
||||
// Set the number of reduced ntuple files
|
||||
// (multiple output files are not yet supported)
|
||||
fNofNtupleFiles = nofNtupleFiles;
|
||||
|
||||
|
||||
// Forced merging mode
|
||||
// MPI
|
||||
if ( fMpiRank >= fMpiSize ) {
|
||||
if (fMpiRank >= fMpiSize) {
|
||||
// the extra worker
|
||||
fNtupleMergeMode = G4NtupleMergeMode::kMain;
|
||||
mergingMode = "G4NtupleMergeMode::kMain";
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
// processing worker
|
||||
fNtupleMergeMode = G4NtupleMergeMode::kSlave;
|
||||
mergingMode = "G4NtupleMergeMode::kSlave";
|
||||
@@ -99,23 +98,21 @@ void G4RootMpiNtupleFileManager::SetMpiNtupleMergingMode(
|
||||
Message(kVL1, "set", "mpi ntuple merging mode", mergingMode);
|
||||
}
|
||||
|
||||
//
|
||||
//
|
||||
// public methods
|
||||
//
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void G4RootMpiNtupleFileManager::SetMpiNtupleMerging(tools::impi* impi,
|
||||
G4int mpiRank, G4int mpiSize,
|
||||
G4int nofNtupleFiles)
|
||||
void G4RootMpiNtupleFileManager::SetMpiNtupleMerging(tools::impi* impi, G4int mpiRank,
|
||||
G4int mpiSize, G4int nofNtupleFiles)
|
||||
{
|
||||
if ( fIsInitialized ) {
|
||||
G4ExceptionDescription description;
|
||||
description
|
||||
<< "Cannot change merging mode." << G4endl
|
||||
<< "The function must be called before OpenFile().";
|
||||
G4Exception("G4RootMpiNtupleFileManager::SetMpiNtupleMerging",
|
||||
"Analysis_W013", JustWarning, description);
|
||||
return;
|
||||
if (fIsInitialized) {
|
||||
G4ExceptionDescription description;
|
||||
description << "Cannot change merging mode." << G4endl
|
||||
<< "The function must be called before OpenFile().";
|
||||
G4Exception("G4RootMpiNtupleFileManager::SetMpiNtupleMerging", "Analysis_W013", JustWarning,
|
||||
description);
|
||||
return;
|
||||
}
|
||||
|
||||
// Save MPI merging parameters
|
||||
@@ -123,7 +120,7 @@ void G4RootMpiNtupleFileManager::SetMpiNtupleMerging(tools::impi* impi,
|
||||
fMpiRank = mpiRank;
|
||||
fMpiSize = mpiSize;
|
||||
|
||||
// Set ntuple merging mode
|
||||
// Set ntuple merging mode
|
||||
SetMpiNtupleMergingMode(nofNtupleFiles);
|
||||
}
|
||||
|
||||
@@ -133,20 +130,17 @@ std::shared_ptr<G4VNtupleManager> G4RootMpiNtupleFileManager::CreateNtupleManage
|
||||
Message(kVL4, "create", "mpi ntuple manager");
|
||||
|
||||
std::shared_ptr<G4VNtupleManager> activeNtupleManager = nullptr;
|
||||
switch ( fNtupleMergeMode )
|
||||
{
|
||||
switch (fNtupleMergeMode) {
|
||||
case G4NtupleMergeMode::kNone:
|
||||
fNtupleManager
|
||||
= make_shared<G4RootNtupleManager>(fState, fBookingManager,
|
||||
0, 0, fNtupleRowWise, fNtupleRowMode);
|
||||
fNtupleManager = make_shared<G4RootNtupleManager>(fState, fBookingManager, 0, 0,
|
||||
fNtupleRowWise, fNtupleRowMode);
|
||||
fNtupleManager->SetFileManager(fFileManager);
|
||||
activeNtupleManager = fNtupleManager;
|
||||
break;
|
||||
|
||||
case G4NtupleMergeMode::kMain: {
|
||||
fNtupleManager
|
||||
= make_shared<G4RootMpiNtupleManager>(fState, fBookingManager,
|
||||
fNtupleRowWise, fNtupleRowMode, fImpi, fMpiSize);
|
||||
fNtupleManager = make_shared<G4RootMpiNtupleManager>(fState, fBookingManager, fNtupleRowWise,
|
||||
fNtupleRowMode, fImpi, fMpiSize);
|
||||
fNtupleManager->SetFileManager(fFileManager);
|
||||
activeNtupleManager = fNtupleManager;
|
||||
break;
|
||||
@@ -154,15 +148,15 @@ std::shared_ptr<G4VNtupleManager> G4RootMpiNtupleFileManager::CreateNtupleManage
|
||||
|
||||
case G4NtupleMergeMode::kSlave: {
|
||||
auto destinationRank = fMpiSize;
|
||||
fMpiSlaveNtupleManager
|
||||
= make_shared<G4RootMpiPNtupleManager>(fState, fImpi, fMpiRank, destinationRank);
|
||||
fMpiSlaveNtupleManager =
|
||||
make_shared<G4RootMpiPNtupleManager>(fState, fImpi, fMpiRank, destinationRank);
|
||||
activeNtupleManager = fMpiSlaveNtupleManager;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
G4String mergeMode;
|
||||
switch ( fNtupleMergeMode ) {
|
||||
switch (fNtupleMergeMode) {
|
||||
case G4NtupleMergeMode::kNone:
|
||||
mergeMode = "";
|
||||
break;
|
||||
@@ -184,30 +178,26 @@ std::shared_ptr<G4VNtupleManager> G4RootMpiNtupleFileManager::CreateNtupleManage
|
||||
G4bool G4RootMpiNtupleFileManager::ActionAtOpenFile(const G4String& fileName)
|
||||
{
|
||||
// No MPI merging, call base class
|
||||
if ( fNtupleMergeMode == G4NtupleMergeMode::kNone ) {
|
||||
if (fNtupleMergeMode == G4NtupleMergeMode::kNone) {
|
||||
return G4RootNtupleFileManager::ActionAtOpenFile(fileName);
|
||||
}
|
||||
|
||||
if ( ! fNtupleBooked ) {
|
||||
|
||||
if (!fNtupleBooked) {
|
||||
G4String objectType = "analysis file";
|
||||
if ( fNtupleMergeMode == G4NtupleMergeMode::kMain ) {
|
||||
if (fNtupleMergeMode == G4NtupleMergeMode::kMain) {
|
||||
objectType = "main analysis file";
|
||||
}
|
||||
Message(kVL4, "open", objectType, fileName);
|
||||
|
||||
|
||||
if ( fNtupleMergeMode == G4NtupleMergeMode::kMain ) {
|
||||
// Creating files is triggered from CreateNtuple
|
||||
fNtupleManager->CreateNtuplesFromBooking(
|
||||
fBookingManager->GetNtupleBookingVector());
|
||||
if (fNtupleMergeMode == G4NtupleMergeMode::kMain) {
|
||||
// Creating files is triggered from CreateNtuple
|
||||
fNtupleManager->CreateNtuplesFromBooking(fBookingManager->GetNtupleBookingVector());
|
||||
}
|
||||
|
||||
if ( fNtupleMergeMode == G4NtupleMergeMode::kSlave ) {
|
||||
if (fNtupleMergeMode == G4NtupleMergeMode::kSlave) {
|
||||
// G4cout << "Slave: Go to create ntuples from booking" << G4endl;
|
||||
// No file is open by Slave manager
|
||||
fMpiSlaveNtupleManager->CreateNtuplesFromBooking(
|
||||
fBookingManager->GetNtupleBookingVector());
|
||||
fMpiSlaveNtupleManager->CreateNtuplesFromBooking(fBookingManager->GetNtupleBookingVector());
|
||||
}
|
||||
|
||||
Message(kVL1, "open", objectType, fileName);
|
||||
@@ -216,29 +206,29 @@ G4bool G4RootMpiNtupleFileManager::ActionAtOpenFile(const G4String& fileName)
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4RootMpiNtupleFileManager::ActionAtWrite()
|
||||
{
|
||||
// No MPI merging, call base class
|
||||
if ( fNtupleMergeMode == G4NtupleMergeMode::kNone ) {
|
||||
if (fNtupleMergeMode == G4NtupleMergeMode::kNone) {
|
||||
return G4RootNtupleFileManager::ActionAtWrite();
|
||||
}
|
||||
|
||||
|
||||
auto result = true;
|
||||
|
||||
G4String ntupleType;
|
||||
if ( fNtupleMergeMode == G4NtupleMergeMode::kMain ) ntupleType = "main ntuples";
|
||||
if ( fNtupleMergeMode == G4NtupleMergeMode::kSlave ) ntupleType = "slave ntuples";
|
||||
if (fNtupleMergeMode == G4NtupleMergeMode::kMain) ntupleType = "main ntuples";
|
||||
if (fNtupleMergeMode == G4NtupleMergeMode::kSlave) ntupleType = "slave ntuples";
|
||||
|
||||
Message(kVL4, "merge", ntupleType);
|
||||
|
||||
if ( fNtupleMergeMode == G4NtupleMergeMode::kMain ) {
|
||||
if (fNtupleMergeMode == G4NtupleMergeMode::kMain) {
|
||||
result &= fNtupleManager->Merge();
|
||||
}
|
||||
|
||||
if ( fNtupleMergeMode == G4NtupleMergeMode::kSlave ) {
|
||||
}
|
||||
|
||||
if (fNtupleMergeMode == G4NtupleMergeMode::kSlave) {
|
||||
result &= fMpiSlaveNtupleManager->Merge();
|
||||
}
|
||||
|
||||
@@ -249,13 +239,13 @@ G4bool G4RootMpiNtupleFileManager::ActionAtWrite()
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4RootMpiNtupleFileManager::ActionAtCloseFile()
|
||||
{
|
||||
{
|
||||
// No MPI merging, call base class
|
||||
if ( fNtupleMergeMode == G4NtupleMergeMode::kNone ) {
|
||||
if (fNtupleMergeMode == G4NtupleMergeMode::kNone) {
|
||||
return G4RootNtupleFileManager::ActionAtCloseFile();
|
||||
}
|
||||
|
||||
if ( fNtupleMergeMode == G4NtupleMergeMode::kSlave) {
|
||||
if (fNtupleMergeMode == G4NtupleMergeMode::kSlave) {
|
||||
fMpiSlaveNtupleManager->SetNewCycle(false);
|
||||
return true;
|
||||
}
|
||||
@@ -266,22 +256,22 @@ G4bool G4RootMpiNtupleFileManager::ActionAtCloseFile()
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4RootMpiNtupleFileManager::Reset()
|
||||
{
|
||||
// Reset ntuples
|
||||
// Reset ntuples
|
||||
|
||||
// No MPI merging, call base class
|
||||
if ( fNtupleMergeMode == G4NtupleMergeMode::kNone ) {
|
||||
if (fNtupleMergeMode == G4NtupleMergeMode::kNone) {
|
||||
return G4RootNtupleFileManager::Reset();
|
||||
}
|
||||
|
||||
auto result = true;
|
||||
|
||||
if ( fNtupleMergeMode == G4NtupleMergeMode::kMain ) {
|
||||
result &= fNtupleManager->Reset();
|
||||
}
|
||||
|
||||
if ( fNtupleMergeMode == G4NtupleMergeMode::kSlave ) {
|
||||
auto result = true;
|
||||
|
||||
if (fNtupleMergeMode == G4NtupleMergeMode::kMain) {
|
||||
result &= fNtupleManager->Reset();
|
||||
}
|
||||
|
||||
if (fNtupleMergeMode == G4NtupleMergeMode::kSlave) {
|
||||
result &= fMpiSlaveNtupleManager->Reset();
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -27,49 +27,47 @@
|
||||
// Author: Ivana Hrivnacova, 21/11/2018 (ivana@ipno.in2p3.fr)
|
||||
|
||||
#include "G4RootMpiNtupleManager.hh"
|
||||
#include "G4RootMainNtupleManager.hh"
|
||||
#include "G4RootFileManager.hh"
|
||||
#include "G4AnalysisManagerState.hh"
|
||||
#include "G4AnalysisUtilities.hh"
|
||||
|
||||
#include "tools/wroot/file"
|
||||
#include "tools/wroot/mpi_ntuple_row_wise"
|
||||
#include "tools/wroot/mpi_ntuple_column_wise"
|
||||
#include "tools/wroot/mpi_ntuple_row_wise"
|
||||
|
||||
#include "G4AnalysisManagerState.hh"
|
||||
#include "G4AnalysisUtilities.hh"
|
||||
#include "G4RootFileManager.hh"
|
||||
#include "G4RootMainNtupleManager.hh"
|
||||
|
||||
using namespace G4Analysis;
|
||||
|
||||
const int kTAG_NTUPLE = 1004; // This constant is defined in G4MPImanager
|
||||
// (should be passed from the application)
|
||||
const int kTAG_NTUPLE = 1004; // This constant is defined in G4MPImanager
|
||||
// (should be passed from the application)
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4RootMpiNtupleManager::G4RootMpiNtupleManager(
|
||||
const G4AnalysisManagerState& state,
|
||||
std::shared_ptr<G4NtupleBookingManager> bookingManager,
|
||||
G4bool rowWise, G4bool rowMode,
|
||||
tools::impi* impi, G4int mpiSize)
|
||||
: G4RootNtupleManager(state, bookingManager, 0, 0, rowWise, rowMode),
|
||||
fImpi(impi),
|
||||
fSlaveRanks(),
|
||||
fMainRank(0)
|
||||
const G4AnalysisManagerState& state, std::shared_ptr<G4NtupleBookingManager> bookingManager,
|
||||
G4bool rowWise, G4bool rowMode, tools::impi* impi, G4int mpiSize)
|
||||
: G4RootNtupleManager(state, bookingManager, 0, 0, rowWise, rowMode),
|
||||
fImpi(impi),
|
||||
fSlaveRanks(),
|
||||
fMainRank(0)
|
||||
{
|
||||
for ( G4int rank = 0; rank < mpiSize; rank++ ) {
|
||||
for (G4int rank = 0; rank < mpiSize; rank++) {
|
||||
fSlaveRanks.push_back(rank);
|
||||
}
|
||||
fMainRank = mpiSize;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4RootMpiNtupleManager::~G4RootMpiNtupleManager()
|
||||
{}
|
||||
G4RootMpiNtupleManager::~G4RootMpiNtupleManager() {}
|
||||
|
||||
//
|
||||
//
|
||||
// private methods
|
||||
//
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4RootMpiNtupleManager::Send(G4int id, RootNtupleDescription* ntupleDescription)
|
||||
{
|
||||
// Pack and send the main ntuple data to the slave ranks
|
||||
// Pack and send the main ntuple data to the slave ranks
|
||||
|
||||
// G4cout << "Going to send main ntuple data " << G4endl;
|
||||
// G4cout << "ntupleDescription: " << ntupleDescription << G4endl;
|
||||
@@ -78,11 +76,12 @@ G4bool G4RootMpiNtupleManager::Send(G4int id, RootNtupleDescription* ntupleDescr
|
||||
// Get ntuple
|
||||
auto ntuple = ntupleDescription->GetNtuple();
|
||||
|
||||
// Get basket sizes
|
||||
// Get basket sizes
|
||||
std::vector<tools::wroot::branch*> mainBranches;
|
||||
ntuple->get_branches(mainBranches);
|
||||
std::vector<tools::uint32> basketSizes;
|
||||
tools_vforcit(tools::wroot::branch*, mainBranches, it) {
|
||||
tools_vforcit(tools::wroot::branch*, mainBranches, it)
|
||||
{
|
||||
basketSizes.push_back((*it)->basket_size());
|
||||
}
|
||||
|
||||
@@ -92,57 +91,58 @@ G4bool G4RootMpiNtupleManager::Send(G4int id, RootNtupleDescription* ntupleDescr
|
||||
tools::uint32 basketSize = fFileManager->GetBasketSize();
|
||||
unsigned int basketEntries = fFileManager->GetBasketEntries();
|
||||
|
||||
for ( auto slaveRank : fSlaveRanks ) {
|
||||
for (auto slaveRank : fSlaveRanks) {
|
||||
// G4cout << "Going to send main ntuple data to slave rank " << slaveRank << G4endl;
|
||||
|
||||
fImpi->pack_reset();
|
||||
if ( ! fImpi->pack(id)) {
|
||||
G4cerr << "pack(id) failed." << G4endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( ! fImpi->bpack(fRowWise) ) {
|
||||
G4cerr << "bpack(fRowWise) failed."<< G4endl;
|
||||
if (!fImpi->pack(id)) {
|
||||
G4cerr << "pack(id) failed." << G4endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( ! fImpi->bpack(ntupleFile->byte_swap())) {
|
||||
G4cerr << "bpack(byte_swap) failed." << G4endl;
|
||||
if (!fImpi->bpack(fRowWise)) {
|
||||
G4cerr << "bpack(fRowWise) failed." << G4endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( ! fImpi->pack(ntupleFile->compression()) ) {
|
||||
G4cerr << "pack(compression) failed." << G4endl;
|
||||
return false;
|
||||
|
||||
if (!fImpi->bpack(ntupleFile->byte_swap())) {
|
||||
G4cerr << "bpack(byte_swap) failed." << G4endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( ! fImpi->pack(ntupleFile->dir().seek_directory())) {
|
||||
|
||||
if (!fImpi->pack(ntupleFile->compression())) {
|
||||
G4cerr << "pack(compression) failed." << G4endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!fImpi->pack(ntupleFile->dir().seek_directory())) {
|
||||
// Should be used fNtupleDirectory ??
|
||||
G4cerr << "pack(seek) failed." << G4endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( fRowWise ) {
|
||||
if ( ! fImpi->pack(basketSize) ) {
|
||||
if (fRowWise) {
|
||||
if (!fImpi->pack(basketSize)) {
|
||||
G4cerr << "pack(basketSize) failed." << G4endl;
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if ( ! fImpi->bpack(fRowMode) ) {
|
||||
}
|
||||
else {
|
||||
if (!fImpi->bpack(fRowMode)) {
|
||||
G4cerr << "bpack(fRowMode) failed." << G4endl;
|
||||
return false;
|
||||
}
|
||||
if ( ! fImpi->vpack(basketSizes) ) {
|
||||
}
|
||||
if (!fImpi->vpack(basketSizes)) {
|
||||
G4cerr << "vpack(basketSizes) failed." << G4endl;
|
||||
return false;
|
||||
}
|
||||
if ( ! fImpi->pack(basketEntries) ) {
|
||||
if (!fImpi->pack(basketEntries)) {
|
||||
G4cerr << "pack(basketEntries) failed." << G4endl;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! fImpi->send_buffer(slaveRank, kTAG_NTUPLE )) {
|
||||
if (!fImpi->send_buffer(slaveRank, kTAG_NTUPLE)) {
|
||||
G4cerr << "send_buffer() failed." << G4endl;
|
||||
return false;
|
||||
}
|
||||
@@ -150,7 +150,7 @@ G4bool G4RootMpiNtupleManager::Send(G4int id, RootNtupleDescription* ntupleDescr
|
||||
|
||||
G4cout << "Sent ntuple description to slave on rank " << slaveRank << G4endl;
|
||||
}
|
||||
|
||||
|
||||
// G4cout << "Done: send main ntuple data " << G4endl;
|
||||
return true;
|
||||
}
|
||||
@@ -163,59 +163,57 @@ G4bool G4RootMpiNtupleManager::InitializeRanks()
|
||||
auto finalResult = true;
|
||||
|
||||
auto counter = 0;
|
||||
for ( auto ntupleDescription : fNtupleDescriptionVector ) {
|
||||
|
||||
// Do not create ntuple if it is inactivated
|
||||
if ( fState.GetIsActivation() && ( ! ntupleDescription->GetActivation() ) ) continue;
|
||||
for (auto ntupleDescription : fNtupleDescriptionVector) {
|
||||
// Do not create ntuple if it is inactivated
|
||||
if (fState.GetIsActivation() && (!ntupleDescription->GetActivation())) continue;
|
||||
|
||||
auto result = Send(counter++, ntupleDescription);
|
||||
finalResult = finalResult && result;
|
||||
}
|
||||
|
||||
return finalResult;
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4RootMpiNtupleManager::WaitBuffer()
|
||||
{
|
||||
// Receive the pntuple data from the slave ranks
|
||||
// For the time being only one ntuple
|
||||
// Receive the pntuple data from the slave ranks
|
||||
// For the time being only one ntuple
|
||||
|
||||
// G4cout << "G4RootMpiNtupleManager::WaitBuffer" << G4endl;
|
||||
|
||||
unsigned long numberOfEndFill = 0;
|
||||
|
||||
|
||||
G4bool verbose = IsVerbose(kVL2);
|
||||
|
||||
while ( true ) {
|
||||
while (true) {
|
||||
fImpi->pack_reset();
|
||||
|
||||
// loop until receiving end_fill from all ranks
|
||||
// G4cout << "G4RootMpiNtupleManager::WaitBuffer entering loop" << G4endl;
|
||||
int probe_src;
|
||||
if ( ! fImpi->wait_buffer(fMainRank, kTAG_NTUPLE, probe_src, verbose)) {
|
||||
if (!fImpi->wait_buffer(fMainRank, kTAG_NTUPLE, probe_src, verbose)) {
|
||||
G4cerr << "!!! wait_buffer() failed." << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
|
||||
tools::uint32 protocol;
|
||||
if ( ! fImpi->unpack(protocol)) {
|
||||
G4cerr << "unpack(protocol) failed."<< G4endl;
|
||||
if (!fImpi->unpack(protocol)) {
|
||||
G4cerr << "unpack(protocol) failed." << G4endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( protocol == tools::wroot::mpi_protocol_basket() ) {
|
||||
|
||||
if (protocol == tools::wroot::mpi_protocol_basket()) {
|
||||
// G4cout << "G4RootMpiNtupleManager::WaitBuffer got protocol_basket" << G4endl;
|
||||
|
||||
|
||||
// get ntuple Id
|
||||
tools::uint32 ntupleId;
|
||||
if ( ! fImpi->unpack(ntupleId) ) {
|
||||
G4cerr << "unpack(ntuple_id) failed."<< std::endl;
|
||||
if (!fImpi->unpack(ntupleId)) {
|
||||
G4cerr << "unpack(ntuple_id) failed." << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( ntupleId >= fNtupleVector.size() ) {
|
||||
if (ntupleId >= fNtupleVector.size()) {
|
||||
std::cerr << "!!! unknown ntupleId " << ntupleId << std::endl;
|
||||
return false;
|
||||
}
|
||||
@@ -224,24 +222,24 @@ G4bool G4RootMpiNtupleManager::WaitBuffer()
|
||||
auto mainNtuple = fNtupleVector[ntupleId];
|
||||
|
||||
// add basket to main ntuple
|
||||
if ( ! mainNtuple->mpi_add_basket(*fImpi)) {
|
||||
std::cerr << "mainNtuple->mpi_add_basket() failed." << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
if (!mainNtuple->mpi_add_basket(*fImpi)) {
|
||||
std::cerr << "mainNtuple->mpi_add_basket() failed." << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
else if ( protocol == tools::wroot::mpi_protocol_baskets() ) {
|
||||
//column_wise and row_mode only.
|
||||
}
|
||||
else if (protocol == tools::wroot::mpi_protocol_baskets()) {
|
||||
// column_wise and row_mode only.
|
||||
|
||||
// G4cout << "G4RootMpiNtupleManager::WaitBuffer got protocol_baskets" << G4endl;
|
||||
|
||||
|
||||
// get ntuple Id
|
||||
tools::uint32 ntupleId;
|
||||
if ( ! fImpi->unpack(ntupleId) ) {
|
||||
G4cerr << "unpack(ntuple_id) failed."<< std::endl;
|
||||
if (!fImpi->unpack(ntupleId)) {
|
||||
G4cerr << "unpack(ntuple_id) failed." << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( ntupleId >= fNtupleVector.size() ) {
|
||||
if (ntupleId >= fNtupleVector.size()) {
|
||||
std::cerr << "!!! unknown ntupleId " << ntupleId << std::endl;
|
||||
return false;
|
||||
}
|
||||
@@ -250,40 +248,39 @@ G4bool G4RootMpiNtupleManager::WaitBuffer()
|
||||
auto mainNtuple = fNtupleVector[ntupleId];
|
||||
|
||||
// add basket to main ntuple
|
||||
if ( ! mainNtuple->mpi_add_baskets(*fImpi)) {
|
||||
std::cerr << "mainNtuple->mpi_add_baskets() failed." << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
if (!mainNtuple->mpi_add_baskets(*fImpi)) {
|
||||
std::cerr << "mainNtuple->mpi_add_baskets() failed." << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
else if ( protocol==tools::wroot::mpi_protocol_end_fill() ) {
|
||||
|
||||
}
|
||||
else if (protocol == tools::wroot::mpi_protocol_end_fill()) {
|
||||
// G4cout << "G4RootMpiNtupleManager::WaitBuffer got protocol_end_fill" << G4endl;
|
||||
|
||||
|
||||
// get ntuple Id
|
||||
tools::uint32 ntupleId;
|
||||
if ( ! fImpi->unpack(ntupleId) ) {
|
||||
G4cerr << "unpack(ntuple_id) failed."<< std::endl;
|
||||
if (!fImpi->unpack(ntupleId)) {
|
||||
G4cerr << "unpack(ntuple_id) failed." << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( ntupleId >= fNtupleVector.size() ) {
|
||||
if (ntupleId >= fNtupleVector.size()) {
|
||||
std::cerr << "!!! unknown ntupleId " << ntupleId << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// Main ntuple
|
||||
auto mainNtuple = fNtupleVector[ntupleId];
|
||||
|
||||
// end_fill in main ntuple
|
||||
if ( ! mainNtuple->mpi_end_fill(*fImpi) ) {
|
||||
G4cerr << "main_ntuple->mpi_end_fill() failed." << std::endl;
|
||||
if (!mainNtuple->mpi_end_fill(*fImpi)) {
|
||||
G4cerr << "main_ntuple->mpi_end_fill() failed." << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
numberOfEndFill++;
|
||||
|
||||
if ( numberOfEndFill == fSlaveRanks.size() ) break;
|
||||
}
|
||||
if (numberOfEndFill == fSlaveRanks.size()) break;
|
||||
}
|
||||
else {
|
||||
G4cerr << "unknown protocol " << protocol << G4endl;
|
||||
return false;
|
||||
@@ -293,30 +290,28 @@ G4bool G4RootMpiNtupleManager::WaitBuffer()
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
//
|
||||
// public methods
|
||||
//
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void G4RootMpiNtupleManager::CreateNtuplesFromBooking(
|
||||
const std::vector<G4NtupleBooking*>& ntupleBookings)
|
||||
const std::vector<G4NtupleBooking*>& ntupleBookings)
|
||||
{
|
||||
// G4cout << "G4RootMpiNtupleManager::CreateNtuplesFromBooking()" << G4endl;
|
||||
|
||||
// Call base class method
|
||||
G4TNtupleManager<tools::wroot::ntuple,G4RootFile>::CreateNtuplesFromBooking(
|
||||
ntupleBookings);
|
||||
G4TNtupleManager<tools::wroot::ntuple, G4RootFile>::CreateNtuplesFromBooking(ntupleBookings);
|
||||
|
||||
// Initialize ranks
|
||||
if ( ! InitializeRanks() ) {
|
||||
if (!InitializeRanks()) {
|
||||
G4cerr << "InitializeRanks failed." << G4endl;
|
||||
}
|
||||
|
||||
// Go to wait buffer mode
|
||||
if ( ! WaitBuffer() ) {
|
||||
if (!WaitBuffer()) {
|
||||
G4cerr << "WaitBuffer failed." << G4endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
@@ -326,10 +321,9 @@ G4bool G4RootMpiNtupleManager::Merge()
|
||||
|
||||
auto finalResult = true;
|
||||
|
||||
for ( auto ntupleDescription : fNtupleDescriptionVector ) {
|
||||
|
||||
// Do not create ntuple if it is inactivated
|
||||
if ( fState.GetIsActivation() && ( ! ntupleDescription->GetActivation() ) ) continue;
|
||||
for (auto ntupleDescription : fNtupleDescriptionVector) {
|
||||
// Do not create ntuple if it is inactivated
|
||||
if (fState.GetIsActivation() && (!ntupleDescription->GetActivation())) continue;
|
||||
|
||||
// G4cout << "Go to call merge_number_of_entries" << G4endl;
|
||||
ntupleDescription->GetNtuple()->merge_number_of_entries();
|
||||
|
||||
@@ -27,18 +27,20 @@
|
||||
// Author: Ivana Hrivnacova, 21/11/2018 (ivana@ipno.in2p3.fr)
|
||||
|
||||
#include "G4RootMpiPNtupleManager.hh"
|
||||
#include "G4RootFileManager.hh"
|
||||
#include "G4AnalysisUtilities.hh"
|
||||
|
||||
#include "tools/wroot/file"
|
||||
#include "tools/wroot/mpi_ntuple_row_wise"
|
||||
#include "tools/wroot/mpi_ntuple_column_wise"
|
||||
#include "tools/wroot/mpi_ntuple_row_wise"
|
||||
|
||||
#include "G4AnalysisUtilities.hh"
|
||||
#include "G4RootFileManager.hh"
|
||||
|
||||
using namespace G4Analysis;
|
||||
|
||||
const int kTAG_NTUPLE = 1004; // This constant is defined in G4MPImanager
|
||||
// (should be passed from the application)
|
||||
namespace {
|
||||
const int kTAG_NTUPLE = 1004; // This constant is defined in G4MPImanager
|
||||
// (should be passed from the application)
|
||||
namespace
|
||||
{
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void NotExistException(const G4String& what, G4int id, const G4String& functionName)
|
||||
@@ -50,26 +52,25 @@ void NotExistException(const G4String& what, G4int id, const G4String& functionN
|
||||
G4Exception(inFunction, "Analysis_W011", JustWarning, description);
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4RootMpiPNtupleManager::G4RootMpiPNtupleManager(
|
||||
const G4AnalysisManagerState& state,
|
||||
tools::impi* impi, G4int mpiRank, G4int destinationRank)
|
||||
: G4BaseNtupleManager(state),
|
||||
fNtupleVector(),
|
||||
fImpi(impi),
|
||||
fMpiRank(mpiRank),
|
||||
fDestinationRank(destinationRank)
|
||||
{
|
||||
}
|
||||
G4RootMpiPNtupleManager::G4RootMpiPNtupleManager(const G4AnalysisManagerState& state,
|
||||
tools::impi* impi, G4int mpiRank,
|
||||
G4int destinationRank)
|
||||
: G4BaseNtupleManager(state),
|
||||
fNtupleVector(),
|
||||
fImpi(impi),
|
||||
fMpiRank(mpiRank),
|
||||
fDestinationRank(destinationRank)
|
||||
{}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4RootMpiPNtupleManager::~G4RootMpiPNtupleManager()
|
||||
{
|
||||
for ( auto ntupleDescription : fNtupleDescriptionVector ) {
|
||||
for (auto ntupleDescription : fNtupleDescriptionVector) {
|
||||
delete ntupleDescription;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
@@ -77,34 +78,34 @@ G4RootMpiPNtupleManager::~G4RootMpiPNtupleManager()
|
||||
//
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4RootMpiPNtupleDescription*
|
||||
G4RootMpiPNtupleManager::GetNtupleDescriptionInFunction(
|
||||
G4int id, G4String functionName, G4bool warn) const
|
||||
{
|
||||
G4RootMpiPNtupleDescription*
|
||||
G4RootMpiPNtupleManager::GetNtupleDescriptionInFunction(G4int id, G4String functionName,
|
||||
G4bool warn) const
|
||||
{
|
||||
auto index = id - fFirstId;
|
||||
if ( index < 0 || index >= G4int(fNtupleDescriptionVector.size()) ) {
|
||||
if ( warn) {
|
||||
if (index < 0 || index >= G4int(fNtupleDescriptionVector.size())) {
|
||||
if (warn) {
|
||||
NotExistException("ntuple description", id, functionName);
|
||||
}
|
||||
return nullptr;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
return fNtupleDescriptionVector[index];
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
tools::wroot::base_pntuple* G4RootMpiPNtupleManager::GetNtupleInFunction(
|
||||
G4int id, G4String functionName, G4bool warn) const
|
||||
{
|
||||
tools::wroot::base_pntuple*
|
||||
G4RootMpiPNtupleManager::GetNtupleInFunction(G4int id, G4String functionName, G4bool warn) const
|
||||
{
|
||||
auto ntupleDescription = GetNtupleDescriptionInFunction(id, functionName);
|
||||
if ( ! ntupleDescription ) return nullptr;
|
||||
if (!ntupleDescription) return nullptr;
|
||||
|
||||
if ( ! ntupleDescription->GetBasePNtuple() ) {
|
||||
if ( warn ) {
|
||||
if (!ntupleDescription->GetBasePNtuple()) {
|
||||
if (warn) {
|
||||
NotExistException("ntuple", id, functionName);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
return ntupleDescription->GetBasePNtuple();
|
||||
}
|
||||
|
||||
@@ -116,7 +117,7 @@ tools::wroot::base_pntuple* G4RootMpiPNtupleManager::GetNtupleInFunction(
|
||||
void G4RootMpiPNtupleManager::CreateNtuple(G4RootMpiPNtupleDescription* ntupleDescription)
|
||||
{
|
||||
Message(kVL4, "create from booking", "mpi pntuple",
|
||||
ntupleDescription->GetDescription().GetNtupleBooking().name());
|
||||
ntupleDescription->GetDescription().GetNtupleBooking().name());
|
||||
|
||||
// Wait for the ntuple data from main
|
||||
|
||||
@@ -125,8 +126,8 @@ void G4RootMpiPNtupleManager::CreateNtuple(G4RootMpiPNtupleDescription* ntupleDe
|
||||
G4cout << "Go to wait_buffer from " << fDestinationRank << G4endl;
|
||||
fImpi->pack_reset();
|
||||
int probe_src;
|
||||
if ( ! fImpi->wait_buffer(fMpiRank, fDestinationRank, kTAG_NTUPLE, probe_src, verbose)) {
|
||||
G4cerr << "G4RootMpiPNtupleManager::CreateNtuple: wait_buffer() failed."<< G4endl;
|
||||
if (!fImpi->wait_buffer(fMpiRank, fDestinationRank, kTAG_NTUPLE, probe_src, verbose)) {
|
||||
G4cerr << "G4RootMpiPNtupleManager::CreateNtuple: wait_buffer() failed." << G4endl;
|
||||
return;
|
||||
}
|
||||
G4cout << "After wait_buffer with " << fImpi << G4endl;
|
||||
@@ -141,51 +142,52 @@ void G4RootMpiPNtupleManager::CreateNtuple(G4RootMpiPNtupleDescription* ntupleDe
|
||||
std::vector<tools::uint32> basketSizes;
|
||||
unsigned int basketEntries;
|
||||
|
||||
if ( ! fImpi->unpack(mainNtupleId) ) {
|
||||
G4cerr << "bunpack(byteSwap) failed."<< G4endl;
|
||||
if (!fImpi->unpack(mainNtupleId)) {
|
||||
G4cerr << "bunpack(byteSwap) failed." << G4endl;
|
||||
return;
|
||||
}
|
||||
// G4cout << "unpack 1" << G4endl;
|
||||
|
||||
if ( ! fImpi->bunpack(rowWise) ) {
|
||||
G4cerr << "bunpack(rowWise) failed."<< G4endl;
|
||||
|
||||
if (!fImpi->bunpack(rowWise)) {
|
||||
G4cerr << "bunpack(rowWise) failed." << G4endl;
|
||||
return;
|
||||
}
|
||||
// G4cout << "unpack 1/2" << G4endl;
|
||||
|
||||
if ( ! fImpi->bunpack(byteSwap) ) {
|
||||
G4cerr << "bunpack(byteSwap) failed."<< G4endl;
|
||||
if (!fImpi->bunpack(byteSwap)) {
|
||||
G4cerr << "bunpack(byteSwap) failed." << G4endl;
|
||||
return;
|
||||
}
|
||||
// G4cout << "unpack 2" << G4endl;
|
||||
|
||||
if ( ! fImpi->unpack(compression) ) {
|
||||
G4cerr << "unpack(compression) failed."<< G4endl;
|
||||
|
||||
if (!fImpi->unpack(compression)) {
|
||||
G4cerr << "unpack(compression) failed." << G4endl;
|
||||
return;
|
||||
}
|
||||
// G4cout << "unpack 3" << G4endl;
|
||||
|
||||
if ( ! fImpi->unpack(seekDirectory) ) {
|
||||
G4cerr << "unpack(seek) failed."<< G4endl;
|
||||
if (!fImpi->unpack(seekDirectory)) {
|
||||
G4cerr << "unpack(seek) failed." << G4endl;
|
||||
return;
|
||||
}
|
||||
// G4cout << "unpack 4" << G4endl;
|
||||
|
||||
|
||||
if (rowWise) {
|
||||
if ( ! fImpi->unpack(basketSize) ) {
|
||||
G4cerr << "unpack(basketSize) failed."<< G4endl;
|
||||
if (!fImpi->unpack(basketSize)) {
|
||||
G4cerr << "unpack(basketSize) failed." << G4endl;
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
if ( ! fImpi->bunpack(rowMode) ) {
|
||||
}
|
||||
else {
|
||||
if (!fImpi->bunpack(rowMode)) {
|
||||
G4cerr << "bpack(rowMode) failed." << G4endl;
|
||||
return;
|
||||
}
|
||||
if ( ! fImpi->vunpack(basketSizes) ) {
|
||||
G4cerr << "vunpack(basketSizes) failed."<< G4endl;
|
||||
}
|
||||
if (!fImpi->vunpack(basketSizes)) {
|
||||
G4cerr << "vunpack(basketSizes) failed." << G4endl;
|
||||
return;
|
||||
}
|
||||
if( ! fImpi->unpack(basketEntries) ) {
|
||||
if (!fImpi->unpack(basketEntries)) {
|
||||
G4cerr << "unpack(basketEntries) failed." << G4endl;
|
||||
return;
|
||||
}
|
||||
@@ -194,7 +196,7 @@ void G4RootMpiPNtupleManager::CreateNtuple(G4RootMpiPNtupleDescription* ntupleDe
|
||||
|
||||
// G4cout << "rank = " << fMpiRank
|
||||
// << ", verbose = " << verbose
|
||||
// << ", mainNtupleId = " << mainNtupleId
|
||||
// << ", mainNtupleId = " << mainNtupleId
|
||||
// << ", byteSwap = " << byteSwap
|
||||
// << ", compression = " << compression
|
||||
// << ", seekDirectory = " << seekDirectory
|
||||
@@ -202,140 +204,133 @@ void G4RootMpiPNtupleManager::CreateNtuple(G4RootMpiPNtupleDescription* ntupleDe
|
||||
// << G4endl;
|
||||
|
||||
// Create MPI pntuple
|
||||
if ( rowWise ) {
|
||||
tools::wroot::mpi_ntuple_row_wise* ntuple
|
||||
= new tools::wroot::mpi_ntuple_row_wise(
|
||||
mainNtupleId, G4cout, byteSwap, compression, seekDirectory,
|
||||
basketSize, ntupleDescription->GetDescription().GetNtupleBooking(), verbose);
|
||||
if (rowWise) {
|
||||
tools::wroot::mpi_ntuple_row_wise* ntuple = new tools::wroot::mpi_ntuple_row_wise(
|
||||
mainNtupleId, G4cout, byteSwap, compression, seekDirectory, basketSize,
|
||||
ntupleDescription->GetDescription().GetNtupleBooking(), verbose);
|
||||
ntupleDescription->SetNtuple(ntuple);
|
||||
ntupleDescription->SetBasePNtuple(ntuple);
|
||||
} else {
|
||||
tools::wroot::mpi_ntuple_column_wise* ntuple
|
||||
= new tools::wroot::mpi_ntuple_column_wise(
|
||||
mainNtupleId, G4cout, byteSwap, compression, seekDirectory,
|
||||
basketSizes, ntupleDescription->GetDescription().GetNtupleBooking(),
|
||||
rowMode, basketEntries, verbose);
|
||||
}
|
||||
else {
|
||||
tools::wroot::mpi_ntuple_column_wise* ntuple = new tools::wroot::mpi_ntuple_column_wise(
|
||||
mainNtupleId, G4cout, byteSwap, compression, seekDirectory, basketSizes,
|
||||
ntupleDescription->GetDescription().GetNtupleBooking(), rowMode, basketEntries, verbose);
|
||||
ntupleDescription->SetNtuple(ntuple);
|
||||
ntupleDescription->SetBasePNtuple(ntuple);
|
||||
}
|
||||
|
||||
ntupleDescription->GetDescription().SetIsNtupleOwner(true);
|
||||
ntupleDescription->SetImpi(fImpi);
|
||||
// should be not needed
|
||||
// pntuple object is not deleted automatically
|
||||
// should be not needed
|
||||
// pntuple object is not deleted automatically
|
||||
fNtupleVector.push_back(ntupleDescription->GetNtuple());
|
||||
|
||||
Message(kVL3, "create from booking", "mpi pntuple",
|
||||
ntupleDescription->GetDescription().GetNtupleBooking().name());
|
||||
ntupleDescription->GetDescription().GetNtupleBooking().name());
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void G4RootMpiPNtupleManager::CreateNtuplesFromBooking(
|
||||
const std::vector<G4NtupleBooking*>& ntupleBookings)
|
||||
{
|
||||
// Create ntuple from ntuple_booking & the buffer from main rank
|
||||
// Create ntuple from ntuple_booking & the buffer from main rank
|
||||
|
||||
// G4cout << "Start G4RootMpiPNtupleManager::CreateNtuplesFromBooking" << G4endl;
|
||||
|
||||
// Do not create ntuples if NtupleVector is not empty
|
||||
if ( fNtupleVector.size() ) return;
|
||||
if (fNtupleVector.size()) return;
|
||||
|
||||
// Create pntuple descriptions from ntuple booking.
|
||||
// auto g4NtupleBookings = fBookingManager->GetNtupleBookingVector();
|
||||
for ( auto g4NtupleBooking : ntupleBookings ) {
|
||||
for (auto g4NtupleBooking : ntupleBookings) {
|
||||
auto ntupleDescription = new G4RootMpiPNtupleDescription(g4NtupleBooking);
|
||||
ntupleDescription->SetMainNtupleRank(fDestinationRank);
|
||||
fNtupleDescriptionVector.push_back(ntupleDescription);
|
||||
fNtupleDescriptionVector.push_back(ntupleDescription);
|
||||
}
|
||||
|
||||
// Create mpi ntuples
|
||||
for ( auto ntupleDescription : fNtupleDescriptionVector ) {
|
||||
for (auto ntupleDescription : fNtupleDescriptionVector) {
|
||||
// Do not create ntuple if it is inactivated
|
||||
if (fState.GetIsActivation() && (!ntupleDescription->GetDescription().GetActivation()))
|
||||
continue;
|
||||
|
||||
// Do not create ntuple if it is inactivated
|
||||
if ( fState.GetIsActivation() && ( ! ntupleDescription->GetDescription().GetActivation() ) ) continue;
|
||||
|
||||
// Do not create ntuple if it already exists
|
||||
if ( ntupleDescription->GetNtuple() ) continue;
|
||||
|
||||
if (ntupleDescription->GetNtuple()) continue;
|
||||
|
||||
Message(kVL4, "create from booking", "mpi pntuple",
|
||||
ntupleDescription->GetDescription().GetNtupleBooking().name());
|
||||
ntupleDescription->GetDescription().GetNtupleBooking().name());
|
||||
|
||||
// create ntuple
|
||||
CreateNtuple(ntupleDescription);
|
||||
|
||||
// finish created ntuple
|
||||
// finish created ntuple
|
||||
// (nothing to be done ?)
|
||||
// FinishTNtuple(ntupleDescription);
|
||||
|
||||
Message(kVL3, "create from booking", "mpi pntuple",
|
||||
ntupleDescription->GetDescription().GetNtupleBooking().name());
|
||||
ntupleDescription->GetDescription().GetNtupleBooking().name());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4int G4RootMpiPNtupleManager::CreateNtuple(G4NtupleBooking* /*booking*/)
|
||||
// const G4String& name, const G4String& title)
|
||||
// const G4String& name, const G4String& title)
|
||||
{
|
||||
// Create pntuple description from g4 ntuple booking
|
||||
// Nothing to be done here.
|
||||
// Create pntuple description from g4 ntuple booking
|
||||
// Nothing to be done here.
|
||||
|
||||
return G4Analysis::kInvalidId;
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4RootMpiPNtupleManager::FillNtupleIColumn(
|
||||
G4int ntupleId, G4int columnId, G4int value)
|
||||
G4bool G4RootMpiPNtupleManager::FillNtupleIColumn(G4int ntupleId, G4int columnId, G4int value)
|
||||
{
|
||||
return FillNtupleTColumn<int>(ntupleId, columnId, value);
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4RootMpiPNtupleManager::FillNtupleFColumn(
|
||||
G4int ntupleId, G4int columnId, G4float value)
|
||||
G4bool G4RootMpiPNtupleManager::FillNtupleFColumn(G4int ntupleId, G4int columnId, G4float value)
|
||||
{
|
||||
return FillNtupleTColumn<float>(ntupleId, columnId, value);
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4RootMpiPNtupleManager::FillNtupleDColumn(
|
||||
G4int ntupleId, G4int columnId, G4double value)
|
||||
G4bool G4RootMpiPNtupleManager::FillNtupleDColumn(G4int ntupleId, G4int columnId, G4double value)
|
||||
{
|
||||
return FillNtupleTColumn<double>(ntupleId, columnId, value);
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4RootMpiPNtupleManager::FillNtupleSColumn(
|
||||
G4int ntupleId, G4int columnId, const G4String& value)
|
||||
G4bool G4RootMpiPNtupleManager::FillNtupleSColumn(G4int ntupleId, G4int columnId,
|
||||
const G4String& value)
|
||||
{
|
||||
return FillNtupleTColumn<std::string>(ntupleId, columnId, value);
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4RootMpiPNtupleManager::AddNtupleRow(G4int ntupleId)
|
||||
{
|
||||
if ( fState.GetIsActivation() && ( ! GetActivation(ntupleId) ) ) {
|
||||
//G4cout << "Skipping AddNtupleRow for " << ntupleId << G4endl;
|
||||
return false;
|
||||
}
|
||||
{
|
||||
if (fState.GetIsActivation() && (!GetActivation(ntupleId))) {
|
||||
// G4cout << "Skipping AddNtupleRow for " << ntupleId << G4endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
Message(kVL4, "add", "pntuple row", " ntupleId " + to_string(ntupleId));
|
||||
|
||||
auto ntupleDescription = GetNtupleDescriptionInFunction(ntupleId, "AddNtupleRow");
|
||||
if ( ! ntupleDescription ) return false;
|
||||
|
||||
// if(!_ntuple->add_row(_impi,rank_src,tag)) {
|
||||
auto result
|
||||
= ntupleDescription->GetNtuple()
|
||||
->add_row(*fImpi, ntupleDescription->GetMainNtupleRank(), kTAG_NTUPLE );
|
||||
if (!ntupleDescription) return false;
|
||||
|
||||
if ( ! result ) {
|
||||
// if(!_ntuple->add_row(_impi,rank_src,tag)) {
|
||||
auto result = ntupleDescription->GetNtuple()->add_row(
|
||||
*fImpi, ntupleDescription->GetMainNtupleRank(), kTAG_NTUPLE);
|
||||
|
||||
if (!result) {
|
||||
G4ExceptionDescription description;
|
||||
description << " " << " ntupleId " << ntupleId
|
||||
<< "adding row has failed.";
|
||||
G4Exception("G4RootMpiPNtupleManager::AddNtupleRow()",
|
||||
"Analysis_W002", JustWarning, description);
|
||||
}
|
||||
description << " "
|
||||
<< " ntupleId " << ntupleId << "adding row has failed.";
|
||||
G4Exception("G4RootMpiPNtupleManager::AddNtupleRow()", "Analysis_W002", JustWarning,
|
||||
description);
|
||||
}
|
||||
|
||||
Message(kVL3, "add", "pntuple row", " ntupleId " + to_string(ntupleId));
|
||||
|
||||
@@ -345,41 +340,40 @@ G4bool G4RootMpiPNtupleManager::AddNtupleRow(G4int ntupleId)
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4RootMpiPNtupleManager::Merge()
|
||||
{
|
||||
|
||||
// G4cout << "Start G4RootMpiPNtupleManager::Merge" << G4endl;
|
||||
|
||||
auto finalResult = true;
|
||||
|
||||
for ( auto ntupleDescription : fNtupleDescriptionVector) {
|
||||
|
||||
for (auto ntupleDescription : fNtupleDescriptionVector) {
|
||||
// skip inactivated ntuples
|
||||
if ( ! ntupleDescription->GetDescription().GetActivation() ) continue;
|
||||
|
||||
if (!ntupleDescription->GetDescription().GetActivation()) continue;
|
||||
|
||||
// skip if ntuple was already merged and deleted
|
||||
// (this happend when the main rank re-opens a new file for merged data)
|
||||
if ( ! ntupleDescription->GetNtuple() ) continue;
|
||||
|
||||
Message(kVL4, "merge", "pntuple", ntupleDescription->GetDescription().GetNtupleBooking().name());
|
||||
if (!ntupleDescription->GetNtuple()) continue;
|
||||
|
||||
// G4cout << "call end_fill " << fImpi
|
||||
Message(kVL4, "merge", "pntuple",
|
||||
ntupleDescription->GetDescription().GetNtupleBooking().name());
|
||||
|
||||
// G4cout << "call end_fill " << fImpi
|
||||
// << " to rank " << ntupleDescription->GetMainNtupleRank()
|
||||
// << " pntuple: " << ntupleDescription->GetNtuple() << G4endl;
|
||||
auto result
|
||||
= ntupleDescription->GetNtuple()
|
||||
->end_fill(*fImpi, ntupleDescription->GetMainNtupleRank(), kTAG_NTUPLE);
|
||||
auto result = ntupleDescription->GetNtuple()->end_fill(
|
||||
*fImpi, ntupleDescription->GetMainNtupleRank(), kTAG_NTUPLE);
|
||||
|
||||
if ( ! result ) {
|
||||
if (!result) {
|
||||
G4ExceptionDescription description;
|
||||
description << " " << " ntuple " << ntupleDescription->GetDescription().GetNtupleBooking().name()
|
||||
description << " "
|
||||
<< " ntuple " << ntupleDescription->GetDescription().GetNtupleBooking().name()
|
||||
<< "end fill has failed.";
|
||||
G4Exception("G4RootMpiPNtupleManager::Merge()",
|
||||
"Analysis_W002", JustWarning, description);
|
||||
G4Exception("G4RootMpiPNtupleManager::Merge()", "Analysis_W002", JustWarning, description);
|
||||
}
|
||||
|
||||
delete ntupleDescription->GetNtuple();
|
||||
ntupleDescription->SetNtuple(nullptr);
|
||||
|
||||
Message(kVL3, "merge", "pntuple", ntupleDescription->GetDescription().GetNtupleBooking().name());
|
||||
|
||||
Message(kVL3, "merge", "pntuple",
|
||||
ntupleDescription->GetDescription().GetNtupleBooking().name());
|
||||
}
|
||||
|
||||
return finalResult;
|
||||
@@ -392,7 +386,7 @@ G4bool G4RootMpiPNtupleManager::Reset()
|
||||
// we have its ownership.
|
||||
// The ntuples will be recreated with new cycle or new open file.
|
||||
|
||||
for ( auto ntupleDescription : fNtupleDescriptionVector ) {
|
||||
for (auto ntupleDescription : fNtupleDescriptionVector) {
|
||||
ntupleDescription->GetDescription().Reset();
|
||||
}
|
||||
|
||||
@@ -404,7 +398,7 @@ G4bool G4RootMpiPNtupleManager::Reset()
|
||||
//_____________________________________________________________________________
|
||||
void G4RootMpiPNtupleManager::Clear()
|
||||
{
|
||||
for ( auto ntupleDescription : fNtupleDescriptionVector ) {
|
||||
for (auto ntupleDescription : fNtupleDescriptionVector) {
|
||||
delete ntupleDescription->GetNtuple();
|
||||
}
|
||||
|
||||
@@ -417,7 +411,7 @@ void G4RootMpiPNtupleManager::Clear()
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4RootMpiPNtupleManager::Delete(G4int id)
|
||||
{
|
||||
if ( IsVerbose(G4Analysis::kVL4) ) {
|
||||
if (IsVerbose(G4Analysis::kVL4)) {
|
||||
Message(G4Analysis::kVL4, "delete", "pntuple ntupleId " + to_string(id));
|
||||
}
|
||||
|
||||
@@ -442,31 +436,28 @@ G4bool G4RootMpiPNtupleManager::Delete(G4int id)
|
||||
|
||||
//_____________________________________________________________________________
|
||||
|
||||
void G4RootMpiPNtupleManager::SetActivation(
|
||||
G4bool activation)
|
||||
void G4RootMpiPNtupleManager::SetActivation(G4bool activation)
|
||||
{
|
||||
for ( auto ntupleDescription : fNtupleDescriptionVector ) {
|
||||
for (auto ntupleDescription : fNtupleDescriptionVector) {
|
||||
ntupleDescription->GetDescription().SetActivation(activation);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
|
||||
void G4RootMpiPNtupleManager::SetActivation(
|
||||
G4int ntupleId, G4bool activation)
|
||||
void G4RootMpiPNtupleManager::SetActivation(G4int ntupleId, G4bool activation)
|
||||
{
|
||||
auto ntupleDescription = GetNtupleDescriptionInFunction(ntupleId, "SetActivation");
|
||||
if ( ! ntupleDescription ) return;
|
||||
if (!ntupleDescription) return;
|
||||
|
||||
ntupleDescription->GetDescription().SetActivation(activation);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4RootMpiPNtupleManager::GetActivation(
|
||||
G4int ntupleId) const
|
||||
G4bool G4RootMpiPNtupleManager::GetActivation(G4int ntupleId) const
|
||||
{
|
||||
auto ntupleDescription = GetNtupleDescriptionInFunction(ntupleId, "GetActivation");
|
||||
if ( ! ntupleDescription ) return false;
|
||||
if (!ntupleDescription) return false;
|
||||
|
||||
return ntupleDescription->GetDescription().GetActivation();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user