[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 | // $Id: HistoMessenger.cc,v 1.5 2006/06/29 17:24:18 gunter Exp $ |
---|
| 28 | // GEANT4 tag $Name: $ |
---|
| 29 | // |
---|
| 30 | ///////////////////////////////////////////////////////////////////////// |
---|
| 31 | // |
---|
| 32 | // HistoMessenger |
---|
| 33 | // |
---|
| 34 | // Created: 31.01.2003 V.Ivanchenko |
---|
| 35 | // |
---|
| 36 | // Modified: |
---|
| 37 | // 04.06.2006 Adoptation of hadr01 (V.Ivanchenko) |
---|
| 38 | // |
---|
| 39 | //////////////////////////////////////////////////////////////////////// |
---|
| 40 | // |
---|
| 41 | |
---|
| 42 | #include "HistoMessenger.hh" |
---|
| 43 | |
---|
| 44 | #include "Histo.hh" |
---|
| 45 | #include "G4UIdirectory.hh" |
---|
| 46 | #include "G4UIcommand.hh" |
---|
| 47 | #include "G4UIparameter.hh" |
---|
| 48 | #include "G4UIcmdWithAString.hh" |
---|
| 49 | #include "G4UIcmdWithAnInteger.hh" |
---|
| 50 | #include <sstream> |
---|
| 51 | |
---|
| 52 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... |
---|
| 53 | |
---|
| 54 | HistoMessenger::HistoMessenger(Histo* man) : histo (man) |
---|
| 55 | { |
---|
| 56 | |
---|
| 57 | factoryCmd = new G4UIcmdWithAString("/testhadr/HistoName",this); |
---|
| 58 | factoryCmd->SetGuidance("set name for the histograms file"); |
---|
| 59 | |
---|
| 60 | fileCmd = new G4UIcmdWithAString("/testhadr/HistoType",this); |
---|
| 61 | fileCmd->SetGuidance("set type (hbook, root, aida) for the histograms file"); |
---|
| 62 | fileCmd->SetCandidates("hbook root aida"); |
---|
| 63 | |
---|
| 64 | optCmd = new G4UIcmdWithAString("/testhadr/HistoOption",this); |
---|
| 65 | optCmd->SetGuidance("set AIDA option for the histograms file"); |
---|
| 66 | |
---|
| 67 | printCmd = new G4UIcmdWithAnInteger("/testhadr/HistoPrint",this); |
---|
| 68 | printCmd->SetGuidance("Print histogram by ID, if ID=0 - all."); |
---|
| 69 | printCmd->SetParameterName("pr",false); |
---|
| 70 | printCmd->AvailableForStates(G4State_PreInit,G4State_Idle); |
---|
| 71 | |
---|
| 72 | histoCmd = new G4UIcommand("/testhadr/SetHisto",this); |
---|
| 73 | histoCmd->SetGuidance("Set bining of the histo number ih :"); |
---|
| 74 | histoCmd->SetGuidance(" nbBins; valMin; valMax; unit (of vmin and vmax)"); |
---|
| 75 | // |
---|
| 76 | G4UIparameter* ih = new G4UIparameter("ih",'i',false); |
---|
| 77 | ih->SetGuidance("histo number : from 1 to MaxHisto"); |
---|
| 78 | ih->SetParameterRange("ih>0"); |
---|
| 79 | histoCmd->SetParameter(ih); |
---|
| 80 | // |
---|
| 81 | G4UIparameter* nbBins = new G4UIparameter("nbBins",'i',false); |
---|
| 82 | nbBins->SetGuidance("number of bins"); |
---|
| 83 | nbBins->SetParameterRange("nbBins>0"); |
---|
| 84 | histoCmd->SetParameter(nbBins); |
---|
| 85 | // |
---|
| 86 | G4UIparameter* valMin = new G4UIparameter("valMin",'d',false); |
---|
| 87 | valMin->SetGuidance("valMin, expressed in unit"); |
---|
| 88 | histoCmd->SetParameter(valMin); |
---|
| 89 | // |
---|
| 90 | G4UIparameter* valMax = new G4UIparameter("valMax",'d',false); |
---|
| 91 | valMax->SetGuidance("valMax, expressed in unit"); |
---|
| 92 | histoCmd->SetParameter(valMax); |
---|
| 93 | // |
---|
| 94 | G4UIparameter* unit = new G4UIparameter("unit",'s',true); |
---|
| 95 | unit->SetGuidance("if omitted, vmin and vmax are assumed dimensionless"); |
---|
| 96 | unit->SetDefaultValue("none"); |
---|
| 97 | histoCmd->SetParameter(unit); |
---|
| 98 | } |
---|
| 99 | |
---|
| 100 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... |
---|
| 101 | |
---|
| 102 | HistoMessenger::~HistoMessenger() |
---|
| 103 | { |
---|
| 104 | delete fileCmd; |
---|
| 105 | delete histoCmd; |
---|
| 106 | delete factoryCmd; |
---|
| 107 | delete optCmd; |
---|
| 108 | delete printCmd; |
---|
| 109 | } |
---|
| 110 | |
---|
| 111 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... |
---|
| 112 | |
---|
| 113 | void HistoMessenger::SetNewValue(G4UIcommand* command,G4String newValues) |
---|
| 114 | { |
---|
| 115 | if (command == factoryCmd) |
---|
| 116 | histo->setFileName(newValues); |
---|
| 117 | |
---|
| 118 | if (command == fileCmd) |
---|
| 119 | histo->setFileType(newValues); |
---|
| 120 | |
---|
| 121 | if (command == optCmd) |
---|
| 122 | histo->setFileOption(newValues); |
---|
| 123 | |
---|
| 124 | if (command == printCmd) |
---|
| 125 | histo->print(printCmd->GetNewIntValue(newValues)); |
---|
| 126 | |
---|
| 127 | if (command == histoCmd) { |
---|
| 128 | G4int ih, nbBins; |
---|
| 129 | G4double vmin,vmax; |
---|
| 130 | G4String unit; |
---|
| 131 | std::istringstream is(newValues); |
---|
| 132 | is >> ih >> nbBins >> vmin >> vmax >> unit; |
---|
| 133 | G4double vUnit = 1. ; |
---|
| 134 | if (unit != "none" && unit != "") vUnit = G4UIcommand::ValueOf(unit); |
---|
| 135 | histo->setHisto1D(ih,nbBins,vmin,vmax,vUnit); |
---|
| 136 | } |
---|
| 137 | } |
---|
| 138 | |
---|
| 139 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... |
---|