Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer 3 // * License and Disclaimer * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/ 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. 9 // * include a list of copyright holders. * 10 // * 10 // * * 11 // * Neither the authors of this software syst 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitatio 16 // * for the full disclaimer and the limitation of liability. * 17 // * 17 // * * 18 // * This code implementation is the result 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboratio 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distri 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you ag 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publicati 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Sof 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************* 24 // ******************************************************************** 25 // 25 // 26 /// \file electromagnetic/TestEm17/src/HistoMe << 26 // $Id: HistoMessenger.cc,v 1.2 2006-06-29 16:49:01 gunter Exp $ 27 /// \brief Implementation of the HistoMessenge << 27 // GEANT4 tag $Name: geant4-09-04-patch-02 $ 28 // << 29 // << 30 // 28 // 31 //....oooOO0OOooo........oooOO0OOooo........oo 29 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 32 //....oooOO0OOooo........oooOO0OOooo........oo 30 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 33 31 34 #include "HistoMessenger.hh" 32 #include "HistoMessenger.hh" 35 33 36 #include "HistoManager.hh" << 34 #include <sstream> 37 35 38 #include "G4UIcmdWithAString.hh" << 36 #include "HistoManager.hh" 39 #include "G4UIcmdWithAnInteger.hh" << 40 #include "G4UIcommand.hh" << 41 #include "G4UIdirectory.hh" 37 #include "G4UIdirectory.hh" >> 38 #include "G4UIcommand.hh" 42 #include "G4UIparameter.hh" 39 #include "G4UIparameter.hh" 43 << 40 #include "G4UIcmdWithAString.hh" 44 #include <sstream> << 41 #include "G4UIcmdWithAnInteger.hh" 45 42 46 //....oooOO0OOooo........oooOO0OOooo........oo 43 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 47 44 48 HistoMessenger::HistoMessenger(HistoManager* m 45 HistoMessenger::HistoMessenger(HistoManager* manager) 49 : G4UImessenger(), << 46 :histoManager (manager) 50 fHistoManager(manager), << 51 fHistoDir(0), << 52 fFileNameCmd(0), << 53 fHistoCmd(0), << 54 fPrtHistoCmd(0) << 55 { 47 { 56 fHistoDir = new G4UIdirectory("/testem/histo << 48 histoDir = new G4UIdirectory("/testem/histo/"); 57 fHistoDir->SetGuidance("histograms control") << 49 histoDir->SetGuidance("histograms control"); 58 50 59 fFileNameCmd = new G4UIcmdWithAString("/test << 51 factoryCmd = new G4UIcmdWithAString("/testem/histo/setFileName",this); 60 fFileNameCmd->SetGuidance("set name for the << 52 factoryCmd->SetGuidance("set name for the histograms file"); 61 53 62 fHistoCmd = new G4UIcommand("/testem/histo/s << 54 typeCmd = new G4UIcmdWithAString("/testem/histo/setFileType",this); 63 fHistoCmd->SetGuidance("Set bining of the hi << 55 typeCmd->SetGuidance("set histograms file type"); 64 fHistoCmd->SetGuidance(" nbBins; valMin; va << 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)"); 65 // 64 // 66 G4UIparameter* ih = new G4UIparameter("ih", << 65 G4UIparameter* ih = new G4UIparameter("ih",'i',false); 67 ih->SetGuidance("histo number : from 1 to kM << 66 ih->SetGuidance("histo number : from 1 to MaxHisto"); 68 ih->SetParameterRange("ih>0"); 67 ih->SetParameterRange("ih>0"); 69 fHistoCmd->SetParameter(ih); << 68 histoCmd->SetParameter(ih); 70 // 69 // 71 G4UIparameter* nbBins = new G4UIparameter("n << 70 G4UIparameter* nbBins = new G4UIparameter("nbBins",'i',false); 72 nbBins->SetGuidance("number of bins"); 71 nbBins->SetGuidance("number of bins"); 73 nbBins->SetParameterRange("nbBins>0"); 72 nbBins->SetParameterRange("nbBins>0"); 74 fHistoCmd->SetParameter(nbBins); << 73 histoCmd->SetParameter(nbBins); 75 // 74 // 76 G4UIparameter* valMin = new G4UIparameter("v << 75 G4UIparameter* valMin = new G4UIparameter("valMin",'d',false); 77 valMin->SetGuidance("valMin, expressed in un 76 valMin->SetGuidance("valMin, expressed in unit"); 78 fHistoCmd->SetParameter(valMin); << 77 histoCmd->SetParameter(valMin); 79 // << 78 // 80 G4UIparameter* valMax = new G4UIparameter("v << 79 G4UIparameter* valMax = new G4UIparameter("valMax",'d',false); 81 valMax->SetGuidance("valMax, expressed in un 80 valMax->SetGuidance("valMax, expressed in unit"); 82 fHistoCmd->SetParameter(valMax); << 81 histoCmd->SetParameter(valMax); 83 // << 82 // 84 G4UIparameter* unit = new G4UIparameter("uni << 83 G4UIparameter* unit = new G4UIparameter("unit",'s',true); 85 unit->SetGuidance("if omitted, vmin and vmax 84 unit->SetGuidance("if omitted, vmin and vmax are assumed dimensionless"); 86 unit->SetDefaultValue("none"); 85 unit->SetDefaultValue("none"); 87 fHistoCmd->SetParameter(unit); << 86 histoCmd->SetParameter(unit); 88 << 87 89 fPrtHistoCmd = new G4UIcmdWithAnInteger("/te << 88 rmhistoCmd = new G4UIcmdWithAnInteger("/testem/histo/removeHisto",this); 90 fPrtHistoCmd->SetGuidance("print histo #id o << 89 rmhistoCmd->SetGuidance("desactivate histo #id"); 91 fPrtHistoCmd->SetParameterName("id", false); << 90 rmhistoCmd->SetParameterName("id",false); 92 fPrtHistoCmd->SetRange("id>0"); << 91 rmhistoCmd->SetRange("id>0"); 93 } 92 } 94 93 95 //....oooOO0OOooo........oooOO0OOooo........oo 94 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 96 95 97 HistoMessenger::~HistoMessenger() 96 HistoMessenger::~HistoMessenger() 98 { 97 { 99 delete fPrtHistoCmd; << 98 delete rmhistoCmd; 100 delete fHistoCmd; << 99 delete histoCmd; 101 delete fFileNameCmd; << 100 delete optionCmd; 102 delete fHistoDir; << 101 delete typeCmd; >> 102 delete factoryCmd; >> 103 delete histoDir; 103 } 104 } 104 105 105 //....oooOO0OOooo........oooOO0OOooo........oo 106 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 106 107 107 void HistoMessenger::SetNewValue(G4UIcommand* 108 void HistoMessenger::SetNewValue(G4UIcommand* command, G4String newValues) 108 { 109 { 109 if (command == fFileNameCmd) fHistoManager-> << 110 if (command == factoryCmd) >> 111 histoManager->SetFileName(newValues); 110 112 111 if (command == fHistoCmd) { << 113 if (command == typeCmd) 112 G4int ih, nbBins; << 114 histoManager->SetFileType(newValues); 113 G4double vmin, vmax; << 115 114 G4String unit; << 116 if (command == optionCmd) 115 const char* t = newValues; << 117 histoManager->SetFileOption(newValues); 116 std::istringstream is(t); << 118 117 is >> ih >> nbBins >> vmin >> vmax >> unit << 119 if (command == histoCmd) 118 fHistoManager->SetHisto(ih, nbBins, vmin, << 120 { G4int ih,nbBins; G4double vmin,vmax; char unts[30]; 119 } << 121 const char* t = newValues; 120 << 122 std::istringstream is(t); 121 if (command == fPrtHistoCmd) fHistoManager-> << 123 is >> ih >> nbBins >> vmin >> vmax >> unts; >> 124 G4String unit = unts; >> 125 G4double vUnit = 1. ; >> 126 if (unit != "none") vUnit = G4UIcommand::ValueOf(unit); >> 127 histoManager->SetHisto (ih,nbBins,vmin*vUnit,vmax*vUnit,unit); >> 128 } >> 129 >> 130 if (command == rmhistoCmd) >> 131 histoManager->RemoveHisto(rmhistoCmd->GetNewIntValue(newValues)); 122 } 132 } 123 133 124 //....oooOO0OOooo........oooOO0OOooo........oo 134 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... >> 135 125 136