Geant4 Cross Reference |
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: G4ITModelManager.cc 87375 2014-12-02 08:17:28Z gcosmo $ 26 // 27 // 27 // Author: Mathieu Karamitros (kara (AT) cenbg 28 // Author: Mathieu Karamitros (kara (AT) cenbg . in2p3 . fr) 28 // 29 // 29 // History: 30 // History: 30 // ----------- 31 // ----------- 31 // 10 Oct 2011 M.Karamitros created 32 // 10 Oct 2011 M.Karamitros created 32 // 33 // 33 // ------------------------------------------- 34 // ------------------------------------------------------------------- 34 35 35 #include "G4ITModelManager.hh" 36 #include "G4ITModelManager.hh" 36 #include "G4VITStepModel.hh" << 37 #include "G4ITType.hh" 37 #include "G4ITType.hh" 38 #include "G4UnitsTable.hh" 38 #include "G4UnitsTable.hh" 39 39 >> 40 using namespace std; 40 41 41 G4ITModelManager::G4ITModelManager() << 42 G4ITModelManager::G4ITModelManager() : 42 << 43 fIsInitialized(FALSE) 43 = default; << 44 { >> 45 ; >> 46 } 44 47 45 G4ITModelManager::~G4ITModelManager() = defaul << 48 G4ITModelManager::~G4ITModelManager() >> 49 { >> 50 //dtor >> 51 mapModels::iterator it; 46 52 47 void G4ITModelManager::Initialize() << 53 for (it = fModels.begin(); it != fModels.end(); it++) >> 54 { >> 55 delete it->second; >> 56 } >> 57 fModels.clear(); >> 58 } >> 59 >> 60 G4ITModelManager::G4ITModelManager(const G4ITModelManager& right) 48 { 61 { 49 std::sort(fModelInfoList.begin(), fModelIn << 62 mapModels::const_iterator it = right.fModels.begin(); 50 [](const ModelInfo& lhs, const M << 51 return lhs.fStartingTime < r << 52 }); << 53 63 54 for (const auto& modelInfo : fModelInfoLis << 64 for (; it != right.fModels.end(); it++) 55 { << 65 { 56 modelInfo.fpModel->Initialize(); << 66 fModels[it->first] = it->second->Clone(); 57 } << 67 } >> 68 >> 69 fIsInitialized = right.fIsInitialized; >> 70 } 58 71 59 fIsInitialized = true; << 72 G4ITModelManager& G4ITModelManager::operator=(const G4ITModelManager& rhs) >> 73 { >> 74 if (this == &rhs) return *this; // handle self assignment >> 75 //assignment operator >> 76 return *this; 60 } 77 } 61 78 62 void G4ITModelManager::SetModel(G4VITStepModel << 79 void G4ITModelManager::Initialize() 63 const G4double << 64 const G4double << 65 { 80 { 66 assert(pModel != nullptr); << 81 mapModels::iterator it = fModels.begin(); 67 if (fIsInitialized) << 82 >> 83 for (; it != fModels.end(); it++) >> 84 { >> 85 G4VITStepModel* model = it->second; >> 86 if (model != 0) 68 { 87 { 69 G4ExceptionDescription exceptionDescri << 88 model->Initialize(); 70 exceptionDescription << 71 << "You are trying to insert a new << 72 G4Exception("G4ITModelManager::SetMode << 73 FatalErrorInArgument, exce << 74 } 89 } 75 << 90 } 76 fModelInfoList.emplace_back(ModelInfo({ st << 77 } 91 } 78 92 79 std::vector<G4VITStepModel*> G4ITModelManager: << 93 void G4ITModelManager::SetModel(G4VITStepModel* aModel, G4double startingTime) 80 { 94 { 81 std::vector<G4VITStepModel*> activeModels; << 95 assert(fIsInitialized == FALSE); >> 96 if (fIsInitialized == true) >> 97 { >> 98 G4ExceptionDescription exceptionDescription; >> 99 exceptionDescription >> 100 << "You are trying to insert a new model after initialization of th model manager."; >> 101 G4Exception("G4ITModelManager::SetModel", "ITModelManager001", >> 102 FatalErrorInArgument, exceptionDescription); >> 103 } >> 104 fModels[startingTime] = aModel; >> 105 } 82 106 83 for (const auto& modelInfo : fModelInfoLis << 107 G4VITStepModel* G4ITModelManager::GetModel(const G4double globalTime) >> 108 { >> 109 if (!fModels.empty()) >> 110 { >> 111 mapModels::reverse_iterator rit = fModels.rbegin(); >> 112 if (rit != fModels.rend()) 84 { 113 { 85 if (modelInfo.fStartingTime < globalTi << 114 if (globalTime > rit->first) >> 115 { >> 116 return rit->second; >> 117 } >> 118 else >> 119 { >> 120 mapModels::iterator it = fModels.begin(); >> 121 >> 122 if (globalTime < it->first) 86 { 123 { 87 activeModels.push_back(modelInfo.f << 124 G4ExceptionDescription exceptionDescription; >> 125 exceptionDescription << "No model was found at time "; >> 126 exceptionDescription << G4BestUnit(globalTime, "Time"); >> 127 exceptionDescription << ". The first model is registered at time : "; >> 128 exceptionDescription << G4BestUnit(it->first, "Time") << ". "; >> 129 G4Exception("G4ITModelManager::GetModel", "ITModelManager003", >> 130 FatalErrorInArgument, exceptionDescription); 88 } 131 } >> 132 >> 133 it = fModels.lower_bound(globalTime); >> 134 >> 135 if (it != fModels.end()) return it->second; >> 136 } 89 } 137 } >> 138 } 90 139 91 return activeModels; << 140 G4ExceptionDescription exceptionDescription; >> 141 exceptionDescription << "No model was found."; >> 142 G4Exception("G4ITModelManager::GetModel", "ITModelManager004", >> 143 FatalErrorInArgument, exceptionDescription); >> 144 return 0; 92 } 145 } 93 << 94 146