Geant4  10.03.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CexmcHistoManagerMessenger.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 /*
27  * ============================================================================
28  *
29  * Filename: CexmcHistoManagerMessenger.cc
30  *
31  * Description: commands to list and show histograms
32  *
33  * Version: 1.0
34  * Created: 17.12.2009 21:39:02
35  * Revision: none
36  * Compiler: gcc
37  *
38  * Author: Alexey Radkov (),
39  * Company: PNPI
40  *
41  * ============================================================================
42  */
43 
44 #ifdef CEXMC_USE_ROOT
45 
47 #include <G4UIcmdWithAnInteger.hh>
48 #include <G4UIcmdWithAString.hh>
49 #include <G4String.hh>
51 #include "CexmcHistoManager.hh"
52 #include "CexmcMessenger.hh"
53 
54 
55 CexmcHistoManagerMessenger::CexmcHistoManagerMessenger(
56  CexmcHistoManager * histoManager ) :
57  histoManager( histoManager ), setVerboseLevel( NULL ), listHistos( NULL ),
58  printHisto( NULL )
59 #ifdef CEXMC_USE_ROOTQT
60  , drawHisto( NULL ), addHistoMenu( NULL ), drawHistoOptions1D( NULL ),
61  drawHistoOptions2D( NULL ), drawHistoOptions3D( NULL )
62 #endif
63 {
64  setVerboseLevel = new G4UIcmdWithAnInteger(
65  ( CexmcMessenger::histoDirName + "verbose" ).c_str(), this );
66  setVerboseLevel->SetGuidance( "0 - basic set of histograms created, "
67  "1 - extra histograms created" );
68  setVerboseLevel->SetParameterName( "Verbose", true );
69  setVerboseLevel->SetDefaultValue( 0 );
70  setVerboseLevel->AvailableForStates( G4State_PreInit );
71 
72  listHistos = new G4UIcmdWithoutParameter(
73  ( CexmcMessenger::histoDirName + "list" ).c_str(), this );
74  listHistos->SetGuidance( "List available histograms" );
75  listHistos->AvailableForStates( G4State_PreInit, G4State_Idle );
76 
77  printHisto = new G4UIcmdWithAString(
78  ( CexmcMessenger::histoDirName + "print" ).c_str(), this );
79  printHisto->SetGuidance( "Print specified histogram" );
80  printHisto->SetParameterName( "PrintHisto", false );
81  printHisto->AvailableForStates( G4State_Idle );
82 
83 #ifdef CEXMC_USE_ROOTQT
84  drawHisto = new G4UIcmdWithAString(
85  ( CexmcMessenger::histoDirName + "draw" ).c_str(), this );
86  drawHisto->SetGuidance( "Draw specified histogram. The first parameter is\n"
87  " the histogram name, the rest is draw "
88  "options.\n Available only if the program was "
89  "launched\n in graphical mode" );
90  drawHisto->SetParameterName( "DrawHisto", false );
91  drawHisto->AvailableForStates( G4State_Idle );
92 
93  addHistoMenu = new G4UIcmdWithAString(
94  ( CexmcMessenger::histoDirName + "addHistoMenu" ).c_str(), this );
95  addHistoMenu->SetGuidance( "Add histogram menu in GUI menu bar. The first "
96  "parameter is\n the menu handle, the rest is "
97  "the menu label.\n The menu cannot be added "
98  "or disabled in runtime" );
99  addHistoMenu->SetParameterName( "AddHistoMenu", true );
100  addHistoMenu->AvailableForStates( G4State_Idle );
101 
102  drawHistoOptions1D = new G4UIcmdWithAString(
103  ( CexmcMessenger::histoDirName + "drawOptions1D" ).c_str(), this );
104  drawHistoOptions1D->SetGuidance( "Set draw options for 1D histograms drawn "
105  "from the menu.\n The options cannot "
106  "be changed after the menu was built");
107  drawHistoOptions1D->SetParameterName( "DrawOptions1D", false );
108  drawHistoOptions1D->AvailableForStates( G4State_Idle );
109 
110  drawHistoOptions2D = new G4UIcmdWithAString(
111  ( CexmcMessenger::histoDirName + "drawOptions2D" ).c_str(), this );
112  drawHistoOptions2D->SetGuidance( "Set draw options for 2D histograms drawn "
113  "from the menu.\n The options cannot "
114  "be changed after the menu was built");
115  drawHistoOptions2D->SetParameterName( "DrawOptions2D", false );
116  drawHistoOptions2D->AvailableForStates( G4State_Idle );
117 
118  drawHistoOptions3D = new G4UIcmdWithAString(
119  ( CexmcMessenger::histoDirName + "drawOptions3D" ).c_str(), this );
120  drawHistoOptions3D->SetGuidance( "Set draw options for 3D histograms drawn "
121  "from the menu.\n The options cannot "
122  "be changed after the menu was built");
123  drawHistoOptions3D->SetParameterName( "DrawOptions3D", false );
124  drawHistoOptions3D->AvailableForStates( G4State_Idle );
125 #endif
126 }
127 
128 
129 CexmcHistoManagerMessenger::~CexmcHistoManagerMessenger()
130 {
131  delete setVerboseLevel;
132  delete listHistos;
133  delete printHisto;
134 #ifdef CEXMC_USE_ROOTQT
135  delete drawHisto;
136  delete addHistoMenu;
137  delete drawHistoOptions1D;
138  delete drawHistoOptions2D;
139  delete drawHistoOptions3D;
140 #endif
141 }
142 
143 
144 void CexmcHistoManagerMessenger::SetNewValue( G4UIcommand * cmd,
145  G4String value )
146 {
147  do
148  {
149  if ( cmd == setVerboseLevel )
150  {
151  histoManager->SetVerboseLevel(
153  break;
154  }
155  if ( cmd == listHistos )
156  {
157  histoManager->List();
158  break;
159  }
160  if ( cmd == printHisto )
161  {
162  histoManager->Print( value );
163  break;
164  }
165 #ifdef CEXMC_USE_ROOTQT
166  if ( cmd == drawHisto )
167  {
168  size_t delimPos( value.find_first_of( " \t" ) );
169  size_t delimPosEnd( G4String::npos );
170  if ( delimPos != G4String::npos )
171  delimPosEnd = value.find_first_not_of( " \t", delimPos );
172  histoManager->Draw( std::string( value, 0, delimPos ),
173  delimPosEnd == G4String::npos ? "" :
174  value.c_str() + delimPosEnd );
175  break;
176  }
177  if ( cmd == addHistoMenu )
178  {
179  size_t delimPos( value.find_first_of( " \t" ) );
180  size_t delimPosEnd( G4String::npos );
181  if ( delimPos != G4String::npos )
182  delimPosEnd = value.find_first_not_of( " \t", delimPos );
183  histoManager->AddHistoMenu( std::string( value, 0, delimPos ),
184  delimPosEnd == G4String::npos ? "" :
185  value.c_str() + delimPosEnd );
186  break;
187  }
188  if ( cmd == drawHistoOptions1D )
189  {
190  histoManager->SetDrawOptions1D( value );
191  break;
192  }
193  if ( cmd == drawHistoOptions2D )
194  {
195  histoManager->SetDrawOptions2D( value );
196  break;
197  }
198  if ( cmd == drawHistoOptions3D )
199  {
200  histoManager->SetDrawOptions3D( value );
201  break;
202  }
203 #endif
204  } while ( false );
205 }
206 
207 #endif
208 
static G4int GetNewIntValue(const char *paramString)
const XML_Char int const XML_Char * value
Definition: expat.h:331