[807] | 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 | // File name: RadmonGeneratorMessenger.cc |
---|
| 28 | // Creation date: Oct 2005 |
---|
| 29 | // Main author: Riccardo Capra <capra@ge.infn.it> |
---|
| 30 | // |
---|
| 31 | // Id: $Id: RadmonGeneratorMessenger.cc,v 1.3 2006/06/29 16:16:27 gunter Exp $ |
---|
| 32 | // Tag: $Name: $ |
---|
| 33 | // |
---|
| 34 | |
---|
| 35 | // Messenger commands path |
---|
| 36 | #define COMMANDS_PATH "/radmon/generator/" |
---|
| 37 | |
---|
| 38 | // Include files |
---|
| 39 | #include "RadmonGeneratorMessenger.hh" |
---|
| 40 | #include "RadmonVGeneratorLayout.hh" |
---|
| 41 | |
---|
| 42 | |
---|
| 43 | |
---|
| 44 | RadmonGeneratorMessenger :: RadmonGeneratorMessenger(RadmonVGeneratorLayout * layout) |
---|
| 45 | : |
---|
| 46 | RadmonMessenger(COMMANDS_PATH, "Interactive beam generation commands."), |
---|
| 47 | generatorLayout(layout), |
---|
| 48 | RADMON_INITIALIZE_COMMAND(InsertSource), |
---|
| 49 | RADMON_INITIALIZE_COMMAND(SetRelativeSourceIntensity), |
---|
| 50 | RADMON_INITIALIZE_COMMAND(RemoveSource), |
---|
| 51 | RADMON_INITIALIZE_COMMAND(AppendSourceAlgorithm), |
---|
| 52 | RADMON_INITIALIZE_COMMAND(SetSourceAlgorithmType), |
---|
| 53 | RADMON_INITIALIZE_COMMAND(RemoveSourceAlgorithm), |
---|
| 54 | RADMON_INITIALIZE_COMMAND(SetSourceAlgorithmAttribute), |
---|
| 55 | RADMON_INITIALIZE_COMMAND(ClearSourceAlgorithmAttribute), |
---|
| 56 | RADMON_INITIALIZE_COMMAND(Load), |
---|
| 57 | RADMON_INITIALIZE_COMMAND(Save), |
---|
| 58 | RADMON_INITIALIZE_COMMAND(DumpLayout) |
---|
| 59 | { |
---|
| 60 | if (layout==0) |
---|
| 61 | G4Exception("RadmonGeneratorMessenger::RadmonGeneratorMessenger: layout==0."); |
---|
| 62 | |
---|
| 63 | RADMON_CREATE_COMMAND_1ARG (InsertSource, "Inserts a new source", "sourcename"); |
---|
| 64 | RADMON_CREATE_COMMAND_2ARGS(SetRelativeSourceIntensity, "Sets the relative intensity of the source", "sourcename", "intensity"); |
---|
| 65 | RADMON_CREATE_COMMAND_1ARG (RemoveSource, "Removes a source from the layout", "sourcename"); |
---|
| 66 | RADMON_CREATE_COMMAND_2ARGS(AppendSourceAlgorithm, "Appends an algorithm to a source", "sourcename", "algorithm"); |
---|
| 67 | RADMON_CREATE_COMMAND_3ARGS(SetSourceAlgorithmType, "Sets the algorithm type of an algorithm or a source", "sourcename", "algorithm", "typename"); |
---|
| 68 | RADMON_CREATE_COMMAND_2ARGS(RemoveSourceAlgorithm, "Removes an algorithm from a source", "sourcename", "algorithm"); |
---|
| 69 | RADMON_CREATE_COMMAND_4ARGS(SetSourceAlgorithmAttribute, "Sets an attribute of the algorithm of a source", "sourcename", "algorithm", "attributename", "value"); |
---|
| 70 | RADMON_CREATE_COMMAND_3ARGS(ClearSourceAlgorithmAttribute, "Removes an attribute from the algorithm of a source", "sourcename", "algorithm", "attributename"); |
---|
| 71 | RADMON_CREATE_COMMAND_1ARG (Load, "Loads a layout from file", "filename"); |
---|
| 72 | RADMON_CREATE_COMMAND_1ARG (Save, "Saves a layout to file", "filename"); |
---|
| 73 | RADMON_CREATE_COMMAND_0ARGS(DumpLayout, "Print out the current layout"); |
---|
| 74 | } |
---|
| 75 | |
---|
| 76 | |
---|
| 77 | |
---|
| 78 | RadmonGeneratorMessenger :: ~RadmonGeneratorMessenger() |
---|
| 79 | { |
---|
| 80 | RADMON_DESTROY_COMMAND(DumpLayout); |
---|
| 81 | RADMON_DESTROY_COMMAND(Save); |
---|
| 82 | RADMON_DESTROY_COMMAND(Load); |
---|
| 83 | RADMON_DESTROY_COMMAND(ClearSourceAlgorithmAttribute); |
---|
| 84 | RADMON_DESTROY_COMMAND(SetSourceAlgorithmAttribute); |
---|
| 85 | RADMON_DESTROY_COMMAND(RemoveSourceAlgorithm); |
---|
| 86 | RADMON_DESTROY_COMMAND(SetSourceAlgorithmType); |
---|
| 87 | RADMON_DESTROY_COMMAND(AppendSourceAlgorithm); |
---|
| 88 | RADMON_DESTROY_COMMAND(RemoveSource); |
---|
| 89 | RADMON_DESTROY_COMMAND(SetRelativeSourceIntensity); |
---|
| 90 | RADMON_DESTROY_COMMAND(InsertSource); |
---|
| 91 | } |
---|
| 92 | |
---|
| 93 | |
---|
| 94 | |
---|
| 95 | |
---|
| 96 | |
---|
| 97 | G4String RadmonGeneratorMessenger :: GetCurrentValue(G4UIcommand * /* command */) |
---|
| 98 | { |
---|
| 99 | G4cout << "RadmonGeneratorMessenger::GetCurrentValue(): Not supported" << G4endl; |
---|
| 100 | |
---|
| 101 | return G4String(); |
---|
| 102 | } |
---|
| 103 | |
---|
| 104 | |
---|
| 105 | |
---|
| 106 | void RadmonGeneratorMessenger :: SetNewValue(G4UIcommand * command, G4String newValue) |
---|
| 107 | { |
---|
| 108 | RADMON_BEGIN_LIST_SET_COMMANDS |
---|
| 109 | RADMON_SET_COMMAND(InsertSource) |
---|
| 110 | RADMON_SET_COMMAND(SetRelativeSourceIntensity) |
---|
| 111 | RADMON_SET_COMMAND(RemoveSource) |
---|
| 112 | RADMON_SET_COMMAND(AppendSourceAlgorithm) |
---|
| 113 | RADMON_SET_COMMAND(SetSourceAlgorithmType) |
---|
| 114 | RADMON_SET_COMMAND(RemoveSourceAlgorithm) |
---|
| 115 | RADMON_SET_COMMAND(SetSourceAlgorithmAttribute) |
---|
| 116 | RADMON_SET_COMMAND(ClearSourceAlgorithmAttribute) |
---|
| 117 | RADMON_SET_COMMAND(Load) |
---|
| 118 | RADMON_SET_COMMAND(Save) |
---|
| 119 | RADMON_SET_COMMAND(DumpLayout) |
---|
| 120 | RADMON_END_LIST_SET_COMMANDS |
---|
| 121 | } |
---|
| 122 | |
---|
| 123 | |
---|
| 124 | |
---|
| 125 | |
---|
| 126 | |
---|
| 127 | // Events |
---|
| 128 | void RadmonGeneratorMessenger :: OnInsertSource(const G4String & value) |
---|
| 129 | { |
---|
| 130 | G4String args[1]; |
---|
| 131 | |
---|
| 132 | if (!ProcessArguments(value, 1, args)) |
---|
| 133 | return; |
---|
| 134 | |
---|
| 135 | generatorLayout->InsertSource(args[0]); |
---|
| 136 | } |
---|
| 137 | |
---|
| 138 | |
---|
| 139 | |
---|
| 140 | void RadmonGeneratorMessenger :: OnSetRelativeSourceIntensity(const G4String & value) |
---|
| 141 | { |
---|
| 142 | G4String args[2]; |
---|
| 143 | |
---|
| 144 | if (!ProcessArguments(value, 2, args)) |
---|
| 145 | return; |
---|
| 146 | |
---|
| 147 | G4double intensity(G4UIcommand::ConvertToDouble(args[1])); |
---|
| 148 | |
---|
| 149 | if (intensity<=0.) |
---|
| 150 | { |
---|
| 151 | G4cout << "RadmonGeneratorMessenger::OnSetRelativeSourceIntensity(): insensitymust be greater than 0." << G4endl; |
---|
| 152 | return; |
---|
| 153 | } |
---|
| 154 | |
---|
| 155 | generatorLayout->SetRelativeSourceIntensity(args[0], intensity); |
---|
| 156 | } |
---|
| 157 | |
---|
| 158 | |
---|
| 159 | |
---|
| 160 | void RadmonGeneratorMessenger :: OnRemoveSource(const G4String & value) |
---|
| 161 | { |
---|
| 162 | G4String args[1]; |
---|
| 163 | |
---|
| 164 | if (!ProcessArguments(value, 1, args)) |
---|
| 165 | return; |
---|
| 166 | |
---|
| 167 | generatorLayout->RemoveSource(args[0]); |
---|
| 168 | } |
---|
| 169 | |
---|
| 170 | |
---|
| 171 | |
---|
| 172 | |
---|
| 173 | |
---|
| 174 | void RadmonGeneratorMessenger :: OnAppendSourceAlgorithm(const G4String & value) |
---|
| 175 | { |
---|
| 176 | G4String args[2]; |
---|
| 177 | |
---|
| 178 | if (!ProcessArguments(value, 2, args)) |
---|
| 179 | return; |
---|
| 180 | |
---|
| 181 | generatorLayout->AppendSourceAlgorithm(args[0], args[1]); |
---|
| 182 | } |
---|
| 183 | |
---|
| 184 | |
---|
| 185 | |
---|
| 186 | void RadmonGeneratorMessenger :: OnSetSourceAlgorithmType(const G4String & value) |
---|
| 187 | { |
---|
| 188 | G4String args[3]; |
---|
| 189 | |
---|
| 190 | if (!ProcessArguments(value, 3, args)) |
---|
| 191 | return; |
---|
| 192 | |
---|
| 193 | generatorLayout->SetSourceAlgorithmType(args[0], args[1], args[2]); |
---|
| 194 | } |
---|
| 195 | |
---|
| 196 | |
---|
| 197 | |
---|
| 198 | void RadmonGeneratorMessenger :: OnRemoveSourceAlgorithm(const G4String & value) |
---|
| 199 | { |
---|
| 200 | G4String args[2]; |
---|
| 201 | |
---|
| 202 | if (!ProcessArguments(value, 2, args)) |
---|
| 203 | return; |
---|
| 204 | |
---|
| 205 | generatorLayout->RemoveSourceAlgorithm(args[0], args[1]); |
---|
| 206 | } |
---|
| 207 | |
---|
| 208 | |
---|
| 209 | |
---|
| 210 | |
---|
| 211 | |
---|
| 212 | void RadmonGeneratorMessenger :: OnSetSourceAlgorithmAttribute(const G4String & value) |
---|
| 213 | { |
---|
| 214 | G4String args[4]; |
---|
| 215 | |
---|
| 216 | if (!ProcessArguments(value, 4, args)) |
---|
| 217 | return; |
---|
| 218 | |
---|
| 219 | generatorLayout->SetSourceAlgorithmAttribute(args[0], args[1], args[2], args[3]); |
---|
| 220 | } |
---|
| 221 | |
---|
| 222 | |
---|
| 223 | |
---|
| 224 | void RadmonGeneratorMessenger :: OnClearSourceAlgorithmAttribute(const G4String & value) |
---|
| 225 | { |
---|
| 226 | G4String args[3]; |
---|
| 227 | |
---|
| 228 | if (!ProcessArguments(value, 3, args)) |
---|
| 229 | return; |
---|
| 230 | |
---|
| 231 | generatorLayout->ClearSourceAlgorithmAttribute(args[0], args[1], args[2]); |
---|
| 232 | } |
---|
| 233 | |
---|
| 234 | |
---|
| 235 | |
---|
| 236 | |
---|
| 237 | |
---|
| 238 | void RadmonGeneratorMessenger :: OnLoad(const G4String & value) |
---|
| 239 | { |
---|
| 240 | G4String args[1]; |
---|
| 241 | |
---|
| 242 | if (!ProcessArguments(value, 1, args)) |
---|
| 243 | return; |
---|
| 244 | |
---|
| 245 | std::istream * in(OpenForInput(args[0])); |
---|
| 246 | |
---|
| 247 | if (!in) |
---|
| 248 | return; |
---|
| 249 | |
---|
| 250 | if (!generatorLayout->Load(*in)) |
---|
| 251 | G4cout << "RadmonGeneratorMessenger::OnLoad(): Error reading from file \"" << args[0] << "\"." << G4endl; |
---|
| 252 | |
---|
| 253 | delete in; |
---|
| 254 | } |
---|
| 255 | |
---|
| 256 | |
---|
| 257 | |
---|
| 258 | void RadmonGeneratorMessenger :: OnSave(const G4String & value) |
---|
| 259 | { |
---|
| 260 | G4String args[1]; |
---|
| 261 | |
---|
| 262 | if (!ProcessArguments(value, 1, args)) |
---|
| 263 | return; |
---|
| 264 | |
---|
| 265 | std::ostream * out(OpenForOutput(args[0])); |
---|
| 266 | |
---|
| 267 | if (!out) |
---|
| 268 | return; |
---|
| 269 | |
---|
| 270 | if (!generatorLayout->Save(*out)) |
---|
| 271 | G4cout << "RadmonGeneratorMessenger::OnSave(): Cannot write layout into file \"" << args[0] << "\"." << G4endl; |
---|
| 272 | |
---|
| 273 | delete out; |
---|
| 274 | } |
---|
| 275 | |
---|
| 276 | |
---|
| 277 | |
---|
| 278 | void RadmonGeneratorMessenger :: OnDumpLayout(const G4String & /* value */) |
---|
| 279 | { |
---|
| 280 | generatorLayout->DumpLayout(G4cout); |
---|
| 281 | G4cout << G4endl; |
---|
| 282 | } |
---|