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] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /analysis/csv/src/G4CsvFileManager.cc (Version 11.3.0) and /analysis/csv/src/G4CsvFileManager.cc (Version 6.0.p1)


  1 //                                                  1 
  2 // *******************************************    
  3 // * License and Disclaimer                       
  4 // *                                              
  5 // * The  Geant4 software  is  copyright of th    
  6 // * the Geant4 Collaboration.  It is provided    
  7 // * conditions of the Geant4 Software License    
  8 // * LICENSE and available at  http://cern.ch/    
  9 // * include a list of copyright holders.         
 10 // *                                              
 11 // * Neither the authors of this software syst    
 12 // * institutes,nor the agencies providing fin    
 13 // * work  make  any representation or  warran    
 14 // * regarding  this  software system or assum    
 15 // * use.  Please see the license in the file     
 16 // * for the full disclaimer and the limitatio    
 17 // *                                              
 18 // * This  code  implementation is the result     
 19 // * technical work of the GEANT4 collaboratio    
 20 // * By using,  copying,  modifying or  distri    
 21 // * any work based  on the software)  you  ag    
 22 // * use  in  resulting  scientific  publicati    
 23 // * acceptance of all terms of the Geant4 Sof    
 24 // *******************************************    
 25 //                                                
 26                                                   
 27 // Author: Ivana Hrivnacova, 18/06/2013  (ivan    
 28                                                   
 29 #include "G4CsvFileManager.hh"                    
 30 #include "G4CsvHnFileManager.hh"                  
 31 #include "G4AnalysisManagerState.hh"              
 32 #include "G4AnalysisUtilities.hh"                 
 33 #include "G4Filesystem.hh"                        
 34                                                   
 35 using namespace G4Analysis;                       
 36 using namespace tools;                            
 37                                                   
 38 //____________________________________________    
 39 G4CsvFileManager::G4CsvFileManager(const G4Ana    
 40  : G4VTFileManager(state)                         
 41 {                                                 
 42   // Create helpers defined in the base class     
 43   fH1FileManager = std::make_shared<G4CsvHnFil    
 44   fH2FileManager = std::make_shared<G4CsvHnFil    
 45   fH3FileManager = std::make_shared<G4CsvHnFil    
 46   fP1FileManager = std::make_shared<G4CsvHnFil    
 47   fP2FileManager = std::make_shared<G4CsvHnFil    
 48 }                                                 
 49                                                   
 50 //                                                
 51 // private methods                                
 52 //                                                
 53                                                   
 54 //____________________________________________    
 55 G4String G4CsvFileManager::GetNtupleFileName(C    
 56 {                                                 
 57   // get ntuple file name                         
 58   auto ntupleFileName = ntupleDescription->Get    
 59   auto cycle = GetCycle();                        
 60   if (ntupleFileName.size() != 0u) {              
 61     // update filename per object per thread      
 62     ntupleFileName = GetTnFileName(ntupleFileN    
 63   }                                               
 64   else {                                          
 65     // compose ntuple file name from the defau    
 66     ntupleFileName = GetNtupleFileName(ntupleD    
 67   }                                               
 68                                                   
 69   if ( IsNtupleDirectory() ) {                    
 70     ntupleFileName = "./" + GetNtupleDirectory    
 71   }                                               
 72                                                   
 73   return ntupleFileName;                          
 74 }                                                 
 75                                                   
 76 //                                                
 77 // protected methods                              
 78 //                                                
 79                                                   
 80 //____________________________________________    
 81 std::shared_ptr<std::ofstream> G4CsvFileManage    
 82 {                                                 
 83   std::shared_ptr<std::ofstream> file = std::m    
 84   if ( file->fail() ) {                           
 85     Warn("Cannot create file " + fileName, fkC    
 86     return nullptr;                               
 87   }                                               
 88                                                   
 89   return file;                                    
 90 }                                                 
 91                                                   
 92 //____________________________________________    
 93 G4bool G4CsvFileManager::WriteFileImpl(std::sh    
 94 {                                                 
 95   // Nothing to be done here                      
 96   return true;                                    
 97 }                                                 
 98                                                   
 99 //____________________________________________    
100 G4bool G4CsvFileManager::CloseFileImpl(std::sh    
101 {                                                 
102   if ( ! file ) return false;                     
103                                                   
104   // close file                                   
105   file->close();                                  
106                                                   
107   return true;                                    
108 }                                                 
109                                                   
110 //                                                
111 // public methods                                 
112 //                                                
113                                                   
114 //____________________________________________    
115 G4bool G4CsvFileManager::OpenFile(const G4Stri    
116 {                                                 
117   // Keep file name                               
118   fFileName =  fileName;                          
119                                                   
120   fIsOpenFile = true;                             
121                                                   
122   return true;                                    
123 }                                                 
124                                                   
125 //____________________________________________    
126 G4bool G4CsvFileManager::SetHistoDirectoryName    
127 {                                                 
128   // A directory is taken into account only if    
129   if ( G4fs::is_directory(dirName.data()) ) {     
130      fIsHistoDirectory = G4VFileManager::SetHi    
131      return fIsHistoDirectory;                    
132   }                                               
133                                                   
134   G4Analysis::Warn("Directory " + dirName + "     
135     "Histograms will be written in the current    
136     fkClass, "SetHistoDirectoryName");            
137   return false;                                   
138 }                                                 
139                                                   
140 //____________________________________________    
141 G4bool G4CsvFileManager::SetNtupleDirectoryNam    
142 {                                                 
143   // A directory is taken into account only if    
144   if ( G4fs::is_directory(dirName.data()) ) {     
145      fIsNtupleDirectory = G4VFileManager::SetN    
146      return fIsNtupleDirectory;                   
147   }                                               
148                                                   
149   G4Analysis::Warn("Directory " + dirName + "     
150     "Ntuples will be written in the current di    
151     fkClass, "SetNtupleDirectoryName");           
152   return false;                                   
153 }                                                 
154                                                   
155 //____________________________________________    
156 G4bool G4CsvFileManager::NotifyNtupleFile(CsvN    
157 {                                                 
158   // Notify not empty file                        
159   auto ntupleFileName = GetNtupleFileName(ntup    
160                                                   
161   return SetIsEmpty(ntupleFileName, ! ntupleDe    
162 }                                                 
163                                                   
164 //____________________________________________    
165 G4bool G4CsvFileManager::CreateNtupleFile(        
166   CsvNtupleDescription* ntupleDescription)        
167 {                                                 
168   // Get ntuple file name per object (if defin    
169   auto ntupleFileName = GetNtupleFileName(ntup    
170                                                   
171   // Update file name if it is already in use     
172   while ( GetTFile(ntupleFileName, false) != n    
173     // the file is already in use                 
174     auto oldName = ntupleFileName;                
175     auto newName = GetBaseName(oldName) + "_bi    
176     ntupleDescription->SetFileName(newName);      
177                                                   
178     Warn("Ntuple filename " + oldName + " is a    
179          "It will be replaced with : " + newNa    
180          fkClass, "CreateNtupleFile");            
181                                                   
182     ntupleFileName = GetNtupleFileName(ntupleD    
183   }                                               
184                                                   
185   // Create new ntuple file                       
186   ntupleDescription->SetFile(CreateTFile(ntupl    
187                                                   
188   return (ntupleDescription->GetFile() != null    
189 }                                                 
190                                                   
191 //____________________________________________    
192 G4bool G4CsvFileManager::CloseNtupleFile(         
193   CsvNtupleDescription* ntupleDescription)        
194 {                                                 
195   // Notifying not empty file is done in G4Csv    
196   // as here we increment the cycle number and    
197   // for the next cycle version.                  
198                                                   
199   // Ntuple files are registered in file manag    
200   // they will be closed with CloseFiles() cal    
201                                                   
202   ntupleDescription->GetFile().reset();           
203                                                   
204   return true;                                    
205 }                                                 
206