Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer 3 // * License and Disclaimer * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/ 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. 9 // * include a list of copyright holders. * 10 // * 10 // * * 11 // * Neither the authors of this software syst 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitatio 16 // * for the full disclaimer and the limitation of liability. * 17 // * 17 // * * 18 // * This code implementation is the result 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboratio 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distri 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you ag 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publicati 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Sof 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************* 24 // ******************************************************************** 25 // 25 // 26 26 27 #include "G4HnInformation.hh" 27 #include "G4HnInformation.hh" 28 28 29 #include "G4THnToolsManager.hh" << 30 << 31 //____________________________________________ 29 //_____________________________________________________________________________ 32 template <typename HT> 30 template <typename HT> 33 inline 31 inline 34 G4bool G4ToolsAnalysisManager::WriteT( 32 G4bool G4ToolsAnalysisManager::WriteT( 35 const std::vector<std::pair<HT*, G4HnInforma 33 const std::vector<std::pair<HT*, G4HnInformation*>>& hnVector) 36 { 34 { 37 auto result = true; 35 auto result = true; 38 36 39 for ( auto& [ht, info] : hnVector) { 37 for ( auto& [ht, info] : hnVector) { 40 auto activation = info->GetActivation(); 38 auto activation = info->GetActivation(); 41 39 42 // skip writing if activation is enabled a 40 // skip writing if activation is enabled and H1 is inactivated 43 // or if histogram was deleted << 41 if ( fState.GetIsActivation() && ( ! activation ) ) continue; 44 if ( ( fState.GetIsActivation() && ( ! act << 45 ( info->GetDeleted() ) ) continue; << 46 42 47 auto name = info->GetName(); 43 auto name = info->GetName(); 48 auto fileName = info->GetFileName(); 44 auto fileName = info->GetFileName(); 49 auto fileManager = GetFileManager(fileName 45 auto fileManager = GetFileManager(fileName); 50 46 51 // skip writing if cannot get file manager 47 // skip writing if cannot get file manager (wrong file extension) 52 if ( ! fileManager ) { 48 if ( ! fileManager ) { 53 G4Analysis::Warn( 49 G4Analysis::Warn( 54 "Cannot get file manager for file " + 50 "Cannot get file manager for file " + fileName + ".\n" + 55 "Writing " + G4Analysis::GetHnType<HT> 51 "Writing " + G4Analysis::GetHnType<HT>() + " " + name + " will be skipped.", 56 fkClass, "WriteT"); 52 fkClass, "WriteT"); 57 continue; 53 continue; 58 } 54 } 59 55 60 auto fileKind = " in file "; 56 auto fileKind = " in file "; 61 if ( fileName != "" ) { 57 if ( fileName != "" ) { 62 fileKind = " in extra file "; 58 fileKind = " in extra file "; 63 } else { 59 } else { 64 fileName = fileManager->GetFullFileName( 60 fileName = fileManager->GetFullFileName(); 65 } 61 } 66 62 67 // update name with a cycle number 63 // update name with a cycle number 68 if (! fileManager->HasCycles() && fState.G 64 if (! fileManager->HasCycles() && fState.GetCycle() > 0) { 69 name += "_v" + std::to_string(fState.Get 65 name += "_v" + std::to_string(fState.GetCycle()); 70 } 66 } 71 67 72 Message(G4Analysis::kVL4, "write", G4Analy 68 Message(G4Analysis::kVL4, "write", G4Analysis::GetHnType<HT>(), 73 name + fileKind + fileName); 69 name + fileKind + fileName); 74 70 75 if ( ! fileManager->template GetHnFileMana 71 if ( ! fileManager->template GetHnFileManager<HT>()->Write(ht, name, fileName) ) { 76 G4Analysis::Warn( 72 G4Analysis::Warn( 77 "Writing " + G4Analysis::GetHnType<HT> 73 "Writing " + G4Analysis::GetHnType<HT>() + " " + name + 78 " to file " + fileName + " failed.", 74 " to file " + fileName + " failed.", 79 fkClass, "WriteT"); 75 fkClass, "WriteT"); 80 result = false; 76 result = false; 81 } 77 } 82 78 83 if (result) { 79 if (result) { 84 // notify that file has a written object 80 // notify that file has a written object 85 fileManager->SetIsEmpty(fileName, false) 81 fileManager->SetIsEmpty(fileName, false); 86 } 82 } 87 83 88 Message(G4Analysis::kVL3, "write", G4Analy 84 Message(G4Analysis::kVL3, "write", G4Analysis::GetHnType<HT>(), 89 name + " in the " + fileKind + " file " 85 name + " in the " + fileKind + " file " + fileName); 90 } 86 } 91 87 92 return result; 88 return result; 93 } 89 } 94 90 95 //____________________________________________ 91 //_____________________________________________________________________________ 96 inline 92 inline 97 G4bool G4ToolsAnalysisManager::IsOpenFileImpl( 93 G4bool G4ToolsAnalysisManager::IsOpenFileImpl() const 98 { 94 { 99 return fVFileManager->IsOpenFile(); 95 return fVFileManager->IsOpenFile(); 100 } 96 } 101 97 102 //____________________________________________ 98 //_____________________________________________________________________________ 103 inline 99 inline 104 tools::histo::h1d* G4ToolsAnalysisManager::Ge 100 tools::histo::h1d* G4ToolsAnalysisManager::GetH1(G4int id, G4bool warn, 105 101 G4bool onlyIfActive) const 106 { 102 { 107 return fH1Manager->GetT(id, warn, onlyIfActi 103 return fH1Manager->GetT(id, warn, onlyIfActive); 108 } 104 } 109 105 110 //____________________________________________ 106 //_____________________________________________________________________________ 111 inline 107 inline 112 tools::histo::h2d* G4ToolsAnalysisManager::Ge 108 tools::histo::h2d* G4ToolsAnalysisManager::GetH2(G4int id, G4bool warn, 113 109 G4bool onlyIfActive) const 114 { 110 { 115 return fH2Manager->GetT(id, warn, onlyIfActi 111 return fH2Manager->GetT(id, warn, onlyIfActive); 116 } 112 } 117 113 118 //____________________________________________ 114 //_____________________________________________________________________________ 119 inline 115 inline 120 tools::histo::h3d* G4ToolsAnalysisManager::Ge 116 tools::histo::h3d* G4ToolsAnalysisManager::GetH3(G4int id, G4bool warn, 121 117 G4bool onlyIfActive) const 122 { 118 { 123 return fH3Manager->GetT(id, warn, onlyIfActi 119 return fH3Manager->GetT(id, warn, onlyIfActive); 124 } 120 } 125 121 126 //____________________________________________ 122 //_____________________________________________________________________________ 127 inline 123 inline 128 tools::histo::p1d* G4ToolsAnalysisManager::Ge 124 tools::histo::p1d* G4ToolsAnalysisManager::GetP1(G4int id, G4bool warn, 129 125 G4bool onlyIfActive) const 130 { 126 { 131 return fP1Manager->GetT(id, warn, onlyIfActi 127 return fP1Manager->GetT(id, warn, onlyIfActive); 132 } 128 } 133 129 134 //____________________________________________ 130 //_____________________________________________________________________________ 135 inline 131 inline 136 tools::histo::p2d* G4ToolsAnalysisManager::Ge 132 tools::histo::p2d* G4ToolsAnalysisManager::GetP2(G4int id, G4bool warn, 137 133 G4bool onlyIfActive) const 138 { 134 { 139 return fP2Manager->GetT(id, warn, onlyIfActi 135 return fP2Manager->GetT(id, warn, onlyIfActive); 140 } 136 } 141 137 142 //____________________________________________ 138 //_____________________________________________________________________________ 143 inline 139 inline 144 std::vector<tools::histo::h1d*>::iterator G4To 140 std::vector<tools::histo::h1d*>::iterator G4ToolsAnalysisManager::BeginH1() 145 { 141 { 146 return fH1Manager->BeginT(); 142 return fH1Manager->BeginT(); 147 } 143 } 148 144 149 //____________________________________________ 145 //_____________________________________________________________________________ 150 inline 146 inline 151 std::vector<tools::histo::h1d*>::iterator G4To 147 std::vector<tools::histo::h1d*>::iterator G4ToolsAnalysisManager::EndH1() 152 { 148 { 153 return fH1Manager->EndT(); 149 return fH1Manager->EndT(); 154 } 150 } 155 151 156 //____________________________________________ 152 //_____________________________________________________________________________ 157 inline 153 inline 158 std::vector<tools::histo::h1d*>::const_iterato 154 std::vector<tools::histo::h1d*>::const_iterator 159 G4ToolsAnalysisManager::BeginConstH1() const 155 G4ToolsAnalysisManager::BeginConstH1() const 160 { 156 { 161 return fH1Manager->BeginConstT(); 157 return fH1Manager->BeginConstT(); 162 } 158 } 163 159 164 //____________________________________________ 160 //_____________________________________________________________________________ 165 inline 161 inline 166 std::vector<tools::histo::h1d*>::const_iterato 162 std::vector<tools::histo::h1d*>::const_iterator 167 G4ToolsAnalysisManager::EndConstH1() const 163 G4ToolsAnalysisManager::EndConstH1() const 168 { 164 { 169 return fH1Manager->EndConstT(); 165 return fH1Manager->EndConstT(); 170 } 166 } 171 167 172 //____________________________________________ 168 //_____________________________________________________________________________ 173 inline 169 inline 174 std::vector<tools::histo::h2d*>::iterator G4To 170 std::vector<tools::histo::h2d*>::iterator G4ToolsAnalysisManager::BeginH2() 175 { 171 { 176 return fH2Manager->BeginT(); 172 return fH2Manager->BeginT(); 177 } 173 } 178 174 179 //____________________________________________ 175 //_____________________________________________________________________________ 180 inline 176 inline 181 std::vector<tools::histo::h2d*>::iterator G4To 177 std::vector<tools::histo::h2d*>::iterator G4ToolsAnalysisManager::EndH2() 182 { 178 { 183 return fH2Manager->EndT(); 179 return fH2Manager->EndT(); 184 } 180 } 185 181 186 //____________________________________________ 182 //_____________________________________________________________________________ 187 inline 183 inline 188 std::vector<tools::histo::h2d*>::const_iterato 184 std::vector<tools::histo::h2d*>::const_iterator 189 G4ToolsAnalysisManager::BeginConstH2() const 185 G4ToolsAnalysisManager::BeginConstH2() const 190 { 186 { 191 return fH2Manager->BeginConstT(); 187 return fH2Manager->BeginConstT(); 192 } 188 } 193 189 194 //____________________________________________ 190 //_____________________________________________________________________________ 195 inline 191 inline 196 std::vector<tools::histo::h2d*>::const_iterato 192 std::vector<tools::histo::h2d*>::const_iterator 197 G4ToolsAnalysisManager::EndConstH2() const 193 G4ToolsAnalysisManager::EndConstH2() const 198 { 194 { 199 return fH2Manager->EndConstT(); 195 return fH2Manager->EndConstT(); 200 } 196 } 201 197 202 //____________________________________________ 198 //_____________________________________________________________________________ 203 inline 199 inline 204 std::vector<tools::histo::h3d*>::iterator G4To 200 std::vector<tools::histo::h3d*>::iterator G4ToolsAnalysisManager::BeginH3() 205 { 201 { 206 return fH3Manager->BeginT(); 202 return fH3Manager->BeginT(); 207 } 203 } 208 204 209 //____________________________________________ 205 //_____________________________________________________________________________ 210 inline 206 inline 211 std::vector<tools::histo::h3d*>::iterator G4To 207 std::vector<tools::histo::h3d*>::iterator G4ToolsAnalysisManager::EndH3() 212 { 208 { 213 return fH3Manager->EndT(); 209 return fH3Manager->EndT(); 214 } 210 } 215 211 216 //____________________________________________ 212 //_____________________________________________________________________________ 217 inline 213 inline 218 std::vector<tools::histo::h3d*>::const_iterato 214 std::vector<tools::histo::h3d*>::const_iterator 219 G4ToolsAnalysisManager::BeginConstH3() const 215 G4ToolsAnalysisManager::BeginConstH3() const 220 { 216 { 221 return fH3Manager->BeginConstT(); 217 return fH3Manager->BeginConstT(); 222 } 218 } 223 219 224 //____________________________________________ 220 //_____________________________________________________________________________ 225 inline 221 inline 226 std::vector<tools::histo::h3d*>::const_iterato 222 std::vector<tools::histo::h3d*>::const_iterator 227 G4ToolsAnalysisManager::EndConstH3() const 223 G4ToolsAnalysisManager::EndConstH3() const 228 { 224 { 229 return fH3Manager->EndConstT(); 225 return fH3Manager->EndConstT(); 230 } 226 } 231 227 232 //____________________________________________ 228 //_____________________________________________________________________________ 233 inline 229 inline 234 std::vector<tools::histo::p1d*>::iterator G4To 230 std::vector<tools::histo::p1d*>::iterator G4ToolsAnalysisManager::BeginP1() 235 { 231 { 236 return fP1Manager->BeginT(); 232 return fP1Manager->BeginT(); 237 } 233 } 238 234 239 //____________________________________________ 235 //_____________________________________________________________________________ 240 inline 236 inline 241 std::vector<tools::histo::p1d*>::iterator G4To 237 std::vector<tools::histo::p1d*>::iterator G4ToolsAnalysisManager::EndP1() 242 { 238 { 243 return fP1Manager->EndT(); 239 return fP1Manager->EndT(); 244 } 240 } 245 241 246 //____________________________________________ 242 //_____________________________________________________________________________ 247 inline 243 inline 248 std::vector<tools::histo::p1d*>::const_iterato 244 std::vector<tools::histo::p1d*>::const_iterator 249 G4ToolsAnalysisManager::BeginConstP1() const 245 G4ToolsAnalysisManager::BeginConstP1() const 250 { 246 { 251 return fP1Manager->BeginConstT(); 247 return fP1Manager->BeginConstT(); 252 } 248 } 253 249 254 //____________________________________________ 250 //_____________________________________________________________________________ 255 inline 251 inline 256 std::vector<tools::histo::p1d*>::const_iterato 252 std::vector<tools::histo::p1d*>::const_iterator 257 G4ToolsAnalysisManager::EndConstP1() const 253 G4ToolsAnalysisManager::EndConstP1() const 258 { 254 { 259 return fP1Manager->EndConstT(); 255 return fP1Manager->EndConstT(); 260 } 256 } 261 257 262 //____________________________________________ 258 //_____________________________________________________________________________ 263 inline 259 inline 264 std::vector<tools::histo::p2d*>::iterator G4To 260 std::vector<tools::histo::p2d*>::iterator G4ToolsAnalysisManager::BeginP2() 265 { 261 { 266 return fP2Manager->BeginT(); 262 return fP2Manager->BeginT(); 267 } 263 } 268 264 269 //____________________________________________ 265 //_____________________________________________________________________________ 270 inline 266 inline 271 std::vector<tools::histo::p2d*>::iterator G4To 267 std::vector<tools::histo::p2d*>::iterator G4ToolsAnalysisManager::EndP2() 272 { 268 { 273 return fP2Manager->EndT(); 269 return fP2Manager->EndT(); 274 } 270 } 275 271 276 //____________________________________________ 272 //_____________________________________________________________________________ 277 inline 273 inline 278 std::vector<tools::histo::p2d*>::const_iterato 274 std::vector<tools::histo::p2d*>::const_iterator 279 G4ToolsAnalysisManager::BeginConstP2() const 275 G4ToolsAnalysisManager::BeginConstP2() const 280 { 276 { 281 return fP2Manager->BeginConstT(); 277 return fP2Manager->BeginConstT(); 282 } 278 } 283 279 284 //____________________________________________ 280 //_____________________________________________________________________________ 285 inline 281 inline 286 std::vector<tools::histo::p2d*>::const_iterato 282 std::vector<tools::histo::p2d*>::const_iterator 287 G4ToolsAnalysisManager::EndConstP2() const 283 G4ToolsAnalysisManager::EndConstP2() const 288 { 284 { 289 return fP2Manager->EndConstT(); 285 return fP2Manager->EndConstT(); 290 } 286 } 291 287