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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/G4RootNtupleManager.cc (Version 11.3.0) and /analysis/root/src/G4RootNtupleManager.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, 18/06/2013  (ivan     27 // Author: Ivana Hrivnacova, 18/06/2013  (ivana@ipno.in2p3.fr)
 28                                                    28 
 29 #include "G4RootNtupleManager.hh"                  29 #include "G4RootNtupleManager.hh"
 30 #include "G4RootMainNtupleManager.hh"              30 #include "G4RootMainNtupleManager.hh"
 31 #include "G4RootFileManager.hh"                    31 #include "G4RootFileManager.hh"
 32 #include "G4AnalysisManagerState.hh"               32 #include "G4AnalysisManagerState.hh"
 33 #include "G4AnalysisUtilities.hh"                  33 #include "G4AnalysisUtilities.hh"
 34                                                    34 
 35 #include "tools/wroot/file"                        35 #include "tools/wroot/file"
 36                                                    36 
 37 using namespace G4Analysis;                        37 using namespace G4Analysis;
 38 using std::to_string;                              38 using std::to_string;
 39                                                    39 
 40 //____________________________________________     40 //_____________________________________________________________________________
 41 G4RootNtupleManager::G4RootNtupleManager(const     41 G4RootNtupleManager::G4RootNtupleManager(const G4AnalysisManagerState& state,
 42                        const std::shared_ptr<G     42                        const std::shared_ptr<G4NtupleBookingManager>& bookingManger,
 43                        G4int nofMainManagers,      43                        G4int nofMainManagers, G4int nofFiles,
 44                        G4bool rowWise, G4bool      44                        G4bool rowWise, G4bool rowMode)
 45  : G4TNtupleManager<tools::wroot::ntuple, G4Ro     45  : G4TNtupleManager<tools::wroot::ntuple, G4RootFile>(state),
 46    fRowWise(rowWise),                              46    fRowWise(rowWise),
 47    fRowMode(rowMode)                               47    fRowMode(rowMode)
 48 {                                                  48 {
 49   for ( G4int i=0; i<nofMainManagers; ++i) {       49   for ( G4int i=0; i<nofMainManagers; ++i) {
 50     auto fileNumber = i;                           50     auto fileNumber = i;
 51     if ( (i == 0) && (nofFiles == 0) ) {           51     if ( (i == 0) && (nofFiles == 0) ) {
 52       // the main ntuple file will be merged i     52       // the main ntuple file will be merged in the default file
 53       fileNumber = -1;                             53       fileNumber = -1;
 54     }                                              54     }
 55     fMainNtupleManagers.push_back(                 55     fMainNtupleManagers.push_back(
 56       std::make_shared<G4RootMainNtupleManager     56       std::make_shared<G4RootMainNtupleManager>(
 57         this, bookingManger, rowWise, fileNumb     57         this, bookingManger, rowWise, fileNumber, fState));
 58   }                                                58   }
 59 }                                                  59 }
 60                                                    60 
 61 //                                                 61 //
 62 // private methods                                 62 // private methods
 63 //                                                 63 //
 64                                                    64 
 65 //____________________________________________     65 //_____________________________________________________________________________
 66 void G4RootNtupleManager::CreateTNtupleFromBoo     66 void G4RootNtupleManager::CreateTNtupleFromBooking(
 67   RootNtupleDescription* ntupleDescription)        67   RootNtupleDescription* ntupleDescription)
 68 {                                                  68 {
 69   if (fMainNtupleManagers.size() == 0u) {          69   if (fMainNtupleManagers.size() == 0u) {
 70     // No merging                                  70     // No merging
 71     if (ntupleDescription->GetNtuple() != null     71     if (ntupleDescription->GetNtuple() != nullptr) {
 72       Warn("Cannot create ntuple. Ntuple alrea     72       Warn("Cannot create ntuple. Ntuple already exists.",
 73         fkClass, "CreateTNtupleFromBooking");      73         fkClass, "CreateTNtupleFromBooking");
 74       return;                                      74       return;
 75     }                                              75     }
 76                                                    76 
 77     // Create ntuple file from ntuple descript     77     // Create ntuple file from ntuple description
 78     auto ntupleFile = fFileManager->CreateNtup     78     auto ntupleFile = fFileManager->CreateNtupleFile(ntupleDescription);
 79     if ( ! ntupleFile ) {                          79     if ( ! ntupleFile ) {
 80       Warn("Cannot create ntuple. Ntuple file      80       Warn("Cannot create ntuple. Ntuple file does not exist.",
 81         fkClass, "CreateTNtupleFromBooking");      81         fkClass, "CreateTNtupleFromBooking");
 82       return;                                      82       return;
 83     }                                              83     }
 84                                                    84 
 85     auto directory = std::get<2>(*ntupleFile);     85     auto directory = std::get<2>(*ntupleFile);
 86     ntupleDescription->SetNtuple(                  86     ntupleDescription->SetNtuple(
 87       new tools::wroot::ntuple(                    87       new tools::wroot::ntuple(
 88             *directory, ntupleDescription->Get     88             *directory, ntupleDescription->GetNtupleBooking(), fRowWise));
 89                                                    89 
 90     auto basketSize = fFileManager->GetBasketS     90     auto basketSize = fFileManager->GetBasketSize();
 91     ntupleDescription->GetNtuple()->set_basket     91     ntupleDescription->GetNtuple()->set_basket_size(basketSize);
                                                   >>  92 
 92     ntupleDescription->SetIsNtupleOwner(false)     93     ntupleDescription->SetIsNtupleOwner(false);
 93            // ntuple object is deleted automat     94            // ntuple object is deleted automatically when closing a file
                                                   >>  95     fNtupleVector.push_back(ntupleDescription->GetNtuple());
 94   }                                                96   }
 95   else {                                           97   else {
 96     // Merging activated                           98     // Merging activated
 97     for ( const auto& manager : fMainNtupleMan     99     for ( const auto& manager : fMainNtupleManagers ) {
 98       manager->SetFirstId(fFirstId);           << 
 99       manager->CreateNtuple(ntupleDescription)    100       manager->CreateNtuple(ntupleDescription);
100     }                                             101     }
101   }                                               102   }
102 }                                                 103 }
103                                                   104 
104 //____________________________________________    105 //_____________________________________________________________________________
105 void G4RootNtupleManager::FinishTNtuple(          106 void G4RootNtupleManager::FinishTNtuple(
106   RootNtupleDescription* /*ntupleDescription*/    107   RootNtupleDescription* /*ntupleDescription*/, G4bool /*fromBooking*/)
107 {                                                 108 {
108   // nothing to be done                           109   // nothing to be done
109 }                                                 110 }
110                                                   111 
111 //____________________________________________    112 //_____________________________________________________________________________
112 G4bool G4RootNtupleManager::Reset()               113 G4bool G4RootNtupleManager::Reset()
113 {                                                 114 {
114   G4TNtupleManager<tools::wroot::ntuple, G4Roo    115   G4TNtupleManager<tools::wroot::ntuple, G4RootFile> ::Reset();
115     // this will clear ntuple vector              116     // this will clear ntuple vector
116                                                   117 
117   auto result = true;                             118   auto result = true;
118                                                   119 
119   for ( const auto& manager : fMainNtupleManag    120   for ( const auto& manager : fMainNtupleManagers ) {
120     result &= manager->Reset();                   121     result &= manager->Reset();
121   }                                               122   }
122                                                   123 
123   return result;                                  124   return result;
124 }                                                 125 }
125                                                   126 
126 //____________________________________________    127 //_____________________________________________________________________________
127 void G4RootNtupleManager::Clear()                 128 void G4RootNtupleManager::Clear()
128 {                                                 129 {
129   G4TNtupleManager<tools::wroot::ntuple, G4Roo    130   G4TNtupleManager<tools::wroot::ntuple, G4RootFile> ::Clear();
130     // this will clear ntuple vector              131     // this will clear ntuple vector
131                                                   132 
132   for ( const auto& manager : fMainNtupleManag    133   for ( const auto& manager : fMainNtupleManagers ) {
133     manager->ClearData();                         134     manager->ClearData();
134   }                                               135   }
135 }                                              << 
136                                                << 
137 //____________________________________________ << 
138 G4bool G4RootNtupleManager::Delete(G4int id)   << 
139 {                                              << 
140   auto result = G4TNtupleManager<tools::wroot: << 
141                                                << 
142   for ( const auto& manager : fMainNtupleManag << 
143     result &= manager->Delete(id);             << 
144   }                                            << 
145                                                << 
146   return result;                               << 
147 }                                                 136 }
148                                                   137 
149 //____________________________________________    138 //_____________________________________________________________________________
150 G4bool G4RootNtupleManager::Merge()               139 G4bool G4RootNtupleManager::Merge()
151 {                                                 140 {
152   auto result = true;                             141   auto result = true;
153                                                   142 
154   for ( const auto& manager : fMainNtupleManag    143   for ( const auto& manager : fMainNtupleManagers ) {
155     result &= manager->Merge();                   144     result &= manager->Merge();
156   }                                               145   }
157                                                   146 
158   return result;                                  147   return result;
159 }                                                 148 }
160                                                   149 
161 //____________________________________________    150 //_____________________________________________________________________________
162 void  G4RootNtupleManager::SetFileManager(        151 void  G4RootNtupleManager::SetFileManager(
163   const std::shared_ptr<G4RootFileManager>& fi    152   const std::shared_ptr<G4RootFileManager>& fileManager)
164 {                                                 153 {
165   fFileManager = fileManager;                     154   fFileManager = fileManager;
166                                                   155 
167   for ( const auto& manager : fMainNtupleManag    156   for ( const auto& manager : fMainNtupleManagers ) {
168     manager->SetFileManager(fileManager);         157     manager->SetFileManager(fileManager);
169   }                                               158   }
170 }                                                 159 }
171                                                   160 
172 //____________________________________________    161 //_____________________________________________________________________________
173 void G4RootNtupleManager::SetNtupleRowWise(G4b    162 void G4RootNtupleManager::SetNtupleRowWise(G4bool rowWise, G4bool rowMode)
174 {                                                 163 {
175 // Set rowWise mode and propagate it to main n    164 // Set rowWise mode and propagate it to main ntuple managers
176                                                   165 
177   fRowWise = rowWise;                             166   fRowWise = rowWise;
178   fRowMode = rowMode;                             167   fRowMode = rowMode;
179                                                   168 
180   for (auto& mainNtupleManager : fMainNtupleMa    169   for (auto& mainNtupleManager : fMainNtupleManagers ) {
181     mainNtupleManager->SetRowWise(rowWise);       170     mainNtupleManager->SetRowWise(rowWise);
182   }                                               171   }
183 }                                                 172 }
184                                                   173 
185 //____________________________________________    174 //_____________________________________________________________________________
186 void G4RootNtupleManager::SetNewCycle(G4bool v    175 void G4RootNtupleManager::SetNewCycle(G4bool value)
187 {                                                 176 {
188   G4TNtupleManager<tools::wroot::ntuple, G4Roo    177   G4TNtupleManager<tools::wroot::ntuple, G4RootFile>::SetNewCycle(value);
189                                                   178 
190   for ( const auto& manager : fMainNtupleManag    179   for ( const auto& manager : fMainNtupleManagers ) {
191     manager->SetNewCycle(value);                  180     manager->SetNewCycle(value);
192   }                                               181   }
193 }                                                 182 }
194                                                   183 
195 //____________________________________________    184 //_____________________________________________________________________________
196 std::shared_ptr<G4RootMainNtupleManager>          185 std::shared_ptr<G4RootMainNtupleManager>
197 G4RootNtupleManager::GetMainNtupleManager(G4in    186 G4RootNtupleManager::GetMainNtupleManager(G4int index) const
198 {                                                 187 {
199   if ( index < 0 || index >= G4int(fMainNtuple    188   if ( index < 0 || index >= G4int(fMainNtupleManagers.size()) ) {
200     Warn("main ntuple manager " + to_string(in    189     Warn("main ntuple manager " + to_string(index) + " does not exist.",
201       fkClass, "GetMainNtupleManager");           190       fkClass, "GetMainNtupleManager");
202     return nullptr;                               191     return nullptr;
203   }                                               192   }
204                                                   193 
205   return fMainNtupleManagers[index];              194   return fMainNtupleManagers[index];
206 }                                                 195 }
207                                                   196 
208 //____________________________________________    197 //_____________________________________________________________________________
209 unsigned int G4RootNtupleManager::GetBasketSiz    198 unsigned int G4RootNtupleManager::GetBasketSize() const
210 {                                                 199 {
211   if ( ! fFileManager ) {                         200   if ( ! fFileManager ) {
212     Warn("File manager must be defined first."    201     Warn("File manager must be defined first.", fkClass, "GetBasketSize");
213     return 0;                                     202     return 0;
214   }                                               203   }
215                                                   204 
216   return fFileManager->GetBasketSize();           205   return fFileManager->GetBasketSize();
217 }                                                 206 }
218                                                   207 
219 //____________________________________________    208 //_____________________________________________________________________________
220 unsigned int G4RootNtupleManager::GetBasketEnt    209 unsigned int G4RootNtupleManager::GetBasketEntries() const
221 {                                                 210 {
222   if ( ! fFileManager ) {                         211   if ( ! fFileManager ) {
223     Warn("File manager must be defined first."    212     Warn("File manager must be defined first.", fkClass, "GetBasketEntries");
224     return 0;                                     213     return 0;
225   }                                               214   }
226                                                   215 
227   return fFileManager->GetBasketEntries();        216   return fFileManager->GetBasketEntries();
228 }                                                 217 }
229                                                   218