Geant4  10.03.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4PlotManager.hh
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 // $Id$
27 
28 // The manager class for batch plotting.
29 
30 // Author: Ivana Hrivnacova, 02/06/2015 (ivana@ipno.in2p3.fr)
31 
32 #ifndef G4PlotManager_h
33 #define G4PlotManager_h 1
34 
36 #include "G4PlotParameters.hh"
37 
38 #include <tools/viewplot>
39 
40 #include <vector>
41 #include <memory>
42 
43 class G4HnInformation;
44 
46 {
47  public:
48  explicit G4PlotManager(const G4AnalysisManagerState& state);
50 
51  // deleted functions
52  G4PlotManager(const G4PlotManager& rhs) = delete;
53  G4PlotManager& operator=(const G4PlotManager& rhs) = delete;
54 
55  public:
56  // methods
57  G4bool OpenFile(const G4String& fileName);
58  template <typename T>
59  G4bool PlotAndWrite(const std::vector<T*>& htVector,
60  const std::vector<G4HnInformation*>& hnVector);
61  G4bool CloseFile();
62 
63  private:
64  // methods
65  G4int GetNofPlotsPerPage() const;
66  G4bool WritePage();
67 
68  // static data members
69  static G4PlotParameters fgPlotParameters;
70 
71  // data members
72  const G4AnalysisManagerState& fState;
73  std::unique_ptr<tools::viewplot> fViewer;
74  G4String fFileName;
75 };
76 
77 // inline functions
78 
79 //_____________________________________________________________________________
80 inline G4int G4PlotManager::GetNofPlotsPerPage() const
81 { return fgPlotParameters.GetColumns()*fgPlotParameters.GetRows(); }
82 
83 
84 //_____________________________________________________________________________
85 template <typename T>
86 inline G4bool G4PlotManager::PlotAndWrite(const std::vector<T*>& htVector,
87  const std::vector<G4HnInformation*>& hnVector)
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.
93  fViewer->set_cols_rows(fgPlotParameters.GetColumns(), fgPlotParameters.GetRows());
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 }
147 
148 #endif
G4double G4ParticleHPJENDLHEData::G4double result
const XML_Char XML_Encoding * info
Definition: expat.h:530
void Message(const G4String &action, const G4String &object, const G4String &objectName, G4bool success=true) const
const XML_Char * name
Definition: expat.h:151
G4bool GetActivation() const
G4bool GetPlotting() const
G4PlotManager(const G4AnalysisManagerState &state)
G4bool PlotAndWrite(const std::vector< T * > &htVector, const std::vector< G4HnInformation * > &hnVector)
G4int GetRows() const
int G4int
Definition: G4Types.hh:78
G4String GetStyle() const
const G4AnalysisVerbose * GetVerboseL3() const
bool G4bool
Definition: G4Types.hh:79
G4int GetColumns() const
G4String GetName() const
G4PlotManager & operator=(const G4PlotManager &rhs)=delete
G4bool CloseFile()
G4bool OpenFile(const G4String &fileName)