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.G4root
#
# 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()
+25
View File
@@ -0,0 +1,25 @@
# $Id: GNUmakefile 66356 2012-12-18 09:02:32Z gcosmo $
# --------------------------------------------------------------------
# GNUmakefile for geometry/biasing library. Gabriele Cosmo, 25/03/02.
# --------------------------------------------------------------------
name := G4root
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
ifdef G4LIB_BUILD_ZLIB
CPPFLAGS += -I$(G4BASE)/externals/zlib/include
endif
include $(G4INSTALL)/config/common.gmk
@@ -0,0 +1,93 @@
//
// ********************************************************************
// * 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: G4RootAnalysisManager.hh 74257 2013-10-02 14:24:55Z gcosmo $
// The main manager for Root analysis.
// It delegates most of functions to the object specific managers.
// Author: Ivana Hrivnacova, 18/06/2013 (ivana@ipno.in2p3.fr)
#ifndef G4RootAnalysisManager_h
#define G4RootAnalysisManager_h 1
#include "G4VAnalysisManager.hh"
#include "globals.hh"
#include "tools/histo/h1d"
#include "tools/histo/h2d"
#include "tools/wroot/ntuple"
class G4RootFileManager;
class G4H1ToolsManager;
class G4H2ToolsManager;
class G4RootNtupleManager;
class G4RootAnalysisManager : public G4VAnalysisManager
{
public:
G4RootAnalysisManager(G4bool isMaster = true);
virtual ~G4RootAnalysisManager();
// static methods
static G4RootAnalysisManager* 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::wroot::ntuple* GetNtuple() const;
tools::wroot::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 G4RootAnalysisManager* fgMasterInstance;
static G4ThreadLocal G4RootAnalysisManager* fgInstance;
// methods
G4bool WriteH1();
G4bool WriteH2();
G4bool Reset();
// data members
G4H1ToolsManager* fH1Manager;
G4H2ToolsManager* fH2Manager;
G4RootNtupleManager* fNtupleManager;
G4RootFileManager* fFileManager;
};
#include "G4RootAnalysisManager.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: G4RootAnalysisManager.hh 70604 2013-06-03 11:27:06Z ihrivnac $
#include "G4H1ToolsManager.hh"
#include "G4H2ToolsManager.hh"
#include "G4RootNtupleManager.hh"
//_____________________________________________________________________________
inline
tools::histo::h1d* G4RootAnalysisManager::GetH1(G4int id, G4bool warn,
G4bool onlyIfActive) const
{
return fH1Manager->GetH1(id, warn, onlyIfActive);
}
//_____________________________________________________________________________
inline
tools::histo::h2d* G4RootAnalysisManager::GetH2(G4int id, G4bool warn,
G4bool onlyIfActive) const
{
return fH2Manager->GetH2(id, warn, onlyIfActive);
}
//_____________________________________________________________________________
inline
tools::wroot::ntuple* G4RootAnalysisManager::GetNtuple() const
{
return fNtupleManager->GetNtuple();
}
//_____________________________________________________________________________
inline
tools::wroot::ntuple* G4RootAnalysisManager::GetNtuple(G4int ntupleId) const
{
return fNtupleManager->GetNtuple(ntupleId);
}
@@ -0,0 +1,84 @@
//
// ********************************************************************
// * 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: G4RootFileManager.hh 70604 2013-06-03 11:27:06Z ihrivnac $
// The manager for Root file operations.
// Author: Ivana Hrivnacova, 18/06/2013 (ivana@ipno.in2p3.fr)
#ifndef G4RootFileManager_h
#define G4RootFileManager_h 1
#include "G4VFileManager.hh"
#include "globals.hh"
namespace tools {
namespace wroot {
class file;
class directory;
}
}
class G4RootFileManager : public G4VFileManager
{
public:
G4RootFileManager(const G4AnalysisManagerState& state);
virtual ~G4RootFileManager();
// Methods to manipulate files
virtual G4bool OpenFile(const G4String& fileName);
virtual G4bool WriteFile();
virtual G4bool CloseFile();
G4bool CreateHistoDirectory();
G4bool CreateNtupleDirectory();
// Get methods
tools::wroot::file* GetFile() const;
tools::wroot::directory* GetHistoDirectory() const;
tools::wroot::directory* GetNtupleDirectory() const;
private:
// data members
//
tools::wroot::file* fFile;
tools::wroot::directory* fHistoDirectory;
tools::wroot::directory* fNtupleDirectory;
};
// inline functions
inline tools::wroot::file* G4RootFileManager::GetFile() const
{ return fFile; }
inline tools::wroot::directory* G4RootFileManager::GetHistoDirectory() const
{ return fHistoDirectory; }
inline tools::wroot::directory* G4RootFileManager::GetNtupleDirectory() const
{ return fNtupleDirectory; }
#endif
@@ -0,0 +1,66 @@
//
// ********************************************************************
// * 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 Root ntuple
//
// Author: Ivana Hrivnacova, 04/07/2012 (ivana@ipno.in2p3.fr)
#ifndef G4RootNtupleDescription_h
#define G4RootNtupleDescription_h 1
#include "tools/wroot/ntuple"
#include <map>
namespace tools {
class ntuple_booking;
}
struct G4RootNtupleDescription
{
G4RootNtupleDescription()
: fNtuple(0),
fNtupleBooking(0),
fNtupleIColumnMap(),
fNtupleFColumnMap(),
fNtupleDColumnMap() {}
~G4RootNtupleDescription()
{
delete fNtupleBooking;
// fNtuple is owned by the file
}
tools::wroot::ntuple* fNtuple;
tools::ntuple_booking* fNtupleBooking;
std::map<G4int, tools::wroot::ntuple::column<int>* > fNtupleIColumnMap;
std::map<G4int, tools::wroot::ntuple::column<float>* > fNtupleFColumnMap;
std::map<G4int, tools::wroot::ntuple::column<double>* > fNtupleDColumnMap;
};
#endif
@@ -0,0 +1,138 @@
//
// ********************************************************************
// * 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: G4RootNtupleManager.hh 70604 2013-06-03 11:27:06Z ihrivnac $
// Manager class for Root ntuples.
// It implements functions specific to Root ntuples.
//
// Author: Ivana Hrivnacova, 18/06/2013 (ivana@ipno.in2p3.fr)
#ifndef G4RootNtupleManager_h
#define G4RootNtupleManager_h 1
#include "G4VNtupleManager.hh"
#include "globals.hh"
#include "tools/wroot/ntuple"
#include <vector>
struct G4RootNtupleDescription;
namespace tools {
namespace wroot {
class directory;
}
}
class G4RootNtupleManager : public G4VNtupleManager
{
friend class G4RootAnalysisManager;
protected:
G4RootNtupleManager(const G4AnalysisManagerState& state);
virtual ~G4RootNtupleManager();
// Functions specific to the output type
//
// Methods to manipulate ntuples
void CreateNtuplesFromBooking();
G4bool IsEmpty() const;
G4bool Reset();
// Set methods
void SetNtupleDirectory(tools::wroot::directory* directory);
// Access methods
tools::wroot::ntuple* GetNtuple() const;
tools::wroot::ntuple* GetNtuple(G4int ntupleId) const;
// Functions independent from the output type
//
// 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::wroot::ntuple::column<int>*
GetNtupleIColumn(G4int ntupleId, G4int columnId) const;
tools::wroot::ntuple::column<float>*
GetNtupleFColumn(G4int ntupleId, G4int columnId) const;
tools::wroot::ntuple::column<double>*
GetNtupleDColumn(G4int ntupleId, G4int columnId) const;
virtual G4RootNtupleDescription* GetNtupleInFunction(G4int id,
G4String function,
G4bool warn = true,
G4bool onlyIfActive = true) const;
// data members
//
tools::wroot::directory* fNtupleDirectory;
std::vector<G4RootNtupleDescription*> fNtupleVector;
};
// inline functions
inline void G4RootNtupleManager::SetNtupleDirectory(
tools::wroot::directory* directory) {
fNtupleDirectory = directory;
}
inline G4int G4RootNtupleManager::GetNofNtuples() const
{ return fNtupleVector.size(); }
#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: g4root.hh 72292 2013-07-15 12:01:43Z ihrivnac $
// Author: Ivana Hrivnacova, 15/06/2011 (ivana@ipno.in2p3.fr)
#ifndef g4root_h
#define g4root_h
#include "g4root_defs.hh"
using namespace G4Root;
#endif
@@ -0,0 +1,48 @@
//
// ********************************************************************
// * 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: g4root_defs.hh 72292 2013-07-15 12:01:43Z ihrivnac $
// Author: Ivana Hrivnacova, 15/06/2011 (ivana@ipno.in2p3.fr)
#ifndef g4root_defs_h
#define g4root_defs_h
#include "tools/histo/h1d"
#include "tools/histo/h2d"
#include "tools/wroot/ntuple"
#include "G4RootAnalysisManager.hh"
namespace G4Root {
typedef tools::histo::h1d G4AnaH1;
typedef tools::histo::h2d G4AnaH2;
typedef tools::wroot::ntuple G4Ntuple;
typedef G4RootAnalysisManager G4AnalysisManager;
}
#endif
+58
View File
@@ -0,0 +1,58 @@
#------------------------------------------------------------------------------
# sources.cmake
# Module : G4csv
# Package: Geant4.src.G4analysis.G4root
#
# 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})
include_directories(${ZLIB_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 G4root
HEADERS
G4RootAnalysisManager.hh
G4RootAnalysisManager.icc
G4RootFileManager.hh
G4RootNtupleDescription.hh
G4RootNtupleManager.hh
g4root_defs.hh
g4root.hh
SOURCES
G4RootAnalysisManager.cc
G4RootFileManager.cc
G4RootNtupleManager.cc
GRANULAR_DEPENDENCIES
G4globman
G4intercoms
G4analysismng
G4hntools
GLOBAL_DEPENDENCIES
G4global
G4intercoms
LINK_LIBRARIES
${ZLIB_LIBRARIES}
)
# List any source specific properties here
@@ -0,0 +1,342 @@
//
// ********************************************************************
// * 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: G4RootAnalysisManager.cc 74257 2013-10-02 14:24:55Z gcosmo $
// Author: Ivana Hrivnacova, 18/06/2013 (ivana@ipno.in2p3.fr)
#include "G4RootAnalysisManager.hh"
#include "G4RootFileManager.hh"
#include "G4H1ToolsManager.hh"
#include "G4H2ToolsManager.hh"
#include "G4RootNtupleManager.hh"
#include "G4AnalysisVerbose.hh"
#include "G4Threading.hh"
#include "G4AutoLock.hh"
#include "tools/wroot/to"
#include "tools/wroot/file"
#include <iostream>
#include <cstdio>
// 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;
}
G4RootAnalysisManager* G4RootAnalysisManager::fgMasterInstance = 0;
G4ThreadLocal G4RootAnalysisManager* G4RootAnalysisManager::fgInstance = 0;
//_____________________________________________________________________________
G4RootAnalysisManager* G4RootAnalysisManager::Instance()
{
if ( fgInstance == 0 ) {
G4bool isMaster = ! G4Threading::IsWorkerThread();
fgInstance = new G4RootAnalysisManager(isMaster);
}
return fgInstance;
}
//_____________________________________________________________________________
G4RootAnalysisManager::G4RootAnalysisManager(G4bool isMaster)
: G4VAnalysisManager("Root", isMaster),
fH1Manager(0),
fH2Manager(0),
fNtupleManager(0),
fFileManager(0)
{
if ( ( isMaster && fgMasterInstance ) || ( fgInstance ) ) {
G4ExceptionDescription description;
description
<< " "
<< "G4RootAnalysisManager already exists."
<< "Cannot create another instance.";
G4Exception("G4RootAnalysisManager::G4RootAnalysisManager()",
"Analysis_F001", FatalException, description);
}
if ( isMaster ) fgMasterInstance = this;
fgInstance = this;
// Create managers
fH1Manager = new G4H1ToolsManager(fState);
fH2Manager = new G4H2ToolsManager(fState);
fNtupleManager = new G4RootNtupleManager(fState);
fFileManager = new G4RootFileManager(fState);
// The managers will be deleted by the base class
// Set managers to base class
SetH1Manager(fH1Manager);
SetH2Manager(fH2Manager);
SetNtupleManager(fNtupleManager);
SetFileManager(fFileManager);
}
//_____________________________________________________________________________
G4RootAnalysisManager::~G4RootAnalysisManager()
{
if ( fState.GetIsMaster() ) fgMasterInstance = 0;
fgInstance = 0;
}
//
// private methods
//
//_____________________________________________________________________________
G4bool G4RootAnalysisManager::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
tools::wroot::directory* histoDirectory
= fFileManager->GetHistoDirectory();
G4bool result
= to(*histoDirectory, *h1, name);
if ( ! result ) {
G4ExceptionDescription description;
description << " " << "saving histogram " << name << " failed";
G4Exception("G4RootAnalysisManager::Write()",
"Analysis_W003", JustWarning, description);
return false;
}
}
}
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 G4RootAnalysisManager::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() ) {
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
tools::wroot::directory* histoDirectory
= fFileManager->GetHistoDirectory();
G4bool result
= to(*histoDirectory, *h2, name);
if ( ! result ) {
G4ExceptionDescription description;
description << " " << "saving histogram " << name << " failed";
G4Exception("G4RootAnalysisManager::Write()",
"Analysis_W003", JustWarning, description);
return false;
}
}
}
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 G4RootAnalysisManager::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 G4RootAnalysisManager::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
result = fFileManager->OpenFile(fileName);
finalResult = finalResult && result;
fNtupleManager->SetNtupleDirectory(fFileManager->GetNtupleDirectory());
fNtupleManager->CreateNtuplesFromBooking();
#ifdef G4VERBOSE
if ( fState.GetVerboseL1() )
fState.GetVerboseL1()->Message("open", "analysis file", name);
#endif
return finalResult;
}
//_____________________________________________________________________________
G4bool G4RootAnalysisManager::WriteImpl()
{
G4bool finalResult = true;
if ( ! fgMasterInstance &&
( ( ! fH1Manager->IsEmpty() ) || ( ! fH2Manager->IsEmpty() ) ) ) {
G4ExceptionDescription description;
description
<< " " << "No master G4RootAnalysisManager instance exists."
<< G4endl
<< " " << "Histogram data will not be merged.";
G4Exception("G4RootAnalysisManager::Write()",
"Analysis_W014", JustWarning, description);
}
// H1
G4bool result = WriteH1();
finalResult = finalResult && result;
// H2
result = WriteH2();
finalResult = finalResult && result;
// File
result = fFileManager->WriteFile();
finalResult = finalResult && result;
// Write ASCII if activated
if ( IsAscii() ) {
result = WriteAscii(fFileManager->GetFileName());
finalResult = finalResult && result;
}
return finalResult;
}
//_____________________________________________________________________________
G4bool G4RootAnalysisManager::CloseFileImpl()
{
G4bool result = true;
#ifdef G4VERBOSE
if ( fState.GetVerboseL4() )
fState.GetVerboseL4()
->Message("close", "file", fFileManager->GetFullFileName());
#endif
// reset data
result = Reset();
if ( ! result ) {
G4ExceptionDescription description;
description << " " << "Resetting data failed";
G4Exception("G4RootAnalysisManager::Write()",
"Analysis_W002", JustWarning, description);
}
// close file
fFileManager->CloseFile();
// No files clean-up in sequential mode
if ( ! fState.IsMT() ) return result;
// Delete files if empty in MT mode
if ( ( fState.GetIsMaster() &&
fH1Manager->IsEmpty() && fH2Manager->IsEmpty() ) ||
( ( ! fState.GetIsMaster() ) && fNtupleManager->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", "file", fFileManager->GetFullFileName());
#endif
}
return result;
}
@@ -0,0 +1,188 @@
//
// ********************************************************************
// * 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: G4RootFileManager.cc 70604 2013-06-03 11:27:06Z ihrivnac $
// Author: Ivana Hrivnacova, 15/06/2011 (ivana@ipno.in2p3.fr)
#include "G4RootFileManager.hh"
#include "G4AnalysisManagerState.hh"
#include "tools/wroot/file"
#include <tools/gzip_buffer>
#include <iostream>
#include <cstdio>
//_____________________________________________________________________________
G4RootFileManager::G4RootFileManager(const G4AnalysisManagerState& state)
: G4VFileManager(state),
fFile(0),
fHistoDirectory(0),
fNtupleDirectory(0)
{
}
//_____________________________________________________________________________
G4RootFileManager::~G4RootFileManager()
{
delete fFile;
}
//
// public methods
//
//_____________________________________________________________________________
G4bool G4RootFileManager::OpenFile(const G4String& fileName)
{
// Keep file name
fFileName = fileName;
G4String name = GetFullFileName();
// delete previous file if exists
if ( fFile ) delete fFile;
fFile = new tools::wroot::file(std::cout, name);
fFile->add_ziper('Z',tools::gzip_buffer);
fFile->set_compression(9);
if ( ! fFile->is_open() ) {
G4ExceptionDescription description;
description << " " << "Cannot open file " << fileName;
G4Exception("G4RootAnalysisManager::OpenFile()",
"Analysis_W001", JustWarning, description);
return false;
}
// Create directories
if ( ! CreateHistoDirectory() ) return false;
if ( ! CreateNtupleDirectory() ) return false;
fLockFileName = true;
fLockHistoDirectoryName = true;
fLockNtupleDirectoryName = true;
return true;
}
//_____________________________________________________________________________
G4bool G4RootFileManager:: WriteFile()
{
#ifdef G4VERBOSE
if ( fState.GetVerboseL4() )
fState.GetVerboseL4()->Message("write", "file", GetFullFileName());
#endif
unsigned int n;
G4bool result = fFile->write(n);
#ifdef G4VERBOSE
if ( fState.GetVerboseL1() )
fState.GetVerboseL1()->Message("write", "file", GetFullFileName(), result);
#endif
return result;
}
//_____________________________________________________________________________
G4bool G4RootFileManager::CloseFile()
{
// close file
fFile->close();
fLockFileName = false;
return true;
}
//_____________________________________________________________________________
G4bool G4RootFileManager::CreateHistoDirectory()
{
if ( fHistoDirectoryName == "" ) {
// Do not create a new directory if its name is not set
fHistoDirectory = &(fFile->dir());
return true;
}
#ifdef G4VERBOSE
if ( fState.GetVerboseL4() )
fState.GetVerboseL4()
->Message("create", "directory for histograms", fHistoDirectoryName);
#endif
fHistoDirectory = fFile->dir().mkdir(fHistoDirectoryName);
if ( ! fHistoDirectory ) {
G4ExceptionDescription description;
description << " "
<< "cannot create directory " << fHistoDirectoryName;
G4Exception("G4RootFileManager::CreateHistoDirectory()",
"Analysis_W002", JustWarning, description);
return false;
}
#ifdef G4VERBOSE
else {
if ( fState.GetVerboseL2() )
fState.GetVerboseL2()
->Message("create", "directory for histograms", fHistoDirectoryName);
}
#endif
return true;
}
//_____________________________________________________________________________
G4bool G4RootFileManager::CreateNtupleDirectory()
{
if ( fNtupleDirectoryName == "" ) {
// Do not create a new directory if its name is not set
fNtupleDirectory = &(fFile->dir());
return true;
}
#ifdef G4VERBOSE
if ( fState.GetVerboseL4() )
fState.GetVerboseL4()
->Message("create", "directory for ntuples", fNtupleDirectoryName);
#endif
fNtupleDirectory = fFile->dir().mkdir(fNtupleDirectoryName);
if ( ! fNtupleDirectory ) {
G4ExceptionDescription description;
description << " "
<< "cannot create directory " << fNtupleDirectoryName;
G4Exception("G4RootFileManager::CreateNtupleDirectory()",
"Analysis_W002", JustWarning, description);
return false;
}
#ifdef G4VERBOSE
else {
if ( fState.GetVerboseL2() )
fState.GetVerboseL2()
->Message("create", "directory for ntuples", fNtupleDirectoryName);
}
#endif
return true;
}
@@ -0,0 +1,617 @@
//
// ********************************************************************
// * 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: G4RootNtupleManager.cc 70604 2013-06-03 11:27:06Z ihrivnac $
// Author: Ivana Hrivnacova, 18/06/2013 (ivana@ipno.in2p3.fr)
#include "G4RootNtupleManager.hh"
#include "G4RootNtupleDescription.hh"
#include "G4AnalysisManagerState.hh"
#include "tools/wroot/file"
//_____________________________________________________________________________
G4RootNtupleManager::G4RootNtupleManager(const G4AnalysisManagerState& state)
: G4VNtupleManager(state),
fNtupleDirectory(0),
fNtupleVector()
{
}
//_____________________________________________________________________________
G4RootNtupleManager::~G4RootNtupleManager()
{
std::vector<G4RootNtupleDescription*>::iterator it;
for (it = fNtupleVector.begin(); it != fNtupleVector.end(); it++ ) {
delete (*it);
}
}
//
// private methods
//
//_____________________________________________________________________________
tools::wroot::ntuple::column<int>*
G4RootNtupleManager::GetNtupleIColumn(G4int ntupleId, G4int columnId) const
{
G4RootNtupleDescription* ntupleDecription
= GetNtupleInFunction(ntupleId, "GetNtupleIColumn");
if ( ! ntupleDecription ) return 0;
std::map<G4int, tools::wroot::ntuple::column<int>* >& ntupleIColumnMap
= ntupleDecription->fNtupleIColumnMap;
std::map<G4int, tools::wroot::ntuple::column<int>* >::const_iterator it
= ntupleIColumnMap.find(columnId);
if ( it == ntupleIColumnMap.end() ) {
G4ExceptionDescription description;
description << " " << "ntupleId " << ntupleId
<< "column " << columnId << " does not exist.";
G4Exception("G4RootNtupleManager::GetNtupleIColumn()",
"Analysis_W009", JustWarning, description);
return 0;
}
return it->second;
}
//_____________________________________________________________________________
tools::wroot::ntuple::column<float>*
G4RootNtupleManager::GetNtupleFColumn(G4int ntupleId, G4int columnId) const
{
G4RootNtupleDescription* ntupleDecription
= GetNtupleInFunction(ntupleId, "GetNtupleIColumn");
if ( ! ntupleDecription ) return 0;
std::map<G4int, tools::wroot::ntuple::column<float>* >& ntupleFColumnMap
= ntupleDecription->fNtupleFColumnMap;
std::map<G4int, tools::wroot::ntuple::column<float>* >::const_iterator it
= ntupleFColumnMap.find(columnId);
if ( it == ntupleFColumnMap.end() ) {
G4ExceptionDescription description;
description << " " << "ntupleId " << ntupleId
<< "column " << columnId << " does not exist.";
G4Exception("G4RootNtupleManager::GetNtupleFColumn()",
"Analysis_W009", JustWarning, description);
return 0;
}
return it->second;
}
//_____________________________________________________________________________
tools::wroot::ntuple::column<double>*
G4RootNtupleManager::GetNtupleDColumn(G4int ntupleId, G4int columnId) const
{
G4RootNtupleDescription* ntupleDecription
= GetNtupleInFunction(ntupleId, "GetNtupleIColumn");
if ( ! ntupleDecription ) return 0;
std::map<G4int, tools::wroot::ntuple::column<double>* >& ntupleDColumnMap
= ntupleDecription->fNtupleDColumnMap;
std::map<G4int, tools::wroot::ntuple::column<double>* >::const_iterator it
= ntupleDColumnMap.find(columnId);
if ( it == ntupleDColumnMap.end() ) {
G4ExceptionDescription description;
description << " " << "ntupleId " << ntupleId
<< "column " << columnId << " does not exist.";
G4Exception("G4RootNtupleManager::GetNtupleDColumn()",
"Analysis_W009", JustWarning, description);
return 0;
}
return it->second;
}
//_____________________________________________________________________________
G4RootNtupleDescription* G4RootNtupleManager::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 = "G4RootNtupleManager::";
inFunction += functionName;
G4ExceptionDescription description;
description << " " << "ntuple " << id << " does not exist.";
G4Exception(inFunction, "Analysis_W007", JustWarning, description);
}
return 0;
}
return fNtupleVector[index];
}
//
// protected methods
//
//_____________________________________________________________________________
void G4RootNtupleManager::CreateNtuplesFromBooking()
{
// Create ntuple from ntuple_booking.
if ( ! fNtupleVector.size() ) return;
std::vector<G4RootNtupleDescription*>::iterator itn;
for (itn = fNtupleVector.begin(); itn != fNtupleVector.end(); itn++ ) {
tools::ntuple_booking* ntupleBooking = (*itn)->fNtupleBooking;
if ( ! ntupleBooking ) continue;
#ifdef G4VERBOSE
if ( fState.GetVerboseL4() )
fState.GetVerboseL4()
->Message("create from booking", "ntuple", ntupleBooking->m_name);
#endif
(*itn)->fNtuple
= new tools::wroot::ntuple(*fNtupleDirectory, *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("G4RootNtupleManager::CreateNtupleFromBooking()",
"Analysis_W004", JustWarning, description);
}
}
}
#ifdef G4VERBOSE
if ( fState.GetVerboseL3() )
fState.GetVerboseL3()
->Message("create from booking", "ntuple", ntupleBooking->m_name);
#endif
}
}
//_____________________________________________________________________________
G4bool G4RootNtupleManager::IsEmpty() const
{
return ! fNtupleVector.size();
}
//_____________________________________________________________________________
G4bool G4RootNtupleManager::Reset()
{
// Reset ntuples
std::vector<G4RootNtupleDescription*>::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::wroot::ntuple* G4RootNtupleManager::GetNtuple() const
{
return GetNtuple(fFirstId);
}
//_____________________________________________________________________________
tools::wroot::ntuple* G4RootNtupleManager::GetNtuple(G4int ntupleId) const
{
G4RootNtupleDescription* ntupleDescription
= GetNtupleInFunction(ntupleId, "GetNtuple");
return ntupleDescription->fNtuple;
}
//_____________________________________________________________________________
G4int G4RootNtupleManager::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();
G4RootNtupleDescription* ntupleDescription
= new G4RootNtupleDescription();
fNtupleVector.push_back(ntupleDescription);
// Create ntuple booking
ntupleDescription->fNtupleBooking = new tools::ntuple_booking();
ntupleDescription->fNtupleBooking->m_name = name;
ntupleDescription->fNtupleBooking->m_title = title;
// ntuple booking object is deleted in destructor
// Create ntuple if the file is open
if ( fNtupleDirectory ) {
ntupleDescription->fNtuple
= new tools::wroot::ntuple(*fNtupleDirectory, name, title);
// ntuple object is deleted automatically 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 G4RootNtupleManager::CreateNtupleIColumn(const G4String& name)
{
G4int ntupleId = fNtupleVector.size() + fFirstId - 1;
return CreateNtupleIColumn(ntupleId, name);
}
//_____________________________________________________________________________
G4int G4RootNtupleManager::CreateNtupleFColumn(const G4String& name)
{
G4int ntupleId = fNtupleVector.size() + fFirstId - 1;
return CreateNtupleFColumn(ntupleId, name);
}
//_____________________________________________________________________________
G4int G4RootNtupleManager::CreateNtupleDColumn(const G4String& name)
{
G4int ntupleId = fNtupleVector.size() + fFirstId - 1;
return CreateNtupleDColumn(ntupleId, name);
}
//_____________________________________________________________________________
void G4RootNtupleManager::FinishNtuple()
{
// nothing to be done here
}
//_____________________________________________________________________________
G4int G4RootNtupleManager::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
G4RootNtupleDescription* ntupleDescription
= GetNtupleInFunction(ntupleId, "CreateNtupleIColumn");
tools::ntuple_booking* ntupleBooking
= ntupleDescription->fNtupleBooking;
if ( ! ntupleBooking ) {
G4ExceptionDescription description;
description << " "
<< "Ntuple " << ntupleId << " has to be created first. ";
G4Exception("G4RootNtupleManager::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::wroot::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 G4RootNtupleManager::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
G4RootNtupleDescription* ntupleDescription
= GetNtupleInFunction(ntupleId, "CreateNtupleFColumn");
tools::ntuple_booking* ntupleBooking
= ntupleDescription->fNtupleBooking;
if ( ! ntupleBooking ) {
G4ExceptionDescription description;
description << " "
<< "Ntuple " << ntupleId << " has to be created first. ";
G4Exception("G4RootNtupleManager::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::wroot::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 G4RootNtupleManager::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
G4RootNtupleDescription* ntupleDescription
= GetNtupleInFunction(ntupleId, "CreateNtupleDColumn");
tools::ntuple_booking* ntupleBooking
= ntupleDescription->fNtupleBooking;
if ( ! ntupleBooking ) {
G4ExceptionDescription description;
description << " "
<< "Ntuple " << ntupleId << " has to be created first. ";
G4Exception("G4RootNtupleManager::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::wroot::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 G4RootNtupleManager::FinishNtuple(G4int /*ntupleId*/)
{
// nothing to be done here
}
//_____________________________________________________________________________
G4bool G4RootNtupleManager::FillNtupleIColumn(G4int columnId, G4int value)
{
return FillNtupleIColumn(fFirstId, columnId, value);
}
//_____________________________________________________________________________
G4bool G4RootNtupleManager::FillNtupleFColumn(G4int columnId, G4float value)
{
return FillNtupleFColumn(fFirstId, columnId, value);
}
//_____________________________________________________________________________
G4bool G4RootNtupleManager::FillNtupleDColumn(G4int columnId, G4double value)
{
return FillNtupleDColumn(fFirstId, columnId, value);
}
//_____________________________________________________________________________
G4bool G4RootNtupleManager::AddNtupleRow()
{
return AddNtupleRow(fFirstId);
}
//_____________________________________________________________________________
G4bool G4RootNtupleManager::FillNtupleIColumn(G4int ntupleId, G4int columnId,
G4int value)
{
tools::wroot::ntuple::column<int>* column
= GetNtupleIColumn(ntupleId, columnId);
if ( ! column ) {
G4ExceptionDescription description;
description << " " << "ntupleId " << ntupleId
<< "column " << columnId << " does not exist.";
G4Exception("G4RootNtupleManager::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 G4RootNtupleManager::FillNtupleFColumn(G4int ntupleId, G4int columnId,
G4float value)
{
tools::wroot::ntuple::column<float>* column
= GetNtupleFColumn(ntupleId, columnId);
if ( ! column ) {
G4ExceptionDescription description;
description << " " << "ntupleId " << ntupleId
<< "column " << columnId << " does not exist.";
G4Exception("G4RootNtupleManager::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 G4RootNtupleManager::FillNtupleDColumn(G4int ntupleId, G4int columnId,
G4double value)
{
tools::wroot::ntuple::column<double>* column
= GetNtupleDColumn(ntupleId, columnId);
if ( ! column ) {
G4ExceptionDescription description;
description << " " << "ntupleId " << ntupleId
<< "column " << columnId << " does not exist.";
G4Exception("G4RootNtupleManager::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 G4RootNtupleManager::AddNtupleRow(G4int ntupleId)
{
#ifdef G4VERBOSE
if ( fState.GetVerboseL4() ) {
G4ExceptionDescription description;
description << " ntupleId " << ntupleId;
fState.GetVerboseL4()->Message("add", "ntuple row", description);
}
#endif
G4RootNtupleDescription* ntupleDescription
= GetNtupleInFunction(ntupleId, "AddNtupleRow");
if ( ! ntupleDescription || ! ntupleDescription->fNtuple ) {
G4ExceptionDescription description;
description << " " << " ntupleId " << ntupleId
<< " does not exist. ";
G4Exception("G4RootNtupleManager::AddNtupleRow()",
"Analysis_W008", JustWarning, description);
return false;
}
G4bool result = ntupleDescription->fNtuple->add_row();
if ( ! result ) {
G4ExceptionDescription description;
description << " " << " ntupleId " << ntupleId
<< "adding row has failed.";
G4Exception("G4RootNtupleManager::AddNtupleRow()",
"Analysis_W004", JustWarning, description);
}
#ifdef G4VERBOSE
if ( fState.GetVerboseL4() ) {
G4ExceptionDescription description;
description << " ntupleId " << ntupleId;
fState.GetVerboseL4()->Message("add", "ntuple row", description, result);
}
#endif
return result;
}