// // ******************************************************************** // * 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. * // ******************************************************************** // // The common implementation of analysis manager classes. // Author: Ivana Hrivnacova, IJCLab IN2P3/CNRS, 07/09/2015 #ifndef G4AccumulableManager_h #define G4AccumulableManager_h 1 #include "G4AccValue.hh" #include "G4AccType.hh" #include "globals.hh" #include #include class G4AccumulableManager; class G4VAccumulable; template class G4ThreadLocalSingleton; template class G4AccArray; template class G4AccMap; template class G4AccUnorderedMap; template class G4AccVector; class G4AccumulableManager { friend class G4ThreadLocalSingleton; public: virtual ~G4AccumulableManager(); // Static methods static G4AccumulableManager* Instance(); // Methods // Create accumulables // template G4AccValue* CreateAccValue(const G4String& name, T value, G4MergeMode mergeMode = G4MergeMode::kAddition); template G4AccValue* CreateAccValue(T value, G4MergeMode mergeMode = G4MergeMode::kAddition); // Deprecated function using the old accumulable value name // template [[deprecated("Use `G4AccumulableManager::CreateAccValue` instead")]] G4AccValue* CreateAccumulable(const G4String& name, T value, G4MergeMode mergeMode = G4MergeMode::kAddition); template [[deprecated("Use `G4AccumulableManager::CreateAccValue` instead")]] G4AccValue* CreateAccumulable(T value, G4MergeMode mergeMode = G4MergeMode::kAddition); // Register existing accumulables // template G4bool Register(G4AccValue& accumulable); template G4bool Register(G4AccArray& accumulableArray); template G4bool Register(G4AccMap& accumulableMap); template G4bool Register(G4AccUnorderedMap& accumulableUnorderedMap); template G4bool Register(G4AccVector& accumulableVector); // user defined accumulable G4bool Register(G4VAccumulable* accumulable); // Deprecated functions with long name // template [[deprecated("Use `G4AccumulableManager::Register` instead")]] G4bool RegisterAccumulable(G4AccValue& accumulable); // user defined accumulable [[deprecated("Use `G4AccumulableManager::Register` instead")]] G4bool RegisterAccumulable(G4VAccumulable* accumulable); // Access registered accumulables // // Via name // templated accumulable // template G4AccValue* GetAccValue(const G4String& name, G4bool warn = true) const; template G4AccArray* GetAccArray(const G4String& name, G4bool warn = true) const; template , class Allocator = std::allocator>> G4AccMap* GetAccMap(const G4String& name, G4bool warn = true) const; template , class KeyEqual = std::equal_to, class Allocator = std::allocator>> G4AccUnorderedMap* GetAccUnorderedMap(const G4String& name, G4bool warn = true) const; template > G4AccVector* GetAccVector(const G4String& name, G4bool warn = true) const; // user defined accumulable G4VAccumulable* GetAccumulable(const G4String& name, G4bool warn = true) const; // Deprecated function using the old accumulable value name template [[deprecated("Use `G4AccumulableManager::GetAccValue` instead")]] G4AccValue* GetAccumulable(const G4String& name, G4bool warn = true) const; // Via id (in the order of registering) // templated accumulable // template G4AccValue* GetAccValue(G4int id, G4bool warn = true) const; template G4AccArray* GetAccArray(G4int id, G4bool warn = true) const; template , class Allocator = std::allocator>> G4AccMap* GetAccMap(G4int id, G4bool warn = true) const; template , class KeyEqual = std::equal_to, class Allocator = std::allocator>> G4AccUnorderedMap* GetAccUnorderedMap(G4int id, G4bool warn = true) const; template > G4AccVector* GetAccVector(G4int id, G4bool warn = true) const; // user defined accumulable G4VAccumulable* GetAccumulable(G4int id, G4bool warn = true) const; // Deprecated function using the old accumulable value name template [[deprecated("Use `G4AccumulableManager::GetAccValue` instead")]] G4AccValue* GetAccumulable(G4int id, G4bool warn = true) const; G4int GetNofAccumulables() const; // Via vector iterators std::vector::iterator Begin(); std::vector::iterator End(); std::vector::const_iterator BeginConst() const; std::vector::const_iterator EndConst() const; // Methods applied to all accumulables void Merge(); void Reset(); void Print(G4PrintOptions options = G4PrintOptions()) const; // Print a selected range void Print(G4int startId, G4int count, G4PrintOptions options = G4PrintOptions()) const; void Print(std::vector::iterator startIt, std::size_t count, G4PrintOptions options = G4PrintOptions()) const; void Print(std::vector::iterator startIt, std::vector::iterator endIt, G4PrintOptions options = G4PrintOptions()) const; // Verbose level void SetVerboseLevel(G4int value); G4int GetVerboseLevel() const; private: // Hide singleton ctor G4AccumulableManager(); // Methods // 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; G4bool CheckType(G4VAccumulable* accumulable, G4AccType type, G4bool warn) const; template G4AccValue* GetAccumulable(G4VAccumulable* accumulable, G4bool warn) const; template G4AccArray* GetAccArray(G4VAccumulable* accumulable, G4bool warn) const; template , typename Allocator = std::allocator>> G4AccMap* GetAccMap(G4VAccumulable* accumulable, G4bool warn = true) const; template , typename KeyEqual = std::equal_to, typename Allocator = std::allocator>> G4AccUnorderedMap* GetAccUnorderedMap(G4VAccumulable* accumulable, G4bool warn = true) const; template > G4AccVector* GetAccVector(G4VAccumulable* accumulable, G4bool warn) const; // Constants const G4String kBaseName = "accumulable"; // Static data members inline static G4AccumulableManager* fgMasterInstance { nullptr }; // Data members std::vector fVector; std::map fMap; std::vector fAccumulablesToDelete; }; #include "G4AccumulableManager.icc" #endif