[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: RadmonMessenger.cc |
---|
| 28 | // Creation date: Sep 2005 |
---|
| 29 | // Main author: Riccardo Capra <capra@ge.infn.it> |
---|
| 30 | // |
---|
| 31 | // Id: $Id: RadmonMessenger.cc,v 1.3 2006/06/29 16:14:47 gunter Exp $ |
---|
| 32 | // Tag: $Name: $ |
---|
| 33 | // |
---|
| 34 | |
---|
| 35 | // Include files |
---|
| 36 | #include "RadmonMessenger.hh" |
---|
| 37 | #include "RadmonTokenizer.hh" |
---|
| 38 | #include "G4UnitsTable.hh" |
---|
| 39 | #include "G4String.hh" |
---|
| 40 | |
---|
| 41 | #include <fstream> |
---|
| 42 | |
---|
| 43 | G4bool RadmonMessenger :: ProcessArguments(const G4String & rawArguments, G4int nArgs, G4String * arguments) |
---|
| 44 | { |
---|
| 45 | RadmonTokenizer args(rawArguments); |
---|
| 46 | |
---|
| 47 | for (G4int i(0); i<nArgs; i++) |
---|
| 48 | { |
---|
| 49 | if (args.eos()) |
---|
| 50 | { |
---|
| 51 | G4cout << "RadmonMessenger::ProcessArguments: " << (nArgs-i) << " arguments missing." << G4endl; |
---|
| 52 | return false; |
---|
| 53 | } |
---|
| 54 | |
---|
| 55 | arguments[i]=args(); |
---|
| 56 | } |
---|
| 57 | |
---|
| 58 | if (!args.eos()) |
---|
| 59 | { |
---|
| 60 | G4cout << "RadmonMessenger::ProcessArguments: Unexpected arguments after \"" << arguments[nArgs-1] << "\"." << G4endl; |
---|
| 61 | return false; |
---|
| 62 | } |
---|
| 63 | |
---|
| 64 | return true; |
---|
| 65 | } |
---|
| 66 | |
---|
| 67 | |
---|
| 68 | |
---|
| 69 | G4double RadmonMessenger :: GetUnit(const G4String & unitStr, const char * category) |
---|
| 70 | { |
---|
| 71 | G4double dbl(G4UnitDefinition::GetValueOf(unitStr)); |
---|
| 72 | |
---|
| 73 | if (dbl<=0.) |
---|
| 74 | { |
---|
| 75 | G4cout << "RadmonMessenger::GetUnit(): Unknown unit of measure \"" << unitStr << "\"." << G4endl; |
---|
| 76 | return -1.; |
---|
| 77 | } |
---|
| 78 | |
---|
| 79 | if (G4UnitDefinition::GetCategory(unitStr)!=category) |
---|
| 80 | { |
---|
| 81 | G4cout << "RadmonMessenger::GetUnit(): Unit of measure \"" << unitStr << "\" is not a " << category << '.' << G4endl; |
---|
| 82 | return -1.; |
---|
| 83 | } |
---|
| 84 | |
---|
| 85 | return dbl; |
---|
| 86 | } |
---|
| 87 | |
---|
| 88 | |
---|
| 89 | |
---|
| 90 | |
---|
| 91 | |
---|
| 92 | RadmonMessenger :: RadmonMessenger(const char * path, const char * guidance) |
---|
| 93 | { |
---|
| 94 | directory=new G4UIdirectory(path); |
---|
| 95 | |
---|
| 96 | if (directory==0) |
---|
| 97 | { |
---|
| 98 | G4String text("RadmonMaterialsMessenger::RadmonMaterialsMessenger: \""); |
---|
| 99 | text+=path; |
---|
| 100 | text+="\" directory not allocated."; |
---|
| 101 | |
---|
| 102 | G4Exception(text); |
---|
| 103 | |
---|
| 104 | return; |
---|
| 105 | } |
---|
| 106 | |
---|
| 107 | if (guidance) |
---|
| 108 | directory->SetGuidance(guidance); |
---|
| 109 | } |
---|
| 110 | |
---|
| 111 | |
---|
| 112 | |
---|
| 113 | |
---|
| 114 | |
---|
| 115 | std::istream * RadmonMessenger :: OpenForInput(const G4String & fileName) const |
---|
| 116 | { |
---|
| 117 | std::ifstream * in(new std::ifstream(fileName.data())); |
---|
| 118 | |
---|
| 119 | if (!in) |
---|
| 120 | { |
---|
| 121 | G4cout << "RadmonMessenger::OpenForInput(): Cannot allocate class std::ifstream." << G4endl; |
---|
| 122 | return 0; |
---|
| 123 | } |
---|
| 124 | |
---|
| 125 | if (!in->good()) |
---|
| 126 | { |
---|
| 127 | G4cout << "RadmonMessenger::OpenForInput(): Cannot access to file \"" << fileName << "\" for read." << G4endl; |
---|
| 128 | delete in; |
---|
| 129 | return 0; |
---|
| 130 | } |
---|
| 131 | |
---|
| 132 | return in; |
---|
| 133 | } |
---|
| 134 | |
---|
| 135 | |
---|
| 136 | |
---|
| 137 | std::ostream * RadmonMessenger :: OpenForOutput(const G4String & fileName) const |
---|
| 138 | { |
---|
| 139 | std::ofstream * out(new std::ofstream(fileName.data())); |
---|
| 140 | |
---|
| 141 | if (!out) |
---|
| 142 | { |
---|
| 143 | G4cout << "RadmonMessenger::OpenForOutput(): Cannot allocate class std::ofstream." << G4endl; |
---|
| 144 | return 0; |
---|
| 145 | } |
---|
| 146 | |
---|
| 147 | if (!out->good()) |
---|
| 148 | { |
---|
| 149 | G4cout << "RadmonMessenger::OpenForOutput(): Cannot access to file \"" << fileName << "\" for write." << G4endl; |
---|
| 150 | delete out; |
---|
| 151 | return 0; |
---|
| 152 | } |
---|
| 153 | |
---|
| 154 | return out; |
---|
| 155 | } |
---|