Import Geant4 10.0.0 source tree

This commit is contained in:
Gabriele Cosmo
2016-06-10 11:51:14 +02:00
parent e2d2f9810a
commit 286caacf06
12421 changed files with 730077 additions and 502383 deletions
+18
View File
@@ -0,0 +1,18 @@
#------------------------------------------------------------------------------
# CMakeLists.txt
# Module : G4analysis
# Package: Geant4.src.G4analysis.G4xml
#
# CMakeLists.txt for building a single granular library.
#
# Created on : 15/07/2013
#
# $Id: CMakeLists.txt 72292 2013-07-15 12:01:43Z ihrivnac $
#
#------------------------------------------------------------------------------
if(GEANT4_BUILD_GRANULAR_LIBS)
include(Geant4MacroLibraryTargets)
GEANT4_GRANULAR_LIBRARY_TARGET(COMPONENT sources.cmake)
endif()
+20
View File
@@ -0,0 +1,20 @@
# $Id: GNUmakefile 66356 2012-12-18 09:02:32Z gcosmo $
# --------------------------------------------------------------------
# GNUmakefile for geometry/biasing library. Gabriele Cosmo, 25/03/02.
# --------------------------------------------------------------------
name := G4xml
ifndef G4INSTALL
G4INSTALL = ../../..
endif
include $(G4INSTALL)/config/architecture.gmk
CPPFLAGS += -I$(G4BASE)/global/management/include \
-I$(G4BASE)/intercoms/include \
-I$(G4BASE)/analysis/g4tools/include \
-I$(G4BASE)/analysis/management/include \
-I$(G4BASE)/analysis/hntools/include
include $(G4INSTALL)/config/common.gmk
@@ -0,0 +1,95 @@
//
// ********************************************************************
// * 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: G4XmlAnalysisManager.hh 74257 2013-10-02 14:24:55Z gcosmo $
// The main manager for Xml analysis.
// It delegates most of functions to the object specific managers.
// Author: Ivana Hrivnacova, 18/06/2013 (ivana@ipno.in2p3.fr)
#ifndef G4XmlAnalysisManager_h
#define G4XmlAnalysisManager_h 1
#include "G4VAnalysisManager.hh"
#include "globals.hh"
#include "tools/histo/h1d"
#include "tools/histo/h2d"
#include "tools/waxml/ntuple"
class G4XmlFileManager;
class G4H1ToolsManager;
class G4H2ToolsManager;
class G4XmlNtupleManager;
class G4XmlAnalysisManager : public G4VAnalysisManager
{
public:
G4XmlAnalysisManager(G4bool isMaster = true);
~G4XmlAnalysisManager();
// static methods
static G4XmlAnalysisManager* Instance();
// Access methods
tools::histo::h1d* GetH1(G4int id, G4bool warn = true,
G4bool onlyIfActive = true) const;
tools::histo::h2d* GetH2(G4int id, G4bool warn = true,
G4bool onlyIfActive = true) const;
tools::waxml::ntuple* GetNtuple() const;
tools::waxml::ntuple* GetNtuple(G4int ntupleId) const;
protected:
// virtual methods from base class
virtual G4bool OpenFileImpl(const G4String& fileName);
virtual G4bool WriteImpl();
virtual G4bool CloseFileImpl();
private:
// static data members
static G4XmlAnalysisManager* fgMasterInstance;
static G4ThreadLocal G4XmlAnalysisManager* fgInstance;
// methods
G4bool WriteH1();
G4bool WriteH2();
G4bool WriteNtuple();
G4bool CloseNtupleFiles();
G4bool Reset();
// data members
G4H1ToolsManager* fH1Manager;
G4H2ToolsManager* fH2Manager;
G4XmlNtupleManager* fNtupleManager;
G4XmlFileManager* fFileManager;
};
#include "G4XmlAnalysisManager.icc"
#endif
@@ -0,0 +1,60 @@
//
// ********************************************************************
// * 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: G4XmlAnalysisManager.hh 70604 2013-06-03 11:27:06Z ihrivnac $
#include "G4H1ToolsManager.hh"
#include "G4H2ToolsManager.hh"
#include "G4XmlNtupleManager.hh"
//_____________________________________________________________________________
inline
tools::histo::h1d* G4XmlAnalysisManager::GetH1(G4int id, G4bool warn,
G4bool onlyIfActive) const
{
return fH1Manager->GetH1(id, warn, onlyIfActive);
}
//_____________________________________________________________________________
inline
tools::histo::h2d* G4XmlAnalysisManager::GetH2(G4int id, G4bool warn,
G4bool onlyIfActive) const
{
return fH2Manager->GetH2(id, warn, onlyIfActive);
}
//_____________________________________________________________________________
inline
tools::waxml::ntuple* G4XmlAnalysisManager::GetNtuple() const
{
return fNtupleManager->GetNtuple();
}
//_____________________________________________________________________________
inline
tools::waxml::ntuple* G4XmlAnalysisManager::GetNtuple(G4int ntupleId) const
{
return fNtupleManager->GetNtuple(ntupleId);
}
@@ -0,0 +1,83 @@
//
// ********************************************************************
// * 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: G4XmlFileManager.hh 70604 2013-06-03 11:27:06Z ihrivnac $
// Author: Ivana Hrivnacova, 18/06/2013 (ivana@ipno.in2p3.fr)
#ifndef G4XmlFileManager_h
#define G4XmlFileManager_h 1
#include "G4VFileManager.hh"
#include "G4XmlNtupleDescription.hh"
#include "globals.hh"
#include <fstream>
class G4AnalysisManagerState;
class G4XmlFileManager : public G4VFileManager
{
public:
G4XmlFileManager(const G4AnalysisManagerState& state);
~G4XmlFileManager();
// Methods to manipulate files
virtual G4bool OpenFile(const G4String& fileName);
virtual G4bool WriteFile();
virtual G4bool CloseFile();
// Specific methods for files per objects
G4bool CreateHnFile();
G4bool CloseHnFile();
G4bool CreateNtupleFile(G4XmlNtupleDescription* ntupleDescription);
G4bool CloseNtupleFile(G4XmlNtupleDescription* ntupleDescription);
// Set methods
void LockHistoDirectoryName();
void LockNtupleDirectoryName();
// Get methods
std::ofstream* GetHnFile() const;
private:
// data members
//
std::ofstream* fHnFile;
};
// inline functions
inline void G4XmlFileManager::LockHistoDirectoryName()
{ fLockHistoDirectoryName = true; }
inline void G4XmlFileManager::LockNtupleDirectoryName()
{ fLockNtupleDirectoryName = true; }
inline std::ofstream* G4XmlFileManager::GetHnFile() const
{ return fHnFile; }
#endif
@@ -0,0 +1,69 @@
//
// ********************************************************************
// * 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$
// Structure containing the information related to Xml ntuple
//
// Author: Ivana Hrivnacova, 04/07/2012 (ivana@ipno.in2p3.fr)
#ifndef G4XmlNtupleDescription_h
#define G4XmlNtupleDescription_h 1
#include "tools/waxml/ntuple"
#include <fstream>
#include <map>
namespace tools {
class ntuple_booking;
}
struct G4XmlNtupleDescription
{
G4XmlNtupleDescription()
: fFile(0),
fNtuple(0),
fNtupleBooking(0),
fNtupleIColumnMap(),
fNtupleFColumnMap(),
fNtupleDColumnMap() {}
~G4XmlNtupleDescription()
{ delete fFile;
delete fNtuple;
delete fNtupleBooking;
}
std::ofstream* fFile;
tools::waxml::ntuple* fNtuple;
tools::ntuple_booking* fNtupleBooking;
std::map<G4int, tools::waxml::ntuple::column<int>* > fNtupleIColumnMap;
std::map<G4int, tools::waxml::ntuple::column<float>* > fNtupleFColumnMap;
std::map<G4int, tools::waxml::ntuple::column<double>* > fNtupleDColumnMap;
};
#endif
@@ -0,0 +1,136 @@
//
// ********************************************************************
// * 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: G4XmlNtupleManager.hh 70604 2013-06-03 11:27:06Z ihrivnac $
// Manager class for Xml ntuples
//
// Author: Ivana Hrivnacova, 18/06/2013 (ivana@ipno.in2p3.fr)
#ifndef G4XmlNtupleManager_h
#define G4XmlNtupleManager_h 1
#include "G4VNtupleManager.hh"
#include "globals.hh"
#include "tools/waxml/ntuple"
#include <vector>
class G4XmlFileManager;
struct G4XmlNtupleDescription;
class G4XmlNtupleManager : public G4VNtupleManager
{
friend class G4XmlAnalysisManager;
protected:
G4XmlNtupleManager(const G4AnalysisManagerState& state);
~G4XmlNtupleManager();
// Functions specific to the output type
//
// Methods to manipulate ntuples
void CreateNtuplesFromBooking();
G4bool IsEmpty() const;
G4bool Reset();
// Set methods
void SetFileManager(G4XmlFileManager* fileManager);
// Access methods
tools::waxml::ntuple* GetNtuple() const;
tools::waxml::ntuple* GetNtuple(G4int ntupleId) const;
// Access to ntuple vector (needed for Write())
const std::vector<G4XmlNtupleDescription*>& GetNtupleVector() const;
// Virtual functions from base class
//
// Methods to create ntuples
virtual G4int CreateNtuple(const G4String& name, const G4String& title);
// Create columns in the last created ntuple
virtual G4int CreateNtupleIColumn(const G4String& name);
virtual G4int CreateNtupleFColumn(const G4String& name);
virtual G4int CreateNtupleDColumn(const G4String& name);
virtual void FinishNtuple();
// Create columns in the ntuple with given id
virtual G4int CreateNtupleIColumn(G4int ntupleId, const G4String& name);
virtual G4int CreateNtupleFColumn(G4int ntupleId, const G4String& name);
virtual G4int CreateNtupleDColumn(G4int ntupleId, const G4String& name);
virtual void FinishNtuple(G4int ntupleId);
// Methods to fill ntuples
// Methods for ntuple with id = FirstNtupleId
virtual G4bool FillNtupleIColumn(G4int columnId, G4int value);
virtual G4bool FillNtupleFColumn(G4int columnId, G4float value);
virtual G4bool FillNtupleDColumn(G4int columnId, G4double value);
virtual G4bool AddNtupleRow();
// Methods for ntuple with id > FirstNtupleId (when more ntuples exist)
virtual G4bool FillNtupleIColumn(G4int ntupleId, G4int columnId, G4int value);
virtual G4bool FillNtupleFColumn(G4int ntupleId, G4int columnId, G4float value);
virtual G4bool FillNtupleDColumn(G4int ntupleId, G4int columnId, G4double value);
virtual G4bool AddNtupleRow(G4int ntupleId);
// Access methods
virtual G4int GetNofNtuples() const;
private:
// methods
//
tools::waxml::ntuple::column<int>*
GetNtupleIColumn(G4int ntupleId, G4int columnId) const;
tools::waxml::ntuple::column<float>*
GetNtupleFColumn(G4int ntupleId, G4int columnId) const;
tools::waxml::ntuple::column<double>*
GetNtupleDColumn(G4int ntupleId, G4int columnId) const;
virtual G4XmlNtupleDescription* GetNtupleInFunction(G4int id,
G4String function,
G4bool warn = true,
G4bool onlyIfActive = true) const;
// data members
//
G4XmlFileManager* fFileManager;
std::vector<G4XmlNtupleDescription*> fNtupleVector;
};
// inline functions
inline void G4XmlNtupleManager::SetFileManager(G4XmlFileManager* fileManager)
{ fFileManager = fileManager; }
inline G4int G4XmlNtupleManager::GetNofNtuples() const
{ return fNtupleVector.size(); }
inline const std::vector<G4XmlNtupleDescription*>& G4XmlNtupleManager::GetNtupleVector() const
{ return fNtupleVector; }
#endif
+39
View File
@@ -0,0 +1,39 @@
//
// ********************************************************************
// * 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: g4xml.hh 72292 2013-07-15 12:01:43Z ihrivnac $
// Author: Ivana Hrivnacova, 15/06/2011 (ivana@ipno.in2p3.fr)
#ifndef g4xml_h
#define g4xml_h
#include "g4xml_defs.hh"
using namespace G4Xml;
#endif
+49
View File
@@ -0,0 +1,49 @@
//
// ********************************************************************
// * 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: g4xml_defs.hh 72292 2013-07-15 12:01:43Z ihrivnac $
// Author: Ivana Hrivnacova, 15/06/2011 (ivana@ipno.in2p3.fr)
#ifndef g4xml_defs_h
#define g4xml_defs_h
#include "tools/histo/h1d"
#include "tools/histo/h2d"
#include "tools/waxml/ntuple"
#include "G4XmlAnalysisManager.hh"
namespace G4Xml {
typedef tools::histo::h1d G4AnaH1;
typedef tools::histo::h2d G4AnaH2;
typedef tools::waxml::ntuple* G4Ntuple;
typedef G4XmlAnalysisManager G4AnalysisManager;
}
#endif
+56
View File
@@ -0,0 +1,56 @@
#------------------------------------------------------------------------------
# sources.cmake
# Module : G4csv
# Package: Geant4.src.G4analysis.G4xml
#
# Sources description for a library.
# Lists the sources and headers of the code explicitely.
# Lists include paths needed.
# Lists the internal granular and global dependencies of the library.
# Source specific properties should be added at the end.
#
# Generated on : 15/07/2013
#
# $Id: sources.cmake 72956 2013-08-14 14:24:35Z gcosmo $
#
#------------------------------------------------------------------------------
# List external includes needed.
include_directories(${CLHEP_INCLUDE_DIRS})
# List internal includes needed.
include_directories(${CMAKE_SOURCE_DIR}/source/global/management/include)
include_directories(${CMAKE_SOURCE_DIR}/source/intercoms/include)
include_directories(${CMAKE_SOURCE_DIR}/source/analysis/g4tools/include)
include_directories(${CMAKE_SOURCE_DIR}/source/analysis/management/include)
include_directories(${CMAKE_SOURCE_DIR}/source/analysis/hntools/include)
#
# Define the Geant4 Module.
#
include(Geant4MacroDefineModule)
GEANT4_DEFINE_MODULE(NAME G4xml
HEADERS
G4XmlAnalysisManager.hh
G4XmlAnalysisManager.icc
G4XmlFileManager.hh
G4XmlNtupleDescription.hh
G4XmlNtupleManager.hh
g4xml_defs.hh
g4xml.hh
SOURCES
G4XmlAnalysisManager.cc
G4XmlFileManager.cc
G4XmlNtupleManager.cc
GRANULAR_DEPENDENCIES
G4globman
G4intercoms
G4analysismng
G4hntools
GLOBAL_DEPENDENCIES
G4global
G4intercoms
LINK_LIBRARIES
)
# List any source specific properties here
@@ -0,0 +1,404 @@
//
// ********************************************************************
// * 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: G4XmlAnalysisManager.cc 74257 2013-10-02 14:24:55Z gcosmo $
// Author: Ivana Hrivnacova, 18/06/2013 (ivana@ipno.in2p3.fr)
#include "G4XmlAnalysisManager.hh"
#include "G4XmlFileManager.hh"
#include "G4H1ToolsManager.hh"
#include "G4H2ToolsManager.hh"
#include "G4XmlNtupleManager.hh"
#include "G4Threading.hh"
#include "G4AutoLock.hh"
#include "tools/waxml/histos"
// mutex in a file scope
namespace {
//Mutex to lock master manager when merging H1 histograms
G4Mutex mergeH1Mutex = G4MUTEX_INITIALIZER;
//Mutex to lock master manager when merging H1 histograms
G4Mutex mergeH2Mutex = G4MUTEX_INITIALIZER;
}
G4XmlAnalysisManager* G4XmlAnalysisManager::fgMasterInstance = 0;
G4ThreadLocal G4XmlAnalysisManager* G4XmlAnalysisManager::fgInstance = 0;
//_____________________________________________________________________________
G4XmlAnalysisManager* G4XmlAnalysisManager::Instance()
{
if ( fgInstance == 0 ) {
G4bool isMaster = ! G4Threading::IsWorkerThread();
fgInstance = new G4XmlAnalysisManager(isMaster);
}
return fgInstance;
}
//_____________________________________________________________________________
G4XmlAnalysisManager::G4XmlAnalysisManager(G4bool isMaster)
: G4VAnalysisManager("Xml", isMaster),
fH1Manager(0),
fH2Manager(0),
fNtupleManager(0),
fFileManager(0)
{
if ( ( isMaster && fgMasterInstance ) || ( fgInstance ) ) {
G4ExceptionDescription description;
description
<< " "
<< "G4XmlAnalysisManager already exists."
<< "Cannot create another instance.";
G4Exception("G4XmlAnalysisManager::G4XmlAnalysisManager",
"Analysis_F001", FatalException, description);
}
if ( isMaster ) fgMasterInstance = this;
fgInstance = this;
// Create managers
fH1Manager = new G4H1ToolsManager(fState);
fH2Manager = new G4H2ToolsManager(fState);
fNtupleManager = new G4XmlNtupleManager(fState);
fFileManager = new G4XmlFileManager(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);
}
//_____________________________________________________________________________
G4XmlAnalysisManager::~G4XmlAnalysisManager()
{
if ( fState.GetIsMaster() ) fgMasterInstance = 0;
fgInstance = 0;
}
//
// private methods
//
//_____________________________________________________________________________
G4bool G4XmlAnalysisManager::WriteH1()
{
const std::vector<tools::histo::h1d*>& h1Vector
= fH1Manager->GetH1Vector();
const std::vector<G4HnInformation*>& hnVector
= fH1Manager->GetHnVector();
if ( ! h1Vector.size() ) return true;
if ( ! G4Threading::IsWorkerThread() ) {
for ( G4int i=0; i<G4int(h1Vector.size()); ++i ) {
G4HnInformation* info = hnVector[i];
G4bool activation = info->fActivation;
G4String name = info->fName;
// skip writing if activation is enabled and H1 is inactivated
if ( fState.GetIsActivation() && ( ! activation ) ) continue;
tools::histo::h1d* h1 = h1Vector[i];
#ifdef G4VERBOSE
if ( fState.GetVerboseL3() )
fState.GetVerboseL3()->Message("write", "h1d", name);
#endif
G4String path = "/";
path.append(fFileManager->GetHistoDirectoryName());
std::ofstream* hnFile = fFileManager->GetHnFile();
G4bool result
= tools::waxml::write(*hnFile, *h1, path, name);
if ( ! result ) {
G4ExceptionDescription description;
description << " " << "saving histogram " << name << " failed";
G4Exception("G4XmlAnalysisManager::Write()",
"Analysis_W003", JustWarning, description);
return false;
}
fFileManager->LockHistoDirectoryName();
}
}
else {
// The worker manager just adds its histograms to the master
// This operation needs a lock
G4AutoLock lH1(&mergeH1Mutex);
fgMasterInstance->fH1Manager->AddH1Vector(h1Vector);
lH1.unlock();
}
return true;
}
//_____________________________________________________________________________
G4bool G4XmlAnalysisManager::WriteH2()
{
const std::vector<tools::histo::h2d*>& h2Vector
= fH2Manager->GetH2Vector();
const std::vector<G4HnInformation*>& hnVector
= fH2Manager->GetHnVector();
if ( ! h2Vector.size() ) return true;
if ( ! G4Threading::IsWorkerThread() ) {
// h2 histograms
for ( G4int i=0; i<G4int(h2Vector.size()); ++i ) {
G4HnInformation* info = hnVector[i];
G4bool activation = info->fActivation;
G4String name = info->fName;
// skip writing if inactivated
if ( fState.GetIsActivation() && ( ! activation ) ) continue;
tools::histo::h2d* h2 = h2Vector[i];
#ifdef G4VERBOSE
if ( fState.GetVerboseL3() )
fState.GetVerboseL3()->Message("write", "h2d", name);
#endif
G4String path = "/";
path.append(fFileManager->GetHistoDirectoryName());
std::ofstream* hnFile = fFileManager->GetHnFile();
G4bool result
= tools::waxml::write(*hnFile, *h2, path, name);
if ( ! result ) {
G4ExceptionDescription description;
description << " " << "saving histogram " << name << " failed";
G4Exception("G4XmlAnalysisManager::Write()",
"Analysis_W003", JustWarning, description);
return false;
}
fFileManager->LockHistoDirectoryName();
}
}
else {
// The worker manager just adds its histograms to the master
// This operation needs a lock
G4AutoLock lH2(&mergeH2Mutex);
fgMasterInstance->fH2Manager->AddH2Vector(h2Vector);
lH2.unlock();
}
return true;
}
//_____________________________________________________________________________
G4bool G4XmlAnalysisManager::WriteNtuple()
{
const std::vector<G4XmlNtupleDescription*>& ntupleVector
= fNtupleManager->GetNtupleVector();
for ( G4int i=0; i<G4int(ntupleVector.size()); ++i ) {
if ( ntupleVector[i]->fNtuple ) ntupleVector[i]->fNtuple->write_trailer();
}
return true;
}
//_____________________________________________________________________________
G4bool G4XmlAnalysisManager::CloseNtupleFiles()
{
const std::vector<G4XmlNtupleDescription*>& ntupleVector
= fNtupleManager->GetNtupleVector();
// Close ntuple files
std::vector<G4XmlNtupleDescription*>::const_iterator it;
for (it = ntupleVector.begin(); it != ntupleVector.end(); it++ ) {
fFileManager->CloseNtupleFile((*it));
}
return true;
}
//_____________________________________________________________________________
G4bool G4XmlAnalysisManager::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
//
//_____________________________________________________________________________
G4bool G4XmlAnalysisManager::OpenFileImpl(const G4String& fileName)
{
G4bool finalResult = true;
G4bool result = fFileManager->SetFileName(fileName);
finalResult = finalResult && result;
#ifdef G4VERBOSE
G4String name = fFileManager->GetFullFileName();
if ( fState.GetVerboseL4() ) {
fState.GetVerboseL4()->Message("open", "analysis file", name);
}
#endif
// Only lock file name in file manager
result = fFileManager->OpenFile(fileName);
finalResult = finalResult && result;
// Create histograms file (on master)
if ( fState.GetIsMaster() ) {
result = fFileManager->CreateHnFile();
finalResult = finalResult && result;
}
// Create ntuples if they are booked
// (The files will be created with creating ntuples)
fNtupleManager->CreateNtuplesFromBooking();
#ifdef G4VERBOSE
if ( fState.GetVerboseL1() )
fState.GetVerboseL1()->Message("open", "analysis file", name);
#endif
return finalResult;
}
//_____________________________________________________________________________
G4bool G4XmlAnalysisManager::WriteImpl()
{
G4bool finalResult = true;
#ifdef G4VERBOSE
G4String name = fFileManager->GetFullFileName();
if ( fState.GetVerboseL4() )
fState.GetVerboseL4()->Message("write", "files", name);
#endif
// ntuples
WriteNtuple();
if ( ! fgMasterInstance &&
( ( ! fH1Manager->IsEmpty() ) || ( ! fH2Manager->IsEmpty() ) ) ) {
G4ExceptionDescription description;
description
<< " " << "No master G4XmlAnalysisManager instance exists."
<< G4endl
<< " " << "Histogram data will not be merged.";
G4Exception("G4XmlAnalysisManager::Write()",
"Analysis_W014", JustWarning, description);
// Create Hn file per thread
G4bool result = fFileManager->CreateHnFile();
if ( ! result ) return false;
}
// H1
G4bool result = WriteH1();
finalResult = finalResult && result;
// H2
result = WriteH2();
finalResult = finalResult && result;
// Write ASCII if activated
if ( IsAscii() ) {
result = WriteAscii(fFileManager->GetFileName());
finalResult = finalResult && result;
}
#ifdef G4VERBOSE
if ( fState.GetVerboseL1() )
fState.GetVerboseL1()
->Message("write", "files", fFileManager->GetFullFileName(), finalResult);
#endif
return finalResult;
}
//_____________________________________________________________________________
G4bool G4XmlAnalysisManager::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 Hn file
result = fFileManager->CloseHnFile();
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 = Reset();
if ( ! result ) {
G4ExceptionDescription description;
description << " " << "Resetting data failed";
G4Exception("G4XmlAnalysisManager::CloseFile()",
"Analysis_W002", 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());
#ifdef G4VERBOSE
if ( fState.GetVerboseL1() )
fState.GetVerboseL1()
->Message("delete", "empty file", fFileManager->GetFullFileName());
#endif
}
else {
#ifdef G4VERBOSE
if ( fState.GetVerboseL1() )
fState.GetVerboseL1()
->Message("close", "files", fFileManager->GetFullFileName());
#endif
}
return finalResult;
}
+191
View File
@@ -0,0 +1,191 @@
//
// ********************************************************************
// * 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: G4XmlFileManager.cc 70604 2013-06-03 11:27:06Z ihrivnac $
// Author: Ivana Hrivnacova, 18/06/2013 (ivana@ipno.in2p3.fr)
#include "G4XmlFileManager.hh"
#include "G4AnalysisManagerState.hh"
#include "tools/waxml/begend"
//_____________________________________________________________________________
G4XmlFileManager::G4XmlFileManager(const G4AnalysisManagerState& state)
: G4VFileManager(state),
fHnFile(0)
{
}
//_____________________________________________________________________________
G4XmlFileManager::~G4XmlFileManager()
{
delete fHnFile;
}
//
// public methods
//
//_____________________________________________________________________________
G4bool G4XmlFileManager::OpenFile(const G4String& fileName)
{
// Keep and locks file name
fFileName = fileName;
fLockFileName = true;
return true;
}
//_____________________________________________________________________________
G4bool G4XmlFileManager::WriteFile()
{
// Nothing to be done here
return true;
}
//_____________________________________________________________________________
G4bool G4XmlFileManager::CloseFile()
{
// Unlock file name
fLockFileName = false;
return true;
}
//_____________________________________________________________________________
G4bool G4XmlFileManager::CreateHnFile()
{
#ifdef G4VERBOSE
if ( fState.GetVerboseL4() )
fState.GetVerboseL4()->Message("create", "histo file", GetFullFileName());
#endif
// delete a previous file if it exists
if ( fHnFile ) delete fHnFile;
fHnFile = new std::ofstream(GetFullFileName());
if ( fHnFile->fail() ) {
G4ExceptionDescription description;
description << " " << "Cannot open file " << GetFullFileName();
G4Exception("G4XmlFileManager::CreateHnFile()",
"Analysis_W001", JustWarning, description);
return false;
}
tools::waxml::begin(*fHnFile);
#ifdef G4VERBOSE
if ( fState.GetVerboseL1() )
fState.GetVerboseL1()->Message("create", "histo file", GetFullFileName());
#endif
return true;
}
//_____________________________________________________________________________
G4bool G4XmlFileManager::CloseHnFile()
{
// No file may be open if no master manager is instantiated
// and no histograms were booked
if ( ! fHnFile ) return true;
#ifdef G4VERBOSE
if ( fState.GetVerboseL4() )
fState.GetVerboseL4()->Message("close", "histo file", GetFullFileName());
#endif
// close file
tools::waxml::end(*fHnFile);
fHnFile->close();
#ifdef G4VERBOSE
if ( fState.GetVerboseL1() )
fState.GetVerboseL1()->Message("close", "histo file", GetFullFileName());
#endif
return true;
}
//_____________________________________________________________________________
G4bool G4XmlFileManager::CreateNtupleFile(
G4XmlNtupleDescription* ntupleDescription)
{
G4String ntupleName = ntupleDescription->fNtupleBooking->m_name;
#ifdef G4VERBOSE
if ( fState.GetVerboseL4() )
fState.GetVerboseL4()
->Message("create", "ntuple file", GetNtupleFileName(ntupleName));
#endif
std::ofstream* ntupleFile
= new std::ofstream(GetNtupleFileName(ntupleName));
if ( ntupleFile->fail() ) {
G4ExceptionDescription description;
description << " " << "Cannot open file "
<< GetNtupleFileName(ntupleName);
G4Exception("G4XmlFileManager::CreateNtupleFile()",
"Analysis_W001", JustWarning, description);
return false;
}
tools::waxml::begin(*ntupleFile);
ntupleDescription->fFile = ntupleFile;
#ifdef G4VERBOSE
if ( fState.GetVerboseL1() )
fState.GetVerboseL1()
->Message("create", "ntuple file", GetNtupleFileName(ntupleName));
#endif
return true;
}
//_____________________________________________________________________________
G4bool G4XmlFileManager::CloseNtupleFile(
G4XmlNtupleDescription* ntupleDescription)
{
G4String ntupleName = ntupleDescription->fNtupleBooking->m_name;
#ifdef G4VERBOSE
if ( fState.GetVerboseL4() )
fState.GetVerboseL4()
->Message("close", "ntuple file", GetNtupleFileName(ntupleName));
#endif
// close file
tools::waxml::end(*(ntupleDescription->fFile));
ntupleDescription->fFile->close();
#ifdef G4VERBOSE
if ( fState.GetVerboseL1() )
fState.GetVerboseL1()
->Message("close", "ntuple file", GetNtupleFileName(ntupleName));
#endif
return true;
}
@@ -0,0 +1,654 @@
//
// ********************************************************************
// * 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: G4XmlNtupleManager.cc 70604 2013-06-03 11:27:06Z ihrivnac $
// Author: Ivana Hrivnacova, 18/06/2013 (ivana@ipno.in2p3.fr)
#include "G4XmlNtupleManager.hh"
#include "G4XmlNtupleDescription.hh"
#include "G4XmlFileManager.hh"
#include "G4AnalysisManagerState.hh"
#include "G4UnitsTable.hh"
#include "tools/ntuple_booking"
#include <iostream>
#include <cstdio>
//_____________________________________________________________________________
G4XmlNtupleManager::G4XmlNtupleManager(const G4AnalysisManagerState& state)
: G4VNtupleManager(state),
fFileManager(0),
fNtupleVector()
{
}
//_____________________________________________________________________________
G4XmlNtupleManager::~G4XmlNtupleManager()
{
std::vector<G4XmlNtupleDescription*>::iterator it;
for (it = fNtupleVector.begin(); it != fNtupleVector.end(); it++ ) {
delete (*it);
}
}
//
// private methods
//
//_____________________________________________________________________________
tools::waxml::ntuple::column<int>*
G4XmlNtupleManager::GetNtupleIColumn(G4int ntupleId, G4int columnId) const
{
G4XmlNtupleDescription* ntupleDecription
= GetNtupleInFunction(ntupleId, "GetNtupleIColumn");
if ( ! ntupleDecription ) return 0;
std::map<G4int, tools::waxml::ntuple::column<int>* >& ntupleIColumnMap
= ntupleDecription->fNtupleIColumnMap;
std::map<G4int, tools::waxml::ntuple::column<int>* >::const_iterator it
= ntupleIColumnMap.find(columnId);
if ( it == ntupleIColumnMap.end() ) {
G4ExceptionDescription description;
description << " " << "ntupleId " << ntupleId
<< "column " << columnId << " does not exist.";
G4Exception("G4XmlNtupleManager::GetNtupleIColumn()",
"Analysis_W009", JustWarning, description);
return 0;
}
return it->second;
}
//_____________________________________________________________________________
tools::waxml::ntuple::column<float>*
G4XmlNtupleManager::GetNtupleFColumn(G4int ntupleId, G4int columnId) const
{
G4XmlNtupleDescription* ntupleDecription
= GetNtupleInFunction(ntupleId, "GetNtupleFColumn");
if ( ! ntupleDecription ) return 0;
std::map<G4int, tools::waxml::ntuple::column<float>* >& ntupleFColumnMap
= ntupleDecription->fNtupleFColumnMap;
std::map<G4int, tools::waxml::ntuple::column<float>* >::const_iterator it
= ntupleFColumnMap.find(columnId);
if ( it == ntupleFColumnMap.end() ) {
G4ExceptionDescription description;
description << " " << "ntupleId " << ntupleId
<< "column " << columnId << " does not exist.";
G4Exception("G4XmlNtupleManager::GetNtupleFColumn()",
"Analysis_W009", JustWarning, description);
return 0;
}
return it->second;
}
//_____________________________________________________________________________
tools::waxml::ntuple::column<double>*
G4XmlNtupleManager::GetNtupleDColumn(G4int ntupleId, G4int columnId) const
{
G4XmlNtupleDescription* ntupleDecription
= GetNtupleInFunction(ntupleId, "GetNtupleDColumn");
if ( ! ntupleDecription ) return 0;
std::map<G4int, tools::waxml::ntuple::column<double>* >& ntupleDColumnMap
= ntupleDecription->fNtupleDColumnMap;
std::map<G4int, tools::waxml::ntuple::column<double>* >::const_iterator it
= ntupleDColumnMap.find(columnId);
if ( it == ntupleDColumnMap.end() ) {
G4ExceptionDescription description;
description << " " << "ntupleId " << ntupleId
<< "column " << columnId << " does not exist.";
G4Exception("G4XmlNtupleManager::GetNtupleFColumn()",
"Analysis_W009", JustWarning, description);
return 0;
}
return it->second;
}
//_____________________________________________________________________________
G4XmlNtupleDescription* G4XmlNtupleManager::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 = "G4XmlNtupleManager::";
inFunction += functionName;
G4ExceptionDescription description;
description << " " << "ntuple " << id << " does not exist.";
G4Exception(inFunction, "Analysis_W007", JustWarning, description);
}
return 0;
}
return fNtupleVector[index];
}
//
// protected methods
//
//_____________________________________________________________________________
void G4XmlNtupleManager::CreateNtuplesFromBooking()
{
// Create ntuple from ntuple_booking.
// Do not create ntuples on master thread
if ( G4AnalysisManagerState::IsMT() && fState.GetIsMaster() ) return;
std::vector<G4XmlNtupleDescription*>::iterator itn;
for (itn = fNtupleVector.begin(); itn != fNtupleVector.end(); itn++ ) {
tools::ntuple_booking* ntupleBooking = (*itn)->fNtupleBooking;
if ( ! ntupleBooking ) continue;
// Create ntuple from ntuple_booking.
#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::waxml::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("G4XmlNtupleManager::CreateNtuplesFromBooking()",
"Analysis_W004", JustWarning, description);
}
}
}
FinishNtuple();
#ifdef G4VERBOSE
if ( fState.GetVerboseL3() )
fState.GetVerboseL3()
->Message("create from booking", "ntuple", ntupleBooking->m_name);
#endif
}
}
//_____________________________________________________________________________
G4bool G4XmlNtupleManager::IsEmpty() const
{
return ! fNtupleVector.size();
}
//_____________________________________________________________________________
G4bool G4XmlNtupleManager::Reset()
{
// Reset ntuples
std::vector<G4XmlNtupleDescription*>::iterator it;
for (it = fNtupleVector.begin(); it != fNtupleVector.end(); it++ ) {
delete (*it)->fNtuple;
(*it)->fNtuple = 0;
}
return true;
}
//_____________________________________________________________________________
tools::waxml::ntuple* G4XmlNtupleManager::GetNtuple() const
{
return GetNtuple(fFirstId);
}
//_____________________________________________________________________________
tools::waxml::ntuple* G4XmlNtupleManager::GetNtuple(G4int ntupleId) const
{
G4XmlNtupleDescription* ntupleDescription
= GetNtupleInFunction(ntupleId, "GetNtuple");
return ntupleDescription->fNtuple;
}
//_____________________________________________________________________________
G4int G4XmlNtupleManager::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();
G4XmlNtupleDescription* ntupleDescription
= new G4XmlNtupleDescription();
fNtupleVector.push_back(ntupleDescription);
// Create ntuple booking
ntupleDescription->fNtupleBooking = new tools::ntuple_booking();
ntupleDescription->fNtupleBooking->m_name = name;
ntupleDescription->fNtupleBooking->m_title = title;
// 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::waxml::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 G4XmlNtupleManager::CreateNtupleIColumn(const G4String& name)
{
G4int ntupleId = fNtupleVector.size() + fFirstId - 1;
return CreateNtupleIColumn(ntupleId, name);
}
//_____________________________________________________________________________
G4int G4XmlNtupleManager::CreateNtupleFColumn(const G4String& name)
{
G4int ntupleId = fNtupleVector.size() + fFirstId - 1;
return CreateNtupleFColumn(ntupleId, name);
}
//_____________________________________________________________________________
G4int G4XmlNtupleManager::CreateNtupleDColumn(const G4String& name)
{
G4int ntupleId = fNtupleVector.size() + fFirstId - 1;
return CreateNtupleDColumn(ntupleId, name);
}
//_____________________________________________________________________________
void G4XmlNtupleManager::FinishNtuple()
{
G4int ntupleId = fNtupleVector.size() + fFirstId - 1;
FinishNtuple(ntupleId);
}
//_____________________________________________________________________________
G4int G4XmlNtupleManager::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
G4XmlNtupleDescription* ntupleDescription
= GetNtupleInFunction(ntupleId, "CreateNtupleIColumn");
tools::ntuple_booking* ntupleBooking
= ntupleDescription->fNtupleBooking;
if ( ! ntupleBooking ) {
G4ExceptionDescription description;
description << " "
<< "Ntuple " << ntupleId << " has to be created first. ";
G4Exception("G4XmlNtupleManager::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::waxml::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 G4XmlNtupleManager::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
G4XmlNtupleDescription* ntupleDescription
= GetNtupleInFunction(ntupleId, "CreateNtupleFColumn");
tools::ntuple_booking* ntupleBooking
= ntupleDescription->fNtupleBooking;
if ( ! ntupleBooking ) {
G4ExceptionDescription description;
description << " "
<< "Ntuple " << ntupleId << " has to be created first. ";
G4Exception("G4XmlNtupleManager::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::waxml::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 G4XmlNtupleManager::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
G4XmlNtupleDescription* ntupleDescription
= GetNtupleInFunction(ntupleId, "CreateNtupleDColumn");
tools::ntuple_booking* ntupleBooking
= ntupleDescription->fNtupleBooking;
if ( ! ntupleBooking ) {
G4ExceptionDescription description;
description << " "
<< "Ntuple " << ntupleId << " has to be created first. ";
G4Exception("G4XmlNtupleManager::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::waxml::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 G4XmlNtupleManager::FinishNtuple(G4int ntupleId)
{
G4XmlNtupleDescription* ntupleDescription
= GetNtupleInFunction(ntupleId, "FinishNtuple");
tools::ntuple_booking* ntupleBooking
= ntupleDescription->fNtupleBooking;
if ( ! ntupleBooking ) {
G4ExceptionDescription description;
description << " "
<< "Ntuple " << ntupleId << " has to be created first. ";
G4Exception("G4XmlNtupleManager::CreateNtupleDColumn()",
"Analysis_W005", JustWarning, description);
return;
}
#ifdef G4VERBOSE
if ( fState.GetVerboseL4() ) {
G4ExceptionDescription description;
description << ntupleBooking->m_name << " ntupleId " << ntupleId;
fState.GetVerboseL4()->Message("finish", "ntuple", description);
}
#endif
// Finish ntuple if ntuple already exists
if ( ntupleDescription->fNtuple ) {
G4String path = "/";
path.append(fFileManager->GetNtupleDirectoryName());
ntupleDescription->fNtuple
->write_header(path, ntupleBooking->m_name, ntupleBooking->m_title);
fFileManager->LockNtupleDirectoryName();
}
#ifdef G4VERBOSE
if ( fState.GetVerboseL2() ) {
G4ExceptionDescription description;
description << ntupleBooking->m_name << " ntupleId " << ntupleId;
fState.GetVerboseL2()->Message("finish", "ntuple", description);
}
#endif
}
//_____________________________________________________________________________
G4bool G4XmlNtupleManager::FillNtupleIColumn(G4int columnId, G4int value)
{
return FillNtupleIColumn(fFirstId, columnId, value);
}
//_____________________________________________________________________________
G4bool G4XmlNtupleManager::FillNtupleFColumn(G4int columnId, G4float value)
{
return FillNtupleFColumn(fFirstId, columnId, value);
}
//_____________________________________________________________________________
G4bool G4XmlNtupleManager::FillNtupleDColumn(G4int columnId, G4double value)
{
return FillNtupleDColumn(fFirstId, columnId, value);
}
//_____________________________________________________________________________
G4bool G4XmlNtupleManager::FillNtupleIColumn(G4int ntupleId, G4int columnId,
G4int value)
{
tools::waxml::ntuple::column<int>* column
= GetNtupleIColumn(ntupleId, columnId);
if ( ! column ) {
G4ExceptionDescription description;
description << " " << "column " << columnId << " does not exist.";
G4Exception("G4XmlNtupleManager::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 G4XmlNtupleManager::FillNtupleFColumn(G4int ntupleId, G4int columnId,
G4float value)
{
tools::waxml::ntuple::column<float>* column
= GetNtupleFColumn(ntupleId, columnId);
if ( ! column ) {
G4ExceptionDescription description;
description << " " << "column " << columnId << " does not exist.";
G4Exception("G4XmlNtupleManager::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 G4XmlNtupleManager::FillNtupleDColumn(G4int ntupleId, G4int columnId,
G4double value)
{
tools::waxml::ntuple::column<double>* column
= GetNtupleDColumn(ntupleId, columnId);
if ( ! column ) {
G4ExceptionDescription description;
description << " " << "column " << columnId << " does not exist.";
G4Exception("G4XmlNtupleManager::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 G4XmlNtupleManager::AddNtupleRow()
{
return AddNtupleRow(fFirstId);
}
//_____________________________________________________________________________
G4bool G4XmlNtupleManager::AddNtupleRow(G4int ntupleId)
{
#ifdef G4VERBOSE
if ( fState.GetVerboseL4() ) {
G4ExceptionDescription description;
description << " ntupleId " << ntupleId;
fState.GetVerboseL4()->Message("add", "ntuple row", description);
}
#endif
G4XmlNtupleDescription* ntupleDescription
= GetNtupleInFunction(ntupleId, "AddNtupleRow");
if ( ! ntupleDescription || ! ntupleDescription->fNtuple ) {
G4ExceptionDescription description;
description << " " << "ntuple does not exist. ";
G4Exception("G4XmlNtupleManager::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;
}