Import Geant4 10.3.0 source tree
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
#------------------------------------------------------------------------------
|
||||
# CMakeLists.txt
|
||||
# Module : G4analysis
|
||||
# Package: Geant4.src.G4analysis.G4analysismng
|
||||
#
|
||||
# CMakeLists.txt for building a single granular library.
|
||||
#
|
||||
# Created on : 15/07/2013
|
||||
#
|
||||
# $Id: CMakeLists.txt 99561 2016-09-27 07:04:12Z gcosmo $
|
||||
#
|
||||
#------------------------------------------------------------------------------
|
||||
|
||||
if(GEANT4_BUILD_GRANULAR_LIBS)
|
||||
include(Geant4MacroLibraryTargets)
|
||||
GEANT4_GRANULAR_LIBRARY_TARGET(COMPONENT sources.cmake)
|
||||
endif()
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
# $Id: GNUmakefile 66356 2012-12-18 09:02:32Z gcosmo $
|
||||
# --------------------------------------------------------------------
|
||||
# GNUmakefile for analysis/management sub-library.
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
name := G4accumulables
|
||||
|
||||
ifndef G4INSTALL
|
||||
G4INSTALL = ../../..
|
||||
endif
|
||||
|
||||
include $(G4INSTALL)/config/architecture.gmk
|
||||
|
||||
CPPFLAGS += -I$(G4BASE)/global/management/include \
|
||||
-I$(G4BASE)/intercoms/include
|
||||
|
||||
include $(G4INSTALL)/config/common.gmk
|
||||
@@ -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$
|
||||
|
||||
// Class template for accumulables handled by Geant4 analysis
|
||||
//
|
||||
// Author: Ivana Hrivnacova, 07/09/2015 (ivana@ipno.in2p3.fr)
|
||||
|
||||
#ifndef G4Accumulable_h
|
||||
#define G4Accumulable_h 1
|
||||
|
||||
#include "G4VAccumulable.hh"
|
||||
#include "G4MergeMode.hh"
|
||||
|
||||
#include "globals.hh"
|
||||
|
||||
template <typename T>
|
||||
class G4Accumulable : public G4VAccumulable
|
||||
{
|
||||
public:
|
||||
G4Accumulable(const G4String& name, T initValue,
|
||||
G4MergeMode mergeMode = G4MergeMode::kAddition);
|
||||
G4Accumulable(T initValue,
|
||||
G4MergeMode mergeMode = G4MergeMode::kAddition);
|
||||
G4Accumulable(const G4Accumulable& rhs);
|
||||
G4Accumulable() = delete;
|
||||
virtual ~G4Accumulable();
|
||||
|
||||
// operators
|
||||
G4Accumulable<T>& operator= (const G4Accumulable<T>& rhs);
|
||||
G4Accumulable<T>& operator+=(const G4Accumulable<T>& rhs);
|
||||
G4Accumulable<T>& operator*=(const G4Accumulable<T>& rhs);
|
||||
G4Accumulable<T> operator++(int); // postfix increment
|
||||
G4Accumulable<T>& operator++(); // prefix increment
|
||||
|
||||
G4Accumulable<T>& operator= (const T& rhs);
|
||||
G4Accumulable<T>& operator+=(const T& rhs);
|
||||
G4Accumulable<T>& operator*=(const T& rhs);
|
||||
|
||||
// methods
|
||||
virtual void Merge(const G4VAccumulable& other) final;
|
||||
virtual void Reset() final;
|
||||
|
||||
// get methods
|
||||
T GetValue() const;
|
||||
G4MergeMode GetMergeMode() const;
|
||||
|
||||
private:
|
||||
// data members
|
||||
T fValue;
|
||||
T fInitValue;
|
||||
G4MergeMode fMergeMode;
|
||||
G4MergeFunction<T> fMergeFunction;
|
||||
};
|
||||
|
||||
// inline functions
|
||||
|
||||
#include "G4Accumulable.icc"
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,186 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * 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$
|
||||
|
||||
//
|
||||
// utilities
|
||||
//
|
||||
|
||||
//
|
||||
// public functions
|
||||
//
|
||||
|
||||
using namespace G4Accumulables;
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename T>
|
||||
G4Accumulable<T>::G4Accumulable(const G4String& name, T initValue, G4MergeMode mergeMode)
|
||||
: G4VAccumulable(name),
|
||||
fValue(initValue),
|
||||
fInitValue(initValue),
|
||||
fMergeMode(mergeMode),
|
||||
fMergeFunction(GetMergeFunction<T>(mergeMode))
|
||||
{}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename T>
|
||||
G4Accumulable<T>::G4Accumulable(T initValue, G4MergeMode mergeMode)
|
||||
: G4VAccumulable(),
|
||||
fValue(initValue),
|
||||
fInitValue(initValue),
|
||||
fMergeMode(mergeMode),
|
||||
fMergeFunction(GetMergeFunction<T>(mergeMode))
|
||||
{}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename T>
|
||||
G4Accumulable<T>::G4Accumulable(const G4Accumulable& rhs)
|
||||
: G4VAccumulable(rhs),
|
||||
fValue(rhs.fValue),
|
||||
fInitValue(rhs.fInitValue),
|
||||
fMergeMode(rhs.fMergeMode),
|
||||
fMergeFunction(rhs.fMergeFunction)
|
||||
{}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename T>
|
||||
G4Accumulable<T>::~G4Accumulable()
|
||||
{}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename T>
|
||||
G4Accumulable<T>&
|
||||
G4Accumulable<T>::operator=(const G4Accumulable<T>& rhs)
|
||||
{
|
||||
// check assignment to self
|
||||
if (this == &rhs) return *this;
|
||||
|
||||
// base class assignment
|
||||
G4VAccumulable::operator=(rhs);
|
||||
|
||||
// this class data assignment
|
||||
fValue = rhs.fValue;
|
||||
fInitValue = rhs.fInitValue;
|
||||
fMergeMode = rhs.fMergeMode;
|
||||
fMergeFunction = rhs.fMergeFunction;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename T>
|
||||
G4Accumulable<T>&
|
||||
G4Accumulable<T>::operator+=(const G4Accumulable<T>& rhs)
|
||||
{
|
||||
// only update the value from rhs
|
||||
fValue += rhs.fValue;
|
||||
return *this;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename T>
|
||||
G4Accumulable<T>&
|
||||
G4Accumulable<T>::operator*=(const G4Accumulable<T>& rhs)
|
||||
{
|
||||
// only update the value from rhs
|
||||
fValue *= rhs.fValue;
|
||||
return *this;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename T>
|
||||
G4Accumulable<T>&
|
||||
G4Accumulable<T>::operator=(const T& value)
|
||||
{
|
||||
// only update the value
|
||||
fValue = value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename T>
|
||||
G4Accumulable<T>&
|
||||
G4Accumulable<T>::operator+=(const T& value)
|
||||
{
|
||||
// only update the value
|
||||
fValue += value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename T>
|
||||
G4Accumulable<T>&
|
||||
G4Accumulable<T>::operator*=(const T& value)
|
||||
{
|
||||
// only update the value from rhs
|
||||
fValue *= value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename T>
|
||||
G4Accumulable<T>
|
||||
G4Accumulable<T>::operator++(int)
|
||||
{
|
||||
// postfix increment
|
||||
G4Accumulable<T> temp = *this;
|
||||
fValue++;
|
||||
return temp;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename T>
|
||||
G4Accumulable<T>&
|
||||
G4Accumulable<T>::operator++()
|
||||
{
|
||||
// prefix increment
|
||||
fValue++;
|
||||
return *this;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename T>
|
||||
void G4Accumulable<T>::Merge(const G4VAccumulable& other)
|
||||
{
|
||||
// G4cout << "Merging other: " << other.GetName() << " " << static_cast<const G4Accumulable<T>&>(other).fValue << G4endl;
|
||||
// G4cout << " to master: " << fName << " " << fValue << G4endl;
|
||||
fValue = fMergeFunction(fValue, static_cast<const G4Accumulable<T>&>(other).fValue);
|
||||
// G4cout << " new value: " << fName << " " << fValue << G4endl;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename T>
|
||||
void G4Accumulable<T>::Reset()
|
||||
{
|
||||
fValue = fInitValue;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename T>
|
||||
T G4Accumulable<T>::GetValue() const
|
||||
{
|
||||
return fValue;
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * License and Disclaimer *
|
||||
// * *
|
||||
// * The Geant4 software is copyright of the Copyright Holders of *
|
||||
// * the Geant4 Collaboration. It is provided under the terms and *
|
||||
// * conditions of the Geant4 Software License, included in the file *
|
||||
// * LICENSE and available at http://cern.ch/geant4/license . These *
|
||||
// * include a list of copyright holders. *
|
||||
// * *
|
||||
// * Neither the authors of this software system, nor their employing *
|
||||
// * institutes,nor the agencies providing financial support for this *
|
||||
// * work make any representation or warranty, express or implied, *
|
||||
// * regarding this software system or assume any liability for its *
|
||||
// * use. Please see the license in the file LICENSE and URL above *
|
||||
// * for the full disclaimer and the limitation of liability. *
|
||||
// * *
|
||||
// * This code implementation is the result of the scientific and *
|
||||
// * technical work of the GEANT4 collaboration. *
|
||||
// * By using, copying, modifying or distributing the software (or *
|
||||
// * any work based on the software) you agree to acknowledge its *
|
||||
// * use in resulting scientific publications, and indicate your *
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// $Id: G4AccumulableManager.hh 91012 2015-06-15 10:38:07Z ihrivnac $
|
||||
|
||||
// The common implementation of analysis manager classes.
|
||||
|
||||
// Author: Ivana Hrivnacova, 07/09/2015 (ivana@ipno.in2p3.fr)
|
||||
|
||||
#ifndef G4AccumulableManager_h
|
||||
#define G4AccumulableManager_h 1
|
||||
|
||||
#include "G4Accumulable.hh"
|
||||
#include "globals.hh"
|
||||
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
class G4AnalysisManagerState;
|
||||
class G4VAccumulable;
|
||||
|
||||
class G4AccumulableManager
|
||||
{
|
||||
public:
|
||||
virtual ~G4AccumulableManager();
|
||||
|
||||
// static methods
|
||||
static G4AccumulableManager* Instance();
|
||||
|
||||
// Methods
|
||||
|
||||
// Create accumulables
|
||||
//
|
||||
template <typename T>
|
||||
G4Accumulable<T>*
|
||||
CreateAccumulable(const G4String& name, T value,
|
||||
G4MergeMode mergeMode = G4MergeMode::kAddition);
|
||||
|
||||
template <typename T>
|
||||
G4Accumulable<T>*
|
||||
CreateAccumulable(T value,
|
||||
G4MergeMode mergeMode = G4MergeMode::kAddition);
|
||||
|
||||
// Register existing accumulables
|
||||
//
|
||||
// templated accumulable
|
||||
template <typename T>
|
||||
G4bool RegisterAccumulable(G4Accumulable<T>& accumulable);
|
||||
// user defined accumulable
|
||||
G4bool RegisterAccumulable(G4VAccumulable* accumulable);
|
||||
|
||||
// Access registered accumulables
|
||||
//
|
||||
// Via name
|
||||
// templated accumulable
|
||||
template <typename T>
|
||||
G4Accumulable<T>* GetAccumulable(const G4String& name, G4bool warn = true) const;
|
||||
// user defined accumulable
|
||||
G4VAccumulable* GetAccumulable(const G4String& name, G4bool warn = true) const;
|
||||
|
||||
// Via id (in the order of registering)
|
||||
// templated accumulable
|
||||
template <typename T>
|
||||
G4Accumulable<T>* GetAccumulable(G4int id, G4bool warn = true) const;
|
||||
// user defined accumulable
|
||||
G4VAccumulable* GetAccumulable(G4int id, G4bool warn = true) const;
|
||||
G4int GetNofAccumulables() const;
|
||||
|
||||
// Via vector iterators
|
||||
std::vector<G4VAccumulable*>::iterator Begin();
|
||||
std::vector<G4VAccumulable*>::iterator End();
|
||||
std::vector<G4VAccumulable*>::const_iterator BeginConst() const;
|
||||
std::vector<G4VAccumulable*>::const_iterator EndConst() const;
|
||||
|
||||
// Methods applied to all accumulables
|
||||
void Merge();
|
||||
void Reset();
|
||||
|
||||
private:
|
||||
// hide ctor requiring master/worker specification
|
||||
G4AccumulableManager(G4bool isMaster);
|
||||
|
||||
// metods
|
||||
// Generate generic accumulable name: accumulableN, where N is the actual number of accumulables
|
||||
G4String GenerateName() const;
|
||||
// Check if a name is already used in a map and print a warning
|
||||
G4bool CheckName(const G4String& name, const G4String& where) const;
|
||||
|
||||
template <typename T>
|
||||
G4Accumulable<T>* GetAccumulable(G4VAccumulable* accumulable, G4bool warn) const;
|
||||
|
||||
// constants
|
||||
const G4String kBaseName = "accumulable";
|
||||
|
||||
// static data members
|
||||
static G4AccumulableManager* fgMasterInstance;
|
||||
static G4ThreadLocal G4AccumulableManager* fgInstance;
|
||||
|
||||
// data members
|
||||
std::vector<G4VAccumulable*> fVector;
|
||||
std::map<G4String, G4VAccumulable*> fMap;
|
||||
std::vector<G4VAccumulable*> fAccumulablesToDelete;
|
||||
};
|
||||
|
||||
#include "G4AccumulableManager.icc"
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,135 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * 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: G4AccumulableManager.hh 70604 2013-06-03 11:27:06Z ihrivnac $
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename T>
|
||||
G4Accumulable<T>*
|
||||
G4AccumulableManager::GetAccumulable(G4VAccumulable* accumulable, G4bool warn) const
|
||||
{
|
||||
// Do not check type if nullptr
|
||||
if ( ! accumulable ) return nullptr;
|
||||
|
||||
// check type
|
||||
G4Accumulable<T>* taccumulable = dynamic_cast<G4Accumulable<T>*>(accumulable);
|
||||
if ( ! taccumulable && warn ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " " << "Accumulable " << accumulable->GetName()
|
||||
<< " has different type";
|
||||
G4Exception("G4AccumulableManager::GetAccumulable<T>",
|
||||
"Analysis_W011", JustWarning, description);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return taccumulable;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename T>
|
||||
G4Accumulable<T>*
|
||||
G4AccumulableManager::CreateAccumulable(
|
||||
const G4String& name, T value, G4MergeMode mergeMode)
|
||||
{
|
||||
// do not accept name if it is already used
|
||||
if ( ! CheckName(name, "CreateAccumulable") ) return 0;
|
||||
|
||||
// create accumulable
|
||||
auto accumulable = new G4Accumulable<T>(name, value, mergeMode);
|
||||
|
||||
// register accumulable in the map and vector
|
||||
RegisterAccumulable(accumulable);
|
||||
fAccumulablesToDelete.push_back(accumulable);
|
||||
|
||||
return accumulable;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename T>
|
||||
G4Accumulable<T>*
|
||||
G4AccumulableManager::CreateAccumulable(
|
||||
T value, G4MergeMode mergeMode)
|
||||
{
|
||||
return CreateAccumulable(G4String(), value, mergeMode);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename T>
|
||||
G4bool G4AccumulableManager::RegisterAccumulable(G4Accumulable<T>& accumulable)
|
||||
{
|
||||
return RegisterAccumulable(&accumulable);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename T>
|
||||
G4Accumulable<T>*
|
||||
G4AccumulableManager::GetAccumulable(const G4String& name, G4bool warn) const
|
||||
{
|
||||
// get G4VParammeter from the map
|
||||
auto accumulable = GetAccumulable(name, warn);
|
||||
return GetAccumulable<T>(accumulable, warn);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename T>
|
||||
G4Accumulable<T>*
|
||||
G4AccumulableManager::GetAccumulable(G4int id, G4bool warn) const
|
||||
{
|
||||
// get G4VParammeter from the map
|
||||
auto accumulable = GetAccumulable(id, warn);
|
||||
return GetAccumulable<T>(accumulable, warn);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
inline G4int G4AccumulableManager::GetNofAccumulables() const
|
||||
{
|
||||
return fVector.size();
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
inline std::vector<G4VAccumulable*>::iterator G4AccumulableManager::Begin()
|
||||
{
|
||||
return fVector.begin();
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
inline std::vector<G4VAccumulable*>::iterator G4AccumulableManager::End()
|
||||
{
|
||||
return fVector.end();
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
inline std::vector<G4VAccumulable*>::const_iterator
|
||||
G4AccumulableManager::BeginConst() const
|
||||
{
|
||||
return fVector.begin();
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
inline std::vector<G4VAccumulable*>::const_iterator
|
||||
G4AccumulableManager::EndConst() const
|
||||
{
|
||||
return fVector.end();
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * License and Disclaimer *
|
||||
// * *
|
||||
// * The Geant4 software is copyright of the Copyright Holders of *
|
||||
// * the Geant4 Collaboration. It is provided under the terms and *
|
||||
// * conditions of the Geant4 Software License, included in the file *
|
||||
// * LICENSE and available at http://cern.ch/geant4/license . These *
|
||||
// * include a list of copyright holders. *
|
||||
// * *
|
||||
// * Neither the authors of this software system, nor their employing *
|
||||
// * institutes,nor the agencies providing financial support for this *
|
||||
// * work make any representation or warranty, express or implied, *
|
||||
// * regarding this software system or assume any liability for its *
|
||||
// * use. Please see the license in the file LICENSE and URL above *
|
||||
// * for the full disclaimer and the limitation of liability. *
|
||||
// * *
|
||||
// * This code implementation is the result of the scientific and *
|
||||
// * technical work of the GEANT4 collaboration. *
|
||||
// * By using, copying, modifying or distributing the software (or *
|
||||
// * any work based on the software) you agree to acknowledge its *
|
||||
// * use in resulting scientific publications, and indicate your *
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// $Id$
|
||||
|
||||
// Author: Ivana Hrivnacova, 04/07/2012 (ivana@ipno.in2p3.fr)
|
||||
|
||||
#ifndef G4MergeMode_h
|
||||
#define G4MergeMode_h 1
|
||||
|
||||
#include "globals.hh"
|
||||
|
||||
#include <functional>
|
||||
#include <cmath>
|
||||
|
||||
// Enumeration for definition available binning schemes
|
||||
|
||||
enum class G4MergeMode {
|
||||
kAddition, // "Or" if boolean type
|
||||
kMultiplication, // "And" if boolean type
|
||||
kMaximum, // "Or" if boolean type
|
||||
kMinimum // "And" if boolean type
|
||||
};
|
||||
|
||||
// Generic merge function
|
||||
template <typename T>
|
||||
using G4MergeFunction = std::function<T(const T&, const T&)>;
|
||||
|
||||
// Utility functions
|
||||
namespace G4Accumulables {
|
||||
|
||||
G4MergeMode GetMergeMode(const G4String& mergeModeName);
|
||||
|
||||
template <typename T>
|
||||
G4MergeFunction<T> GetMergeFunction(G4MergeMode mergeMode)
|
||||
{
|
||||
switch ( mergeMode ) {
|
||||
case G4MergeMode::kAddition:
|
||||
// return std::bind([](const T& x, const T& y) { return x + y; });
|
||||
return [](const T& x, const T& y) { return x + y; };
|
||||
|
||||
case G4MergeMode::kMultiplication:
|
||||
return [](const T& x, const T& y) { return x * y; };
|
||||
|
||||
case G4MergeMode::kMaximum:
|
||||
// return std::bind([](const T& x, const T& y) { return std::max(x,y);});
|
||||
return [](const T& x, const T& y) { return std::max(x,y); };
|
||||
|
||||
case G4MergeMode::kMinimum:
|
||||
// return std::bind([](const T& x, const T& y) { return std::min(x,y);});
|
||||
return [](const T& x, const T& y) { return std::min(x,y); };
|
||||
}
|
||||
}
|
||||
|
||||
template <G4bool>
|
||||
G4MergeFunction<G4bool> GetMergeFunction(G4MergeMode mergeMode)
|
||||
{
|
||||
switch ( mergeMode ) {
|
||||
case G4MergeMode::kAddition:
|
||||
case G4MergeMode::kMaximum:
|
||||
// return std::bind([](const T& x, const T& y) { return x + y; });
|
||||
return [](const G4bool& x, const G4bool& y) { return x || y; };
|
||||
|
||||
case G4MergeMode::kMultiplication:
|
||||
case G4MergeMode::kMinimum:
|
||||
return [](const G4bool& x, const G4bool& y) { return x && y; };
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,65 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * License and Disclaimer *
|
||||
// * *
|
||||
// * The Geant4 software is copyright of the Copyright Holders of *
|
||||
// * the Geant4 Collaboration. It is provided under the terms and *
|
||||
// * conditions of the Geant4 Software License, included in the file *
|
||||
// * LICENSE and available at http://cern.ch/geant4/license . These *
|
||||
// * include a list of copyright holders. *
|
||||
// * *
|
||||
// * Neither the authors of this software system, nor their employing *
|
||||
// * institutes,nor the agencies providing financial support for this *
|
||||
// * work make any representation or warranty, express or implied, *
|
||||
// * regarding this software system or assume any liability for its *
|
||||
// * use. Please see the license in the file LICENSE and URL above *
|
||||
// * for the full disclaimer and the limitation of liability. *
|
||||
// * *
|
||||
// * This code implementation is the result of the scientific and *
|
||||
// * technical work of the GEANT4 collaboration. *
|
||||
// * By using, copying, modifying or distributing the software (or *
|
||||
// * any work based on the software) you agree to acknowledge its *
|
||||
// * use in resulting scientific publications, and indicate your *
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// $Id: G4CsvNtupleManager.hh 70604 2013-06-03 11:27:06Z ihrivnac $
|
||||
|
||||
// Value type independent base class for accumulables handled by Geant4 analysis
|
||||
//
|
||||
// Author: Ivana Hrivnacova, 04/09/2015 (ivana@ipno.in2p3.fr)
|
||||
|
||||
#ifndef G4VAccumulable_h
|
||||
#define G4VAccumulable_h 1
|
||||
|
||||
#include "globals.hh"
|
||||
|
||||
|
||||
class G4VAccumulable
|
||||
{
|
||||
// To allow G4AccumulableManager set name if not defined by user
|
||||
friend class G4AccumulableManager;
|
||||
|
||||
public:
|
||||
G4VAccumulable(const G4String& name = "");
|
||||
G4VAccumulable(const G4VAccumulable& rhs);
|
||||
virtual ~G4VAccumulable() {}
|
||||
|
||||
// operators
|
||||
G4VAccumulable& operator=(const G4VAccumulable& rhs);
|
||||
|
||||
// methods
|
||||
virtual void Merge(const G4VAccumulable& other) = 0;
|
||||
virtual void Reset() = 0;
|
||||
|
||||
// get methods
|
||||
G4String GetName() const;
|
||||
|
||||
protected:
|
||||
G4String fName;
|
||||
};
|
||||
|
||||
#include "G4VAccumulable.icc"
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * 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: G4AccumulableManager.hh 70604 2013-06-03 11:27:06Z ihrivnac $
|
||||
|
||||
//_____________________________________________________________________________
|
||||
inline G4VAccumulable::G4VAccumulable(const G4String& name)
|
||||
: fName(name)
|
||||
{}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
inline G4VAccumulable::G4VAccumulable(const G4VAccumulable& rhs)
|
||||
: fName(rhs.fName)
|
||||
{}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
inline G4VAccumulable& G4VAccumulable::operator=(const G4VAccumulable& rhs)
|
||||
{
|
||||
fName = rhs.fName;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
inline G4String G4VAccumulable::GetName() const
|
||||
{
|
||||
return fName;
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
#------------------------------------------------------------------------------
|
||||
# sources.cmake
|
||||
# Module : G4hntools
|
||||
# Package: Geant4.src.G4analysis.G4hntools
|
||||
#
|
||||
# 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 91489 2015-07-20 12:53:29Z ihrivnac $
|
||||
#
|
||||
#------------------------------------------------------------------------------
|
||||
|
||||
# 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)
|
||||
|
||||
#
|
||||
# Define the Geant4 Module.
|
||||
#
|
||||
|
||||
include(Geant4MacroDefineModule)
|
||||
GEANT4_DEFINE_MODULE(NAME G4accumulables
|
||||
HEADERS
|
||||
G4MergeMode.hh
|
||||
G4AccumulableManager.hh
|
||||
G4AccumulableManager.icc
|
||||
G4Accumulable.hh
|
||||
G4Accumulable.icc
|
||||
G4VAccumulable.hh
|
||||
G4VAccumulable.icc
|
||||
SOURCES
|
||||
G4MergeMode.cc
|
||||
G4AccumulableManager.cc
|
||||
GRANULAR_DEPENDENCIES
|
||||
G4globman
|
||||
G4intercoms
|
||||
# G4analysismng
|
||||
GLOBAL_DEPENDENCIES
|
||||
G4global
|
||||
G4intercoms
|
||||
LINK_LIBRARIES
|
||||
)
|
||||
|
||||
# List any source specific properties here
|
||||
@@ -0,0 +1,216 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * 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: G4AccumulableManager.cc 91116 2015-06-20 12:33:45Z ihrivnac $
|
||||
|
||||
// Author: Ivana Hrivnacova, 18/06/2013 (ivana@ipno.in2p3.fr)
|
||||
|
||||
#include "G4AccumulableManager.hh"
|
||||
#include "G4Threading.hh"
|
||||
#include "G4AutoLock.hh"
|
||||
|
||||
// mutex in a file scope
|
||||
|
||||
namespace {
|
||||
//Mutex to lock master manager when merging accumulables
|
||||
G4Mutex mergeMutex = G4MUTEX_INITIALIZER;
|
||||
}
|
||||
|
||||
G4AccumulableManager* G4AccumulableManager::fgMasterInstance = nullptr;
|
||||
G4ThreadLocal G4AccumulableManager* G4AccumulableManager::fgInstance = nullptr;
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4AccumulableManager* G4AccumulableManager::Instance()
|
||||
{
|
||||
if ( fgInstance == nullptr ) {
|
||||
G4bool isMaster = ! G4Threading::IsWorkerThread();
|
||||
fgInstance = new G4AccumulableManager(isMaster);
|
||||
}
|
||||
|
||||
return fgInstance;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4AccumulableManager::G4AccumulableManager(G4bool isMaster)
|
||||
: fVector(),
|
||||
fMap()
|
||||
{
|
||||
if ( ( isMaster && fgMasterInstance ) || ( fgInstance ) ) {
|
||||
G4ExceptionDescription description;
|
||||
description
|
||||
<< " "
|
||||
<< "G4AccumulableAnalysisManager already exists."
|
||||
<< "Cannot create another instance.";
|
||||
G4Exception("G4AccumulableAnalysisManager::G4AccumulableAnalysisManager()",
|
||||
"Analysis_F001", FatalException, description);
|
||||
}
|
||||
if ( isMaster ) fgMasterInstance = this;
|
||||
fgInstance = this;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4AccumulableManager::~G4AccumulableManager()
|
||||
{
|
||||
// delete only accumulables create by the mager itself
|
||||
for ( auto it : fAccumulablesToDelete ) {
|
||||
delete it;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// private methods
|
||||
//
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4String G4AccumulableManager::GenerateName() const
|
||||
{
|
||||
G4String name = kBaseName;
|
||||
std::ostringstream os;
|
||||
os << fVector.size();
|
||||
name.append("_");
|
||||
name.append(os.str());
|
||||
return name;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4AccumulableManager::CheckName(const G4String& name, const G4String& where) const
|
||||
{
|
||||
if ( fMap.find(name) == fMap.end() ) return true;
|
||||
|
||||
G4ExceptionDescription description;
|
||||
description << " " << "Name " << name << " is already used." << G4endl;
|
||||
description << " " << "Paremeter will be not created/registered.";
|
||||
G4String method("G4AccumulableManager::");
|
||||
method.append(where);
|
||||
G4Exception(method, "Analysis_W002", JustWarning, description);
|
||||
return false;
|
||||
}
|
||||
|
||||
//
|
||||
// public methods
|
||||
//
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4AccumulableManager::RegisterAccumulable(G4VAccumulable* accumulable)
|
||||
{
|
||||
auto name = accumulable->GetName();
|
||||
|
||||
// do not accept name if it is already used
|
||||
if ( ! CheckName(name, "RegisterAccumulable") ) return false;
|
||||
|
||||
// generate name if empty
|
||||
if ( ! name.length() ) {
|
||||
name = GenerateName();
|
||||
accumulable->fName = name;
|
||||
}
|
||||
|
||||
fMap[name] = accumulable;
|
||||
fVector.push_back(accumulable);
|
||||
return true;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4VAccumulable*
|
||||
G4AccumulableManager::GetAccumulable(const G4String& name, G4bool warn) const
|
||||
{
|
||||
// get G4VParammeter from the map
|
||||
auto it = fMap.find(name);
|
||||
if ( it == fMap.end() ) {
|
||||
if ( warn) {
|
||||
G4ExceptionDescription description;
|
||||
description << " " << "accumulable " << name << " does not exist.";
|
||||
G4Exception("G4AccumulableManager::GetAccumulable",
|
||||
"Analysis_W011", JustWarning, description);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return it->second;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4VAccumulable*
|
||||
G4AccumulableManager::GetAccumulable(G4int id, G4bool warn) const
|
||||
{
|
||||
// get G4VParammeter from the vector
|
||||
if ( id < 0 || id >= G4int(fVector.size()) ) {
|
||||
if ( warn) {
|
||||
G4ExceptionDescription description;
|
||||
description << " " << "accumulable " << id << " does not exist.";
|
||||
G4Exception("G4AccumulableManager::GetAccumulable",
|
||||
"Analysis_W011", JustWarning, description);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return fVector[id];
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void G4AccumulableManager::Merge()
|
||||
{
|
||||
// Do nothing if there are no accumulables registered
|
||||
// or if master thread
|
||||
if ( (! fVector.size()) || (! G4Threading::IsWorkerThread()) ) return;
|
||||
|
||||
// The manager on mastter must exist
|
||||
if ( ! fgMasterInstance ) {
|
||||
G4ExceptionDescription description;
|
||||
description
|
||||
<< " " << "No master G4AccumulableManager instance exists."
|
||||
<< G4endl
|
||||
<< " " << "Accumulables will not be merged.";
|
||||
G4Exception("G4AccumulableManager::Merge()",
|
||||
"Analysis_W031", JustWarning, description);
|
||||
return;
|
||||
}
|
||||
|
||||
// The worker manager just merges its accumulables to the master
|
||||
// This operation needs a lock
|
||||
// G4cout << "Go to merge accumulables" << G4endl;
|
||||
G4AutoLock lock(&mergeMutex);
|
||||
|
||||
// the other manager has the vector with the "same" accumulables
|
||||
auto it = fVector.begin();
|
||||
for ( auto itMaster : fgMasterInstance->fVector ) {
|
||||
// G4VAccumulable* masterAccumulable = itMaster;
|
||||
// G4VAccumulable* accumulable = *(it++);
|
||||
// masterAccumulable->Merge(*(accumulable));
|
||||
itMaster->Merge(*(*(it++)));
|
||||
}
|
||||
lock.unlock();
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void G4AccumulableManager::Reset()
|
||||
{
|
||||
// Reset histograms and profiles
|
||||
|
||||
for ( auto it : fVector ) {
|
||||
it->Reset();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * License and Disclaimer *
|
||||
// * *
|
||||
// * The Geant4 software is copyright of the Copyright Holders of *
|
||||
// * the Geant4 Collaboration. It is provided under the terms and *
|
||||
// * conditions of the Geant4 Software License, included in the file *
|
||||
// * LICENSE and available at http://cern.ch/geant4/license . These *
|
||||
// * include a list of copyright holders. *
|
||||
// * *
|
||||
// * Neither the authors of this software system, nor their employing *
|
||||
// * institutes,nor the agencies providing financial support for this *
|
||||
// * work make any representation or warranty, express or implied, *
|
||||
// * regarding this software system or assume any liability for its *
|
||||
// * use. Please see the license in the file LICENSE and URL above *
|
||||
// * for the full disclaimer and the limitation of liability. *
|
||||
// * *
|
||||
// * This code implementation is the result of the scientific and *
|
||||
// * technical work of the GEANT4 collaboration. *
|
||||
// * By using, copying, modifying or distributing the software (or *
|
||||
// * any work based on the software) you agree to acknowledge its *
|
||||
// * use in resulting scientific publications, and indicate your *
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// $Id:$
|
||||
|
||||
// Author: Ivana Hrivnacova, 22/08/2013 (ivana@ipno.in2p3.fr)
|
||||
|
||||
#include "G4MergeMode.hh"
|
||||
|
||||
namespace G4Accumulables
|
||||
{
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4MergeMode GetMergeMode(const G4String& mergeModeName) {
|
||||
if ( mergeModeName == "+" ) { return G4MergeMode::kAddition; }
|
||||
else if ( mergeModeName == "*" ) { return G4MergeMode::kMultiplication; }
|
||||
else {
|
||||
G4ExceptionDescription description;
|
||||
description
|
||||
<< " \"" << mergeModeName << "\" merge mode is not supported." << G4endl
|
||||
<< " " << "Addition will be applied.";
|
||||
G4Exception("G4Analysis::GetMergeMode",
|
||||
"Analysis_W013", JustWarning, description);
|
||||
return G4MergeMode::kAddition;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user