Warning, file /include/Geant4/G4RootHnRFileManager.icc was not indexed
or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029 #include "G4AnalysisUtilities.hh"
0030 #include "G4RootRFileDef.hh"
0031
0032 #include "tools/rroot/file"
0033 #include "tools/rroot/rall"
0034 #include "tools/rroot/streamers"
0035
0036
0037 template <typename HT>
0038 inline
0039 tools::rroot::buffer* G4RootHnRFileManager<HT>::GetBuffer(
0040 const G4String& fileName, const G4String& dirName, const G4String& objectName)
0041 {
0042
0043
0044
0045
0046
0047 G4bool isPerThread = false;
0048
0049
0050 auto rfileTuple = fRFileManager->GetRFile(fileName, isPerThread);
0051 if (rfileTuple == nullptr) {
0052 if ( ! fRFileManager->OpenRFile(fileName, isPerThread) ) {
0053 return nullptr;
0054 }
0055 rfileTuple = fRFileManager->GetRFile(fileName, isPerThread);
0056 }
0057 auto rfile = std::get<0>(*rfileTuple);
0058
0059
0060 tools::rroot::TDirectory* histoDirectory = nullptr;
0061 if ( histoDirectory == nullptr ) {
0062
0063
0064 if ( ! dirName.empty() ) {
0065 histoDirectory = tools::rroot::find_dir(rfile->dir(), dirName);
0066 if ( histoDirectory != nullptr ) {
0067 std::get<1>(*rfileTuple) = histoDirectory;
0068 }
0069 else {
0070 G4Analysis::Warn(
0071 "Directory " + dirName + " not found in file " + fileName + ".",
0072 fkClass, "ReadNtupleImpl");
0073 return nullptr;
0074 }
0075 }
0076 }
0077
0078
0079 tools::rroot::key* key = nullptr;
0080 if ( histoDirectory != nullptr ) {
0081 key = histoDirectory->find_key(objectName);
0082 }
0083 else {
0084 key = rfile->dir().find_key(objectName);
0085 }
0086 if (key == nullptr) {
0087 G4Analysis::Warn(
0088 "Key " + objectName + " for Histogram/Profile not found in file " +
0089 fileName + ", directory " + dirName, fkClass, "GetBuffer");
0090 return nullptr;
0091 }
0092
0093 unsigned int size;
0094 char* charBuffer = key->get_object_buffer(*rfile, size);
0095
0096 if (charBuffer == nullptr) {
0097 G4Analysis::Warn(
0098 "Cannot get " + objectName + " in file " + fileName,
0099 fkClass, "GetBuffer");
0100 return nullptr;
0101 }
0102
0103 auto verbose = false;
0104 return new tools::rroot::buffer(G4cout, rfile->byte_swap(), size, charBuffer,
0105 key->key_length(), verbose);
0106 }
0107
0108
0109 template <>
0110 inline
0111 tools::histo::h1d* G4RootHnRFileManager<tools::histo::h1d>::ReadT(
0112 tools::rroot::buffer* buffer)
0113 {
0114 return tools::rroot::TH1D_stream(*buffer);
0115 }
0116
0117
0118 template <>
0119 inline
0120 tools::histo::h2d* G4RootHnRFileManager<tools::histo::h2d>::ReadT(
0121 tools::rroot::buffer* buffer)
0122 {
0123 return tools::rroot::TH2D_stream(*buffer);
0124 }
0125
0126
0127 template <>
0128 inline
0129 tools::histo::h3d* G4RootHnRFileManager<tools::histo::h3d>::ReadT(
0130 tools::rroot::buffer* buffer)
0131 {
0132 return tools::rroot::TH3D_stream(*buffer);
0133 }
0134
0135
0136 template <>
0137 inline
0138 tools::histo::p1d* G4RootHnRFileManager<tools::histo::p1d>::ReadT(
0139 tools::rroot::buffer* buffer)
0140 {
0141 return tools::rroot::TProfile_stream(*buffer);
0142 }
0143
0144
0145 template <>
0146 inline
0147 tools::histo::p2d* G4RootHnRFileManager<tools::histo::p2d>::ReadT(
0148 tools::rroot::buffer* buffer)
0149 {
0150 return tools::rroot::TProfile2D_stream(*buffer);
0151 }
0152
0153
0154 template <typename HT>
0155 inline
0156 HT* G4RootHnRFileManager<HT>::Read(
0157 const G4String& htName, const G4String& fileName, const G4String& dirName,
0158 G4bool )
0159 {
0160 auto buffer = GetBuffer(fileName, dirName, htName);
0161 if ( ! buffer ) {
0162 return nullptr;
0163 }
0164
0165 auto ht = ReadT(buffer);
0166 delete buffer;
0167
0168 if ( ! ht ) {
0169 G4Analysis::Warn(
0170 "Streaming " + htName + " in file " + fileName + " failed.",
0171 fkClass, "Read");
0172 return nullptr;
0173 }
0174
0175 return ht;
0176 }