Import Geant4 10.0.0 source tree
This commit is contained in:
@@ -0,0 +1,192 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * 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: G4CsvAnalysisManager.cc 74257 2013-10-02 14:24:55Z gcosmo $
|
||||
|
||||
// Author: Ivana Hrivnacova, 18/06/2013 (ivana@ipno.in2p3.fr)
|
||||
|
||||
#include "G4CsvAnalysisManager.hh"
|
||||
#include "G4CsvFileManager.hh"
|
||||
#include "G4H1DummyManager.hh"
|
||||
#include "G4H2DummyManager.hh"
|
||||
#include "G4CsvNtupleManager.hh"
|
||||
#include "G4AnalysisVerbose.hh"
|
||||
#include "G4UnitsTable.hh"
|
||||
#include "G4Threading.hh"
|
||||
#include "G4AutoLock.hh"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
G4CsvAnalysisManager* G4CsvAnalysisManager::fgMasterInstance = 0;
|
||||
G4ThreadLocal G4CsvAnalysisManager* G4CsvAnalysisManager::fgInstance = 0;
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4CsvAnalysisManager* G4CsvAnalysisManager::Instance()
|
||||
{
|
||||
if ( fgInstance == 0 ) {
|
||||
G4bool isMaster = ! G4Threading::IsWorkerThread();
|
||||
fgInstance = new G4CsvAnalysisManager(isMaster);
|
||||
}
|
||||
|
||||
return fgInstance;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4CsvAnalysisManager::G4CsvAnalysisManager(G4bool isMaster)
|
||||
: G4VAnalysisManager("Csv", isMaster),
|
||||
fNtupleManager(0),
|
||||
fFileManager(0)
|
||||
{
|
||||
if ( ( isMaster && fgMasterInstance ) || ( fgInstance ) ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " "
|
||||
<< "G4CsvAnalysisManager already exists."
|
||||
<< "Cannot create another instance.";
|
||||
G4Exception("G4CsvAnalysisManager::G4CsvAnalysisManager()",
|
||||
"Analysis_F001", FatalException, description);
|
||||
}
|
||||
|
||||
if ( isMaster ) fgMasterInstance = this;
|
||||
fgInstance = this;
|
||||
|
||||
// Create managers
|
||||
fH1Manager = new G4H1DummyManager(fState);
|
||||
fH2Manager = new G4H2DummyManager(fState);
|
||||
fNtupleManager = new G4CsvNtupleManager(fState);
|
||||
fFileManager = new G4CsvFileManager(fState);
|
||||
fNtupleManager->SetFileManager(fFileManager);
|
||||
// The managers will be deleted by the base class
|
||||
|
||||
// Set managers to base class
|
||||
SetH1Manager(fH1Manager);
|
||||
SetH2Manager(fH2Manager);
|
||||
SetNtupleManager(fNtupleManager);
|
||||
SetFileManager(fFileManager);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4CsvAnalysisManager::~G4CsvAnalysisManager()
|
||||
{
|
||||
if ( fState.GetIsMaster() ) fgMasterInstance = 0;
|
||||
fgInstance = 0;
|
||||
}
|
||||
|
||||
//
|
||||
// private methods
|
||||
//
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4CsvAnalysisManager::CloseNtupleFiles()
|
||||
{
|
||||
const std::vector<G4CsvNtupleDescription*>& ntupleVector
|
||||
= fNtupleManager->GetNtupleVector();
|
||||
|
||||
// Close ntuple files
|
||||
std::vector<G4CsvNtupleDescription*>::const_iterator it;
|
||||
for (it = ntupleVector.begin(); it != ntupleVector.end(); it++ ) {
|
||||
fFileManager->CloseNtupleFile((*it));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// protected methods
|
||||
//
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4CsvAnalysisManager::OpenFileImpl(const G4String& fileName)
|
||||
{
|
||||
G4bool finalResult = true;
|
||||
|
||||
// Only book file name in file manager
|
||||
G4bool result = fFileManager->OpenFile(fileName);
|
||||
finalResult = finalResult && result;
|
||||
|
||||
// Create ntuples if they are booked
|
||||
// (The files will be created with creating ntuples)
|
||||
fNtupleManager->CreateNtuplesFromBooking();
|
||||
|
||||
|
||||
return finalResult;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4CsvAnalysisManager::WriteImpl()
|
||||
{
|
||||
// nothing to be done for Csv file
|
||||
G4bool result = true;
|
||||
|
||||
// Write ASCII if activated
|
||||
// Not available
|
||||
//if ( IsAscii() ) {
|
||||
// result = WriteAscii();
|
||||
//}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
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;
|
||||
|
||||
// Close ntuple files
|
||||
if ( ( ! G4AnalysisManagerState::IsMT() ) || ( ! fState.GetIsMaster() ) ) {
|
||||
// In sequential mode or in MT mode only on workers
|
||||
result = CloseNtupleFiles();
|
||||
finalResult = finalResult && result;
|
||||
}
|
||||
|
||||
// reset data
|
||||
result = fNtupleManager->Reset();
|
||||
if ( ! result ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " " << "Resetting data failed";
|
||||
G4Exception("G4CsvAnalysisManager::CloseFile()",
|
||||
"Analysis_W002", JustWarning, description);
|
||||
result = false;
|
||||
}
|
||||
finalResult = finalResult && result;
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL1() ) {
|
||||
fState.GetVerboseL1()->Message("close", "files", "");
|
||||
}
|
||||
#endif
|
||||
|
||||
return finalResult;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,130 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * 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: G4CsvFileManager.cc 70604 2013-06-03 11:27:06Z ihrivnac $
|
||||
|
||||
// Author: Ivana Hrivnacova, 18/06/2013 (ivana@ipno.in2p3.fr)
|
||||
|
||||
#include "G4CsvFileManager.hh"
|
||||
#include "G4AnalysisManagerState.hh"
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4CsvFileManager::G4CsvFileManager(const G4AnalysisManagerState& state)
|
||||
: G4VFileManager(state)
|
||||
{
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4CsvFileManager::~G4CsvFileManager()
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// public methods
|
||||
//
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4CsvFileManager::OpenFile(const G4String& fileName)
|
||||
{
|
||||
// Keep file name
|
||||
fFileName = fileName;
|
||||
|
||||
fLockFileName = true;
|
||||
fLockNtupleDirectoryName = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4CsvFileManager::WriteFile()
|
||||
{
|
||||
// nothing to be done for Csv file
|
||||
return true;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4CsvFileManager::CloseFile()
|
||||
{
|
||||
fLockFileName = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4CsvFileManager::CreateNtupleFile(
|
||||
G4CsvNtupleDescription* ntupleDescription)
|
||||
{
|
||||
G4String ntupleName = ntupleDescription->fNtupleBooking->m_name;
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() )
|
||||
fState.GetVerboseL4()
|
||||
->Message("create", "file", GetNtupleFileName(ntupleName));
|
||||
#endif
|
||||
|
||||
std::ofstream* ntupleFile
|
||||
= new std::ofstream(GetNtupleFileName(ntupleName));
|
||||
if ( ntupleFile->fail() ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " " << "Cannot open file "
|
||||
<< GetNtupleFileName(ntupleName);
|
||||
G4Exception("G4CsvFileManager::CreateNtupleFile()",
|
||||
"Analysis_W001", JustWarning, description);
|
||||
return false;
|
||||
}
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL1() )
|
||||
fState.GetVerboseL1()
|
||||
->Message("create", "file", GetNtupleFileName(ntupleName));
|
||||
#endif
|
||||
|
||||
ntupleDescription->fFile = ntupleFile;
|
||||
return true;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4CsvFileManager::CloseNtupleFile(
|
||||
G4CsvNtupleDescription* ntupleDescription)
|
||||
{
|
||||
G4String ntupleName = ntupleDescription->fNtupleBooking->m_name;
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() )
|
||||
fState.GetVerboseL4()
|
||||
->Message("close", "file", GetNtupleFileName(ntupleName));
|
||||
#endif
|
||||
|
||||
// close file
|
||||
ntupleDescription->fFile->close();
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL1() )
|
||||
fState.GetVerboseL1()
|
||||
->Message("close", "file", GetNtupleFileName(ntupleName));
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,620 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * 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: G4CsvNtupleManager.cc 70604 2013-06-03 11:27:06Z ihrivnac $
|
||||
|
||||
// Author: Ivana Hrivnacova, 18/06/2013 (ivana@ipno.in2p3.fr)
|
||||
|
||||
#include "G4CsvNtupleManager.hh"
|
||||
#include "G4CsvNtupleDescription.hh"
|
||||
#include "G4CsvFileManager.hh"
|
||||
#include "G4AnalysisManagerState.hh"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4CsvNtupleManager::G4CsvNtupleManager(const G4AnalysisManagerState& state)
|
||||
: G4VNtupleManager(state),
|
||||
fFileManager(0),
|
||||
fNtupleVector()
|
||||
{
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4CsvNtupleManager::~G4CsvNtupleManager()
|
||||
{
|
||||
std::vector<G4CsvNtupleDescription*>::iterator it;
|
||||
for (it = fNtupleVector.begin(); it != fNtupleVector.end(); it++ ) {
|
||||
delete (*it);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// private methods
|
||||
//
|
||||
|
||||
//_____________________________________________________________________________
|
||||
tools::wcsv::ntuple::column<int>*
|
||||
G4CsvNtupleManager::GetNtupleIColumn(G4int ntupleId, G4int columnId) const
|
||||
{
|
||||
G4CsvNtupleDescription* ntupleDecription
|
||||
= GetNtupleInFunction(ntupleId, "GetNtupleIColumn");
|
||||
if ( ! ntupleDecription ) {
|
||||
// add exception
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::map<G4int, tools::wcsv::ntuple::column<int>* >& ntupleIColumnMap
|
||||
= ntupleDecription->fNtupleIColumnMap;
|
||||
std::map<G4int, tools::wcsv::ntuple::column<int>* >::const_iterator it
|
||||
= ntupleIColumnMap.find(columnId);
|
||||
if ( it == ntupleIColumnMap.end() ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " " << "ntupleId " << ntupleId
|
||||
<< "column " << columnId << " does not exist.";
|
||||
G4Exception("G4CsvNtupleManager::GetNtupleIColumn()",
|
||||
"Analysis_W009", JustWarning, description);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return it->second;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
tools::wcsv::ntuple::column<float>*
|
||||
G4CsvNtupleManager::GetNtupleFColumn(G4int ntupleId, G4int columnId) const
|
||||
{
|
||||
G4CsvNtupleDescription* ntupleDecription
|
||||
= GetNtupleInFunction(ntupleId, "GetNtupleFColumn");
|
||||
if ( ! ntupleDecription ) {
|
||||
// add exception
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::map<G4int, tools::wcsv::ntuple::column<float>* >& ntupleFColumnMap
|
||||
= ntupleDecription->fNtupleFColumnMap;
|
||||
std::map<G4int, tools::wcsv::ntuple::column<float>* >::const_iterator it
|
||||
= ntupleFColumnMap.find(columnId);
|
||||
if ( it == ntupleFColumnMap.end() ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " " << "ntupleId " << ntupleId
|
||||
<< "column " << columnId << " does not exist.";
|
||||
G4Exception("G4CsvNtupleManager::GetNtupleFColumn()",
|
||||
"Analysis_W009", JustWarning, description);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return it->second;
|
||||
}
|
||||
|
||||
|
||||
//_____________________________________________________________________________
|
||||
tools::wcsv::ntuple::column<double>*
|
||||
G4CsvNtupleManager::GetNtupleDColumn(G4int ntupleId, G4int columnId) const
|
||||
{
|
||||
G4CsvNtupleDescription* ntupleDecription
|
||||
= GetNtupleInFunction(ntupleId, "GetNtupleDColumn");
|
||||
if ( ! ntupleDecription ) {
|
||||
// add exception
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::map<G4int, tools::wcsv::ntuple::column<double>* >& ntupleDColumnMap
|
||||
= ntupleDecription->fNtupleDColumnMap;
|
||||
std::map<G4int, tools::wcsv::ntuple::column<double>* >::const_iterator it
|
||||
= ntupleDColumnMap.find(columnId);
|
||||
if ( it == ntupleDColumnMap.end() ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " " << "ntupleId " << ntupleId
|
||||
<< "column " << columnId << " does not exist.";
|
||||
G4Exception("G4CsvNtupleManager::GetNtupleDColumn()",
|
||||
"Analysis_W009", JustWarning, description);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return it->second;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4CsvNtupleDescription* G4CsvNtupleManager::GetNtupleInFunction(G4int id,
|
||||
G4String functionName, G4bool warn,
|
||||
G4bool /*onlyIfActive*/) const
|
||||
{
|
||||
G4int index = id - fFirstId;
|
||||
if ( index < 0 || index >= G4int(fNtupleVector.size()) ) {
|
||||
if ( warn) {
|
||||
G4String inFunction = "G4CsvNtupleManager::";
|
||||
inFunction += functionName;
|
||||
G4ExceptionDescription description;
|
||||
description << " " << "ntuple " << id << " does not exist.";
|
||||
G4Exception(inFunction, "Analysis_W007", JustWarning, description);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
return fNtupleVector[index];
|
||||
}
|
||||
|
||||
//
|
||||
// protected methods
|
||||
//
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void G4CsvNtupleManager::CreateNtuplesFromBooking()
|
||||
{
|
||||
// Create ntuple from ntuple_booking.
|
||||
|
||||
// Do not create ntuples on master thread
|
||||
if ( G4AnalysisManagerState::IsMT() && fState.GetIsMaster() ) return;
|
||||
|
||||
std::vector<G4CsvNtupleDescription*>::iterator itn;
|
||||
for (itn = fNtupleVector.begin(); itn != fNtupleVector.end(); itn++ ) {
|
||||
|
||||
tools::ntuple_booking* ntupleBooking = (*itn)->fNtupleBooking;
|
||||
if ( ! ntupleBooking ) continue;
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() )
|
||||
fState.GetVerboseL4()
|
||||
->Message("create from booking", "ntuple", ntupleBooking->m_name);
|
||||
#endif
|
||||
|
||||
// create a file for this ntuple
|
||||
if ( ! fFileManager->CreateNtupleFile((*itn)) ) continue;
|
||||
|
||||
// create ntuple
|
||||
(*itn)->fNtuple
|
||||
= new tools::wcsv::ntuple(*((*itn)->fFile), G4cerr, *ntupleBooking);
|
||||
|
||||
if ( ntupleBooking->m_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;
|
||||
G4int index = 0;
|
||||
for ( it = columns.begin(); it!=columns.end(); ++it) {
|
||||
if ( (*it).second == tools::_cid(int(0) ) ) {
|
||||
(*itn)->fNtupleIColumnMap[index++]
|
||||
= (*itn)->fNtuple->find_column<int>((*it).first);
|
||||
}
|
||||
else if ( (*it).second == tools::_cid(float(0) ) ) {
|
||||
(*itn)->fNtupleFColumnMap[index++]
|
||||
= (*itn)->fNtuple->find_column<float>((*it).first);
|
||||
}
|
||||
else if ( (*it).second== tools::_cid(double(0))) {
|
||||
(*itn)->fNtupleDColumnMap[index++]
|
||||
= (*itn)->fNtuple->find_column<double>((*it).first);
|
||||
}
|
||||
else {
|
||||
G4ExceptionDescription description;
|
||||
description << " "
|
||||
<< "Unsupported column type " << (*it).first;
|
||||
G4Exception("G4CsvNtupleManager::CreateNtupleFromBooking()",
|
||||
"Analysis_W004", JustWarning, description);
|
||||
}
|
||||
}
|
||||
}
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL3() )
|
||||
fState.GetVerboseL3()
|
||||
->Message("create from booking", "ntuple", ntupleBooking->m_name);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4CsvNtupleManager::IsEmpty() const
|
||||
{
|
||||
return ! fNtupleVector.size();
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4CsvNtupleManager::Reset()
|
||||
{
|
||||
std::vector<G4CsvNtupleDescription*>::iterator it;
|
||||
for (it = fNtupleVector.begin(); it != fNtupleVector.end(); it++ ) {
|
||||
delete (*it)->fNtuple;
|
||||
(*it)->fNtuple = 0;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
tools::wcsv::ntuple* G4CsvNtupleManager::GetNtuple() const
|
||||
{
|
||||
return GetNtuple(fFirstId);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
tools::wcsv::ntuple* G4CsvNtupleManager::GetNtuple(G4int ntupleId) const
|
||||
{
|
||||
G4CsvNtupleDescription* ntupleDescription
|
||||
= GetNtupleInFunction(ntupleId, "GetNtuple");
|
||||
|
||||
return ntupleDescription->fNtuple;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4int G4CsvNtupleManager::CreateNtuple(const G4String& name,
|
||||
const G4String& title)
|
||||
{
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() )
|
||||
fState.GetVerboseL4()->Message("create", "ntuple", name);
|
||||
#endif
|
||||
|
||||
// Create ntuple description
|
||||
G4int index = fNtupleVector.size();
|
||||
G4CsvNtupleDescription* ntupleDescription
|
||||
= new G4CsvNtupleDescription();
|
||||
fNtupleVector.push_back(ntupleDescription);
|
||||
|
||||
// Create ntuple booking
|
||||
ntupleDescription->fNtupleBooking = new tools::ntuple_booking();
|
||||
ntupleDescription->fNtupleBooking->m_name = name;
|
||||
ntupleDescription->fNtupleBooking->m_title = title;
|
||||
// ntuple booking object is deleted in destructor
|
||||
|
||||
// Create ntuple if the file is open (what means here that
|
||||
// a filename was already set)
|
||||
if ( fFileManager->GetFileName().size() ) {
|
||||
if ( fFileManager->CreateNtupleFile(ntupleDescription) ) {
|
||||
ntupleDescription->fNtuple
|
||||
= new tools::wcsv::ntuple(*(ntupleDescription->fFile));
|
||||
// ntuple object is deleted when closing a file
|
||||
}
|
||||
}
|
||||
|
||||
fLockFirstId = true;
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL2() ) {
|
||||
G4ExceptionDescription description;
|
||||
description << name << " ntupleId " << index + fFirstId;
|
||||
fState.GetVerboseL2()->Message("create", "ntuple", description);
|
||||
}
|
||||
#endif
|
||||
|
||||
return index + fFirstId;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4int G4CsvNtupleManager::CreateNtupleIColumn(const G4String& name)
|
||||
{
|
||||
G4int ntupleId = fNtupleVector.size() + fFirstId - 1;
|
||||
return CreateNtupleIColumn(ntupleId, name);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4int G4CsvNtupleManager::CreateNtupleFColumn(const G4String& name)
|
||||
{
|
||||
G4int ntupleId = fNtupleVector.size() + fFirstId - 1;
|
||||
return CreateNtupleFColumn(ntupleId, name);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4int G4CsvNtupleManager::CreateNtupleDColumn(const G4String& name)
|
||||
{
|
||||
G4int ntupleId = fNtupleVector.size() + fFirstId - 1;
|
||||
return CreateNtupleDColumn(ntupleId, name);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void G4CsvNtupleManager::FinishNtuple()
|
||||
{
|
||||
// nothing to be done here
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4int G4CsvNtupleManager::CreateNtupleIColumn(G4int ntupleId, const G4String& name)
|
||||
{
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() ) {
|
||||
G4ExceptionDescription description;
|
||||
description << name << " ntupleId " << ntupleId;
|
||||
fState.GetVerboseL4()->Message("create", "ntuple I column", description);
|
||||
}
|
||||
#endif
|
||||
|
||||
G4CsvNtupleDescription* ntupleDescription
|
||||
= GetNtupleInFunction(ntupleId, "CreateNtupleIColumn");
|
||||
tools::ntuple_booking* ntupleBooking
|
||||
= ntupleDescription->fNtupleBooking;
|
||||
|
||||
if ( ! ntupleBooking ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " "
|
||||
<< "Ntuple " << ntupleId << " has to be created first. ";
|
||||
G4Exception("G4CsvNtupleManager::CreateNtupleIColumn()",
|
||||
"Analysis_W005", JustWarning, description);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Save column info in booking
|
||||
G4int index = ntupleBooking->m_columns.size();
|
||||
ntupleBooking->add_column<int>(name);
|
||||
|
||||
// Create column if ntuple already exists
|
||||
if ( ntupleDescription->fNtuple ) {
|
||||
tools::wcsv::ntuple::column<int>* column
|
||||
= ntupleDescription->fNtuple->create_column<int>(name);
|
||||
ntupleDescription->fNtupleIColumnMap[index] = column;
|
||||
}
|
||||
|
||||
fLockFirstNtupleColumnId = true;
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL2() ) {
|
||||
G4ExceptionDescription description;
|
||||
description << name << " ntupleId " << ntupleId;
|
||||
fState.GetVerboseL2()->Message("create", "ntuple I column", description);
|
||||
}
|
||||
#endif
|
||||
|
||||
return index + fFirstNtupleColumnId;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4int G4CsvNtupleManager::CreateNtupleFColumn(G4int ntupleId, const G4String& name)
|
||||
{
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() ) {
|
||||
G4ExceptionDescription description;
|
||||
description << name << " ntupleId " << ntupleId;
|
||||
fState.GetVerboseL4()->Message("create", "ntuple F column", description);
|
||||
}
|
||||
#endif
|
||||
|
||||
G4CsvNtupleDescription* ntupleDescription
|
||||
= GetNtupleInFunction(ntupleId, "CreateNtupleFColumn");
|
||||
tools::ntuple_booking* ntupleBooking
|
||||
= ntupleDescription->fNtupleBooking;
|
||||
|
||||
if ( ! ntupleBooking ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " "
|
||||
<< "Ntuple " << ntupleId << " has to be created first. ";
|
||||
G4Exception("G4CsvNtupleManager::CreateNtupleFColumn()",
|
||||
"Analysis_W005", JustWarning, description);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Save column info in booking
|
||||
G4int index = ntupleBooking->m_columns.size();
|
||||
ntupleBooking->add_column<float>(name);
|
||||
|
||||
// Create column if ntuple already exists
|
||||
if ( ntupleDescription->fNtuple ) {
|
||||
tools::wcsv::ntuple::column<float>* column
|
||||
= ntupleDescription->fNtuple->create_column<float>(name);
|
||||
ntupleDescription->fNtupleFColumnMap[index] = column;
|
||||
}
|
||||
|
||||
fLockFirstNtupleColumnId = true;
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL2() ) {
|
||||
G4ExceptionDescription description;
|
||||
description << name << " ntupleId " << ntupleId;
|
||||
fState.GetVerboseL2()->Message("create", "ntuple F column", description);
|
||||
}
|
||||
#endif
|
||||
|
||||
return index + fFirstNtupleColumnId;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4int G4CsvNtupleManager::CreateNtupleDColumn(G4int ntupleId, const G4String& name)
|
||||
{
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() ) {
|
||||
G4ExceptionDescription description;
|
||||
description << name << " ntupleId " << ntupleId;
|
||||
fState.GetVerboseL4()->Message("create", "ntuple D column", description);
|
||||
}
|
||||
#endif
|
||||
|
||||
G4CsvNtupleDescription* ntupleDescription
|
||||
= GetNtupleInFunction(ntupleId, "CreateNtupleDColumn");
|
||||
tools::ntuple_booking* ntupleBooking
|
||||
= ntupleDescription->fNtupleBooking;
|
||||
|
||||
if ( ! ntupleBooking ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " "
|
||||
<< "Ntuple " << ntupleId << " has to be created first. ";
|
||||
G4Exception("G4CsvNtupleManager::CreateNtupleDColumn()",
|
||||
"Analysis_W005", JustWarning, description);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Save column info in booking
|
||||
G4int index = ntupleBooking->m_columns.size();
|
||||
ntupleBooking->add_column<double>(name);
|
||||
|
||||
// Create column if ntuple already exists
|
||||
if ( ntupleDescription->fNtuple ) {
|
||||
tools::wcsv::ntuple::column<double>* column
|
||||
= ntupleDescription->fNtuple->create_column<double>(name);
|
||||
ntupleDescription->fNtupleDColumnMap[index] = column;
|
||||
}
|
||||
|
||||
fLockFirstNtupleColumnId = true;
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL2() ) {
|
||||
G4ExceptionDescription description;
|
||||
description << name << " ntupleId " << ntupleId;
|
||||
fState.GetVerboseL2()->Message("create", "ntuple D column", description);
|
||||
}
|
||||
#endif
|
||||
|
||||
return index + fFirstNtupleColumnId;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void G4CsvNtupleManager::FinishNtuple(G4int /*ntupleId*/)
|
||||
{
|
||||
// nothing to be done here
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4CsvNtupleManager::FillNtupleIColumn(G4int columnId, G4int value)
|
||||
{
|
||||
return FillNtupleIColumn(fFirstId, columnId, value);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4CsvNtupleManager::FillNtupleFColumn(G4int columnId, G4float value)
|
||||
{
|
||||
return FillNtupleFColumn(fFirstId, columnId, value);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4CsvNtupleManager::FillNtupleDColumn(G4int columnId, G4double value)
|
||||
{
|
||||
return FillNtupleDColumn(fFirstId, columnId, value);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4CsvNtupleManager::AddNtupleRow()
|
||||
{
|
||||
return AddNtupleRow(fFirstId);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4CsvNtupleManager::FillNtupleIColumn(G4int ntupleId, G4int columnId,
|
||||
G4int value)
|
||||
{
|
||||
tools::wcsv::ntuple::column<int>* column
|
||||
= GetNtupleIColumn(ntupleId, columnId);
|
||||
if ( ! column ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " " << "ntupleId " << ntupleId
|
||||
<< "column " << columnId << " does not exist.";
|
||||
G4Exception("G4CsvNtupleManager::FillNtupleIColumn()",
|
||||
"Analysis_W009", 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 I column", description);
|
||||
}
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4CsvNtupleManager::FillNtupleFColumn(G4int ntupleId, G4int columnId,
|
||||
G4float value)
|
||||
{
|
||||
tools::wcsv::ntuple::column<float>* column
|
||||
= GetNtupleFColumn(ntupleId, columnId);
|
||||
if ( ! column ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " " << "ntupleId " << ntupleId
|
||||
<< "column " << columnId << " does not exist.";
|
||||
G4Exception("G4CsvNtupleManager::FillNtupleFColumn()",
|
||||
"Analysis_W009", 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 F column", description);
|
||||
}
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4CsvNtupleManager::FillNtupleDColumn(G4int ntupleId, G4int columnId,
|
||||
G4double value)
|
||||
{
|
||||
tools::wcsv::ntuple::column<double>* column
|
||||
= GetNtupleDColumn(ntupleId, columnId);
|
||||
if ( ! column ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " " << "ntupleId " << ntupleId
|
||||
<< "column " << columnId << " does not exist.";
|
||||
G4Exception("G4CsvNtupleManager::FillNtupleDColumn()",
|
||||
"Analysis_W009", 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 D column", description);
|
||||
}
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4CsvNtupleManager::AddNtupleRow(G4int ntupleId)
|
||||
{
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " ntupleId " << ntupleId;
|
||||
fState.GetVerboseL4()->Message("add", "ntuple row", description);
|
||||
}
|
||||
#endif
|
||||
|
||||
G4CsvNtupleDescription* ntupleDescription
|
||||
= GetNtupleInFunction(ntupleId, "AddNtupleRow");
|
||||
|
||||
if ( ! ntupleDescription || ! ntupleDescription->fNtuple ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " " << "ntuple does not exist. ";
|
||||
G4Exception("G4CsvNtupleManager::AddNtupleRow()",
|
||||
"Analysis_W008", JustWarning, description);
|
||||
return false;
|
||||
}
|
||||
|
||||
ntupleDescription->fNtuple->add_row();
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " ntupleId " << ntupleId;
|
||||
fState.GetVerboseL4()->Message("add", "ntuple row", description);
|
||||
}
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
Reference in New Issue
Block a user