Geant4 Cross Reference |
1 // 1 2 // ******************************************* 3 // * License and Disclaimer 4 // * 5 // * The Geant4 software is copyright of th 6 // * the Geant4 Collaboration. It is provided 7 // * conditions of the Geant4 Software License 8 // * LICENSE and available at http://cern.ch/ 9 // * include a list of copyright holders. 10 // * 11 // * Neither the authors of this software syst 12 // * institutes,nor the agencies providing fin 13 // * work make any representation or warran 14 // * regarding this software system or assum 15 // * use. Please see the license in the file 16 // * for the full disclaimer and the limitatio 17 // * 18 // * This code implementation is the result 19 // * technical work of the GEANT4 collaboratio 20 // * By using, copying, modifying or distri 21 // * any work based on the software) you ag 22 // * use in resulting scientific publicati 23 // * acceptance of all terms of the Geant4 Sof 24 // ******************************************* 25 // 26 27 // Author: Ivana Hrivnacova, 09/04/2014 (ivana 28 29 #include "G4RootRNtupleManager.hh" 30 #include "G4RootRFileManager.hh" 31 #include "G4AnalysisManagerState.hh" 32 #include "G4AnalysisUtilities.hh" 33 34 #include "tools/rroot/file" 35 #include "tools/rroot/rall" 36 #include "tools/rroot/streamers" 37 #include "tools/rroot/fac" 38 #include "tools/rroot/tree" 39 40 using namespace G4Analysis; 41 42 //____________________________________________ 43 G4RootRNtupleManager::G4RootRNtupleManager(con 44 : G4TRNtupleManager<tools::rroot::ntuple>(sta 45 {} 46 47 // 48 // private methods 49 // 50 51 //____________________________________________ 52 G4int G4RootRNtupleManager::ReadNtupleImpl(con 53 con 54 con 55 G4b 56 { 57 Message(kVL4, "read", "ntuple", ntupleName); 58 59 // Ntuples are saved per thread 60 // but do not apply the thread suffix if fil 61 auto isPerThread = true; 62 if ( isUserFileName ) isPerThread = false; 63 64 // Get or open a file 65 auto rfileTuple = fFileManager->GetRFile(fil 66 if (rfileTuple == nullptr) { 67 if ( ! fFileManager->OpenRFile(fileName, i 68 rfileTuple = fFileManager->GetRFile(fileNa 69 } 70 auto rfile = std::get<0>(*rfileTuple); 71 72 // Get or open a directory if dirName is def 73 tools::rroot::TDirectory* ntupleDirectory = 74 if ( ntupleDirectory == nullptr ) { 75 // Retrieve directory only once as analysi 76 // 1 ntuple directory par file) 77 if ( ! dirName.empty() ) { 78 ntupleDirectory = tools::rroot::find_dir 79 if ( ntupleDirectory != nullptr ) { 80 std::get<2>(*rfileTuple) = ntupleDirec 81 } 82 else { 83 G4Analysis::Warn( 84 "Directory " + dirName + " not found 85 fkClass, "ReadNtupleImpl"); 86 return kInvalidId; 87 } 88 } 89 } 90 91 // Get key 92 tools::rroot::key* key = nullptr; 93 if ( ntupleDirectory != nullptr ) { 94 key = ntupleDirectory->find_key(ntupleName 95 } 96 else { 97 key = rfile->dir().find_key(ntupleName); 98 } 99 if (key == nullptr) { 100 Warn("Key " + ntupleName + " for Ntuple no 101 ", directory " + dirName, fkClass, "Read 102 return kInvalidId; 103 } 104 105 unsigned int size; 106 char* charBuffer = key->get_object_buffer(*r 107 if (charBuffer == nullptr) { 108 Warn("Cannot get data buffer for Ntuple " 109 " in file " + fileName, fkClass, "Rea 110 return kInvalidId; 111 } 112 113 auto verbose = false; 114 auto buffer 115 = new tools::rroot::buffer(G4cout, rfile-> 116 key->key_length 117 buffer->set_map_objs(true); 118 119 auto fac = new tools::rroot::fac(G4cout); 120 121 auto tree = new tools::rroot::tree(*rfile, * 122 if ( ! tree->stream(*buffer) ) { 123 Warn("TTree streaming failed for Ntuple " 124 " in file " + fileName, 125 fkClass, "ReadNtupleImpl"); 126 127 delete buffer; 128 delete tree; 129 return kInvalidId; 130 } 131 132 auto rntuple = new tools::rroot::ntuple(*tr 133 auto rntupleDescription = new G4TRNtupleDesc 134 135 auto id = SetNtuple(rntupleDescription); 136 137 138 Message(kVL2, "read", "ntuple", ntupleName, 139 140 return id; 141 } 142 143 //____________________________________________ 144 G4bool G4RootRNtupleManager::GetTNtupleRow( 145 G4TRNtupleDescription<tools::rroot::ntuple>* 146 { 147 auto ntuple = ntupleDescription->fNtuple; 148 auto ntupleBinding = ntupleDescription->fNtu 149 150 G4bool isInitialized = ntupleDescription->fI 151 if ( ! isInitialized ) { 152 153 if ( ! ntuple->initialize(G4cout, *ntupleB 154 Warn("Ntuple initialization failed !!", 155 return false; 156 } 157 ntupleDescription->fIsInitialized = true; 158 ntuple->start(); 159 } 160 161 auto next = ntuple->next(); 162 if ( next ) { 163 if ( ! ntuple->get_row() ) { 164 Warn("Ntuple get_row() failed !!", fkCla 165 return false; 166 } 167 } 168 169 return next; 170 } 171