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 // $Id: G4RootNtupleManager.cc 70604 2013-06-03 11:27:06Z ihrivnac $ 26 27 27 // Author: Ivana Hrivnacova, 18/06/2013 (ivan 28 // Author: Ivana Hrivnacova, 18/06/2013 (ivana@ipno.in2p3.fr) 28 29 29 #include "G4RootNtupleManager.hh" 30 #include "G4RootNtupleManager.hh" 30 #include "G4RootMainNtupleManager.hh" << 31 #include "G4RootFileManager.hh" << 32 #include "G4AnalysisManagerState.hh" 31 #include "G4AnalysisManagerState.hh" 33 #include "G4AnalysisUtilities.hh" 32 #include "G4AnalysisUtilities.hh" 34 33 35 #include "tools/wroot/file" 34 #include "tools/wroot/file" 36 35 37 using namespace G4Analysis; 36 using namespace G4Analysis; 38 using std::to_string; << 39 37 40 //____________________________________________ 38 //_____________________________________________________________________________ 41 G4RootNtupleManager::G4RootNtupleManager(const << 39 G4RootNtupleManager::G4RootNtupleManager(const G4AnalysisManagerState& state) 42 const std::shared_ptr<G << 40 : G4TNtupleManager<tools::wroot::ntuple>(state), 43 G4int nofMainManagers, << 41 fNtupleDirectory(nullptr) 44 G4bool rowWise, G4bool << 42 {} 45 : G4TNtupleManager<tools::wroot::ntuple, G4Ro << 46 fRowWise(rowWise), << 47 fRowMode(rowMode) << 48 { << 49 for ( G4int i=0; i<nofMainManagers; ++i) { << 50 auto fileNumber = i; << 51 if ( (i == 0) && (nofFiles == 0) ) { << 52 // the main ntuple file will be merged i << 53 fileNumber = -1; << 54 } << 55 fMainNtupleManagers.push_back( << 56 std::make_shared<G4RootMainNtupleManager << 57 this, bookingManger, rowWise, fileNumb << 58 } << 59 } << 60 43 61 // << 44 //_____________________________________________________________________________ >> 45 G4RootNtupleManager::~G4RootNtupleManager() >> 46 {} >> 47 >> 48 // 62 // private methods 49 // private methods 63 // 50 // 64 51 65 //____________________________________________ 52 //_____________________________________________________________________________ 66 void G4RootNtupleManager::CreateTNtupleFromBoo << 53 void G4RootNtupleManager::CreateTNtuple( 67 RootNtupleDescription* ntupleDescription) << 54 G4TNtupleDescription<tools::wroot::ntuple>* ntupleDescription, 68 { << 55 const G4String& name, const G4String& title) 69 if (fMainNtupleManagers.size() == 0u) { << 56 { 70 // No merging << 57 // Create ntuple if the file is open 71 if (ntupleDescription->GetNtuple() != null << 58 if ( fNtupleDirectory ) { 72 Warn("Cannot create ntuple. Ntuple alrea << 59 ntupleDescription->fNtuple 73 fkClass, "CreateTNtupleFromBooking"); << 60 = new tools::wroot::ntuple(*fNtupleDirectory, name, title); 74 return; << 61 ntupleDescription->fIsNtupleOwner = false; 75 } << 76 << 77 // Create ntuple file from ntuple descript << 78 auto ntupleFile = fFileManager->CreateNtup << 79 if ( ! ntupleFile ) { << 80 Warn("Cannot create ntuple. Ntuple file << 81 fkClass, "CreateTNtupleFromBooking"); << 82 return; << 83 } << 84 << 85 auto directory = std::get<2>(*ntupleFile); << 86 ntupleDescription->SetNtuple( << 87 new tools::wroot::ntuple( << 88 *directory, ntupleDescription->Get << 89 << 90 auto basketSize = fFileManager->GetBasketS << 91 ntupleDescription->GetNtuple()->set_basket << 92 ntupleDescription->SetIsNtupleOwner(false) << 93 // ntuple object is deleted automat 62 // ntuple object is deleted automatically when closing a file >> 63 fNtupleVector.push_back(ntupleDescription->fNtuple); 94 } 64 } 95 else { << 96 // Merging activated << 97 for ( const auto& manager : fMainNtupleMan << 98 manager->SetFirstId(fFirstId); << 99 manager->CreateNtuple(ntupleDescription) << 100 } << 101 } << 102 } << 103 << 104 //____________________________________________ << 105 void G4RootNtupleManager::FinishTNtuple( << 106 RootNtupleDescription* /*ntupleDescription*/ << 107 { << 108 // nothing to be done << 109 } << 110 << 111 //____________________________________________ << 112 G4bool G4RootNtupleManager::Reset() << 113 { << 114 G4TNtupleManager<tools::wroot::ntuple, G4Roo << 115 // this will clear ntuple vector << 116 << 117 auto result = true; << 118 << 119 for ( const auto& manager : fMainNtupleManag << 120 result &= manager->Reset(); << 121 } << 122 << 123 return result; << 124 } << 125 << 126 //____________________________________________ << 127 void G4RootNtupleManager::Clear() << 128 { << 129 G4TNtupleManager<tools::wroot::ntuple, G4Roo << 130 // this will clear ntuple vector << 131 << 132 for ( const auto& manager : fMainNtupleManag << 133 manager->ClearData(); << 134 } << 135 } << 136 << 137 //____________________________________________ << 138 G4bool G4RootNtupleManager::Delete(G4int id) << 139 { << 140 auto result = G4TNtupleManager<tools::wroot: << 141 << 142 for ( const auto& manager : fMainNtupleManag << 143 result &= manager->Delete(id); << 144 } << 145 << 146 return result; << 147 } << 148 << 149 //____________________________________________ << 150 G4bool G4RootNtupleManager::Merge() << 151 { << 152 auto result = true; << 153 << 154 for ( const auto& manager : fMainNtupleManag << 155 result &= manager->Merge(); << 156 } << 157 << 158 return result; << 159 } 65 } 160 66 161 //____________________________________________ 67 //_____________________________________________________________________________ 162 void G4RootNtupleManager::SetFileManager( << 68 void G4RootNtupleManager::CreateTNtupleFromBooking( 163 const std::shared_ptr<G4RootFileManager>& fi << 69 G4TNtupleDescription<tools::wroot::ntuple>* ntupleDescription) 164 { << 165 fFileManager = fileManager; << 166 << 167 for ( const auto& manager : fMainNtupleManag << 168 manager->SetFileManager(fileManager); << 169 } << 170 } << 171 << 172 //____________________________________________ << 173 void G4RootNtupleManager::SetNtupleRowWise(G4b << 174 { << 175 // Set rowWise mode and propagate it to main n << 176 << 177 fRowWise = rowWise; << 178 fRowMode = rowMode; << 179 << 180 for (auto& mainNtupleManager : fMainNtupleMa << 181 mainNtupleManager->SetRowWise(rowWise); << 182 } << 183 } << 184 << 185 //____________________________________________ << 186 void G4RootNtupleManager::SetNewCycle(G4bool v << 187 { << 188 G4TNtupleManager<tools::wroot::ntuple, G4Roo << 189 << 190 for ( const auto& manager : fMainNtupleManag << 191 manager->SetNewCycle(value); << 192 } << 193 } << 194 << 195 //____________________________________________ << 196 std::shared_ptr<G4RootMainNtupleManager> << 197 G4RootNtupleManager::GetMainNtupleManager(G4in << 198 { << 199 if ( index < 0 || index >= G4int(fMainNtuple << 200 Warn("main ntuple manager " + to_string(in << 201 fkClass, "GetMainNtupleManager"); << 202 return nullptr; << 203 } << 204 << 205 return fMainNtupleManagers[index]; << 206 } << 207 << 208 //____________________________________________ << 209 unsigned int G4RootNtupleManager::GetBasketSiz << 210 { 70 { 211 if ( ! fFileManager ) { << 71 ntupleDescription->fNtuple 212 Warn("File manager must be defined first." << 72 = new tools::wroot::ntuple( 213 return 0; << 73 *fNtupleDirectory, ntupleDescription->fNtupleBooking); 214 } << 74 ntupleDescription->fIsNtupleOwner = false; 215 << 75 // ntuple object is deleted automatically when closing a file 216 return fFileManager->GetBasketSize(); << 76 fNtupleVector.push_back(ntupleDescription->fNtuple); 217 } 77 } 218 78 219 //____________________________________________ 79 //_____________________________________________________________________________ 220 unsigned int G4RootNtupleManager::GetBasketEnt << 80 void G4RootNtupleManager::FinishTNtuple( >> 81 G4TNtupleDescription<tools::wroot::ntuple>* /*ntupleDescription*/) 221 { 82 { 222 if ( ! fFileManager ) { << 83 // nothing to be done here 223 Warn("File manager must be defined first." << 224 return 0; << 225 } << 226 << 227 return fFileManager->GetBasketEntries(); << 228 } 84 } 229 85