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 ] [ 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/G4RootMainNtupleManager.cc (Version 11.3.0) and /analysis/root/src/G4RootMainNtupleManager.cc (Version 8.3.p2)


  1 //                                                  1 
  2 // *******************************************    
  3 // * License and Disclaimer                       
  4 // *                                              
  5 // * The  Geant4 software  is  copyright of th    
  6 // * the Geant4 Collaboration.  It is provided    
  7 // * conditions of the Geant4 Software License    
  8 // * LICENSE and available at  http://cern.ch/    
  9 // * include a list of copyright holders.         
 10 // *                                              
 11 // * Neither the authors of this software syst    
 12 // * institutes,nor the agencies providing fin    
 13 // * work  make  any representation or  warran    
 14 // * regarding  this  software system or assum    
 15 // * use.  Please see the license in the file     
 16 // * for the full disclaimer and the limitatio    
 17 // *                                              
 18 // * This  code  implementation is the result     
 19 // * technical work of the GEANT4 collaboratio    
 20 // * By using,  copying,  modifying or  distri    
 21 // * any work based  on the software)  you  ag    
 22 // * use  in  resulting  scientific  publicati    
 23 // * acceptance of all terms of the Geant4 Sof    
 24 // *******************************************    
 25 //                                                
 26 //                                                
 27 // Author: Ivana Hrivnacova, 04/10/2016  (ivan    
 28                                                   
 29 #include "G4RootMainNtupleManager.hh"             
 30 #include "G4RootFileManager.hh"                   
 31 #include "G4RootNtupleManager.hh"                 
 32 #include "G4AnalysisUtilities.hh"                 
 33                                                   
 34 #include "tools/wroot/file"                       
 35 #include "tools/wroot/ntuple"                     
 36                                                   
 37 using namespace G4Analysis;                       
 38                                                   
 39 //____________________________________________    
 40 G4RootMainNtupleManager::G4RootMainNtupleManag    
 41                 G4RootNtupleManager* ntupleBui    
 42                 std::shared_ptr<G4NtupleBookin    
 43                 G4bool rowWise,                   
 44                 G4int fileNumber,                 
 45                 const G4AnalysisManagerState&     
 46  : G4BaseAnalysisManager(state),                  
 47    fNtupleBuilder(ntupleBuilder),                 
 48    fBookingManager(std::move(bookingManager)),    
 49    fRowWise(rowWise),                             
 50    fFileNumber(fileNumber)                        
 51 {}                                                
 52                                                   
 53 //                                                
 54 // private functions                              
 55 //                                                
 56                                                   
 57 //____________________________________________    
 58 G4int G4RootMainNtupleManager::CreateNtupleFro    
 59   G4NtupleBooking* g4NtupleBooking, std::share    
 60 {                                                 
 61   // Do not create ntuple if it was deleted       
 62   if ( g4NtupleBooking->GetDeleted()) {           
 63     // G4cout << "Ntuple " << g4NtupleBooking-    
 64     return G4Analysis::kInvalidId;                
 65   }                                               
 66                                                   
 67   // The ntuple index                             
 68   auto index = g4NtupleBooking->fNtupleId - fF    
 69                                                   
 70   // Do not create ntuple if it already exists    
 71   if ( (index < G4int(fNtupleVector.size())) &    
 72     // G4cout << "Ntuple " << g4NtupleBooking-    
 73     return G4Analysis::kInvalidId;                
 74   }                                               
 75                                                   
 76   // Get ntuple booking                           
 77   const auto& ntupleBooking = g4NtupleBooking-    
 78                                                   
 79   Message(kVL4, "create", "main ntuple", ntupl    
 80                                                   
 81   // Allocate the ntuple vector element(s) if     
 82   while ( index >= G4int(fNtupleVector.size())    
 83     fNtupleVector.push_back(nullptr);             
 84   }                                               
 85                                                   
 86   // Create ntuple                                
 87   auto ntuple = new tools::wroot::ntuple(*std:    
 88          // ntuple object is deleted automatic    
 89   auto basketSize = fNtupleBuilder->GetBasketS    
 90   ntuple->set_basket_size(basketSize);            
 91                                                   
 92   // Save ntuple & ntuple description pair in     
 93   fNtupleVector[index] = ntuple;                  
 94                                                   
 95   Message(kVL3, "create", "main ntuple", ntupl    
 96                                                   
 97   return index;                                   
 98 }                                                 
 99                                                   
100 //                                                
101 // protected functions                            
102 //                                                
103                                                   
104 //____________________________________________    
105 void G4RootMainNtupleManager::CreateNtuple(Roo    
106                                            G4b    
107 {                                                 
108 // Create ntuple from booking if file was open    
109                                                   
110   // Get/Create main ntuple file                  
111   auto ntupleFile = fFileManager->CreateNtuple    
112   if ( ntupleFile == nullptr ) {                  
113     if ( warn ) {                                 
114       Warn("Ntuple file must be defined first.    
115            "Cannot create main ntuple.",          
116            fkClass, "CreateNtuple");              
117     }                                             
118     return;                                       
119   }                                               
120                                                   
121   // Create ntuple from g4 booking                
122   auto g4NtupleBooking = ntupleDescription->Ge    
123   auto index = CreateNtupleFromBooking(g4Ntupl    
124                                                   
125   // Return if ntuple was not created             
126   if (index == G4Analysis::kInvalidId) return;    
127                                                   
128   // Allocate the ntuple description pair vect    
129   while ( index >= G4int(fNtupleDescriptionVec    
130     fNtupleDescriptionVector.emplace_back(null    
131   }                                               
132                                                   
133   // Save ntuple description pair in vectors      
134   fNtupleDescriptionVector[index] = std::make_    
135 }                                                 
136                                                   
137 //____________________________________________    
138 G4bool G4RootMainNtupleManager::Delete(G4int i    
139 {                                                 
140   if (fNtupleVector.empty()) {                    
141     // Main ntuples are delete with each new c    
142     return true;                                  
143   }                                               
144                                                   
145   // Proceed with deleting if vector is not em    
146                                                   
147   Message(kVL4, "delete", "main ntuple ntupleI    
148                                                   
149   // Get ntuple description                       
150   auto index = id - fFirstId;                     
151   if ( index < 0 || index >= G4int(fNtupleVect    
152     G4Analysis::Warn("Main ntuple " + to_strin    
153       fkClass, "Delete");                         
154     return false;                                 
155   }                                               
156                                                   
157   // Delete main ntuple and update ntuple vect    
158   delete fNtupleVector[index];                    
159   fNtupleVector[index] = nullptr;                 
160                                                   
161   Message(kVL3, "delete", "main ntuple ntupleI    
162                                                   
163   return true;                                    
164 }                                                 
165                                                   
166 //____________________________________________    
167 G4bool G4RootMainNtupleManager::Merge()           
168 {                                                 
169   std::size_t counter = 0;                        
170                                                   
171   for ( auto ntuple : fNtupleVector ) {           
172     // skip deleted ntuples                       
173     if (ntuple == nullptr) continue;              
174                                                   
175     ntuple->merge_number_of_entries();            
176                                                   
177     // Notify ntuple description that file is     
178     if (ntuple->entries() != 0u) {                
179       auto ntupleDescription = fNtupleDescript    
180       ntupleDescription->SetHasFill(true);        
181     }                                             
182     ++counter;                                    
183   }                                               
184                                                   
185   return true;                                    
186 }                                                 
187                                                   
188 //____________________________________________    
189 G4bool G4RootMainNtupleManager::Reset()           
190 {                                                 
191   // The ntuples will be recreated with new cy    
192   // Ntuple objects are deleted automatically     
193                                                   
194   fNtupleVector.clear();                          
195                                                   
196   return true;                                    
197 }                                                 
198                                                   
199 //____________________________________________    
200 void G4RootMainNtupleManager::ClearData()         
201 {                                                 
202   fNtupleDescriptionVector.clear();               
203   fNtupleVector.clear();                          
204                                                   
205   Message(G4Analysis::kVL2, "clear", "main ntu    
206 }                                                 
207                                                   
208 //____________________________________________    
209 std::shared_ptr<G4RootFile>                       
210 G4RootMainNtupleManager::GetNtupleFile(RootNtu    
211 {                                                 
212   auto perThread = false;                         
213   return fFileManager->GetNtupleFile(ntupleDes    
214 }                                                 
215                                                   
216 //                                                
217 // public functions                               
218 //                                                
219                                                   
220 //____________________________________________    
221 void G4RootMainNtupleManager::CreateNtuplesFro    
222 {                                                 
223 // Create ntuples from booking (without creati    
224 // This function is triggered from workers at     
225                                                   
226   for (auto [ntupleDescription, ntupleFile] :     
227     CreateNtupleFromBooking(ntupleDescription-    
228   }                                               
229                                                   
230   SetNewCycle(false);                             
231 }                                                 
232