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
+220 -19
View File
@@ -23,7 +23,7 @@
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
// $Id: G4XmlAnalysisManager.cc 74257 2013-10-02 14:24:55Z gcosmo $
// $Id: G4XmlAnalysisManager.cc 85317 2014-10-27 15:58:15Z gcosmo $
// Author: Ivana Hrivnacova, 18/06/2013 (ivana@ipno.in2p3.fr)
@@ -31,7 +31,11 @@
#include "G4XmlFileManager.hh"
#include "G4H1ToolsManager.hh"
#include "G4H2ToolsManager.hh"
#include "G4H3ToolsManager.hh"
#include "G4P1ToolsManager.hh"
#include "G4P2ToolsManager.hh"
#include "G4XmlNtupleManager.hh"
#include "G4AnalysisManagerState.hh"
#include "G4Threading.hh"
#include "G4AutoLock.hh"
@@ -44,6 +48,12 @@ namespace {
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;
}
G4XmlAnalysisManager* G4XmlAnalysisManager::fgMasterInstance = 0;
@@ -65,6 +75,9 @@ G4XmlAnalysisManager::G4XmlAnalysisManager(G4bool isMaster)
: G4VAnalysisManager("Xml", isMaster),
fH1Manager(0),
fH2Manager(0),
fH3Manager(0),
fP1Manager(0),
fP2Manager(0),
fNtupleManager(0),
fFileManager(0)
{
@@ -83,6 +96,9 @@ G4XmlAnalysisManager::G4XmlAnalysisManager(G4bool isMaster)
// Create managers
fH1Manager = new G4H1ToolsManager(fState);
fH2Manager = new G4H2ToolsManager(fState);
fH3Manager = new G4H3ToolsManager(fState);
fP1Manager = new G4P1ToolsManager(fState);
fP2Manager = new G4P2ToolsManager(fState);
fNtupleManager = new G4XmlNtupleManager(fState);
fFileManager = new G4XmlFileManager(fState);
fNtupleManager->SetFileManager(fFileManager);
@@ -91,6 +107,9 @@ G4XmlAnalysisManager::G4XmlAnalysisManager(G4bool isMaster)
// Set managers to base class
SetH1Manager(fH1Manager);
SetH2Manager(fH2Manager);
SetH3Manager(fH3Manager);
SetP1Manager(fP1Manager);
SetP2Manager(fP2Manager);
SetNtupleManager(fNtupleManager);
SetFileManager(fFileManager);
}
@@ -120,8 +139,8 @@ G4bool G4XmlAnalysisManager::WriteH1()
for ( G4int i=0; i<G4int(h1Vector.size()); ++i ) {
G4HnInformation* info = hnVector[i];
G4bool activation = info->fActivation;
G4String name = info->fName;
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];
@@ -138,7 +157,7 @@ G4bool G4XmlAnalysisManager::WriteH1()
G4ExceptionDescription description;
description << " " << "saving histogram " << name << " failed";
G4Exception("G4XmlAnalysisManager::Write()",
"Analysis_W003", JustWarning, description);
"Analysis_W022", JustWarning, description);
return false;
}
fFileManager->LockHistoDirectoryName();
@@ -170,8 +189,8 @@ G4bool G4XmlAnalysisManager::WriteH2()
// h2 histograms
for ( G4int i=0; i<G4int(h2Vector.size()); ++i ) {
G4HnInformation* info = hnVector[i];
G4bool activation = info->fActivation;
G4String name = info->fName;
G4bool activation = info->GetActivation();
G4String name = info->GetName();
// skip writing if inactivated
if ( fState.GetIsActivation() && ( ! activation ) ) continue;
tools::histo::h2d* h2 = h2Vector[i];
@@ -188,7 +207,7 @@ G4bool G4XmlAnalysisManager::WriteH2()
G4ExceptionDescription description;
description << " " << "saving histogram " << name << " failed";
G4Exception("G4XmlAnalysisManager::Write()",
"Analysis_W003", JustWarning, description);
"Analysis_W022", JustWarning, description);
return false;
}
fFileManager->LockHistoDirectoryName();
@@ -205,11 +224,159 @@ G4bool G4XmlAnalysisManager::WriteH2()
return true;
}
//_____________________________________________________________________________
G4bool G4XmlAnalysisManager::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];
#ifdef G4VERBOSE
if ( fState.GetVerboseL3() )
fState.GetVerboseL3()->Message("write", "h3d", name);
#endif
G4String path = "/";
path.append(fFileManager->GetHistoDirectoryName());
std::ofstream* hnFile = fFileManager->GetHnFile();
G4bool result
= tools::waxml::write(*hnFile, *h3, path, name);
if ( ! result ) {
G4ExceptionDescription description;
description << " " << "saving histogram " << name << " failed";
G4Exception("G4XmlAnalysisManager::Write()",
"Analysis_W022", JustWarning, description);
return false;
}
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 G4XmlAnalysisManager::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];
#ifdef G4VERBOSE
if ( fState.GetVerboseL3() )
fState.GetVerboseL3()->Message("write", "p1d", name);
#endif
G4String path = "/";
path.append(fFileManager->GetProfileDirectoryName());
std::ofstream* hnFile = fFileManager->GetHnFile();
G4bool result
= tools::waxml::write(*hnFile, *p1, path, name);
if ( ! result ) {
G4ExceptionDescription description;
description << " " << "saving profile " << name << " failed";
G4Exception("G4XmlAnalysisManager::Write()",
"Analysis_W022", JustWarning, description);
return false;
}
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 G4XmlAnalysisManager::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];
#ifdef G4VERBOSE
if ( fState.GetVerboseL3() )
fState.GetVerboseL3()->Message("write", "p2d", name);
#endif
G4String path = "/";
path.append(fFileManager->GetProfileDirectoryName());
std::ofstream* hnFile = fFileManager->GetHnFile();
G4bool result
= tools::waxml::write(*hnFile, *p2, path, name);
if ( ! result ) {
G4ExceptionDescription description;
description << " " << "saving profile " << name << " failed";
G4Exception("G4XmlAnalysisManager::Write()",
"Analysis_W022", JustWarning, description);
return false;
}
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 G4XmlAnalysisManager::WriteNtuple()
{
const std::vector<G4XmlNtupleDescription*>& ntupleVector
= fNtupleManager->GetNtupleVector();
= fNtupleManager->GetNtupleDescriptionVector();
for ( G4int i=0; i<G4int(ntupleVector.size()); ++i ) {
if ( ntupleVector[i]->fNtuple ) ntupleVector[i]->fNtuple->write_trailer();
@@ -222,7 +389,7 @@ G4bool G4XmlAnalysisManager::WriteNtuple()
G4bool G4XmlAnalysisManager::CloseNtupleFiles()
{
const std::vector<G4XmlNtupleDescription*>& ntupleVector
= fNtupleManager->GetNtupleVector();
= fNtupleManager->GetNtupleDescriptionVector();
// Close ntuple files
std::vector<G4XmlNtupleDescription*>::const_iterator it;
@@ -247,6 +414,15 @@ G4bool G4XmlAnalysisManager::Reset()
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;
@@ -308,7 +484,9 @@ G4bool G4XmlAnalysisManager::WriteImpl()
WriteNtuple();
if ( ! fgMasterInstance &&
( ( ! fH1Manager->IsEmpty() ) || ( ! fH2Manager->IsEmpty() ) ) ) {
( ( ! fH1Manager->IsEmpty() ) || ( ! fH2Manager->IsEmpty() ) ||
( ! fH3Manager->IsEmpty() ) || ( ! fP1Manager->IsEmpty() ) ||
( ! fP2Manager->IsEmpty() ) ) ) {
G4ExceptionDescription description;
description
@@ -316,7 +494,7 @@ G4bool G4XmlAnalysisManager::WriteImpl()
<< G4endl
<< " " << "Histogram data will not be merged.";
G4Exception("G4XmlAnalysisManager::Write()",
"Analysis_W014", JustWarning, description);
"Analysis_W031", JustWarning, description);
// Create Hn file per thread
G4bool result = fFileManager->CreateHnFile();
@@ -331,6 +509,18 @@ G4bool G4XmlAnalysisManager::WriteImpl()
result = WriteH2();
finalResult = finalResult && result;
// H3
result = WriteH3();
finalResult = finalResult && result;
// P1
result = WriteP1();
finalResult = finalResult && result;
// P2
result = WriteP2();
finalResult = finalResult && result;
// Write ASCII if activated
if ( IsAscii() ) {
result = WriteAscii(fFileManager->GetFileName());
@@ -340,7 +530,7 @@ G4bool G4XmlAnalysisManager::WriteImpl()
#ifdef G4VERBOSE
if ( fState.GetVerboseL1() )
fState.GetVerboseL1()
->Message("write", "files", fFileManager->GetFullFileName(), finalResult);
->Message("write", "file", fFileManager->GetFullFileName(), finalResult);
#endif
return finalResult;
@@ -365,7 +555,8 @@ G4bool G4XmlAnalysisManager::CloseFileImpl()
finalResult = finalResult && result;
// 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;
@@ -377,15 +568,25 @@ G4bool G4XmlAnalysisManager::CloseFileImpl()
G4ExceptionDescription description;
description << " " << "Resetting data failed";
G4Exception("G4XmlAnalysisManager::CloseFile()",
"Analysis_W002", JustWarning, description);
"Analysis_W021", JustWarning, description);
}
finalResult = finalResult && result;
// delete files if empty
// (ntuple files are created only if an ntuple is created)
if ( fFileManager->GetHnFile() &&
fH1Manager->IsEmpty() && fH2Manager->IsEmpty() ) {
std::remove(fFileManager->GetFullFileName());
fH1Manager->IsEmpty() && fH2Manager->IsEmpty() && fH3Manager->IsEmpty() &&
fP1Manager->IsEmpty() && fP2Manager->IsEmpty() ) {
result = ! std::remove(fFileManager->GetFullFileName());
// std::remove returns 0 when success
if ( ! result ) {
G4ExceptionDescription description;
description << " " << "Removing file "
<< fFileManager->GetFullFileName() << " failed";
G4Exception("G4XmlAnalysisManager::CloseFile()",
"Analysis_W021", JustWarning, description);
}
finalResult = finalResult && result;
#ifdef G4VERBOSE
if ( fState.GetVerboseL1() )
fState.GetVerboseL1()
@@ -394,9 +595,9 @@ G4bool G4XmlAnalysisManager::CloseFileImpl()
}
else {
#ifdef G4VERBOSE
if ( fState.GetVerboseL1() )
fState.GetVerboseL1()
->Message("close", "files", fFileManager->GetFullFileName());
if ( fState.GetVerboseL2() )
fState.GetVerboseL2()
->Message("close", "files", "");
#endif
}
@@ -0,0 +1,349 @@
//
// ********************************************************************
// * 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: G4XmlAnalysisReader.cc 74257 2013-10-02 14:24:55Z gcosmo $
// Author: Ivana Hrivnacova, 25/07/2014 (ivana@ipno.in2p3.fr)
#include "G4XmlAnalysisReader.hh"
#include "G4XmlRFileManager.hh"
#include "G4H1ToolsManager.hh"
#include "G4H2ToolsManager.hh"
#include "G4H3ToolsManager.hh"
#include "G4P1ToolsManager.hh"
#include "G4P2ToolsManager.hh"
#include "G4XmlRNtupleManager.hh"
#include "G4XmlRNtupleDescription.hh"
#include "G4AnalysisVerbose.hh"
#include "G4AnalysisUtilities.hh"
#include "G4Threading.hh"
#include <iostream>
#include <cstdio>
using namespace G4Analysis;
G4XmlAnalysisReader* G4XmlAnalysisReader::fgMasterInstance = 0;
G4ThreadLocal G4XmlAnalysisReader* G4XmlAnalysisReader::fgInstance = 0;
//_____________________________________________________________________________
G4XmlAnalysisReader* G4XmlAnalysisReader::Instance()
{
if ( fgInstance == 0 ) {
G4bool isMaster = ! G4Threading::IsWorkerThread();
fgInstance = new G4XmlAnalysisReader(isMaster);
}
return fgInstance;
}
//_____________________________________________________________________________
G4XmlAnalysisReader::G4XmlAnalysisReader(G4bool isMaster)
: G4VAnalysisReader("Xml", isMaster),
fH1Manager(0),
fH2Manager(0),
fH3Manager(0),
fP1Manager(0),
fP2Manager(0),
fNtupleManager(0),
fFileManager(0)
{
if ( ( isMaster && fgMasterInstance ) || ( fgInstance ) ) {
G4ExceptionDescription description;
description
<< " "
<< "G4XmlAnalysisReader already exists."
<< "Cannot create another instance.";
G4Exception("G4XmlAnalysisReader::G4XmlAnalysisReader()",
"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 G4XmlRNtupleManager(fState);
fFileManager = new G4XmlRFileManager(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);
}
//_____________________________________________________________________________
G4XmlAnalysisReader::~G4XmlAnalysisReader()
{
if ( fState.GetIsMaster() ) fgMasterInstance = 0;
fgInstance = 0;
}
//
// private methods
//
//_____________________________________________________________________________
tools::raxml_out* G4XmlAnalysisReader::GetHandler(
const G4String& fileName,
const G4String& objectName,
const G4String& objectType,
const G4String& inFunction)
{
// Get buffer for reading object specified by objectName and objectType
// for a file specified by fileName;
// open the file if it was not yet open
// Histograms and profiles are not saved per thread
// and ntuple file name is already updated
tools::raxml* rfile = fFileManager->GetRFile(fileName);
if ( ! rfile ) {
if ( ! fFileManager->OpenRFile(fileName) ) return 0;
rfile = fFileManager->GetRFile(fileName);
}
tools::raxml_out* handler = 0;
if ( rfile ) {
std::vector<tools::raxml_out>& objects = rfile->objects();
std::vector<tools::raxml_out>::iterator it;
for (it = objects.begin(); it!=objects.end(); ++it) {
tools::raxml_out& object = *it;
if ( object.cls() == objectType && object.name() == objectName ) {
handler = &object;
break;
}
}
}
if ( ! handler ) {
G4ExceptionDescription description;
description
<< " "
<< "Cannot get "<< objectName << " in file " << fileName;
G4String inFunctionFull = "G4XmlAnalysisReader::";
inFunctionFull.append(inFunction);
G4Exception(inFunctionFull, "Analysis_WR011", JustWarning, description);
return 0;
}
return handler;
}
//_____________________________________________________________________________
G4bool G4XmlAnalysisReader::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 G4XmlAnalysisReader::ReadH1Impl(const G4String& h1Name,
const G4String& fileName,
G4bool /*isUserFileName*/)
{
#ifdef G4VERBOSE
if ( fState.GetVerboseL4() )
fState.GetVerboseL4()->Message("read", "h1", h1Name);
#endif
tools::raxml_out* handler
= GetHandler(fileName, h1Name, tools::histo::h1d::s_class(), "ReadH1Impl");
if ( ! handler ) return kInvalidId;
tools::histo::h1d* h1
= static_cast<tools::histo::h1d*>(handler->object());
G4int id = fH1Manager->AddH1(h1Name, h1);
#ifdef G4VERBOSE
if ( fState.GetVerboseL2() )
fState.GetVerboseL2()->Message("read", "h1", h1Name, id > kInvalidId);
#endif
return id;
}
//_____________________________________________________________________________
G4int G4XmlAnalysisReader::ReadH2Impl(const G4String& h2Name,
const G4String& fileName,
G4bool /*isUserFileName*/)
{
#ifdef G4VERBOSE
if ( fState.GetVerboseL4() )
fState.GetVerboseL4()->Message("read", "h2", h2Name);
#endif
tools::raxml_out* handler
= GetHandler(fileName, h2Name, tools::histo::h2d::s_class(), "ReadH2Impl");
if ( ! handler ) return kInvalidId;
tools::histo::h2d* h2
= static_cast<tools::histo::h2d*>(handler->object());
G4int id = fH2Manager->AddH2(h2Name, h2);
#ifdef G4VERBOSE
if ( fState.GetVerboseL2() )
fState.GetVerboseL2()->Message("read", "h2", h2Name, id > kInvalidId);
#endif
return id;
}
//_____________________________________________________________________________
G4int G4XmlAnalysisReader::ReadH3Impl(const G4String& h3Name,
const G4String& fileName,
G4bool /*isUserFileName*/)
{
#ifdef G4VERBOSE
if ( fState.GetVerboseL4() )
fState.GetVerboseL4()->Message("read", "h3", h3Name);
#endif
tools::raxml_out* handler
= GetHandler(fileName, h3Name, tools::histo::h3d::s_class(), "ReadH3Impl");
if ( ! handler ) return kInvalidId;
tools::histo::h3d* h3
= static_cast<tools::histo::h3d*>(handler->object());
G4int id = fH3Manager->AddH3(h3Name, h3);
#ifdef G4VERBOSE
if ( fState.GetVerboseL2() )
fState.GetVerboseL2()->Message("read", "h3", h3Name, id > kInvalidId);
#endif
return id;
}
//_____________________________________________________________________________
G4int G4XmlAnalysisReader::ReadP1Impl(const G4String& p1Name,
const G4String& fileName,
G4bool /*isUserFileName*/)
{
#ifdef G4VERBOSE
if ( fState.GetVerboseL4() )
fState.GetVerboseL4()->Message("read", "p1", p1Name);
#endif
tools::raxml_out* handler
= GetHandler(fileName, p1Name, tools::histo::p1d::s_class(), "ReadP1Impl");
if ( ! handler ) return kInvalidId;
tools::histo::p1d* p1
= static_cast<tools::histo::p1d*>(handler->object());
G4int id = fP1Manager->AddP1(p1Name, p1);
#ifdef G4VERBOSE
if ( fState.GetVerboseL2() )
fState.GetVerboseL2()->Message("read", "p1", p1Name, id > kInvalidId);
#endif
return id;
}
//_____________________________________________________________________________
G4int G4XmlAnalysisReader::ReadP2Impl(const G4String& p2Name,
const G4String& fileName,
G4bool /*isUserFileName*/)
{
#ifdef G4VERBOSE
if ( fState.GetVerboseL4() )
fState.GetVerboseL4()->Message("read", "p2", p2Name);
#endif
tools::raxml_out* handler
= GetHandler(fileName, p2Name, tools::histo::p2d::s_class(), "ReadP2Impl");
if ( ! handler ) return kInvalidId;
tools::histo::p2d* p2
= static_cast<tools::histo::p2d*>(handler->object());
G4int id = fP2Manager->AddP2(p2Name, p2);
#ifdef G4VERBOSE
if ( fState.GetVerboseL2() )
fState.GetVerboseL2()->Message("read", "p2", p2Name, id > kInvalidId);
#endif
return id;
}
//_____________________________________________________________________________
G4int G4XmlAnalysisReader::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);
}
tools::raxml_out* handler
= GetHandler(fullFileName, ntupleName, tools::aida::ntuple::s_class(),
"ReadNtupleImpl");
if ( ! handler ) return kInvalidId;
tools::aida::ntuple* rntuple
= static_cast<tools::aida::ntuple*>(handler->object());
G4int id
= fNtupleManager->SetNtuple(new G4XmlRNtupleDescription(rntuple));
#ifdef G4VERBOSE
if ( fState.GetVerboseL2() )
fState.GetVerboseL2()->Message("read", "ntuple", ntupleName, id > kInvalidId);
#endif
return id;
}
+2 -2
View File
@@ -133,7 +133,7 @@ G4bool G4XmlFileManager::CloseHnFile()
G4bool G4XmlFileManager::CreateNtupleFile(
G4XmlNtupleDescription* ntupleDescription)
{
G4String ntupleName = ntupleDescription->fNtupleBooking->m_name;
G4String ntupleName = ntupleDescription->fNtupleBooking->name();
#ifdef G4VERBOSE
if ( fState.GetVerboseL4() )
@@ -168,7 +168,7 @@ G4bool G4XmlFileManager::CreateNtupleFile(
G4bool G4XmlFileManager::CloseNtupleFile(
G4XmlNtupleDescription* ntupleDescription)
{
G4String ntupleName = ntupleDescription->fNtupleBooking->m_name;
G4String ntupleName = ntupleDescription->fNtupleBooking->name();
#ifdef G4VERBOSE
if ( fState.GetVerboseL4() )
+258 -84
View File
@@ -31,6 +31,8 @@
#include "G4XmlNtupleDescription.hh"
#include "G4XmlFileManager.hh"
#include "G4AnalysisManagerState.hh"
#include "G4AnalysisUtilities.hh"
#include "G4Threading.hh"
#include "G4UnitsTable.hh"
#include "tools/ntuple_booking"
@@ -38,10 +40,13 @@
#include <iostream>
#include <cstdio>
using namespace G4Analysis;
//_____________________________________________________________________________
G4XmlNtupleManager::G4XmlNtupleManager(const G4AnalysisManagerState& state)
: G4VNtupleManager(state),
fFileManager(0),
fNtupleDescriptionVector(),
fNtupleVector()
{
}
@@ -50,7 +55,7 @@ G4XmlNtupleManager::G4XmlNtupleManager(const G4AnalysisManagerState& state)
G4XmlNtupleManager::~G4XmlNtupleManager()
{
std::vector<G4XmlNtupleDescription*>::iterator it;
for (it = fNtupleVector.begin(); it != fNtupleVector.end(); it++ ) {
for (it = fNtupleDescriptionVector.begin(); it != fNtupleDescriptionVector.end(); it++ ) {
delete (*it);
}
}
@@ -74,9 +79,9 @@ G4XmlNtupleManager::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("G4XmlNtupleManager::GetNtupleIColumn()",
"Analysis_W009", JustWarning, description);
"Analysis_W011", JustWarning, description);
return 0;
}
@@ -98,9 +103,9 @@ G4XmlNtupleManager::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("G4XmlNtupleManager::GetNtupleFColumn()",
"Analysis_W009", JustWarning, description);
"Analysis_W011", JustWarning, description);
return 0;
}
@@ -122,9 +127,33 @@ G4XmlNtupleManager::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("G4XmlNtupleManager::GetNtupleFColumn()",
"Analysis_W009", JustWarning, description);
"Analysis_W011", JustWarning, description);
return 0;
}
return it->second;
}
//_____________________________________________________________________________
tools::waxml::ntuple::column<std::string>*
G4XmlNtupleManager::GetNtupleSColumn(G4int ntupleId, G4int columnId) const
{
G4XmlNtupleDescription* ntupleDecription
= GetNtupleInFunction(ntupleId, "GetNtupleSColumn");
if ( ! ntupleDecription ) return 0;
std::map<G4int, tools::waxml::ntuple::column<std::string>* >& ntupleSColumnMap
= ntupleDecription->fNtupleSColumnMap;
std::map<G4int, tools::waxml::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("G4XmlNtupleManager::GetNtupleSColumn()",
"Analysis_W011", JustWarning, description);
return 0;
}
@@ -137,18 +166,18 @@ G4XmlNtupleDescription* G4XmlNtupleManager::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 = "G4XmlNtupleManager::";
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];
}
//
@@ -161,10 +190,15 @@ void G4XmlNtupleManager::CreateNtuplesFromBooking()
// Create ntuple from ntuple_booking.
// Do not create ntuples on master thread
if ( G4AnalysisManagerState::IsMT() && fState.GetIsMaster() ) return;
if ( G4Threading::IsMultithreadedApplication() &&
fState.GetIsMaster() ) {
G4cout << "Do not create ntuples on master thread" << G4endl;
return;
}
G4int ntupleId = fFirstId;
std::vector<G4XmlNtupleDescription*>::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;
@@ -173,7 +207,7 @@ void G4XmlNtupleManager::CreateNtuplesFromBooking()
#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
@@ -182,40 +216,45 @@ void G4XmlNtupleManager::CreateNtuplesFromBooking()
// create ntuple
(*itn)->fNtuple
= new tools::waxml::ntuple(*((*itn)->fFile), G4cerr, *ntupleBooking);
fNtupleVector.push_back((*itn)->fNtuple);
if ( ntupleBooking->m_columns.size() ) {
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->name();
G4Exception("G4XmlNtupleManager::CreateNtuplesFromBooking()",
"Analysis_W004", JustWarning, description);
"Analysis_W002", JustWarning, description);
}
}
}
FinishNtuple();
FinishNtuple(ntupleId++);
#ifdef G4VERBOSE
if ( fState.GetVerboseL3() )
fState.GetVerboseL3()
->Message("create from booking", "ntuple", ntupleBooking->m_name);
->Message("create from booking", "ntuple", ntupleBooking->name());
#endif
}
}
@@ -223,7 +262,7 @@ void G4XmlNtupleManager::CreateNtuplesFromBooking()
//_____________________________________________________________________________
G4bool G4XmlNtupleManager::IsEmpty() const
{
return ! fNtupleVector.size();
return ! fNtupleDescriptionVector.size();
}
//_____________________________________________________________________________
@@ -232,10 +271,11 @@ G4bool G4XmlNtupleManager::Reset()
// Reset ntuples
std::vector<G4XmlNtupleDescription*>::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;
}
@@ -252,6 +292,8 @@ tools::waxml::ntuple* G4XmlNtupleManager::GetNtuple(G4int ntupleId) const
G4XmlNtupleDescription* ntupleDescription
= GetNtupleInFunction(ntupleId, "GetNtuple");
if ( ! ntupleDescription ) return 0;
return ntupleDescription->fNtuple;
}
@@ -265,15 +307,14 @@ G4int G4XmlNtupleManager::CreateNtuple(const G4String& name,
#endif
// Create ntuple description
G4int index = fNtupleVector.size();
G4int index = fNtupleDescriptionVector.size();
G4XmlNtupleDescription* ntupleDescription
= new G4XmlNtupleDescription();
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);
// Create ntuple if the file is open (what means here that
// a filename was already set)
@@ -282,6 +323,7 @@ G4int G4XmlNtupleManager::CreateNtuple(const G4String& name,
ntupleDescription->fNtuple
= new tools::waxml::ntuple(*(ntupleDescription->fFile));
// ntuple object is deleted when closing a file
fNtupleVector.push_back(ntupleDescription->fNtuple);
}
}
@@ -299,35 +341,47 @@ G4int G4XmlNtupleManager::CreateNtuple(const G4String& name,
}
//_____________________________________________________________________________
G4int G4XmlNtupleManager::CreateNtupleIColumn(const G4String& name)
G4int G4XmlNtupleManager::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 G4XmlNtupleManager::CreateNtupleFColumn(const G4String& name)
G4int G4XmlNtupleManager::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 G4XmlNtupleManager::CreateNtupleDColumn(const G4String& name)
G4int G4XmlNtupleManager::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 G4XmlNtupleManager::CreateNtupleSColumn(const G4String& name)
{
G4int ntupleId = fNtupleDescriptionVector.size() + fFirstId - 1;
return CreateNtupleSColumn(ntupleId, name);
}
//_____________________________________________________________________________
void G4XmlNtupleManager::FinishNtuple()
{
G4int ntupleId = fNtupleVector.size() + fFirstId - 1;
G4int ntupleId = fNtupleDescriptionVector.size() + fFirstId - 1;
FinishNtuple(ntupleId);
}
//_____________________________________________________________________________
G4int G4XmlNtupleManager::CreateNtupleIColumn(G4int ntupleId, const G4String& name)
G4int G4XmlNtupleManager::CreateNtupleIColumn(G4int ntupleId,
const G4String& name,
std::vector<int>* vector)
{
#ifdef G4VERBOSE
if ( fState.GetVerboseL4() ) {
@@ -339,6 +393,8 @@ G4int G4XmlNtupleManager::CreateNtupleIColumn(G4int ntupleId, const G4String& na
G4XmlNtupleDescription* ntupleDescription
= GetNtupleInFunction(ntupleId, "CreateNtupleIColumn");
if ( ! ntupleDescription ) return kInvalidId;
tools::ntuple_booking* ntupleBooking
= ntupleDescription->fNtupleBooking;
@@ -347,19 +403,27 @@ G4int G4XmlNtupleManager::CreateNtupleIColumn(G4int ntupleId, const G4String& na
description << " "
<< "Ntuple " << ntupleId << " has to be created first. ";
G4Exception("G4XmlNtupleManager::CreateNtupleIColumn()",
"Analysis_W005", JustWarning, description);
return -1;
"Analysis_W002", JustWarning, description);
return kInvalidId;
}
// Save column info in booking
G4int index = ntupleBooking->m_columns.size();
ntupleBooking->add_column<int>(name);
G4int index = ntupleBooking->columns().size();
if ( ! vector )
ntupleBooking->add_column<int>(name);
else
ntupleBooking->add_column<int>(name, *vector);
// Create column if ntuple already exists
if ( ntupleDescription->fNtuple ) {
tools::waxml::ntuple::column<int>* column
= ntupleDescription->fNtuple->create_column<int>(name);
ntupleDescription->fNtupleIColumnMap[index] = column;
if ( ! vector ) {
tools::waxml::ntuple::column<int>* column
= ntupleDescription->fNtuple->create_column<int>(name);
ntupleDescription->fNtupleIColumnMap[index] = column;
}
else {
ntupleDescription->fNtuple->create_column<int>(name, *vector);
}
}
fLockFirstNtupleColumnId = true;
@@ -376,7 +440,9 @@ G4int G4XmlNtupleManager::CreateNtupleIColumn(G4int ntupleId, const G4String& na
}
//_____________________________________________________________________________
G4int G4XmlNtupleManager::CreateNtupleFColumn(G4int ntupleId, const G4String& name)
G4int G4XmlNtupleManager::CreateNtupleFColumn(G4int ntupleId,
const G4String& name,
std::vector<float>* vector)
{
#ifdef G4VERBOSE
if ( fState.GetVerboseL4() ) {
@@ -388,6 +454,8 @@ G4int G4XmlNtupleManager::CreateNtupleFColumn(G4int ntupleId, const G4String& na
G4XmlNtupleDescription* ntupleDescription
= GetNtupleInFunction(ntupleId, "CreateNtupleFColumn");
if ( ! ntupleDescription ) return kInvalidId;
tools::ntuple_booking* ntupleBooking
= ntupleDescription->fNtupleBooking;
@@ -396,19 +464,27 @@ G4int G4XmlNtupleManager::CreateNtupleFColumn(G4int ntupleId, const G4String& na
description << " "
<< "Ntuple " << ntupleId << " has to be created first. ";
G4Exception("G4XmlNtupleManager::CreateNtupleFColumn()",
"Analysis_W005", JustWarning, description);
return -1;
"Analysis_W002", JustWarning, description);
return kInvalidId;
}
// Save column info in booking
G4int index = ntupleBooking->m_columns.size();
ntupleBooking->add_column<float>(name);
G4int index = ntupleBooking->columns().size();
if ( ! vector )
ntupleBooking->add_column<float>(name);
else
ntupleBooking->add_column<float>(name, *vector);
// Create column if ntuple already exists
if ( ntupleDescription->fNtuple ) {
tools::waxml::ntuple::column<float>* column
= ntupleDescription->fNtuple->create_column<float>(name);
ntupleDescription->fNtupleFColumnMap[index] = column;
if ( ! vector ) {
tools::waxml::ntuple::column<float>* column
= ntupleDescription->fNtuple->create_column<float>(name);
ntupleDescription->fNtupleFColumnMap[index] = column;
}
else {
ntupleDescription->fNtuple->create_column<float>(name, *vector);
}
}
fLockFirstNtupleColumnId = true;
@@ -425,7 +501,9 @@ G4int G4XmlNtupleManager::CreateNtupleFColumn(G4int ntupleId, const G4String& na
}
//_____________________________________________________________________________
G4int G4XmlNtupleManager::CreateNtupleDColumn(G4int ntupleId, const G4String& name)
G4int G4XmlNtupleManager::CreateNtupleDColumn(G4int ntupleId,
const G4String& name,
std::vector<double>* vector)
{
#ifdef G4VERBOSE
if ( fState.GetVerboseL4() ) {
@@ -437,6 +515,8 @@ G4int G4XmlNtupleManager::CreateNtupleDColumn(G4int ntupleId, const G4String& na
G4XmlNtupleDescription* ntupleDescription
= GetNtupleInFunction(ntupleId, "CreateNtupleDColumn");
if ( ! ntupleDescription ) return kInvalidId;
tools::ntuple_booking* ntupleBooking
= ntupleDescription->fNtupleBooking;
@@ -445,19 +525,27 @@ G4int G4XmlNtupleManager::CreateNtupleDColumn(G4int ntupleId, const G4String& na
description << " "
<< "Ntuple " << ntupleId << " has to be created first. ";
G4Exception("G4XmlNtupleManager::CreateNtupleDColumn()",
"Analysis_W005", JustWarning, description);
return -1;
"Analysis_W002", JustWarning, description);
return kInvalidId;
}
// Save column info in booking
G4int index = ntupleBooking->m_columns.size();
ntupleBooking->add_column<double>(name);
G4int index = ntupleBooking->columns().size();
if ( ! vector )
ntupleBooking->add_column<double>(name);
else
ntupleBooking->add_column<double>(name, *vector);
// Create column if ntuple already exists
if ( ntupleDescription->fNtuple ) {
tools::waxml::ntuple::column<double>* column
= ntupleDescription->fNtuple->create_column<double>(name);
ntupleDescription->fNtupleDColumnMap[index] = column;
if ( ! vector ) {
tools::waxml::ntuple::column<double>* column
= ntupleDescription->fNtuple->create_column<double>(name);
ntupleDescription->fNtupleDColumnMap[index] = column;
}
else {
ntupleDescription->fNtuple->create_column<double>(name, *vector);
}
}
fLockFirstNtupleColumnId = true;
@@ -474,26 +562,80 @@ G4int G4XmlNtupleManager::CreateNtupleDColumn(G4int ntupleId, const G4String& na
}
//_____________________________________________________________________________
void G4XmlNtupleManager::FinishNtuple(G4int ntupleId)
{
G4int G4XmlNtupleManager::CreateNtupleSColumn(G4int ntupleId,
const G4String& name)
{
#ifdef G4VERBOSE
if ( fState.GetVerboseL4() ) {
G4ExceptionDescription description;
description << name << " ntupleId " << ntupleId;
fState.GetVerboseL4()->Message("create", "ntuple S column", description);
}
#endif
G4XmlNtupleDescription* ntupleDescription
= GetNtupleInFunction(ntupleId, "FinishNtuple");
= 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("G4XmlNtupleManager::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::waxml::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 G4XmlNtupleManager::FinishNtuple(G4int ntupleId)
{
G4XmlNtupleDescription* ntupleDescription
= GetNtupleInFunction(ntupleId, "FinishNtuple");
tools::ntuple_booking* ntupleBooking = 0;
if ( ntupleDescription ) {
ntupleBooking = ntupleDescription->fNtupleBooking;
}
if ( ( ! ntupleDescription ) || ( ! ntupleBooking ) ) {
G4ExceptionDescription description;
description << " "
<< "Ntuple " << ntupleId << " has to be created first. ";
G4Exception("G4XmlNtupleManager::CreateNtupleDColumn()",
"Analysis_W005", JustWarning, description);
"Analysis_W002", JustWarning, description);
return;
}
#ifdef G4VERBOSE
if ( fState.GetVerboseL4() ) {
G4ExceptionDescription description;
description << ntupleBooking->m_name << " ntupleId " << ntupleId;
description << ntupleBooking->name() << " ntupleId " << ntupleId;
fState.GetVerboseL4()->Message("finish", "ntuple", description);
}
#endif
@@ -503,15 +645,14 @@ void G4XmlNtupleManager::FinishNtuple(G4int ntupleId)
G4String path = "/";
path.append(fFileManager->GetNtupleDirectoryName());
ntupleDescription->fNtuple
->write_header(path, ntupleBooking->m_name, ntupleBooking->m_title);
->write_header(path, ntupleBooking->name(), ntupleBooking->title());
fFileManager->LockNtupleDirectoryName();
}
#ifdef G4VERBOSE
if ( fState.GetVerboseL2() ) {
G4ExceptionDescription description;
description << ntupleBooking->m_name << " ntupleId " << ntupleId;
description << ntupleBooking->name() << " ntupleId " << ntupleId;
fState.GetVerboseL2()->Message("finish", "ntuple", description);
}
#endif
@@ -535,6 +676,12 @@ G4bool G4XmlNtupleManager::FillNtupleDColumn(G4int columnId, G4double value)
return FillNtupleDColumn(fFirstId, columnId, value);
}
//_____________________________________________________________________________
G4bool G4XmlNtupleManager::FillNtupleSColumn(G4int columnId, const G4String& value)
{
return FillNtupleSColumn(fFirstId, columnId, value);
}
//_____________________________________________________________________________
G4bool G4XmlNtupleManager::FillNtupleIColumn(G4int ntupleId, G4int columnId,
G4int value)
@@ -543,9 +690,9 @@ G4bool G4XmlNtupleManager::FillNtupleIColumn(G4int ntupleId, G4int columnId,
= GetNtupleIColumn(ntupleId, columnId);
if ( ! column ) {
G4ExceptionDescription description;
description << " " << "column " << columnId << " does not exist.";
description << " " << " columnId " << columnId << " does not exist.";
G4Exception("G4XmlNtupleManager::FillNtupleIColumn()",
"Analysis_W009", JustWarning, description);
"Analysis_W011", JustWarning, description);
return false;
}
@@ -568,9 +715,9 @@ G4bool G4XmlNtupleManager::FillNtupleFColumn(G4int ntupleId, G4int columnId,
= GetNtupleFColumn(ntupleId, columnId);
if ( ! column ) {
G4ExceptionDescription description;
description << " " << "column " << columnId << " does not exist.";
description << " " << " columnId " << columnId << " does not exist.";
G4Exception("G4XmlNtupleManager::FillNtupleFColumn()",
"Analysis_W009", JustWarning, description);
"Analysis_W011", JustWarning, description);
return false;
}
@@ -594,9 +741,9 @@ G4bool G4XmlNtupleManager::FillNtupleDColumn(G4int ntupleId, G4int columnId,
= GetNtupleDColumn(ntupleId, columnId);
if ( ! column ) {
G4ExceptionDescription description;
description << " " << "column " << columnId << " does not exist.";
description << " " << " columnId " << columnId << " does not exist.";
G4Exception("G4XmlNtupleManager::FillNtupleDColumn()",
"Analysis_W009", JustWarning, description);
"Analysis_W011", JustWarning, description);
return false;
}
@@ -612,6 +759,32 @@ G4bool G4XmlNtupleManager::FillNtupleDColumn(G4int ntupleId, G4int columnId,
return true;
}
//_____________________________________________________________________________
G4bool G4XmlNtupleManager::FillNtupleSColumn(G4int ntupleId, G4int columnId,
const G4String& value)
{
tools::waxml::ntuple::column<std::string>* column
= GetNtupleSColumn(ntupleId, columnId);
if ( ! column ) {
G4ExceptionDescription description;
description << " " << " columnId " << columnId << " does not exist.";
G4Exception("G4XmlNtupleManager::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 G4XmlNtupleManager::AddNtupleRow()
{
@@ -631,12 +804,13 @@ G4bool G4XmlNtupleManager::AddNtupleRow(G4int ntupleId)
G4XmlNtupleDescription* ntupleDescription
= GetNtupleInFunction(ntupleId, "AddNtupleRow");
if ( ! ntupleDescription ) return false;
if ( ! ntupleDescription || ! ntupleDescription->fNtuple ) {
if ( ! ntupleDescription->fNtuple ) {
G4ExceptionDescription description;
description << " " << "ntuple does not exist. ";
G4Exception("G4XmlNtupleManager::AddNtupleRow()",
"Analysis_W008", JustWarning, description);
"Analysis_W022", JustWarning, description);
return false;
}
@@ -0,0 +1,128 @@
//
// ********************************************************************
// * 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: G4XmlRFileManager.cc 70604 2013-06-03 11:27:06Z ihrivnac $
// Author: Ivana Hrivnacova, 10/09/2014 (ivana@ipno.in2p3.fr)
#include "G4XmlRFileManager.hh"
#include "G4AnalysisManagerState.hh"
#include "tools/waxml/begend"
//_____________________________________________________________________________
G4XmlRFileManager::G4XmlRFileManager(const G4AnalysisManagerState& state)
: G4BaseFileManager(state),
fReadFactory(0),
fRFiles()
{
}
//_____________________________________________________________________________
G4XmlRFileManager::~G4XmlRFileManager()
{
for (G4int i=0; i<G4int(fRFiles.size()); ++i) {
delete fRFiles[i];
}
delete fReadFactory;
}
//
// public methods
//
//_____________________________________________________________________________
G4bool G4XmlRFileManager::OpenRFile(const G4String& fileName)
{
// Get full file name (add only extension)
G4bool isPerThread = false;
G4String name = GetFullFileName(fileName, isPerThread);
#ifdef G4VERBOSE
if ( fState.GetVerboseL4() )
fState.GetVerboseL4()->Message("open", "read analysis file", name);
#endif
G4bool verbose = false;
// create factory (if it does not yet exist)
if ( ! fReadFactory ) {
fReadFactory = new tools::xml::default_factory();
}
// create new file
tools::raxml* newFile
= new tools::raxml(*fReadFactory, G4cout, verbose);
// clear objects
// (this should not be needed when starting a new raxml)
std::vector<tools::raxml_out>& objs = newFile->objects();
objs.clear();
G4bool compressed = false;
if ( ! newFile->load_file(name, compressed) ) {
G4ExceptionDescription description;
description << " " << "Cannot open file " << name;
G4Exception("G4XmlRFileManager::OpenRFile()",
"Analysis_WR001", JustWarning, description);
delete newFile;
return false;
}
// add file in a map and delete the previous file if it exists
std::map<G4String, tools::raxml*>::iterator it
= fRFiles.find(name);
if ( it != fRFiles.end() ) {
delete it->second;
it->second = newFile;
}
else {
fRFiles[name] = newFile;
}
#ifdef G4VERBOSE
if ( fState.GetVerboseL1() )
fState.GetVerboseL1()
->Message("open", "read analysis file", name);
#endif
return true;
}
//_____________________________________________________________________________
tools::raxml* G4XmlRFileManager::GetRFile(const G4String& fileName) const
{
// Get full file name (add only extension)
G4bool isPerThread = false;
G4String name = GetFullFileName(fileName, isPerThread);
std::map<G4String, tools::raxml*>::const_iterator it
= fRFiles.find(name);
if ( it != fRFiles.end() )
return it->second;
else {
return 0;
}
}
@@ -0,0 +1,462 @@
//
// ********************************************************************
// * 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 "G4XmlRNtupleManager.hh"
#include "G4XmlRNtupleDescription.hh"
#include "G4AnalysisManagerState.hh"
//_____________________________________________________________________________
G4XmlRNtupleManager::G4XmlRNtupleManager(const G4AnalysisManagerState& state)
: G4VRNtupleManager(state),
fNtupleVector()
{
}
//_____________________________________________________________________________
G4XmlRNtupleManager::~G4XmlRNtupleManager()
{
std::vector<G4XmlRNtupleDescription*>::iterator it;
for (it = fNtupleVector.begin(); it != fNtupleVector.end(); it++ ) {
delete (*it);
}
}
//
// private methods
//
//_____________________________________________________________________________
G4XmlRNtupleDescription* G4XmlRNtupleManager::GetNtupleInFunction(G4int id,
G4String functionName, G4bool warn) const
{
G4int index = id - fFirstId;
if ( index < 0 || index >= G4int(fNtupleVector.size()) ) {
if ( warn) {
G4String inFunction = "G4XmlRNtupleManager::";
inFunction += functionName;
G4ExceptionDescription description;
description << " " << "ntuple " << id << " does not exist.";
G4Exception(inFunction, "Analysis_WR011", JustWarning, description);
}
return 0;
}
return fNtupleVector[index];
}
//
// protected methods
//
//_____________________________________________________________________________
G4bool G4XmlRNtupleManager::IsEmpty() const
{
return ! fNtupleVector.size();
}
//_____________________________________________________________________________
G4bool G4XmlRNtupleManager::Reset()
{
// Reset ntuples
std::vector<G4XmlRNtupleDescription*>::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::aida::ntuple* G4XmlRNtupleManager::GetNtuple() const
{
return GetNtuple(fFirstId);
}
//_____________________________________________________________________________
tools::aida::ntuple* G4XmlRNtupleManager::GetNtuple(G4int ntupleId) const
{
G4XmlRNtupleDescription* rntupleDescription
= GetNtupleInFunction(ntupleId, "GetRNtuple");
if ( ! rntupleDescription ) return 0;
return rntupleDescription->fNtuple;
}
//_____________________________________________________________________________
G4int G4XmlRNtupleManager::SetNtuple(G4XmlRNtupleDescription* rntupleDescription)
{
G4int id = fNtupleVector.size() + fFirstId;
fNtupleVector.push_back(rntupleDescription);
return id;
}
//_____________________________________________________________________________
G4bool G4XmlRNtupleManager::SetNtupleIColumn(const G4String& columnName,
G4int& value)
{
return SetNtupleIColumn(fFirstId, columnName, value);
}
//_____________________________________________________________________________
G4bool G4XmlRNtupleManager::SetNtupleFColumn(const G4String& columnName,
G4float& value)
{
return SetNtupleFColumn(fFirstId, columnName, value);
}
//_____________________________________________________________________________
G4bool G4XmlRNtupleManager::SetNtupleDColumn(const G4String& columnName,
G4double& value)
{
return SetNtupleDColumn(fFirstId, columnName, value);
}
//_____________________________________________________________________________
G4bool G4XmlRNtupleManager::SetNtupleSColumn(const G4String& columnName,
G4String& value)
{
return SetNtupleSColumn(fFirstId, columnName, value);
}
//_____________________________________________________________________________
G4bool G4XmlRNtupleManager::SetNtupleIColumn(const G4String& columnName,
std::vector<G4int>& vector)
{
return SetNtupleIColumn(fFirstId, columnName, vector);
}
//_____________________________________________________________________________
G4bool G4XmlRNtupleManager::SetNtupleFColumn(const G4String& columnName,
std::vector<G4float>& vector)
{
return SetNtupleFColumn(fFirstId, columnName, vector);
}
//_____________________________________________________________________________
G4bool G4XmlRNtupleManager::SetNtupleDColumn(const G4String& columnName,
std::vector<G4double>& vector)
{
return SetNtupleDColumn(fFirstId, columnName, vector);
}
//_____________________________________________________________________________
G4bool G4XmlRNtupleManager::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
G4XmlRNtupleDescription* 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 G4XmlRNtupleManager::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
G4XmlRNtupleDescription* 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 G4XmlRNtupleManager::SetNtupleDColumn(G4int ntupleId,
const G4String& columnName,
G4double& value)
{
// Add protection if ntuple is initialized
#ifdef G4VERBOSE
if ( fState.GetVerboseL4() ) {
G4ExceptionDescription description;
description << " ntupleId " << ntupleId << " " << columnName;
fState.GetVerboseL4()->Message("set", "ntuple D column", description);
}
#endif
G4XmlRNtupleDescription* 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 G4XmlRNtupleManager::SetNtupleSColumn(G4int ntupleId,
const G4String& columnName,
G4String& value)
{
// Add protection if ntuple is initialized
#ifdef G4VERBOSE
if ( fState.GetVerboseL4() ) {
G4ExceptionDescription description;
description << " ntupleId " << ntupleId << " " << columnName;
fState.GetVerboseL4()->Message("set", "ntuple S column", description);
}
#endif
G4XmlRNtupleDescription* 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 G4XmlRNtupleManager::SetNtupleIColumn(G4int ntupleId,
const G4String& columnName,
std::vector<G4int>& vector)
{
// Add protection if ntuple is initialized
#ifdef G4VERBOSE
if ( fState.GetVerboseL4() ) {
G4ExceptionDescription description;
description << " ntupleId " << ntupleId << " " << columnName;
fState.GetVerboseL4()->Message("set", "ntuple I column", description);
}
#endif
G4XmlRNtupleDescription* 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 G4XmlRNtupleManager::SetNtupleFColumn(G4int ntupleId,
const G4String& columnName,
std::vector<G4float>& vector)
{
// Add protection if ntuple is initialized
#ifdef G4VERBOSE
if ( fState.GetVerboseL4() ) {
G4ExceptionDescription description;
description << " ntupleId " << ntupleId << " " << columnName;
fState.GetVerboseL4()->Message("set", "ntuple F column of vector", description);
}
#endif
G4XmlRNtupleDescription* 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 G4XmlRNtupleManager::SetNtupleDColumn(G4int ntupleId,
const G4String& columnName,
std::vector<G4double>& vector)
{
// Add protection if ntuple is initialized
#ifdef G4VERBOSE
if ( fState.GetVerboseL4() ) {
G4ExceptionDescription description;
description << " ntupleId " << ntupleId << " " << columnName;
fState.GetVerboseL4()->Message("set", "ntuple D column of vector", description);
}
#endif
G4XmlRNtupleDescription* 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 G4XmlRNtupleManager::GetNtupleRow()
{
return GetNtupleRow(fFirstId);
}
//_____________________________________________________________________________
G4bool G4XmlRNtupleManager::GetNtupleRow(G4int ntupleId)
{
#ifdef G4VERBOSE
if ( fState.GetVerboseL4() ) {
G4ExceptionDescription description;
description << " ntupleId " << ntupleId;
fState.GetVerboseL4()->Message("get", "ntuple row", description);
}
#endif
G4XmlRNtupleDescription* ntupleDescription
= GetNtupleInFunction(ntupleId, "GetNtupleRow");
if ( ! ntupleDescription ) return false;
tools::aida::ntuple* ntuple = ntupleDescription->fNtuple;
G4bool isInitialized = ntupleDescription->fIsInitialized;
if ( ! isInitialized ) {
tools::ntuple_binding* ntupleBinding = ntupleDescription->fNtupleBinding;
if ( ! ntuple->set_binding(std::cout, *ntupleBinding) ) {
G4ExceptionDescription description;
description
<< " "
<< "Ntuple initialization failed !!";
G4Exception("G4XmlRNtuple::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("G4XmlRNtuple::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;
}