Geant4 Cross Reference

Cross-Referencing   Geant4
Geant4/analysis/root/src/G4RootNtupleFileManager.cc

Version: [ ReleaseNotes ] [ 1.0 ] [ 1.1 ] [ 2.0 ] [ 3.0 ] [ 3.1 ] [ 3.2 ] [ 4.0 ] [ 4.0.p1 ] [ 4.0.p2 ] [ 4.1 ] [ 4.1.p1 ] [ 5.0 ] [ 5.0.p1 ] [ 5.1 ] [ 5.1.p1 ] [ 5.2 ] [ 5.2.p1 ] [ 5.2.p2 ] [ 6.0 ] [ 6.0.p1 ] [ 6.1 ] [ 6.2 ] [ 6.2.p1 ] [ 6.2.p2 ] [ 7.0 ] [ 7.0.p1 ] [ 7.1 ] [ 7.1.p1 ] [ 8.0 ] [ 8.0.p1 ] [ 8.1 ] [ 8.1.p1 ] [ 8.1.p2 ] [ 8.2 ] [ 8.2.p1 ] [ 8.3 ] [ 8.3.p1 ] [ 8.3.p2 ] [ 9.0 ] [ 9.0.p1 ] [ 9.0.p2 ] [ 9.1 ] [ 9.1.p1 ] [ 9.1.p2 ] [ 9.1.p3 ] [ 9.2 ] [ 9.2.p1 ] [ 9.2.p2 ] [ 9.2.p3 ] [ 9.2.p4 ] [ 9.3 ] [ 9.3.p1 ] [ 9.3.p2 ] [ 9.4 ] [ 9.4.p1 ] [ 9.4.p2 ] [ 9.4.p3 ] [ 9.4.p4 ] [ 9.5 ] [ 9.5.p1 ] [ 9.5.p2 ] [ 9.6 ] [ 9.6.p1 ] [ 9.6.p2 ] [ 9.6.p3 ] [ 9.6.p4 ] [ 10.0 ] [ 10.0.p1 ] [ 10.0.p2 ] [ 10.0.p3 ] [ 10.0.p4 ] [ 10.1 ] [ 10.1.p1 ] [ 10.1.p2 ] [ 10.1.p3 ] [ 10.2 ] [ 10.2.p1 ] [ 10.2.p2 ] [ 10.2.p3 ] [ 10.3 ] [ 10.3.p1 ] [ 10.3.p2 ] [ 10.3.p3 ] [ 10.4 ] [ 10.4.p1 ] [ 10.4.p2 ] [ 10.4.p3 ] [ 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/root/src/G4RootNtupleFileManager.cc (Version 11.3.0) and /analysis/root/src/G4RootNtupleFileManager.cc (Version 10.7.p2)


  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                                                    26 
 27 // Author: Ivana Hrivnacova, 15/09/2020 (ivana     27 // Author: Ivana Hrivnacova, 15/09/2020 (ivana@ipno.in2p3.fr)
 28                                                    28 
 29 #include "G4RootNtupleFileManager.hh"              29 #include "G4RootNtupleFileManager.hh"
 30 #include "G4RootFileManager.hh"                    30 #include "G4RootFileManager.hh"
 31 #include "G4RootNtupleManager.hh"                  31 #include "G4RootNtupleManager.hh"
 32 #include "G4RootMainNtupleManager.hh"              32 #include "G4RootMainNtupleManager.hh"
 33 #include "G4RootPNtupleManager.hh"                 33 #include "G4RootPNtupleManager.hh"
 34 #include "G4VAnalysisManager.hh"                   34 #include "G4VAnalysisManager.hh"
                                                   >>  35 #include "G4AnalysisVerbose.hh"
 35 #include "G4AnalysisManagerState.hh"               36 #include "G4AnalysisManagerState.hh"
 36 #include "G4AnalysisUtilities.hh"                  37 #include "G4AnalysisUtilities.hh"
 37                                                    38 
 38 #include "G4Threading.hh"                          39 #include "G4Threading.hh"
 39 #include "G4AutoLock.hh"                           40 #include "G4AutoLock.hh"
 40                                                    41 
 41 using namespace G4Analysis;                    <<  42 #include <iostream>
 42 using std::make_shared;                        <<  43 #include <cstdio>
 43 using std::to_string;                          <<  44 
                                                   >>  45 namespace {
                                                   >>  46 
                                                   >>  47 void MergingException(const G4String& functionName,
                                                   >>  48                       G4ExceptionDescription& description)
                                                   >>  49 {
                                                   >>  50   G4String inFunction = "G4RootNtupleFileManager::" + functionName;
                                                   >>  51   G4Exception(inFunction, "Analysis_W013", JustWarning, description);
                                                   >>  52 }
 44                                                    53 
                                                   >>  54 }
 45                                                    55 
                                                   >>  56 using namespace G4Analysis;
                                                   >>  57 using std::make_shared;
 46                                                    58 
 47 G4RootNtupleFileManager* G4RootNtupleFileManag     59 G4RootNtupleFileManager* G4RootNtupleFileManager::fgMasterInstance = nullptr;
 48                                                    60 
 49 //____________________________________________     61 //_____________________________________________________________________________
 50 G4RootNtupleFileManager::G4RootNtupleFileManag     62 G4RootNtupleFileManager::G4RootNtupleFileManager(const G4AnalysisManagerState& state)
 51  : G4VNtupleFileManager(state, "root")         <<  63  : G4VNtupleFileManager(state, "root"),
 52 {                                              <<  64    fIsInitialized(false),
                                                   >>  65    fNofNtupleFiles(0),
                                                   >>  66    fNtupleRowWise(false),
                                                   >>  67    fNtupleRowMode(true),
                                                   >>  68    fNtupleMergeMode(G4NtupleMergeMode::kNone),
                                                   >>  69    fNtupleManager(nullptr),
                                                   >>  70    fSlaveNtupleManager(nullptr),
                                                   >>  71    fFileManager(nullptr)
                                                   >>  72 {
                                                   >>  73   if ( G4Threading::IsMasterThread() && fgMasterInstance ) {
                                                   >>  74     G4ExceptionDescription description;
                                                   >>  75     description 
                                                   >>  76       << "      " 
                                                   >>  77       << "G4RootNtupleFileManager already exists." 
                                                   >>  78       << "Cannot create another instance.";
                                                   >>  79     G4Exception("G4RootNtupleFileManager::G4RootNtupleFileManager()",
                                                   >>  80                 "Analysis_F001", FatalException, description);
                                                   >>  81   }
 53   if ( G4Threading::IsMasterThread() ) fgMaste     82   if ( G4Threading::IsMasterThread() ) fgMasterInstance = this;
 54                                                    83 
 55   // Do not merge ntuples by default               84   // Do not merge ntuples by default
 56   // Merging may require user code migration a     85   // Merging may require user code migration as analysis manager
 57   // must be created both on master and worker     86   // must be created both on master and workers.
 58   auto mergeNtuples = false;                       87   auto mergeNtuples = false;
 59   SetNtupleMergingMode(mergeNtuples, fNofNtupl     88   SetNtupleMergingMode(mergeNtuples, fNofNtupleFiles);
 60 }                                                  89 }
 61                                                    90 
 62 //____________________________________________     91 //_____________________________________________________________________________
 63 G4RootNtupleFileManager::~G4RootNtupleFileMana     92 G4RootNtupleFileManager::~G4RootNtupleFileManager()
 64 {                                                  93 {
 65   if ( fState.GetIsMaster() ) fgMasterInstance <<  94   if ( fState.GetIsMaster() ) fgMasterInstance = nullptr;  
 66 }                                                  95 }
 67                                                    96 
 68 //                                             <<  97 // 
 69 // private methods                                 98 // private methods
 70 //                                                 99 //
 71                                                   100 
 72 //____________________________________________    101 //_____________________________________________________________________________
 73 void G4RootNtupleFileManager::SetNtupleMerging << 102 void G4RootNtupleFileManager::SetNtupleMergingMode(G4bool mergeNtuples, 
 74                                                   103                                                  G4int nofNtupleFiles)
 75                                                   104 
 76 {                                                 105 {
 77   Message(kVL4, "set", "ntuple merging mode"); << 106 #ifdef G4VERBOSE
                                                   >> 107   if ( fState.GetVerboseL4() ) {
                                                   >> 108     fState.GetVerboseL4()->Message("set", "ntuple merging mode", "");
                                                   >> 109   }
                                                   >> 110 #endif
 78                                                   111 
 79   auto canMerge = true;                           112   auto canMerge = true;
 80                                                   113 
 81   // Illegal situations                           114   // Illegal situations
 82   if ( mergeNtuples && ( ! G4Threading::IsMult    115   if ( mergeNtuples && ( ! G4Threading::IsMultithreadedApplication() ) ) {
 83     Warn("Merging ntuples is not applicable in << 116     G4ExceptionDescription description;
 84          "Setting was ignored.",               << 117     description
 85          fkClass, "SetNtupleMergingMode");     << 118       << "Merging ntuples is not applicable in sequential application." << G4endl
 86     canMerge = false;                          << 119       << "Setting was ignored.";
                                                   >> 120       MergingException("SetNtupleMergingMode", description);
                                                   >> 121     canMerge = false;      
 87   }                                               122   }
 88                                                   123 
 89   // Illegal situations                           124   // Illegal situations
 90   if (mergeNtuples && G4Threading::IsMultithre << 125   if ( mergeNtuples && G4Threading::IsMultithreadedApplication() &&
 91     Warn("Merging ntuples requires G4AnalysisM << 126        ( ! fgMasterInstance ) ) {
 92          "Setting was ignored.",               << 127     G4ExceptionDescription description;
 93          fkClass, "SetNtupleMergingMode");     << 128     description
 94     canMerge = false;                          << 129       << "Merging ntuples requires G4AnalysisManager instance on master." << G4endl
                                                   >> 130       << "Setting was ignored.";
                                                   >> 131     MergingException("SetNtupleMergingMode", description);
                                                   >> 132     canMerge = false;      
 95   }                                               133   }
 96                                                   134 
 97   G4String mergingMode;                           135   G4String mergingMode;
 98   if ( ( ! mergeNtuples ) || ( ! canMerge ) )     136   if ( ( ! mergeNtuples ) || ( ! canMerge ) ) {
 99     fNtupleMergeMode = G4NtupleMergeMode::kNon    137     fNtupleMergeMode = G4NtupleMergeMode::kNone;
100     mergingMode = "G4NtupleMergeMode::kNone";     138     mergingMode = "G4NtupleMergeMode::kNone";
101   }                                               139   }
102   else {                                          140   else {
103     // Set the number of reduced ntuple files     141     // Set the number of reduced ntuple files
104     fNofNtupleFiles = nofNtupleFiles;             142     fNofNtupleFiles = nofNtupleFiles;
105                                                << 143   
106     // Check the number of reduced ntuple file    144     // Check the number of reduced ntuple files
107     if ( fNofNtupleFiles < 0  ) {                 145     if ( fNofNtupleFiles < 0  ) {
108       Warn("Number of reduced files must be [0 << 146       G4ExceptionDescription description;
109            "Cannot set  " + to_string(nofNtupl << 147       description 
110            "Setting was ignored.",             << 148         << "Number of reduced files must be [0, nofThreads]." << G4endl 
111            fkClass, "SetNtupleMergingMode");   << 149         << "Cannot set  " <<  nofNtupleFiles << " files" << G4endl   
                                                   >> 150         << "Ntuples will be merged in a single file.";
                                                   >> 151       MergingException("SetNtupleMergingMode", description);
112       fNofNtupleFiles = 0;                        152       fNofNtupleFiles = 0;
113     }                                             153     }
114                                                << 154   
115     // Forced merging mode                        155     // Forced merging mode
116     G4bool isMaster = ! G4Threading::IsWorkerT    156     G4bool isMaster = ! G4Threading::IsWorkerThread();
117     // G4bool isMaster = fState.GetIsMaster(); << 
118     if ( isMaster ) {                             157     if ( isMaster ) {
119       fNtupleMergeMode = G4NtupleMergeMode::kM    158       fNtupleMergeMode = G4NtupleMergeMode::kMain;
120       mergingMode = "G4NtupleMergeMode::kMain"    159       mergingMode = "G4NtupleMergeMode::kMain";
121     } else {                                      160     } else {
122       fNtupleMergeMode = G4NtupleMergeMode::kS << 161       fNtupleMergeMode = G4NtupleMergeMode::kSlave;    
123       mergingMode = "G4NtupleMergeMode::kSlave    162       mergingMode = "G4NtupleMergeMode::kSlave";
124     }                                             163     }
125   }                                               164   }
126                                                   165 
127   Message(kVL2, "set", "ntuple merging mode",  << 166 #ifdef G4VERBOSE
                                                   >> 167   if ( fState.GetVerboseL2() ) {
                                                   >> 168     fState.GetVerboseL2()->Message("set", "ntuple merging mode", mergingMode);
                                                   >> 169   }
                                                   >> 170 #endif
128 }                                                 171 }
129                                                   172 
130 //____________________________________________    173 //_____________________________________________________________________________
131 G4int G4RootNtupleFileManager::GetNtupleFileNu    174 G4int G4RootNtupleFileManager::GetNtupleFileNumber()
132 {                                                 175 {
133   if (fNofNtupleFiles == 0) return 0;          << 176   if ( ! fNofNtupleFiles ) return 0;
134                                                   177 
135   G4int nofMainManagers = fNofNtupleFiles;        178   G4int nofMainManagers = fNofNtupleFiles;
136   if (nofMainManagers == 0) nofMainManagers =  << 179   if ( ! nofMainManagers ) nofMainManagers = 1;
137                                                   180 
138   auto fileNumber = G4Threading::G4GetThreadId    181   auto fileNumber = G4Threading::G4GetThreadId() % nofMainManagers;
139   return fileNumber;                              182   return fileNumber;
140 }                                                 183 }
141                                                   184 
142 //____________________________________________    185 //_____________________________________________________________________________
143 G4bool G4RootNtupleFileManager::CloseNtupleFil    186 G4bool G4RootNtupleFileManager::CloseNtupleFiles()
144 {                                                 187 {
145   // Take into account main ntuple files if pr << 188  // Close ntuple files
146   auto mainNumber = ( fNofNtupleFiles > 0 ) ?  << 
147                                                   189 
148   auto result = true;                          << 190   auto finalResult = true;
149   auto ntupleVector = fNtupleManager->GetNtupl    191   auto ntupleVector = fNtupleManager->GetNtupleDescriptionVector();
150   for ( auto ntupleDescription : ntupleVector)    192   for ( auto ntupleDescription : ntupleVector) {
151     for (G4int i = mainNumber; i < fNofNtupleF << 193     auto result = fFileManager->CloseNtupleFile(ntupleDescription);
152       result &= fFileManager->CloseNtupleFile( << 194     finalResult = finalResult && result;
153     }                                          << 
154   }                                               195   }
155   return result;                               << 196 
                                                   >> 197   return finalResult;
156 }                                                 198 }
157                                                   199 
158 //                                             << 200 // 
159 // public methods                                 201 // public methods
160 //                                                202 //
161                                                   203 
162 //____________________________________________    204 //_____________________________________________________________________________
163 void G4RootNtupleFileManager::SetNtupleMerging << 205 void G4RootNtupleFileManager::SetNtupleMerging(G4bool mergeNtuples, 
164                                                   206                                                G4int  nofNtupleFiles)
165                                                   207 
166 {                                                 208 {
167   if ( fIsInitialized ) {                         209   if ( fIsInitialized ) {
168     Warn("Cannot change merging mode.\n"       << 210       G4ExceptionDescription description;
169          "The function must be called before O << 211       description 
170          fkClass, "SetNtupleMerging");         << 212         << "Cannot change merging mode." << G4endl
171     return;                                    << 213         << "The function must be called before OpenFile().";
                                                   >> 214       MergingException("SetNtupleMerging", description);
                                                   >> 215       return;
172   }                                               216   }
173                                                   217 
174   // Set ntuple merging mode                   << 218   // Set ntuple merging mode 
175   SetNtupleMergingMode(mergeNtuples, nofNtuple    219   SetNtupleMergingMode(mergeNtuples, nofNtupleFiles);
176 }                                                 220 }
177                                                   221 
178 //____________________________________________    222 //_____________________________________________________________________________
179 void G4RootNtupleFileManager::SetNtupleRowWise << 223 void G4RootNtupleFileManager::SetNtupleRowWise(G4bool rowWise, G4bool rowMode) 
180 {                                                 224 {
181                                                << 225 #ifdef G4VERBOSE
182   // Print info even when setting makes no eff    226   // Print info even when setting makes no effect
183   // (as we do not get printed the default set    227   // (as we do not get printed the default setting in the output)
184   G4String rowWiseMode;                           228   G4String rowWiseMode;
185   if ( rowWise ) {                                229   if ( rowWise ) {
186     rowWiseMode = "row-wise with extra branch"    230     rowWiseMode = "row-wise with extra branch";
187   }                                            << 231   } 
188   else if ( rowMode ) {                           232   else if ( rowMode ) {
189     rowWiseMode = "row-wise";                     233     rowWiseMode = "row-wise";
190   }                                               234   }
191   else {                                          235   else {
192     rowWiseMode = "column-wise";               << 236     rowWiseMode = "column-wise"; 
193   }                                               237   }
194                                                   238 
195   Message(kVL1, "set", "ntuple merging row mod << 239   if ( fState.GetVerboseL1() ) 
                                                   >> 240     fState.GetVerboseL1()
                                                   >> 241       ->Message("set", "ntuple merging row mode", rowWiseMode);
                                                   >> 242 #endif
196                                                   243 
197   // Do nothing if the mode is not changed        244   // Do nothing if the mode is not changed
198   if ( fNtupleRowWise == rowWise && fNtupleRow    245   if ( fNtupleRowWise == rowWise && fNtupleRowMode == rowMode ) return;
199                                                   246 
200   fNtupleRowWise = rowWise;                       247   fNtupleRowWise = rowWise;
201   fNtupleRowMode = rowMode;                       248   fNtupleRowMode = rowMode;
202                                                   249 
203   if ( fNtupleManager ) {                         250   if ( fNtupleManager ) {
204     fNtupleManager->SetNtupleRowWise(rowWise,     251     fNtupleManager->SetNtupleRowWise(rowWise, rowMode);
205   }                                               252   }
206                                                   253 
207   if ( fSlaveNtupleManager ) {                    254   if ( fSlaveNtupleManager ) {
208     fSlaveNtupleManager->SetNtupleRowWise(rowW    255     fSlaveNtupleManager->SetNtupleRowWise(rowWise, rowMode);
209   }                                               256   }
210 }                                                 257 }
211                                                   258 
212 //____________________________________________    259 //_____________________________________________________________________________
213 void G4RootNtupleFileManager::SetBasketSize(un << 260 void G4RootNtupleFileManager::SetBasketSize(unsigned int basketSize) 
214 {                                                 261 {
215   fFileManager->SetBasketSize(basketSize);        262   fFileManager->SetBasketSize(basketSize);
216 }                                                 263 }
217                                                   264 
218 //____________________________________________    265 //_____________________________________________________________________________
219 void G4RootNtupleFileManager::SetBasketEntries    266 void G4RootNtupleFileManager::SetBasketEntries(unsigned int basketEntries)
220 {                                                 267 {
221   fFileManager->SetBasketEntries(basketEntries    268   fFileManager->SetBasketEntries(basketEntries);
222 }                                                 269 }
223                                                   270 
224 //____________________________________________    271 //_____________________________________________________________________________
225 std::shared_ptr<G4VNtupleManager> G4RootNtuple    272 std::shared_ptr<G4VNtupleManager> G4RootNtupleFileManager::CreateNtupleManager()
226 {                                                 273 {
227 // Create and return ntuple manager.              274 // Create and return ntuple manager.
228 // If ntuple merging is activated, managers of    275 // If ntuple merging is activated, managers of different types are created
229 // on master/worker.                              276 // on master/worker.
230                                                   277 
231   Message(kVL4, "create", "ntuple manager");   << 278 #ifdef G4VERBOSE
                                                   >> 279   if ( fState.GetVerboseL4() ) 
                                                   >> 280     fState.GetVerboseL4()->Message("create", "ntuple manager", "");
                                                   >> 281 #endif
232                                                   282 
233   // Check that file manager and anaysis manag    283   // Check that file manager and anaysis manager are set !
234                                                   284 
235   std::shared_ptr<G4VNtupleManager> activeNtup    285   std::shared_ptr<G4VNtupleManager> activeNtupleManager = nullptr;
236   switch ( fNtupleMergeMode )                     286   switch ( fNtupleMergeMode )
237   {                                               287   {
238     case G4NtupleMergeMode::kNone:                288     case G4NtupleMergeMode::kNone:
239       fNtupleManager                           << 289       fNtupleManager 
240         = make_shared<G4RootNtupleManager>(       290         = make_shared<G4RootNtupleManager>(
241             fState, fBookingManager, 0, 0, fNt    291             fState, fBookingManager, 0, 0, fNtupleRowWise, fNtupleRowMode);
242       fNtupleManager->SetFileManager(fFileMana    292       fNtupleManager->SetFileManager(fFileManager);
243       activeNtupleManager = fNtupleManager;       293       activeNtupleManager = fNtupleManager;
244       break;                                      294       break;
245                                                   295 
246     case G4NtupleMergeMode::kMain: {              296     case G4NtupleMergeMode::kMain: {
247       G4int nofMainManagers = fNofNtupleFiles;    297       G4int nofMainManagers = fNofNtupleFiles;
248       if (nofMainManagers == 0) {              << 298       if ( ! nofMainManagers ) nofMainManagers = 1;
249         // create one manager if merging requi << 299              // create one manager if merging required into the histos & profiles files
250         nofMainManagers = 1;                   << 300       fNtupleManager 
251       }                                        << 
252       fNtupleManager                           << 
253         = make_shared<G4RootNtupleManager>(       301         = make_shared<G4RootNtupleManager>(
254             fState, fBookingManager, nofMainMa    302             fState, fBookingManager, nofMainManagers, fNofNtupleFiles, fNtupleRowWise, fNtupleRowMode);
255       fNtupleManager->SetFileManager(fFileMana    303       fNtupleManager->SetFileManager(fFileManager);
256       activeNtupleManager = fNtupleManager;       304       activeNtupleManager = fNtupleManager;
257       break;                                      305       break;
258     }                                             306     }
259                                                   307 
260     case G4NtupleMergeMode::kSlave:               308     case G4NtupleMergeMode::kSlave:
261       fNtupleManager = fgMasterInstance->fNtup    309       fNtupleManager = fgMasterInstance->fNtupleManager;
262         // The master class is used only in Ge    310         // The master class is used only in Get* functions
263       auto mainNtupleManager                   << 311       auto mainNtupleManager 
264         = fNtupleManager->GetMainNtupleManager << 312         = fNtupleManager->GetMainNtupleManager(GetNtupleFileNumber()); 
265       fSlaveNtupleManager                      << 313       fSlaveNtupleManager 
266         = make_shared<G4RootPNtupleManager>(      314         = make_shared<G4RootPNtupleManager>(
267             fState, fBookingManager, mainNtupl    315             fState, fBookingManager, mainNtupleManager, fNtupleRowWise, fNtupleRowMode);
268       activeNtupleManager = fSlaveNtupleManage    316       activeNtupleManager = fSlaveNtupleManager;
269       break;                                      317       break;
270   }                                               318   }
271                                                   319 
272   G4String mergeMode;                          << 320 #ifdef G4VERBOSE
273   switch ( fNtupleMergeMode ) {                << 321   if ( fState.GetVerboseL3() ) {
274     case G4NtupleMergeMode::kNone:             << 322     G4String mergeMode;
275       mergeMode = "";                          << 323     switch ( fNtupleMergeMode ) {
276       break;                                   << 324       case G4NtupleMergeMode::kNone:
277     case G4NtupleMergeMode::kMain:             << 325         mergeMode = "";
278       mergeMode = "main ";                     << 326         break;
279       break;                                   << 327       case G4NtupleMergeMode::kMain:
280     case G4NtupleMergeMode::kSlave:            << 328         mergeMode = "main ";
281       mergeMode = "slave ";                    << 329         break;
282       break;                                   << 330       case G4NtupleMergeMode::kSlave:
                                                   >> 331         mergeMode = "slave ";
                                                   >> 332         break;
                                                   >> 333     }
                                                   >> 334     fState.GetVerboseL3()->Message("create", mergeMode + "ntuple manager", "");
283   }                                               335   }
284   Message(kVL3, "create", mergeMode + "ntuple  << 336 #endif
285                                                   337 
286   fIsInitialized = true;                          338   fIsInitialized = true;
287                                                   339 
288   return activeNtupleManager;                     340   return activeNtupleManager;
289 }                                                 341 }
290                                                   342 
291 //____________________________________________    343 //_____________________________________________________________________________
292 G4bool G4RootNtupleFileManager::ActionAtOpenFi << 344 #ifdef G4VERBOSE
                                                   >> 345 G4bool G4RootNtupleFileManager::ActionAtOpenFile(const G4String& fileName)
                                                   >> 346 #else
                                                   >> 347 G4bool G4RootNtupleFileManager::ActionAtOpenFile(const G4String& /*fileName*/)
                                                   >> 348 #endif
293 {                                                 349 {
294   // Check if fNtupleBookingManager is set        350   // Check if fNtupleBookingManager is set
295                                                   351 
296   if ( fNtupleMergeMode == G4NtupleMergeMode:: << 352   auto finalResult = true;
                                                   >> 353 
                                                   >> 354   if ( fNtupleMergeMode == G4NtupleMergeMode::kNone || 
297        fNtupleMergeMode == G4NtupleMergeMode::    355        fNtupleMergeMode == G4NtupleMergeMode::kMain )  {
298                                                   356 
                                                   >> 357 #ifdef G4VERBOSE
299     G4String objectType = "analysis file";        358     G4String objectType = "analysis file";
300     if ( fNtupleMergeMode == G4NtupleMergeMode    359     if ( fNtupleMergeMode == G4NtupleMergeMode::kMain ) {
301       objectType = "main analysis file";          360       objectType = "main analysis file";
302     }                                             361     }
303     Message(kVL4, "open", objectType, fileName << 362     if ( fState.GetVerboseL4() ) 
                                                   >> 363       fState.GetVerboseL4()->Message("open", objectType, fileName);
                                                   >> 364 #endif
304                                                   365 
305     // Creating files is triggered from Create    366     // Creating files is triggered from CreateNtuple
306     fNtupleManager->CreateNtuplesFromBooking(     367     fNtupleManager->CreateNtuplesFromBooking(
307       fBookingManager->GetNtupleBookingVector(    368       fBookingManager->GetNtupleBookingVector());
308                                                   369 
309     Message(kVL1, "open", objectType, fileName << 370 #ifdef G4VERBOSE
                                                   >> 371     if ( fState.GetVerboseL1() )  {
                                                   >> 372       fState.GetVerboseL1()->Message("open", objectType, fileName, finalResult);
                                                   >> 373     }
                                                   >> 374 #endif
310   }                                               375   }
311                                                   376 
312   // Creating ntuples from main is triggered f    377   // Creating ntuples from main is triggered from the first Fill call
313   // if ( fNtupleMergeMode == G4NtupleMergeMod    378   // if ( fNtupleMergeMode == G4NtupleMergeMode::kSlave )  {
314   //   // G4cout << "Going to create slave ntu    379   //   // G4cout << "Going to create slave ntuples from main" << G4endl;
315   //   fSlaveNtupleManager->CreateNtuplesFromM    380   //   fSlaveNtupleManager->CreateNtuplesFromMain();
316   // }                                            381   // }
317                                                   382 
318   return true;                                 << 383   return finalResult;
319 }                                              << 384 }  
320                                                << 385   
321 //____________________________________________    386 //_____________________________________________________________________________
322 G4bool G4RootNtupleFileManager::ActionAtWrite(    387 G4bool G4RootNtupleFileManager::ActionAtWrite()
323 {                                                 388 {
324   if ( fNtupleMergeMode == G4NtupleMergeMode::    389   if ( fNtupleMergeMode == G4NtupleMergeMode::kNone ) {
325     return true;                                  390     return true;
326   }                                               391   }
327                                                << 392   
328   auto result = true;                          << 393   auto finalResult = true;
329                                                   394 
330   G4String ntupleType;                            395   G4String ntupleType;
331   if ( fNtupleMergeMode == G4NtupleMergeMode::    396   if ( fNtupleMergeMode == G4NtupleMergeMode::kMain ) ntupleType = "main ntuples";
332   if ( fNtupleMergeMode == G4NtupleMergeMode::    397   if ( fNtupleMergeMode == G4NtupleMergeMode::kSlave ) ntupleType = "slave ntuples";
333                                                   398 
334   Message(kVL4, "merge", ntupleType);          << 399 #ifdef G4VERBOSE 
                                                   >> 400   if ( fState.GetVerboseL4() ) 
                                                   >> 401     fState.GetVerboseL4()->Message("merge", ntupleType, "");
                                                   >> 402 #endif
335                                                   403 
336   if ( fNtupleMergeMode == G4NtupleMergeMode::    404   if ( fNtupleMergeMode == G4NtupleMergeMode::kMain )  {
337     result &= fNtupleManager->Merge();         << 405     auto result = fNtupleManager->Merge();
338   }                                            << 406     finalResult = result && finalResult;
339                                                << 407   }  
                                                   >> 408   
340   if ( fNtupleMergeMode == G4NtupleMergeMode::    409   if ( fNtupleMergeMode == G4NtupleMergeMode::kSlave ) {
341     result &= fSlaveNtupleManager->Merge();    << 410     auto result = fSlaveNtupleManager->Merge();
                                                   >> 411     finalResult = result && finalResult;
342   }                                               412   }
343                                                   413 
344   Message(kVL2, "merge", ntupleType, "", resul << 414 #ifdef G4VERBOSE
345                                                << 415   if ( fState.GetVerboseL1() ) 
346   return result;                               << 416     fState.GetVerboseL1()->Message("merge", ntupleType, "");
                                                   >> 417 #endif
                                                   >> 418   
                                                   >> 419   return finalResult;
347 }                                                 420 }
348                                                   421 
349 //____________________________________________    422 //_____________________________________________________________________________
350 G4bool G4RootNtupleFileManager::ActionAtCloseF << 423 G4bool G4RootNtupleFileManager::ActionAtCloseFile(G4bool reset)
351 {                                                 424 {
352   if ( fNtupleMergeMode == G4NtupleMergeMode:: << 425   auto finalResult = true;
353     fSlaveNtupleManager->SetNewCycle(false);   << 426 
354     return true;                               << 427   // close files
                                                   >> 428   if ( fNtupleMergeMode != G4NtupleMergeMode::kSlave )  {
                                                   >> 429     auto result = CloseNtupleFiles();
                                                   >> 430     finalResult = finalResult && result;
                                                   >> 431   }
                                                   >> 432 
                                                   >> 433   if ( ! reset ) {
                                                   >> 434     // The ntuples must be always reset when closing file) 
                                                   >> 435     auto result = Reset();
                                                   >> 436     if ( ! result ) {
                                                   >> 437       G4ExceptionDescription description;
                                                   >> 438       description << "      " << "Resetting data failed";
                                                   >> 439       G4Exception("G4RootNtupleFileManager::CloseFile()",
                                                   >> 440                 "Analysis_W021", JustWarning, description);
                                                   >> 441     }
                                                   >> 442     finalResult = finalResult && result;
355   }                                               443   }
356                                                   444 
357   return CloseNtupleFiles();                   << 445   return finalResult;
358 }                                                 446 }
359                                                   447 
360 //____________________________________________    448 //_____________________________________________________________________________
361 G4bool G4RootNtupleFileManager::Reset()           449 G4bool G4RootNtupleFileManager::Reset()
362 {                                                 450 {
363 // Reset ntuples                                  451 // Reset ntuples
364                                                   452 
365   auto result = true;                             453   auto result = true;
366                                                << 454   
367   if ( fNtupleMergeMode == G4NtupleMergeMode:: << 455   if ( fNtupleMergeMode == G4NtupleMergeMode::kNone || 
368        fNtupleMergeMode == G4NtupleMergeMode::    456        fNtupleMergeMode == G4NtupleMergeMode::kMain )  {
369     result &= fNtupleManager->Reset();         << 457     result = fNtupleManager->Reset(false);
370   }                                            << 458   }  
371                                                << 
372   if ( fNtupleMergeMode == G4NtupleMergeMode:: << 
373     fSlaveNtupleManager->Reset();              << 
374   }                                            << 
375                                                   459 
376   return result;                                  460   return result;
377 }                                                 461 }
378                                                   462