2// ********************************************************************
3// * License and Disclaimer *
5// * The Geant4 software is copyright of the Copyright Holders of *
6// * the Geant4 Collaboration. It is provided under the terms and *
7// * conditions of the Geant4 Software License, included in the file *
8// * LICENSE and available at http://cern.ch/geant4/license . These *
9// * include a list of copyright holders. *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work make any representation or warranty, express or implied, *
14// * regarding this software system or assume any liability for its *
15// * use. Please see the license in the file LICENSE and URL above *
16// * for the full disclaimer and the limitation of liability. *
18// * This code implementation is the result of the scientific and *
19// * technical work of the GEANT4 collaboration. *
20// * By using, copying, modifying or distributing the software (or *
21// * any work based on the software) you agree to acknowledge its *
22// * use in resulting scientific publications, and indicate your *
23// * acceptance of all terms of the Geant4 Software license. *
24// ********************************************************************
27// Author: Ivana Hrivnacova, 26/08/2021 (ivana@ipno.in2p3.fr)
29#include "G4AnalysisUtilities.hh"
31#include "tools/rroot/file"
32#include "tools/rroot/rall"
33#include "tools/rroot/streamers"
35//_____________________________________________________________________________
38std::tuple<tools::rroot::buffer*, tools::rroot::TDirectory*>
39G4RootHnRFileManager<HT>::GetBuffer(
40 const G4String& fileName, const G4String& dirName, const G4String& objectName)
42// Get buffer for reading histogram or profile specified by objectNmae
43// for a file specified by fileName;
44// Open the file if it was not yet open
46 // Histograms and profiles are not saved per thread
47 G4bool isPerThread = false;
50 auto rfile = fRFileManager->GetRFile(fileName, isPerThread);
52 if ( ! fRFileManager->OpenRFile(fileName, isPerThread) ) {
53 return std::tuple(nullptr, nullptr);
55 rfile = fRFileManager->GetRFile(fileName, isPerThread);
59 tools::rroot::key* key = nullptr;
60 tools::rroot::TDirectory* newDir = nullptr;
61 if ( ! dirName.empty() ) {
62 newDir = tools::rroot::find_dir(rfile->dir(), dirName);
64 key = newDir->find_key(objectName);
68 "Directory " + dirName + " not found in file " + fileName + ".",
69 fkClass, "GetBuffer");
70 return std::tuple(nullptr, nullptr);
74 key = rfile->dir().find_key(objectName);
79 "Key " + objectName + " for Histogram/Profile not found in file " +
80 fileName + ", directory " + dirName, fkClass, "GetBuffer");
81 return std::tuple(nullptr, newDir);
85 char* charBuffer = key->get_object_buffer(*rfile, size);
89 "Cannot get " + objectName + " in file " + fileName,
90 fkClass, "GetBuffer");
91 return std::tuple(nullptr, newDir);
95 return std::tuple(new tools::rroot::buffer(G4cout, rfile->byte_swap(), size, charBuffer,
96 key->key_length(), verbose), newDir);
99//_____________________________________________________________________________
102tools::histo::h1d* G4RootHnRFileManager<tools::histo::h1d>::ReadT(
103 tools::rroot::buffer* buffer)
105 return tools::rroot::TH1D_stream(*buffer);
108//_____________________________________________________________________________
111tools::histo::h2d* G4RootHnRFileManager<tools::histo::h2d>::ReadT(
112 tools::rroot::buffer* buffer)
114 return tools::rroot::TH2D_stream(*buffer);
117//_____________________________________________________________________________
120tools::histo::h3d* G4RootHnRFileManager<tools::histo::h3d>::ReadT(
121 tools::rroot::buffer* buffer)
123 return tools::rroot::TH3D_stream(*buffer);
126//_____________________________________________________________________________
129tools::histo::p1d* G4RootHnRFileManager<tools::histo::p1d>::ReadT(
130 tools::rroot::buffer* buffer)
132 return tools::rroot::TProfile_stream(*buffer);
135//_____________________________________________________________________________
138tools::histo::p2d* G4RootHnRFileManager<tools::histo::p2d>::ReadT(
139 tools::rroot::buffer* buffer)
141 return tools::rroot::TProfile2D_stream(*buffer);
144//_____________________________________________________________________________
145template <typename HT>
147HT* G4RootHnRFileManager<HT>::Read(
148 const G4String& htName, const G4String& fileName, const G4String& dirName,
149 G4bool /*isUserFileName*/)
151 auto [buffer, newDir] = GetBuffer(fileName, dirName, htName);
157 auto ht = ReadT(buffer);
163 "Streaming " + htName + " in file " + fileName + " failed.",