QwGeant4
QweakSimAnalysis Class Reference

Handling of the output ROOT file. More...

#include <QweakSimAnalysis.hh>

+ Collaboration diagram for QweakSimAnalysis:

Public Member Functions

 QweakSimAnalysis (QweakSimUserInformation *)
 
virtual ~QweakSimAnalysis ()
 
void BeginOfRun (const G4Run *aRun)
 
void EndOfRun (const G4Run *aRun)
 
void EndOfEvent (G4int flag)
 
void SetNumberOfEventToBeProcessed (G4int n)
 
G4int GetNumberOfEventToBeProcessed () const
 
void SetRootFileStem (const G4String &stem)
 
void SetRootFileName (const G4String &name)
 
void FillRootNtuple ()
 
void AutoSaveRootNtuple ()
 

Data Fields

QweakSimUserMainEventfRootEvent
 

Private Member Functions

void ConstructRootNtuple ()
 

Private Attributes

QweakSimAnalysisMessengerpAnalysisMessenger
 
QweakSimUserInformationmyUserInfo
 
QweakSimUserRunInformationpUserRunInformation
 
G4String fRootFileStem
 
G4String fRootFileName
 
TTree * fRootNtuple
 
TBranch * fRootBranch
 
TFile * fRootFile
 

Detailed Description

Handling of the output ROOT file.

Placeholder for a long explaination

Definition at line 56 of file QweakSimAnalysis.hh.

Constructor & Destructor Documentation

QweakSimAnalysis::QweakSimAnalysis ( QweakSimUserInformation userInfo)

Definition at line 35 of file QweakSimAnalysis.cc.

References fRootBranch, fRootEvent, fRootFile, fRootNtuple, myUserInfo, pAnalysisMessenger, and pUserRunInformation.

36 : fRootFileStem("QwSim"),fRootFileName("")
37 {
38  G4cout << "###### Calling QweakSimAnalysis::QweakSimAnalysis()" << G4endl;
39 
40  myUserInfo = userInfo;
41 
42  // Initialize
43  fRootEvent = NULL;
44  fRootNtuple = NULL;
45  fRootBranch = NULL;
46  fRootFile = NULL;
47 
48  // Create messenger
50 
51  // Create user run data
53 
54  G4cout << "###### Leaving QweakSimAnalysis::QweakSimAnalysis()" << G4endl;
55 }
QweakSimUserRunInformation * pUserRunInformation
QweakSimUserMainEvent * fRootEvent
QweakSimAnalysisMessenger * pAnalysisMessenger
QweakSimUserInformation * myUserInfo
QweakSimAnalysis::~QweakSimAnalysis ( )
virtual

Definition at line 58 of file QweakSimAnalysis.cc.

References fRootBranch, fRootEvent, fRootFile, fRootNtuple, and pAnalysisMessenger.

59 {
60  G4cout << "###### Calling QweakSimAnalysis::QweakSimAnalysis()" << G4endl;
61 
62  // Delete ROOT objects
63  if (fRootEvent) delete fRootEvent;
64  if (fRootNtuple) delete fRootNtuple;
65  if (fRootBranch) delete fRootBranch;
66  if (fRootFile) delete fRootFile;
67 
68  // Delete messenger
70 
71  G4cout << "###### Leaving QweakSimAnalysis::QweakSimAnalysis()" << G4endl;
72 }
QweakSimUserMainEvent * fRootEvent
QweakSimAnalysisMessenger * pAnalysisMessenger

Member Function Documentation

void QweakSimAnalysis::AutoSaveRootNtuple ( )

Definition at line 143 of file QweakSimAnalysis.cc.

References fRootNtuple.

Referenced by QweakSimEventAction::EndOfEventAction(), and EndOfRun().

144 {
145  // save the current ntuple:
146  // In case your program crashes before closing the file holding this tree,
147  // the file will be automatically recovered when you will connect the file
148  // in UPDATE mode.
149  // The Tree will be recovered at the status corresponding to the last AutoSave.
150  //
151  // if option contains "SaveSelf", gDirectory->SaveSelf() is called.
152  // This allows another process to analyze the Tree while the Tree is being filled.
153  //
154  // see http://root.cern.ch/root/html/TTree.html#TTree:AutoSave
155 
156  // fRootNtuple -> AutoSave("SaveSelf");
157  fRootNtuple -> AutoSave();
158  gDirectory -> Purge(); //jpan: Purge old trees
159 }

+ Here is the caller graph for this function:

void QweakSimAnalysis::BeginOfRun ( const G4Run *  aRun)

Definition at line 85 of file QweakSimAnalysis.cc.

References ConstructRootNtuple(), fRootFile, fRootFileName, and fRootFileStem.

Referenced by QweakSimRunAction::BeginOfRunAction().

86 {
87  // Get run number
88  G4int runID = aRun->GetRunID();
89 
90  // Construct file name if not set explicitly
91  if (fRootFileName.size() == 0)
92  fRootFileName = fRootFileStem + "_" + Form("%d",runID) + ".root";
93 
94  // Create ROOT file
95  G4cout << "###### Analysis: creating ROOT file " << fRootFileName << G4endl;
96  fRootFile = new TFile(fRootFileName,"RECREATE","Qweak ROOT file");
98 }

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void QweakSimAnalysis::ConstructRootNtuple ( )
private

Definition at line 121 of file QweakSimAnalysis.cc.

References fRootBranch, fRootEvent, fRootNtuple, and pUserRunInformation.

Referenced by BeginOfRun().

122 {
123  // Create ROOT tree
124  fRootNtuple = new TTree("QweakSimG4_Tree","Qweak Geant4 Simulation Tree");
125 
126  // Save the file after so many bytes. Avoids complete data loss after crash
127  //fRootNtuple ->SetAutoSave(1000000); //AutoSave after every 1 Mbyte written to disk
128 
129  // Instance of data structure to be written into ROOT file
131 
132  // Create a branch with the data structure defined by fRootEvent
133  int bufsize = 64000;
134  int split = 99;
135  fRootBranch = fRootNtuple->Branch("QweakSimUserMainEvent", "QweakSimUserMainEvent", &fRootEvent, bufsize, split);
136 
137  // Write run data
138  pUserRunInformation->Write();
139 }
QweakSimUserRunInformation * pUserRunInformation
QweakSimUserMainEvent * fRootEvent
Defines Top ROOT Tree structure of the ROOT file for each event.

+ Here is the caller graph for this function:

void QweakSimAnalysis::EndOfEvent ( G4int  flag)

Definition at line 114 of file QweakSimAnalysis.cc.

115 {
116  // This member is called at the end of every event
117  if (!flag) return;
118 }
void QweakSimAnalysis::EndOfRun ( const G4Run *  aRun)

Definition at line 101 of file QweakSimAnalysis.cc.

References AutoSaveRootNtuple(), fRootFile, and fRootFileName.

Referenced by QweakSimRunAction::EndOfRunAction().

102 {
103  // Autosave one last time
105 
106  // Write the data to the ROOT file
107  G4cout << "###### Analysis: closing ROOT file " << fRootFileName << G4endl;
108  fRootFile->Write(0,TObject::kOverwrite);
109  fRootFile->Close();
110  fRootFileName = "";
111 }

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void QweakSimAnalysis::FillRootNtuple ( )
inline

Definition at line 76 of file QweakSimAnalysis.hh.

References fRootNtuple.

Referenced by QweakSimEventAction::EndOfEventAction().

76 { fRootNtuple->Fill(); }

+ Here is the caller graph for this function:

G4int QweakSimAnalysis::GetNumberOfEventToBeProcessed ( ) const

Definition at line 80 of file QweakSimAnalysis.cc.

References QweakSimUserInformation::GetNumberOfEventToBeProcessed(), and myUserInfo.

80  {
82 }
G4int GetNumberOfEventToBeProcessed() const
QweakSimUserInformation * myUserInfo

+ Here is the call graph for this function:

void QweakSimAnalysis::SetNumberOfEventToBeProcessed ( G4int  n)

Definition at line 77 of file QweakSimAnalysis.cc.

References myUserInfo, and QweakSimUserInformation::SetNumberOfEventToBeProcessed().

Referenced by QweakSimRunAction::BeginOfRunAction().

77  {
79 }
QweakSimUserInformation * myUserInfo

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void QweakSimAnalysis::SetRootFileName ( const G4String &  name)
inline

Definition at line 74 of file QweakSimAnalysis.hh.

References fRootFileName.

Referenced by QweakSimAnalysisMessenger::SetNewValue().

74 { fRootFileName = name; }

+ Here is the caller graph for this function:

void QweakSimAnalysis::SetRootFileStem ( const G4String &  stem)
inline

Definition at line 73 of file QweakSimAnalysis.hh.

References fRootFileStem.

Referenced by QweakSimAnalysisMessenger::SetNewValue().

73 { fRootFileStem = stem; }

+ Here is the caller graph for this function:

Field Documentation

TBranch* QweakSimAnalysis::fRootBranch
private

Definition at line 95 of file QweakSimAnalysis.hh.

Referenced by ConstructRootNtuple(), QweakSimAnalysis(), and ~QweakSimAnalysis().

TFile* QweakSimAnalysis::fRootFile
private

Definition at line 96 of file QweakSimAnalysis.hh.

Referenced by BeginOfRun(), EndOfRun(), QweakSimAnalysis(), and ~QweakSimAnalysis().

G4String QweakSimAnalysis::fRootFileName
private

Definition at line 90 of file QweakSimAnalysis.hh.

Referenced by BeginOfRun(), EndOfRun(), and SetRootFileName().

G4String QweakSimAnalysis::fRootFileStem
private

Definition at line 89 of file QweakSimAnalysis.hh.

Referenced by BeginOfRun(), and SetRootFileStem().

TTree* QweakSimAnalysis::fRootNtuple
private
QweakSimUserInformation* QweakSimAnalysis::myUserInfo
private
QweakSimAnalysisMessenger* QweakSimAnalysis::pAnalysisMessenger
private

Definition at line 83 of file QweakSimAnalysis.hh.

Referenced by QweakSimAnalysis(), and ~QweakSimAnalysis().

QweakSimUserRunInformation* QweakSimAnalysis::pUserRunInformation
private

Definition at line 87 of file QweakSimAnalysis.hh.

Referenced by ConstructRootNtuple(), and QweakSimAnalysis().


The documentation for this class was generated from the following files: