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 11.0.p4)


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