Geant4  10.03.p03
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4CsvNtupleManager.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: G4CsvNtupleManager.cc 70604 2013-06-03 11:27:06Z ihrivnac $
27 
28 // Author: Ivana Hrivnacova, 18/06/2013 (ivana@ipno.in2p3.fr)
29 
30 #include "G4CsvNtupleManager.hh"
31 #include "G4CsvFileManager.hh"
33 #include "G4AnalysisUtilities.hh"
34 
35 #include "G4Threading.hh"
36 
37 #include <iostream>
38 
39 using namespace G4Analysis;
40 
41 //
42 // utility methods
43 //
44 
45 //_____________________________________________________________________________
47  : G4TNtupleManager<tools::wcsv::ntuple>(state),
48  fFileManager(nullptr),
49  fIsCommentedHeader(true),
50  fIsHippoHeader(false)
51 {}
52 
53 //_____________________________________________________________________________
55 {}
56 
57 //
58 // private methods
59 //
60 
61 //_____________________________________________________________________________
62 void G4CsvNtupleManager::CreateTNtuple(
64  const G4String& /*name*/, const G4String& title)
65 {
66  // Create ntuple if the file is open (what means here that
67  // a filename was already set)
68  if ( fFileManager->GetFileName().size() ) {
69  if ( fFileManager->CreateNtupleFile(ntupleDescription) ) {
70  ntupleDescription->fNtuple
71  = new tools::wcsv::ntuple(*(ntupleDescription->fFile));
72  // ntuple object is deleted when closing a file
73  (ntupleDescription->fNtuple)->set_title(title);
74  fNtupleVector.push_back(ntupleDescription->fNtuple);
75  }
76  }
77 }
78 
79 //_____________________________________________________________________________
80 void G4CsvNtupleManager::CreateTNtupleFromBooking(
82 {
83  // create a file for this ntuple
84  if ( ! fFileManager->CreateNtupleFile(ntupleDescription) ) return;
85 
86  // create ntuple
87  ntupleDescription->fNtuple
88  = new tools::wcsv::ntuple(
89  *(ntupleDescription->fFile), G4cerr, ntupleDescription->fNtupleBooking);
90  fNtupleVector.push_back(ntupleDescription->fNtuple);
91  }
92 
93 //_____________________________________________________________________________
94 void G4CsvNtupleManager::FinishTNtuple(
96 {
97  if ( ! ntupleDescription->fNtuple ) return;
98 
99  // Write header if ntuple already exists
100  if ( ! WriteHeader(ntupleDescription->fNtuple) ) {
101  G4ExceptionDescription description;
102  description << " "
103  << "Writing ntuple header has failed. ";
104  G4Exception("G4CsvNtupleManager::FinishTNtuple()",
105  "Analysis_W022", JustWarning, description);
106  }
107 }
108 
109 //_____________________________________________________________________________
110 G4bool G4CsvNtupleManager::WriteHeader(tools::wcsv::ntuple* ntuple) const
111 {
112 // Write header if ntuple already exists and if this option is activated.
113 // When both Hippo and Commented headers are selected, only Commented
114 // header, which reading is supported.
115 // Return false only if an error occurred.
116 
117  if ( fIsCommentedHeader ) {
118  return ntuple->write_commented_header(G4cout);
119  }
120 
121  // write hippo header (if activated and if not commented header)
122  if ( fIsHippoHeader ) {
123  ntuple->write_hippo_header();
124  return true;
125  }
126 
127  return true;
128 }
std::ostringstream G4ExceptionDescription
Definition: globals.hh:76
G4CsvNtupleManager(const G4AnalysisManagerState &state)
G4GLOB_DLL std::ostream G4cout
bool G4bool
Definition: G4Types.hh:79
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
std::vector< tools::wcsv::ntuple * > fNtupleVector
tools::ntuple_booking fNtupleBooking
subroutine title
Definition: hijing1.383.f:5980
G4GLOB_DLL std::ostream G4cerr