2// ********************************************************************
3// * License and Disclaimer *
5// * The Geant4 software is copyright of the Copyright Holders of *
6// * the Geant4 Collaboration. It is provided under the terms and *
7// * conditions of the Geant4 Software License, included in the file *
8// * LICENSE and available at http://cern.ch/geant4/license . These *
9// * include a list of copyright holders. *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work make any representation or warranty, express or implied, *
14// * regarding this software system or assume any liability for its *
15// * use. Please see the license in the file LICENSE and URL above *
16// * for the full disclaimer and the limitation of liability. *
18// * This code implementation is the result of the scientific and *
19// * technical work of the GEANT4 collaboration. *
20// * By using, copying, modifying or distributing the software (or *
21// * any work based on the software) you agree to acknowledge its *
22// * use in resulting scientific publications, and indicate your *
23// * acceptance of all terms of the Geant4 Software license. *
24// ********************************************************************
27// Author: Ivana Hrivnacova, 23/06/2015 (ivana@ipno.in2p3.fr)
29#include "G4AnalysisManagerState.hh"
30#include "G4HnManager.hh"
31#include "G4AnalysisUtilities.hh"
32#include "G4AutoLock.hh"
36//_____________________________________________________________________________
38G4THnManager<HT>::G4THnManager(const G4AnalysisManagerState& state,
39 const G4String& hnType)
42 fHnManager = std::make_shared<G4HnManager>(hnType, state);
45//_____________________________________________________________________________
47G4THnManager<HT>::~G4THnManager()
49 for ( auto t : fTVector ) {
58//_____________________________________________________________________________
60HT* G4THnManager<HT>::GetTInFunction(G4int id,
61 std::string_view functionName, G4bool warn,
62 G4bool onlyIfActive) const
64 G4int index = id - fHnManager->GetFirstId();
65 if ( index < 0 || index >= G4int(fTVector.size()) ) {
67 G4Analysis::Warn("Histogram " + to_string(id) + " does not exist.",
68 fkClass, functionName);
73 // Do not return histogram if inactive
74 if ( fState.GetIsActivation() && onlyIfActive && ( ! fHnManager->GetActivation(id) ) ) {
78 return fTVector[index];
81//_____________________________________________________________________________
83G4int G4THnManager<HT>::GetTId(const G4String& name, G4bool warn) const
85 auto it = fNameIdMap.find(name);
86 if ( it == fNameIdMap.end() ) {
88 G4Analysis::Warn("histogram " + name + " does not exist.",
91 return G4Analysis::kInvalidId;
96//_____________________________________________________________________________
98G4bool G4THnManager<HT>::IsVerbose(G4int verboseLevel) const
100 return fState.IsVerbose(verboseLevel);
103//_____________________________________________________________________________
104template <typename HT>
105void G4THnManager<HT>::Message(
106 G4int level, const G4String& action, const G4String& objectType,
107 const G4String& objectName, G4bool success) const
109 fState.Message(level, action, objectType, objectName, success);
112//_____________________________________________________________________________
113template <typename HT>
114void G4THnManager<HT>::AddTVector(const std::vector<HT*>& tVector)
116 Message(G4Analysis::kVL4, "merge", "all " + fHnManager->GetHnType());
118 // std::vector<tools::histo::h1d*>::const_iterator itw = h1Vector.begin();
119 // std::vector<tools::histo::h1d*>::iterator it;
120 // for (it = fH1Vector.begin(); it != fH1Vector.end(); it++ ) {
121 // (*it)->add(*(*itw++));
123 auto itw = tVector.begin();
124 for ( auto t : fTVector ) {
128 Message(G4Analysis::kVL1, "merge", "all " + fHnManager->GetHnType());
131//_____________________________________________________________________________
132template <typename HT>
133void G4THnManager<HT>::Merge(
134 G4Mutex& mergeMutex, G4THnManager<HT>* masterInstance)
136 G4AutoLock lH1(&mergeMutex);
137 masterInstance->AddTVector(fTVector);
141//_____________________________________________________________________________
142template <typename HT>
143typename std::vector<HT*>::iterator G4THnManager<HT>::BeginT()
145 return fTVector.begin();
148//_____________________________________________________________________________
149template <typename HT>
150typename std::vector<HT*>::iterator G4THnManager<HT>::EndT()
152 return fTVector.end();
155//_____________________________________________________________________________
156template <typename HT>
157typename std::vector<HT*>::const_iterator G4THnManager<HT>::BeginConstT() const
159 return fTVector.begin();
162//_____________________________________________________________________________
163template <typename HT>
164typename std::vector<HT*>::const_iterator G4THnManager<HT>::EndConstT() const
166 return fTVector.end();
173//_____________________________________________________________________________
174template <typename HT>
175G4int G4THnManager<HT>::RegisterT(HT* t, const G4String& name)
177 G4int index = fTVector.size();
178 fTVector.push_back(t);
180 fHnManager->SetLockFirstId(true);
181 fNameIdMap[name] = index + fHnManager->GetFirstId();
182 return index + fHnManager->GetFirstId();
185//_____________________________________________________________________________
186template <typename HT>
187G4bool G4THnManager<HT>::Reset()
193 for ( auto t : fTVector ) {
194 result &= t->reset();
200//_____________________________________________________________________________
201template <typename HT>
203G4THnManager<HT>::ClearData()
205 for ( auto t : fTVector ) {
212 if ( fHnManager != nullptr ) {
213 fHnManager->ClearData();
216 Message(G4Analysis::kVL2, "clear", G4Analysis::GetHnType<HT>());
219//_____________________________________________________________________________
220template <typename HT>
221G4bool G4THnManager<HT>::IsEmpty() const
223 return ! fTVector.size();
226//_____________________________________________________________________________
227template <typename HT>
228HT* G4THnManager<HT>::GetT(G4int id) const
230 return GetTInFunction(id, "GetT");