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10.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/hntools/src/G4ToolsAnalysisManager.cc (Version 11.3.0) and /analysis/hntools/src/G4ToolsAnalysisManager.cc (Version 10.3.p3)


  1 //                                                  1 //
  2 // *******************************************      2 // ********************************************************************
  3 // * License and Disclaimer                         3 // * License and Disclaimer                                           *
  4 // *                                                4 // *                                                                  *
  5 // * The  Geant4 software  is  copyright of th      5 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
  6 // * the Geant4 Collaboration.  It is provided      6 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
  7 // * conditions of the Geant4 Software License      7 // * conditions of the Geant4 Software License,  included in the file *
  8 // * LICENSE and available at  http://cern.ch/      8 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
  9 // * include a list of copyright holders.           9 // * include a list of copyright holders.                             *
 10 // *                                               10 // *                                                                  *
 11 // * Neither the authors of this software syst     11 // * Neither the authors of this software system, nor their employing *
 12 // * institutes,nor the agencies providing fin     12 // * institutes,nor the agencies providing financial support for this *
 13 // * work  make  any representation or  warran     13 // * work  make  any representation or  warranty, express or implied, *
 14 // * regarding  this  software system or assum     14 // * regarding  this  software system or assume any liability for its *
 15 // * use.  Please see the license in the file      15 // * use.  Please see the license in the file  LICENSE  and URL above *
 16 // * for the full disclaimer and the limitatio     16 // * for the full disclaimer and the limitation of liability.         *
 17 // *                                               17 // *                                                                  *
 18 // * This  code  implementation is the result      18 // * This  code  implementation is the result of  the  scientific and *
 19 // * technical work of the GEANT4 collaboratio     19 // * technical work of the GEANT4 collaboration.                      *
 20 // * By using,  copying,  modifying or  distri     20 // * By using,  copying,  modifying or  distributing the software (or *
 21 // * any work based  on the software)  you  ag     21 // * any work based  on the software)  you  agree  to acknowledge its *
 22 // * use  in  resulting  scientific  publicati     22 // * use  in  resulting  scientific  publications,  and indicate your *
 23 // * acceptance of all terms of the Geant4 Sof     23 // * acceptance of all terms of the Geant4 Software license.          *
 24 // *******************************************     24 // ********************************************************************
 25 //                                                 25 //
                                                   >>  26 // $Id: G4ToolsAnalysisManager.cc 91116 2015-06-20 12:33:45Z ihrivnac $
 26                                                    27 
 27 // Author: Ivana Hrivnacova, 18/06/2013  (ivan     28 // Author: Ivana Hrivnacova, 18/06/2013  (ivana@ipno.in2p3.fr)
 28                                                    29 
 29 #include "G4ToolsAnalysisManager.hh"               30 #include "G4ToolsAnalysisManager.hh"
 30 #include "G4VNtupleFileManager.hh"             <<  31 #include "G4H1ToolsManager.hh"
                                                   >>  32 #include "G4H2ToolsManager.hh"
                                                   >>  33 #include "G4H3ToolsManager.hh"
                                                   >>  34 #include "G4P1ToolsManager.hh"
                                                   >>  35 #include "G4P2ToolsManager.hh"
 31 #include "G4PlotManager.hh"                        36 #include "G4PlotManager.hh"
 32 #include "G4MPIToolsManager.hh"                    37 #include "G4MPIToolsManager.hh"
 33 #include "G4AnalysisUtilities.hh"              << 
 34 #include "G4AutoLock.hh"                       << 
 35 #include "G4Threading.hh"                      << 
 36                                                << 
 37 using namespace G4Analysis;                    << 
 38                                                << 
 39 namespace {                                    << 
 40   //Mutex to lock master manager when merging  << 
 41   G4Mutex mergeHnMutex = G4MUTEX_INITIALIZER;  << 
 42 }                                              << 
 43                                                << 
 44 //____________________________________________ << 
 45 G4ToolsAnalysisManager* G4ToolsAnalysisManager << 
 46 {                                              << 
 47   return fgToolsInstance;                      << 
 48 }                                              << 
 49                                                    38 
 50 //____________________________________________     39 //_____________________________________________________________________________
 51 G4bool G4ToolsAnalysisManager::IsInstance()    <<  40 G4ToolsAnalysisManager::G4ToolsAnalysisManager(const G4String& type, G4bool isMaster)
                                                   >>  41  : G4VAnalysisManager(type, isMaster),
                                                   >>  42    fH1Manager(nullptr),
                                                   >>  43    fH2Manager(nullptr),
                                                   >>  44    fH3Manager(nullptr),
                                                   >>  45    fP1Manager(nullptr),
                                                   >>  46    fP2Manager(nullptr)
 52 {                                                  47 {
 53   return ( fgToolsInstance != nullptr );       << 
 54 }                                              << 
 55                                                << 
 56 //____________________________________________ << 
 57 G4ToolsAnalysisManager::G4ToolsAnalysisManager << 
 58  : G4VAnalysisManager(type)                    << 
 59 {                                              << 
 60   // Set instance pointer                      << 
 61   if ( ! G4Threading::IsWorkerThread() ) fgMas << 
 62   fgToolsInstance = this;                      << 
 63                                                << 
 64   // Create managers                               48   // Create managers
 65   fH1Manager = new G4THnToolsManager<kDim1, to <<  49   fH1Manager = new G4H1ToolsManager(fState);
 66   fH2Manager = new G4THnToolsManager<kDim2, to <<  50   fH2Manager = new G4H2ToolsManager(fState);
 67   fH3Manager = new G4THnToolsManager<kDim3, to <<  51   fH3Manager = new G4H3ToolsManager(fState);
 68   fP1Manager = new G4THnToolsManager<kDim2, to <<  52   fP1Manager = new G4P1ToolsManager(fState);
 69   fP2Manager = new G4THnToolsManager<kDim3, to <<  53   fP2Manager = new G4P2ToolsManager(fState);
 70       // The managers will be deleted by the b     54       // The managers will be deleted by the base class
 71                                                <<  55   
 72   // Set managers to base class which takes th     56   // Set managers to base class which takes then their ownership
 73   SetH1Manager(fH1Manager);                        57   SetH1Manager(fH1Manager);
 74   SetH2Manager(fH2Manager);                        58   SetH2Manager(fH2Manager);
 75   SetH3Manager(fH3Manager);                        59   SetH3Manager(fH3Manager);
 76   SetP1Manager(fP1Manager);                        60   SetP1Manager(fP1Manager);
 77   SetP2Manager(fP2Manager);                        61   SetP2Manager(fP2Manager);
 78                                                << 
 79   // Plot manager                              << 
 80   fPlotManager = std::make_unique<G4PlotManage << 
 81 }                                                  62 }
 82                                                    63 
 83 //____________________________________________     64 //_____________________________________________________________________________
 84 G4ToolsAnalysisManager::~G4ToolsAnalysisManage     65 G4ToolsAnalysisManager::~G4ToolsAnalysisManager()
 85 {                                              <<  66 {}
 86   if ( fState.GetIsMaster() ) fgMasterToolsIns << 
 87   fgToolsInstance = nullptr;                   << 
 88 }                                              << 
 89                                                << 
 90 //                                             << 
 91 // private methods                             << 
 92 //                                             << 
 93                                                << 
 94 //____________________________________________ << 
 95 G4bool G4ToolsAnalysisManager::WriteHns()      << 
 96 {                                              << 
 97   // Nothing to be done on worker              << 
 98   if ( G4Threading::IsWorkerThread() ) return  << 
 99                                                << 
100   auto result = true;                          << 
101                                                << 
102   // Write all histograms/profile on master    << 
103   result &= WriteT(fH1Manager->GetTHnVectorRef << 
104   result &= WriteT(fH2Manager->GetTHnVectorRef << 
105   result &= WriteT(fH3Manager->GetTHnVectorRef << 
106   result &= WriteT(fP1Manager->GetTHnVectorRef << 
107   result &= WriteT(fP2Manager->GetTHnVectorRef << 
108                                                << 
109   return result;                               << 
110 }                                              << 
111                                                << 
112 //____________________________________________ << 
113 G4bool G4ToolsAnalysisManager::ResetHns()      << 
114 {                                              << 
115 // Reset histograms and profiles               << 
116                                                << 
117   auto result = true;                          << 
118                                                << 
119   result &= fH1Manager->Reset();               << 
120   result &= fH2Manager->Reset();               << 
121   result &= fH3Manager->Reset();               << 
122   result &= fP1Manager->Reset();               << 
123   result &= fP2Manager->Reset();               << 
124                                                << 
125   return result;                               << 
126 }                                              << 
127                                                << 
128 //____________________________________________ << 
129 G4bool G4ToolsAnalysisManager::MergeHns()      << 
130 {                                              << 
131   // Nothing to be done on master              << 
132   if ( ! G4Threading::IsWorkerThread() ) retur << 
133                                                << 
134   if (fgMasterToolsInstance == nullptr) {      << 
135     if (! IsEmpty() ) {                        << 
136       Warn("No master G4AnalysisManager instan << 
137            "Histogram/profile data will not be << 
138            fkClass, "Merge");                  << 
139       return false;                            << 
140     }                                          << 
141     return true;                               << 
142   }                                            << 
143                                                << 
144   Message(kVL4, "merge on worker", "histograms << 
145                                                << 
146   // The worker manager just adds its histogra << 
147   fH1Manager->Merge(mergeHnMutex, fgMasterTool << 
148   fH2Manager->Merge(mergeHnMutex, fgMasterTool << 
149   fH3Manager->Merge(mergeHnMutex, fgMasterTool << 
150   fP1Manager->Merge(mergeHnMutex, fgMasterTool << 
151   fP2Manager->Merge(mergeHnMutex, fgMasterTool << 
152                                                << 
153   Message(kVL3, "merge on worker", "histograms << 
154                                                << 
155   return true;                                 << 
156 }                                              << 
157                                                    67 
158 //                                                 68 //
159 // protected methods                               69 // protected methods
160 //                                                 70 //
161                                                    71 
162 //____________________________________________     72 //_____________________________________________________________________________
163 G4bool G4ToolsAnalysisManager::OpenFileImpl(co <<  73 G4bool G4ToolsAnalysisManager::PlotImpl() 
164 {                                              << 
165   // Create ntuple manager(s)                  << 
166   // and set it to base class which takes then << 
167   SetNtupleManager(fVNtupleFileManager->Create << 
168                                                << 
169   auto result = true;                          << 
170                                                << 
171   // Open file                                 << 
172   if ( fVNtupleFileManager->GetMergeMode() !=  << 
173     result &= fVFileManager->OpenFile(fileName << 
174   }                                            << 
175                                                << 
176   // Open ntuple files and create ntuples from << 
177   result &= fVNtupleFileManager->ActionAtOpenF << 
178                                                << 
179   return result;                               << 
180 }                                              << 
181                                                << 
182 //____________________________________________ << 
183 G4bool G4ToolsAnalysisManager::WriteImpl()     << 
184 {                                              << 
185   Message(kVL4, "write", "files");             << 
186                                                << 
187   auto result = true;                          << 
188   if ( G4Threading::IsWorkerThread() )  {      << 
189     result &= MergeHns();                      << 
190   }                                            << 
191   else {                                       << 
192     // Open all files registered with objects  << 
193     fVFileManager->OpenFiles();                << 
194                                                << 
195     // Write all histograms/profile on master  << 
196     result &= WriteHns();                      << 
197   }                                            << 
198                                                << 
199   // Ntuples                                   << 
200   if (fVNtupleFileManager) {                   << 
201     result &= fVNtupleFileManager->ActionAtWri << 
202   }                                            << 
203                                                << 
204   // Files                                     << 
205   if ( (fVNtupleFileManager == nullptr) ||     << 
206        (fVNtupleFileManager->GetMergeMode() != << 
207     result &= fVFileManager->WriteFiles();     << 
208   }                                            << 
209                                                << 
210   // Write ASCII if activated                  << 
211   if ( IsAscii() ) {                           << 
212     result &= WriteAscii(fVFileManager->GetFil << 
213   }                                            << 
214                                                << 
215   Message(kVL3, "write", "files", "", result); << 
216                                                << 
217   return result;                               << 
218 }                                              << 
219                                                << 
220 //____________________________________________ << 
221 G4bool G4ToolsAnalysisManager::CloseFileImpl(G << 
222 {                                              << 
223   Message(kVL4, "close", "files");             << 
224                                                << 
225   auto result = true;                          << 
226   if (fVNtupleFileManager) {                   << 
227     result &= fVNtupleFileManager->ActionAtClo << 
228   }                                            << 
229                                                << 
230   // close file                                << 
231   if ( (fVNtupleFileManager == nullptr) ||     << 
232        (fVNtupleFileManager->GetMergeMode() != << 
233     if ( ! fVFileManager->CloseFiles() ) {     << 
234       Warn("Closing files failed", fkClass, "C << 
235       result = false;                          << 
236     }                                          << 
237   }                                            << 
238                                                << 
239   // delete empty files                        << 
240   if ( ! fVFileManager->DeleteEmptyFiles() ) { << 
241     Warn("Deleting empty files failed", fkClas << 
242     result = false;                            << 
243   }                                            << 
244                                                << 
245   // reset histograms                          << 
246   if ( reset ) {                               << 
247     if ( ! Reset() ) {                         << 
248       Warn("Resetting data failed", fkClass, " << 
249       result = false;                          << 
250     }                                          << 
251   }                                            << 
252                                                << 
253   Message(kVL3, "close", "files", "", result); << 
254                                                << 
255   return result;                               << 
256 }                                              << 
257                                                << 
258 //____________________________________________ << 
259 G4bool G4ToolsAnalysisManager::ResetImpl()     << 
260 {                                              << 
261 // Reset histograms and ntuple                 << 
262                                                << 
263   Message(kVL4, "reset", "");                  << 
264                                                << 
265   auto result = true;                          << 
266   result &= ResetHns();                        << 
267   if ( fVNtupleFileManager != nullptr ) {      << 
268     result &= fVNtupleFileManager->Reset();    << 
269   }                                            << 
270                                                << 
271   Message(kVL3, "reset", "", "", result);      << 
272                                                << 
273   return result;                               << 
274 }                                              << 
275                                                << 
276 //____________________________________________ << 
277 void G4ToolsAnalysisManager::ClearImpl()       << 
278 {                                              << 
279 // Reset histograms and profiles               << 
280                                                << 
281   fH1Manager->ClearData();                     << 
282   fH2Manager->ClearData();                     << 
283   fH3Manager->ClearData();                     << 
284   fP1Manager->ClearData();                     << 
285   fP2Manager->ClearData();                     << 
286 }                                              << 
287                                                << 
288 //____________________________________________ << 
289 G4bool G4ToolsAnalysisManager::PlotImpl()      << 
290 {                                                  74 {
291                                                    75 
292   // Only master thread performs plotting          76   // Only master thread performs plotting
293   if ( G4Threading::IsWorkerThread() )  return     77   if ( G4Threading::IsWorkerThread() )  return true;
294                                                    78 
295   auto result = true;                          <<  79   auto finalResult = true;
296                                                    80 
297   // Open output file                          <<  81   // Create plotter
298   fPlotManager->OpenFile(fVFileManager->GetPlo <<  82   G4PlotManager plotManager(fState);
                                                   >>  83   plotManager.OpenFile(fVFileManager->GetPlotFileName());
299                                                    84 
300   // H1                                            85   // H1
301   result                                       <<  86   auto result 
302     &= fPlotManager->PlotAndWrite<tools::histo <<  87     = plotManager.PlotAndWrite<tools::histo::h1d>(fH1Manager->GetH1Vector(), 
                                                   >>  88                                                   fH1Manager->GetHnVector());
                                                   >>  89   finalResult = finalResult && result;
303                                                    90 
304   // H2                                            91   // H2
305   result                                       <<  92   result 
306     &= fPlotManager->PlotAndWrite<tools::histo <<  93     = plotManager.PlotAndWrite<tools::histo::h2d>(fH2Manager->GetH2Vector(), 
                                                   >>  94                                                   fH2Manager->GetHnVector());
                                                   >>  95   finalResult = finalResult && result;
307                                                    96 
308   // H3                                            97   // H3
309   // not yet available in tools                    98   // not yet available in tools
310                                                    99 
311   // P1                                           100   // P1
312   result                                       << 101   result 
313     &= fPlotManager->PlotAndWrite<tools::histo << 102     = plotManager.PlotAndWrite<tools::histo::p1d>(fP1Manager->GetP1Vector(), 
                                                   >> 103                                                   fP1Manager->GetHnVector());
                                                   >> 104   finalResult = finalResult && result;
314                                                   105 
315   // P2                                           106   // P2
316   // not yet available in tools                   107   // not yet available in tools
317                                                   108 
318   // Close output file                         << 109   result = plotManager.CloseFile();
319   result &= fPlotManager->CloseFile();         << 110   finalResult = finalResult && result;
320                                                   111 
321   return result;                               << 112   return finalResult;
322 }                                                 113 }
323                                                   114 
324 //____________________________________________    115 //_____________________________________________________________________________
325 G4bool G4ToolsAnalysisManager::MergeImpl(tools << 116 G4bool G4ToolsAnalysisManager::MergeImpl(tools::histo::hmpi* hmpi) 
326 {                                                 117 {
327                                                   118 
328   // if ( G4Threading::IsWorkerThread() )  ret    119   // if ( G4Threading::IsWorkerThread() )  return true;
329                                                   120 
330   if (hmpi == nullptr) return false;           << 121   if ( ! hmpi )  return false;
331                                                   122 
332   auto result = true;                          << 123   G4bool finalResult = true;
333                                                   124 
334   // Create MPI manager                           125   // Create MPI manager
335   G4MPIToolsManager mpiToolsManager(fState, hm    126   G4MPIToolsManager mpiToolsManager(fState, hmpi);
336                                                   127 
337   // H1                                           128   // H1
338   result &= mpiToolsManager.Merge<tools::histo << 129   G4bool result 
                                                   >> 130     = mpiToolsManager.Merge<tools::histo::h1d>(fH1Manager->GetH1Vector(), 
                                                   >> 131                                                fH1Manager->GetHnVector());
                                                   >> 132   finalResult = finalResult && result;
339                                                   133 
340   // H2                                           134   // H2
341   result &= mpiToolsManager.Merge<tools::histo << 135   result 
                                                   >> 136     = mpiToolsManager.Merge<tools::histo::h2d>(fH2Manager->GetH2Vector(), 
                                                   >> 137                                                fH2Manager->GetHnVector());
                                                   >> 138   finalResult = finalResult && result;
342                                                   139 
343   // H3                                           140   // H3
344   result &= mpiToolsManager.Merge<tools::histo << 141   result 
                                                   >> 142     = mpiToolsManager.Merge<tools::histo::h3d>(fH3Manager->GetH3Vector(), 
                                                   >> 143                                                fH3Manager->GetHnVector());
                                                   >> 144   finalResult = finalResult && result;
345                                                   145 
346   // P1                                           146   // P1
347   result &= mpiToolsManager.Merge<tools::histo << 147   result 
                                                   >> 148     = mpiToolsManager.Merge<tools::histo::p1d>(fP1Manager->GetP1Vector(), 
                                                   >> 149                                                fP1Manager->GetHnVector());
                                                   >> 150   finalResult = finalResult && result;
348                                                   151 
349   // P2                                           152   // P2
350   result &= mpiToolsManager.Merge<tools::histo << 153   result 
                                                   >> 154     = mpiToolsManager.Merge<tools::histo::p2d>(fP2Manager->GetP2Vector(), 
                                                   >> 155                                                fP2Manager->GetHnVector());
                                                   >> 156   finalResult = finalResult && result;
351                                                   157 
352   return result;                               << 158   return finalResult;
353 }                                                 159 }
354                                                   160 
355                                                << 
356 //____________________________________________    161 //_____________________________________________________________________________
357 G4bool G4ToolsAnalysisManager::IsEmpty()       << 162 G4bool G4ToolsAnalysisManager::Reset()
358 {                                                 163 {
359   return fH1Manager->IsEmpty() && fH2Manager-> << 164 // Reset histograms and profiles
360          fP1Manager->IsEmpty() && fP2Manager-> << 165 
361 }                                              << 166   auto finalResult = true;
                                                   >> 167   
                                                   >> 168   auto result = fH1Manager->Reset();
                                                   >> 169   finalResult = finalResult && result;
                                                   >> 170 
                                                   >> 171   result = fH2Manager->Reset();
                                                   >> 172   finalResult = finalResult && result;
                                                   >> 173   
                                                   >> 174   result = fH3Manager->Reset();
                                                   >> 175   finalResult = finalResult && result;
                                                   >> 176   
                                                   >> 177   result = fP1Manager->Reset();
                                                   >> 178   finalResult = finalResult && result;
                                                   >> 179   
                                                   >> 180   result = fP2Manager->Reset();
                                                   >> 181   finalResult = finalResult && result;
                                                   >> 182   
                                                   >> 183   return finalResult;
                                                   >> 184 }  
                                                   >> 185  
                                                   >> 186 
362                                                   187