Geant4-11
G4CsvAnalysisManager.cc
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, 18/06/2013 (ivana@ipno.in2p3.fr)
28
30#include "G4CsvFileManager.hh"
34#include "G4UnitsTable.hh"
36#include "G4Threading.hh"
37
38using namespace G4Analysis;
39
40//_____________________________________________________________________________
42{
44 fgIsInstance = true;
45 return instance.Instance();
46}
47
48//_____________________________________________________________________________
50{
51 return fgIsInstance;
52}
53
54//_____________________________________________________________________________
57{
59
60 // File Manager
61 fFileManager = std::make_shared<G4CsvFileManager>(fState);
63
64 // Ntuple file manager
65 fNtupleFileManager = std::make_shared<G4CsvNtupleFileManager>(fState);
66 fNtupleFileManager->SetFileManager(fFileManager);
67 fNtupleFileManager->SetBookingManager(fNtupleBookingManager);
68}
69
70//_____________________________________________________________________________
72{
73 if ( fState.GetIsMaster() ) fgMasterInstance = nullptr;
74 fgIsInstance = false;
75}
76
77//
78// protected methods
79//
80
81//_____________________________________________________________________________
83{
84 // Create ntuple manager(s)
85 // and set it to base class which takes then their ownership
86 SetNtupleManager(fNtupleFileManager->CreateNtupleManager());
87
88 auto result = true;
89
90 // Save file name in file manager
91 result &= fFileManager->OpenFile(fileName);
92
93 // Open ntuple files and create ntuples from bookings
94 result &= fNtupleFileManager->ActionAtOpenFile(fFileManager->GetFullFileName());
95
96 return result;
97}
98
99//_____________________________________________________________________________
101{
102 // nothing to be done for Csv file
103 auto result = true;
104
105 Message(kVL4, "write", "files");
106
109 }
110 else {
111 // Write all histograms/profile on master
113 }
114
115 // Ntuples
116 // Nothing to be done
117
118 // Write ASCII if activated
119 // Not available
120 //if ( IsAscii() ) {
121 // result &= WriteAscii();
122 //}
123
124 Message(kVL3, "write", "files", "", result);
125
126 return result;
127}
128
129//_____________________________________________________________________________
131{
132 auto result = true;
133
134 // close open files
135 result &= fFileManager->CloseFiles();
136
137 // Histogram and profile files are created/closed indivudually for each
138 // object in WriteT function
139
140 result &= fNtupleFileManager->ActionAtCloseFile(reset);
141
142 // Reset data
143 if ( reset ) {
144 result = Reset();
145 if ( ! result ) {
146 Warn("Resetting data failed", fkClass, "CloseFileImpl");
147 }
148 }
149
150 return result;
151}
152
153//_____________________________________________________________________________
155{
156// Reset histograms and ntuple
157
158 auto result = true;
159
161 if ( fNtupleFileManager != nullptr ) {
162 result &= fNtupleFileManager->Reset();
163 }
164
165 return result;
166}
bool G4bool
Definition: G4Types.hh:86
virtual G4bool OpenFileImpl(const G4String &fileName) final
static G4CsvAnalysisManager * Instance()
virtual G4bool CloseFileImpl(G4bool reset) final
virtual G4bool ResetImpl() final
static constexpr std::string_view fkClass
virtual G4bool WriteImpl() final
std::shared_ptr< G4CsvFileManager > fFileManager
std::shared_ptr< G4CsvNtupleFileManager > fNtupleFileManager
static G4ThreadLocal G4bool fgIsInstance
static G4CsvAnalysisManager * fgMasterInstance
virtual G4bool ResetImpl() override
virtual G4bool WriteImpl() override
std::shared_ptr< G4NtupleBookingManager > fNtupleBookingManager
void Message(G4int level, const G4String &action, const G4String &objectType, const G4String &objectName="", G4bool success=true) const
G4AnalysisManagerState fState
void SetFileManager(std::shared_ptr< G4VFileManager > fileManager)
void SetNtupleManager(std::shared_ptr< G4VNtupleManager > ntupleManager)
constexpr G4int kVL3
constexpr G4int kVL4
void Warn(const G4String &message, const std::string_view inClass, const std::string_view inFunction)
G4bool IsWorkerThread()
Definition: G4Threading.cc:123