ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4HadronicInteractionRegistry.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4HadronicInteractionRegistry.cc
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 // 23-Jan-2009 V.Ivanchenko make the class to be a singleton
28 // 17-Aug-2012 V.Ivanchenko added methods
29 
31 #include "G4HadronicInteraction.hh"
32 
35 
37 {
38  if(nullptr == instance) {
40  instance = inst.Instance();
41  }
42  return instance;
43 }
44 
46 {}
47 
49 {
50  Clean();
51 }
52 
54 {
55  size_t nModels = allModels.size();
56  //G4cout << "G4HadronicInteractionRegistry::Clean() start " << nModels
57  // << " " << this << G4endl;
58  for (size_t i=0; i<nModels; ++i) {
59  if( allModels[i] ) {
60  const char* xxx = (allModels[i]->GetModelName()).c_str();
61  G4int len = (allModels[i]->GetModelName()).length();
62  len = std::min(len, 9);
63  const G4String mname = G4String(xxx, len);
64  //G4cout << "G4HadronicInteractionRegistry: delete " << i << " "
65  // << allModels[i] << " " << mname
66  // << " " << this << G4endl;
67  if(mname != "NeutronHP" && mname != "ParticleH") {
68  delete allModels[i];
69  }
70  // G4cout << "done " << this << G4endl;
71  }
72  }
73  allModels.clear();
74  //G4cout <<"G4HadronicInteractionRegistry::Clean() is done "<<G4endl;
75 }
76 
78 {
79  for (auto & mod : allModels) {
80  if( mod ) { mod->InitialiseModel(); }
81  }
82 }
83 
84 void
86 {
87  if(!aModel) { return; }
88  for (auto & mod : allModels) {
89  if( aModel == mod ) { return; }
90  }
91  //G4cout << "Register model <" << aModel->GetModelName()
92  // << "> " << nModels+1 << " " << aModel << G4endl;
93  allModels.push_back(aModel);
94 }
95 
96 void
98 {
99  if(!aModel) { return; }
100  for (size_t i=0; i<allModels.size(); ++i) {
101  if( aModel == allModels[i] ) {
102  //G4cout << "DeRegister model <" << aModel
103  // << "> " << i << G4endl;
104  allModels[i] = nullptr;
105  return;
106  }
107  }
108 }
109 
112 {
113  G4HadronicInteraction* model = nullptr;
114  for (auto & mod : allModels) {
115  if(mod && mod->GetModelName() == name) {
116  model = mod;
117  break;
118  }
119  }
120  return model;
121 }
122 
123 std::vector<G4HadronicInteraction*>
125 {
126  std::vector<G4HadronicInteraction*> models;
127  for (auto & mod : allModels) {
128  if(mod && mod->GetModelName() == name) {
129  models.push_back(mod);
130  }
131  }
132  return models;
133 }