Geant4  10.02.p02
G4HadronicInteractionRegistry.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: G4HadronicInteractionRegistry.cc 93882 2015-11-03 08:23:54Z gcosmo $
27 //
28 // 23-Jan-2009 V.Ivanchenko make the class to be a singleton
29 // 17-Aug-2012 V.Ivanchenko added hadronic model factories
30 
32 #include "G4HadronicInteraction.hh"
33 
35 
37 {
38  if(!instance) {
40  instance = inst.Instance();
41  }
42  return instance;
43 }
44 
46 {
47  //std::cout << "G4HadronicInteractionRegistry " << this << std::endl;
48 }
49 
51 {
52  Clean();
53 }
54 
56 {
57  size_t nModels = allModels.size();
58  //std::cout << "G4HadronicInteractionRegistry::Clean() start " << nModels
59  // << " " << this << std::endl;
60  for (size_t i=0; i<nModels; ++i) {
61  if( allModels[i] ) {
62  const char* xxx = (allModels[i]->GetModelName()).c_str();
63  G4int len = (allModels[i]->GetModelName()).length();
64  len = std::min(len, 9);
65  const G4String mname = G4String(xxx, len);
66  //std::cout << "G4HadronicInteractionRegistry: delete " << i << " "
67  // << allModels[i] << " " << mname
68  // << " " << this << std::endl;
69  if(mname != "NeutronHP" && mname != "ParticleH") {
70  delete allModels[i];
71  }
72  // std::cout << "done " << this << std::endl;
73  }
74  }
75  allModels.clear();
76  //std::cout <<"G4HadronicInteractionRegistry::Clean() is done "<<std::endl;
77 }
78 
79 void
81 {
82  if(!aModel) { return; }
83  size_t nModels = allModels.size();
84  for (size_t i=0; i<nModels; ++i) {
85  if( aModel == allModels[i] ) { return; }
86  }
87  //G4cout << "Register model <" << aModel->GetModelName()
88  // << "> " << nModels+1 << " " << aModel << G4endl;
89  allModels.push_back(aModel);
90 }
91 
92 void
94 {
95  if(!aModel) { return; }
96  size_t nModels = allModels.size();
97  for (size_t i=0; i<nModels; ++i) {
98  if( aModel == allModels[i] ) {
99  //std::cout << "DeRegister model <" << aModel
100  // << "> " << i << std::endl;
101  allModels[i] = 0;
102  return;
103  }
104  }
105 }
106 
109 {
110  G4HadronicInteraction* model = 0;
111 
112  size_t nModels = allModels.size();
113  for (size_t i=0; i<nModels; ++i) {
115  if(p) {
116  if (p->GetModelName() == name) {
117  model = p;
118  break;
119  }
120  }
121  }
122  return model;
123 }
124 
125 std::vector<G4HadronicInteraction*>
127 {
128  std::vector<G4HadronicInteraction*> models;
129 
130  size_t nModels = allModels.size();
131  for (size_t i=0; i<nModels; ++i) {
133  if(p) {
134  if (p->GetModelName() == name) {
135  models.push_back(p);
136  }
137  }
138  }
139  return models;
140 }
G4String name
Definition: TRTMaterials.hh:40
std::vector< G4HadronicInteraction * > FindAllModels(const G4String &name)
static G4ThreadLocal G4HadronicInteractionRegistry * instance
void RemoveMe(G4HadronicInteraction *aModel)
std::vector< G4HadronicInteraction * > allModels
const G4String & GetModelName() const
void RegisterMe(G4HadronicInteraction *aModel)
#define G4ThreadLocal
Definition: tls.hh:89
int G4int
Definition: G4Types.hh:78
G4HadronicInteraction * FindModel(const G4String &name)
static G4HadronicInteractionRegistry * Instance()
T min(const T t1, const T t2)
brief Return the smallest of the two arguments