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, 18/06/2013 (ivan 27 // Author: Ivana Hrivnacova, 18/06/2013 (ivana@ipno.in2p3.fr) 28 28 29 #include "G4CsvAnalysisManager.hh" 29 #include "G4CsvAnalysisManager.hh" 30 #include "G4CsvFileManager.hh" 30 #include "G4CsvFileManager.hh" 31 #include "G4CsvNtupleFileManager.hh" 31 #include "G4CsvNtupleFileManager.hh" 32 #include "G4AnalysisManagerState.hh" 32 #include "G4AnalysisManagerState.hh" 33 #include "G4AnalysisUtilities.hh" 33 #include "G4AnalysisUtilities.hh" 34 #include "G4UnitsTable.hh" 34 #include "G4UnitsTable.hh" 35 #include "G4ThreadLocalSingleton.hh" 35 #include "G4ThreadLocalSingleton.hh" 36 #include "G4Threading.hh" 36 #include "G4Threading.hh" 37 37 38 using namespace G4Analysis; 38 using namespace G4Analysis; 39 39 40 //____________________________________________ 40 //_____________________________________________________________________________ 41 G4CsvAnalysisManager* G4CsvAnalysisManager::In 41 G4CsvAnalysisManager* G4CsvAnalysisManager::Instance() 42 { 42 { 43 static G4ThreadLocalSingleton<G4CsvAnalysisM 43 static G4ThreadLocalSingleton<G4CsvAnalysisManager> instance; 44 fgIsInstance = true; 44 fgIsInstance = true; 45 return instance.Instance(); 45 return instance.Instance(); 46 } 46 } 47 47 48 //____________________________________________ 48 //_____________________________________________________________________________ 49 G4bool G4CsvAnalysisManager::IsInstance() 49 G4bool G4CsvAnalysisManager::IsInstance() 50 { 50 { 51 return fgIsInstance; 51 return fgIsInstance; 52 } 52 } 53 53 54 //____________________________________________ 54 //_____________________________________________________________________________ 55 G4CsvAnalysisManager::G4CsvAnalysisManager() 55 G4CsvAnalysisManager::G4CsvAnalysisManager() 56 : G4ToolsAnalysisManager("Csv") 56 : G4ToolsAnalysisManager("Csv") 57 { 57 { >> 58 if ( ! G4Threading::IsWorkerThread() ) fgMasterInstance = this; >> 59 58 // File Manager 60 // File Manager 59 auto fileManager = std::make_shared<G4CsvFil << 61 fFileManager = std::make_shared<G4CsvFileManager>(fState); 60 SetFileManager(fileManager); << 62 SetFileManager(fFileManager); 61 63 62 // Ntuple file manager 64 // Ntuple file manager 63 fNtupleFileManager = std::make_shared<G4CsvN 65 fNtupleFileManager = std::make_shared<G4CsvNtupleFileManager>(fState); 64 SetNtupleFileManager(fNtupleFileManager); << 66 fNtupleFileManager->SetFileManager(fFileManager); 65 fNtupleFileManager->SetFileManager(std::move << 66 fNtupleFileManager->SetBookingManager(fNtupl 67 fNtupleFileManager->SetBookingManager(fNtupleBookingManager); 67 } 68 } 68 69 69 //____________________________________________ 70 //_____________________________________________________________________________ 70 G4CsvAnalysisManager::~G4CsvAnalysisManager() 71 G4CsvAnalysisManager::~G4CsvAnalysisManager() 71 { 72 { >> 73 if ( fState.GetIsMaster() ) fgMasterInstance = nullptr; 72 fgIsInstance = false; 74 fgIsInstance = false; >> 75 } >> 76 >> 77 // >> 78 // protected methods >> 79 // >> 80 >> 81 //_____________________________________________________________________________ >> 82 G4bool G4CsvAnalysisManager::OpenFileImpl(const G4String& fileName) >> 83 { >> 84 // Create ntuple manager(s) >> 85 // and set it to base class which takes then their ownership >> 86 SetNtupleManager(fNtupleFileManager->CreateNtupleManager()); >> 87 >> 88 auto result = true; >> 89 >> 90 // Save file name in file manager >> 91 result &= fFileManager->OpenFile(fileName); >> 92 >> 93 // Open ntuple files and create ntuples from bookings >> 94 result &= fNtupleFileManager->ActionAtOpenFile(fFileManager->GetFullFileName()); >> 95 >> 96 return result; >> 97 } >> 98 >> 99 //_____________________________________________________________________________ >> 100 G4bool G4CsvAnalysisManager::WriteImpl() >> 101 { >> 102 // nothing to be done for Csv file >> 103 auto result = true; >> 104 >> 105 Message(kVL4, "write", "files"); >> 106 >> 107 if ( G4Threading::IsWorkerThread() ) { >> 108 result &= G4ToolsAnalysisManager::Merge(); >> 109 } >> 110 else { >> 111 // Write all histograms/profile on master >> 112 result &= G4ToolsAnalysisManager::WriteImpl(); >> 113 } >> 114 >> 115 // Ntuples >> 116 // Nothing to be done >> 117 >> 118 // Write ASCII if activated >> 119 // Not available >> 120 //if ( IsAscii() ) { >> 121 // result &= WriteAscii(); >> 122 //} >> 123 >> 124 Message(kVL3, "write", "files", "", result); >> 125 >> 126 return result; >> 127 } >> 128 >> 129 //_____________________________________________________________________________ >> 130 G4bool G4CsvAnalysisManager::CloseFileImpl(G4bool reset) >> 131 { >> 132 auto result = true; >> 133 >> 134 // close open files >> 135 result &= fFileManager->CloseFiles(); >> 136 >> 137 // Histogram and profile files are created/closed indivudually for each >> 138 // object in WriteT function >> 139 >> 140 result &= fNtupleFileManager->ActionAtCloseFile(reset); >> 141 >> 142 // Reset data >> 143 if ( reset ) { >> 144 result = Reset(); >> 145 if ( ! result ) { >> 146 Warn("Resetting data failed", fkClass, "CloseFileImpl"); >> 147 } >> 148 } >> 149 >> 150 return result; >> 151 } >> 152 >> 153 //_____________________________________________________________________________ >> 154 G4bool G4CsvAnalysisManager::ResetImpl() >> 155 { >> 156 // Reset histograms and ntuple >> 157 >> 158 auto result = true; >> 159 >> 160 result &= G4ToolsAnalysisManager::ResetImpl(); >> 161 if ( fNtupleFileManager != nullptr ) { >> 162 result &= fNtupleFileManager->Reset(); >> 163 } >> 164 >> 165 return result; 73 } 166 } 74 167