Import Geant4 11.0.0 source tree
This commit is contained in:
committed by
Ben Morgan
parent
6399a014b6
commit
80e2389dd8
@@ -27,21 +27,112 @@
|
||||
// Author: Ivana Hrivnacova, 09/04/2014 (ivana@ipno.in2p3.fr)
|
||||
|
||||
#include "G4RootRNtupleManager.hh"
|
||||
#include "G4RootRFileManager.hh"
|
||||
#include "G4AnalysisManagerState.hh"
|
||||
#include "G4AnalysisUtilities.hh"
|
||||
|
||||
#include "tools/rroot/file"
|
||||
#include "tools/rroot/rall"
|
||||
#include "tools/rroot/streamers"
|
||||
#include "tools/rroot/fac"
|
||||
#include "tools/rroot/tree"
|
||||
|
||||
using namespace G4Analysis;
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4RootRNtupleManager::G4RootRNtupleManager(const G4AnalysisManagerState& state)
|
||||
: G4TRNtupleManager<tools::rroot::ntuple>(state)
|
||||
{}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4RootRNtupleManager::~G4RootRNtupleManager()
|
||||
{}
|
||||
|
||||
//
|
||||
//
|
||||
// private methods
|
||||
//
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4int G4RootRNtupleManager::ReadNtupleImpl(const G4String& ntupleName,
|
||||
const G4String& fileName,
|
||||
const G4String& dirName,
|
||||
G4bool isUserFileName)
|
||||
{
|
||||
Message(kVL4, "read", "ntuple", ntupleName);
|
||||
|
||||
// Ntuples are saved per thread
|
||||
// but do not apply the thread suffix if fileName is provided explicitly
|
||||
auto isPerThread = true;
|
||||
if ( isUserFileName ) isPerThread = false;
|
||||
|
||||
// Get or open a file
|
||||
auto rfile = fFileManager->GetRFile(fileName, isPerThread);
|
||||
if ( ! rfile ) {
|
||||
if ( ! fFileManager->OpenRFile(fileName, isPerThread) ) return kInvalidId;
|
||||
rfile = fFileManager->GetRFile(fileName, isPerThread);
|
||||
}
|
||||
|
||||
// Get key
|
||||
tools::rroot::key* key = nullptr;
|
||||
tools::rroot::TDirectory* newDir = nullptr;
|
||||
if ( ! dirName.empty() ) {
|
||||
newDir = tools::rroot::find_dir(rfile->dir(), dirName);
|
||||
if ( newDir ) {
|
||||
key = newDir->find_key(ntupleName);
|
||||
}
|
||||
else {
|
||||
G4Analysis::Warn(
|
||||
"Directory " + dirName + " not found in file " + fileName + ".",
|
||||
fkClass, "ReadNtupleImpl");
|
||||
return kInvalidId;
|
||||
}
|
||||
}
|
||||
else {
|
||||
key = rfile->dir().find_key(ntupleName);
|
||||
}
|
||||
|
||||
if ( ! key ) {
|
||||
Warn("Key " + ntupleName + " for Ntuple not found in file " + fileName +
|
||||
", directory " + dirName, fkClass, "ReadNtupleImpl");
|
||||
delete newDir;
|
||||
return kInvalidId;
|
||||
}
|
||||
|
||||
unsigned int size;
|
||||
char* charBuffer = key->get_object_buffer(*rfile, size);
|
||||
if ( ! charBuffer ) {
|
||||
Warn("Cannot get data buffer for Ntuple " + ntupleName +
|
||||
" in file " + fileName, fkClass, "ReadNtupleImpl");
|
||||
delete newDir;
|
||||
return kInvalidId;
|
||||
}
|
||||
|
||||
auto verbose = false;
|
||||
auto buffer
|
||||
= new tools::rroot::buffer(G4cout, rfile->byte_swap(), size, charBuffer,
|
||||
key->key_length(), verbose);
|
||||
buffer->set_map_objs(true);
|
||||
|
||||
auto fac = new tools::rroot::fac(G4cout);
|
||||
|
||||
auto tree = new tools::rroot::tree(*rfile, *fac);
|
||||
if ( ! tree->stream(*buffer) ) {
|
||||
Warn("TTree streaming failed for Ntuple " + ntupleName +
|
||||
" in file " + fileName,
|
||||
fkClass, "ReadNtupleImpl");
|
||||
|
||||
delete buffer;
|
||||
delete tree;
|
||||
delete newDir;
|
||||
return kInvalidId;
|
||||
}
|
||||
|
||||
auto rntuple = new tools::rroot::ntuple(*tree); //use the flat ntuple API.
|
||||
auto rntupleDescription = new G4TRNtupleDescription<tools::rroot::ntuple>(rntuple);
|
||||
|
||||
auto id = SetNtuple(rntupleDescription);
|
||||
|
||||
Message(kVL2, "read", "ntuple", ntupleName, id > kInvalidId);
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4RootRNtupleManager::GetTNtupleRow(
|
||||
G4TRNtupleDescription<tools::rroot::ntuple>* ntupleDescription)
|
||||
@@ -53,12 +144,7 @@ G4bool G4RootRNtupleManager::GetTNtupleRow(
|
||||
if ( ! isInitialized ) {
|
||||
|
||||
if ( ! ntuple->initialize(G4cout, *ntupleBinding) ) {
|
||||
G4ExceptionDescription description;
|
||||
description
|
||||
<< " "
|
||||
<< "Ntuple initialization failed !!";
|
||||
G4Exception("G4RootRNtuple::GetTNtupleRow()",
|
||||
"Analysis_WR021", JustWarning, description);
|
||||
Warn("Ntuple initialization failed !!", fkClass, "GetTNtupleRow");
|
||||
return false;
|
||||
}
|
||||
ntupleDescription->fIsInitialized = true;
|
||||
@@ -68,15 +154,10 @@ G4bool G4RootRNtupleManager::GetTNtupleRow(
|
||||
auto next = ntuple->next();
|
||||
if ( next ) {
|
||||
if ( ! ntuple->get_row() ) {
|
||||
G4ExceptionDescription description;
|
||||
description
|
||||
<< " "
|
||||
<< "Ntuple get_row() failed !!";
|
||||
G4Exception("G4RootRNtuple::GetTNtupleRow()",
|
||||
"Analysis_WR021", JustWarning, description);
|
||||
Warn("Ntuple get_row() failed !!", fkClass, "GetTNtupleRow");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return next;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user