Geant4  10.01.p01
G4ITModelManager.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 // $Id: G4ITModelManager.cc 87375 2014-12-02 08:17:28Z gcosmo $
27 //
28 // Author: Mathieu Karamitros (kara (AT) cenbg . in2p3 . fr)
29 //
30 // History:
31 // -----------
32 // 10 Oct 2011 M.Karamitros created
33 //
34 // -------------------------------------------------------------------
35 
36 #include "G4ITModelManager.hh"
37 #include "G4ITType.hh"
38 #include "G4UnitsTable.hh"
39 
40 using namespace std;
41 
43  fIsInitialized(FALSE)
44 {
45  ;
46 }
47 
49 {
50  //dtor
51  mapModels::iterator it;
52 
53  for (it = fModels.begin(); it != fModels.end(); it++)
54  {
55  delete it->second;
56  }
57  fModels.clear();
58 }
59 
61 {
62  mapModels::const_iterator it = right.fModels.begin();
63 
64  for (; it != right.fModels.end(); it++)
65  {
66  fModels[it->first] = it->second->Clone();
67  }
68 
70 }
71 
73 {
74  if (this == &rhs) return *this; // handle self assignment
75  //assignment operator
76  return *this;
77 }
78 
80 {
81  mapModels::iterator it = fModels.begin();
82 
83  for (; it != fModels.end(); it++)
84  {
85  G4VITStepModel* model = it->second;
86  if (model != 0)
87  {
88  model->Initialize();
89  }
90  }
91 }
92 
94 {
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 }
106 
108 {
109  if (!fModels.empty())
110  {
111  mapModels::reverse_iterator rit = fModels.rbegin();
112  if (rit != fModels.rend())
113  {
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)
123  {
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);
131  }
132 
133  it = fModels.lower_bound(globalTime);
134 
135  if (it != fModels.end()) return it->second;
136  }
137  }
138  }
139 
140  G4ExceptionDescription exceptionDescription;
141  exceptionDescription << "No model was found.";
142  G4Exception("G4ITModelManager::GetModel", "ITModelManager004",
143  FatalErrorInArgument, exceptionDescription);
144  return 0;
145 }
virtual void Initialize()
std::ostringstream G4ExceptionDescription
Definition: globals.hh:76
void SetModel(G4VITStepModel *aModel, G4double startingTime)
Define what to do before stepping and after stepping.
#define G4BestUnit(a, b)
#define G4_USE_G4BESTUNIT_FOR_VERBOSE 1
#define FALSE
Definition: globals.hh:52
G4ITModelManager & operator=(const G4ITModelManager &rhs)
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
G4VITStepModel * GetModel(const G4double globalTime)
double G4double
Definition: G4Types.hh:76
G4ITModelManager chooses which model to use according to the global simulation time.