File indexing completed on 2025-01-31 09:21:53
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044 #ifdef CEXMC_USE_ROOT
0045
0046 #include <G4UIcmdWithoutParameter.hh>
0047 #include <G4UIcmdWithAnInteger.hh>
0048 #include <G4UIcmdWithAString.hh>
0049 #include <G4String.hh>
0050 #include "CexmcHistoManagerMessenger.hh"
0051 #include "CexmcHistoManager.hh"
0052 #include "CexmcMessenger.hh"
0053
0054
0055 CexmcHistoManagerMessenger::CexmcHistoManagerMessenger(
0056 CexmcHistoManager * histoManager_ ) :
0057 histoManager( histoManager_ ), setVerboseLevel( NULL ), listHistos( NULL ),
0058 printHisto( NULL )
0059 #ifdef CEXMC_USE_ROOTQT
0060 , drawHisto( NULL ), addHistoMenu( NULL ), drawHistoOptions1D( NULL ),
0061 drawHistoOptions2D( NULL ), drawHistoOptions3D( NULL )
0062 #endif
0063 {
0064 setVerboseLevel = new G4UIcmdWithAnInteger(
0065 ( CexmcMessenger::histoDirName + "verbose" ).c_str(), this );
0066 setVerboseLevel->SetGuidance( "0 - basic set of histograms created, "
0067 "1 - extra histograms created" );
0068 setVerboseLevel->SetParameterName( "Verbose", true );
0069 setVerboseLevel->SetDefaultValue( 0 );
0070 setVerboseLevel->AvailableForStates( G4State_PreInit );
0071
0072 listHistos = new G4UIcmdWithoutParameter(
0073 ( CexmcMessenger::histoDirName + "list" ).c_str(), this );
0074 listHistos->SetGuidance( "List available histograms" );
0075 listHistos->AvailableForStates( G4State_PreInit, G4State_Idle );
0076
0077 printHisto = new G4UIcmdWithAString(
0078 ( CexmcMessenger::histoDirName + "print" ).c_str(), this );
0079 printHisto->SetGuidance( "Print specified histogram" );
0080 printHisto->SetParameterName( "PrintHisto", false );
0081 printHisto->AvailableForStates( G4State_Idle );
0082
0083 #ifdef CEXMC_USE_ROOTQT
0084 drawHisto = new G4UIcmdWithAString(
0085 ( CexmcMessenger::histoDirName + "draw" ).c_str(), this );
0086 drawHisto->SetGuidance( "Draw specified histogram. The first parameter is\n"
0087 " the histogram name, the rest is draw "
0088 "options.\n Available only if the program was "
0089 "launched\n in graphical mode" );
0090 drawHisto->SetParameterName( "DrawHisto", false );
0091 drawHisto->AvailableForStates( G4State_Idle );
0092
0093 addHistoMenu = new G4UIcmdWithAString(
0094 ( CexmcMessenger::histoDirName + "addHistoMenu" ).c_str(), this );
0095 addHistoMenu->SetGuidance( "Add histogram menu in GUI menu bar. The first "
0096 "parameter is\n the menu handle, the rest is "
0097 "the menu label.\n The menu cannot be added "
0098 "or disabled in runtime" );
0099 addHistoMenu->SetParameterName( "AddHistoMenu", true );
0100 addHistoMenu->AvailableForStates( G4State_Idle );
0101
0102 drawHistoOptions1D = new G4UIcmdWithAString(
0103 ( CexmcMessenger::histoDirName + "drawOptions1D" ).c_str(), this );
0104 drawHistoOptions1D->SetGuidance( "Set draw options for 1D histograms drawn "
0105 "from the menu.\n The options cannot "
0106 "be changed after the menu was built");
0107 drawHistoOptions1D->SetParameterName( "DrawOptions1D", false );
0108 drawHistoOptions1D->AvailableForStates( G4State_Idle );
0109
0110 drawHistoOptions2D = new G4UIcmdWithAString(
0111 ( CexmcMessenger::histoDirName + "drawOptions2D" ).c_str(), this );
0112 drawHistoOptions2D->SetGuidance( "Set draw options for 2D histograms drawn "
0113 "from the menu.\n The options cannot "
0114 "be changed after the menu was built");
0115 drawHistoOptions2D->SetParameterName( "DrawOptions2D", false );
0116 drawHistoOptions2D->AvailableForStates( G4State_Idle );
0117
0118 drawHistoOptions3D = new G4UIcmdWithAString(
0119 ( CexmcMessenger::histoDirName + "drawOptions3D" ).c_str(), this );
0120 drawHistoOptions3D->SetGuidance( "Set draw options for 3D histograms drawn "
0121 "from the menu.\n The options cannot "
0122 "be changed after the menu was built");
0123 drawHistoOptions3D->SetParameterName( "DrawOptions3D", false );
0124 drawHistoOptions3D->AvailableForStates( G4State_Idle );
0125 #endif
0126 }
0127
0128
0129 CexmcHistoManagerMessenger::~CexmcHistoManagerMessenger()
0130 {
0131 delete setVerboseLevel;
0132 delete listHistos;
0133 delete printHisto;
0134 #ifdef CEXMC_USE_ROOTQT
0135 delete drawHisto;
0136 delete addHistoMenu;
0137 delete drawHistoOptions1D;
0138 delete drawHistoOptions2D;
0139 delete drawHistoOptions3D;
0140 #endif
0141 }
0142
0143
0144 void CexmcHistoManagerMessenger::SetNewValue( G4UIcommand * cmd,
0145 G4String value )
0146 {
0147 do
0148 {
0149 if ( cmd == setVerboseLevel )
0150 {
0151 histoManager->SetVerboseLevel(
0152 G4UIcmdWithAnInteger::GetNewIntValue( value ) );
0153 break;
0154 }
0155 if ( cmd == listHistos )
0156 {
0157 histoManager->List();
0158 break;
0159 }
0160 if ( cmd == printHisto )
0161 {
0162 histoManager->Print( value );
0163 break;
0164 }
0165 #ifdef CEXMC_USE_ROOTQT
0166 if ( cmd == drawHisto )
0167 {
0168 size_t delimPos( value.find_first_of( " \t" ) );
0169 size_t delimPosEnd( G4String::npos );
0170 if ( delimPos != G4String::npos )
0171 delimPosEnd = value.find_first_not_of( " \t", delimPos );
0172 histoManager->Draw( std::string( value, 0, delimPos ),
0173 delimPosEnd == G4String::npos ? "" :
0174 value.c_str() + delimPosEnd );
0175 break;
0176 }
0177 if ( cmd == addHistoMenu )
0178 {
0179 size_t delimPos( value.find_first_of( " \t" ) );
0180 size_t delimPosEnd( G4String::npos );
0181 if ( delimPos != G4String::npos )
0182 delimPosEnd = value.find_first_not_of( " \t", delimPos );
0183 histoManager->AddHistoMenu( std::string( value, 0, delimPos ),
0184 delimPosEnd == G4String::npos ? "" :
0185 value.c_str() + delimPosEnd );
0186 break;
0187 }
0188 if ( cmd == drawHistoOptions1D )
0189 {
0190 histoManager->SetDrawOptions1D( value );
0191 break;
0192 }
0193 if ( cmd == drawHistoOptions2D )
0194 {
0195 histoManager->SetDrawOptions2D( value );
0196 break;
0197 }
0198 if ( cmd == drawHistoOptions3D )
0199 {
0200 histoManager->SetDrawOptions3D( value );
0201 break;
0202 }
0203 #endif
0204 } while ( false );
0205 }
0206
0207 #endif
0208