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10.5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

  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 #include "G4HnInformation.hh"
 28 
 29 #include "G4THnToolsManager.hh"
 30 
 31 //_____________________________________________________________________________
 32 template <typename HT>
 33 inline
 34 G4bool G4ToolsAnalysisManager::WriteT(
 35   const std::vector<std::pair<HT*, G4HnInformation*>>& hnVector)
 36 {
 37   auto result = true;
 38 
 39   for ( auto& [ht, info] : hnVector) {
 40     auto activation = info->GetActivation();
 41 
 42     // skip writing if activation is enabled and H1 is inactivated
 43     // or if histogram was deleted
 44     if ( ( fState.GetIsActivation() && ( ! activation ) ) ||
 45          ( info->GetDeleted() ) ) continue;
 46 
 47     auto name = info->GetName();
 48     auto fileName = info->GetFileName();
 49     auto fileManager = GetFileManager(fileName);
 50 
 51     // skip writing if cannot get file manager (wrong file extension)
 52     if ( ! fileManager ) {
 53       G4Analysis::Warn(
 54         "Cannot get file manager for file " + fileName + ".\n" +
 55         "Writing " + G4Analysis::GetHnType<HT>() + " " +  name + " will be skipped.",
 56         fkClass, "WriteT");
 57       continue;
 58     }
 59 
 60     auto fileKind = " in file ";
 61     if ( fileName != "" ) {
 62       fileKind = " in extra file ";
 63     } else {
 64       fileName = fileManager->GetFullFileName();
 65     }
 66 
 67     // update name with a cycle number
 68     if (! fileManager->HasCycles() && fState.GetCycle() > 0) {
 69       name += "_v" + std::to_string(fState.GetCycle());
 70     }
 71 
 72     Message(G4Analysis::kVL4, "write", G4Analysis::GetHnType<HT>(),
 73       name + fileKind + fileName);
 74 
 75     if ( ! fileManager->template GetHnFileManager<HT>()->Write(ht, name, fileName) ) {
 76       G4Analysis::Warn(
 77         "Writing " + G4Analysis::GetHnType<HT>() + " " +  name +
 78         " to file " +  fileName + " failed.",
 79         fkClass, "WriteT");
 80       result = false;
 81     }
 82 
 83     if (result) {
 84       // notify that file has a written object
 85       fileManager->SetIsEmpty(fileName, false);
 86     }
 87 
 88     Message(G4Analysis::kVL3, "write", G4Analysis::GetHnType<HT>(),
 89       name + " in the " + fileKind + " file " + fileName);
 90   }
 91 
 92   return result;
 93 }
 94 
 95 //_____________________________________________________________________________
 96 inline
 97 G4bool G4ToolsAnalysisManager::IsOpenFileImpl() const
 98 {
 99   return fVFileManager->IsOpenFile();
100 }
101 
102 //_____________________________________________________________________________
103 inline
104 tools::histo::h1d*  G4ToolsAnalysisManager::GetH1(G4int id, G4bool warn,
105                                                  G4bool onlyIfActive) const
106 {
107   return fH1Manager->GetT(id, warn, onlyIfActive);
108 }
109 
110 //_____________________________________________________________________________
111 inline
112 tools::histo::h2d*  G4ToolsAnalysisManager::GetH2(G4int id, G4bool warn,
113                                                  G4bool onlyIfActive) const
114 {
115   return fH2Manager->GetT(id, warn, onlyIfActive);
116 }
117 
118 //_____________________________________________________________________________
119 inline
120 tools::histo::h3d*  G4ToolsAnalysisManager::GetH3(G4int id, G4bool warn,
121                                                  G4bool onlyIfActive) const
122 {
123   return fH3Manager->GetT(id, warn, onlyIfActive);
124 }
125 
126 //_____________________________________________________________________________
127 inline
128 tools::histo::p1d*  G4ToolsAnalysisManager::GetP1(G4int id, G4bool warn,
129                                                  G4bool onlyIfActive) const
130 {
131   return fP1Manager->GetT(id, warn, onlyIfActive);
132 }
133 
134 //_____________________________________________________________________________
135 inline
136 tools::histo::p2d*  G4ToolsAnalysisManager::GetP2(G4int id, G4bool warn,
137                                                  G4bool onlyIfActive) const
138 {
139   return fP2Manager->GetT(id, warn, onlyIfActive);
140 }
141 
142 //_____________________________________________________________________________
143 inline
144 std::vector<tools::histo::h1d*>::iterator G4ToolsAnalysisManager::BeginH1()
145 {
146   return fH1Manager->BeginT();
147 }
148 
149 //_____________________________________________________________________________
150 inline
151 std::vector<tools::histo::h1d*>::iterator G4ToolsAnalysisManager::EndH1()
152 {
153   return fH1Manager->EndT();
154 }
155 
156 //_____________________________________________________________________________
157 inline
158 std::vector<tools::histo::h1d*>::const_iterator
159 G4ToolsAnalysisManager::BeginConstH1() const
160 {
161   return fH1Manager->BeginConstT();
162 }
163 
164 //_____________________________________________________________________________
165 inline
166 std::vector<tools::histo::h1d*>::const_iterator
167 G4ToolsAnalysisManager::EndConstH1() const
168 {
169   return fH1Manager->EndConstT();
170 }
171 
172 //_____________________________________________________________________________
173 inline
174 std::vector<tools::histo::h2d*>::iterator G4ToolsAnalysisManager::BeginH2()
175 {
176   return fH2Manager->BeginT();
177 }
178 
179 //_____________________________________________________________________________
180 inline
181 std::vector<tools::histo::h2d*>::iterator G4ToolsAnalysisManager::EndH2()
182 {
183   return fH2Manager->EndT();
184 }
185 
186 //_____________________________________________________________________________
187 inline
188 std::vector<tools::histo::h2d*>::const_iterator
189 G4ToolsAnalysisManager::BeginConstH2() const
190 {
191   return fH2Manager->BeginConstT();
192 }
193 
194 //_____________________________________________________________________________
195 inline
196 std::vector<tools::histo::h2d*>::const_iterator
197 G4ToolsAnalysisManager::EndConstH2() const
198 {
199   return fH2Manager->EndConstT();
200 }
201 
202 //_____________________________________________________________________________
203 inline
204 std::vector<tools::histo::h3d*>::iterator G4ToolsAnalysisManager::BeginH3()
205 {
206   return fH3Manager->BeginT();
207 }
208 
209 //_____________________________________________________________________________
210 inline
211 std::vector<tools::histo::h3d*>::iterator G4ToolsAnalysisManager::EndH3()
212 {
213   return fH3Manager->EndT();
214 }
215 
216 //_____________________________________________________________________________
217 inline
218 std::vector<tools::histo::h3d*>::const_iterator
219 G4ToolsAnalysisManager::BeginConstH3() const
220 {
221   return fH3Manager->BeginConstT();
222 }
223 
224 //_____________________________________________________________________________
225 inline
226 std::vector<tools::histo::h3d*>::const_iterator
227 G4ToolsAnalysisManager::EndConstH3() const
228 {
229   return fH3Manager->EndConstT();
230 }
231 
232 //_____________________________________________________________________________
233 inline
234 std::vector<tools::histo::p1d*>::iterator G4ToolsAnalysisManager::BeginP1()
235 {
236   return fP1Manager->BeginT();
237 }
238 
239 //_____________________________________________________________________________
240 inline
241 std::vector<tools::histo::p1d*>::iterator G4ToolsAnalysisManager::EndP1()
242 {
243   return fP1Manager->EndT();
244 }
245 
246 //_____________________________________________________________________________
247 inline
248 std::vector<tools::histo::p1d*>::const_iterator
249 G4ToolsAnalysisManager::BeginConstP1() const
250 {
251   return fP1Manager->BeginConstT();
252 }
253 
254 //_____________________________________________________________________________
255 inline
256 std::vector<tools::histo::p1d*>::const_iterator
257 G4ToolsAnalysisManager::EndConstP1() const
258 {
259   return fP1Manager->EndConstT();
260 }
261 
262 //_____________________________________________________________________________
263 inline
264 std::vector<tools::histo::p2d*>::iterator G4ToolsAnalysisManager::BeginP2()
265 {
266   return fP2Manager->BeginT();
267 }
268 
269 //_____________________________________________________________________________
270 inline
271 std::vector<tools::histo::p2d*>::iterator G4ToolsAnalysisManager::EndP2()
272 {
273   return fP2Manager->EndT();
274 }
275 
276 //_____________________________________________________________________________
277 inline
278 std::vector<tools::histo::p2d*>::const_iterator
279 G4ToolsAnalysisManager::BeginConstP2() const
280 {
281   return fP2Manager->BeginConstT();
282 }
283 
284 //_____________________________________________________________________________
285 inline
286 std::vector<tools::histo::p2d*>::const_iterator
287 G4ToolsAnalysisManager::EndConstP2() const
288 {
289   return fP2Manager->EndConstT();
290 }
291