G4CrossSectionDataSetRegistry.cc

Go to the documentation of this file.
00001 //
00002 // ********************************************************************
00003 // * License and Disclaimer                                           *
00004 // *                                                                  *
00005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
00006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
00007 // * conditions of the Geant4 Software License,  included in the file *
00008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
00009 // * include a list of copyright holders.                             *
00010 // *                                                                  *
00011 // * Neither the authors of this software system, nor their employing *
00012 // * institutes,nor the agencies providing financial support for this *
00013 // * work  make  any representation or  warranty, express or implied, *
00014 // * regarding  this  software system or assume any liability for its *
00015 // * use.  Please see the license in the file  LICENSE  and URL above *
00016 // * for the full disclaimer and the limitation of liability.         *
00017 // *                                                                  *
00018 // * This  code  implementation is the result of  the  scientific and *
00019 // * technical work of the GEANT4 collaboration.                      *
00020 // * By using,  copying,  modifying or  distributing the software (or *
00021 // * any work based  on the software)  you  agree  to acknowledge its *
00022 // * use  in  resulting  scientific  publications,  and indicate your *
00023 // * acceptance of all terms of the Geant4 Software license.          *
00024 // ********************************************************************
00025 //
00026 //
00027 // $Id$
00028 //
00029 // -------------------------------------------------------------------
00030 //
00031 // GEANT4 Class file
00032 //
00033 //
00034 // File name:    G4CrossSectionDataSetRegistry
00035 //
00036 // Author  V.Ivanchenko  24.01.2009
00037 //
00038 // Modifications:
00039 //
00040 
00041 #include "G4ios.hh"
00042 
00043 #include "G4CrossSectionDataSetRegistry.hh"
00044 #include "G4VCrossSectionDataSet.hh"
00045 #include "G4CrossSectionFactory.hh"
00046 
00047 // Neeed for running with 'static' libraries to pull the references of the 
00048 // declared factories
00049 G4_REFERENCE_XS_FACTORY(G4ChipsKaonMinusInelasticXS);
00050 G4_REFERENCE_XS_FACTORY(G4ChipsKaonMinusElasticXS);
00051 G4_REFERENCE_XS_FACTORY(G4ChipsKaonPlusInelasticXS);
00052 G4_REFERENCE_XS_FACTORY(G4ChipsKaonPlusElasticXS);
00053 G4_REFERENCE_XS_FACTORY(G4ChipsKaonZeroInelasticXS);
00054 G4_REFERENCE_XS_FACTORY(G4ChipsKaonZeroElasticXS);
00055 G4_REFERENCE_XS_FACTORY(G4ChipsHyperonInelasticXS);
00056 G4_REFERENCE_XS_FACTORY(G4ChipsHyperonElasticXS);
00057 G4_REFERENCE_XS_FACTORY(G4ChipsProtonInelasticXS);
00058 G4_REFERENCE_XS_FACTORY(G4ChipsProtonElasticXS);
00059 G4_REFERENCE_XS_FACTORY(G4ChipsNeutronInelasticXS);
00060 G4_REFERENCE_XS_FACTORY(G4ChipsNeutronElasticXS);
00061 G4_REFERENCE_XS_FACTORY(G4ChipsPionPlusInelasticXS);
00062 G4_REFERENCE_XS_FACTORY(G4ChipsPionPlusElasticXS);
00063 G4_REFERENCE_XS_FACTORY(G4ChipsPionMinusInelasticXS);
00064 G4_REFERENCE_XS_FACTORY(G4ChipsPionMinusElasticXS);
00065 G4_REFERENCE_XS_FACTORY(G4ChipsAntiBaryonInelasticXS);
00066 G4_REFERENCE_XS_FACTORY(G4ChipsAntiBaryonElasticXS);
00067 G4_REFERENCE_XS_FACTORY(G4NucleonNuclearCrossSection);
00068 G4_REFERENCE_XS_FACTORY(G4GlauberGribovCrossSection);
00069 G4_REFERENCE_XS_FACTORY(G4GGNuclNuclCrossSection);
00070 
00071 
00072 G4CrossSectionDataSetRegistry* G4CrossSectionDataSetRegistry::theInstance = 0;
00073 
00074 G4CrossSectionDataSetRegistry* G4CrossSectionDataSetRegistry::Instance()
00075 {
00076   if(0 == theInstance) {
00077     static G4CrossSectionDataSetRegistry manager;
00078     theInstance = &manager;
00079   }
00080   return theInstance;
00081 }
00082 
00083 G4CrossSectionDataSetRegistry::G4CrossSectionDataSetRegistry()
00084 {}
00085 
00086 G4CrossSectionDataSetRegistry::~G4CrossSectionDataSetRegistry()
00087 {
00088   Clean();
00089 }
00090 
00091 void G4CrossSectionDataSetRegistry::Clean()
00092 {
00093   size_t n = xSections.size(); 
00094   if(n > 0) {
00095     for (size_t i=0; i<n; ++i) {
00096       if(xSections[i]) {
00097         G4VCrossSectionDataSet* p = xSections[i];
00098         xSections[i] = 0;
00099         delete p;
00100       }
00101     }
00102     xSections.clear();
00103   }
00104 }
00105 
00106 void G4CrossSectionDataSetRegistry::Register(G4VCrossSectionDataSet* p)
00107 {
00108   if(!p) return;
00109   size_t n = xSections.size(); 
00110   if(n > 0) {
00111     for (size_t i=0; i<n; ++i) {
00112       if(xSections[i] == p) { return; }
00113     }
00114   }
00115   xSections.push_back(p);
00116 }
00117 
00118 void G4CrossSectionDataSetRegistry::DeRegister(G4VCrossSectionDataSet* p)
00119 {
00120   if(!p) return;
00121   size_t n = xSections.size(); 
00122   if(n > 0) {
00123     for (size_t i=0; i<n; ++i) {
00124       if(xSections[i] == p) {
00125         xSections[i] = 0;
00126         return;
00127       }
00128     }
00129   }
00130 }
00131 
00132 void G4CrossSectionDataSetRegistry::AddFactory(G4String name, G4VBaseXSFactory* factory)
00133 {
00134   factories[name] = factory;
00135 }
00136 
00137 G4VCrossSectionDataSet* G4CrossSectionDataSetRegistry::GetCrossSectionDataSet(const G4String& name, G4bool warning)
00138 {
00139   size_t n = xSections.size(); 
00140  
00141   for (size_t i=0; i<n; ++i) 
00142     {
00143       if(xSections[i]) 
00144         {
00145           G4VCrossSectionDataSet* p = xSections[i];
00146           if (p->GetName() == name) return p;
00147         }
00148     }
00149   // check if factory exists...
00150   //
00151   if (factories.find(name)!=factories.end())
00152     {
00153       return factories[name]->Instantiate();
00154     }
00155   else
00156     {
00157         if(warning)
00158         {
00159          G4ExceptionDescription ED;
00160          ED << "Factory for ["<< name << "] cross section data set not found." << G4endl;
00161          G4Exception("G4CrossSectionDataSetRegistry::GetCrossSectionDataSet", "CrossSection001", FatalException, ED);
00162         }
00163       return 0;
00164     }
00165 }

Generated on Mon May 27 17:47:58 2013 for Geant4 by  doxygen 1.4.7