EGSnrc C++ class library  Report PIRS-898 (2021)
Iwan Kawrakow, Ernesto Mainegra-Hing, Frederic Tessier, Reid Townson and Blake Walters
egs_transformed_source.cpp
Go to the documentation of this file.
1 /*
2 ###############################################################################
3 #
4 # EGSnrc egs++ transformed 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: Hannah Gallop
27 #
28 ###############################################################################
29 */
30 
31 
37 #include "egs_transformed_source.h"
38 #include "egs_input.h"
39 
40 static bool EGS_TRANSFORMED_SOURCE_LOCAL inputSet = false;
41 
43  EGS_ObjectFactory *f) : EGS_BaseSource(input,f), source(0), T(0) {
44  EGS_Input *isource = input->takeInputItem("source",false);
45  if (isource) {
47  delete isource;
48  }
49  if (!source) {
50  string sname;
51  int err = input->getInput("source name",sname);
52  if (err)
53  egsWarning("EGS_TransformedSource: missing/wrong inline source "
54  "definition and missing wrong 'source name' input\n");
55  else {
57  if (!source) egsWarning("EGS_TransformedSource: a source named %s"
58  " does not exist\n");
59  }
60  }
62  setUp(t);
63  delete t;
64 }
65 
66 void EGS_TransformedSource::setUp(EGS_AffineTransform *t) {
67  setTransformation(t);
68  otype = "EGS_TransformedSource";
69  if (!isValid()) {
70  description = "Invalid transformed source";
71  }
72  else {
73  description = "Transformed ";
75  source->ref();
76  }
77 }
78 
79 extern "C" {
80 
81  static void setInputs() {
82  inputSet = true;
83 
84  setBaseSourceInputs(false, false);
85 
86  srcBlockInput->getSingleInput("library")->setValues({"egs_transformed_source"});
87 
88  // Format: name, isRequired, description, vector string of allowed values
89  srcBlockInput->addSingleInput("source name", true, "The name of a previously defined source.");
90 
91  addTransformationBlock(srcBlockInput);
92  }
93 
94  EGS_TRANSFORMED_SOURCE_EXPORT string getExample() {
95  string example;
96  example = {
97  R"(
98  # Example of egs_transformed_source
99  #:start source:
100  library = egs_transformed_source
101  name = my_source
102  source name = my_parallel_source
103  #create source called my_parallel_source
104  :start transformation:
105  rotation vector = 0 -1 1
106  :stop transformation:
107  :stop source:
108 )"};
109  return example;
110  }
111 
112  EGS_TRANSFORMED_SOURCE_EXPORT shared_ptr<EGS_BlockInput> getInputs() {
113  if(!inputSet) {
114  setInputs();
115  }
116  return srcBlockInput;
117  }
118 
119  EGS_TRANSFORMED_SOURCE_EXPORT EGS_BaseSource *createSource(EGS_Input *input,
120  EGS_ObjectFactory *f) {
121  return
122  createSourceTemplate<EGS_TransformedSource>(input,f,"transformed source");
123  }
124 
125 }
A class providing affine transformations.
static EGS_AffineTransform * getTransformation(EGS_Input *inp)
Constructs an affine transformation object from the input pointed to by inp and returns a pointer to ...
Base source class. All particle sources must be derived from this class.
const char * getSourceDescription() const
Get a short description of this source.
static EGS_BaseSource * getSource(const string &Name)
Get a pointer to the source named Name.
string description
A short source description.
static EGS_BaseSource * createSource(EGS_Input *)
Create sources from the information pointed to by input.
A class for storing information in a tree-like structure of key-value pairs. This class is used throu...
Definition: egs_input.h:182
EGS_Input * takeInputItem(const string &key, bool self=true)
Get the property named key.
Definition: egs_input.cpp:229
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:341
An object factory.
int ref()
Increase the reference count to this object.
string otype
The object type.
EGS_BaseSource * source
The source being transformed.
EGS_TransformedSource(EGS_BaseSource *Source, EGS_AffineTransform *t, const string &Name="", EGS_ObjectFactory *f=0)
Construct a transformed source using Source as the source and t as the transformation.
EGS_Input class header file.
A transformed source.
EGS_InfoFunction EGS_EXPORT egsWarning
Always use this function for reporting warnings.