Geant4  10.00.p03
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 )
61 #endif
62 {
63  setVerboseLevel = new G4UIcmdWithAnInteger(
64  ( CexmcMessenger::histoDirName + "verbose" ).c_str(), this );
65  setVerboseLevel->SetGuidance( "0 - basic set of histograms created, "
66  "1 - extra histograms created" );
67  setVerboseLevel->SetParameterName( "Verbose", true );
68  setVerboseLevel->SetDefaultValue( 0 );
69  setVerboseLevel->AvailableForStates( G4State_PreInit );
70 
71  listHistos = new G4UIcmdWithoutParameter(
72  ( CexmcMessenger::histoDirName + "list" ).c_str(), this );
73  listHistos->SetGuidance( "List available histograms" );
74  listHistos->AvailableForStates( G4State_PreInit, G4State_Idle );
75 
76  printHisto = new G4UIcmdWithAString(
77  ( CexmcMessenger::histoDirName + "print" ).c_str(), this );
78  printHisto->SetGuidance( "Print specified histogram" );
79  printHisto->SetParameterName( "PrintHisto", false );
80  printHisto->AvailableForStates( G4State_Idle );
81 
82 #ifdef CEXMC_USE_ROOTQT
83  drawHisto = new G4UIcmdWithAString(
84  ( CexmcMessenger::histoDirName + "draw" ).c_str(), this );
85  drawHisto->SetGuidance( "Draw specified histogram. The first parameter is\n"
86  " the histogram name, the second is draw "
87  "options.\n Available only if the program was "
88  "launched\n in graphical mode" );
89  drawHisto->SetParameterName( "DrawHisto", false );
90  drawHisto->AvailableForStates( G4State_Idle );
91 #endif
92 }
93 
94 
95 CexmcHistoManagerMessenger::~CexmcHistoManagerMessenger()
96 {
97  delete setVerboseLevel;
98  delete listHistos;
99  delete printHisto;
100 #ifdef CEXMC_USE_ROOTQT
101  delete drawHisto;
102 #endif
103 }
104 
105 
106 void CexmcHistoManagerMessenger::SetNewValue( G4UIcommand * cmd,
107  G4String value )
108 {
109  do
110  {
111  if ( cmd == setVerboseLevel )
112  {
113  histoManager->SetVerboseLevel(
115  break;
116  }
117  if ( cmd == listHistos )
118  {
119  histoManager->List();
120  break;
121  }
122  if ( cmd == printHisto )
123  {
124  histoManager->Print( value );
125  break;
126  }
127 #ifdef CEXMC_USE_ROOTQT
128  if ( cmd == drawHisto )
129  {
130  size_t delimPos( value.find_first_of( " \t" ) );
131  size_t delimPosEnd( G4String::npos );
132  if ( delimPos != G4String::npos )
133  delimPosEnd = value.find_first_not_of( " \t", delimPos );
134  histoManager->Draw( std::string( value, 0, delimPos ),
135  delimPosEnd == G4String::npos ? "" :
136  value.c_str() + delimPosEnd );
137  break;
138  }
139 #endif
140  } while ( false );
141 }
142 
143 #endif
144 
static G4int GetNewIntValue(const char *paramString)