ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4PlotMessenger.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4PlotMessenger.cc
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 // Author: Ivana Hrivnacova, 21/10/2015 (ivana@ipno.in2p3.fr)
28 
29 #include "G4PlotMessenger.hh"
30 #include "G4PlotParameters.hh"
31 #include "G4AnalysisUtilities.hh"
33 
34 #include "G4UIdirectory.hh"
35 #include "G4UIcommand.hh"
36 #include "G4UIparameter.hh"
37 #include "G4UIcmdWithAString.hh"
38 //#include "G4Tokenizer.hh"
39 
40 #include <iostream>
41 #include <sstream>
42 #include <vector>
43 
44 using namespace G4Analysis;
45 
46 //_____________________________________________________________________________
48  : G4UImessenger(),
49  fPlotParameters(plotParameters),
50  fHelper(nullptr),
51  fDirectory(nullptr),
52  fSetLayoutCmd(nullptr),
53  fSetDimensionsCmd(nullptr),
54  fSetStyleCmd(nullptr)
55 {
56  fHelper = G4Analysis::make_unique<G4AnalysisMessengerHelper>("plot");
57 
58  fDirectory = fHelper->CreateHnDirectory();
59 
60  SetStyleCmd();
61  SetLayoutCmd();
63 }
64 
65 //_____________________________________________________________________________
67 {}
68 
69 //
70 // private functions
71 //
72 
73 //_____________________________________________________________________________
75 {
76  fSetStyleCmd = G4Analysis::make_unique<G4UIcmdWithAString>("/analysis/plot/setStyle",this);
77 #if defined(TOOLS_USE_FREETYPE)
78  fSetStyleCmd->SetGuidance("Set plotting style from: ");
79  fSetStyleCmd->SetGuidance(" ROOT_default: ROOT style with high resolution fonts");
80  fSetStyleCmd->SetGuidance(" hippodraw: hippodraw style with high resolution fonts");
81  fSetStyleCmd->SetGuidance(" inlib_default: PAW style with low resolution fonts");
82  fSetStyleCmd->SetParameterName("Style", false);
83 #else
84  fSetStyleCmd->SetGuidance("Only one plotting style is available in low resolution: ");
85  fSetStyleCmd->SetGuidance(" inlib_default: PAW style with low resolution fonts");
86  fSetStyleCmd->SetParameterName("Style", false);
87  fSetStyleCmd->SetCandidates("inlib_default");
88 #endif
90  fSetStyleCmd->AvailableForStates(G4State_PreInit, G4State_Idle);
91 }
92 
93 //_____________________________________________________________________________
95 {
96  auto columns = new G4UIparameter("columns", 'i', false);
97  columns->SetGuidance("The number of columns in the page layout.");
98  G4String range = "columns>=1 && columns<=";
99  std::ostringstream osMaxColumns;
100  osMaxColumns << fPlotParameters->GetMaxColumns();
101  range.append(osMaxColumns.str());
102  columns->SetParameterRange(range);
103 
104  auto rows = new G4UIparameter("rows", 'i', false);
105  rows->SetGuidance("The number of rows in the page layout.");
106  range = "rows>=1 && rows<=";
107  std::ostringstream osMaxRows;
108  osMaxRows << fPlotParameters->GetMaxRows();
109  range.append(osMaxRows.str());
110  rows->SetParameterRange(range);
111 
112  fSetLayoutCmd = G4Analysis::make_unique<G4UIcommand>("/analysis/plot/setLayout", this);
113  // Guidance text:
114  // Set page layout (number of columns and rows per page).
115  // Supported layouts:
116  // columns = 1 .. maxValueAllowed
117  // rows = 1 .. maxValueAllowed, and >= columns
118  fSetLayoutCmd->SetGuidance("Set page layout (number of columns and rows per page).");
119  fSetLayoutCmd->SetGuidance(" Supported layouts: ");
120  G4String guidance = " columns = 1 .. ";
121  guidance.append(osMaxColumns.str());
122  fSetLayoutCmd->SetGuidance(guidance);
123  guidance = " rows = 1 .. ";
124  guidance.append(osMaxRows.str());
125  guidance.append(" and >= columns");
126  fSetLayoutCmd->SetGuidance(guidance);
127  fSetLayoutCmd->SetParameter(columns);
128  fSetLayoutCmd->SetParameter(rows);
129  fSetLayoutCmd->AvailableForStates(G4State_PreInit, G4State_Idle);
130 }
131 
132 //_____________________________________________________________________________
134 {
135  auto width = new G4UIparameter("width", 'i', false);
136  width->SetGuidance("The page width.");
137 
138  auto height = new G4UIparameter("height", 'i', false);
139  height->SetGuidance("The page height.");
140 
141  fSetDimensionsCmd = G4Analysis::make_unique<G4UIcommand>("/analysis/plot/setDimensions", this);
142  fSetDimensionsCmd->SetGuidance("Set the plotter window size (width and height) in pixels.");
143  fSetDimensionsCmd->SetParameter(width);
144  fSetDimensionsCmd->SetParameter(height);
145  fSetDimensionsCmd->AvailableForStates(G4State_PreInit, G4State_Idle);
146 }
147 
148 //
149 // public functions
150 //
151 
152 //_____________________________________________________________________________
154 {
155  // tokenize parameters in a vector
156  std::vector<G4String> parameters;
157  G4Analysis::Tokenize(newValues, parameters);
158  // check consistency
159  if ( parameters.size() != command->GetParameterEntries() ) {
160  // Should never happen but let's check anyway for consistency
161  fHelper->WarnAboutParameters(command, parameters.size());
162  return;
163  }
164 
165  if ( command == fSetLayoutCmd.get() ) {
166  auto counter = 0;
167  auto columns = G4UIcommand::ConvertToInt(parameters[counter++]);
168  auto rows = G4UIcommand::ConvertToInt(parameters[counter++]);
169  fPlotParameters->SetLayout(columns, rows);
170  }
171  else if ( command == fSetDimensionsCmd.get() ) {
172  auto counter = 0;
173  auto width = G4UIcommand::ConvertToInt(parameters[counter++]);
174  auto height = G4UIcommand::ConvertToInt(parameters[counter++]);
176  }
177 #if defined(TOOLS_USE_FREETYPE)
178  else if ( command == fSetStyleCmd.get() ) {
179  fPlotParameters->SetStyle(newValues);
180  }
181 #endif
182 }