Geant4  10.02.p03
G4PlotManager Class Reference

#include <G4PlotManager.hh>

Collaboration diagram for G4PlotManager:

Public Member Functions

 G4PlotManager (const G4AnalysisManagerState &state)
 
 ~G4PlotManager ()
 
 G4PlotManager (const G4PlotManager &rhs)=delete
 
G4PlotManageroperator= (const G4PlotManager &rhs)=delete
 
G4bool OpenFile (const G4String &fileName)
 
template<typename T >
G4bool PlotAndWrite (const std::vector< T *> &htVector, const std::vector< G4HnInformation *> &hnVector)
 
G4bool CloseFile ()
 

Private Member Functions

G4int GetNofPlotsPerPage () const
 
G4bool WritePage ()
 

Private Attributes

const G4AnalysisManagerStatefState
 
std::unique_ptr< tools::viewplot > fViewer
 
G4String fFileName
 

Static Private Attributes

static G4PlotParameters fgPlotParameters
 

Detailed Description

Definition at line 45 of file G4PlotManager.hh.

Constructor & Destructor Documentation

◆ G4PlotManager() [1/2]

G4PlotManager::G4PlotManager ( const G4AnalysisManagerState state)
explicit

Definition at line 156 of file G4PlotManager.cc.

157  : fState(state),
158  fViewer(nullptr),
159  fFileName()
160 {
161 #if defined(TOOLS_USE_FREETYPE)
162 #ifdef G4VERBOSE
166  if ( fState.GetVerboseL1() )
167  G4cout << "... using high resolution with Freetype fonts" << G4endl;
168 #endif
169  //Have vertical A4 :
170  // unsigned int ww = 2000; //to have better antialising on freetype fonts.
171  // float A4 = 29.7f/21.0f;
172  // unsigned int wh = (unsigned int)(float(ww)*A4*0.80);
173  static tools::sg::text_freetype ttf;
174  fViewer.reset(new tools::viewplot(G4cout, ttf,
179  fViewer->plots().view_border = false;
180  load_embeded_styles(fViewer->styles());
181  fViewer->styles().add_colormap("default",tools::sg::style_default_colormap());
182  fViewer->styles().add_colormap("ROOT",tools::sg::style_ROOT_colormap());
183 #else
184  // cretae a viewer with default parameters
185 #ifdef G4VERBOSE
186  if ( fState.GetVerboseL1() )
187  G4cout << "... using low resolution with Hershey fonts" << G4endl;
188 #endif
189  fViewer.reset(new tools::viewplot(G4cout,
194  fViewer->plots().view_border = false;
195 #endif
196 }
static G4PlotParameters fgPlotParameters
std::unique_ptr< tools::viewplot > fViewer
G4int GetWidth() const
G4int GetColumns() const
G4GLOB_DLL std::ostream G4cout
const G4AnalysisVerbose * GetVerboseL1() const
const G4AnalysisManagerState & fState
G4int GetRows() const
G4int GetHeight() const
#define G4endl
Definition: G4ios.hh:61
G4String fFileName
Here is the call graph for this function:

◆ ~G4PlotManager()

G4PlotManager::~G4PlotManager ( )

Definition at line 199 of file G4PlotManager.cc.

200 {}

◆ G4PlotManager() [2/2]

G4PlotManager::G4PlotManager ( const G4PlotManager rhs)
delete

Member Function Documentation

◆ CloseFile()

G4bool G4PlotManager::CloseFile ( )

Definition at line 271 of file G4PlotManager.cc.

272 {
273 #ifdef G4VERBOSE
274  if ( fState.GetVerboseL4() )
275  fState.GetVerboseL4()->Message("close", "plot file", fFileName);
276 #endif
277 
278  G4bool result = fViewer->close_file();
279  if ( ! result ) {
280  G4ExceptionDescription description;
281  description << " " << "Cannot close the plot file.";
282  G4Exception("G4PlotManager::CloseFile()",
283  "Analysis_W021", JustWarning, description);
284  }
285 
286 #ifdef G4VERBOSE
287  if ( fState.GetVerboseL1() )
288  fState.GetVerboseL1()->Message("close", "plot file", fFileName);
289 #endif
290 
291  return result;
292 }
std::ostringstream G4ExceptionDescription
Definition: globals.hh:76
std::unique_ptr< tools::viewplot > fViewer
bool G4bool
Definition: G4Types.hh:79
const G4AnalysisVerbose * GetVerboseL1() const
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
const G4AnalysisManagerState & fState
const G4AnalysisVerbose * GetVerboseL4() const
void Message(const G4String &action, const G4String &object, const G4String &objectName, G4bool success=true) const
G4String fFileName
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetNofPlotsPerPage()

G4int G4PlotManager::GetNofPlotsPerPage ( ) const
inlineprivate

Definition at line 80 of file G4PlotManager.hh.

static G4PlotParameters fgPlotParameters
G4int GetColumns() const
G4int GetRows() const
Here is the call graph for this function:
Here is the caller graph for this function:

◆ OpenFile()

G4bool G4PlotManager::OpenFile ( const G4String fileName)

Definition at line 244 of file G4PlotManager.cc.

245 {
246 #ifdef G4VERBOSE
247  if ( fState.GetVerboseL4() )
248  fState.GetVerboseL4()->Message("open", "plot file", fileName);
249 #endif
250 
251  // Keep filename for logging
252  fFileName = fileName;
253 
254  G4bool result = fViewer->open_file(fileName);
255  if ( ! result ) {
256  G4ExceptionDescription description;
257  description << " " << "Cannot open plot file " << fileName;
258  G4Exception("G4PlotManager::OpenFile()",
259  "Analysis_W001", JustWarning, description);
260  }
261 
262 #ifdef G4VERBOSE
263  if ( fState.GetVerboseL1() )
264  fState.GetVerboseL1()->Message("open", "plot file", fileName);
265 #endif
266 
267  return result;
268 }
std::ostringstream G4ExceptionDescription
Definition: globals.hh:76
std::unique_ptr< tools::viewplot > fViewer
bool G4bool
Definition: G4Types.hh:79
const G4AnalysisVerbose * GetVerboseL1() const
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
const G4AnalysisManagerState & fState
const G4AnalysisVerbose * GetVerboseL4() const
void Message(const G4String &action, const G4String &object, const G4String &objectName, G4bool success=true) const
G4String fFileName
Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator=()

G4PlotManager& G4PlotManager::operator= ( const G4PlotManager rhs)
delete

◆ PlotAndWrite()

template<typename T >
G4bool G4PlotManager::PlotAndWrite ( const std::vector< T *> &  htVector,
const std::vector< G4HnInformation *> &  hnVector 
)
inline

Definition at line 86 of file G4PlotManager.hh.

88 {
89  if ( ! htVector.size() ) return true;
90 
91  fViewer->plots().init_sg();
92  //it will recreate the sg::plotters and then reset the styles on new ones.
94  fViewer->plots().set_current_plotter(0);
95 
96  G4bool finalResult = true;
97  G4bool isWriteNeeded = false;
98 
99  for ( G4int i=0; i<G4int(htVector.size()); ++i ) {
100  G4HnInformation* info = hnVector[i];
101  G4bool plotting = info->GetPlotting();
102  G4bool activation = info->GetActivation();
103  G4String name = info->GetName();
104  // skip plotting if not selected for plotting or
105  // if activation is enabled and HT is inactivated
106  if ( ( ! plotting ) ||
107  ( fState.GetIsActivation() && ( ! activation ) ) ) continue;
108 
109  T* ht = htVector[i];
110 
111  // plot this object
112  fViewer->plot(*ht);
113  fViewer->set_current_plotter_style(fgPlotParameters.GetStyle());
114 
115  // set color (only blue for the time being)
116  tools::sg::plotter& plotter = fViewer->plots().current_plotter();
117  // set plot properties (use info object to get these)
118  plotter.bins_style(0).color = tools::colorf::blue();
119 
120  isWriteNeeded = true;
121 
122 #ifdef G4VERBOSE
123  if ( fState.GetVerboseL3() )
124  fState.GetVerboseL3()->Message("plotting", "hd|pd", name);
125 #endif
126 
127  // write a page if number of plots per page is achieved
128  if ( G4int(fViewer->plots().current_index()) == (GetNofPlotsPerPage() - 1) ) {
129  G4bool result = WritePage();
130  finalResult = result && finalResult;
131  isWriteNeeded = false;
132  }
133 
134  // Prepare for the next plot
135  fViewer->plots().next();
136  }
137 
138  // write a page if loop is finished and there are plots to be written
139  if ( isWriteNeeded ) {
140  G4bool result = WritePage();
141  finalResult = result && finalResult;
142  }
143 
144  // add test of result
145  return finalResult;
146 }
G4bool WritePage()
static G4PlotParameters fgPlotParameters
G4String GetStyle() const
std::unique_ptr< tools::viewplot > fViewer
G4String GetName() const
G4String name
Definition: TRTMaterials.hh:40
G4bool GetPlotting() const
Definition: test07.cc:36
int G4int
Definition: G4Types.hh:78
G4int GetColumns() const
G4bool GetActivation() const
bool G4bool
Definition: G4Types.hh:79
const G4AnalysisManagerState & fState
G4int GetRows() const
const G4AnalysisVerbose * GetVerboseL3() const
G4int GetNofPlotsPerPage() const
void Message(const G4String &action, const G4String &object, const G4String &objectName, G4bool success=true) const
Here is the call graph for this function:
Here is the caller graph for this function:

◆ WritePage()

G4bool G4PlotManager::WritePage ( )
private

Definition at line 207 of file G4PlotManager.cc.

208 {
209 #ifdef G4VERBOSE
210  if ( fState.GetVerboseL4() )
211  fState.GetVerboseL4()->Message("write a page in", "plot file", fFileName);
212 #endif
213 
214 #if defined(TOOLS_USE_FREETYPE)
215  HD_style(fViewer->plots(), 5);
216  regions_style(fViewer->plots(), fgPlotParameters.GetScale());
217 #endif
218 
219  G4bool result = fViewer->write_page();
220  if ( ! result ) {
221  G4ExceptionDescription description;
222  description << " " << "Cannot write a page in the plot file " << fFileName;
223  G4Exception("G4PlotManager::WritePage()",
224  "Analysis_W022", JustWarning, description);
225  }
226 
227  // clear viewers plots
228  fViewer->plots().init_sg();
229  //it will recreate the sg::plotters and then reset the styles on new ones.
230 
231 #ifdef G4VERBOSE
232  if ( fState.GetVerboseL3() )
233  fState.GetVerboseL3()->Message("write a page in", "plot file", fFileName);
234 #endif
235 
236  return result;
237 }
std::ostringstream G4ExceptionDescription
Definition: globals.hh:76
static G4PlotParameters fgPlotParameters
std::unique_ptr< tools::viewplot > fViewer
bool G4bool
Definition: G4Types.hh:79
G4float GetScale() const
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
const G4AnalysisManagerState & fState
const G4AnalysisVerbose * GetVerboseL3() const
const G4AnalysisVerbose * GetVerboseL4() const
void Message(const G4String &action, const G4String &object, const G4String &objectName, G4bool success=true) const
G4String fFileName
Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ fFileName

G4String G4PlotManager::fFileName
private

Definition at line 74 of file G4PlotManager.hh.

◆ fgPlotParameters

G4PlotParameters G4PlotManager::fgPlotParameters
staticprivate

Definition at line 69 of file G4PlotManager.hh.

◆ fState

const G4AnalysisManagerState& G4PlotManager::fState
private

Definition at line 72 of file G4PlotManager.hh.

◆ fViewer

std::unique_ptr<tools::viewplot> G4PlotManager::fViewer
private

Definition at line 73 of file G4PlotManager.hh.


The documentation for this class was generated from the following files: