Geant4  10.00.p01
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 // $Id: G4CsvAnalysisManager.cc 74257 2013-10-02 14:24:55Z gcosmo $
27 
28 // Author: Ivana Hrivnacova, 18/06/2013 (ivana@ipno.in2p3.fr)
29 
30 #include "G4CsvAnalysisManager.hh"
31 #include "G4CsvFileManager.hh"
32 #include "G4H1DummyManager.hh"
33 #include "G4H2DummyManager.hh"
34 #include "G4CsvNtupleManager.hh"
35 #include "G4AnalysisVerbose.hh"
36 #include "G4UnitsTable.hh"
37 #include "G4Threading.hh"
38 #include "G4AutoLock.hh"
39 
40 #include <iostream>
41 
44 
45 //_____________________________________________________________________________
47 {
48  if ( fgInstance == 0 ) {
49  G4bool isMaster = ! G4Threading::IsWorkerThread();
50  fgInstance = new G4CsvAnalysisManager(isMaster);
51  }
52 
53  return fgInstance;
54 }
55 
56 //_____________________________________________________________________________
58  : G4VAnalysisManager("Csv", isMaster),
59  fNtupleManager(0),
60  fFileManager(0)
61 {
62  if ( ( isMaster && fgMasterInstance ) || ( fgInstance ) ) {
63  G4ExceptionDescription description;
64  description << " "
65  << "G4CsvAnalysisManager already exists."
66  << "Cannot create another instance.";
67  G4Exception("G4CsvAnalysisManager::G4CsvAnalysisManager()",
68  "Analysis_F001", FatalException, description);
69  }
70 
71  if ( isMaster ) fgMasterInstance = this;
72  fgInstance = this;
73 
74  // Create managers
80  // The managers will be deleted by the base class
81 
82  // Set managers to base class
87 }
88 
89 //_____________________________________________________________________________
91 {
92  if ( fState.GetIsMaster() ) fgMasterInstance = 0;
93  fgInstance = 0;
94 }
95 
96 //
97 // private methods
98 //
99 
100 //_____________________________________________________________________________
102 {
103  const std::vector<G4CsvNtupleDescription*>& ntupleVector
105 
106  // Close ntuple files
107  std::vector<G4CsvNtupleDescription*>::const_iterator it;
108  for (it = ntupleVector.begin(); it != ntupleVector.end(); it++ ) {
110  }
111 
112  return true;
113 }
114 
115 
116 //
117 // protected methods
118 //
119 
120 //_____________________________________________________________________________
122 {
123  G4bool finalResult = true;
124 
125  // Only book file name in file manager
126  G4bool result = fFileManager->OpenFile(fileName);
127  finalResult = finalResult && result;
128 
129  // Create ntuples if they are booked
130  // (The files will be created with creating ntuples)
132 
133 
134  return finalResult;
135 }
136 
137 //_____________________________________________________________________________
139 {
140  // nothing to be done for Csv file
141  G4bool result = true;
142 
143  // Write ASCII if activated
144  // Not available
145  //if ( IsAscii() ) {
146  // result = WriteAscii();
147  //}
148 
149  return result;
150 }
151 
152 //_____________________________________________________________________________
154 {
155  G4bool finalResult = true;
156 
157 #ifdef G4VERBOSE
158  if ( fState.GetVerboseL4() )
159  fState.GetVerboseL4()->Message("close", "files", "");
160 #endif
161 
162  // Unlock file name only
163  G4bool result = fFileManager->CloseFile();
164  finalResult = finalResult && result;
165 
166  // Close ntuple files
167  if ( ( ! G4AnalysisManagerState::IsMT() ) || ( ! fState.GetIsMaster() ) ) {
168  // In sequential mode or in MT mode only on workers
169  result = CloseNtupleFiles();
170  finalResult = finalResult && result;
171  }
172 
173  // reset data
174  result = fNtupleManager->Reset();
175  if ( ! result ) {
176  G4ExceptionDescription description;
177  description << " " << "Resetting data failed";
178  G4Exception("G4CsvAnalysisManager::CloseFile()",
179  "Analysis_W002", JustWarning, description);
180  result = false;
181  }
182  finalResult = finalResult && result;
183 
184 #ifdef G4VERBOSE
185  if ( fState.GetVerboseL1() ) {
186  fState.GetVerboseL1()->Message("close", "files", "");
187  }
188 #endif
189 
190  return finalResult;
191 }
192 
void Message(const G4String &action, const G4String &object, const G4String &objectName, G4bool success=true) const
void SetFileManager(G4CsvFileManager *fileManager)
std::ostringstream G4ExceptionDescription
Definition: globals.hh:76
static G4ThreadLocal G4CsvAnalysisManager * fgInstance
const std::vector< G4CsvNtupleDescription * > & GetNtupleVector() const
virtual G4bool CloseFile()
void SetH1Manager(G4VH1Manager *h1Manager)
G4CsvFileManager * fFileManager
virtual G4bool OpenFileImpl(const G4String &fileName)
G4CsvAnalysisManager(G4bool isMaster=true)
G4bool CloseNtupleFile(G4CsvNtupleDescription *ntupleDescription)
#define G4ThreadLocal
Definition: tls.hh:52
static G4CsvAnalysisManager * Instance()
const G4AnalysisVerbose * GetVerboseL4() const
virtual G4bool CloseFileImpl()
bool G4bool
Definition: G4Types.hh:79
G4CsvNtupleManager * fNtupleManager
void SetFileManager(G4VFileManager *fileManager)
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
G4bool IsWorkerThread()
Definition: G4Threading.cc:104
void SetH2Manager(G4VH2Manager *h2Manager)
static G4CsvAnalysisManager * fgMasterInstance
virtual G4bool OpenFile(const G4String &fileName)
G4AnalysisManagerState fState
G4H2DummyManager * fH2Manager
const G4AnalysisVerbose * GetVerboseL1() const
void SetNtupleManager(G4VNtupleManager *ntupleManager)
G4H1DummyManager * fH1Manager