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 11.1.3)


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