Geant4 Cross Reference

Cross-Referencing   Geant4
Geant4/processes/electromagnetic/dna/utils/src/G4DNAMolecularMaterial.cc

Version: [ ReleaseNotes ] [ 1.0 ] [ 1.1 ] [ 2.0 ] [ 3.0 ] [ 3.1 ] [ 3.2 ] [ 4.0 ] [ 4.0.p1 ] [ 4.0.p2 ] [ 4.1 ] [ 4.1.p1 ] [ 5.0 ] [ 5.0.p1 ] [ 5.1 ] [ 5.1.p1 ] [ 5.2 ] [ 5.2.p1 ] [ 5.2.p2 ] [ 6.0 ] [ 6.0.p1 ] [ 6.1 ] [ 6.2 ] [ 6.2.p1 ] [ 6.2.p2 ] [ 7.0 ] [ 7.0.p1 ] [ 7.1 ] [ 7.1.p1 ] [ 8.0 ] [ 8.0.p1 ] [ 8.1 ] [ 8.1.p1 ] [ 8.1.p2 ] [ 8.2 ] [ 8.2.p1 ] [ 8.3 ] [ 8.3.p1 ] [ 8.3.p2 ] [ 9.0 ] [ 9.0.p1 ] [ 9.0.p2 ] [ 9.1 ] [ 9.1.p1 ] [ 9.1.p2 ] [ 9.1.p3 ] [ 9.2 ] [ 9.2.p1 ] [ 9.2.p2 ] [ 9.2.p3 ] [ 9.2.p4 ] [ 9.3 ] [ 9.3.p1 ] [ 9.3.p2 ] [ 9.4 ] [ 9.4.p1 ] [ 9.4.p2 ] [ 9.4.p3 ] [ 9.4.p4 ] [ 9.5 ] [ 9.5.p1 ] [ 9.5.p2 ] [ 9.6 ] [ 9.6.p1 ] [ 9.6.p2 ] [ 9.6.p3 ] [ 9.6.p4 ] [ 10.0 ] [ 10.0.p1 ] [ 10.0.p2 ] [ 10.0.p3 ] [ 10.0.p4 ] [ 10.1 ] [ 10.1.p1 ] [ 10.1.p2 ] [ 10.1.p3 ] [ 10.2 ] [ 10.2.p1 ] [ 10.2.p2 ] [ 10.2.p3 ] [ 10.3 ] [ 10.3.p1 ] [ 10.3.p2 ] [ 10.3.p3 ] [ 10.4 ] [ 10.4.p1 ] [ 10.4.p2 ] [ 10.4.p3 ] [ 10.5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /processes/electromagnetic/dna/utils/src/G4DNAMolecularMaterial.cc (Version 11.3.0) and /processes/electromagnetic/dna/utils/src/G4DNAMolecularMaterial.cc (Version 10.1.p1)


  1 //                                                  1 //
  2 // *******************************************      2 // ********************************************************************
  3 // * License and Disclaimer                         3 // * License and Disclaimer                                           *
  4 // *                                                4 // *                                                                  *
  5 // * The  Geant4 software  is  copyright of th      5 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
  6 // * the Geant4 Collaboration.  It is provided      6 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
  7 // * conditions of the Geant4 Software License      7 // * conditions of the Geant4 Software License,  included in the file *
  8 // * LICENSE and available at  http://cern.ch/      8 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
  9 // * include a list of copyright holders.           9 // * include a list of copyright holders.                             *
 10 // *                                               10 // *                                                                  *
 11 // * Neither the authors of this software syst     11 // * Neither the authors of this software system, nor their employing *
 12 // * institutes,nor the agencies providing fin     12 // * institutes,nor the agencies providing financial support for this *
 13 // * work  make  any representation or  warran     13 // * work  make  any representation or  warranty, express or implied, *
 14 // * regarding  this  software system or assum     14 // * regarding  this  software system or assume any liability for its *
 15 // * use.  Please see the license in the file      15 // * use.  Please see the license in the file  LICENSE  and URL above *
 16 // * for the full disclaimer and the limitatio     16 // * for the full disclaimer and the limitation of liability.         *
 17 // *                                               17 // *                                                                  *
 18 // * This  code  implementation is the result      18 // * This  code  implementation is the result of  the  scientific and *
 19 // * technical work of the GEANT4 collaboratio     19 // * technical work of the GEANT4 collaboration.                      *
 20 // * By using,  copying,  modifying or  distri     20 // * By using,  copying,  modifying or  distributing the software (or *
 21 // * any work based  on the software)  you  ag     21 // * any work based  on the software)  you  agree  to acknowledge its *
 22 // * use  in  resulting  scientific  publicati     22 // * use  in  resulting  scientific  publications,  and indicate your *
 23 // * acceptance of all terms of the Geant4 Sof     23 // * acceptance of all terms of the Geant4 Software license.          *
 24 // *******************************************     24 // ********************************************************************
 25 //                                                 25 //
                                                   >>  26 // $Id: G4DNAMolecularMaterial.cc 84858 2014-10-21 16:08:22Z gcosmo $
 26 //                                                 27 //
 27 // Author: Mathieu Karamitros                  << 
 28 //                                             << 
 29                                                << 
 30 #include "G4DNAMolecularMaterial.hh"               28 #include "G4DNAMolecularMaterial.hh"
 31                                                << 
 32 #include "G4AutoLock.hh"                       << 
 33 #include "G4Material.hh"                           29 #include "G4Material.hh"
 34 #include "G4MoleculeTable.hh"                  <<  30 #include <utility>
 35 #include "G4StateManager.hh"                       31 #include "G4StateManager.hh"
 36 #include "G4Threading.hh"                          32 #include "G4Threading.hh"
 37                                                <<  33 #include "G4AutoLock.hh"
 38 #include <utility>                             <<  34 #include "G4StateManager.hh"
 39                                                    35 
 40 using namespace std;                               36 using namespace std;
 41                                                    37 
 42 G4DNAMolecularMaterial* G4DNAMolecularMaterial <<  38 G4DNAMolecularMaterial* G4DNAMolecularMaterial::fInstance(0);
 43                                                <<  39 //G4ThreadLocal G4DNAMolecularMaterial* G4DNAMolecularMaterial::fInstance(0);
 44 namespace                                      <<  40 G4Mutex aMutex = G4MUTEX_INITIALIZER;
 45 {                                              << 
 46   G4Mutex aMutex = G4MUTEX_INITIALIZER;        << 
 47 }                                              << 
 48                                                << 
 49 //-------------------------------------------- << 
 50                                                    41 
 51 bool CompareMaterial::operator()(const G4Mater     42 bool CompareMaterial::operator()(const G4Material* mat1,
 52                                  const G4Mater     43                                  const G4Material* mat2) const
 53 {                                                  44 {
 54   if (mat1 == nullptr && mat2 == nullptr) retu <<  45   if (mat1 == 0 && mat2 == 0) return false; //(mat1 == mat2)
 55   if (mat1 == nullptr) return true; // mat1 <  <<  46   if (mat1 == 0) return true; // mat1 < mat2
 56   if (mat2 == nullptr) return false; //mat2 <  <<  47   if (mat2 == 0) return false; //mat2 < mat1
 57                                                    48 
 58   const G4Material* baseMat1 = mat1->GetBaseMa     49   const G4Material* baseMat1 = mat1->GetBaseMaterial();
 59   const G4Material* baseMat2 = mat2->GetBaseMa     50   const G4Material* baseMat2 = mat2->GetBaseMaterial();
 60                                                    51 
 61   if ((baseMat1 == nullptr) && (baseMat2 == nu <<  52   if ((baseMat1 || baseMat2) == 0) // None of the materials derives from a base material
 62     // None of the materials derives from a ba <<  53   {
 63     return mat1 < mat2;                            54     return mat1 < mat2;
 64   }                                                55   }
 65   if ((baseMat1 != nullptr) && (baseMat2 != nu <<  56   else if (baseMat1 && baseMat2) // Both materials derive from a base material
 66     // Both materials derive from a base mater <<  57   {
 67     return baseMat1 < baseMat2;                    58     return baseMat1 < baseMat2;
 68   }                                                59   }
 69                                                    60 
 70   if ((baseMat1 != nullptr) && (baseMat2 == nu <<  61   else if (baseMat1 && (baseMat2 == 0)) // Only the material 1 derives from a base material
 71     // Only the material 1 derives from a base <<  62   {
 72     return baseMat1 < mat2;                        63     return baseMat1 < mat2;
 73   }                                                64   }
 74   // only case baseMat1==nullptr && baseMat2 r <<  65   // only case baseMat1==0 && baseMat2 remains
 75   return mat1 < baseMat2;                          66   return mat1 < baseMat2;
 76 }                                                  67 }
 77                                                    68 
 78 //-------------------------------------------- << 
 79                                                << 
 80 G4DNAMolecularMaterial* G4DNAMolecularMaterial     69 G4DNAMolecularMaterial* G4DNAMolecularMaterial::Instance()
 81 {                                                  70 {
 82   if (fInstance == nullptr) fInstance = new G4 <<  71   if (!fInstance) new G4DNAMolecularMaterial();
 83   return fInstance;                                72   return fInstance;
 84 }                                                  73 }
 85                                                    74 
 86 //-------------------------------------------- <<  75 void G4DNAMolecularMaterial::DeleteInstance()
                                                   >>  76 {
                                                   >>  77   if (fInstance)
                                                   >>  78   {
                                                   >>  79     delete fInstance;
                                                   >>  80     fInstance = 0;
                                                   >>  81   }
                                                   >>  82 }
 87                                                    83 
 88 void G4DNAMolecularMaterial::Create()              84 void G4DNAMolecularMaterial::Create()
 89 {                                                  85 {
 90   fpCompFractionTable = nullptr;               <<  86   fpCompFractionTable = 0;
 91   fpCompDensityTable = nullptr;                <<  87   fpCompDensityTable = 0;
 92   fpCompNumMolPerVolTable = nullptr;           <<  88   fpCompNumMolPerVolTable = 0;
 93   fIsInitialized = false;                          89   fIsInitialized = false;
 94   fNMaterials = 0;                                 90   fNMaterials = 0;
                                                   >>  91   fInstance = this;
 95 }                                                  92 }
 96                                                    93 
 97 //-------------------------------------------- << 
 98                                                << 
 99 void G4DNAMolecularMaterial::Clear()               94 void G4DNAMolecularMaterial::Clear()
100 {                                                  95 {
101   G4AutoLock l2(&aMutex);                      <<  96   if (fpCompFractionTable)
102   if (fpCompFractionTable != nullptr){         <<  97   {
103     fpCompFractionTable->clear();                  98     fpCompFractionTable->clear();
104     delete fpCompFractionTable;                    99     delete fpCompFractionTable;
105     fpCompFractionTable = nullptr;             << 100     fpCompFractionTable = 0;
106   }                                               101   }
107   if (fpCompDensityTable != nullptr){          << 102   if (fpCompDensityTable)
                                                   >> 103   {
108     fpCompDensityTable->clear();                  104     fpCompDensityTable->clear();
109     delete fpCompDensityTable;                    105     delete fpCompDensityTable;
110     fpCompDensityTable = nullptr;              << 106     fpCompDensityTable = 0;
111   }                                               107   }
112   if (fpCompNumMolPerVolTable != nullptr){     << 108   if (fpCompNumMolPerVolTable)
                                                   >> 109   {
113     fpCompNumMolPerVolTable->clear();             110     fpCompNumMolPerVolTable->clear();
114     delete fpCompNumMolPerVolTable;               111     delete fpCompNumMolPerVolTable;
115     fpCompNumMolPerVolTable = nullptr;         << 112     fpCompNumMolPerVolTable = 0;
116   }                                               113   }
117                                                   114 
118   std::map<const G4Material*, std::vector<G4do << 115   map<const G4Material*, std::vector<double>*, CompareMaterial>::iterator it;
119                                                   116 
120   for (it = fAskedDensityTable.begin(); it !=  << 117   for (it = fAskedDensityTable.begin(); it != fAskedDensityTable.end(); it++)
121     if (it->second != nullptr){                << 118   {
                                                   >> 119     if (it->second)
                                                   >> 120     {
122       delete it->second;                          121       delete it->second;
123       it->second = nullptr;                    << 122       it->second = 0;
124     }                                             123     }
125   }                                               124   }
126                                                   125 
127   for (it = fAskedNumPerVolTable.begin(); it ! << 126   for (it = fAskedNumPerVolTable.begin(); it != fAskedNumPerVolTable.end();
128     if (it->second != nullptr){                << 127       it++)
                                                   >> 128   {
                                                   >> 129     if (it->second)
                                                   >> 130     {
129       delete it->second;                          131       delete it->second;
130       it->second = nullptr;                    << 132       it->second = 0;
131     }                                             133     }
132   }                                               134   }
133   l2.unlock();                                 << 
134 }                                                 135 }
135                                                   136 
136                                                << 137 G4DNAMolecularMaterial::G4DNAMolecularMaterial() :
137 //-------------------------------------------- << 138     G4VStateDependent()
138                                                << 
139 G4DNAMolecularMaterial::G4DNAMolecularMaterial << 
140 {                                                 139 {
141   Create();                                       140   Create();
                                                   >> 141   fInstance = this;
142 }                                                 142 }
143                                                   143 
144 //-------------------------------------------- << 
145                                                << 
146 G4bool G4DNAMolecularMaterial::Notify(G4Applic    144 G4bool G4DNAMolecularMaterial::Notify(G4ApplicationState requestedState)
147 {                                                 145 {
148   if (requestedState == G4State_Idle && G4Stat    146   if (requestedState == G4State_Idle && G4StateManager::GetStateManager()
149       ->GetPreviousState() == G4State_PreInit) << 147       ->GetPreviousState() == G4State_PreInit)
                                                   >> 148   {
150     Initialize();                                 149     Initialize();
151   }                                               150   }
                                                   >> 151   else if (requestedState == G4State_Quit)
                                                   >> 152   {
                                                   >> 153 //    G4cout << "G4DNAMolecularMaterial::Notify ---> received G4State_Quit"
                                                   >> 154 //           << G4endl;
                                                   >> 155     Clear();
                                                   >> 156     //DeleteInstance();
                                                   >> 157   }
152   return true;                                    158   return true;
153 }                                                 159 }
154                                                   160 
155 //-------------------------------------------- << 161 G4DNAMolecularMaterial::G4DNAMolecularMaterial(
                                                   >> 162     const G4DNAMolecularMaterial& /*rhs*/) :
                                                   >> 163     G4VStateDependent()
                                                   >> 164 {
                                                   >> 165   Create();
                                                   >> 166 }
                                                   >> 167 
                                                   >> 168 G4DNAMolecularMaterial&
                                                   >> 169 G4DNAMolecularMaterial::operator=(const G4DNAMolecularMaterial& rhs)
                                                   >> 170 {
                                                   >> 171   if (this == &rhs) return *this;
                                                   >> 172   Create();
                                                   >> 173   return *this;
                                                   >> 174 }
156                                                   175 
157 G4DNAMolecularMaterial::~G4DNAMolecularMateria    176 G4DNAMolecularMaterial::~G4DNAMolecularMaterial()
158 {                                                 177 {
                                                   >> 178 //  G4cout << "Deleting G4DNAMolecularMaterial" << G4endl;
159   Clear();                                        179   Clear();
                                                   >> 180   fInstance = 0;
                                                   >> 181   //assert(G4StateManager::GetStateManager()->DeregisterDependent(this) == true);
160 }                                                 182 }
161                                                   183 
162 //-------------------------------------------- << 
163                                                << 
164 void G4DNAMolecularMaterial::Initialize()         184 void G4DNAMolecularMaterial::Initialize()
165 {                                                 185 {
166   if (fIsInitialized){                         << 186   G4AutoLock l(&aMutex);
                                                   >> 187   if (fIsInitialized)
                                                   >> 188   {
167     return;                                       189     return;
168   }                                               190   }
169                                                   191 
170   const G4MaterialTable* materialTable = G4Mat    192   const G4MaterialTable* materialTable = G4Material::GetMaterialTable();
171                                                   193 
172   fNMaterials = materialTable->size();            194   fNMaterials = materialTable->size();
173   // This is to prevent segment fault if mater    195   // This is to prevent segment fault if materials are created later on
174   // Actually this creation should not be done    196   // Actually this creation should not be done
175                                                   197 
176   G4AutoLock l1(&aMutex);                      << 198   if (fpCompFractionTable == 0)
177   if (fpCompFractionTable == nullptr){         << 199   {
178     fpCompFractionTable = new vector<Component    200     fpCompFractionTable = new vector<ComponentMap>(materialTable->size());
179   }                                               201   }
180                                                   202 
181   G4Material* mat(nullptr);                    << 203   G4Material* mat(0);
182                                                   204 
183   for (std::size_t i = 0; i < fNMaterials; ++i << 205   for (size_t i = 0; i < fNMaterials; i++)
                                                   >> 206   {
184     mat = materialTable->at(i);                   207     mat = materialTable->at(i);
185     SearchMolecularMaterial(mat, mat, 1);         208     SearchMolecularMaterial(mat, mat, 1);
                                                   >> 209 
                                                   >> 210     mat = 0;
186   }                                               211   }
187                                                   212 
188   InitializeDensity();                            213   InitializeDensity();
189   InitializeNumMolPerVol();                       214   InitializeNumMolPerVol();
190   l1.unlock();                                 << 
191                                                   215 
192   fIsInitialized = true;                          216   fIsInitialized = true;
193 }                                                 217 }
194                                                   218 
195 //-------------------------------------------- << 
196                                                << 
197 void G4DNAMolecularMaterial::InitializeDensity    219 void G4DNAMolecularMaterial::InitializeDensity()
198 {                                                 220 {
199   if (fpCompFractionTable != nullptr){         << 221   if (fpCompFractionTable)
                                                   >> 222   {
200     const G4MaterialTable* materialTable = G4M    223     const G4MaterialTable* materialTable = G4Material::GetMaterialTable();
201     fpCompDensityTable = new vector<ComponentM    224     fpCompDensityTable = new vector<ComponentMap>(
202         G4Material::GetMaterialTable()->size()    225         G4Material::GetMaterialTable()->size());
203                                                   226 
204     G4Material* parentMat;                        227     G4Material* parentMat;
205     const G4Material* compMat(nullptr);        << 228     const G4Material* compMat(0);
206     G4double massFraction = -1;                << 229     double massFraction = -1;
207     G4double parentDensity = -1;               << 230     double parentDensity = -1;
208                                                   231 
209     for (std::size_t i = 0; i < fNMaterials; + << 232     for (size_t i = 0; i < fNMaterials; i++)
                                                   >> 233     {
210       parentMat = materialTable->at(i);           234       parentMat = materialTable->at(i);
211       ComponentMap& massFractionComp = (*fpCom    235       ComponentMap& massFractionComp = (*fpCompFractionTable)[i];
212       ComponentMap& densityComp = (*fpCompDens    236       ComponentMap& densityComp = (*fpCompDensityTable)[i];
213                                                   237 
214       parentDensity = parentMat->GetDensity();    238       parentDensity = parentMat->GetDensity();
215                                                   239 
216       for (const auto& it : massFractionComp){ << 240       for (ComponentMap::iterator it = massFractionComp.begin();
217         compMat = it.first;                    << 241           it != massFractionComp.end(); it++)
218         massFraction = it.second;              << 242       {
                                                   >> 243         compMat = it->first;
                                                   >> 244         massFraction = it->second;
219         densityComp[compMat] = massFraction *     245         densityComp[compMat] = massFraction * parentDensity;
220         compMat = nullptr;                     << 246         compMat = 0;
221         massFraction = -1;                        247         massFraction = -1;
222       }                                           248       }
223     }                                             249     }
224   }                                               250   }
225   else{                                        << 251   else
                                                   >> 252   {
226     G4ExceptionDescription exceptionDescriptio    253     G4ExceptionDescription exceptionDescription;
227     exceptionDescription << "The pointer fpCom    254     exceptionDescription << "The pointer fpCompFractionTable is not initialized"
228                          << G4endl;               255                          << G4endl;
229     G4Exception("G4DNAMolecularMaterial::Initi    256     G4Exception("G4DNAMolecularMaterial::InitializeDensity",
230                 "G4DNAMolecularMaterial001", F    257                 "G4DNAMolecularMaterial001", FatalException,
231                 exceptionDescription);            258                 exceptionDescription);
232   }                                               259   }
233 }                                                 260 }
234                                                   261 
235 //-------------------------------------------- << 
236                                                << 
237 void G4DNAMolecularMaterial::InitializeNumMolP    262 void G4DNAMolecularMaterial::InitializeNumMolPerVol()
238 {                                                 263 {
239   if (fpCompDensityTable != nullptr){          << 264   if (fpCompDensityTable)
                                                   >> 265   {
240     fpCompNumMolPerVolTable = new vector<Compo    266     fpCompNumMolPerVolTable = new vector<ComponentMap>(fNMaterials);
241                                                   267 
242     const G4Material* compMat(nullptr);        << 268     const G4Material* compMat(0);
243                                                   269 
244     for (std::size_t i = 0; i < fNMaterials; + << 270     for (size_t i = 0; i < fNMaterials; i++)
                                                   >> 271     {
245       ComponentMap& massFractionComp = (*fpCom    272       ComponentMap& massFractionComp = (*fpCompFractionTable)[i];
246       ComponentMap& densityComp = (*fpCompDens    273       ComponentMap& densityComp = (*fpCompDensityTable)[i];
247       ComponentMap& numMolPerVol = (*fpCompNum    274       ComponentMap& numMolPerVol = (*fpCompNumMolPerVolTable)[i];
248                                                   275 
249       for (auto& it : massFractionComp){       << 276       for (ComponentMap::iterator it = massFractionComp.begin();
250         compMat = it.first;                    << 277           it != massFractionComp.end(); it++)
                                                   >> 278       {
                                                   >> 279         compMat = it->first;
251         numMolPerVol[compMat] = densityComp[co    280         numMolPerVol[compMat] = densityComp[compMat]
252             / compMat->GetMassOfMolecule();       281             / compMat->GetMassOfMolecule();
253         compMat = nullptr;                     << 282         compMat = 0;
254       }                                           283       }
255     }                                             284     }
256   }                                               285   }
257   else{                                        << 286   else
                                                   >> 287   {
258     G4ExceptionDescription exceptionDescriptio    288     G4ExceptionDescription exceptionDescription;
259     exceptionDescription << "The pointer fpCom    289     exceptionDescription << "The pointer fpCompDensityTable is not initialized"
260                          << G4endl;               290                          << G4endl;
261     G4Exception("G4DNAMolecularMaterial::Initi    291     G4Exception("G4DNAMolecularMaterial::InitializeNumMolPerVol",
262                 "G4DNAMolecularMaterial002", F    292                 "G4DNAMolecularMaterial002", FatalException,
263                 exceptionDescription);            293                 exceptionDescription);
264   }                                               294   }
265 }                                                 295 }
266                                                   296 
267 //-------------------------------------------- << 297 void G4DNAMolecularMaterial::RecordMolecularMaterial(G4Material* parentMaterial,
268                                                << 298                                                      G4Material* molecularMaterial,
269 void                                           << 299                                                      G4double fraction)
270 G4DNAMolecularMaterial::RecordMolecularMateria << 
271                                                << 
272                                                << 
273 {                                                 300 {
274   ComponentMap& matComponent =                    301   ComponentMap& matComponent =
275       (*fpCompFractionTable)[parentMaterial->G    302       (*fpCompFractionTable)[parentMaterial->GetIndex()];
276                                                   303 
277   if (matComponent.empty()){                   << 304   if (matComponent.empty())
                                                   >> 305   {
278     matComponent[molecularMaterial] = fraction    306     matComponent[molecularMaterial] = fraction;
279     return;                                       307     return;
280   }                                               308   }
281                                                   309 
282   auto it = matComponent.find(molecularMateria << 310   ComponentMap::iterator it = matComponent.find(molecularMaterial);
283                                                   311 
284   if (it == matComponent.cend()){              << 312   if (it == matComponent.end())
                                                   >> 313   {
285     matComponent[molecularMaterial] = fraction    314     matComponent[molecularMaterial] = fraction;
286   }                                               315   }
287   else{                                        << 316   else
                                                   >> 317   {
288     matComponent[molecularMaterial] = it->seco    318     matComponent[molecularMaterial] = it->second + fraction;
289     // handle "base material"                  << 
290   }                                               319   }
291 }                                                 320 }
292                                                   321 
293 //-------------------------------------------- << 
294                                                << 
295 void G4DNAMolecularMaterial::SearchMolecularMa    322 void G4DNAMolecularMaterial::SearchMolecularMaterial(G4Material* parentMaterial,
296                                                   323                                                      G4Material* material,
297                                                << 324                                                      double currentFraction)
298 {                                                 325 {
299   if (material->GetMassOfMolecule() != 0.0){ / << 326   if (material->GetMassOfMolecule() != 0.0)
                                                   >> 327   {
300     RecordMolecularMaterial(parentMaterial, ma    328     RecordMolecularMaterial(parentMaterial, material, currentFraction);
301     return;                                       329     return;
302   }                                               330   }
303                                                   331 
304   G4Material* compMat(nullptr);                << 332   G4Material* compMat(0);
305   G4double fraction = -1.;                     << 333   G4double fraction = -1;
306   std::map<G4Material*, G4double> matComponent    334   std::map<G4Material*, G4double> matComponent = material->GetMatComponents();
307   auto it = matComponent.cbegin();             << 335   std::map<G4Material*, G4double>::iterator it = matComponent.begin();
308                                                   336 
309   for (; it != matComponent.cend(); ++it){     << 337   for (; it != matComponent.end(); it++)
                                                   >> 338   {
310     compMat = it->first;                          339     compMat = it->first;
311     fraction = it->second;                        340     fraction = it->second;
312     if (compMat->GetMassOfMolecule() == 0.0){  << 341     if (compMat->GetMassOfMolecule() == 0.0)
                                                   >> 342     {
313       SearchMolecularMaterial(parentMaterial,     343       SearchMolecularMaterial(parentMaterial, compMat,
314                               currentFraction     344                               currentFraction * fraction);
315     }                                             345     }
316     else{ // is a molecular material           << 346     else
                                                   >> 347     {
317       RecordMolecularMaterial(parentMaterial,     348       RecordMolecularMaterial(parentMaterial, compMat,
318                               currentFraction     349                               currentFraction * fraction);
319     }                                             350     }
                                                   >> 351 
                                                   >> 352     compMat = 0;
                                                   >> 353     fraction = -1;
320   }                                               354   }
321 }                                                 355 }
322                                                   356 
323 //-------------------------------------------- << 357 const std::vector<double>*
324                                                << 
325 const std::vector<G4double>*                   << 
326 G4DNAMolecularMaterial::                          358 G4DNAMolecularMaterial::
327 GetDensityTableFor(const G4Material* lookForMa    359 GetDensityTableFor(const G4Material* lookForMaterial) const
328 {                                                 360 {
329   if (fpCompDensityTable == nullptr){          << 361   if (!fpCompDensityTable)
330     if (fIsInitialized){                       << 362   {
                                                   >> 363     if (fIsInitialized)
                                                   >> 364     {
331       G4ExceptionDescription exceptionDescript    365       G4ExceptionDescription exceptionDescription;
332       exceptionDescription                        366       exceptionDescription
333           << "The pointer fpCompDensityTable i    367           << "The pointer fpCompDensityTable is not initialized will the "
334           "singleton of G4DNAMolecularMaterial    368           "singleton of G4DNAMolecularMaterial "
335           << "has already been initialized." <    369           << "has already been initialized." << G4endl;
336       G4Exception("G4DNAMolecularMaterial::Get    370       G4Exception("G4DNAMolecularMaterial::GetDensityTableFor",
337                   "G4DNAMolecularMaterial003",    371                   "G4DNAMolecularMaterial003", FatalException,
338                   exceptionDescription);          372                   exceptionDescription);
339     }                                             373     }
340                                                   374 
341     if (G4StateManager::GetStateManager()->Get << 375     if (G4StateManager::GetStateManager()->GetCurrentState() == G4State_Idle)
                                                   >> 376     {
342       const_cast<G4DNAMolecularMaterial*>(this    377       const_cast<G4DNAMolecularMaterial*>(this)->Initialize();
343     }                                             378     }
344     else{                                      << 379     else
                                                   >> 380     {
345       G4ExceptionDescription exceptionDescript    381       G4ExceptionDescription exceptionDescription;
346       exceptionDescription                        382       exceptionDescription
347           << "The geant4 application is at the    383           << "The geant4 application is at the wrong state. State must be: "
348           "G4State_Init."                      << 384           "G4State_Idle."
349           << G4endl;                              385           << G4endl;
350       G4Exception("G4DNAMolecularMaterial::Get    386       G4Exception("G4DNAMolecularMaterial::GetDensityTableFor",
351                   "G4DNAMolecularMaterial_WRON    387                   "G4DNAMolecularMaterial_WRONG_STATE_APPLICATION",
352                   FatalException, exceptionDes    388                   FatalException, exceptionDescription);
353     }                                             389     }
354   }                                               390   }
355                                                   391 
356   auto it_askedDensityTable = fAskedDensityTab << 392   std::map<const G4Material*, std::vector<double>*, CompareMaterial>::
                                                   >> 393     const_iterator it_askedDensityTable =
                                                   >> 394         fAskedDensityTable.find(lookForMaterial);
357                                                   395 
358   if (it_askedDensityTable != fAskedDensityTab << 396   if (it_askedDensityTable != fAskedDensityTable.end())
                                                   >> 397   {
359     return it_askedDensityTable->second;          398     return it_askedDensityTable->second;
360   }                                               399   }
361                                                   400 
362   const G4MaterialTable* materialTable = G4Mat    401   const G4MaterialTable* materialTable = G4Material::GetMaterialTable();
363                                                   402 
364   auto  output = new std::vector<G4double>(mat << 403   std::vector<double>* output = new std::vector<double>(materialTable->size());
365                                                   404 
366   ComponentMap::const_iterator it;                405   ComponentMap::const_iterator it;
367                                                   406 
368   G4bool materialWasNotFound = true;              407   G4bool materialWasNotFound = true;
369                                                   408 
370   for (std::size_t i = 0; i < fNMaterials; ++i << 409   for (size_t i = 0; i < fNMaterials; i++)
                                                   >> 410   {
371     ComponentMap& densityTable = (*fpCompDensi    411     ComponentMap& densityTable = (*fpCompDensityTable)[i];
372                                                   412 
373     it = densityTable.find(lookForMaterial);      413     it = densityTable.find(lookForMaterial);
374                                                   414 
375     if (it == densityTable.cend()){            << 415     if (it == densityTable.end())
                                                   >> 416     {
376       (*output)[i] = 0.0;                         417       (*output)[i] = 0.0;
377     }                                             418     }
378     else{                                      << 419     else
                                                   >> 420     {
379       materialWasNotFound = false;                421       materialWasNotFound = false;
380       (*output)[i] = it->second;                  422       (*output)[i] = it->second;
381     }                                             423     }
382   }                                               424   }
383                                                   425 
384   if (materialWasNotFound){                    << 426   if (materialWasNotFound)
                                                   >> 427   {
385     PrintNotAMolecularMaterial("G4DNAMolecular    428     PrintNotAMolecularMaterial("G4DNAMolecularMaterial::GetDensityTableFor",
386                                lookForMaterial    429                                lookForMaterial);
387   }                                               430   }
388                                                   431 
389   fAskedDensityTable.insert(make_pair(lookForM    432   fAskedDensityTable.insert(make_pair(lookForMaterial, output));
390                                                   433 
391   return output;                                  434   return output;
392 }                                                 435 }
393                                                   436 
394 //-------------------------------------------- << 437 const std::vector<double>* G4DNAMolecularMaterial::GetNumMolPerVolTableFor(
395                                                << 
396 const std::vector<G4double>* G4DNAMolecularMat << 
397     const G4Material* lookForMaterial) const      438     const G4Material* lookForMaterial) const
398 {                                                 439 {
399   if(lookForMaterial==nullptr) return nullptr; << 440   if (!fpCompNumMolPerVolTable)
400                                                << 441   {
401   if (fpCompNumMolPerVolTable == nullptr){     << 442     if (fIsInitialized)
402     if (fIsInitialized){                       << 443     {
403       G4ExceptionDescription exceptionDescript    444       G4ExceptionDescription exceptionDescription;
404       exceptionDescription                        445       exceptionDescription
405           << "The pointer fpCompNumMolPerVolTa    446           << "The pointer fpCompNumMolPerVolTable is not initialized whereas "
406           "the singleton of G4DNAMolecularMate    447           "the singleton of G4DNAMolecularMaterial "
407           << "has already been initialized." <    448           << "has already been initialized." << G4endl;
408       G4Exception("G4DNAMolecularMaterial::Get    449       G4Exception("G4DNAMolecularMaterial::GetNumMolPerVolTableFor",
409                   "G4DNAMolecularMaterial005",    450                   "G4DNAMolecularMaterial005", FatalException,
410                   exceptionDescription);          451                   exceptionDescription);
411     }                                             452     }
412                                                   453 
413     if (G4StateManager::GetStateManager()->Get << 454     if (G4StateManager::GetStateManager()->GetCurrentState() == G4State_Idle)
                                                   >> 455     {
414       const_cast<G4DNAMolecularMaterial*>(this    456       const_cast<G4DNAMolecularMaterial*>(this)->Initialize();
415     }                                             457     }
416     else{                                      << 458     else
                                                   >> 459     {
417       G4ExceptionDescription exceptionDescript    460       G4ExceptionDescription exceptionDescription;
418       exceptionDescription                        461       exceptionDescription
419           << "The geant4 application is at the    462           << "The geant4 application is at the wrong state. State must be : "
420           "G4State_Init."                      << 463           "G4State_Idle."
421           << G4endl;                              464           << G4endl;
422       G4Exception("G4DNAMolecularMaterial::Get    465       G4Exception("G4DNAMolecularMaterial::GetNumMolPerVolTableFor",
423                   "G4DNAMolecularMaterial_WRON    466                   "G4DNAMolecularMaterial_WRONG_STATE_APPLICATION",
424                   FatalException, exceptionDes    467                   FatalException, exceptionDescription);
425     }                                             468     }
426   }                                               469   }
427                                                   470 
428   auto it_askedNumMolPerVolTable = fAskedNumPe << 471   std::map<const G4Material*, std::vector<double>*, CompareMaterial>::
429   if (it_askedNumMolPerVolTable != fAskedNumPe << 472       const_iterator it_askedNumMolPerVolTable =
                                                   >> 473           fAskedNumPerVolTable.find(lookForMaterial);
                                                   >> 474   if (it_askedNumMolPerVolTable != fAskedNumPerVolTable.end())
                                                   >> 475   {
430     return it_askedNumMolPerVolTable->second;     476     return it_askedNumMolPerVolTable->second;
431   }                                               477   }
432                                                   478 
433   const G4MaterialTable* materialTable = G4Mat    479   const G4MaterialTable* materialTable = G4Material::GetMaterialTable();
434                                                   480 
435   auto  output = new std::vector<G4double>(mat << 481   std::vector<double>* output = new std::vector<double>(materialTable->size());
436                                                   482 
437   ComponentMap::const_iterator it;                483   ComponentMap::const_iterator it;
438                                                   484 
439   G4bool materialWasNotFound = true;              485   G4bool materialWasNotFound = true;
440                                                   486 
441   for (std::size_t i = 0; i < fNMaterials; ++i << 487   for (size_t i = 0; i < fNMaterials; i++)
                                                   >> 488   {
442     ComponentMap& densityTable = (*fpCompNumMo    489     ComponentMap& densityTable = (*fpCompNumMolPerVolTable)[i];
443                                                   490 
444     it = densityTable.find(lookForMaterial);      491     it = densityTable.find(lookForMaterial);
445                                                   492 
446     if (it == densityTable.cend()){            << 493     if (it == densityTable.end())
                                                   >> 494     {
447       (*output)[i] = 0.0;                         495       (*output)[i] = 0.0;
448     }                                             496     }
449     else{                                      << 497     else
                                                   >> 498     {
450       materialWasNotFound = false;                499       materialWasNotFound = false;
451       (*output)[i] = it->second;                  500       (*output)[i] = it->second;
452     }                                             501     }
453   }                                               502   }
454                                                   503 
455   if (materialWasNotFound){                    << 504   if (materialWasNotFound)
                                                   >> 505   {
456     PrintNotAMolecularMaterial(                   506     PrintNotAMolecularMaterial(
457         "G4DNAMolecularMaterial::GetNumMolPerV    507         "G4DNAMolecularMaterial::GetNumMolPerVolTableFor", lookForMaterial);
458   }                                               508   }
459                                                   509 
460   fAskedNumPerVolTable.insert(make_pair(lookFo    510   fAskedNumPerVolTable.insert(make_pair(lookForMaterial, output));
461                                                   511 
462   return output;                                  512   return output;
463 }                                                 513 }
464                                                   514 
465 //-------------------------------------------- << 
466                                                << 
467 void G4DNAMolecularMaterial::                     515 void G4DNAMolecularMaterial::
468 PrintNotAMolecularMaterial(const char* methodN    516 PrintNotAMolecularMaterial(const char* methodName,
469                            const G4Material* l    517                            const G4Material* lookForMaterial) const
470 {                                                 518 {
471   auto it = fWarningPrinted.find(lookForMateri << 519   std::map<const G4Material*, bool, CompareMaterial>::iterator it =
                                                   >> 520       fWarningPrinted.find(lookForMaterial);
472                                                   521 
473   if (it == fWarningPrinted.cend()){           << 522   if (it == fWarningPrinted.end())
                                                   >> 523   {
474     G4ExceptionDescription exceptionDescriptio    524     G4ExceptionDescription exceptionDescription;
475     exceptionDescription << "The material " <<    525     exceptionDescription << "The material " << lookForMaterial->GetName()
476                          << " is not defined a    526                          << " is not defined as a molecular material."
477                          << G4endl                527                          << G4endl
478                          << "Meaning: The elem    528                          << "Meaning: The elements should be added to the "
479                          "material using atom     529                          "material using atom count rather than mass fraction "
480                          "(cf. G4Material)"       530                          "(cf. G4Material)"
481     << G4endl                                     531     << G4endl
482     << "If you want to use DNA processes on li    532     << "If you want to use DNA processes on liquid water, you should better use "
483     "the NistManager to create the water mater    533     "the NistManager to create the water material."
484     << G4endl                                     534     << G4endl
485     << "Since this message is displayed, it me    535     << "Since this message is displayed, it means that the DNA models will not "
486     "be called."                                  536     "be called."
487     << "Please note that this message will onl    537     << "Please note that this message will only appear once even if you are "
488     "using other methods of G4DNAMolecularMate    538     "using other methods of G4DNAMolecularMaterial."
489     << G4endl;                                    539     << G4endl;
490                                                   540 
491     G4Exception(methodName, "MATERIAL_NOT_DEFI    541     G4Exception(methodName, "MATERIAL_NOT_DEFINE_USING_ATOM_COUNT", JustWarning,
492                 exceptionDescription);            542                 exceptionDescription);
493     fWarningPrinted[lookForMaterial] = true;      543     fWarningPrinted[lookForMaterial] = true;
494   }                                               544   }
495 }                                              << 
496                                                << 
497 //-------------------------------------------- << 
498                                                << 
499 G4MolecularConfiguration*                      << 
500 G4DNAMolecularMaterial::                       << 
501 GetMolecularConfiguration(const G4Material* ma << 
502 {                                              << 
503   auto  material_id = (G4int)material->GetInde << 
504   auto it = fMaterialToMolecularConf.find(mate << 
505   if(it == fMaterialToMolecularConf.cend()) re << 
506   return it->second;                           << 
507 }                                              << 
508                                                << 
509 //-------------------------------------------- << 
510                                                << 
511 void                                           << 
512 G4DNAMolecularMaterial::                       << 
513 SetMolecularConfiguration(const G4Material* ma << 
514                           G4MolecularConfigura << 
515 {                                              << 
516   assert(material != nullptr);                 << 
517   auto  material_id = (G4int)material->GetInde << 
518   fMaterialToMolecularConf[material_id] = molC << 
519 }                                              << 
520                                                << 
521 //-------------------------------------------- << 
522                                                << 
523 void                                           << 
524 G4DNAMolecularMaterial::SetMolecularConfigurat << 
525                                                << 
526 {                                              << 
527   assert(material != nullptr);                 << 
528   auto  material_id = (G4int)material->GetInde << 
529   fMaterialToMolecularConf[material_id] =      << 
530     G4MoleculeTable::Instance()->GetConfigurat << 
531 }                                              << 
532                                                << 
533 //-------------------------------------------- << 
534                                                << 
535 void                                           << 
536 G4DNAMolecularMaterial::SetMolecularConfigurat << 
537                                                << 
538 {                                              << 
539   G4Material* material = G4Material::GetMateri << 
540                                                << 
541   if(material == nullptr){                     << 
542     G4cout<< "Material " << materialName       << 
543           << " was not found and therefore won << 
544           << molUserID << G4endl;              << 
545     return;                                    << 
546   }                                            << 
547   SetMolecularConfiguration(material, molUserI << 
548 }                                              << 
549                                                << 
550 //-------------------------------------------- << 
551                                                << 
552 G4double                                       << 
553 G4DNAMolecularMaterial::                       << 
554 GetNumMoleculePerVolumeUnitForMaterial(const G << 
555 {                                              << 
556   G4Exception("G4DNAMolecularMaterial::GetNumM << 
557               "DEPRECATED",                    << 
558               FatalException,"Use standard met << 
559               " at the run initialization to r << 
560               " during stepping. The method is << 
561   return 0.;                                   << 
562 }                                              << 
563                                                << 
564 //-------------------------------------------- << 
565                                                << 
566 G4double                                       << 
567 G4DNAMolecularMaterial::                       << 
568 GetNumMolPerVolForComponentInComposite(const G << 
569                                        const G << 
570                                        G4doubl << 
571 {                                              << 
572   G4Exception("G4DNAMolecularMaterial::GetNumM << 
573                "DEPRECATED",                   << 
574                FatalException,"Use standard me << 
575               " at the run initialization to r << 
576               " during stepping. The method is << 
577   return 0.;                                   << 
578 }                                                 545 }
579                                                   546