Geant4  10.01.p02
G4MoleculeTable.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  * G4MoleculeTable.cc
28  *
29  * Created on: 23 oct. 2013
30  * Author: kara
31  */
32 
33 #include "G4MoleculeTable.hh"
34 
36 
38 {
39  // TODO Auto-generated constructor stub
40 
41 }
42 
44 {
45  // TODO Auto-generated destructor stub
46 }
47 
49 {
51  return fpgMoleculeTable;
52 }
53 
55 {
56  return Instance();
57 }
58 
60  double diffusion_coefficient)
61 {
62  MoleculeDefTable::iterator it = fMoleculeDefTable.find(name);
63  G4MoleculeDefinition* definition(0);
64  if (it == fMoleculeDefTable.end())
65  {
66  definition = new G4MoleculeDefinition(name, -1 /* mass*/,
67  diffusion_coefficient);
68  fMoleculeDefTable[name] = definition;
69  }
70  else
71  {
72  // exception
73  G4ExceptionDescription description;
74  description << "The molecule definition " << name
75  << " was already recorded in the table" << G4endl;
76  G4Exception("G4MoleculeTable::CreateMoleculeDefinition",
77  "DEFINITION_ALREADY_CREATED", FatalException, description);
78  }
79  return definition;
80 }
81 
83  G4MoleculeDefinition* molDef,
84  int charge,
85  double diffusion_coefficient)
86 {
87 
88  G4Molecule* molecule = new G4Molecule(molDef, charge);
89  if (diffusion_coefficient != -1) molecule->SetDiffusionCoefficient(
90  diffusion_coefficient);
91 
92  RecordMoleculeModel(name, molecule);
93 
94  return molecule;
95 }
96 
98  G4MoleculeDefinition* molDef)
99 {
100 
101  G4Molecule* molecule = new G4Molecule(molDef);
102  RecordMoleculeModel(name, molecule);
103 
104  return molecule;
105 }
106 
108 {
109  MoleculeDefTable::iterator it = fMoleculeDefTable.find(name);
110  G4MoleculeDefinition* definition(0);
111  if (it != fMoleculeDefTable.end())
112  {
113  definition = it->second;
114  }
115  else if(mustExist)
116  {
117  // exception
118  G4ExceptionDescription description;
119  description << "The molecule defintion " << name
120  << " was NOT recorded in the table" << G4endl;
121  G4Exception("G4MoleculeTable::CreateMoleculeModel", "MOLECULE_DEFINITION_NOT_CREATED",
122  FatalException, description);
123  }
124  return definition;
125 }
126 
128  G4Molecule* molecule)
129 {
130  MoleculeTable::iterator it = fMoleculeTable.find(name);
131 
132  G4int id = molecule->GetMoleculeID();
133  MoleculeTablePerID::iterator it_perID = fMoleculeTablePerID.find(id);
134 
135  if (it == fMoleculeTable.end() && it_perID == fMoleculeTablePerID.end())
136  {
137  fMoleculeTable[name] = molecule;
138  fMoleculeTablePerID[id] = molecule;
139  }
140  else if(it != fMoleculeTable.end())
141  {
142  // exception
143  G4ExceptionDescription description;
144  description << "The molecule model " << name
145  << " was already recorded in the table" << G4endl;
146  G4Exception("G4MoleculeTable::CreateMoleculeModel", "MODEL_ALREADY_CREATED",
147  FatalException, description);
148  }
149  else if(it != fMoleculeTable.end())
150  {
151  // exception
152  G4ExceptionDescription description;
153  description << "The molecule model " << name
154  << " was already recorded per ID (" << id<<") in the table"
155  << G4endl;
156  G4Exception("G4MoleculeTable::CreateMoleculeModel", "MODEL_ALREADY_CREATED",
157  FatalException, description);
158  }
159 }
160 
162 {
163  MoleculeTable::iterator it = fMoleculeTable.find(name);
164  G4Molecule* molecule(0);
165  if (it != fMoleculeTable.end())
166  {
167  molecule = it->second;
168  }
169  else if(mustExist)
170  {
171  // exception
172  G4ExceptionDescription description;
173  description << "The molecule model " << name
174  << " was already recorded in the table" << G4endl;
175  G4Exception("G4MoleculeTable::CreateMoleculeModel", "MODEL_ALREADY_CREATED",
176  FatalException, description);
177  }
178  return molecule;
179 }
180 
182 {
183  MoleculeTablePerID::iterator it = fMoleculeTablePerID.find(id);
184  G4Molecule* molecule(0);
185  if (it != fMoleculeTablePerID.end())
186  {
187  molecule = it->second;
188  }
189  else
190  {
191  // exception
192  return 0;
193  }
194  return molecule;
195 }
196 
198 {
199 
200  const G4String& name = moleculeDefinition->GetName();
201  MoleculeDefTable::iterator it = fMoleculeDefTable.find(name);
202  if (it == fMoleculeDefTable.end())
203  {
204  fMoleculeDefTable[name] = moleculeDefinition;
205  }
206  else
207  {
208  // exception
209  G4ExceptionDescription description;
210  description << "The molecule definition " << name
211  << " was already recorded in the table" << G4endl;
212  G4Exception("G4MoleculeTable::CreateMoleculeDefinition",
213  "DEFINITION_ALREADY_CREATED", FatalException, description);
214  }
215 }
void Insert(G4MoleculeDefinition *)
G4MoleculeDefinition * CreateMoleculeDefinition(const G4String &, double diffusion_coefficient)
void SetDiffusionCoefficient(G4double)
Sets the diffusion coefficient D of the molecule used in diffusion processes to calculate the mean sq...
Definition: G4Molecule.cc:460
G4MoleculeDefinition * GetMoleculeDefinition(const G4String &, bool mustExist=true)
std::ostringstream G4ExceptionDescription
Definition: globals.hh:76
G4String name
Definition: TRTMaterials.hh:40
MoleculeTable fMoleculeTable
int G4int
Definition: G4Types.hh:78
void RecordMoleculeModel(const G4String &name, G4Molecule *)
static G4MoleculeTable * Instance()
static G4MoleculeTable * fpgMoleculeTable
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
G4Molecule * GetMoleculeModel(const G4String &, bool mustExist=true)
MoleculeTablePerID fMoleculeTablePerID
static G4MoleculeTable * GetMoleculeTable()
const G4String & GetName() const
MoleculeDefTable fMoleculeDefTable
#define G4endl
Definition: G4ios.hh:61
Class Description The dynamic molecule holds all the data that change for a molecule It has a pointer...
Definition: G4Molecule.hh:93
G4Molecule * CreateMoleculeModel(const G4String &, G4MoleculeDefinition *, int charge, double diffusion_coefficient=-1)
virtual ~G4MoleculeTable()
G4int GetMoleculeID() const
Definition: G4Molecule.cc:410