Geant4  v4-10.4-release
 모두 클래스 네임스페이스들 파일들 함수 변수 타입정의 열거형 타입 열거형 멤버 Friends 매크로 그룹들 페이지들
G4PlotManager.hh
이 파일의 문서화 페이지로 가기
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 #include "G4HnInformation.hh"
38 
39 #include <tools/viewplot>
40 
41 #include <vector>
42 #include <memory>
43 
45 {
46  public:
47  explicit G4PlotManager(const G4AnalysisManagerState& state);
49 
50  // deleted functions
51  G4PlotManager(const G4PlotManager& rhs) = delete;
52  G4PlotManager& operator=(const G4PlotManager& rhs) = delete;
53 
54  public:
55  // methods
56  G4bool OpenFile(const G4String& fileName);
57  template <typename T>
58  G4bool PlotAndWrite(const std::vector<T*>& htVector,
59  const std::vector<G4HnInformation*>& hnVector);
60  G4bool CloseFile();
61 
62  private:
63  // methods
64  G4int GetNofPlotsPerPage() const;
65  G4bool WritePage();
66 
67  // static data members
69 
70  // data members
72  std::unique_ptr<tools::viewplot> fViewer;
74 };
75 
76 // inline functions
77 
78 //_____________________________________________________________________________
81 
82 
83 //_____________________________________________________________________________
84 template <typename T>
85 inline G4bool G4PlotManager::PlotAndWrite(const std::vector<T*>& htVector,
86  const std::vector<G4HnInformation*>& hnVector)
87 {
88  if ( ! htVector.size() ) return true;
89 
90  fViewer->plots().init_sg();
91  //it will recreate the sg::plotters and then reset the styles on new ones.
93  fViewer->plots().set_current_plotter(0);
94 
95  G4bool finalResult = true;
96  G4bool isWriteNeeded = false;
97 
98  for ( G4int i=0; i<G4int(htVector.size()); ++i ) {
99  G4HnInformation* info = hnVector[i];
100  G4bool plotting = info->GetPlotting();
101  G4bool activation = info->GetActivation();
102  G4String name = info->GetName();
103  // skip plotting if not selected for plotting or
104  // if activation is enabled and HT is inactivated
105  if ( ( ! plotting ) ||
106  ( fState.GetIsActivation() && ( ! activation ) ) ) continue;
107 
108  T* ht = htVector[i];
109 
110  // plot this object
111  fViewer->plot(*ht);
112  fViewer->set_current_plotter_style(fgPlotParameters.GetStyle());
113 
114  // set color (only blue for the time being)
115  tools::sg::plotter& plotter = fViewer->plots().current_plotter();
116  // set plot properties (use info object to get these)
117  plotter.bins_style(0).color = tools::colorf_blue();
118 
119  isWriteNeeded = true;
120 
121 #ifdef G4VERBOSE
122  if ( fState.GetVerboseL3() )
123  fState.GetVerboseL3()->Message("plotting", "hd|pd", name);
124 #endif
125 
126  // write a page if number of plots per page is achieved
127  if ( G4int(fViewer->plots().current_index()) == (GetNofPlotsPerPage() - 1) ) {
128  G4bool result = WritePage();
129  finalResult = result && finalResult;
130  isWriteNeeded = false;
131  }
132 
133  // Prepare for the next plot
134  fViewer->plots().next();
135  }
136 
137  // write a page if loop is finished and there are plots to be written
138  if ( isWriteNeeded ) {
139  G4bool result = WritePage();
140  finalResult = result && finalResult;
141  }
142 
143  // add test of result
144  return finalResult;
145 }
146 
147 #endif
const XML_Char XML_Encoding * info
Definition: expat.h:530
const XML_Char * name
Definition: expat.h:151
G4String GetName() const
G4String GetStyle() const
static G4PlotParameters fgPlotParameters
G4bool WritePage()
G4bool CloseFile()
G4PlotManager(const G4AnalysisManagerState &state)
G4String fFileName
G4bool OpenFile(const G4String &fileName)
bool G4bool
Definition: G4Types.hh:79
G4int GetColumns() const
std::unique_ptr< tools::viewplot > fViewer
G4bool GetPlotting() const
const G4AnalysisVerbose * GetVerboseL3() const
G4int GetNofPlotsPerPage() const
G4PlotManager & operator=(const G4PlotManager &rhs)=delete
G4int GetRows() const
G4double G4ParticleHPJENDLHEData::G4double result
G4bool GetActivation() const
int G4int
Definition: G4Types.hh:78
void Message(const G4String &action, const G4String &object, const G4String &objectName, G4bool success=true) const
const G4AnalysisManagerState & fState
G4bool PlotAndWrite(const std::vector< T * > &htVector, const std::vector< G4HnInformation * > &hnVector)