Geant4  v4-10.4-release
 모두 클래스 네임스페이스들 파일들 함수 변수 타입정의 열거형 타입 열거형 멤버 Friends 매크로 그룹들 페이지들
G4CsvNtupleManager.cc
이 파일의 문서화 페이지로 가기
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 //_____________________________________________________________________________
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 //_____________________________________________________________________________
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 //_____________________________________________________________________________
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 //_____________________________________________________________________________
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 }
virtual void CreateTNtuple(NtupleDescriptionType *ntupleDescription, const G4String &name, const G4String &title) final
std::ostringstream G4ExceptionDescription
Definition: G4Exception.hh:45
std::shared_ptr< G4CsvFileManager > fFileManager
TTree * ntuple
G4bool WriteHeader(NtupleType *ntuple) const
virtual void FinishTNtuple(NtupleDescriptionType *ntupleDescription) final
virtual void CreateTNtupleFromBooking(NtupleDescriptionType *ntupleDescription) final
bool G4bool
Definition: G4Types.hh:79
G4GLOB_DLL std::ostream G4cerr
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.hh:65
G4GLOB_DLL std::ostream G4cout
tools::ntuple_booking fNtupleBooking
G4CsvNtupleManager(const G4AnalysisManagerState &state)
std::vector< tools::wcsv::ntuple * > fNtupleVector