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5 ] [ 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/factory/src/G4GenericAnalysisManager.cc (Version 11.3.0) and /analysis/factory/src/G4GenericAnalysisManager.cc (Version 8.2.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 "G4GenericAnalysisManager.hh"            
 30 #include "G4GenericFileManager.hh"                
 31 #include "G4AnalysisManagerState.hh"              
 32 #include "G4AnalysisUtilities.hh"                 
 33 #include "G4NtupleBookingManager.hh"              
 34 #include "G4VNtupleFileManager.hh"                
 35 #include "G4ThreadLocalSingleton.hh"              
 36 #include "G4Exception.hh"                         
 37                                                   
 38 using namespace G4Analysis;                       
 39 using std::to_string;                             
 40                                                   
 41 // mutex in a file scope                          
 42                                                   
 43 namespace {                                       
 44                                                   
 45 //____________________________________________    
 46 void WriteHnWarning(const G4String& hnType, G4    
 47                     std::string_view inClass,     
 48                     std::string_view inFunctio    
 49 {                                                 
 50   Warn("Failed to get " + hnType + " id " + to    
 51 }                                                 
 52                                                   
 53 }                                                 
 54                                                   
 55 //____________________________________________    
 56 G4GenericAnalysisManager* G4GenericAnalysisMan    
 57 {                                                 
 58   static G4ThreadLocalSingleton<G4GenericAnaly    
 59   fgIsInstance = true;                            
 60   return instance.Instance();                     
 61 }                                                 
 62                                                   
 63 //____________________________________________    
 64 G4bool G4GenericAnalysisManager::IsInstance()     
 65 {                                                 
 66   return fgIsInstance;                            
 67 }                                                 
 68                                                   
 69 //____________________________________________    
 70 G4GenericAnalysisManager::G4GenericAnalysisMan    
 71  : G4ToolsAnalysisManager("")                     
 72 {                                                 
 73   if ( ! G4Threading::IsWorkerThread() ) fgMas    
 74                                                   
 75   // File manager                                 
 76   fFileManager = std::make_shared<G4GenericFil    
 77   SetFileManager(fFileManager);                   
 78 }                                                 
 79                                                   
 80 //____________________________________________    
 81 G4GenericAnalysisManager::~G4GenericAnalysisMa    
 82 {                                                 
 83   if ( fState.GetIsMaster() ) fgMasterInstance    
 84   fgIsInstance = false;                           
 85 }                                                 
 86                                                   
 87 //                                                
 88 // private methods                                
 89 //                                                
 90                                                   
 91 //____________________________________________    
 92 void G4GenericAnalysisManager::CreateNtupleFil    
 93 {                                                 
 94   if ( fNtupleFileManager ) {                     
 95     Warn("The ntuple file manager already exis    
 96       fkClass, "CreateNtupleFileManager");        
 97     return;                                       
 98   }                                               
 99                                                   
100   auto fileType = GetExtension(fileName);         
101   auto output = G4Analysis::GetOutput(fileType    
102   if ( output == G4AnalysisOutput::kNone ) {      
103     Warn("The file type " + fileType + "is not    
104       fkClass, "CreateNtupleFileManager");        
105     return;                                       
106   }                                               
107                                                   
108   // Set file type to booked ntuples              
109   fNtupleBookingManager->SetFileType(fileType)    
110                                                   
111   Message(kVL4, "create", "ntuple file manager    
112                                                   
113   fNtupleFileManager = fFileManager->CreateNtu    
114   if (fNtupleFileManager) {                       
115     SetNtupleFileManager(fNtupleFileManager);     
116     fNtupleFileManager->SetBookingManager(fNtu    
117                                                   
118     if ( fNtupleFileManager->IsNtupleMergingSu    
119       // set merginng                             
120       fNtupleFileManager->SetNtupleMerging(fMe    
121       fNtupleFileManager->SetNtupleRowWise(fNt    
122       fNtupleFileManager->SetBasketSize(fBaske    
123       fNtupleFileManager->SetBasketEntries(fBa    
124     }                                             
125     else if ( fIsNtupleMergingSet && fMergeNtu    
126       Warn("Ntuple merging is not available wi    
127            "Setting is ignored.",                 
128            fkClass, "CreateNtupleFileManager")    
129     }                                             
130   }                                               
131                                                   
132   Message(kVL3, "create", "ntuple file manager    
133 }                                                 
134                                                   
135 //                                                
136 // protected methods                              
137 //                                                
138                                                   
139 //____________________________________________    
140 G4bool G4GenericAnalysisManager::OpenFileImpl(    
141 {                                                 
142   Message(kVL4, "open", "file", fileName);        
143                                                   
144   // Add file name extension, if missing          
145   auto fullFileName = fileName;                   
146   if (GetExtension(fileName).size() == 0u) {      
147     auto defaultFileType = fFileManager->GetDe    
148     // G4cout << "File type is not defined, us    
149     if (defaultFileType.size() == 0u) {           
150       G4Exception("G4GenericAnalysisManager::O    
151         FatalException,                           
152         G4String("Cannot open file \"" + fileN    
153           "Please, use a file name with an ext    
154           "via G4AnalysisManager::SetDefaultFi    
155     }                                             
156                                                   
157     fullFileName = fileName + "." + fFileManag    
158   }                                               
159                                                   
160   // Create ntuple file manager if there are b    
161   if (! fNtupleFileManager) {                     
162     CreateNtupleFileManager(fullFileName);        
163   }                                               
164                                                   
165   auto result = true;                             
166   if (fNtupleFileManager) {                       
167     result &= G4ToolsAnalysisManager::OpenFile    
168   }                                               
169   else {                                          
170     // no ntuples (check if this mode is suppo    
171     result &= fFileManager->OpenFile(fullFileN    
172   }                                               
173                                                   
174   Message(kVL3, "open", "file", fileName, resu    
175                                                   
176   return result;                                  
177 }                                                 
178                                                   
179 //____________________________________________    
180 void G4GenericAnalysisManager::SetDefaultFileT    
181 {                                                 
182   G4VAnalysisManager::SetDefaultFileTypeImpl(v    
183                                                   
184   fFileManager->SetDefaultFileType(value);        
185 }                                                 
186                                                   
187 //____________________________________________    
188 G4bool G4GenericAnalysisManager::WriteH1(G4int    
189 {                                                 
190   // Experimental extra write                     
191                                                   
192   // Do not write histo on worker (redundant a    
193   // If default file is not used, users have t    
194   if ( G4Threading::IsWorkerThread() ) return     
195                                                   
196   auto h1d = GetH1(id, false);                    
197   if (h1d == nullptr) {                           
198     WriteHnWarning("H1", id, fkClass, "WriteH1    
199     return false;                                 
200   }                                               
201                                                   
202   auto h1Name = GetH1Name(id);                    
203   return fFileManager->WriteTExtra<tools::hist    
204 }                                                 
205                                                   
206 //____________________________________________    
207 G4bool G4GenericAnalysisManager::WriteH2(G4int    
208 {                                                 
209   // Experimental extra write                     
210                                                   
211   // Do not write histo on worker (redundant a    
212   // If default file is not used, users have t    
213   if ( G4Threading::IsWorkerThread() ) return     
214                                                   
215   auto h2d = GetH2(id, false);                    
216   if (h2d == nullptr) {                           
217     WriteHnWarning("H2", id, fkClass, "WriteH2    
218     return false;                                 
219   }                                               
220                                                   
221   auto h2Name = GetH2Name(id);                    
222   return fFileManager->WriteTExtra<tools::hist    
223 }                                                 
224 //____________________________________________    
225 G4bool G4GenericAnalysisManager::WriteH3(G4int    
226 {                                                 
227   // Experimental extra write                     
228                                                   
229   // Do not write histo on worker (redundant a    
230   // If default file is not used, users have t    
231   if ( G4Threading::IsWorkerThread() ) return     
232                                                   
233   auto h3d = GetH3(id, false);                    
234   if (h3d == nullptr) {                           
235     WriteHnWarning("H3", id, fkClass, "WriteH3    
236     return false;                                 
237   }                                               
238                                                   
239   auto h3Name = GetH3Name(id);                    
240   return fFileManager->WriteTExtra<tools::hist    
241 }                                                 
242                                                   
243 //____________________________________________    
244 G4bool G4GenericAnalysisManager::WriteP1(G4int    
245 {                                                 
246   // Experimental extra write                     
247                                                   
248   // Do not write histo on worker (redundant a    
249   // If default file is not used, users have t    
250   if ( G4Threading::IsWorkerThread() ) return     
251                                                   
252   auto p1d = GetP1(id, false);                    
253   if (p1d == nullptr) {                           
254     WriteHnWarning("P1", id, fkClass, "WriteP1    
255     return false;                                 
256   }                                               
257                                                   
258   auto p1Name = GetP1Name(id);                    
259   return fFileManager->WriteTExtra<tools::hist    
260 }                                                 
261                                                   
262 //____________________________________________    
263 G4bool G4GenericAnalysisManager::WriteP2(G4int    
264 {                                                 
265   // Experimental extra write                     
266                                                   
267   // Do not write histo on worker (redundant a    
268   // If default file is not used, users have t    
269   if ( G4Threading::IsWorkerThread() ) return     
270                                                   
271   auto p2d = GetP2(id, false);                    
272   if (p2d == nullptr) {                           
273     WriteHnWarning("P2", id, fkClass, "WriteP2    
274     return false;                                 
275   }                                               
276                                                   
277   auto p2Name = GetP2Name(id);                    
278   return fFileManager->WriteTExtra<tools::hist    
279 }                                                 
280                                                   
281 //____________________________________________    
282 tools::ntuple_booking* G4GenericAnalysisManage    
283   G4bool warn, G4bool onlyIfActive) const         
284 {                                                 
285   return fNtupleBookingManager->GetNtuple(warn    
286 }                                                 
287                                                   
288 //____________________________________________    
289 tools::ntuple_booking* G4GenericAnalysisManage    
290   G4int ntupleId, G4bool warn, G4bool onlyIfAc    
291 {                                                 
292   return fNtupleBookingManager->GetNtuple(ntup    
293 }                                                 
294