// // ******************************************************************** // * 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. * // ******************************************************************** // // Author: Ivana Hrivnacova, 23/06/2015 (ivana@ipno.in2p3.fr) #include "G4AnalysisManagerState.hh" #include "G4HnManager.hh" #include "G4AnalysisUtilities.hh" #include "G4AutoLock.hh" using std::to_string; //_____________________________________________________________________________ template G4THnManager::G4THnManager(const G4AnalysisManagerState& state, const G4String& hnType) : fState(state) { fHnManager = std::make_shared(hnType, state); } //_____________________________________________________________________________ template G4THnManager::~G4THnManager() { for ( auto t : fTVector ) { delete t; } } // // protected methods // //_____________________________________________________________________________ template HT* G4THnManager::GetTInFunction(G4int id, std::string_view functionName, G4bool warn, G4bool onlyIfActive) const { G4int index = id - fHnManager->GetFirstId(); if ( index < 0 || index >= G4int(fTVector.size()) ) { if ( warn) { G4Analysis::Warn("Histogram " + to_string(id) + " does not exist.", fkClass, functionName); } return nullptr; } // Do not return histogram if inactive if ( fState.GetIsActivation() && onlyIfActive && ( ! fHnManager->GetActivation(id) ) ) { return nullptr; } return fTVector[index]; } //_____________________________________________________________________________ template G4int G4THnManager::GetTId(const G4String& name, G4bool warn) const { auto it = fNameIdMap.find(name); if ( it == fNameIdMap.end() ) { if ( warn) { G4Analysis::Warn("histogram " + name + " does not exist.", fkClass, "GetTId"); } return G4Analysis::kInvalidId; } return it->second; } //_____________________________________________________________________________ template G4bool G4THnManager::IsVerbose(G4int verboseLevel) const { return fState.IsVerbose(verboseLevel); } //_____________________________________________________________________________ template void G4THnManager::Message( G4int level, const G4String& action, const G4String& objectType, const G4String& objectName, G4bool success) const { fState.Message(level, action, objectType, objectName, success); } //_____________________________________________________________________________ template void G4THnManager::AddTVector(const std::vector& tVector) { Message(G4Analysis::kVL4, "merge", "all " + fHnManager->GetHnType()); // std::vector::const_iterator itw = h1Vector.begin(); // std::vector::iterator it; // for (it = fH1Vector.begin(); it != fH1Vector.end(); it++ ) { // (*it)->add(*(*itw++)); // } auto itw = tVector.begin(); for ( auto t : fTVector ) { t->add(*(*itw++)); } Message(G4Analysis::kVL1, "merge", "all " + fHnManager->GetHnType()); } //_____________________________________________________________________________ template void G4THnManager::Merge( G4Mutex& mergeMutex, G4THnManager* masterInstance) { G4AutoLock lH1(&mergeMutex); masterInstance->AddTVector(fTVector); lH1.unlock(); } //_____________________________________________________________________________ template typename std::vector::iterator G4THnManager::BeginT() { return fTVector.begin(); } //_____________________________________________________________________________ template typename std::vector::iterator G4THnManager::EndT() { return fTVector.end(); } //_____________________________________________________________________________ template typename std::vector::const_iterator G4THnManager::BeginConstT() const { return fTVector.begin(); } //_____________________________________________________________________________ template typename std::vector::const_iterator G4THnManager::EndConstT() const { return fTVector.end(); } // // public methods // //_____________________________________________________________________________ template G4int G4THnManager::RegisterT(HT* t, const G4String& name) { G4int index = fTVector.size(); fTVector.push_back(t); fHnManager->SetLockFirstId(true); fNameIdMap[name] = index + fHnManager->GetFirstId(); return index + fHnManager->GetFirstId(); } //_____________________________________________________________________________ template G4bool G4THnManager::Reset() { // Reset histograms auto result = true; for ( auto t : fTVector ) { result &= t->reset(); } return result; } //_____________________________________________________________________________ template void G4THnManager::ClearData() { for ( auto t : fTVector ) { delete t; } fTVector.clear(); fNameIdMap.clear(); if ( fHnManager != nullptr ) { fHnManager->ClearData(); } Message(G4Analysis::kVL2, "clear", G4Analysis::GetHnType()); } //_____________________________________________________________________________ template G4bool G4THnManager::IsEmpty() const { return ! fTVector.size(); } //_____________________________________________________________________________ template HT* G4THnManager::GetT(G4int id) const { return GetTInFunction(id, "GetT"); }