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 // Author: Ivana Hrivnacova, 15/06/2011 (ivan 27 // Author: Ivana Hrivnacova, 15/06/2011 (ivana@ipno.in2p3.fr) 28 28 29 #include "G4GenericFileManager.hh" 29 #include "G4GenericFileManager.hh" 30 #include "G4AnalysisManagerState.hh" 30 #include "G4AnalysisManagerState.hh" 31 #include "G4AnalysisUtilities.hh" 31 #include "G4AnalysisUtilities.hh" 32 #include "G4CsvFileManager.hh" 32 #include "G4CsvFileManager.hh" 33 #include "G4CsvNtupleFileManager.hh" 33 #include "G4CsvNtupleFileManager.hh" 34 #ifdef TOOLS_USE_HDF5 34 #ifdef TOOLS_USE_HDF5 35 #include "G4Hdf5FileManager.hh" 35 #include "G4Hdf5FileManager.hh" 36 #include "G4Hdf5NtupleFileManager.hh" 36 #include "G4Hdf5NtupleFileManager.hh" 37 #endif 37 #endif 38 #include "G4RootFileManager.hh" 38 #include "G4RootFileManager.hh" 39 #include "G4RootNtupleFileManager.hh" 39 #include "G4RootNtupleFileManager.hh" 40 #include "G4XmlFileManager.hh" 40 #include "G4XmlFileManager.hh" 41 #include "G4XmlNtupleFileManager.hh" 41 #include "G4XmlNtupleFileManager.hh" 42 42 43 using namespace G4Analysis; 43 using namespace G4Analysis; 44 44 45 namespace { 45 namespace { 46 46 47 //____________________________________________ 47 //_____________________________________________________________________________ 48 void FileManagerWarning(const G4String& fileNa 48 void FileManagerWarning(const G4String& fileName, 49 std::string_view class 49 std::string_view className, 50 std::string_view funct 50 std::string_view functionName, 51 G4bool hdf5Warn = true 51 G4bool hdf5Warn = true) 52 { 52 { 53 if ( GetExtension(fileName) == "hdf5" && ( ! 53 if ( GetExtension(fileName) == "hdf5" && ( ! hdf5Warn ) ) return; 54 54 55 Warn("Cannot get file manager for " + fileNa 55 Warn("Cannot get file manager for " + fileName, 56 className, functionName); 56 className, functionName); 57 } 57 } 58 58 59 } 59 } 60 60 61 //____________________________________________ 61 //_____________________________________________________________________________ 62 G4GenericFileManager::G4GenericFileManager(con 62 G4GenericFileManager::G4GenericFileManager(const G4AnalysisManagerState& state) 63 : G4VFileManager(state) 63 : G4VFileManager(state) 64 {} 64 {} 65 65 66 // 66 // 67 // private methods 67 // private methods 68 // 68 // 69 69 70 //____________________________________________ 70 //_____________________________________________________________________________ 71 void G4GenericFileManager::CreateFileManager(G 71 void G4GenericFileManager::CreateFileManager(G4AnalysisOutput output) 72 { 72 { 73 Message(kVL4, "create", "file manager", GetO 73 Message(kVL4, "create", "file manager", GetOutputName(output)); 74 74 75 auto outputId = static_cast<size_t>(output); 75 auto outputId = static_cast<size_t>(output); 76 if ( fFileManagers[outputId] ) { 76 if ( fFileManagers[outputId] ) { 77 Warn("The file manager of " + G4Analysis:: 77 Warn("The file manager of " + G4Analysis::GetOutputName(output) + 78 " type already exists.", 78 " type already exists.", 79 fkClass, "CreateFileManager"); 79 fkClass, "CreateFileManager"); 80 return; 80 return; 81 } 81 } 82 82 83 // Create the manager 83 // Create the manager 84 switch ( output ) { 84 switch ( output ) { 85 case G4AnalysisOutput::kCsv: 85 case G4AnalysisOutput::kCsv: 86 fCsvFileManager = std::make_shared<G4Csv 86 fCsvFileManager = std::make_shared<G4CsvFileManager>(fState); 87 fFileManagers[outputId] = fCsvFileManage 87 fFileManagers[outputId] = fCsvFileManager; 88 break; 88 break; 89 case G4AnalysisOutput::kHdf5: 89 case G4AnalysisOutput::kHdf5: 90 #ifdef TOOLS_USE_HDF5 90 #ifdef TOOLS_USE_HDF5 91 fHdf5FileManager = std::make_shared<G4Hd 91 fHdf5FileManager = std::make_shared<G4Hdf5FileManager>(fState); 92 fFileManagers[outputId] = fHdf5FileManag 92 fFileManagers[outputId] = fHdf5FileManager; 93 #else 93 #else 94 if ( fHdf5Warn) { 94 if ( fHdf5Warn) { 95 Warn("Hdf5 type is not available.", fk 95 Warn("Hdf5 type is not available.", fkClass, "CreateFileManager"); 96 fHdf5Warn = false; 96 fHdf5Warn = false; 97 } 97 } 98 #endif 98 #endif 99 break; 99 break; 100 case G4AnalysisOutput::kRoot: 100 case G4AnalysisOutput::kRoot: 101 fRootFileManager = std::make_shared<G4Ro 101 fRootFileManager = std::make_shared<G4RootFileManager>(fState); 102 fFileManagers[outputId] = fRootFileManag 102 fFileManagers[outputId] = fRootFileManager; 103 break; 103 break; 104 case G4AnalysisOutput::kXml: 104 case G4AnalysisOutput::kXml: 105 fXmlFileManager = std::make_shared<G4Xml 105 fXmlFileManager = std::make_shared<G4XmlFileManager>(fState); 106 fFileManagers[outputId] = fXmlFileManage 106 fFileManagers[outputId] = fXmlFileManager ; 107 break; 107 break; 108 case G4AnalysisOutput::kNone: 108 case G4AnalysisOutput::kNone: 109 Warn(G4Analysis::GetOutputName(output) + 109 Warn(G4Analysis::GetOutputName(output) + " type is not supported.", 110 fkClass, "CreateFileManager"); 110 fkClass, "CreateFileManager"); 111 return; 111 return; 112 } 112 } 113 113 114 // Pass directory names (only if set) 114 // Pass directory names (only if set) 115 if ( ! GetHistoDirectoryName().empty() ) { 115 if ( ! GetHistoDirectoryName().empty() ) { 116 fFileManagers[outputId]->SetHistoDirectory 116 fFileManagers[outputId]->SetHistoDirectoryName(GetHistoDirectoryName()); 117 } 117 } 118 if ( ! GetNtupleDirectoryName().empty() ) { 118 if ( ! GetNtupleDirectoryName().empty() ) { 119 fFileManagers[outputId]->SetNtupleDirector 119 fFileManagers[outputId]->SetNtupleDirectoryName(GetNtupleDirectoryName()); 120 } 120 } 121 121 122 Message(kVL3, "create", "file manager", GetO 122 Message(kVL3, "create", "file manager", GetOutputName(output)); 123 } 123 } 124 124 125 //____________________________________________ 125 //_____________________________________________________________________________ 126 std::shared_ptr<G4VFileManager> 126 std::shared_ptr<G4VFileManager> 127 G4GenericFileManager::GetFileManager(G4Analysi 127 G4GenericFileManager::GetFileManager(G4AnalysisOutput output) const 128 { 128 { 129 return fFileManagers[static_cast<size_t>(out 129 return fFileManagers[static_cast<size_t>(output)]; 130 } 130 } 131 131 132 //____________________________________________ 132 //_____________________________________________________________________________ 133 std::shared_ptr<G4VFileManager> 133 std::shared_ptr<G4VFileManager> 134 G4GenericFileManager::GetFileManager(const G4S 134 G4GenericFileManager::GetFileManager(const G4String& fileName) 135 { 135 { 136 // Get file extension 136 // Get file extension 137 G4String extension = GetExtension(fileName); 137 G4String extension = GetExtension(fileName); 138 if (extension.size() == 0u) { 138 if (extension.size() == 0u) { 139 // use the default 139 // use the default 140 extension = fDefaultFileType; 140 extension = fDefaultFileType; 141 } 141 } 142 142 143 auto output = G4Analysis::GetOutput(extensio 143 auto output = G4Analysis::GetOutput(extension); 144 if ( output == G4AnalysisOutput::kNone ) { 144 if ( output == G4AnalysisOutput::kNone ) { 145 Warn("The file extension " + extension + " 145 Warn("The file extension " + extension + "is not supported.", 146 fkClass, "GetFileManager"); 146 fkClass, "GetFileManager"); 147 return nullptr; 147 return nullptr; 148 } 148 } 149 149 150 std::shared_ptr<G4VFileManager> fileManager 150 std::shared_ptr<G4VFileManager> fileManager = GetFileManager(output); 151 if ( ! GetFileManager(output) ) { 151 if ( ! GetFileManager(output) ) { 152 CreateFileManager(output); 152 CreateFileManager(output); 153 fileManager = GetFileManager(output); 153 fileManager = GetFileManager(output); 154 } 154 } 155 155 156 return GetFileManager(output); 156 return GetFileManager(output); 157 } 157 } 158 158 159 // 159 // 160 // public methods 160 // public methods 161 // 161 // 162 162 163 //____________________________________________ 163 //_____________________________________________________________________________ 164 G4bool G4GenericFileManager::OpenFile(const G4 164 G4bool G4GenericFileManager::OpenFile(const G4String& fileName) 165 { 165 { 166 auto fileManager = GetFileManager(fileName); 166 auto fileManager = GetFileManager(fileName); 167 if ( ! fileManager ) return false; 167 if ( ! fileManager ) return false; 168 168 169 if ( fDefaultFileManager && (fDefaultFileMan 169 if ( fDefaultFileManager && (fDefaultFileManager != fileManager) ) { 170 // Print warning if default output changed 170 // Print warning if default output changed 171 // (maybe be not needed?) 171 // (maybe be not needed?) 172 Warn("Default file manager changed " 172 Warn("Default file manager changed " 173 "(old: " +fDefaultFileManager->GetFil 173 "(old: " +fDefaultFileManager->GetFileType() + 174 ", new:" + fileManager->GetFileType() 174 ", new:" + fileManager->GetFileType() + ")", 175 fkClass, "OpenFile"); 175 fkClass, "OpenFile"); 176 } 176 } 177 fDefaultFileManager = fileManager; 177 fDefaultFileManager = fileManager; 178 fDefaultFileType = fileManager->GetFileType( 178 fDefaultFileType = fileManager->GetFileType(); 179 179 180 Message(kVL4, "open", "analysis file", fileN 180 Message(kVL4, "open", "analysis file", fileName); 181 181 182 auto result = true; 182 auto result = true; 183 183 184 // Save the default file name 184 // Save the default file name 185 // both in the generic file manager and the 185 // both in the generic file manager and the output specific one 186 result &= SetFileName(fileName); 186 result &= SetFileName(fileName); 187 result &= fDefaultFileManager->SetFileName(f 187 result &= fDefaultFileManager->SetFileName(fileName); 188 result &= fDefaultFileManager->OpenFile(file 188 result &= fDefaultFileManager->OpenFile(fileName); 189 189 190 LockDirectoryNames(); 190 LockDirectoryNames(); 191 fIsOpenFile = true; 191 fIsOpenFile = true; 192 192 193 Message(kVL1, "open", "analysis file", fileN 193 Message(kVL1, "open", "analysis file", fileName, result); 194 194 195 return result; 195 return result; 196 } 196 } 197 197 198 //____________________________________________ 198 //_____________________________________________________________________________ 199 G4bool G4GenericFileManager::OpenFiles() 199 G4bool G4GenericFileManager::OpenFiles() 200 { 200 { 201 // Open all files regeistered with objects 201 // Open all files regeistered with objects 202 202 203 Message(kVL4, "open", "analysis files"); 203 Message(kVL4, "open", "analysis files"); 204 204 205 auto result = true; 205 auto result = true; 206 206 207 // process names registered in base file man 207 // process names registered in base file manager 208 for ( const auto& fileName : GetFileNames() 208 for ( const auto& fileName : GetFileNames() ) { 209 auto fileManager = GetFileManager(fileName 209 auto fileManager = GetFileManager(fileName); 210 if ( ! fileManager ) { 210 if ( ! fileManager ) { 211 FileManagerWarning(fileName, fkClass, "O 211 FileManagerWarning(fileName, fkClass, "OpenFiles", fHdf5Warn); 212 continue; 212 continue; 213 } 213 } 214 214 215 // filenames for csv need to be updated 215 // filenames for csv need to be updated 216 auto newFileName = fileName; 216 auto newFileName = fileName; 217 if (fileManager == fCsvFileManager) { 217 if (fileManager == fCsvFileManager) { 218 newFileName = fileManager->GetHnFileName 218 newFileName = fileManager->GetHnFileName(fileName, GetCycle()); 219 } 219 } 220 220 221 result &= fileManager->CreateFile(newFileN 221 result &= fileManager->CreateFile(newFileName); 222 } 222 } 223 223 224 Message(kVL3, "open", "analysis files", "", 224 Message(kVL3, "open", "analysis files", "", result); 225 225 226 return result; 226 return result; 227 } 227 } 228 228 229 //____________________________________________ 229 //_____________________________________________________________________________ 230 G4bool G4GenericFileManager::WriteFiles() 230 G4bool G4GenericFileManager::WriteFiles() 231 { 231 { 232 // Finish write for all files registered with 232 // Finish write for all files registered with objects 233 233 234 Message(kVL4, "write", "analysis files"); 234 Message(kVL4, "write", "analysis files"); 235 235 236 auto result = true; 236 auto result = true; 237 237 238 for ( const auto& fileManager : fFileManager 238 for ( const auto& fileManager : fFileManagers ) { 239 if ( ! fileManager ) continue; 239 if ( ! fileManager ) continue; 240 240 241 Message(kVL4, "write", fileManager->GetFil 241 Message(kVL4, "write", fileManager->GetFileType(), "files"); 242 242 243 result &= fileManager->WriteFiles(); 243 result &= fileManager->WriteFiles(); 244 } 244 } 245 245 246 Message(kVL3, "write", "analysis files", "", 246 Message(kVL3, "write", "analysis files", "", result); 247 247 248 return result; 248 return result; 249 } 249 } 250 250 251 //____________________________________________ 251 //_____________________________________________________________________________ 252 G4bool G4GenericFileManager::CloseFiles() 252 G4bool G4GenericFileManager::CloseFiles() 253 { 253 { 254 // Close all files regeistered with objects 254 // Close all files regeistered with objects 255 255 256 Message(kVL4, "close", "analysis files"); 256 Message(kVL4, "close", "analysis files"); 257 257 258 auto result = true; 258 auto result = true; 259 259 260 for ( const auto& fileManager : fFileManager 260 for ( const auto& fileManager : fFileManagers ) { 261 if ( ! fileManager ) continue; 261 if ( ! fileManager ) continue; 262 262 263 Message(kVL4, "close", fileManager->GetFil 263 Message(kVL4, "close", fileManager->GetFileType(), "files"); 264 264 265 result &= fileManager->CloseFiles(); 265 result &= fileManager->CloseFiles(); 266 } 266 } 267 267 268 fIsOpenFile = false; 268 fIsOpenFile = false; 269 269 270 Message(kVL3, "close", "analysis files", "", 270 Message(kVL3, "close", "analysis files", "", result); 271 271 272 return result; 272 return result; 273 } 273 } 274 274 275 //____________________________________________ 275 //_____________________________________________________________________________ 276 G4bool G4GenericFileManager::DeleteEmptyFiles( 276 G4bool G4GenericFileManager::DeleteEmptyFiles() 277 { 277 { 278 // Close all files regeistered with objects 278 // Close all files regeistered with objects 279 279 280 Message(kVL4, "delete", "empty files"); 280 Message(kVL4, "delete", "empty files"); 281 281 282 auto result = true; 282 auto result = true; 283 283 284 for ( const auto& fileManager : fFileManager 284 for ( const auto& fileManager : fFileManagers ) { 285 if ( ! fileManager ) continue; 285 if ( ! fileManager ) continue; 286 286 287 Message(kVL4, "delete", fileManager->GetFi 287 Message(kVL4, "delete", fileManager->GetFileType(), "empty files"); 288 288 289 result &= fileManager->DeleteEmptyFiles(); 289 result &= fileManager->DeleteEmptyFiles(); 290 } 290 } 291 291 292 // Clear all saved file names in base file m << 293 G4BaseFileManager::ClearData(); << 294 << 295 Message(kVL3, "delete", "empty files", "", r 292 Message(kVL3, "delete", "empty files", "", result); 296 293 297 return result; 294 return result; 298 } 295 } 299 296 300 //____________________________________________ 297 //_____________________________________________________________________________ 301 void G4GenericFileManager::Clear() 298 void G4GenericFileManager::Clear() 302 { 299 { 303 // Clear files data 300 // Clear files data 304 301 305 for ( const auto& fileManager : fFileManager 302 for ( const auto& fileManager : fFileManagers ) { 306 if ( ! fileManager ) continue; 303 if ( ! fileManager ) continue; 307 304 308 fileManager->Clear(); 305 fileManager->Clear(); 309 } 306 } 310 UnlockDirectoryNames(); 307 UnlockDirectoryNames(); 311 } 308 } 312 309 313 //____________________________________________ 310 //_____________________________________________________________________________ 314 G4bool G4GenericFileManager::CreateFile(const 311 G4bool G4GenericFileManager::CreateFile(const G4String& fileName) 315 { 312 { 316 // New prototype, fully implemented in templat 313 // New prototype, fully implemented in templated base class 317 314 318 auto fileManager = GetFileManager(fileName); 315 auto fileManager = GetFileManager(fileName); 319 if ( ! fileManager ) { 316 if ( ! fileManager ) { 320 FileManagerWarning(fileName, fkClass, "Cre 317 FileManagerWarning(fileName, fkClass, "CreateFile", fHdf5Warn); 321 return false; 318 return false; 322 } 319 } 323 320 324 return fileManager->CreateFile(fileName); 321 return fileManager->CreateFile(fileName); 325 } 322 } 326 323 327 //____________________________________________ 324 //_____________________________________________________________________________ 328 G4bool G4GenericFileManager::WriteFile(const G 325 G4bool G4GenericFileManager::WriteFile(const G4String& fileName) 329 { 326 { 330 // New prototype, fully implemented in templat 327 // New prototype, fully implemented in templated base class 331 328 332 auto fileManager = GetFileManager(fileName); 329 auto fileManager = GetFileManager(fileName); 333 if ( ! fileManager ) { 330 if ( ! fileManager ) { 334 FileManagerWarning(fileName, fkClass, "Wri 331 FileManagerWarning(fileName, fkClass, "WriteFile", fHdf5Warn); 335 return false; 332 return false; 336 } 333 } 337 334 338 return fileManager->WriteFile(fileName); 335 return fileManager->WriteFile(fileName); 339 } 336 } 340 337 341 //____________________________________________ 338 //_____________________________________________________________________________ 342 G4bool G4GenericFileManager::CloseFile(const G 339 G4bool G4GenericFileManager::CloseFile(const G4String& fileName) 343 { 340 { 344 // New prototype, fully implemented in templat 341 // New prototype, fully implemented in templated base class 345 342 346 auto fileManager = GetFileManager(fileName); 343 auto fileManager = GetFileManager(fileName); 347 if ( ! fileManager ) { 344 if ( ! fileManager ) { 348 FileManagerWarning(fileName, fkClass, "Clo 345 FileManagerWarning(fileName, fkClass, "CloseFile", fHdf5Warn); 349 return false; 346 return false; 350 } 347 } 351 348 352 return fileManager->CloseFile(fileName); 349 return fileManager->CloseFile(fileName); 353 } 350 } 354 351 355 //____________________________________________ 352 //_____________________________________________________________________________ 356 G4bool G4GenericFileManager::SetIsEmpty(const 353 G4bool G4GenericFileManager::SetIsEmpty(const G4String& fileName, G4bool isEmpty) 357 { 354 { 358 auto fileManager = GetFileManager(fileName); 355 auto fileManager = GetFileManager(fileName); 359 if ( ! fileManager ) { 356 if ( ! fileManager ) { 360 FileManagerWarning(fileName, fkClass, "Set 357 FileManagerWarning(fileName, fkClass, "SetIsEmpty", fHdf5Warn); 361 return false; 358 return false; 362 } 359 } 363 360 364 return fileManager->SetIsEmpty(fileName, isE 361 return fileManager->SetIsEmpty(fileName, isEmpty); 365 } 362 } 366 363 367 //____________________________________________ 364 //_____________________________________________________________________________ 368 G4bool G4GenericFileManager::SetHistoDirectory 365 G4bool G4GenericFileManager::SetHistoDirectoryName(const G4String& dirName) 369 { 366 { 370 auto result = G4VFileManager::SetHistoDirect 367 auto result = G4VFileManager::SetHistoDirectoryName(dirName); 371 368 372 for (auto& fileManager : fFileManagers ) { 369 for (auto& fileManager : fFileManagers ) { 373 if ( fileManager != nullptr ) { 370 if ( fileManager != nullptr ) { 374 result &= fileManager->SetHistoDirectory 371 result &= fileManager->SetHistoDirectoryName(dirName); 375 } 372 } 376 } 373 } 377 return result; 374 return result; 378 } 375 } 379 376 380 //____________________________________________ 377 //_____________________________________________________________________________ 381 G4bool G4GenericFileManager::SetNtupleDirector 378 G4bool G4GenericFileManager::SetNtupleDirectoryName(const G4String& dirName) 382 { 379 { 383 auto result = G4VFileManager::SetNtupleDirec 380 auto result = G4VFileManager::SetNtupleDirectoryName(dirName); 384 381 385 for (auto& fileManager : fFileManagers ) { 382 for (auto& fileManager : fFileManagers ) { 386 if ( fileManager != nullptr ) { 383 if ( fileManager != nullptr ) { 387 result &= fileManager->SetNtupleDirector 384 result &= fileManager->SetNtupleDirectoryName(dirName); 388 } 385 } 389 } 386 } 390 return result; 387 return result; 391 } << 392 << 393 //____________________________________________ << 394 void G4GenericFileManager::SetCompressionLevel << 395 { << 396 G4BaseFileManager::SetCompressionLevel(level << 397 << 398 for (auto& fileManager : fFileManagers ) { << 399 if ( fileManager != nullptr ) { << 400 fileManager->SetCompressionLevel(level); << 401 } << 402 } << 403 } 388 } 404 389 405 //____________________________________________ 390 //_____________________________________________________________________________ 406 void G4GenericFileManager::SetDefaultFileType( 391 void G4GenericFileManager::SetDefaultFileType(const G4String& value) 407 { 392 { 408 // Check if value correspond to a valid file 393 // Check if value correspond to a valid file type 409 auto output = G4Analysis::GetOutput(value); 394 auto output = G4Analysis::GetOutput(value); 410 if ( output == G4AnalysisOutput::kNone ) { 395 if ( output == G4AnalysisOutput::kNone ) { 411 Warn("The file type " + value + "is not su 396 Warn("The file type " + value + "is not supported.\n" + 412 "The default type " + fDefaultFileTyp 397 "The default type " + fDefaultFileType + " will be used.", 413 fkClass, "SetDeafultFileType"); 398 fkClass, "SetDeafultFileType"); 414 return; 399 return; 415 } 400 } 416 401 417 fDefaultFileType = value; 402 fDefaultFileType = value; 418 } 403 } 419 404 420 //____________________________________________ 405 //_____________________________________________________________________________ 421 std::shared_ptr<G4VNtupleFileManager> 406 std::shared_ptr<G4VNtupleFileManager> 422 G4GenericFileManager::CreateNtupleFileManager( 407 G4GenericFileManager::CreateNtupleFileManager(G4AnalysisOutput output) 423 { 408 { 424 if ( ! GetFileManager(output) ) { 409 if ( ! GetFileManager(output) ) { 425 CreateFileManager(output); 410 CreateFileManager(output); 426 } 411 } 427 412 428 std::shared_ptr<G4VNtupleFileManager> vNtupl 413 std::shared_ptr<G4VNtupleFileManager> vNtupleFileManager = nullptr; 429 G4String failure; 414 G4String failure; 430 415 431 switch ( output ) { 416 switch ( output ) { 432 case G4AnalysisOutput::kCsv: { 417 case G4AnalysisOutput::kCsv: { 433 auto ntupleFileManager = std::make_share 418 auto ntupleFileManager = std::make_shared<G4CsvNtupleFileManager>(fState); 434 ntupleFileManager->SetFileManager(fCsvFi 419 ntupleFileManager->SetFileManager(fCsvFileManager); 435 vNtupleFileManager = ntupleFileManager; 420 vNtupleFileManager = ntupleFileManager; 436 break; 421 break; 437 } 422 } 438 case G4AnalysisOutput::kHdf5: { 423 case G4AnalysisOutput::kHdf5: { 439 #ifdef TOOLS_USE_HDF5 424 #ifdef TOOLS_USE_HDF5 440 auto ntupleFileManager = std::make_share 425 auto ntupleFileManager = std::make_shared<G4Hdf5NtupleFileManager>(fState); 441 ntupleFileManager->SetFileManager(fHdf5F 426 ntupleFileManager->SetFileManager(fHdf5FileManager); 442 vNtupleFileManager = ntupleFileManager; 427 vNtupleFileManager = ntupleFileManager; 443 #else 428 #else 444 failure = " Hdf5 is not available"; 429 failure = " Hdf5 is not available"; 445 #endif 430 #endif 446 break; 431 break; 447 } 432 } 448 case G4AnalysisOutput::kRoot: { 433 case G4AnalysisOutput::kRoot: { 449 auto ntupleFileManager = std::make_share 434 auto ntupleFileManager = std::make_shared<G4RootNtupleFileManager>(fState); 450 ntupleFileManager->SetFileManager(fRootF 435 ntupleFileManager->SetFileManager(fRootFileManager); 451 vNtupleFileManager = ntupleFileManager; 436 vNtupleFileManager = ntupleFileManager; 452 break; 437 break; 453 } 438 } 454 case G4AnalysisOutput::kXml: { 439 case G4AnalysisOutput::kXml: { 455 auto ntupleFileManager = std::make_share 440 auto ntupleFileManager = std::make_shared<G4XmlNtupleFileManager>(fState); 456 ntupleFileManager->SetFileManager(fXmlFi 441 ntupleFileManager->SetFileManager(fXmlFileManager); 457 vNtupleFileManager = ntupleFileManager; 442 vNtupleFileManager = ntupleFileManager; 458 break; 443 break; 459 } 444 } 460 case G4AnalysisOutput::kNone: 445 case G4AnalysisOutput::kNone: 461 break; 446 break; 462 } 447 } 463 448 464 if ( ! vNtupleFileManager ) { 449 if ( ! vNtupleFileManager ) { 465 Warn("Failed to create ntuple file manag 450 Warn("Failed to create ntuple file manager of " + 466 G4Analysis::GetOutputName(output) + 451 G4Analysis::GetOutputName(output) + " type.\n" + failure, 467 fkClass, "CreateNtupleFileManager") 452 fkClass, "CreateNtupleFileManager"); 468 } 453 } 469 454 470 return vNtupleFileManager; 455 return vNtupleFileManager; 471 } 456 } 472 457