Geant4_10
G4ScoringManager.cc
Go to the documentation of this file.
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 //
27 // $Id: G4ScoringManager.cc 78004 2013-12-02 08:28:23Z gcosmo $
28 //
29 
30 #include "G4ScoringManager.hh"
31 #include "G4ScoringMessenger.hh"
33 #include "G4VScoringMesh.hh"
34 #include "G4THitsMap.hh"
35 #include "G4VScoreColorMap.hh"
37 #include "G4ScoreLogColorMap.hh"
38 
39 G4ThreadLocal G4ScoringManager* G4ScoringManager::fSManager = 0;
40 
41 G4ThreadLocal G4int G4ScoringManager::replicaLevel = 3;
42 
44 {
45  if(!fSManager)
46  {
47  fSManager = new G4ScoringManager;
48  }
49  return fSManager;
50 }
51 
53 { return fSManager; }
54 
56  : verboseLevel(0),fCurrentMesh(0)
57 {
58  fMessenger = new G4ScoringMessenger(this);
59  fQuantityMessenger = new G4ScoreQuantityMessenger(this);
60  fColorMapDict = new ColorMapDict();
61  fDefaultLinearColorMap = new G4DefaultLinearColorMap("defaultLinearColorMap");
62  (*fColorMapDict)[fDefaultLinearColorMap->GetName()] = fDefaultLinearColorMap;
63  G4VScoreColorMap * logColorMap = new G4ScoreLogColorMap("logColorMap");
64  (*fColorMapDict)[logColorMap->GetName()] = logColorMap;
65  writer = new G4VScoreWriter();
66 }
67 
69 {
70  if (writer) { delete writer; }
71  delete fDefaultLinearColorMap;
72  delete fColorMapDict;
73  delete fQuantityMessenger;
74  delete fMessenger;
75  fSManager = 0;
76 }
77 
79 { replicaLevel = lvl; }
81 { return replicaLevel; }
82 
84 {
85  G4String wName = map->GetSDname();
86  G4VScoringMesh* sm = FindMesh(wName);
87  if(sm == 0) return;
88  if(verboseLevel>9)
89  { G4cout << "G4ScoringManager::Accumulate() for " << map->GetSDname() << " / " << map->GetName() << G4endl;
90  G4cout << " is calling G4VScoringMesh::Accumulate() of " << sm->GetWorldName() << G4endl; }
91  sm->Accumulate(static_cast<G4THitsMap<double>*>(map));
92 }
93 
95 {
96  G4VScoringMesh* sm = 0;
97  for(MeshVecItr itr = fMeshVec.begin(); itr != fMeshVec.end(); itr++) {
98  G4String smName = (*itr)->GetWorldName();
99  if(wName == smName) {
100  sm = *itr;
101  break;
102  }
103  }
104  if(!sm && verboseLevel>9)
105  { G4cout << "WARNING : G4ScoringManager::FindMesh() --- <" << wName << "> is not found. Null returned." << G4endl; }
106 
107  return sm;
108 }
109 
111 {
112  G4cout << "G4ScoringManager has " << GetNumberOfMesh() << " scoring meshes." << G4endl;
113  for(MeshVecConstItr itr = fMeshVec.begin(); itr != fMeshVec.end(); itr++) {
114  (*itr)->List();
115  }
116 }
117 
119 {
120  for(MeshVecConstItr itr = fMeshVec.begin(); itr != fMeshVec.end(); itr++) {
121  (*itr)->Dump();
122  }
123 }
124 
126  const G4String& psName,
127  const G4String& colorMapName, G4int axflg)
128 {
129  G4VScoringMesh* mesh = FindMesh(meshName);
130  if(mesh)
131  {
132  G4VScoreColorMap* colorMap = GetScoreColorMap(colorMapName);
133  if(!colorMap)
134  {
135  G4cerr << "WARNING : Score color map <" << colorMapName << "> is not found. Default linear color map is used." << G4endl;
136  colorMap = fDefaultLinearColorMap;
137  }
138  mesh->DrawMesh(psName,colorMap,axflg);
139  } else {
140  G4cerr << "ERROR : G4ScoringManager::DrawMesh() --- <"
141  << meshName << "> is not found. Nothing is done." << G4endl;
142  }
143 }
144 
146  const G4String& psName,
147  G4int idxPlane, G4int iColumn,
148  const G4String& colorMapName)
149 {
150  G4VScoringMesh* mesh = FindMesh(meshName);
151  if(mesh)
152  {
153  G4VScoreColorMap* colorMap = GetScoreColorMap(colorMapName);
154  if(!colorMap)
155  {
156  G4cerr << "WARNING : Score color map <" << colorMapName << "> is not found. Default linear color map is used." << G4endl;
157  colorMap = fDefaultLinearColorMap;
158  }
159  mesh->DrawMesh(psName,idxPlane,iColumn,colorMap);
160  } else {
161  G4cerr << "ERROR : G4ScoringManager::DrawMesh() --- <"
162  << meshName << "> is not found. Nothing is done." << G4endl;
163  }
164 }
165 
167  const G4String& psName,
168  const G4String& fileName,
169  const G4String& option)
170 {
171  G4VScoringMesh* mesh = FindMesh(meshName);
172  if(mesh) {
173  writer->SetScoringMesh(mesh);
174  writer->DumpQuantityToFile(psName, fileName, option);
175  } else {
176  G4cerr << "ERROR : G4ScoringManager::DrawQuantityToFile() --- <"
177  << meshName << "> is not found. Nothing is done." << G4endl;
178  }
179 }
180 
182  const G4String& fileName,
183  const G4String& option)
184 {
185  G4VScoringMesh* mesh = FindMesh(meshName);
186  if(mesh) {
187  writer->SetScoringMesh(mesh);
188  writer->DumpAllQuantitiesToFile(fileName, option);
189  } else {
190  G4cerr << "ERROR : G4ScoringManager::DrawAllQuantitiesToFile() --- <"
191  << meshName << "> is not found. Nothing is done." << G4endl;
192  }
193 }
194 
196 {
197  if(fColorMapDict->find(colorMap->GetName()) != fColorMapDict->end())
198  {
199  G4cerr << "ERROR : G4ScoringManager::RegisterScoreColorMap -- "
200  << colorMap->GetName() << " has already been registered. Method ignored." << G4endl;
201  }
202  else
203  {
204  (*fColorMapDict)[colorMap->GetName()] = colorMap;
205  }
206 }
207 
209 {
210  ColorMapDictItr mItr = fColorMapDict->find(mapName);
211  if(mItr == fColorMapDict->end()) { return 0; }
212  return (mItr->second);
213 }
214 
216 {
217  G4cout << "Registered Score Color Maps -------------------------------------------------------" << G4endl;
218  ColorMapDictItr mItr = fColorMapDict->begin();
219  for(;mItr!=fColorMapDict->end();mItr++)
220  { G4cout << " " << mItr->first; }
221  G4cout << G4endl;
222 }
223 
225 {
226  for(size_t i = 0; i< GetNumberOfMesh() ; i++)
227  {
228  G4VScoringMesh* fMesh = GetMesh(i);
229  G4VScoringMesh* scMesh = mgr->GetMesh(i);
230  fMesh->Merge(scMesh);
231  }
232 }
233 
234 
static void SetReplicaLevel(G4int)
const G4String & GetWorldName() const
void DrawMesh(const G4String &psName, G4VScoreColorMap *colorMap, G4int axflg=111)
void RegisterScoreColorMap(G4VScoreColorMap *colorMap)
void Merge(const G4VScoringMesh *scMesh)
void Dump() const
std::vector< G4VScoringMesh * >::const_iterator MeshVecConstItr
void Accumulate(G4THitsMap< G4double > *map)
void List() const
#define G4ThreadLocal
Definition: tls.hh:52
int G4int
Definition: G4Types.hh:78
void DumpAllQuantitiesToFile(const G4String &meshName, const G4String &fileName, const G4String &option="")
G4String GetName() const
virtual void DumpAllQuantitiesToFile(const G4String &fileName, const G4String &option)
std::vector< G4VScoringMesh * >::iterator MeshVecItr
G4GLOB_DLL std::ostream G4cout
static G4ScoringManager * GetScoringManagerIfExist()
static G4int GetReplicaLevel()
std::map< G4String, G4VScoreColorMap * > ColorMapDict
void Accumulate(G4VHitsCollection *map)
G4VScoreColorMap * GetScoreColorMap(const G4String &mapName)
G4VScoringMesh * FindMesh(const G4String &)
void Merge(const G4ScoringManager *scMan)
void DrawMesh(const G4String &meshName, const G4String &psName, const G4String &colorMapName, G4int axflg=111)
void SetScoringMesh(G4VScoringMesh *sm)
void DumpQuantityToFile(const G4String &meshName, const G4String &psName, const G4String &fileName, const G4String &option="")
#define G4endl
Definition: G4ios.hh:61
static G4ScoringManager * GetScoringManager()
size_t GetNumberOfMesh() const
std::map< G4String, G4VScoreColorMap * >::iterator ColorMapDictItr
G4VScoringMesh * GetMesh(G4int i) const
G4GLOB_DLL std::ostream G4cerr
virtual void DumpQuantityToFile(const G4String &psName, const G4String &fileName, const G4String &option)