Geant4  9.6.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 //
28 //
29 //
30 // $Id$
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 :fHistoManager (manager)
50 {
51  fHistoDir = new G4UIdirectory("/testem/histo/");
52  fHistoDir->SetGuidance("histograms control");
53 
54  fFileNameCmd = new G4UIcmdWithAString("/testem/histo/setFileName",this);
55  fFileNameCmd->SetGuidance("set name for the histograms file");
56 
57  fHistoCmd = new G4UIcommand("/testem/histo/setHisto",this);
58  fHistoCmd->SetGuidance("Set bining of the histo number ih :");
59  fHistoCmd->SetGuidance(" nbBins; valMin; valMax; unit (of vmin and vmax)");
60  //
61  G4UIparameter* ih = new G4UIparameter("ih",'i',false);
62  ih->SetGuidance("histo number : from 1 to MaxHisto");
63  ih->SetParameterRange("ih>0");
64  fHistoCmd->SetParameter(ih);
65  //
66  G4UIparameter* nbBins = new G4UIparameter("nbBins",'i',false);
67  nbBins->SetGuidance("number of bins");
68  nbBins->SetParameterRange("nbBins>0");
69  fHistoCmd->SetParameter(nbBins);
70  //
71  G4UIparameter* valMin = new G4UIparameter("valMin",'d',false);
72  valMin->SetGuidance("valMin, expressed in unit");
73  fHistoCmd->SetParameter(valMin);
74  //
75  G4UIparameter* valMax = new G4UIparameter("valMax",'d',false);
76  valMax->SetGuidance("valMax, expressed in unit");
77  fHistoCmd->SetParameter(valMax);
78  //
79  G4UIparameter* unit = new G4UIparameter("unit",'s',true);
80  unit->SetGuidance("if omitted, vmin and vmax are assumed dimensionless");
81  unit->SetDefaultValue("none");
82  fHistoCmd->SetParameter(unit);
83 
84  fPrtHistoCmd = new G4UIcmdWithAnInteger("/testem/histo/printHisto",this);
85  fPrtHistoCmd->SetGuidance("print histo #id on ascii file");
86  fPrtHistoCmd->SetParameterName("id",false);
87  fPrtHistoCmd->SetRange("id>0");
88 }
89 
90 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
91 
93 {
94  delete fPrtHistoCmd;
95  delete fHistoCmd;
96  delete fFileNameCmd;
97  delete fHistoDir;
98 }
99 
100 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
101 
102 void HistoMessenger::SetNewValue(G4UIcommand* command, G4String newValues)
103 {
104  if (command == fFileNameCmd)
105  fHistoManager->SetFileName(newValues);
106 
107  if (command == fHistoCmd)
108  { G4int ih,nbBins; G4double vmin,vmax; G4String unit;
109  const char* t = newValues;
110  std::istringstream is(t);
111  is >> ih >> nbBins >> vmin >> vmax >> unit;
112  fHistoManager->SetHisto (ih,nbBins,vmin,vmax,unit);
113  }
114 
115  if (command == fPrtHistoCmd)
116  fHistoManager->PrintHisto(fPrtHistoCmd->GetNewIntValue(newValues));
117 }
118 
119 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
120