Geant4 Cross Reference

Cross-Referencing   Geant4
Geant4/analysis/root/src/G4RootPNtupleManager.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/G4RootPNtupleManager.cc (Version 11.3.0) and /analysis/root/src/G4RootPNtupleManager.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, 04/10/2016  (ivan     27 // Author: Ivana Hrivnacova, 04/10/2016  (ivana@ipno.in2p3.fr)
 28                                                    28 
 29 #include "G4NtupleBookingManager.hh"               29 #include "G4NtupleBookingManager.hh"
 30 #include "G4RootPNtupleManager.hh"                 30 #include "G4RootPNtupleManager.hh"
                                                   >>  31 #include "G4RootMainNtupleManager.hh"
 31 #include "G4AnalysisUtilities.hh"                  32 #include "G4AnalysisUtilities.hh"
 32                                                    33 
 33 #include "tools/wroot/file"                        34 #include "tools/wroot/file"
 34 #include "tools/wroot/ntuple"                      35 #include "tools/wroot/ntuple"
 35                                                    36 
 36 using namespace G4Analysis;                    << 
 37 using std::to_string;                          << 
 38                                                << 
 39 // mutex in a file scope                           37 // mutex in a file scope
 40 namespace {                                        38 namespace {
 41                                                    39 
 42 //Mutex to lock master manager when adding ntu     40 //Mutex to lock master manager when adding ntuple row and ending fill
 43 G4Mutex pntupleMutex = G4MUTEX_INITIALIZER;        41 G4Mutex pntupleMutex = G4MUTEX_INITIALIZER;
 44 //Mutex to lock master manager when createing  << 
 45 G4Mutex createMainMutex = G4MUTEX_INITIALIZER; << 
 46                                                    42 
 47 //____________________________________________     43 //_____________________________________________________________________________
 48 void NotExistWarning(const G4String& what, G4i <<  44 void NotExistException(const G4String& what, G4int id, const G4String& functionName)
 49                      std::string_view classNam << 
 50                      std::string_view function << 
 51 {                                                  45 {
 52   Warn(what + " id= " + to_string(id) + " does <<  46   G4String inFunction = "G4RootPNtupleManager::";
 53     className, functionName);                  <<  47   inFunction += functionName;
 54                                                <<  48   G4ExceptionDescription description;
                                                   >>  49   description << what << " id= " << id << " does not exist.";
                                                   >>  50   G4Exception(inFunction, "Analysis_W011", JustWarning, description);
 55 }                                                  51 }
 56                                                    52 
 57 }                                                  53 }
 58                                                    54 
 59 //____________________________________________     55 //_____________________________________________________________________________
 60 G4RootPNtupleManager::G4RootPNtupleManager(con     56 G4RootPNtupleManager::G4RootPNtupleManager(const G4AnalysisManagerState& state,
 61                         std::shared_ptr<G4Ntup     57                         std::shared_ptr<G4NtupleBookingManager> bookingManger,
 62                         std::shared_ptr<G4Root     58                         std::shared_ptr<G4RootMainNtupleManager> main,
 63                         G4bool rowWise, G4bool     59                         G4bool rowWise, G4bool rowMode)
 64  : G4BaseNtupleManager(state),                     60  : G4BaseNtupleManager(state),
 65    fBookingManager(std::move(bookingManger)),  <<  61    fBookingManager(bookingManger),
 66    fMainNtupleManager(std::move(main)),        <<  62    fMainNtupleManager(main),
                                                   >>  63    fNtupleDescriptionVector(),
                                                   >>  64    fNtupleVector(),
 67    fRowWise(rowWise),                              65    fRowWise(rowWise),
 68    fRowMode(rowMode)                           <<  66    fRowMode(rowMode),
                                                   >>  67    fCreateNtuples(true)
 69 {}                                                 68 {}
 70                                                    69 
 71 //____________________________________________     70 //_____________________________________________________________________________
 72 G4RootPNtupleManager::~G4RootPNtupleManager()      71 G4RootPNtupleManager::~G4RootPNtupleManager()
 73 {                                                  72 {
 74   for ( auto ntupleDescription : fNtupleDescri     73   for ( auto ntupleDescription : fNtupleDescriptionVector ) {
 75     delete ntupleDescription;                      74     delete ntupleDescription;
 76   }                                            <<  75   }   
 77 }                                                  76 }
 78                                                    77 
 79 //                                                 78 //
 80 // private functions                               79 // private functions
 81 //                                                 80 //
 82                                                    81 
 83 //____________________________________________     82 //_____________________________________________________________________________
 84 G4RootPNtupleDescription*                      <<  83 G4RootPNtupleDescription*  
 85 G4RootPNtupleManager::GetNtupleDescriptionInFu     84 G4RootPNtupleManager::GetNtupleDescriptionInFunction(
 86   G4int id, std::string_view functionName, G4b <<  85   G4int id, G4String functionName, G4bool warn) const
 87 {                                              <<  86 {                                      
 88   auto index = id - fFirstId;                      87   auto index = id - fFirstId;
 89   if ( index < 0 || index >= G4int(fNtupleDesc     88   if ( index < 0 || index >= G4int(fNtupleDescriptionVector.size()) ) {
 90     if ( warn) {                                   89     if ( warn) {
 91       NotExistWarning("ntuple description", id <<  90       NotExistException("ntuple description", id, functionName);
 92     }                                              91     }
 93     return nullptr;                            <<  92     return nullptr;         
 94   }                                                93   }
 95                                                <<  94   
 96   return fNtupleDescriptionVector[index];          95   return fNtupleDescriptionVector[index];
 97 }                                                  96 }
 98                                                    97 
 99 //____________________________________________     98 //_____________________________________________________________________________
100 tools::wroot::base_pntuple*                    <<  99 tools::wroot::base_pntuple*  
101  G4RootPNtupleManager::GetNtupleInFunction(       100  G4RootPNtupleManager::GetNtupleInFunction(
102   G4int id, std::string_view functionName, G4b << 101   G4int id, G4String functionName, G4bool warn) const
103 {                                              << 102 {                                      
104   auto ntupleDescription = GetNtupleDescriptio    103   auto ntupleDescription = GetNtupleDescriptionInFunction(id, functionName);
105   if (ntupleDescription == nullptr) return nul << 104   if ( ! ntupleDescription ) return nullptr;
106                                                   105 
107   if (ntupleDescription->GetBasePNtuple() == n << 106   if ( ! ntupleDescription->fBasePNtuple ) {
108     if ( warn ) {                                 107     if ( warn ) {
109       NotExistWarning("ntuple", id, fkClass, f << 108       NotExistException("ntuple", id, functionName);
110     }                                             109     }
111     return nullptr;                               110     return nullptr;
112   }                                            << 111   }  
113   return ntupleDescription->GetBasePNtuple();  << 112   return ntupleDescription->fBasePNtuple;
114 }                                                 113 }
115                                                   114 
116 //____________________________________________    115 //_____________________________________________________________________________
117 tools::wroot::ntuple*                             116 tools::wroot::ntuple*
118 G4RootPNtupleManager::GetMainNtupleInFunction(    117 G4RootPNtupleManager::GetMainNtupleInFunction(
119   G4int id, std::string_view functionName, G4b << 118   G4int id, G4String functionName, G4bool warn) const
120 {                                              << 119 {                                      
121   auto& mainNtupleVector = fMainNtupleManager-    120   auto& mainNtupleVector = fMainNtupleManager->GetNtupleVector();
122                                                   121 
123   auto index = id - fFirstId;                     122   auto index = id - fFirstId;
124   if ( index < 0 || index >= G4int(mainNtupleV    123   if ( index < 0 || index >= G4int(mainNtupleVector.size()) ) {
125     if ( warn) {                                  124     if ( warn) {
126       NotExistWarning("main ntuple", id, fkCla << 125       NotExistException("main ntuple", id, functionName);
127     }                                             126     }
128     return nullptr;                            << 127     return nullptr;         
129   }                                               128   }
130                                                << 129   
131   return mainNtupleVector[index];                 130   return mainNtupleVector[index];
132 }                                                 131 }
133                                                   132 
134 //                                                133 //
135 // protected functions                            134 // protected functions
136 //                                                135 //
137                                                   136 
138 //____________________________________________    137 //_____________________________________________________________________________
139 void G4RootPNtupleManager::CreateNtupleFromMai    138 void G4RootPNtupleManager::CreateNtupleFromMain(
140                              G4RootPNtupleDesc    139                              G4RootPNtupleDescription* ntupleDescription,
141                              tools::wroot::ntu    140                              tools::wroot::ntuple* mainNtuple)
142 {                                                 141 {
143   // Do not create pntuple if ntuple was delet << 142 #ifdef G4VERBOSE
144   if (mainNtuple == nullptr) {                 << 143   if ( fState.GetVerboseL4() ) {
145     ntupleDescription->SetNtuple(nullptr);     << 144     fState.GetVerboseL4()
146     ntupleDescription->SetBasePNtuple(nullptr) << 145       ->Message("create from main", "pntuple", mainNtuple->name());
147     return;                                    << 
148   }                                               146   }
                                                   >> 147 #endif
149                                                   148 
150   Message(kVL4, "create from main", "pntuple", << 149   auto file = fMainNtupleManager->GetNtupleFile(&ntupleDescription->fDescription);
151                                                << 
152   auto file = fMainNtupleManager->GetNtupleFil << 
153   if ( ! file ) {                                 150   if ( ! file ) {
154     Warn("Cannot create pntuple. Main ntuple f << 151     G4String inFunction = "G4RootPNtupleManager::::CreateNtupleFromMain";
155       fkClass, "CreateNtupleFromMain");        << 152     G4ExceptionDescription description;
                                                   >> 153     description
                                                   >> 154       << "Cannot create pntuple. Main ntuple file does not exist." << G4endl;
                                                   >> 155     G4Exception(inFunction, "Analysis_W002", JustWarning, description);
156     return;                                       156     return;
157   }                                               157   }
158                                                   158 
159   ntupleDescription->GetDescription().SetFile( << 159   ntupleDescription->fDescription.fFile = file;
160                                                   160 
161   // Get parameters from ntupleDescription        161   // Get parameters from ntupleDescription
162   mainNtuple->get_branches(ntupleDescription-> << 162   mainNtuple->get_branches(ntupleDescription->fMainBranches);
163                                                   163 
164   auto rfile = std::get<0>(*file);                164   auto rfile = std::get<0>(*file);
165   G4bool verbose = true;                          165   G4bool verbose = true;
166   if ( fRowWise ) {                               166   if ( fRowWise ) {
167     auto mainBranch = mainNtuple->get_row_wise    167     auto mainBranch = mainNtuple->get_row_wise_branch();
168     auto mtNtuple                              << 168     tools::wroot::mt_ntuple_row_wise* mtNtuple 
169       = new tools::wroot::mt_ntuple_row_wise(     169       = new tools::wroot::mt_ntuple_row_wise(
170               G4cout, rfile->byte_swap(), rfil    170               G4cout, rfile->byte_swap(), rfile->compression(),
171               mainNtuple->dir().seek_directory    171               mainNtuple->dir().seek_directory(),
172               *mainBranch, mainBranch->basket_ << 172               *mainBranch, mainBranch->basket_size(), 
173               ntupleDescription->GetDescriptio << 173               ntupleDescription->fDescription.fNtupleBooking, verbose);
174                                                   174 
175     ntupleDescription->SetNtuple(              << 175     ntupleDescription->fNtuple
176       static_cast<tools::wroot::imt_ntuple*>(m << 176       = static_cast<tools::wroot::imt_ntuple*>(mtNtuple);
177     ntupleDescription->SetBasePNtuple(         << 177     ntupleDescription->fBasePNtuple
178       static_cast<tools::wroot::base_pntuple*> << 178       = static_cast<tools::wroot::base_pntuple*>(mtNtuple);
179   }                                            << 179   } 
180   else {                                          180   else {
181     std::vector<tools::uint32> basketSizes;       181     std::vector<tools::uint32> basketSizes;
182     tools_vforcit(tools::wroot::branch*, ntupl << 182     tools_vforcit(tools::wroot::branch*, ntupleDescription->fMainBranches, it) {
183       basketSizes.push_back((*it)->basket_size    183       basketSizes.push_back((*it)->basket_size());
184     }                                             184     }
185     auto basketEntries = fMainNtupleManager->G    185     auto basketEntries = fMainNtupleManager->GetBasketEntries();
186                                                << 186    
187     auto mtNtuple =                            << 187     tools::wroot::mt_ntuple_column_wise* mtNtuple =
188       new tools::wroot::mt_ntuple_column_wise(    188       new tools::wroot::mt_ntuple_column_wise(
189             G4cout, rfile->byte_swap(), rfile-    189             G4cout, rfile->byte_swap(), rfile->compression(),
190             mainNtuple->dir().seek_directory()    190             mainNtuple->dir().seek_directory(),
191             ntupleDescription->GetMainBranches << 191             ntupleDescription->fMainBranches, basketSizes,
192             ntupleDescription->GetDescription( << 192             ntupleDescription->fDescription.fNtupleBooking, 
193             fRowMode, basketEntries, verbose);    193             fRowMode, basketEntries, verbose);
194                                                << 194     
195     ntupleDescription->SetNtuple(              << 195     ntupleDescription->fNtuple
196       static_cast<tools::wroot::imt_ntuple*>(m << 196       = static_cast<tools::wroot::imt_ntuple*>(mtNtuple);
197     ntupleDescription->SetBasePNtuple(         << 197     ntupleDescription->fBasePNtuple
198       static_cast<tools::wroot::base_pntuple*> << 198       = static_cast<tools::wroot::base_pntuple*>(mtNtuple);
199   }                                               199   }
200                                                   200 
201   ntupleDescription->GetDescription().SetIsNtu << 201   ntupleDescription->fDescription.fIsNtupleOwner = true;  
202   //        // pntuple object is not deleted a    202   //        // pntuple object is not deleted automatically
203   fNtupleVector.push_back(ntupleDescription->G << 203   fNtupleVector.push_back(ntupleDescription->fNtuple);  
204                                                   204 
205   Message(kVL3, "create from main", "pntuple", << 205 #ifdef G4VERBOSE
                                                   >> 206   if ( fState.GetVerboseL3() ) {
                                                   >> 207     fState.GetVerboseL3()
                                                   >> 208       ->Message("create from main", "pntuple", mainNtuple->name());
                                                   >> 209   }
                                                   >> 210 #endif
206 }                                                 211 }
207                                                   212 
208 //____________________________________________    213 //_____________________________________________________________________________
209 void G4RootPNtupleManager::CreateNtupleDescrip << 214 void G4RootPNtupleManager::CreateNtuplesFromMain()
210 {                                                 215 {
211 // Create ntuple descriptions from booking.    << 216 // Create ntuple from booking (if not yet done) and main ntuple 
212 // This function is called from the first Fill    217 // This function is called from the first Fill call.
213                                                   218 
214   // Create pntuple descriptions from ntuple b    219   // Create pntuple descriptions from ntuple booking.
215   auto g4NtupleBookings = fBookingManager->Get    220   auto g4NtupleBookings = fBookingManager->GetNtupleBookingVector();
216                                                << 
217   for ( auto g4NtupleBooking : g4NtupleBooking    221   for ( auto g4NtupleBooking : g4NtupleBookings ) {
218     auto ntupleDescription = new G4RootPNtuple    222     auto ntupleDescription = new G4RootPNtupleDescription(g4NtupleBooking);
219     // Save g4booking, activation in pntuple b    223     // Save g4booking, activation in pntuple booking
220     fNtupleDescriptionVector.push_back(ntupleD << 224     fNtupleDescriptionVector.push_back(ntupleDescription);  
221   }                                               225   }
222 }                                              << 
223                                                << 
224 //____________________________________________ << 
225 void G4RootPNtupleManager::CreateNtuplesFromMa << 
226 {                                              << 
227 // Create slave ntuples from  main ntuple.     << 
228 // This function is called from the first Fill << 
229                                                   226 
230   auto& mainNtupleVector = fMainNtupleManager-    227   auto& mainNtupleVector = fMainNtupleManager->GetNtupleVector();
231                                                   228 
232   G4int lcounter = 0;                             229   G4int lcounter = 0;
233   for ( auto mainNtuple : mainNtupleVector ) { << 230   for ( auto mainNtuple : mainNtupleVector ) {    
234     auto& ntupleDescription = fNtupleDescripti    231     auto& ntupleDescription = fNtupleDescriptionVector[lcounter++];
235     CreateNtupleFromMain(ntupleDescription, ma    232     CreateNtupleFromMain(ntupleDescription, mainNtuple);
236   }                                               233   }
237 }                                              << 
238                                                << 
239 //____________________________________________ << 
240 void G4RootPNtupleManager::CreateNtuplesIfNeed << 
241 {                                              << 
242 // The ntuples on workers are created at first << 
243 // (if only columns of vector type) call.      << 
244 // When writing multiple times in teh same fil << 
245 // to be recreated as well.                    << 
246                                                << 
247   // G4cout << "G4RootPNtupleManager::CreateNt << 
248   //   << " fCreateNtuple: " << fCreateNtuples << 
249   //   << " fNewCycle: " << fNewCycle          << 
250   //   << " fMainNtupleManager->GetNewCycle(): << 
251   //   << " fNtupleDescriptionVector.size(): " << 
252   //   << " fNtupleVector.size(): " << fNtuple << 
253   //   << G4endl;                              << 
254                                                << 
255   if (fCreateNtuples) {                        << 
256     // create ntuple descriptions              << 
257     CreateNtupleDescriptionsFromBooking();     << 
258                                                << 
259     // create main ntuples if needed           << 
260     G4AutoLock lock(&createMainMutex);         << 
261     if (fMainNtupleManager->GetNewCycle()) {   << 
262       fMainNtupleManager->CreateNtuplesFromBoo << 
263     }                                          << 
264     lock.unlock();                             << 
265                                                   234 
266     // create slave ntuples                    << 235   fCreateNtuples = false;
267     CreateNtuplesFromMain();                   << 
268     fCreateNtuples = false;                    << 
269   }                                            << 
270                                                << 
271   if (fNewCycle) {                             << 
272     // create main ntuples if needed           << 
273     G4AutoLock lock(&createMainMutex);         << 
274     if (fMainNtupleManager->GetNewCycle()) {   << 
275       fMainNtupleManager->CreateNtuplesFromBoo << 
276     }                                          << 
277     lock.unlock();                             << 
278                                                << 
279     // create slave ntuples                    << 
280     CreateNtuplesFromMain();                   << 
281     fNewCycle = false;                         << 
282   }                                            << 
283 }                                                 236 }
284                                                   237 
285 //____________________________________________    238 //_____________________________________________________________________________
286 G4int G4RootPNtupleManager::CreateNtuple(G4Ntu    239 G4int G4RootPNtupleManager::CreateNtuple(G4NtupleBooking* /*booking*/)
287 {                                                 240 {
288 // Create pntuple from g4 ntuple booking.         241 // Create pntuple from g4 ntuple booking.
289 // Nothing to be done here.                       242 // Nothing to be done here.
290                                                   243 
291   return G4Analysis::kInvalidId;                  244   return G4Analysis::kInvalidId;
292 }                                              << 245 }                                         
293                                                   246 
294 //____________________________________________    247 //_____________________________________________________________________________
295 G4bool G4RootPNtupleManager::FillNtupleIColumn    248 G4bool G4RootPNtupleManager::FillNtupleIColumn(
296   G4int ntupleId, G4int columnId, G4int value)    249   G4int ntupleId, G4int columnId, G4int value)
297 {                                                 250 {
298   return FillNtupleTColumn<int>(ntupleId, colu    251   return FillNtupleTColumn<int>(ntupleId, columnId, value);
299 }                                              << 252 }                                         
300                                                   253 
301 //____________________________________________    254 //_____________________________________________________________________________
302 G4bool G4RootPNtupleManager::FillNtupleFColumn    255 G4bool G4RootPNtupleManager::FillNtupleFColumn(
303   G4int ntupleId, G4int columnId, G4float valu    256   G4int ntupleId, G4int columnId, G4float value)
304 {                                                 257 {
305   return FillNtupleTColumn<float>(ntupleId, co    258   return FillNtupleTColumn<float>(ntupleId, columnId, value);
306 }                                              << 259 }                                         
307                                                   260 
308 //____________________________________________    261 //_____________________________________________________________________________
309 G4bool G4RootPNtupleManager::FillNtupleDColumn    262 G4bool G4RootPNtupleManager::FillNtupleDColumn(
310   G4int ntupleId, G4int columnId, G4double val    263   G4int ntupleId, G4int columnId, G4double value)
311 {                                                 264 {
312   return FillNtupleTColumn<double>(ntupleId, c    265   return FillNtupleTColumn<double>(ntupleId, columnId, value);
313 }                                              << 266 }                                         
314                                                   267 
315 //____________________________________________    268 //_____________________________________________________________________________
316 G4bool G4RootPNtupleManager::FillNtupleSColumn    269 G4bool G4RootPNtupleManager::FillNtupleSColumn(
317   G4int ntupleId, G4int columnId, const G4Stri    270   G4int ntupleId, G4int columnId, const G4String& value)
318 {                                                 271 {
319   return FillNtupleTColumn<std::string>(ntuple    272   return FillNtupleTColumn<std::string>(ntupleId, columnId, value);
320 }                                              << 273 }                                         
321                                                   274 
322 //____________________________________________    275 //_____________________________________________________________________________
323 G4bool G4RootPNtupleManager::AddNtupleRow(G4in    276 G4bool G4RootPNtupleManager::AddNtupleRow(G4int ntupleId)
324 {                                              << 277 { 
325   if ( fState.GetIsActivation() && ( ! GetActi << 278   if (fCreateNtuples) {
326     //G4cout << "Skipping AddNtupleRow for " < << 279     CreateNtuplesFromMain();
327     return false;                              << 
328   }                                            << 
329                                                << 
330   if ( IsVerbose(kVL4) ) {                     << 
331     Message(kVL4, "add", "pntuple row", " ntup << 
332   }                                               280   }
333                                                   281 
334   // Creating ntuples on workers is triggered  << 282   if ( fState.GetIsActivation() && ( ! GetActivation(ntupleId) ) ) {
335   // or AddRow (in only columns of vector type << 283     //G4cout << "Skipping AddNtupleRow for " << ntupleId << G4endl; 
336   CreateNtuplesIfNeeded();                     << 284     return false; 
                                                   >> 285   }  
                                                   >> 286 
                                                   >> 287 #ifdef G4VERBOSE
                                                   >> 288   if ( fState.GetVerboseL4() ) {
                                                   >> 289     G4ExceptionDescription description;
                                                   >> 290     description << " ntupleId " << ntupleId;  
                                                   >> 291     fState.GetVerboseL4()->Message("add", "pntuple row", description);
                                                   >> 292   }  
                                                   >> 293 #endif
337                                                   294 
338   auto ntupleDescription = GetNtupleDescriptio    295   auto ntupleDescription = GetNtupleDescriptionInFunction(ntupleId, "AddNtupleRow");
339   if (ntupleDescription == nullptr) return fal << 296   if ( ! ntupleDescription ) return false;
340                                                   297 
341   auto rfile = std::get<0>(*ntupleDescription- << 298   auto rfile = std::get<0>(*ntupleDescription->fDescription.fFile);
342                                                   299 
343   G4AutoLock lock(&pntupleMutex);                 300   G4AutoLock lock(&pntupleMutex);
344   lock.unlock();                                  301   lock.unlock();
345   mutex toolsLock(lock);                          302   mutex toolsLock(lock);
346   auto result                                  << 303   auto result 
347     = ntupleDescription->GetNtuple()->add_row( << 304     = ntupleDescription->fNtuple->add_row(toolsLock, *rfile);
348                                                   305 
349   if ( ! result ) {                               306   if ( ! result ) {
350     Warn("NtupleId " + to_string(ntupleId) + " << 307     G4ExceptionDescription description;
351       fkClass, "AddNtupleRow");                << 308     description << "      " << " ntupleId " << ntupleId 
352   }                                            << 309                 << "adding row has failed.";
353                                                << 310     G4Exception("G4RootPNtupleManager::AddNtupleRow()",
354   ntupleDescription->GetDescription().SetHasFi << 311                 "Analysis_W022", JustWarning, description);
355                                                << 312   }
356   if ( IsVerbose(kVL3) ) {                     << 313 
357     Message(kVL3, "add", "pntuple row", " ntup << 314   ntupleDescription->fDescription.fHasFill = true;
358   }                                            << 315 
359                                                << 316 #ifdef G4VERBOSE
                                                   >> 317   if ( fState.GetVerboseL3() ) {
                                                   >> 318     G4ExceptionDescription description;
                                                   >> 319     description << " ntupleId " << ntupleId;  
                                                   >> 320     fState.GetVerboseL3()->Message("add", "pntuple row", description);
                                                   >> 321   }  
                                                   >> 322 #endif
360                                                   323 
361   return true;                                    324   return true;
362 }                                                 325 }
363                                                   326 
364 //____________________________________________    327 //_____________________________________________________________________________
365 G4bool G4RootPNtupleManager::Merge()              328 G4bool G4RootPNtupleManager::Merge()
366 {                                                 329 {
367   for ( auto ntupleDescription : fNtupleDescri    330   for ( auto ntupleDescription : fNtupleDescriptionVector) {
368                                                   331 
369     // skip inactivated ntuples                   332     // skip inactivated ntuples
370     if (! ntupleDescription->GetDescription(). << 333     if(!ntupleDescription->fDescription.fActivation || !ntupleDescription->fNtuple) {
371         (ntupleDescription->GetNtuple() == nul << 
372       // G4cout << "skipping inactive ntuple "    334       // G4cout << "skipping inactive ntuple " << G4endl;
373       continue;                                   335       continue;
374     }                                             336     }
375                                                   337 
376     if ( IsVerbose(kVL4) ) {                   << 338 #ifdef G4VERBOSE
377       Message(kVL4, "merge", "pntuple",        << 339     if ( fState.GetVerboseL4() ) {
378         ntupleDescription->GetDescription().Ge << 340       fState.GetVerboseL4()
379     }                                          << 341         ->Message("merge", "pntuple", ntupleDescription->fDescription.fNtupleBooking.name());
380                                                << 342     }  
381     auto rfile = std::get<0>(*ntupleDescriptio << 343 #endif
                                                   >> 344   
                                                   >> 345     auto rfile = std::get<0>(*ntupleDescription->fDescription.fFile);
382                                                   346 
383     G4AutoLock lock(&pntupleMutex);               347     G4AutoLock lock(&pntupleMutex);
384     lock.unlock();                                348     lock.unlock();
385     mutex toolsLock(lock);                        349     mutex toolsLock(lock);
386     auto result                                << 350     auto result 
387       = ntupleDescription->GetNtuple()->end_fi << 351       = ntupleDescription->fNtuple->end_fill(toolsLock, *rfile);
388                                                   352 
389     if ( ! result ) {                             353     if ( ! result ) {
390       Warn("Ntuple " + ntupleDescription->GetD << 354       G4ExceptionDescription description;
391            "end fill has failed.", fkClass, "M << 355       description << "      " << " ntuple " << ntupleDescription->fDescription.fNtupleBooking.name()
392     }                                          << 356                   << "end fill has failed.";
393                                                << 357       G4Exception("G4RootPNtupleManager::Merge()",
394     if ( IsVerbose(kVL3) ) {                   << 358                   "Analysis_W031", JustWarning, description);
395       Message(kVL3, "merge", "pntuple",        << 
396         ntupleDescription->GetDescription().Ge << 
397     }                                             359     }
398                                                   360 
                                                   >> 361     delete ntupleDescription->fNtuple;
                                                   >> 362     ntupleDescription->fNtuple = nullptr;
                                                   >> 363   
                                                   >> 364 #ifdef G4VERBOSE
                                                   >> 365     if ( fState.GetVerboseL3() ) {
                                                   >> 366       fState.GetVerboseL3()
                                                   >> 367         ->Message("merge", "pntuple", ntupleDescription->fDescription.fNtupleBooking.name());
                                                   >> 368     }  
                                                   >> 369 #endif
399   }                                               370   }
400                                                << 
401   // Set new cycle                             << 
402   fNewCycle = true;                            << 
403                                                << 
404   return true;                                    371   return true;
405 }                                              << 
406                                                << 
407 //____________________________________________ << 
408 G4bool G4RootPNtupleManager::Reset()           << 
409 {                                              << 
410   // Reset ntuple description, this will delet << 
411   // we have its ownership.                    << 
412   // The ntuples will be recreated with new cy << 
413                                                << 
414   for ( auto ntupleDescription : fNtupleDescri << 
415     ntupleDescription->Reset();                << 
416   }                                            << 
417                                                << 
418   fNtupleVector.clear();                       << 
419                                                   372 
420   return true;                                 << 
421 }                                                 373 }
422                                                   374 
423 //____________________________________________    375 //_____________________________________________________________________________
424 void G4RootPNtupleManager::Clear()             << 376 G4bool G4RootPNtupleManager::Reset(G4bool deleteNtuple)
425 {                                                 377 {
426   for ( auto ntupleDescription : fNtupleDescri    378   for ( auto ntupleDescription : fNtupleDescriptionVector ) {
427     delete ntupleDescription->GetNtuple();     << 379     if ( deleteNtuple ) {
428   }                                            << 380       delete ntupleDescription->fNtuple;
429                                                << 381     }  
430   fNtupleDescriptionVector.clear();            << 382     ntupleDescription->fNtuple = nullptr;
431   fNtupleVector.clear();                       << 
432                                                << 
433   Message(kVL2, "clear", "pntuples");          << 
434 }                                              << 
435                                                << 
436 //____________________________________________ << 
437 G4bool G4RootPNtupleManager::Delete(G4int id)  << 
438 {                                              << 
439   if ( IsVerbose(G4Analysis::kVL4) ) {         << 
440     Message(G4Analysis::kVL4, "delete", "pntup << 
441   }                                               383   }
442                                                   384 
443   auto ntupleDescription = GetNtupleDescriptio << 385   fNtupleVector.clear(); 
444                                                << 386   
445   if (ntupleDescription == nullptr) return fal << 
446                                                << 
447   // Delete/clear ntuple data                  << 
448   delete ntupleDescription->GetNtuple();       << 
449   ntupleDescription->SetNtuple(nullptr);       << 
450   ntupleDescription->SetBasePNtuple(nullptr);  << 
451   ntupleDescription->GetMainBranches().clear() << 
452                                                << 
453   // Update ntuple vector                      << 
454   auto index = id - GetFirstId();              << 
455   fNtupleVector[index] = nullptr;              << 
456                                                << 
457   Message(G4Analysis::kVL2, "delete", "pntuple << 
458                                                << 
459   return true;                                    387   return true;
460 }                                              << 388 }  
461                                                   389 
462 //____________________________________________    390 //_____________________________________________________________________________
463                                                   391 
464 void  G4RootPNtupleManager::SetActivation(        392 void  G4RootPNtupleManager::SetActivation(
465   G4bool activation)                              393   G4bool activation)
466 {                                                 394 {
467   for ( auto ntupleDescription : fNtupleDescri    395   for ( auto ntupleDescription : fNtupleDescriptionVector ) {
468     ntupleDescription->GetDescription().SetAct << 396     ntupleDescription->fDescription.fActivation = activation;
469   }                                            << 397   } 
470 }                                                 398 }
471                                                   399 
472 //____________________________________________    400 //_____________________________________________________________________________
473                                                   401 
474 void  G4RootPNtupleManager::SetActivation(        402 void  G4RootPNtupleManager::SetActivation(
475   G4int ntupleId, G4bool activation)              403   G4int ntupleId, G4bool activation)
476 {                                                 404 {
477   auto ntupleDescription = GetNtupleDescriptio    405   auto ntupleDescription = GetNtupleDescriptionInFunction(ntupleId, "SetActivation");
478   if (ntupleDescription == nullptr) return;    << 406   if ( ! ntupleDescription ) return;
479                                                   407 
480   ntupleDescription->GetDescription().SetActiv << 408   ntupleDescription->fDescription.fActivation = activation;
481 }                                                 409 }
482                                                   410 
483 //____________________________________________    411 //_____________________________________________________________________________
484 G4bool  G4RootPNtupleManager::GetActivation(      412 G4bool  G4RootPNtupleManager::GetActivation(
485   G4int ntupleId) const                           413   G4int ntupleId) const
486 {                                                 414 {
487   auto ntupleDescription = GetNtupleDescriptio    415   auto ntupleDescription = GetNtupleDescriptionInFunction(ntupleId, "GetActivation");
488   if (ntupleDescription == nullptr) return fal << 416   if ( ! ntupleDescription ) return false;
489                                                   417 
490   return ntupleDescription->GetDescription().G << 418   return ntupleDescription->fDescription.fActivation;
491 }                                                 419 }
492                                                   420 
493 //____________________________________________    421 //_____________________________________________________________________________
494 void G4RootPNtupleManager::SetNewCycle(G4bool  << 422 G4int G4RootPNtupleManager::GetNofNtuples() const
495 {                                                 423 {
496   fNewCycle = value;                           << 424   return fNtupleVector.size();
497 }                                              << 
498                                                << 
499 //____________________________________________ << 
500 G4bool G4RootPNtupleManager::GetNewCycle() con << 
501 {                                              << 
502   return fNewCycle;                            << 
503 }                                                 425 }
504                                                   426 
505 //____________________________________________    427 //_____________________________________________________________________________
506 void G4RootPNtupleManager::SetNtupleRowWise(G4    428 void G4RootPNtupleManager::SetNtupleRowWise(G4bool rowWise, G4bool rowMode)
507 {                                              << 429 { 
508   fRowWise = rowWise;                             430   fRowWise = rowWise;
509   fRowMode = rowMode;                             431   fRowMode = rowMode;
510 }                                                 432 }
511                                                   433