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, 26/08/2021 (ivana 28 29 #include "G4AnalysisUtilities.hh" 30 #include "G4RootRFileDef.hh" 31 32 #include "tools/rroot/file" 33 #include "tools/rroot/rall" 34 #include "tools/rroot/streamers" 35 36 //____________________________________________ 37 template <typename HT> 38 inline 39 tools::rroot::buffer* G4RootHnRFileManager<HT> 40 const G4String& fileName, const G4String& di 41 { 42 // Get buffer for reading histogram or profile 43 // for a file specified by fileName; 44 // Open the file if it was not yet open 45 46 // Histograms and profiles are not saved per 47 G4bool isPerThread = false; 48 49 // Get or open a file 50 auto rfileTuple = fRFileManager->GetRFile(fi 51 if (rfileTuple == nullptr) { 52 if ( ! fRFileManager->OpenRFile(fileName, 53 return nullptr; 54 } 55 rfileTuple = fRFileManager->GetRFile(fileN 56 } 57 auto rfile = std::get<0>(*rfileTuple); 58 59 // Get or open a directory if dirName is def 60 tools::rroot::TDirectory* histoDirectory = n 61 if ( histoDirectory == nullptr ) { 62 // Retrieve directory only once as analysi 63 // 1 histo directory par file) 64 if ( ! dirName.empty() ) { 65 histoDirectory = tools::rroot::find_dir( 66 if ( histoDirectory != nullptr ) { 67 std::get<1>(*rfileTuple) = histoDirect 68 } 69 else { 70 G4Analysis::Warn( 71 "Directory " + dirName + " not found 72 fkClass, "ReadNtupleImpl"); 73 return nullptr; 74 } 75 } 76 } 77 78 // Get key 79 tools::rroot::key* key = nullptr; 80 if ( histoDirectory != nullptr ) { 81 key = histoDirectory->find_key(objectName) 82 } 83 else { 84 key = rfile->dir().find_key(objectName); 85 } 86 if (key == nullptr) { 87 G4Analysis::Warn( 88 "Key " + objectName + " for Histogram/Pr 89 fileName + ", directory " + dirName, fkC 90 return nullptr; 91 } 92 93 unsigned int size; 94 char* charBuffer = key->get_object_buffer(*r 95 96 if (charBuffer == nullptr) { 97 G4Analysis::Warn( 98 "Cannot get " + objectName + " in file " 99 fkClass, "GetBuffer"); 100 return nullptr; 101 } 102 103 auto verbose = false; 104 return new tools::rroot::buffer(G4cout, rfil 105 key->key_len 106 } 107 108 //____________________________________________ 109 template <> 110 inline 111 tools::histo::h1d* G4RootHnRFileManager<tools: 112 tools::rroot::buffer* buffer) 113 { 114 return tools::rroot::TH1D_stream(*buffer); 115 } 116 117 //____________________________________________ 118 template <> 119 inline 120 tools::histo::h2d* G4RootHnRFileManager<tools: 121 tools::rroot::buffer* buffer) 122 { 123 return tools::rroot::TH2D_stream(*buffer); 124 } 125 126 //____________________________________________ 127 template <> 128 inline 129 tools::histo::h3d* G4RootHnRFileManager<tools: 130 tools::rroot::buffer* buffer) 131 { 132 return tools::rroot::TH3D_stream(*buffer); 133 } 134 135 //____________________________________________ 136 template <> 137 inline 138 tools::histo::p1d* G4RootHnRFileManager<tools: 139 tools::rroot::buffer* buffer) 140 { 141 return tools::rroot::TProfile_stream(*buffer 142 } 143 144 //____________________________________________ 145 template <> 146 inline 147 tools::histo::p2d* G4RootHnRFileManager<tools: 148 tools::rroot::buffer* buffer) 149 { 150 return tools::rroot::TProfile2D_stream(*buff 151 } 152 153 //____________________________________________ 154 template <typename HT> 155 inline 156 HT* G4RootHnRFileManager<HT>::Read( 157 const G4String& htName, const G4String& file 158 G4bool /*isUserFileName*/) 159 { 160 auto buffer = GetBuffer(fileName, dirName, h 161 if ( ! buffer ) { 162 return nullptr; 163 } 164 165 auto ht = ReadT(buffer); 166 delete buffer; 167 168 if ( ! ht ) { 169 G4Analysis::Warn( 170 "Streaming " + htName + " in file " + fi 171 fkClass, "Read"); 172 return nullptr; 173 } 174 175 return ht; 176 } 177