Geant4.10
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
extended/electromagnetic/TestEm17/src/HistoMessenger.cc
Go to the documentation of this file.
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 /// \file electromagnetic/TestEm17/src/HistoMessenger.cc
27 /// \brief Implementation of the HistoMessenger class
28 //
29 //
30 // $Id: HistoMessenger.cc 67268 2013-02-13 11:38:40Z ihrivnac $
31 //
32 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
33 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
34 
35 #include "HistoMessenger.hh"
36 
37 #include <sstream>
38 
39 #include "HistoManager.hh"
40 #include "G4UIdirectory.hh"
41 #include "G4UIcommand.hh"
42 #include "G4UIparameter.hh"
43 #include "G4UIcmdWithAString.hh"
44 #include "G4UIcmdWithAnInteger.hh"
45 
46 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
47 
49 :G4UImessenger(),fHistoManager (manager),
50  fHistoDir(0),
51  fFileNameCmd(0),
52  fHistoCmd(0),
53  fPrtHistoCmd(0)
54 {
55  fHistoDir = new G4UIdirectory("/testem/histo/");
56  fHistoDir->SetGuidance("histograms control");
57 
58  fFileNameCmd = new G4UIcmdWithAString("/testem/histo/setFileName",this);
59  fFileNameCmd->SetGuidance("set name for the histograms file");
60 
61  fHistoCmd = new G4UIcommand("/testem/histo/setHisto",this);
62  fHistoCmd->SetGuidance("Set bining of the histo number ih :");
63  fHistoCmd->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  fHistoCmd->SetParameter(ih);
69  //
70  G4UIparameter* nbBins = new G4UIparameter("nbBins",'i',false);
71  nbBins->SetGuidance("number of bins");
72  nbBins->SetParameterRange("nbBins>0");
73  fHistoCmd->SetParameter(nbBins);
74  //
75  G4UIparameter* valMin = new G4UIparameter("valMin",'d',false);
76  valMin->SetGuidance("valMin, expressed in unit");
77  fHistoCmd->SetParameter(valMin);
78  //
79  G4UIparameter* valMax = new G4UIparameter("valMax",'d',false);
80  valMax->SetGuidance("valMax, expressed in unit");
81  fHistoCmd->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  fHistoCmd->SetParameter(unit);
87 
88  fPrtHistoCmd = new G4UIcmdWithAnInteger("/testem/histo/printHisto",this);
89  fPrtHistoCmd->SetGuidance("print histo #id on ascii file");
90  fPrtHistoCmd->SetParameterName("id",false);
91  fPrtHistoCmd->SetRange("id>0");
92 }
93 
94 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
95 
97 {
98  delete fPrtHistoCmd;
99  delete fHistoCmd;
100  delete fFileNameCmd;
101  delete fHistoDir;
102 }
103 
104 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
105 
106 void HistoMessenger::SetNewValue(G4UIcommand* command, G4String newValues)
107 {
108  if (command == fFileNameCmd)
109  fHistoManager->SetFileName(newValues);
110 
111  if (command == fHistoCmd)
112  { G4int ih,nbBins; G4double vmin,vmax; G4String unit;
113  const char* t = newValues;
114  std::istringstream is(t);
115  is >> ih >> nbBins >> vmin >> vmax >> unit;
116  fHistoManager->SetHisto (ih,nbBins,vmin,vmax,unit);
117  }
118 
119  if (command == fPrtHistoCmd)
120  fHistoManager->PrintHisto(fPrtHistoCmd->GetNewIntValue(newValues));
121 }
122 
123 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
124 
void SetParameter(G4UIparameter *const newParameter)
Definition: G4UIcommand.hh:152
void SetNewValue(G4UIcommand *, G4String)
void SetParameterName(const char *theName, G4bool omittable, G4bool currentAsDefault=false)
static G4int GetNewIntValue(const char *paramString)
void SetParameterRange(const char *theRange)
void SetDefaultValue(const char *theDefaultValue)
int G4int
Definition: G4Types.hh:78
void SetRange(const char *rs)
Definition: G4UIcommand.hh:125
void SetGuidance(const char *aGuidance)
Definition: G4UIcommand.hh:161
void SetHisto(G4int, G4int, G4double, G4double, const G4String &unit="none")
void SetFileName(const G4String &name)
double G4double
Definition: G4Types.hh:76
void SetGuidance(const char *theGuidance)