Geant4-11
G4RootHnFileManager.icc
Go to the documentation of this file.
1//
2// ********************************************************************
3// * License and Disclaimer *
4// * *
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. *
10// * *
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. *
17// * *
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// ********************************************************************
25//
26
27// Author: Ivana Hrivnacova, 15/09/2020 (ivana@ipno.in2p3.fr)
28
29#include "G4AnalysisUtilities.hh"
30
31#include "tools/wroot/to"
32#include "tools/wroot/file"
33#include "tools/zlib"
34
35//_____________________________________________________________________________
36template <typename HT>
37G4bool G4RootHnFileManager<HT>::Write(
38 tools::wroot::directory* directory, HT* ht, const G4String& htName)
39{
40 // write histpgram
41 return to(*directory, *ht, htName);
42}
43
44//_____________________________________________________________________________
45template <typename HT>
46G4bool G4RootHnFileManager<HT>::WriteExtra(
47 HT* ht, const G4String& htName, const G4String& fileName)
48{
49 auto result = true;
50
51 // // create a new file
52 auto rfile = new tools::wroot::file(G4cout, fileName);
53 // TO DO
54 // rfile->add_ziper('Z', tools::compress_buffer);
55 // rfile->set_compression(fState.GetCompressionLevel());
56 if ( ! rfile ) return false;
57
58 // no directory supported in this mode
59 auto hdirectory = &(rfile->dir());
60 if ( ! hdirectory ) return false;
61
62 // write histo
63 result &= Write(hdirectory, ht, htName);
64
65 // write file
66 unsigned int n;
67 result &= rfile->write(n);
68
69 // close file
70 rfile->close();
71
72 return result;
73}
74
75//_____________________________________________________________________________
76template <typename HT>
77G4bool G4RootHnFileManager<HT>::Write(
78 HT* ht, const G4String& htName, G4String& fileName)
79{
80 if ( fileName.empty()) {
81 // should not happen
82 G4cerr << "!!! Root file name not defined." << G4endl;
83 G4cerr << "!!! Write " << htName << " failed." << G4endl;
84 return false;
85 }
86
87 auto hdirectory = std::get<1>(*fFileManager->GetTFile(fileName));
88 if ( hdirectory == nullptr ) {
89 G4Analysis::Warn(
90 "Failed to get Root file " + fileName + " histo directory.",
91 fkClass, "Write");
92 return false;
93 }
94
95 auto result = Write(hdirectory, ht, htName);
96 fFileManager->LockDirectoryNames();
97 return result;
98}