Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer << 3 // * DISCLAIMER * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th << 5 // * The following disclaimer summarizes all the specific disclaimers * 6 // * the Geant4 Collaboration. It is provided << 6 // * of contributors to this software. The specific disclaimers,which * 7 // * conditions of the Geant4 Software License << 7 // * govern, are listed with their locations in: * 8 // * LICENSE and available at http://cern.ch/ << 8 // * http://cern.ch/geant4/license * 9 // * include a list of copyright holders. << 10 // * 9 // * * 11 // * Neither the authors of this software syst 10 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 11 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 12 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 13 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file << 14 // * use. * 16 // * for the full disclaimer and the limitatio << 17 // * 15 // * * 18 // * This code implementation is the result << 16 // * This code implementation is the intellectual property of the * 19 // * technical work of the GEANT4 collaboratio << 17 // * authors in the GEANT4 collaboration. * 20 // * By using, copying, modifying or distri << 18 // * By copying, distributing or modifying the Program (or any work * 21 // * any work based on the software) you ag << 19 // * based on the Program) you indicate your acceptance of this * 22 // * use in resulting scientific publicati << 20 // * statement, and all its terms. * 23 // * acceptance of all terms of the Geant4 Sof << 24 // ******************************************* 21 // ******************************************************************** 25 // 22 // 26 // << 27 // 23-Jan-2009 V.Ivanchenko make the class to << 28 // 17-Aug-2012 V.Ivanchenko added methods << 29 << 30 #include "G4HadronicInteractionRegistry.hh" 23 #include "G4HadronicInteractionRegistry.hh" 31 #include "G4HadronicInteraction.hh" 24 #include "G4HadronicInteraction.hh" 32 25 33 G4ThreadLocal G4HadronicInteractionRegistry* << 26 G4HadronicInteractionRegistry G4HadronicInteractionRegistry:: 34 G4HadronicInteractionRegistry::instance = null << 27 theRegistry; 35 28 36 G4HadronicInteractionRegistry* G4HadronicInter << 29 void G4HadronicInteractionRegistry:: >> 30 RegisterMe(G4HadronicInteraction * aModel) 37 { 31 { 38 if(nullptr == instance) { << 32 theRegistry.AddModel(aModel); 39 static G4ThreadLocalSingleton<G4HadronicIn << 40 instance = inst.Instance(); << 41 } << 42 return instance; << 43 } 33 } 44 34 45 G4HadronicInteractionRegistry::G4HadronicInter << 46 {} << 47 << 48 G4HadronicInteractionRegistry::~G4HadronicInte 35 G4HadronicInteractionRegistry::~G4HadronicInteractionRegistry() 49 { 36 { 50 Clean(); << 37 for(G4int i=0; i<nModels; i++) 51 } << 38 { 52 << 39 delete allModels[i]; 53 void G4HadronicInteractionRegistry::Clean() << 54 { << 55 size_t nModels = allModels.size(); << 56 //G4cout << "G4HadronicInteractionRegistry:: << 57 // << " " << this << G4endl; << 58 for (size_t i=0; i<nModels; ++i) { << 59 if( allModels[i] ) { << 60 //const char* xxx = (allModels[i]->GetMo << 61 //G4int len = (allModels[i]->GetModelNam << 62 //len = std::min(len, 9); << 63 //const G4String mname = G4String(xxx, l << 64 //G4cout << "G4HadronicInteractionRegist << 65 // << allModels[i] << " " << mname << 66 // << " " << this << G4endl; << 67 //if(mname != "NeutronHP" && mname != "P << 68 delete allModels[i]; << 69 // G4cout << "done " << this << G4endl; << 70 } << 71 } << 72 allModels.clear(); << 73 //G4cout <<"G4HadronicInteractionRegistry::C << 74 } << 75 << 76 void G4HadronicInteractionRegistry::Initialise << 77 { << 78 for (auto & mod : allModels) { << 79 if( mod ) { mod->InitialiseModel(); } << 80 } << 81 } << 82 << 83 void << 84 G4HadronicInteractionRegistry::RegisterMe(G4Ha << 85 { << 86 if(!aModel) { return; } << 87 for (auto & mod : allModels) { << 88 if( aModel == mod ) { return; } << 89 } 40 } 90 //G4cout << "Register model <" << aModel->Ge << 91 // << "> " << nModels+1 << " " << aModel << 92 allModels.push_back(aModel); << 93 } 41 } 94 42 95 void << 43 void G4HadronicInteractionRegistry:: 96 G4HadronicInteractionRegistry::RemoveMe(G4Hadr << 44 AddModel(G4HadronicInteraction * aModel) 97 { << 45 { 98 if(!aModel) { return; } << 46 G4bool alreadyThere = false; 99 for (size_t i=0; i<allModels.size(); ++i) { << 47 for(G4int i=0; i<nModels; i++) 100 if( aModel == allModels[i] ) { << 48 { 101 //G4cout << "DeRegister model <" << aMod << 49 if(allModels[i]==aModel) 102 // << "> " << i << G4endl; << 50 { 103 allModels[i] = nullptr; << 51 alreadyThere = true; 104 return; << 52 break; 105 } 53 } 106 } 54 } 107 } << 55 if(!alreadyThere) 108 << 56 { 109 G4HadronicInteraction* << 57 nModels++; 110 G4HadronicInteractionRegistry::FindModel(const << 58 allModels.push_back(aModel); 111 { << 112 G4HadronicInteraction* model = nullptr; << 113 for (auto & mod : allModels) { << 114 if(mod && mod->GetModelName() == name) { << 115 model = mod; << 116 break; << 117 } << 118 } << 119 return model; << 120 } << 121 << 122 std::vector<G4HadronicInteraction*> << 123 G4HadronicInteractionRegistry::FindAllModels(c << 124 { << 125 std::vector<G4HadronicInteraction*> models; << 126 for (auto & mod : allModels) { << 127 if(mod && mod->GetModelName() == name) { << 128 models.push_back(mod); << 129 } << 130 } 59 } 131 return models; << 132 } 60 } 133 61