[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 | // $Id: HistoMessenger.cc,v 1.3 2007/11/13 14:13:31 maire Exp $ |
---|
[1337] | 27 | // GEANT4 tag $Name: geant4-09-04-beta-01 $ |
---|
[807] | 28 | // |
---|
| 29 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... |
---|
| 30 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... |
---|
| 31 | |
---|
| 32 | #include "HistoMessenger.hh" |
---|
| 33 | |
---|
| 34 | #include <sstream> |
---|
| 35 | |
---|
| 36 | #include "HistoManager.hh" |
---|
| 37 | #include "G4UIdirectory.hh" |
---|
| 38 | #include "G4UIcommand.hh" |
---|
| 39 | #include "G4UIparameter.hh" |
---|
| 40 | #include "G4UIcmdWithAString.hh" |
---|
| 41 | #include "G4UIcmdWithAnInteger.hh" |
---|
| 42 | |
---|
| 43 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... |
---|
| 44 | |
---|
| 45 | HistoMessenger::HistoMessenger(HistoManager* manager) |
---|
| 46 | :histoManager (manager) |
---|
| 47 | { |
---|
| 48 | histoDir = new G4UIdirectory("/testem/histo/"); |
---|
| 49 | histoDir->SetGuidance("histograms control"); |
---|
| 50 | |
---|
| 51 | factoryCmd = new G4UIcmdWithAString("/testem/histo/setFileName",this); |
---|
| 52 | factoryCmd->SetGuidance("set name for the histograms file"); |
---|
| 53 | |
---|
| 54 | typeCmd = new G4UIcmdWithAString("/testem/histo/setFileType",this); |
---|
| 55 | typeCmd->SetGuidance("set histograms file type: hbook, root, XML"); |
---|
| 56 | typeCmd->SetCandidates("hbook root XML"); |
---|
| 57 | |
---|
| 58 | optionCmd = new G4UIcmdWithAString("/testem/histo/setFileOption",this); |
---|
| 59 | optionCmd->SetGuidance("set option for the histograms file"); |
---|
| 60 | |
---|
| 61 | histoCmd = new G4UIcommand("/testem/histo/setHisto",this); |
---|
| 62 | histoCmd->SetGuidance("Set bining of the histo number ih :"); |
---|
| 63 | histoCmd->SetGuidance(" nbBins; valMin; valMax; unit (of vmin and vmax)"); |
---|
| 64 | // |
---|
| 65 | G4UIparameter* ih = new G4UIparameter("ih",'i',false); |
---|
| 66 | ih->SetGuidance("histo number : from 1 to MaxHisto"); |
---|
| 67 | ih->SetParameterRange("ih>0"); |
---|
| 68 | histoCmd->SetParameter(ih); |
---|
| 69 | // |
---|
| 70 | G4UIparameter* nbBins = new G4UIparameter("nbBins",'i',false); |
---|
| 71 | nbBins->SetGuidance("number of bins"); |
---|
| 72 | nbBins->SetParameterRange("nbBins>0"); |
---|
| 73 | histoCmd->SetParameter(nbBins); |
---|
| 74 | // |
---|
| 75 | G4UIparameter* valMin = new G4UIparameter("valMin",'d',false); |
---|
| 76 | valMin->SetGuidance("valMin, expressed in unit"); |
---|
| 77 | histoCmd->SetParameter(valMin); |
---|
| 78 | // |
---|
| 79 | G4UIparameter* valMax = new G4UIparameter("valMax",'d',false); |
---|
| 80 | valMax->SetGuidance("valMax, expressed in unit"); |
---|
| 81 | histoCmd->SetParameter(valMax); |
---|
| 82 | // |
---|
| 83 | G4UIparameter* unit = new G4UIparameter("unit",'s',true); |
---|
| 84 | unit->SetGuidance("if omitted, vmin and vmax are assumed dimensionless"); |
---|
| 85 | unit->SetDefaultValue("none"); |
---|
| 86 | histoCmd->SetParameter(unit); |
---|
| 87 | |
---|
| 88 | prhistoCmd = new G4UIcmdWithAnInteger("/testem/histo/printHisto",this); |
---|
| 89 | prhistoCmd->SetGuidance("print histo #id on ascii file"); |
---|
| 90 | prhistoCmd->SetParameterName("id",false); |
---|
| 91 | prhistoCmd->SetRange("id>0"); |
---|
| 92 | |
---|
| 93 | rmhistoCmd = new G4UIcmdWithAnInteger("/testem/histo/removeHisto",this); |
---|
| 94 | rmhistoCmd->SetGuidance("desactivate histo #id"); |
---|
| 95 | rmhistoCmd->SetParameterName("id",false); |
---|
| 96 | rmhistoCmd->SetRange("id>0"); |
---|
| 97 | } |
---|
| 98 | |
---|
| 99 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... |
---|
| 100 | |
---|
| 101 | HistoMessenger::~HistoMessenger() |
---|
| 102 | { |
---|
| 103 | delete rmhistoCmd; |
---|
| 104 | delete prhistoCmd; |
---|
| 105 | delete histoCmd; |
---|
| 106 | delete optionCmd; |
---|
| 107 | delete typeCmd; |
---|
| 108 | delete factoryCmd; |
---|
| 109 | delete histoDir; |
---|
| 110 | } |
---|
| 111 | |
---|
| 112 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... |
---|
| 113 | |
---|
| 114 | void HistoMessenger::SetNewValue(G4UIcommand* command, G4String newValues) |
---|
| 115 | { |
---|
| 116 | if (command == factoryCmd) |
---|
| 117 | histoManager->SetFileName(newValues); |
---|
| 118 | |
---|
| 119 | if (command == typeCmd) |
---|
| 120 | histoManager->SetFileType(newValues); |
---|
| 121 | |
---|
| 122 | if (command == optionCmd) |
---|
| 123 | histoManager->SetFileOption(newValues); |
---|
| 124 | |
---|
| 125 | if (command == histoCmd) |
---|
| 126 | { G4int ih,nbBins; G4double vmin,vmax; char unts[30]; |
---|
| 127 | const char* t = newValues; |
---|
| 128 | std::istringstream is(t); |
---|
| 129 | is >> ih >> nbBins >> vmin >> vmax >> unts; |
---|
| 130 | G4String unit = unts; |
---|
| 131 | G4double vUnit = 1. ; |
---|
| 132 | if (unit != "none") vUnit = G4UIcommand::ValueOf(unit); |
---|
| 133 | histoManager->SetHisto (ih,nbBins,vmin*vUnit,vmax*vUnit,unit); |
---|
| 134 | } |
---|
| 135 | |
---|
| 136 | if (command == prhistoCmd) |
---|
| 137 | histoManager->PrintHisto(prhistoCmd->GetNewIntValue(newValues)); |
---|
| 138 | |
---|
| 139 | if (command == rmhistoCmd) |
---|
| 140 | histoManager->RemoveHisto(rmhistoCmd->GetNewIntValue(newValues)); |
---|
| 141 | } |
---|
| 142 | |
---|
| 143 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... |
---|
| 144 | |
---|