Import Geant4 10.1.0 source tree

This commit is contained in:
Gabriele Cosmo
2016-06-10 12:08:39 +02:00
parent 286caacf06
commit c9b32a6c0a
5770 changed files with 1050949 additions and 367105 deletions
+384 -27
View File
@@ -23,22 +23,43 @@
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
// $Id: G4CsvAnalysisManager.cc 74257 2013-10-02 14:24:55Z gcosmo $
// $Id: G4CsvAnalysisManager.cc 85317 2014-10-27 15:58:15Z gcosmo $
// Author: Ivana Hrivnacova, 18/06/2013 (ivana@ipno.in2p3.fr)
#include "G4CsvAnalysisManager.hh"
#include "G4CsvFileManager.hh"
#include "G4H1DummyManager.hh"
#include "G4H2DummyManager.hh"
#include "G4H1ToolsManager.hh"
#include "G4H2ToolsManager.hh"
#include "G4H3ToolsManager.hh"
#include "G4P1ToolsManager.hh"
#include "G4P2ToolsManager.hh"
#include "G4CsvNtupleManager.hh"
#include "G4AnalysisVerbose.hh"
#include "G4AnalysisManagerState.hh"
#include "G4UnitsTable.hh"
#include "G4Threading.hh"
#include "G4AutoLock.hh"
#include "tools/wcsv_histo"
#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 = 0;
G4ThreadLocal G4CsvAnalysisManager* G4CsvAnalysisManager::fgInstance = 0;
@@ -56,6 +77,11 @@ G4CsvAnalysisManager* G4CsvAnalysisManager::Instance()
//_____________________________________________________________________________
G4CsvAnalysisManager::G4CsvAnalysisManager(G4bool isMaster)
: G4VAnalysisManager("Csv", isMaster),
fH1Manager(0),
fH2Manager(0),
fH3Manager(0),
fP1Manager(0),
fP2Manager(0),
fNtupleManager(0),
fFileManager(0)
{
@@ -72,8 +98,11 @@ G4CsvAnalysisManager::G4CsvAnalysisManager(G4bool isMaster)
fgInstance = this;
// Create managers
fH1Manager = new G4H1DummyManager(fState);
fH2Manager = new G4H2DummyManager(fState);
fH1Manager = new G4H1ToolsManager(fState);
fH2Manager = new G4H2ToolsManager(fState);
fH3Manager = new G4H3ToolsManager(fState);
fP1Manager = new G4P1ToolsManager(fState);
fP2Manager = new G4P2ToolsManager(fState);
fNtupleManager = new G4CsvNtupleManager(fState);
fFileManager = new G4CsvFileManager(fState);
fNtupleManager->SetFileManager(fFileManager);
@@ -82,6 +111,9 @@ G4CsvAnalysisManager::G4CsvAnalysisManager(G4bool isMaster)
// Set managers to base class
SetH1Manager(fH1Manager);
SetH2Manager(fH2Manager);
SetH3Manager(fH3Manager);
SetP1Manager(fP1Manager);
SetP2Manager(fP2Manager);
SetNtupleManager(fNtupleManager);
SetFileManager(fFileManager);
}
@@ -101,7 +133,7 @@ G4CsvAnalysisManager::~G4CsvAnalysisManager()
G4bool G4CsvAnalysisManager::CloseNtupleFiles()
{
const std::vector<G4CsvNtupleDescription*>& ntupleVector
= fNtupleManager->GetNtupleVector();
= fNtupleManager->GetNtupleDescriptionVector();
// Close ntuple files
std::vector<G4CsvNtupleDescription*>::const_iterator it;
@@ -117,20 +149,304 @@ G4bool G4CsvAnalysisManager::CloseNtupleFiles()
// protected methods
//
//
// private methods
//
//_____________________________________________________________________________
G4bool G4CsvAnalysisManager::WriteH1()
{
const std::vector<tools::histo::h1d*>& h1Vector
= fH1Manager->GetH1Vector();
const std::vector<G4HnInformation*>& hnVector
= fH1Manager->GetHnVector();
if ( ! h1Vector.size() ) return true;
if ( ! G4Threading::IsWorkerThread() ) {
for ( G4int i=0; i<G4int(h1Vector.size()); ++i ) {
G4HnInformation* info = hnVector[i];
G4bool activation = info->GetActivation();
G4String name = info->GetName();
// skip writing if activation is enabled and H1 is inactivated
if ( fState.GetIsActivation() && ( ! activation ) ) continue;
tools::histo::h1d* h1 = h1Vector[i];
G4String fileName = fFileManager->GetHnFileName("h1", name);
std::ofstream hnFile(fileName);
G4bool result
= tools::wcsv::hto(hnFile, h1->s_cls(), *h1);
if ( ! result ) {
G4ExceptionDescription description;
description << " " << "saving histogram " << name << " failed";
G4Exception("G4CsvAnalysisManager::Write()",
"Analysis_W022", JustWarning, description);
return false;
}
hnFile.close();
#ifdef G4VERBOSE
if ( fState.GetVerboseL1() )
fState.GetVerboseL1()->Message("write", "file", fileName);
#endif
fFileManager->LockHistoDirectoryName();
}
}
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 true;
}
//_____________________________________________________________________________
G4bool G4CsvAnalysisManager::WriteH2()
{
const std::vector<tools::histo::h2d*>& h2Vector
= fH2Manager->GetH2Vector();
const std::vector<G4HnInformation*>& hnVector
= fH2Manager->GetHnVector();
if ( ! h2Vector.size() ) return true;
if ( ! G4Threading::IsWorkerThread() ) {
// h2 histograms
for ( G4int i=0; i<G4int(h2Vector.size()); ++i ) {
G4HnInformation* info = hnVector[i];
G4bool activation = info->GetActivation();
G4String name = info->GetName();
// skip writing if inactivated
if ( fState.GetIsActivation() && ( ! activation ) ) continue;
tools::histo::h2d* h2 = h2Vector[i];
G4String fileName = fFileManager->GetHnFileName("h2", name);
std::ofstream hnFile(fileName);
G4bool result
= tools::wcsv::hto(hnFile, h2->s_cls(), *h2);
if ( ! result ) {
G4ExceptionDescription description;
description << " " << "saving histogram " << name << " failed";
G4Exception("G4CsvAnalysisManager::Write()",
"Analysis_W022", JustWarning, description);
return false;
}
hnFile.close();
#ifdef G4VERBOSE
if ( fState.GetVerboseL1() )
fState.GetVerboseL1()->Message("write", "file", fileName);
#endif
fFileManager->LockHistoDirectoryName();
}
}
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 true;
}
//_____________________________________________________________________________
G4bool G4CsvAnalysisManager::WriteH3()
{
const std::vector<tools::histo::h3d*>& h3Vector
= fH3Manager->GetH3Vector();
const std::vector<G4HnInformation*>& hnVector
= fH3Manager->GetHnVector();
if ( ! h3Vector.size() ) return true;
if ( ! G4Threading::IsWorkerThread() ) {
// h3 histograms
for ( G4int i=0; i<G4int(h3Vector.size()); ++i ) {
G4HnInformation* info = hnVector[i];
G4bool activation = info->GetActivation();
G4String name = info->GetName();
// skip writing if inactivated
if ( fState.GetIsActivation() && ( ! activation ) ) continue;
tools::histo::h3d* h3 = h3Vector[i];
G4String fileName = fFileManager->GetHnFileName("h3", name);
std::ofstream hnFile(fileName);
G4bool result
= tools::wcsv::hto(hnFile, h3->s_cls(), *h3);
if ( ! result ) {
G4ExceptionDescription description;
description << " " << "saving histogram " << name << " failed";
G4Exception("G4CsvAnalysisManager::Write()",
"Analysis_W022", JustWarning, description);
return false;
}
hnFile.close();
#ifdef G4VERBOSE
if ( fState.GetVerboseL1() )
fState.GetVerboseL1()->Message("write", "file", fileName);
#endif
fFileManager->LockHistoDirectoryName();
}
}
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 true;
}
//_____________________________________________________________________________
G4bool G4CsvAnalysisManager::WriteP1()
{
const std::vector<tools::histo::p1d*>& p1Vector
= fP1Manager->GetP1Vector();
const std::vector<G4HnInformation*>& hnVector
= fP1Manager->GetHnVector();
if ( ! p1Vector.size() ) return true;
if ( ! G4Threading::IsWorkerThread() ) {
for ( G4int i=0; i<G4int(p1Vector.size()); ++i ) {
G4HnInformation* info = hnVector[i];
G4bool activation = info->GetActivation();
G4String name = info->GetName();
// skip writing if activation is enabled and P1 is inactivated
if ( fState.GetIsActivation() && ( ! activation ) ) continue;
tools::histo::p1d* p1 = p1Vector[i];
G4String fileName = fFileManager->GetHnFileName("p1", name);
std::ofstream hnFile(fileName);
G4bool result
= tools::wcsv::pto(hnFile, p1->s_cls(), *p1);
if ( ! result ) {
G4ExceptionDescription description;
description << " " << "saving profile " << name << " failed";
G4Exception("G4CsvAnalysisManager::Write()",
"Analysis_W022", JustWarning, description);
return false;
}
hnFile.close();
#ifdef G4VERBOSE
if ( fState.GetVerboseL1() )
fState.GetVerboseL1()->Message("write", "file", fileName);
#endif
fFileManager->LockProfileDirectoryName();
}
}
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 true;
}
//_____________________________________________________________________________
G4bool G4CsvAnalysisManager::WriteP2()
{
const std::vector<tools::histo::p2d*>& p2Vector
= fP2Manager->GetP2Vector();
const std::vector<G4HnInformation*>& hnVector
= fP2Manager->GetHnVector();
if ( ! p2Vector.size() ) return true;
if ( ! G4Threading::IsWorkerThread() ) {
for ( G4int i=0; i<G4int(p2Vector.size()); ++i ) {
G4HnInformation* info = hnVector[i];
G4bool activation = info->GetActivation();
G4String name = info->GetName();
// skip writing if activation is enabled and P2 is inactivated
if ( fState.GetIsActivation() && ( ! activation ) ) continue;
tools::histo::p2d* p2 = p2Vector[i];
G4String fileName = fFileManager->GetHnFileName("p2", name);
std::ofstream hnFile(fileName);
G4bool result
= tools::wcsv::pto(hnFile, p2->s_cls(), *p2);
if ( ! result ) {
G4ExceptionDescription description;
description << " " << "saving profile " << name << " failed";
G4Exception("G4CsvAnalysisManager::Write()",
"Analysis_W022", JustWarning, description);
return false;
}
hnFile.close();
#ifdef G4VERBOSE
if ( fState.GetVerboseL1() )
fState.GetVerboseL1()->Message("write", "file", fileName);
#endif
fFileManager->LockProfileDirectoryName();
}
}
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 true;
}
//_____________________________________________________________________________
G4bool G4CsvAnalysisManager::Reset()
{
// Reset histograms and ntuple
G4bool finalResult = true;
G4bool result = fH1Manager->Reset();
finalResult = finalResult && result;
result = fH2Manager->Reset();
finalResult = finalResult && result;
result = fH3Manager->Reset();
finalResult = finalResult && result;
result = fP1Manager->Reset();
finalResult = finalResult && result;
result = fP2Manager->Reset();
finalResult = finalResult && result;
result = fNtupleManager->Reset();
finalResult = finalResult && result;
return finalResult;
}
//_____________________________________________________________________________
G4bool G4CsvAnalysisManager::OpenFileImpl(const G4String& fileName)
{
G4bool finalResult = true;
// Only book file name in file manager
G4bool result = fFileManager->OpenFile(fileName);
G4bool result = fFileManager->SetFileName(fileName);
finalResult = finalResult && result;
// Only lock file name in file manager
result = fFileManager->OpenFile(fileName);
finalResult = finalResult && result;
// Histogram and profile files are created/closed indivudually for each
// object in WriteHn{Pn] function
// Create ntuples if they are booked
// (The files will be created with creating ntuples)
fNtupleManager->CreateNtuplesFromBooking();
return finalResult;
}
@@ -138,14 +454,63 @@ G4bool G4CsvAnalysisManager::OpenFileImpl(const G4String& fileName)
G4bool G4CsvAnalysisManager::WriteImpl()
{
// nothing to be done for Csv file
G4bool result = true;
G4bool finalResult = true;
#ifdef G4VERBOSE
if ( fState.GetVerboseL4() )
fState.GetVerboseL4()->Message("write", "files", "");
#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);
}
// H1
G4bool 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
//if ( IsAscii() ) {
// result = WriteAscii();
//}
#ifdef G4VERBOSE
if ( fState.GetVerboseL4() )
fState.GetVerboseL4()
->Message("write", "files", "", finalResult);
#endif
return result;
}
@@ -154,39 +519,31 @@ G4bool G4CsvAnalysisManager::CloseFileImpl()
{
G4bool finalResult = true;
#ifdef G4VERBOSE
if ( fState.GetVerboseL4() )
fState.GetVerboseL4()->Message("close", "files", "");
#endif
// Unlock file name only
G4bool result = fFileManager->CloseFile();
finalResult = finalResult && result;
// Histogram and profile files are created/closed indivudually for each
// object in WriteHn{Pn] function
// Close ntuple files
if ( ( ! G4AnalysisManagerState::IsMT() ) || ( ! fState.GetIsMaster() ) ) {
if ( ( ! G4Threading::IsMultithreadedApplication() ) ||
( ! fState.GetIsMaster() ) ) {
// In sequential mode or in MT mode only on workers
result = CloseNtupleFiles();
finalResult = finalResult && result;
}
// reset data
result = fNtupleManager->Reset();
result = Reset();
if ( ! result ) {
G4ExceptionDescription description;
description << " " << "Resetting data failed";
G4Exception("G4CsvAnalysisManager::CloseFile()",
"Analysis_W002", JustWarning, description);
"Analysis_W021", JustWarning, description);
result = false;
}
finalResult = finalResult && result;
#ifdef G4VERBOSE
if ( fState.GetVerboseL1() ) {
fState.GetVerboseL1()->Message("close", "files", "");
}
#endif
return finalResult;
}
@@ -0,0 +1,445 @@
//
// ********************************************************************
// * 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: G4CsvAnalysisReader.cc 74257 2013-10-02 14:24:55Z gcosmo $
// Author: Ivana Hrivnacova, 05/09/2014 (ivana@ipno.in2p3.fr)
#include "G4CsvAnalysisReader.hh"
#include "G4CsvRFileManager.hh"
#include "G4H1ToolsManager.hh"
#include "G4H2ToolsManager.hh"
#include "G4H3ToolsManager.hh"
#include "G4P1ToolsManager.hh"
#include "G4P2ToolsManager.hh"
#include "G4CsvRNtupleManager.hh"
#include "G4CsvRNtupleDescription.hh"
#include "G4AnalysisVerbose.hh"
#include "G4AnalysisUtilities.hh"
#include "G4Threading.hh"
#include <tools/aida_ntuple>
#include <tools/rcsv_histo>
#include <iostream>
#include <cstdio>
using namespace G4Analysis;
G4CsvAnalysisReader* G4CsvAnalysisReader::fgMasterInstance = 0;
G4ThreadLocal G4CsvAnalysisReader* G4CsvAnalysisReader::fgInstance = 0;
//
// utility functions
//
namespace {
//_____________________________________________________________________________
void* ReadObject(std::istream& hnFile,
const G4String& objectType,
const G4String& fileName,
const G4String& inFunction)
{
tools::rcsv::histo handler(hnFile);
std::string objectTypeInFile;
void* object;
G4bool verbose = false;
if ( ! handler.read(G4cout, objectTypeInFile, object, verbose) ) {
G4ExceptionDescription description;
description
<< " "
<< "Cannot get "<< objectType << " in file " << fileName;
G4String inFunctionFull = "G4CsvAnalysisReader::";
inFunctionFull.append(inFunction);
G4Exception(inFunctionFull, "Analysis_WR011", JustWarning, description);
return 0;
}
if ( objectTypeInFile != objectType ) {
G4ExceptionDescription description;
description
<< " "
<< "Object type read in "<< fileName
<< " does not match" << G4endl;
G4String inFunctionFull = "G4CsvAnalysisReader::";
inFunctionFull.append(inFunction);
G4Exception(inFunctionFull, "Analysis_WR011", JustWarning, description);
return 0;
}
return object;
}
}
//_____________________________________________________________________________
G4CsvAnalysisReader* G4CsvAnalysisReader::Instance()
{
if ( fgInstance == 0 ) {
G4bool isMaster = ! G4Threading::IsWorkerThread();
fgInstance = new G4CsvAnalysisReader(isMaster);
}
return fgInstance;
}
//_____________________________________________________________________________
G4CsvAnalysisReader::G4CsvAnalysisReader(G4bool isMaster)
: G4VAnalysisReader("Csv", isMaster),
fH1Manager(0),
fH2Manager(0),
fH3Manager(0),
fP1Manager(0),
fP2Manager(0),
fNtupleManager(0),
fFileManager(0)
{
if ( ( isMaster && fgMasterInstance ) || ( fgInstance ) ) {
G4ExceptionDescription description;
description
<< " "
<< "G4CsvAnalysisReader already exists."
<< "Cannot create another instance.";
G4Exception("G4CsvAnalysisReader::G4CsvAnalysisReader()",
"Analysis_F001", FatalException, description);
}
if ( isMaster ) fgMasterInstance = this;
fgInstance = this;
// Create managers
fH1Manager = new G4H1ToolsManager(fState);
fH2Manager = new G4H2ToolsManager(fState);
fH3Manager = new G4H3ToolsManager(fState);
fP1Manager = new G4P1ToolsManager(fState);
fP2Manager = new G4P2ToolsManager(fState);
fNtupleManager = new G4CsvRNtupleManager(fState);
fFileManager = new G4CsvRFileManager(fState);
// The managers will be deleted by the base class
// Set managers to base class
SetH1Manager(fH1Manager);
SetH2Manager(fH2Manager);
SetH3Manager(fH3Manager);
SetP1Manager(fP1Manager);
SetP2Manager(fP2Manager);
SetNtupleManager(fNtupleManager);
SetFileManager(fFileManager);
}
//_____________________________________________________________________________
G4CsvAnalysisReader::~G4CsvAnalysisReader()
{
if ( fState.GetIsMaster() ) fgMasterInstance = 0;
fgInstance = 0;
}
//
// private methods
//
//_____________________________________________________________________________
G4String G4CsvAnalysisReader::GetHnFileName(
const G4String& hnType,
const G4String& hnName,
const G4String& fileName,
G4bool isUserFileName) const
{
if ( isUserFileName ) {
return fFileManager->GetFullFileName(fileName);
}
else {
return fFileManager->GetHnFileName(hnType, hnName);
}
}
//_____________________________________________________________________________
G4bool G4CsvAnalysisReader::Reset()
{
// Reset histograms and ntuple
G4bool finalResult = true;
G4bool result = fH1Manager->Reset();
finalResult = finalResult && result;
result = fH2Manager->Reset();
finalResult = finalResult && result;
result = fNtupleManager->Reset();
finalResult = finalResult && result;
return finalResult;
}
//
// protected methods
//
//_____________________________________________________________________________
G4int G4CsvAnalysisReader::ReadH1Impl(const G4String& h1Name,
const G4String& fileName,
G4bool isUserFileName)
{
#ifdef G4VERBOSE
if ( fState.GetVerboseL4() )
fState.GetVerboseL4()->Message("get", "h1", h1Name);
#endif
// open file
G4String h1FileName = GetHnFileName("h1", h1Name, fileName, isUserFileName);
std::ifstream hnFile(h1FileName);
if ( ! hnFile.is_open() ) {
G4ExceptionDescription description;
description << " " << "Cannot open file " << h1FileName;
G4Exception("G4CsvAnalysisReader::ReadH1Impl()",
"Analysis_WR001", JustWarning, description);
return kInvalidId;
}
#ifdef G4VERBOSE
if ( fState.GetVerboseL1() )
fState.GetVerboseL1()
->Message("open", "read file", h1FileName);
#endif
void* object
= ReadObject(hnFile, tools::histo::h1d::s_class(), h1FileName, "ReadH1Impl");
if ( ! object ) return kInvalidId;
tools::histo::h1d* h1
= static_cast<tools::histo::h1d*>(object);
G4int id = fH1Manager->AddH1(h1Name, h1);
#ifdef G4VERBOSE
if ( fState.GetVerboseL2() )
fState.GetVerboseL2()->Message("read", "h1", h1Name, id > kInvalidId);
#endif
return id;
}
//_____________________________________________________________________________
G4int G4CsvAnalysisReader::ReadH2Impl(const G4String& h2Name,
const G4String& fileName,
G4bool isUserFileName)
{
#ifdef G4VERBOSE
if ( fState.GetVerboseL4() )
fState.GetVerboseL4()->Message("read", "h2", h2Name);
#endif
// open file
G4String h2FileName = GetHnFileName("h2", h2Name, fileName, isUserFileName);
std::ifstream hnFile(h2FileName);
if ( ! hnFile.is_open() ) {
G4ExceptionDescription description;
description << " " << "Cannot open file " << h2FileName;
G4Exception("G4CsvAnalysisReader::ReadH2Impl()",
"Analysis_WR001", JustWarning, description);
return kInvalidId;
}
#ifdef G4VERBOSE
if ( fState.GetVerboseL1() )
fState.GetVerboseL1()
->Message("open", "read file", h2FileName);
#endif
void* object
= ReadObject(hnFile, tools::histo::h2d::s_class(), h2FileName, "ReadH2Impl");
if ( ! object ) return kInvalidId;
tools::histo::h2d* h2
= static_cast<tools::histo::h2d*>(object);
G4int id = fH2Manager->AddH2(h2Name, h2);
#ifdef G4VERBOSE
if ( fState.GetVerboseL2() )
fState.GetVerboseL2()->Message("read", "h2", h2Name, id > kInvalidId);
#endif
return id;
}
//_____________________________________________________________________________
G4int G4CsvAnalysisReader::ReadH3Impl(const G4String& h3Name,
const G4String& fileName,
G4bool isUserFileName)
{
#ifdef G4VERBOSE
if ( fState.GetVerboseL4() )
fState.GetVerboseL4()->Message("read", "h3", h3Name);
#endif
// open file
G4String h3FileName = GetHnFileName("h3", h3Name, fileName, isUserFileName);
std::ifstream hnFile(h3FileName);
if ( ! hnFile.is_open() ) {
G4ExceptionDescription description;
description << " " << "Cannot open file " << h3FileName;
G4Exception("G4CsvAnalysisReader::ReadH3Impl()",
"Analysis_WR001", JustWarning, description);
return kInvalidId;
}
#ifdef G4VERBOSE
if ( fState.GetVerboseL1() )
fState.GetVerboseL1()
->Message("open", "read file", h3FileName);
#endif
void* object
= ReadObject(hnFile, tools::histo::h3d::s_class(), h3FileName, "ReadH3Impl");
if ( ! object ) return kInvalidId;
tools::histo::h3d* h3
= static_cast<tools::histo::h3d*>(object);
G4int id = fH3Manager->AddH3(h3Name, h3);
#ifdef G4VERBOSE
if ( fState.GetVerboseL2() )
fState.GetVerboseL2()->Message("read", "h3", h3Name, id > kInvalidId);
#endif
return id;
}
//_____________________________________________________________________________
G4int G4CsvAnalysisReader::ReadP1Impl(const G4String& p1Name,
const G4String& fileName,
G4bool isUserFileName)
{
#ifdef G4VERBOSE
if ( fState.GetVerboseL4() )
fState.GetVerboseL4()->Message("read", "p1", p1Name);
#endif
// open file
G4String p1FileName = GetHnFileName("p1", p1Name, fileName, isUserFileName);
std::ifstream hnFile(p1FileName);
if ( ! hnFile.is_open() ) {
G4ExceptionDescription description;
description << " " << "Cannot open file " << p1FileName;
G4Exception("G4CsvAnalysisReader::ReadP1Impl()",
"Analysis_WR001", JustWarning, description);
return kInvalidId;
}
#ifdef G4VERBOSE
if ( fState.GetVerboseL1() )
fState.GetVerboseL1()
->Message("open", "read file", p1FileName);
#endif
void* object
= ReadObject(hnFile, tools::histo::p1d::s_class(), fileName, "ReadP1Impl");
if ( ! object ) return kInvalidId;
tools::histo::p1d* p1
= static_cast<tools::histo::p1d*>(object);
G4int id = fP1Manager->AddP1(p1Name, p1);
#ifdef G4VERBOSE
if ( fState.GetVerboseL2() )
fState.GetVerboseL2()->Message("read", "p1", p1Name, id > kInvalidId);
#endif
return id;
}
//_____________________________________________________________________________
G4int G4CsvAnalysisReader::ReadP2Impl(const G4String& p2Name,
const G4String& fileName,
G4bool isUserFileName)
{
#ifdef G4VERBOSE
if ( fState.GetVerboseL4() )
fState.GetVerboseL4()->Message("read", "p2", p2Name);
#endif
// open file
G4String p2FileName = GetHnFileName("p2", p2Name, fileName, isUserFileName);
std::ifstream hnFile(p2FileName);
if ( ! hnFile.is_open() ) {
G4ExceptionDescription description;
description << " " << "Cannot open file " << p2FileName;
G4Exception("G4CsvAnalysisReader::ReadP2Impl()",
"Analysis_WR001", JustWarning, description);
return kInvalidId;
}
#ifdef G4VERBOSE
if ( fState.GetVerboseL1() )
fState.GetVerboseL1()
->Message("open", "read file", p2FileName);
#endif
void* object
= ReadObject(hnFile, tools::histo::p2d::s_class(), p2FileName, "ReadP2Impl");
if ( ! object ) return kInvalidId;
tools::histo::p2d* p2
= static_cast<tools::histo::p2d*>(object);
G4int id = fP2Manager->AddP2(p2Name, p2);
#ifdef G4VERBOSE
if ( fState.GetVerboseL2() )
fState.GetVerboseL2()->Message("read", "p2", p2Name, id > kInvalidId);
#endif
return id;
}
//_____________________________________________________________________________
G4int G4CsvAnalysisReader::ReadNtupleImpl(const G4String& ntupleName,
const G4String& fileName,
G4bool isUserFileName)
{
#ifdef G4VERBOSE
if ( fState.GetVerboseL4() )
fState.GetVerboseL4()->Message("read", "ntuple", ntupleName);
#endif
// Ntuples are saved per object and per thread
// but apply the ntuple name and the thread suffixes
// only if fileName is not provided explicitly
G4String fullFileName = fileName;
if ( ! isUserFileName ) {
fullFileName = fFileManager->GetNtupleFileName(ntupleName);
}
// Open file
if ( ! fFileManager->OpenRFile(fullFileName) ) return kInvalidId;
std::ifstream* ntupleFile
= fFileManager->GetRFile(fullFileName);
// Create ntuple
tools::rcsv::ntuple* rntuple = new tools::rcsv::ntuple(*ntupleFile);
G4int id
= fNtupleManager->SetNtuple(new G4CsvRNtupleDescription(rntuple));
#ifdef G4VERBOSE
if ( fState.GetVerboseL2() )
fState.GetVerboseL2()->Message("read", "ntuple", ntupleName, id > kInvalidId);
#endif
return id;
}
+2 -2
View File
@@ -75,7 +75,7 @@ G4bool G4CsvFileManager::CloseFile()
G4bool G4CsvFileManager::CreateNtupleFile(
G4CsvNtupleDescription* ntupleDescription)
{
G4String ntupleName = ntupleDescription->fNtupleBooking->m_name;
G4String ntupleName = ntupleDescription->fNtupleBooking->name();
#ifdef G4VERBOSE
if ( fState.GetVerboseL4() )
@@ -108,7 +108,7 @@ G4bool G4CsvFileManager::CreateNtupleFile(
G4bool G4CsvFileManager::CloseNtupleFile(
G4CsvNtupleDescription* ntupleDescription)
{
G4String ntupleName = ntupleDescription->fNtupleBooking->m_name;
G4String ntupleName = ntupleDescription->fNtupleBooking->name();
#ifdef G4VERBOSE
if ( fState.GetVerboseL4() )
+306 -79
View File
@@ -31,14 +31,22 @@
#include "G4CsvNtupleDescription.hh"
#include "G4CsvFileManager.hh"
#include "G4AnalysisManagerState.hh"
#include "G4AnalysisUtilities.hh"
#include "G4Threading.hh"
#include <iostream>
using namespace G4Analysis;
//_____________________________________________________________________________
G4CsvNtupleManager::G4CsvNtupleManager(const G4AnalysisManagerState& state)
: G4VNtupleManager(state),
fFileManager(0),
fNtupleVector()
fNtupleDescriptionVector(),
fNtupleVector(),
fIsCommentedHeader(true),
fIsHippoHeader(false)
{
}
@@ -46,7 +54,7 @@ G4CsvNtupleManager::G4CsvNtupleManager(const G4AnalysisManagerState& state)
G4CsvNtupleManager::~G4CsvNtupleManager()
{
std::vector<G4CsvNtupleDescription*>::iterator it;
for (it = fNtupleVector.begin(); it != fNtupleVector.end(); it++ ) {
for (it = fNtupleDescriptionVector.begin(); it != fNtupleDescriptionVector.end(); it++ ) {
delete (*it);
}
}
@@ -61,10 +69,7 @@ G4CsvNtupleManager::GetNtupleIColumn(G4int ntupleId, G4int columnId) const
{
G4CsvNtupleDescription* ntupleDecription
= GetNtupleInFunction(ntupleId, "GetNtupleIColumn");
if ( ! ntupleDecription ) {
// add exception
return 0;
}
if ( ! ntupleDecription ) return 0;
std::map<G4int, tools::wcsv::ntuple::column<int>* >& ntupleIColumnMap
= ntupleDecription->fNtupleIColumnMap;
@@ -73,9 +78,9 @@ G4CsvNtupleManager::GetNtupleIColumn(G4int ntupleId, G4int columnId) const
if ( it == ntupleIColumnMap.end() ) {
G4ExceptionDescription description;
description << " " << "ntupleId " << ntupleId
<< "column " << columnId << " does not exist.";
<< " columnId " << columnId << " does not exist.";
G4Exception("G4CsvNtupleManager::GetNtupleIColumn()",
"Analysis_W009", JustWarning, description);
"Analysis_W011", JustWarning, description);
return 0;
}
@@ -88,10 +93,7 @@ G4CsvNtupleManager::GetNtupleFColumn(G4int ntupleId, G4int columnId) const
{
G4CsvNtupleDescription* ntupleDecription
= GetNtupleInFunction(ntupleId, "GetNtupleFColumn");
if ( ! ntupleDecription ) {
// add exception
return 0;
}
if ( ! ntupleDecription ) return 0;
std::map<G4int, tools::wcsv::ntuple::column<float>* >& ntupleFColumnMap
= ntupleDecription->fNtupleFColumnMap;
@@ -100,9 +102,9 @@ G4CsvNtupleManager::GetNtupleFColumn(G4int ntupleId, G4int columnId) const
if ( it == ntupleFColumnMap.end() ) {
G4ExceptionDescription description;
description << " " << "ntupleId " << ntupleId
<< "column " << columnId << " does not exist.";
<< " columnId " << columnId << " does not exist.";
G4Exception("G4CsvNtupleManager::GetNtupleFColumn()",
"Analysis_W009", JustWarning, description);
"Analysis_W011", JustWarning, description);
return 0;
}
@@ -116,10 +118,7 @@ G4CsvNtupleManager::GetNtupleDColumn(G4int ntupleId, G4int columnId) const
{
G4CsvNtupleDescription* ntupleDecription
= GetNtupleInFunction(ntupleId, "GetNtupleDColumn");
if ( ! ntupleDecription ) {
// add exception
return 0;
}
if ( ! ntupleDecription ) return 0;
std::map<G4int, tools::wcsv::ntuple::column<double>* >& ntupleDColumnMap
= ntupleDecription->fNtupleDColumnMap;
@@ -128,9 +127,33 @@ G4CsvNtupleManager::GetNtupleDColumn(G4int ntupleId, G4int columnId) const
if ( it == ntupleDColumnMap.end() ) {
G4ExceptionDescription description;
description << " " << "ntupleId " << ntupleId
<< "column " << columnId << " does not exist.";
<< " columnId " << columnId << " does not exist.";
G4Exception("G4CsvNtupleManager::GetNtupleDColumn()",
"Analysis_W009", JustWarning, description);
"Analysis_W011", JustWarning, description);
return 0;
}
return it->second;
}
//_____________________________________________________________________________
tools::wcsv::ntuple::column<std::string>*
G4CsvNtupleManager::GetNtupleSColumn(G4int ntupleId, G4int columnId) const
{
G4CsvNtupleDescription* ntupleDecription
= GetNtupleInFunction(ntupleId, "GetNtupleSColumn");
if ( ! ntupleDecription ) return 0;
std::map<G4int, tools::wcsv::ntuple::column<std::string>* >& ntupleSColumnMap
= ntupleDecription->fNtupleSColumnMap;
std::map<G4int, tools::wcsv::ntuple::column<std::string>* >::const_iterator it
= ntupleSColumnMap.find(columnId);
if ( it == ntupleSColumnMap.end() ) {
G4ExceptionDescription description;
description << " " << "ntupleId " << ntupleId
<< " columnId " << columnId << " does not exist.";
G4Exception("G4CsvNtupleManager::GetNtupleSColumn()",
"Analysis_W011", JustWarning, description);
return 0;
}
@@ -143,20 +166,41 @@ G4CsvNtupleDescription* G4CsvNtupleManager::GetNtupleInFunction(G4int id,
G4bool /*onlyIfActive*/) const
{
G4int index = id - fFirstId;
if ( index < 0 || index >= G4int(fNtupleVector.size()) ) {
if ( index < 0 || index >= G4int(fNtupleDescriptionVector.size()) ) {
if ( warn) {
G4String inFunction = "G4CsvNtupleManager::";
inFunction += functionName;
G4ExceptionDescription description;
description << " " << "ntuple " << id << " does not exist.";
G4Exception(inFunction, "Analysis_W007", JustWarning, description);
G4Exception(inFunction, "Analysis_W011", JustWarning, description);
}
return 0;
}
return fNtupleVector[index];
return fNtupleDescriptionVector[index];
}
//_____________________________________________________________________________
G4bool G4CsvNtupleManager::WriteHeader(tools::wcsv::ntuple* ntuple) const
{
// Write header if ntuple already exists and if this option is activated.
// When both Hippo and Commented headers are selected, only Commented
// header, which reading is supported.
// Return false only if an error occurred.
if ( fIsCommentedHeader ) {
return ntuple->write_commented_header(G4cout);
}
// write hippo header (if activated and if not commented header)
if ( fIsHippoHeader ) {
ntuple->write_hippo_header();
return true;
}
return true;
}
//
// protected methods
//
@@ -167,18 +211,22 @@ void G4CsvNtupleManager::CreateNtuplesFromBooking()
// Create ntuple from ntuple_booking.
// Do not create ntuples on master thread
if ( G4AnalysisManagerState::IsMT() && fState.GetIsMaster() ) return;
if ( G4Threading::IsMultithreadedApplication() &&
fState.GetIsMaster() ) return;
std::vector<G4CsvNtupleDescription*>::iterator itn;
for (itn = fNtupleVector.begin(); itn != fNtupleVector.end(); itn++ ) {
for (itn = fNtupleDescriptionVector.begin(); itn != fNtupleDescriptionVector.end(); itn++ ) {
tools::ntuple_booking* ntupleBooking = (*itn)->fNtupleBooking;
if ( ! ntupleBooking ) continue;
// Do not create ntuple if it already exists
if ( (*itn)->fNtuple ) continue;
#ifdef G4VERBOSE
if ( fState.GetVerboseL4() )
fState.GetVerboseL4()
->Message("create from booking", "ntuple", ntupleBooking->m_name);
->Message("create from booking", "ntuple", ntupleBooking->name());
#endif
// create a file for this ntuple
@@ -187,39 +235,53 @@ void G4CsvNtupleManager::CreateNtuplesFromBooking()
// create ntuple
(*itn)->fNtuple
= new tools::wcsv::ntuple(*((*itn)->fFile), G4cerr, *ntupleBooking);
fNtupleVector.push_back((*itn)->fNtuple);
if ( ntupleBooking->m_columns.size() ) {
// write header (if activated)
if ( ! WriteHeader((*itn)->fNtuple) ) {
G4ExceptionDescription description;
description << " "
<< "Writing ntuple header has failed. ";
G4Exception("G4CsvNtupleManager::CreateNtupleFromBooking()",
"Analysis_W021", JustWarning, description);
}
if ( ntupleBooking->columns().size() ) {
// store ntuple columns in local maps
const std::vector<tools::ntuple_booking::col_t>& columns
= ntupleBooking->m_columns;
std::vector<tools::ntuple_booking::col_t>::const_iterator it;
const std::vector<tools::column_booking>& columns
= ntupleBooking->columns();
std::vector<tools::column_booking>::const_iterator it;
G4int index = 0;
for ( it = columns.begin(); it!=columns.end(); ++it) {
if ( (*it).second == tools::_cid(int(0) ) ) {
if ( it->cls_id() == tools::_cid(int(0) ) ) {
(*itn)->fNtupleIColumnMap[index++]
= (*itn)->fNtuple->find_column<int>((*it).first);
= (*itn)->fNtuple->find_column<int>(it->name());
}
else if ( (*it).second == tools::_cid(float(0) ) ) {
else if ( it->cls_id() == tools::_cid(float(0) ) ) {
(*itn)->fNtupleFColumnMap[index++]
= (*itn)->fNtuple->find_column<float>((*it).first);
= (*itn)->fNtuple->find_column<float>(it->name());
}
else if ( (*it).second== tools::_cid(double(0))) {
else if ( it->cls_id() == tools::_cid(double(0))) {
(*itn)->fNtupleDColumnMap[index++]
= (*itn)->fNtuple->find_column<double>((*it).first);
= (*itn)->fNtuple->find_column<double>(it->name());
}
else if ( it->cls_id() == tools::_cid(std::string(""))) {
(*itn)->fNtupleSColumnMap[index++]
= (*itn)->fNtuple->find_column<std::string>(it->name());
}
else {
G4ExceptionDescription description;
description << " "
<< "Unsupported column type " << (*it).first;
<< "Unsupported column type " << it->cls_id();
G4Exception("G4CsvNtupleManager::CreateNtupleFromBooking()",
"Analysis_W004", JustWarning, description);
"Analysis_W002", JustWarning, description);
}
}
}
#ifdef G4VERBOSE
if ( fState.GetVerboseL3() )
fState.GetVerboseL3()
->Message("create from booking", "ntuple", ntupleBooking->m_name);
->Message("create from booking", "ntuple", ntupleBooking->name());
#endif
}
}
@@ -227,17 +289,18 @@ void G4CsvNtupleManager::CreateNtuplesFromBooking()
//_____________________________________________________________________________
G4bool G4CsvNtupleManager::IsEmpty() const
{
return ! fNtupleVector.size();
return ! fNtupleDescriptionVector.size();
}
//_____________________________________________________________________________
G4bool G4CsvNtupleManager::Reset()
{
std::vector<G4CsvNtupleDescription*>::iterator it;
for (it = fNtupleVector.begin(); it != fNtupleVector.end(); it++ ) {
for (it = fNtupleDescriptionVector.begin(); it != fNtupleDescriptionVector.end(); it++ ) {
delete (*it)->fNtuple;
(*it)->fNtuple = 0;
}
fNtupleVector.clear();
return true;
}
@@ -253,13 +316,15 @@ tools::wcsv::ntuple* G4CsvNtupleManager::GetNtuple(G4int ntupleId) const
{
G4CsvNtupleDescription* ntupleDescription
= GetNtupleInFunction(ntupleId, "GetNtuple");
if ( ! ntupleDescription ) return 0;
return ntupleDescription->fNtuple;
}
//_____________________________________________________________________________
G4int G4CsvNtupleManager::CreateNtuple(const G4String& name,
const G4String& title)
const G4String& title)
{
#ifdef G4VERBOSE
if ( fState.GetVerboseL4() )
@@ -267,15 +332,14 @@ G4int G4CsvNtupleManager::CreateNtuple(const G4String& name,
#endif
// Create ntuple description
G4int index = fNtupleVector.size();
G4int index = fNtupleDescriptionVector.size();
G4CsvNtupleDescription* ntupleDescription
= new G4CsvNtupleDescription();
fNtupleVector.push_back(ntupleDescription);
fNtupleDescriptionVector.push_back(ntupleDescription);
// Create ntuple booking
ntupleDescription->fNtupleBooking = new tools::ntuple_booking();
ntupleDescription->fNtupleBooking->m_name = name;
ntupleDescription->fNtupleBooking->m_title = title;
ntupleDescription->fNtupleBooking
= new tools::ntuple_booking(name, title);
// ntuple booking object is deleted in destructor
// Create ntuple if the file is open (what means here that
@@ -285,6 +349,8 @@ G4int G4CsvNtupleManager::CreateNtuple(const G4String& name,
ntupleDescription->fNtuple
= new tools::wcsv::ntuple(*(ntupleDescription->fFile));
// ntuple object is deleted when closing a file
(ntupleDescription->fNtuple)->set_title(title);
fNtupleVector.push_back(ntupleDescription->fNtuple);
}
}
@@ -302,35 +368,57 @@ G4int G4CsvNtupleManager::CreateNtuple(const G4String& name,
}
//_____________________________________________________________________________
G4int G4CsvNtupleManager::CreateNtupleIColumn(const G4String& name)
G4int G4CsvNtupleManager::CreateNtupleIColumn(const G4String& name,
std::vector<int>* vector)
{
G4int ntupleId = fNtupleVector.size() + fFirstId - 1;
return CreateNtupleIColumn(ntupleId, name);
G4int ntupleId = fNtupleDescriptionVector.size() + fFirstId - 1;
return CreateNtupleIColumn(ntupleId, name, vector);
}
//_____________________________________________________________________________
G4int G4CsvNtupleManager::CreateNtupleFColumn(const G4String& name)
G4int G4CsvNtupleManager::CreateNtupleFColumn(const G4String& name,
std::vector<float>* vector)
{
G4int ntupleId = fNtupleVector.size() + fFirstId - 1;
return CreateNtupleFColumn(ntupleId, name);
G4int ntupleId = fNtupleDescriptionVector.size() + fFirstId - 1;
return CreateNtupleFColumn(ntupleId, name, vector);
}
//_____________________________________________________________________________
G4int G4CsvNtupleManager::CreateNtupleDColumn(const G4String& name)
G4int G4CsvNtupleManager::CreateNtupleDColumn(const G4String& name,
std::vector<double>* vector)
{
G4int ntupleId = fNtupleVector.size() + fFirstId - 1;
return CreateNtupleDColumn(ntupleId, name);
G4int ntupleId = fNtupleDescriptionVector.size() + fFirstId - 1;
return CreateNtupleDColumn(ntupleId, name, vector);
}
//_____________________________________________________________________________
G4int G4CsvNtupleManager::CreateNtupleSColumn(const G4String& name)
{
G4int ntupleId = fNtupleDescriptionVector.size() + fFirstId - 1;
return CreateNtupleSColumn(ntupleId, name);
}
//_____________________________________________________________________________
void G4CsvNtupleManager::FinishNtuple()
{
// nothing to be done here
G4int ntupleId = fNtupleDescriptionVector.size() + fFirstId - 1;
FinishNtuple(ntupleId);
}
//_____________________________________________________________________________
G4int G4CsvNtupleManager::CreateNtupleIColumn(G4int ntupleId, const G4String& name)
G4int G4CsvNtupleManager::CreateNtupleIColumn(G4int ntupleId,
const G4String& name,
std::vector<int>* vector)
{
if ( vector ) {
G4ExceptionDescription description;
description << " "
<< "Ntuple columns of vector are not supported." ;
G4Exception("G4CsvAnalysisManager::CreateNtupleIColumn",
"Analysis_W002", JustWarning, description);
return 0;
}
#ifdef G4VERBOSE
if ( fState.GetVerboseL4() ) {
G4ExceptionDescription description;
@@ -341,6 +429,8 @@ G4int G4CsvNtupleManager::CreateNtupleIColumn(G4int ntupleId, const G4String& na
G4CsvNtupleDescription* ntupleDescription
= GetNtupleInFunction(ntupleId, "CreateNtupleIColumn");
if ( ! ntupleDescription ) return kInvalidId;
tools::ntuple_booking* ntupleBooking
= ntupleDescription->fNtupleBooking;
@@ -349,12 +439,12 @@ G4int G4CsvNtupleManager::CreateNtupleIColumn(G4int ntupleId, const G4String& na
description << " "
<< "Ntuple " << ntupleId << " has to be created first. ";
G4Exception("G4CsvNtupleManager::CreateNtupleIColumn()",
"Analysis_W005", JustWarning, description);
return -1;
"Analysis_W002", JustWarning, description);
return kInvalidId;
}
// Save column info in booking
G4int index = ntupleBooking->m_columns.size();
G4int index = ntupleBooking->columns().size();
ntupleBooking->add_column<int>(name);
// Create column if ntuple already exists
@@ -378,8 +468,19 @@ G4int G4CsvNtupleManager::CreateNtupleIColumn(G4int ntupleId, const G4String& na
}
//_____________________________________________________________________________
G4int G4CsvNtupleManager::CreateNtupleFColumn(G4int ntupleId, const G4String& name)
G4int G4CsvNtupleManager::CreateNtupleFColumn(G4int ntupleId,
const G4String& name,
std::vector<float>* vector)
{
if ( vector ) {
G4ExceptionDescription description;
description << " "
<< "Ntuple columns of vector are not supported." ;
G4Exception("G4CsvAnalysisManager::CreateNtupleFColumn",
"Analysis_W002", JustWarning, description);
return 0;
}
#ifdef G4VERBOSE
if ( fState.GetVerboseL4() ) {
G4ExceptionDescription description;
@@ -390,6 +491,8 @@ G4int G4CsvNtupleManager::CreateNtupleFColumn(G4int ntupleId, const G4String& na
G4CsvNtupleDescription* ntupleDescription
= GetNtupleInFunction(ntupleId, "CreateNtupleFColumn");
if ( ! ntupleDescription ) return kInvalidId;
tools::ntuple_booking* ntupleBooking
= ntupleDescription->fNtupleBooking;
@@ -398,12 +501,12 @@ G4int G4CsvNtupleManager::CreateNtupleFColumn(G4int ntupleId, const G4String& na
description << " "
<< "Ntuple " << ntupleId << " has to be created first. ";
G4Exception("G4CsvNtupleManager::CreateNtupleFColumn()",
"Analysis_W005", JustWarning, description);
return -1;
"Analysis_W002", JustWarning, description);
return kInvalidId;
}
// Save column info in booking
G4int index = ntupleBooking->m_columns.size();
G4int index = ntupleBooking->columns().size();
ntupleBooking->add_column<float>(name);
// Create column if ntuple already exists
@@ -427,8 +530,19 @@ G4int G4CsvNtupleManager::CreateNtupleFColumn(G4int ntupleId, const G4String& na
}
//_____________________________________________________________________________
G4int G4CsvNtupleManager::CreateNtupleDColumn(G4int ntupleId, const G4String& name)
G4int G4CsvNtupleManager::CreateNtupleDColumn(G4int ntupleId,
const G4String& name,
std::vector<double>* vector)
{
if ( vector ) {
G4ExceptionDescription description;
description << " "
<< "Ntuple columns of vector are not supported." ;
G4Exception("G4CsvAnalysisManager::CreateNtupleDColumn",
"Analysis_W002", JustWarning, description);
return 0;
}
#ifdef G4VERBOSE
if ( fState.GetVerboseL4() ) {
G4ExceptionDescription description;
@@ -439,6 +553,8 @@ G4int G4CsvNtupleManager::CreateNtupleDColumn(G4int ntupleId, const G4String& na
G4CsvNtupleDescription* ntupleDescription
= GetNtupleInFunction(ntupleId, "CreateNtupleDColumn");
if ( ! ntupleDescription ) return kInvalidId;
tools::ntuple_booking* ntupleBooking
= ntupleDescription->fNtupleBooking;
@@ -447,12 +563,12 @@ G4int G4CsvNtupleManager::CreateNtupleDColumn(G4int ntupleId, const G4String& na
description << " "
<< "Ntuple " << ntupleId << " has to be created first. ";
G4Exception("G4CsvNtupleManager::CreateNtupleDColumn()",
"Analysis_W005", JustWarning, description);
return -1;
"Analysis_W002", JustWarning, description);
return kInvalidId;
}
// Save column info in booking
G4int index = ntupleBooking->m_columns.size();
G4int index = ntupleBooking->columns().size();
ntupleBooking->add_column<double>(name);
// Create column if ntuple already exists
@@ -476,9 +592,85 @@ G4int G4CsvNtupleManager::CreateNtupleDColumn(G4int ntupleId, const G4String& na
}
//_____________________________________________________________________________
void G4CsvNtupleManager::FinishNtuple(G4int /*ntupleId*/)
G4int G4CsvNtupleManager::CreateNtupleSColumn(G4int ntupleId,
const G4String& name)
{
/*
if ( vector ) {
G4ExceptionDescription description;
description << " "
<< "Ntuple columns of vector are not supported." ;
G4Exception("G4CsvAnalysisManager::CreateNtupleSColumn",
"Analysis_W002", JustWarning, description);
return 0;
}
*/
#ifdef G4VERBOSE
if ( fState.GetVerboseL4() ) {
G4ExceptionDescription description;
description << name << " ntupleId " << ntupleId;
fState.GetVerboseL4()->Message("create", "ntuple S column", description);
}
#endif
G4CsvNtupleDescription* ntupleDescription
= GetNtupleInFunction(ntupleId, "CreateNtupleSColumn");
if ( ! ntupleDescription ) return kInvalidId;
tools::ntuple_booking* ntupleBooking
= ntupleDescription->fNtupleBooking;
if ( ! ntupleBooking ) {
G4ExceptionDescription description;
description << " "
<< "Ntuple " << ntupleId << " has to be created first. ";
G4Exception("G4CsvNtupleManager::CreateNtupleSColumn()",
"Analysis_W002", JustWarning, description);
return kInvalidId;
}
// Save column info in booking
G4int index = ntupleBooking->columns().size();
ntupleBooking->add_column<std::string>(name);
// Create column if ntuple already exists
if ( ntupleDescription->fNtuple ) {
tools::wcsv::ntuple::column<std::string>* column
= ntupleDescription->fNtuple->create_column<std::string>(name);
ntupleDescription->fNtupleSColumnMap[index] = column;
}
fLockFirstNtupleColumnId = true;
#ifdef G4VERBOSE
if ( fState.GetVerboseL2() ) {
G4ExceptionDescription description;
description << name << " ntupleId " << ntupleId;
fState.GetVerboseL2()->Message("create", "ntuple S column", description);
}
#endif
return index + fFirstNtupleColumnId;
}
//_____________________________________________________________________________
void G4CsvNtupleManager::FinishNtuple(G4int ntupleId)
{
// nothing to be done here
// nothing to be done if hippo header is inactivated
G4CsvNtupleDescription* ntupleDescription
= GetNtupleInFunction(ntupleId, "FinishNtuple");
if ( ! ntupleDescription ) return;
// Write hippo header if ntuple already exists
if ( ntupleDescription->fNtuple ) {
if ( ! WriteHeader(ntupleDescription->fNtuple) ) {
G4ExceptionDescription description;
description << " "
<< "Writing ntuple header has failed. ";
G4Exception("G4CsvNtupleManager::Finish()",
"Analysis_W022", JustWarning, description);
}
}
}
//_____________________________________________________________________________
@@ -499,6 +691,13 @@ G4bool G4CsvNtupleManager::FillNtupleDColumn(G4int columnId, G4double value)
return FillNtupleDColumn(fFirstId, columnId, value);
}
//_____________________________________________________________________________
G4bool G4CsvNtupleManager::FillNtupleSColumn(G4int columnId,
const G4String& value)
{
return FillNtupleSColumn(fFirstId, columnId, value);
}
//_____________________________________________________________________________
G4bool G4CsvNtupleManager::AddNtupleRow()
{
@@ -514,9 +713,9 @@ G4bool G4CsvNtupleManager::FillNtupleIColumn(G4int ntupleId, G4int columnId,
if ( ! column ) {
G4ExceptionDescription description;
description << " " << "ntupleId " << ntupleId
<< "column " << columnId << " does not exist.";
<< " columnId " << columnId << " does not exist.";
G4Exception("G4CsvNtupleManager::FillNtupleIColumn()",
"Analysis_W009", JustWarning, description);
"Analysis_W011", JustWarning, description);
return false;
}
@@ -540,9 +739,9 @@ G4bool G4CsvNtupleManager::FillNtupleFColumn(G4int ntupleId, G4int columnId,
if ( ! column ) {
G4ExceptionDescription description;
description << " " << "ntupleId " << ntupleId
<< "column " << columnId << " does not exist.";
<< " columnId " << columnId << " does not exist.";
G4Exception("G4CsvNtupleManager::FillNtupleFColumn()",
"Analysis_W009", JustWarning, description);
"Analysis_W011", JustWarning, description);
return false;
}
@@ -567,9 +766,9 @@ G4bool G4CsvNtupleManager::FillNtupleDColumn(G4int ntupleId, G4int columnId,
if ( ! column ) {
G4ExceptionDescription description;
description << " " << "ntupleId " << ntupleId
<< "column " << columnId << " does not exist.";
<< " columnId " << columnId << " does not exist.";
G4Exception("G4CsvNtupleManager::FillNtupleDColumn()",
"Analysis_W009", JustWarning, description);
"Analysis_W011", JustWarning, description);
return false;
}
@@ -585,6 +784,33 @@ G4bool G4CsvNtupleManager::FillNtupleDColumn(G4int ntupleId, G4int columnId,
return true;
}
//_____________________________________________________________________________
G4bool G4CsvNtupleManager::FillNtupleSColumn(G4int ntupleId, G4int columnId,
const G4String& value)
{
tools::wcsv::ntuple::column<std::string>* column
= GetNtupleSColumn(ntupleId, columnId);
if ( ! column ) {
G4ExceptionDescription description;
description << " " << "ntupleId " << ntupleId
<< " columnId " << columnId << " does not exist.";
G4Exception("G4CsvNtupleManager::FillNtupleSColumn()",
"Analysis_W011", JustWarning, description);
return false;
}
column->fill(value);
#ifdef G4VERBOSE
if ( fState.GetVerboseL4() ) {
G4ExceptionDescription description;
description << " ntupleId " << ntupleId
<< " columnId " << columnId << " value " << value;
fState.GetVerboseL4()->Message("fill", "ntuple S column", description);
}
#endif
return true;
}
//_____________________________________________________________________________
G4bool G4CsvNtupleManager::AddNtupleRow(G4int ntupleId)
{
@@ -598,12 +824,13 @@ G4bool G4CsvNtupleManager::AddNtupleRow(G4int ntupleId)
G4CsvNtupleDescription* ntupleDescription
= GetNtupleInFunction(ntupleId, "AddNtupleRow");
if ( ! ntupleDescription ) return false;
if ( ! ntupleDescription || ! ntupleDescription->fNtuple ) {
if ( ! ntupleDescription->fNtuple ) {
G4ExceptionDescription description;
description << " " << "ntuple does not exist. ";
G4Exception("G4CsvNtupleManager::AddNtupleRow()",
"Analysis_W008", JustWarning, description);
"Analysis_W022", JustWarning, description);
return false;
}
@@ -0,0 +1,100 @@
//
// ********************************************************************
// * 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: G4CsvRFileManager.cc 70604 2013-06-03 11:27:06Z ihrivnac $
// Author: Ivana Hrivnacova, 21/10/2014 (ivana@ipno.in2p3.fr)
#include "G4CsvRFileManager.hh"
#include "G4AnalysisManagerState.hh"
//_____________________________________________________________________________
G4CsvRFileManager::G4CsvRFileManager(const G4AnalysisManagerState& state)
: G4BaseFileManager(state),
fRFiles()
{
}
//_____________________________________________________________________________
G4CsvRFileManager::~G4CsvRFileManager()
{
for (G4int i=0; i<G4int(fRFiles.size()); ++i) {
delete fRFiles[i];
}
}
//
// public methods
//
//_____________________________________________________________________________
G4bool G4CsvRFileManager::OpenRFile(const G4String& fileName)
{
#ifdef G4VERBOSE
if ( fState.GetVerboseL4() )
fState.GetVerboseL4()->Message("open", "read analysis file", fileName);
#endif
// create new file
std::ifstream* newFile = new std::ifstream(fileName);
if ( ! newFile->is_open() ) {
G4ExceptionDescription description;
description << " " << "Cannot open file " << fileName;
G4Exception("G4CsvAnalysisReader::OpenRFile()",
"Analysis_WR001", JustWarning, description);
return false;
}
// add file in a map and delete the previous file if it exists
std::map<G4String, std::ifstream*>::iterator it
= fRFiles.find(fileName);
if ( it != fRFiles.end() ) {
delete it->second;
it->second = newFile;
}
else {
fRFiles[fileName] = newFile;
}
#ifdef G4VERBOSE
if ( fState.GetVerboseL1() )
fState.GetVerboseL1()
->Message("open", "read analysis file", fileName);
#endif
return true;
}
//_____________________________________________________________________________
std::ifstream* G4CsvRFileManager::GetRFile(const G4String& fileName) const
{
std::map<G4String, std::ifstream*>::const_iterator it
= fRFiles.find(fileName);
if ( it != fRFiles.end() )
return it->second;
else {
return 0;
}
}
@@ -0,0 +1,453 @@
//
// ********************************************************************
// * 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$
// Author: Ivana Hrivnacova, 25/07/2014 (ivana@ipno.in2p3.fr)
#include "G4CsvRNtupleManager.hh"
#include "G4CsvRNtupleDescription.hh"
#include "G4AnalysisManagerState.hh"
//_____________________________________________________________________________
G4CsvRNtupleManager::G4CsvRNtupleManager(const G4AnalysisManagerState& state)
: G4VRNtupleManager(state),
fNtupleVector()
{
}
//_____________________________________________________________________________
G4CsvRNtupleManager::~G4CsvRNtupleManager()
{
std::vector<G4CsvRNtupleDescription*>::iterator it;
for (it = fNtupleVector.begin(); it != fNtupleVector.end(); it++ ) {
delete (*it);
}
}
//
// private methods
//
//_____________________________________________________________________________
G4CsvRNtupleDescription* G4CsvRNtupleManager::GetNtupleInFunction(G4int id,
G4String functionName, G4bool warn) const
{
G4int index = id - fFirstId;
if ( index < 0 || index >= G4int(fNtupleVector.size()) ) {
if ( warn) {
G4String inFunction = "G4CsvRNtupleManager::";
inFunction += functionName;
G4ExceptionDescription description;
description << " " << "ntuple " << id << " does not exist.";
G4Exception(inFunction, "Analysis_WR011", JustWarning, description);
}
return 0;
}
return fNtupleVector[index];
}
//
// protected methods
//
//_____________________________________________________________________________
G4bool G4CsvRNtupleManager::IsEmpty() const
{
return ! fNtupleVector.size();
}
//_____________________________________________________________________________
G4bool G4CsvRNtupleManager::Reset()
{
// Reset ntuples
std::vector<G4CsvRNtupleDescription*>::iterator it;
for (it = fNtupleVector.begin(); it != fNtupleVector.end(); it++ ) {
// ntuple is deleted automatically when file is closed
// delete (*it)->fNtuple;
(*it)->fNtuple=0;
}
return true;
}
//_____________________________________________________________________________
tools::rcsv::ntuple* G4CsvRNtupleManager::GetNtuple() const
{
return GetNtuple(fFirstId);
}
//_____________________________________________________________________________
tools::rcsv::ntuple* G4CsvRNtupleManager::GetNtuple(G4int ntupleId) const
{
G4CsvRNtupleDescription* rntupleDescription
= GetNtupleInFunction(ntupleId, "GetNtuple");
if ( ! rntupleDescription ) return 0;
return rntupleDescription->fNtuple;
}
//_____________________________________________________________________________
G4int G4CsvRNtupleManager::SetNtuple(G4CsvRNtupleDescription* rntupleDescription)
{
G4int id = fNtupleVector.size() + fFirstId;
fNtupleVector.push_back(rntupleDescription);
return id;
}
//_____________________________________________________________________________
G4bool G4CsvRNtupleManager::SetNtupleIColumn(const G4String& columnName,
G4int& value)
{
return SetNtupleIColumn(fFirstId, columnName, value);
}
//_____________________________________________________________________________
G4bool G4CsvRNtupleManager::SetNtupleFColumn(const G4String& columnName,
G4float& value)
{
return SetNtupleFColumn(fFirstId, columnName, value);
}
//_____________________________________________________________________________
G4bool G4CsvRNtupleManager::SetNtupleDColumn(const G4String& columnName,
G4double& value)
{
return SetNtupleDColumn(fFirstId, columnName, value);
}
//_____________________________________________________________________________
G4bool G4CsvRNtupleManager::SetNtupleIColumn(const G4String& columnName,
std::vector<G4int>& vector)
{
return SetNtupleIColumn(fFirstId, columnName, vector);
}
//_____________________________________________________________________________
G4bool G4CsvRNtupleManager::SetNtupleFColumn(const G4String& columnName,
std::vector<G4float>& vector)
{
return SetNtupleFColumn(fFirstId, columnName, vector);
}
//_____________________________________________________________________________
G4bool G4CsvRNtupleManager::SetNtupleDColumn(const G4String& columnName,
std::vector<G4double>& vector)
{
return SetNtupleDColumn(fFirstId, columnName, vector);
}
//_____________________________________________________________________________
G4bool G4CsvRNtupleManager::SetNtupleSColumn(const G4String& columnName,
G4String& value)
{
return SetNtupleSColumn(fFirstId, columnName, value);
}
//_____________________________________________________________________________
G4bool G4CsvRNtupleManager::SetNtupleIColumn(G4int ntupleId,
const G4String& columnName,
G4int& value)
{
#ifdef G4VERBOSE
if ( fState.GetVerboseL4() ) {
G4ExceptionDescription description;
description << " ntupleId " << ntupleId << " " << columnName;
fState.GetVerboseL4()->Message("set", "ntuple I column", description);
}
#endif
G4CsvRNtupleDescription* ntupleDescription
= GetNtupleInFunction(ntupleId, "SetNtupleIColumn");
if ( ! ntupleDescription ) return false;
tools::ntuple_binding* ntupleBinding = ntupleDescription->fNtupleBinding;
ntupleBinding->add_column(columnName, value);
#ifdef G4VERBOSE
if ( fState.GetVerboseL2() ) {
G4ExceptionDescription description;
description << " ntupleId " << ntupleId << " " << columnName;
fState.GetVerboseL2()->Message("set", "ntuple I colum", description, true);
}
#endif
return true;
}
//_____________________________________________________________________________
G4bool G4CsvRNtupleManager::SetNtupleFColumn(G4int ntupleId,
const G4String& columnName,
G4float& value)
{
#ifdef G4VERBOSE
if ( fState.GetVerboseL4() ) {
G4ExceptionDescription description;
description << " ntupleId " << ntupleId << " " << columnName;
fState.GetVerboseL4()->Message("set", "ntuple F column", description);
}
#endif
G4CsvRNtupleDescription* ntupleDescription
= GetNtupleInFunction(ntupleId, "SetNtupleFColumn");
if ( ! ntupleDescription ) return false;
tools::ntuple_binding* ntupleBinding = ntupleDescription->fNtupleBinding;
ntupleBinding->add_column(columnName, value);
#ifdef G4VERBOSE
if ( fState.GetVerboseL2() ) {
G4ExceptionDescription description;
description << " ntupleId " << ntupleId << " " << columnName;
fState.GetVerboseL2()->Message("set", "ntuple F colum", description, true);
}
#endif
return true;
}
//_____________________________________________________________________________
G4bool G4CsvRNtupleManager::SetNtupleDColumn(G4int ntupleId,
const G4String& columnName,
G4double& value)
{
#ifdef G4VERBOSE
if ( fState.GetVerboseL4() ) {
G4ExceptionDescription description;
description << " ntupleId " << ntupleId << " " << columnName;
fState.GetVerboseL4()->Message("set", "ntuple D column", description);
}
#endif
G4CsvRNtupleDescription* ntupleDescription
= GetNtupleInFunction(ntupleId, "SetNtupleDColumn");
if ( ! ntupleDescription ) return false;
tools::ntuple_binding* ntupleBinding = ntupleDescription->fNtupleBinding;
ntupleBinding->add_column(columnName, value);
#ifdef G4VERBOSE
if ( fState.GetVerboseL2() ) {
G4ExceptionDescription description;
description << " ntupleId " << ntupleId << " " << columnName;
fState.GetVerboseL2()->Message("set", "ntuple D colum", description, true);
}
#endif
return true;
}
//_____________________________________________________________________________
G4bool G4CsvRNtupleManager::SetNtupleIColumn(G4int ntupleId,
const G4String& columnName,
std::vector<G4int>& vector)
{
#ifdef G4VERBOSE
if ( fState.GetVerboseL4() ) {
G4ExceptionDescription description;
description << " ntupleId " << ntupleId << " " << columnName;
fState.GetVerboseL4()->Message("set", "ntuple I column", description);
}
#endif
G4CsvRNtupleDescription* ntupleDescription
= GetNtupleInFunction(ntupleId, "SetNtupleIColumn");
if ( ! ntupleDescription ) return false;
tools::ntuple_binding* ntupleBinding = ntupleDescription->fNtupleBinding;
ntupleBinding->add_column(columnName, vector);
#ifdef G4VERBOSE
if ( fState.GetVerboseL2() ) {
G4ExceptionDescription description;
description << " ntupleId " << ntupleId << " " << columnName;
fState.GetVerboseL2()->Message("set", "ntuple I colum", description, true);
}
#endif
return true;
}
//_____________________________________________________________________________
G4bool G4CsvRNtupleManager::SetNtupleFColumn(G4int ntupleId,
const G4String& columnName,
std::vector<G4float>& vector)
{
#ifdef G4VERBOSE
if ( fState.GetVerboseL4() ) {
G4ExceptionDescription description;
description << " ntupleId " << ntupleId << " " << columnName;
fState.GetVerboseL4()->Message("set", "ntuple F column of vector", description);
}
#endif
G4CsvRNtupleDescription* ntupleDescription
= GetNtupleInFunction(ntupleId, "SetNtupleFColumn");
if ( ! ntupleDescription ) return false;
tools::ntuple_binding* ntupleBinding = ntupleDescription->fNtupleBinding;
ntupleBinding->add_column(columnName, vector);
#ifdef G4VERBOSE
if ( fState.GetVerboseL2() ) {
G4ExceptionDescription description;
description << " ntupleId " << ntupleId << " " << columnName;
fState.GetVerboseL2()->Message("set", "ntuple F colum", description, true);
}
#endif
return true;
}
//_____________________________________________________________________________
G4bool G4CsvRNtupleManager::SetNtupleDColumn(G4int ntupleId,
const G4String& columnName,
std::vector<G4double>& vector)
{
#ifdef G4VERBOSE
if ( fState.GetVerboseL4() ) {
G4ExceptionDescription description;
description << " ntupleId " << ntupleId << " " << columnName;
fState.GetVerboseL4()->Message("set", "ntuple D column of vector", description);
}
#endif
G4CsvRNtupleDescription* ntupleDescription
= GetNtupleInFunction(ntupleId, "SetNtupleDColumn");
if ( ! ntupleDescription ) return false;
tools::ntuple_binding* ntupleBinding = ntupleDescription->fNtupleBinding;
ntupleBinding->add_column(columnName, vector);
#ifdef G4VERBOSE
if ( fState.GetVerboseL2() ) {
G4ExceptionDescription description;
description << " ntupleId " << ntupleId << " " << columnName;
fState.GetVerboseL2()->Message("set", "ntuple D colum", description, true);
}
#endif
return true;
}
//_____________________________________________________________________________
G4bool G4CsvRNtupleManager::SetNtupleSColumn(G4int ntupleId,
const G4String& columnName,
G4String& value)
{
#ifdef G4VERBOSE
if ( fState.GetVerboseL4() ) {
G4ExceptionDescription description;
description << " ntupleId " << ntupleId << " " << columnName;
fState.GetVerboseL4()->Message("set", "ntuple S column", description);
}
#endif
G4CsvRNtupleDescription* ntupleDescription
= GetNtupleInFunction(ntupleId, "SetNtupleSColumn");
if ( ! ntupleDescription ) return false;
tools::ntuple_binding* ntupleBinding = ntupleDescription->fNtupleBinding;
ntupleBinding->add_column(columnName, value);
#ifdef G4VERBOSE
if ( fState.GetVerboseL2() ) {
G4ExceptionDescription description;
description << " ntupleId " << ntupleId << " " << columnName;
fState.GetVerboseL2()->Message("set", "ntuple S colum", description, true);
}
#endif
return true;
}
//_____________________________________________________________________________
G4bool G4CsvRNtupleManager::GetNtupleRow()
{
return GetNtupleRow(fFirstId);
}
//_____________________________________________________________________________
G4bool G4CsvRNtupleManager::GetNtupleRow(G4int ntupleId)
{
#ifdef G4VERBOSE
if ( fState.GetVerboseL4() ) {
G4ExceptionDescription description;
description << " ntupleId " << ntupleId;
fState.GetVerboseL4()->Message("get", "ntuple row", description);
}
#endif
G4CsvRNtupleDescription* ntupleDescription
= GetNtupleInFunction(ntupleId, "GetNtupleRow");
if ( ! ntupleDescription ) return false;
tools::rcsv::ntuple* ntuple = ntupleDescription->fNtuple;
G4bool isInitialized = ntupleDescription->fIsInitialized;
if ( ! isInitialized ) {
tools::ntuple_binding* ntupleBinding = ntupleDescription->fNtupleBinding;
if ( ! ntuple->initialize(G4cout, *ntupleBinding) ) {
G4ExceptionDescription description;
description
<< " "
<< "Ntuple initialization failed !!";
G4Exception("G4CsvRNtuple::GetNtupleRow()",
"Analysis_WR021", JustWarning, description);
return false;
}
ntupleDescription->fIsInitialized = true;
ntuple->start();
}
G4bool next = ntuple->next();
if ( next ) {
if ( ! ntuple->get_row() ) {
G4ExceptionDescription description;
description
<< " "
<< "Ntuple get_row() failed !!";
G4Exception("G4CsvRNtuple::GetNtupleRow()",
"Analysis_WR021", JustWarning, description);
return false;
}
}
#ifdef G4VERBOSE
if ( fState.GetVerboseL2() ) {
G4ExceptionDescription description;
description << " ntupleId " << ntupleId;
fState.GetVerboseL2()->Message("get", "ntuple row", description, true);
}
#endif
return next;
}