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