Geant4 Cross Reference |
1 // 2 // ******************************************************************** 3 // * License and Disclaimer * 4 // * * 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. * 10 // * * 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. * 17 // * * 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 // ******************************************************************** 25 // 26 // G4ScoringManager 27 // 28 // Class description: 29 // 30 // This is a singleton class which manages the interactive scoring. 31 // The user cannot access to the constructor. The pointer of the 32 // only existing object can be got via G4ScoringManager::GetScoringManager() 33 // static method. The first invocation of this static method makes 34 // the singleton object. 35 // 36 // Author: Makoto Asai 37 // -------------------------------------------------------------------- 38 #ifndef G4ScoringManager_h 39 #define G4ScoringManager_h 1 40 41 #include "globals.hh" 42 #include "G4VScoringMesh.hh" 43 #include "G4VScoreWriter.hh" 44 45 #include <vector> 46 #include <map> 47 48 class G4ScoringMessenger; 49 class G4ScoreQuantityMessenger; 50 class G4VHitsCollection; 51 class G4VScoreColorMap; 52 53 using MeshVec = std::vector<G4VScoringMesh *>; 54 using MeshVecItr = MeshVec::iterator; 55 using MeshVecConstItr = MeshVec::const_iterator; 56 using ColorMapDict = std::map<G4String, G4VScoreColorMap *>; 57 using ColorMapDictItr = ColorMapDict::iterator; 58 using ColorMapDictConstItr = ColorMapDict::const_iterator; 59 using MeshMap = std::map<G4int, G4VScoringMesh *>; 60 using MeshMapItr = MeshMap::iterator; 61 using MeshMapConstItr = MeshMap::const_iterator; 62 63 class G4ScoringManager 64 { 65 public: 66 67 static G4ScoringManager* GetScoringManager(); 68 // Returns the pointer to the singleton object. 69 70 static G4ScoringManager* GetScoringManagerIfExist(); 71 72 G4ScoringManager(const G4ScoringManager&) = delete; 73 G4ScoringManager& operator=(const G4ScoringManager&) = delete; 74 75 ~G4ScoringManager(); 76 77 static void SetReplicaLevel(G4int); 78 static G4int GetReplicaLevel(); 79 80 void RegisterScoreColorMap(G4VScoreColorMap* colorMap); 81 // Register a color map. Once registered, it is available by /score/draw and 82 // /score/drawColumn commands. 83 84 void Accumulate(G4VHitsCollection* map); 85 void Merge(const G4ScoringManager* scMan); 86 G4VScoringMesh* FindMesh(G4VHitsCollection* map); 87 G4VScoringMesh* FindMesh(const G4String&); 88 void List() const; 89 void Dump() const; 90 void DrawMesh(const G4String& meshName, const G4String& psName, 91 const G4String& colorMapName, G4int axflg = 111); 92 void DrawMesh(const G4String& meshName, const G4String& psName, 93 G4int idxPlane, G4int iColumn, const G4String& colorMapName); 94 void DumpQuantityToFile(const G4String& meshName, const G4String& psName, 95 const G4String& fileName, 96 const G4String& option = ""); 97 void DumpAllQuantitiesToFile(const G4String& meshName, 98 const G4String& fileName, 99 const G4String& option = ""); 100 G4VScoreColorMap* GetScoreColorMap(const G4String& mapName); 101 void ListScoreColorMaps(); 102 103 inline void SetCurrentMesh(G4VScoringMesh* scm) { fCurrentMesh = scm; } 104 inline G4VScoringMesh* GetCurrentMesh() const { return fCurrentMesh; } 105 inline void CloseCurrentMesh() { fCurrentMesh = nullptr; } 106 inline void SetVerboseLevel(G4int vl) 107 { 108 verboseLevel = vl; 109 for(auto& itr : fMeshVec) 110 { 111 itr->SetVerboseLevel(vl); 112 } 113 if(writer != nullptr) 114 writer->SetVerboseLevel(vl); 115 } 116 inline G4int GetVerboseLevel() const { return verboseLevel; } 117 inline std::size_t GetNumberOfMesh() const { return fMeshVec.size(); } 118 inline void RegisterScoringMesh(G4VScoringMesh* scm) 119 { 120 scm->SetVerboseLevel(verboseLevel); 121 fMeshVec.push_back(scm); 122 SetCurrentMesh(scm); 123 } 124 inline G4VScoringMesh* GetMesh(G4int i) const { return fMeshVec[i]; } 125 inline const G4String& GetWorldName(G4int i) const 126 { 127 return fMeshVec[i]->GetWorldName(); 128 } 129 130 inline void SetScoreWriter(G4VScoreWriter* sw) 131 { 132 delete writer; 133 writer = sw; 134 if(writer != nullptr) 135 writer->SetVerboseLevel(verboseLevel); 136 } 137 // Replace score writers. 138 139 inline void SetFactor(G4double val = 1.0) 140 { 141 if(writer != nullptr) 142 writer->SetFactor(val); 143 } 144 inline G4double GetFactor() const 145 { 146 if(writer != nullptr) 147 { 148 return writer->GetFactor(); 149 } 150 151 return -1.0; 152 } 153 154 protected: 155 156 G4ScoringManager(); 157 158 private: 159 160 static G4ThreadLocal G4ScoringManager* fSManager; 161 static G4ThreadLocal G4int replicaLevel; 162 163 G4int verboseLevel; 164 G4ScoringMessenger* fMessenger; 165 G4ScoreQuantityMessenger* fQuantityMessenger; 166 167 MeshVec fMeshVec; 168 G4VScoringMesh* fCurrentMesh; 169 170 G4VScoreWriter* writer; 171 G4VScoreColorMap* fDefaultLinearColorMap; 172 ColorMapDict* fColorMapDict; 173 174 MeshMap fMeshMap; 175 }; 176 177 #endif 178