EGSnrc C++ class library  Report PIRS-898 (2021)
Iwan Kawrakow, Ernesto Mainegra-Hing, Frederic Tessier, Reid Townson and Blake Walters
egs_base_source.cpp
Go to the documentation of this file.
1 /*
2 ###############################################################################
3 #
4 # EGSnrc egs++ base source
5 # Copyright (C) 2015 National Research Council Canada
6 #
7 # This file is part of EGSnrc.
8 #
9 # EGSnrc is free software: you can redistribute it and/or modify it under
10 # the terms of the GNU Affero General Public License as published by the
11 # Free Software Foundation, either version 3 of the License, or (at your
12 # option) any later version.
13 #
14 # EGSnrc is distributed in the hope that it will be useful, but WITHOUT ANY
15 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16 # FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
17 # more details.
18 #
19 # You should have received a copy of the GNU Affero General Public License
20 # along with EGSnrc. If not, see <http://www.gnu.org/licenses/>.
21 #
22 ###############################################################################
23 #
24 # Author: Iwan Kawrakow, 2005
25 #
26 # Contributors:
27 #
28 ###############################################################################
29 */
30 
31 
40 #include "egs_base_source.h"
41 #include "egs_input.h"
42 
44  EGS_ObjectFactory *f) : EGS_BaseSource(input,f), q(0), s(0), count(0) {
45  int Q;
46  int err = input->getInput("charge",Q);
47  if (!err) {
48  q = Q;
49  }
51  if (!s) egsWarning("EGS_BaseSimpleSource::EGS_BaseSimpleSource:\n"
52  " no spectrum was defined\n");
53 }
54 
56 source_creator(string("egs++/dso/")+CONFIG_NAME,"EGS_BaseSource");
57 
59  //EGS_Object *o = source_creator.createSingleObject(i,"createSource",true);
60  EGS_Object *o = source_creator.createObjects(i,"source definition",
61  "source","simulation source","createSource",true);
62  return dynamic_cast<EGS_BaseSource *>(o);
63 }
64 
66  EGS_Object *o = source_creator.getObject(Name);
67  if (!o) {
68  return 0;
69  }
70  EGS_BaseSource *s = dynamic_cast<EGS_BaseSource *>(o);
71  if (s) {
72  return s;
73  }
74  egsWarning("EGS_BaseSource::getSource(): dynamic cast failed?\n"
75  " Object named %s is of type %s. Trying simple cast\n",
76  Name.c_str(),o->getObjectType().c_str());
77  return (EGS_BaseSource *)o;
78 }
79 
81  if (o) egsInformation("Adding known source of type %s\n",
82  o->getObjectType().c_str());
83  source_creator.addKnownObject(o);
84 }
85 
86 void EGS_BaseSource::addKnownTypeId(const char *tid) {
87  source_creator.addKnownTypeId(tid);
88 }
Base egspp object.
static EGS_BaseSource * createSource(EGS_Input *)
Create sources from the information pointed to by input.
EGS_BaseSimpleSource(int Q, EGS_BaseSpectrum *Spec, const string &Name="", EGS_ObjectFactory *f=0)
Constructor.
EGS_BaseSource class header file.
static void addKnownSource(EGS_BaseSource *o)
Add a known source object to the source factory.
EGS_Input class header file.
A typed object factory.
static EGS_BaseSpectrum * createSpectrum(EGS_Input *inp)
Create and return a pointer to a spectrum object from the information pointed to by inp...
EGS_BaseSpectrum * s
The energy spectrum of this source.
EGS_InfoFunction EGS_EXPORT egsInformation
Always use this function for reporting the progress of a simulation and any other type of information...
An object factory.
static EGS_BaseSource * getSource(const string &Name)
Get a pointer to the source named Name.
int q
The charge of this simple source.
const string & getObjectType() const
Get the object type.
A class for storing information in a tree-like structure of key-value pairs. This class is used throu...
Definition: egs_input.h:182
static void addKnownTypeId(const char *name)
Add a known source object typeid to the source factory.
int getInput(const string &key, vector< string > &values) const
Assign values to an array of strings from an input identified by key.
Definition: egs_input.cpp:338
Base source class. All particle sources must be derived from this class.
EGS_InfoFunction EGS_EXPORT egsWarning
Always use this function for reporting warnings.