Import Geant4 10.7.0 source tree
This commit is contained in:
@@ -26,6 +26,7 @@
|
||||
//
|
||||
// Author: Ivana Hrivnacova, 04/10/2016 (ivana@ipno.in2p3.fr)
|
||||
|
||||
#include "G4NtupleBookingManager.hh"
|
||||
#include "G4RootPNtupleManager.hh"
|
||||
#include "G4RootMainNtupleManager.hh"
|
||||
#include "G4AnalysisUtilities.hh"
|
||||
@@ -35,17 +36,31 @@
|
||||
|
||||
// mutex in a file scope
|
||||
namespace {
|
||||
//Mutex to lock master manager when adding ntuple row and ending fill
|
||||
G4Mutex pntupleMutex = G4MUTEX_INITIALIZER;
|
||||
|
||||
//Mutex to lock master manager when adding ntuple row and ending fill
|
||||
G4Mutex pntupleMutex = G4MUTEX_INITIALIZER;
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void NotExistException(const G4String& what, G4int id, const G4String& functionName)
|
||||
{
|
||||
G4String inFunction = "G4RootPNtupleManager::";
|
||||
inFunction += functionName;
|
||||
G4ExceptionDescription description;
|
||||
description << what << " id= " << id << " does not exist.";
|
||||
G4Exception(inFunction, "Analysis_W011", JustWarning, description);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4RootPNtupleManager::G4RootPNtupleManager(G4RootMainNtupleManager* main,
|
||||
const G4AnalysisManagerState& state,
|
||||
G4bool rowWise, G4bool rowMode)
|
||||
G4RootPNtupleManager::G4RootPNtupleManager(const G4AnalysisManagerState& state,
|
||||
std::shared_ptr<G4NtupleBookingManager> bookingManger,
|
||||
std::shared_ptr<G4RootMainNtupleManager> main,
|
||||
G4bool rowWise, G4bool rowMode)
|
||||
: G4BaseNtupleManager(state),
|
||||
fCreateMode(G4PNtupleCreateMode::kUndefined),
|
||||
fBookingManager(bookingManger),
|
||||
fMainNtupleManager(main),
|
||||
fNtupleDescriptionVector(),
|
||||
fNtupleVector(),
|
||||
fRowWise(rowWise),
|
||||
fRowMode(rowMode)
|
||||
@@ -71,11 +86,7 @@ G4RootPNtupleManager::GetNtupleDescriptionInFunction(
|
||||
auto index = id - fFirstId;
|
||||
if ( index < 0 || index >= G4int(fNtupleDescriptionVector.size()) ) {
|
||||
if ( warn) {
|
||||
G4String inFunction = "G4RootPNtupleManager::";
|
||||
inFunction += functionName;
|
||||
G4ExceptionDescription description;
|
||||
description << " " << "ntuple " << id << " does not exist.";
|
||||
G4Exception(inFunction, "Analysis_W011", JustWarning, description);
|
||||
NotExistException("ntuple description", id, functionName);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
@@ -93,11 +104,7 @@ tools::wroot::base_pntuple*
|
||||
|
||||
if ( ! ntupleDescription->fBasePNtuple ) {
|
||||
if ( warn ) {
|
||||
G4String inFunction = "G4RootPNtupleManager::";
|
||||
inFunction += functionName;
|
||||
G4ExceptionDescription description;
|
||||
description << " " << "ntupleId " << id << " does not exist.";
|
||||
G4Exception(inFunction, "Analysis_W011", JustWarning, description);
|
||||
NotExistException("ntuple", id, functionName);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
@@ -109,17 +116,12 @@ tools::wroot::ntuple*
|
||||
G4RootPNtupleManager::GetMainNtupleInFunction(
|
||||
G4int id, G4String functionName, G4bool warn) const
|
||||
{
|
||||
auto& mainNtupleVector
|
||||
= fMainNtupleManager->GetNtupleVector();
|
||||
|
||||
auto& mainNtupleVector = fMainNtupleManager->GetNtupleVector();
|
||||
|
||||
auto index = id - fFirstId;
|
||||
if ( index < 0 || index >= G4int(mainNtupleVector.size()) ) {
|
||||
if ( warn) {
|
||||
G4String inFunction = "G4RootPNtupleManager::";
|
||||
inFunction += functionName;
|
||||
G4ExceptionDescription description;
|
||||
description << " " << "main ntuple " << id << " does not exist.";
|
||||
G4Exception(inFunction, "Analysis_W011", JustWarning, description);
|
||||
NotExistException("main ntuple", id, functionName);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
@@ -127,28 +129,38 @@ G4RootPNtupleManager::GetMainNtupleInFunction(
|
||||
return mainNtupleVector[index];
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// protected functions
|
||||
//
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void G4RootPNtupleManager::CreateNtuple(G4RootPNtupleDescription* ntupleDescription,
|
||||
tools::wroot::ntuple* mainNtuple)
|
||||
void G4RootPNtupleManager::CreateNtupleFromMain(
|
||||
G4RootPNtupleDescription* ntupleDescription,
|
||||
tools::wroot::ntuple* mainNtuple)
|
||||
{
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() )
|
||||
fState.GetVerboseL4()
|
||||
->Message("create from main", "pntuple", mainNtuple->name());
|
||||
if ( fState.GetVerboseL4() ) {
|
||||
fState.GetVerboseL4()
|
||||
->Message("create from main", "pntuple", mainNtuple->name());
|
||||
}
|
||||
#endif
|
||||
|
||||
auto rfile = fMainNtupleManager->GetNtupleFile();
|
||||
// auto directory = fMainNtupleManager->GetNtupleDirectory();
|
||||
auto file = fMainNtupleManager->GetNtupleFile(&ntupleDescription->fDescription);
|
||||
if ( ! file ) {
|
||||
G4String inFunction = "G4RootPNtupleManager::::CreateNtupleFromMain";
|
||||
G4ExceptionDescription description;
|
||||
description
|
||||
<< "Cannot create pntuple. Main ntuple file does not exist." << G4endl;
|
||||
G4Exception(inFunction, "Analysis_W002", JustWarning, description);
|
||||
return;
|
||||
}
|
||||
|
||||
ntupleDescription->fDescription.fFile = file;
|
||||
|
||||
// Get parameters from ntupleDescription
|
||||
ntupleDescription->fFile = rfile.get();
|
||||
mainNtuple->get_branches(ntupleDescription->fMainBranches);
|
||||
|
||||
auto rfile = std::get<0>(*file);
|
||||
G4bool verbose = true;
|
||||
if ( fRowWise ) {
|
||||
auto mainBranch = mainNtuple->get_row_wise_branch();
|
||||
@@ -157,7 +169,7 @@ void G4RootPNtupleManager::CreateNtuple(G4RootPNtupleDescription* ntupleDescript
|
||||
G4cout, rfile->byte_swap(), rfile->compression(),
|
||||
mainNtuple->dir().seek_directory(),
|
||||
*mainBranch, mainBranch->basket_size(),
|
||||
ntupleDescription->fNtupleBooking, verbose);
|
||||
ntupleDescription->fDescription.fNtupleBooking, verbose);
|
||||
|
||||
ntupleDescription->fNtuple
|
||||
= static_cast<tools::wroot::imt_ntuple*>(mtNtuple);
|
||||
@@ -176,7 +188,7 @@ void G4RootPNtupleManager::CreateNtuple(G4RootPNtupleDescription* ntupleDescript
|
||||
G4cout, rfile->byte_swap(), rfile->compression(),
|
||||
mainNtuple->dir().seek_directory(),
|
||||
ntupleDescription->fMainBranches, basketSizes,
|
||||
ntupleDescription->fNtupleBooking,
|
||||
ntupleDescription->fDescription.fNtupleBooking,
|
||||
fRowMode, basketEntries, verbose);
|
||||
|
||||
ntupleDescription->fNtuple
|
||||
@@ -185,15 +197,15 @@ void G4RootPNtupleManager::CreateNtuple(G4RootPNtupleDescription* ntupleDescript
|
||||
= static_cast<tools::wroot::base_pntuple*>(mtNtuple);
|
||||
}
|
||||
|
||||
ntupleDescription->fIsNtupleOwner = true;
|
||||
ntupleDescription->fDescription.fIsNtupleOwner = true;
|
||||
// // pntuple object is not deleted automatically
|
||||
fNtupleVector.push_back(ntupleDescription->fNtuple);
|
||||
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL3() )
|
||||
fState.GetVerboseL3()
|
||||
->Message("create from main", "pntuple", mainNtuple->name());
|
||||
if ( fState.GetVerboseL3() ) {
|
||||
fState.GetVerboseL3()
|
||||
->Message("create from main", "pntuple", mainNtuple->name());
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -201,125 +213,34 @@ void G4RootPNtupleManager::CreateNtuple(G4RootPNtupleDescription* ntupleDescript
|
||||
void G4RootPNtupleManager::CreateNtuplesFromMain()
|
||||
{
|
||||
// Create ntuple from booking (if not yet done) and main ntuple
|
||||
// This function is called from G4AnalysisManager::OpenFile.
|
||||
// This function is called from G4RootNtupleFileManager::ActionAtOpenFile.
|
||||
|
||||
if ( fCreateMode == G4PNtupleCreateMode::kUndefined ) {
|
||||
if ( fNtupleDescriptionVector.size() ) {
|
||||
fCreateMode = G4PNtupleCreateMode::kSlaveBeforeOpen;
|
||||
// G4cout << "Create mode: kSlaveBeforeOpen" << G4endl;
|
||||
} else {
|
||||
fCreateMode = G4PNtupleCreateMode::kSlaveAfterOpen;
|
||||
// G4cout << "Create mode: kSlaveAfterOpen" << G4endl;
|
||||
}
|
||||
// Create pntuple descriptions from ntuple booking.
|
||||
auto g4NtupleBookings = fBookingManager->GetNtupleBookingVector();
|
||||
for ( auto g4NtupleBooking : g4NtupleBookings ) {
|
||||
auto ntupleDescription = new G4RootPNtupleDescription(g4NtupleBooking);
|
||||
// Save g4booking, activation in pntuple booking
|
||||
fNtupleDescriptionVector.push_back(ntupleDescription);
|
||||
}
|
||||
|
||||
if ( fCreateMode == G4PNtupleCreateMode::kSlaveAfterOpen ) {
|
||||
// ntuples are not yet booked
|
||||
// G4cout << "Ntuples are not yet booked ?" << G4endl;
|
||||
return;
|
||||
}
|
||||
|
||||
auto& mainNtupleVector
|
||||
= fMainNtupleManager->GetNtupleVector();
|
||||
auto& mainNtupleVector = fMainNtupleManager->GetNtupleVector();
|
||||
|
||||
G4int lcounter = 0;
|
||||
for ( auto mainNtuple : mainNtupleVector ) {
|
||||
|
||||
auto& ntupleDescription
|
||||
= fNtupleDescriptionVector[lcounter++];
|
||||
CreateNtuple(ntupleDescription, mainNtuple);
|
||||
for ( auto mainNtuple : mainNtupleVector ) {
|
||||
auto& ntupleDescription = fNtupleDescriptionVector[lcounter++];
|
||||
CreateNtupleFromMain(ntupleDescription, mainNtuple);
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4int G4RootPNtupleManager::CreateNtuple(
|
||||
const G4String& name, const G4String& title)
|
||||
G4int G4RootPNtupleManager::CreateNtuple(G4NtupleBooking* /*booking*/)
|
||||
{
|
||||
// Create pntuple description with ntuple_booking
|
||||
// Create pntuple from g4 ntuple booking.
|
||||
// Nothing to be done here.
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() )
|
||||
fState.GetVerboseL4()->Message("create", "pntuple booking", name);
|
||||
#endif
|
||||
|
||||
// Set create mode if not yet defined
|
||||
if ( fCreateMode == G4PNtupleCreateMode::kUndefined ) {
|
||||
if ( fMainNtupleManager->GetNtupleFile() ) {
|
||||
fCreateMode = G4PNtupleCreateMode::kSlaveAfterOpen;
|
||||
} else {
|
||||
fCreateMode = G4PNtupleCreateMode::kSlaveBeforeOpen;
|
||||
}
|
||||
}
|
||||
|
||||
// Create ntuple description
|
||||
auto index = fNtupleDescriptionVector.size();
|
||||
auto ntupleDescription = new G4RootPNtupleDescription();
|
||||
fNtupleDescriptionVector.push_back(ntupleDescription);
|
||||
|
||||
// Save name & title in ntuple booking
|
||||
ntupleDescription->fNtupleBooking.set_name(name);
|
||||
ntupleDescription->fNtupleBooking.set_title(title);
|
||||
|
||||
fLockFirstId = true;
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL2() ) {
|
||||
G4ExceptionDescription description;
|
||||
description << name << " ntupleId " << index + fFirstId;
|
||||
fState.GetVerboseL2()->Message("create", "pntuple booking", description);
|
||||
}
|
||||
#endif
|
||||
|
||||
return index + fFirstId;
|
||||
return G4Analysis::kInvalidId;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4int G4RootPNtupleManager::CreateNtupleIColumn(
|
||||
G4int ntupleId, const G4String& name, std::vector<int>* vector)
|
||||
{
|
||||
return CreateNtupleTColumn<int>(ntupleId, name, vector);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4int G4RootPNtupleManager::CreateNtupleFColumn(
|
||||
G4int ntupleId, const G4String& name, std::vector<float>* vector)
|
||||
{
|
||||
return CreateNtupleTColumn<float>(ntupleId, name, vector);
|
||||
}
|
||||
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4int G4RootPNtupleManager::CreateNtupleDColumn(
|
||||
G4int ntupleId, const G4String& name, std::vector<double>* vector)
|
||||
{
|
||||
return CreateNtupleTColumn<double>(ntupleId, name, vector);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4int G4RootPNtupleManager::CreateNtupleSColumn(
|
||||
G4int ntupleId, const G4String& name)
|
||||
{
|
||||
return CreateNtupleTColumn<std::string>(ntupleId, name, nullptr);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void G4RootPNtupleManager::FinishNtuple(G4int ntupleId)
|
||||
{
|
||||
// create ntuple if file was open
|
||||
|
||||
// if ( fMainNtupleManager->GetNtupleFile() ) {
|
||||
if ( fCreateMode == G4PNtupleCreateMode::kSlaveAfterOpen ) {
|
||||
auto ntupleDescription
|
||||
= GetNtupleDescriptionInFunction(ntupleId, "FinishNtuple");
|
||||
if ( ! ntupleDescription ) return;
|
||||
|
||||
auto mainNtuple = GetMainNtupleInFunction(ntupleId, "FinishNtuple");
|
||||
if ( ! mainNtuple ) return;
|
||||
|
||||
CreateNtuple(ntupleDescription, mainNtuple);
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4RootPNtupleManager::FillNtupleIColumn(
|
||||
G4int ntupleId, G4int columnId, G4int value)
|
||||
@@ -367,20 +288,23 @@ G4bool G4RootPNtupleManager::AddNtupleRow(G4int ntupleId)
|
||||
auto ntupleDescription = GetNtupleDescriptionInFunction(ntupleId, "AddNtupleRow");
|
||||
if ( ! ntupleDescription ) return false;
|
||||
|
||||
auto rfile = std::get<0>(*ntupleDescription->fDescription.fFile);
|
||||
|
||||
G4AutoLock lock(&pntupleMutex);
|
||||
lock.unlock();
|
||||
mutex toolsLock(lock);
|
||||
auto result
|
||||
= ntupleDescription->fNtuple
|
||||
->add_row(toolsLock, *ntupleDescription->fFile);
|
||||
= ntupleDescription->fNtuple->add_row(toolsLock, *rfile);
|
||||
|
||||
if ( ! result ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " " << " ntupleId " << ntupleId
|
||||
<< "adding row has failed.";
|
||||
G4Exception("G4RootPNtupleManager::AddNtupleRow()",
|
||||
"Analysis_W002", JustWarning, description);
|
||||
}
|
||||
"Analysis_W022", JustWarning, description);
|
||||
}
|
||||
|
||||
ntupleDescription->fDescription.fHasFill = true;
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL3() ) {
|
||||
@@ -399,29 +323,32 @@ G4bool G4RootPNtupleManager::Merge()
|
||||
for ( auto ntupleDescription : fNtupleDescriptionVector) {
|
||||
|
||||
// skip inactivated ntuples
|
||||
if(!ntupleDescription->fActivation || !ntupleDescription->fNtuple)
|
||||
if(!ntupleDescription->fDescription.fActivation || !ntupleDescription->fNtuple) {
|
||||
// G4cout << "skipping inactive ntuple " << G4endl;
|
||||
continue;
|
||||
}
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() ) {
|
||||
fState.GetVerboseL4()
|
||||
->Message("merge", "pntuple", ntupleDescription->fNtupleBooking.name());
|
||||
->Message("merge", "pntuple", ntupleDescription->fDescription.fNtupleBooking.name());
|
||||
}
|
||||
#endif
|
||||
|
||||
auto rfile = std::get<0>(*ntupleDescription->fDescription.fFile);
|
||||
|
||||
G4AutoLock lock(&pntupleMutex);
|
||||
lock.unlock();
|
||||
mutex toolsLock(lock);
|
||||
auto result
|
||||
= ntupleDescription->fNtuple
|
||||
->end_fill(toolsLock, *ntupleDescription->fFile);
|
||||
= ntupleDescription->fNtuple->end_fill(toolsLock, *rfile);
|
||||
|
||||
if ( ! result ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " " << " ntuple " << ntupleDescription->fNtupleBooking.name()
|
||||
description << " " << " ntuple " << ntupleDescription->fDescription.fNtupleBooking.name()
|
||||
<< "end fill has failed.";
|
||||
G4Exception("G4RootPNtupleManager::Merge()",
|
||||
"Analysis_W002", JustWarning, description);
|
||||
"Analysis_W031", JustWarning, description);
|
||||
}
|
||||
|
||||
delete ntupleDescription->fNtuple;
|
||||
@@ -430,7 +357,7 @@ G4bool G4RootPNtupleManager::Merge()
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL3() ) {
|
||||
fState.GetVerboseL3()
|
||||
->Message("merge", "pntuple", ntupleDescription->fNtupleBooking.name());
|
||||
->Message("merge", "pntuple", ntupleDescription->fDescription.fNtupleBooking.name());
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -459,7 +386,7 @@ void G4RootPNtupleManager::SetActivation(
|
||||
G4bool activation)
|
||||
{
|
||||
for ( auto ntupleDescription : fNtupleDescriptionVector ) {
|
||||
ntupleDescription->fActivation = activation;
|
||||
ntupleDescription->fDescription.fActivation = activation;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -471,7 +398,7 @@ void G4RootPNtupleManager::SetActivation(
|
||||
auto ntupleDescription = GetNtupleDescriptionInFunction(ntupleId, "SetActivation");
|
||||
if ( ! ntupleDescription ) return;
|
||||
|
||||
ntupleDescription->fActivation = activation;
|
||||
ntupleDescription->fDescription.fActivation = activation;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
@@ -481,7 +408,7 @@ G4bool G4RootPNtupleManager::GetActivation(
|
||||
auto ntupleDescription = GetNtupleDescriptionInFunction(ntupleId, "GetActivation");
|
||||
if ( ! ntupleDescription ) return false;
|
||||
|
||||
return ntupleDescription->fActivation;
|
||||
return ntupleDescription->fDescription.fActivation;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
@@ -490,18 +417,6 @@ G4int G4RootPNtupleManager::GetNofNtuples() const
|
||||
return fNtupleVector.size();
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4int G4RootPNtupleManager::GetNofNtupleBookings() const
|
||||
{
|
||||
return fNtupleDescriptionVector.size();
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4RootPNtupleManager::IsEmpty() const
|
||||
{
|
||||
return ! fNtupleDescriptionVector.size();
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void G4RootPNtupleManager::SetNtupleRowWise(G4bool rowWise, G4bool rowMode)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user