Geant4 Cross Reference

Cross-Referencing   Geant4
Geant4/analysis/root/src/G4RootNtupleManager.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/G4RootNtupleManager.cc (Version 11.3.0) and /analysis/root/src/G4RootNtupleManager.cc (Version 10.0.p4)


  1 //                                                  1 //
  2 // *******************************************      2 // ********************************************************************
  3 // * License and Disclaimer                         3 // * License and Disclaimer                                           *
  4 // *                                                4 // *                                                                  *
  5 // * The  Geant4 software  is  copyright of th      5 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
  6 // * the Geant4 Collaboration.  It is provided      6 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
  7 // * conditions of the Geant4 Software License      7 // * conditions of the Geant4 Software License,  included in the file *
  8 // * LICENSE and available at  http://cern.ch/      8 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
  9 // * include a list of copyright holders.           9 // * include a list of copyright holders.                             *
 10 // *                                               10 // *                                                                  *
 11 // * Neither the authors of this software syst     11 // * Neither the authors of this software system, nor their employing *
 12 // * institutes,nor the agencies providing fin     12 // * institutes,nor the agencies providing financial support for this *
 13 // * work  make  any representation or  warran     13 // * work  make  any representation or  warranty, express or implied, *
 14 // * regarding  this  software system or assum     14 // * regarding  this  software system or assume any liability for its *
 15 // * use.  Please see the license in the file      15 // * use.  Please see the license in the file  LICENSE  and URL above *
 16 // * for the full disclaimer and the limitatio     16 // * for the full disclaimer and the limitation of liability.         *
 17 // *                                               17 // *                                                                  *
 18 // * This  code  implementation is the result      18 // * This  code  implementation is the result of  the  scientific and *
 19 // * technical work of the GEANT4 collaboratio     19 // * technical work of the GEANT4 collaboration.                      *
 20 // * By using,  copying,  modifying or  distri     20 // * By using,  copying,  modifying or  distributing the software (or *
 21 // * any work based  on the software)  you  ag     21 // * any work based  on the software)  you  agree  to acknowledge its *
 22 // * use  in  resulting  scientific  publicati     22 // * use  in  resulting  scientific  publications,  and indicate your *
 23 // * acceptance of all terms of the Geant4 Sof     23 // * acceptance of all terms of the Geant4 Software license.          *
 24 // *******************************************     24 // ********************************************************************
 25 //                                                 25 //
                                                   >>  26 // $Id: G4RootNtupleManager.cc 70604 2013-06-03 11:27:06Z ihrivnac $
 26                                                    27 
 27 // Author: Ivana Hrivnacova, 18/06/2013  (ivan     28 // Author: Ivana Hrivnacova, 18/06/2013  (ivana@ipno.in2p3.fr)
 28                                                    29 
 29 #include "G4RootNtupleManager.hh"                  30 #include "G4RootNtupleManager.hh"
 30 #include "G4RootMainNtupleManager.hh"          <<  31 #include "G4RootNtupleDescription.hh"
 31 #include "G4RootFileManager.hh"                << 
 32 #include "G4AnalysisManagerState.hh"               32 #include "G4AnalysisManagerState.hh"
 33 #include "G4AnalysisUtilities.hh"              << 
 34                                                    33 
 35 #include "tools/wroot/file"                        34 #include "tools/wroot/file"
 36                                                    35 
 37 using namespace G4Analysis;                    << 
 38 using std::to_string;                          << 
 39                                                << 
 40 //____________________________________________ << 
 41 G4RootNtupleManager::G4RootNtupleManager(const << 
 42                        const std::shared_ptr<G << 
 43                        G4int nofMainManagers,  << 
 44                        G4bool rowWise, G4bool  << 
 45  : G4TNtupleManager<tools::wroot::ntuple, G4Ro << 
 46    fRowWise(rowWise),                          << 
 47    fRowMode(rowMode)                           << 
 48 {                                              << 
 49   for ( G4int i=0; i<nofMainManagers; ++i) {   << 
 50     auto fileNumber = i;                       << 
 51     if ( (i == 0) && (nofFiles == 0) ) {       << 
 52       // the main ntuple file will be merged i << 
 53       fileNumber = -1;                         << 
 54     }                                          << 
 55     fMainNtupleManagers.push_back(             << 
 56       std::make_shared<G4RootMainNtupleManager << 
 57         this, bookingManger, rowWise, fileNumb << 
 58   }                                            << 
 59 }                                              << 
 60                                                << 
 61 //                                             << 
 62 // private methods                             << 
 63 //                                             << 
 64                                                << 
 65 //____________________________________________     36 //_____________________________________________________________________________
 66 void G4RootNtupleManager::CreateTNtupleFromBoo <<  37 G4RootNtupleManager::G4RootNtupleManager(const G4AnalysisManagerState& state)
 67   RootNtupleDescription* ntupleDescription)    <<  38  : G4VNtupleManager(state),
                                                   >>  39    fNtupleDirectory(0),
                                                   >>  40    fNtupleVector()
 68 {                                                  41 {
 69   if (fMainNtupleManagers.size() == 0u) {      << 
 70     // No merging                              << 
 71     if (ntupleDescription->GetNtuple() != null << 
 72       Warn("Cannot create ntuple. Ntuple alrea << 
 73         fkClass, "CreateTNtupleFromBooking");  << 
 74       return;                                  << 
 75     }                                          << 
 76                                                << 
 77     // Create ntuple file from ntuple descript << 
 78     auto ntupleFile = fFileManager->CreateNtup << 
 79     if ( ! ntupleFile ) {                      << 
 80       Warn("Cannot create ntuple. Ntuple file  << 
 81         fkClass, "CreateTNtupleFromBooking");  << 
 82       return;                                  << 
 83     }                                          << 
 84                                                << 
 85     auto directory = std::get<2>(*ntupleFile); << 
 86     ntupleDescription->SetNtuple(              << 
 87       new tools::wroot::ntuple(                << 
 88             *directory, ntupleDescription->Get << 
 89                                                << 
 90     auto basketSize = fFileManager->GetBasketS << 
 91     ntupleDescription->GetNtuple()->set_basket << 
 92     ntupleDescription->SetIsNtupleOwner(false) << 
 93            // ntuple object is deleted automat << 
 94   }                                            << 
 95   else {                                       << 
 96     // Merging activated                       << 
 97     for ( const auto& manager : fMainNtupleMan << 
 98       manager->SetFirstId(fFirstId);           << 
 99       manager->CreateNtuple(ntupleDescription) << 
100     }                                          << 
101   }                                            << 
102 }                                                  42 }
103                                                    43 
104 //____________________________________________     44 //_____________________________________________________________________________
105 void G4RootNtupleManager::FinishTNtuple(       <<  45 G4RootNtupleManager::~G4RootNtupleManager()
106   RootNtupleDescription* /*ntupleDescription*/ <<  46 {  
107 {                                              <<  47   std::vector<G4RootNtupleDescription*>::iterator it;  
108   // nothing to be done                        <<  48   for (it = fNtupleVector.begin(); it != fNtupleVector.end(); it++ ) {
                                                   >>  49     delete (*it);
                                                   >>  50   }   
109 }                                                  51 }
110                                                    52 
111 //____________________________________________ <<  53 // 
112 G4bool G4RootNtupleManager::Reset()            <<  54 // private methods
113 {                                              <<  55 //
114   G4TNtupleManager<tools::wroot::ntuple, G4Roo << 
115     // this will clear ntuple vector           << 
116                                                << 
117   auto result = true;                          << 
118                                                << 
119   for ( const auto& manager : fMainNtupleManag << 
120     result &= manager->Reset();                << 
121   }                                            << 
122                                                << 
123   return result;                               << 
124 }                                              << 
125                                                    56 
126 //____________________________________________     57 //_____________________________________________________________________________
127 void G4RootNtupleManager::Clear()              <<  58 tools::wroot::ntuple::column<int>*    
                                                   >>  59 G4RootNtupleManager::GetNtupleIColumn(G4int ntupleId, G4int columnId) const
128 {                                                  60 {
129   G4TNtupleManager<tools::wroot::ntuple, G4Roo <<  61   G4RootNtupleDescription* ntupleDecription
130     // this will clear ntuple vector           <<  62     = GetNtupleInFunction(ntupleId, "GetNtupleIColumn");
131                                                <<  63   if ( ! ntupleDecription ) return 0;
132   for ( const auto& manager : fMainNtupleManag <<  64 
133     manager->ClearData();                      <<  65   std::map<G4int, tools::wroot::ntuple::column<int>* >& ntupleIColumnMap
                                                   >>  66     = ntupleDecription->fNtupleIColumnMap;
                                                   >>  67   std::map<G4int, tools::wroot::ntuple::column<int>* >::const_iterator it
                                                   >>  68     = ntupleIColumnMap.find(columnId);
                                                   >>  69 
                                                   >>  70   if ( it == ntupleIColumnMap.end() ) {
                                                   >>  71     G4ExceptionDescription description;
                                                   >>  72     description << "      "  << "ntupleId " << ntupleId
                                                   >>  73                 << " columnId " << columnId << " does not exist.";
                                                   >>  74     G4Exception("G4RootNtupleManager::GetNtupleIColumn()",
                                                   >>  75                 "Analysis_W009", JustWarning, description);
                                                   >>  76     return 0;
134   }                                                77   }
135 }                                              <<  78   
136                                                <<  79   return it->second;
137 //____________________________________________ <<  80 }  
138 G4bool G4RootNtupleManager::Delete(G4int id)   <<  81     
139 {                                              <<  82 //_____________________________________________________________________________
140   auto result = G4TNtupleManager<tools::wroot: <<  83 tools::wroot::ntuple::column<float>*  
141                                                <<  84 G4RootNtupleManager::GetNtupleFColumn(G4int ntupleId, G4int columnId) const
142   for ( const auto& manager : fMainNtupleManag <<  85 {
143     result &= manager->Delete(id);             <<  86   G4RootNtupleDescription* ntupleDecription
                                                   >>  87     = GetNtupleInFunction(ntupleId, "GetNtupleIColumn");
                                                   >>  88   if ( ! ntupleDecription ) return 0;
                                                   >>  89 
                                                   >>  90   std::map<G4int, tools::wroot::ntuple::column<float>* >& ntupleFColumnMap
                                                   >>  91     = ntupleDecription->fNtupleFColumnMap;
                                                   >>  92   std::map<G4int, tools::wroot::ntuple::column<float>* >::const_iterator it
                                                   >>  93     = ntupleFColumnMap.find(columnId);
                                                   >>  94     
                                                   >>  95   if ( it == ntupleFColumnMap.end() ) {
                                                   >>  96     G4ExceptionDescription description;
                                                   >>  97     description << "      "  << "ntupleId " << ntupleId
                                                   >>  98                 << " columnId " << columnId << " does not exist.";
                                                   >>  99     G4Exception("G4RootNtupleManager::GetNtupleFColumn()",
                                                   >> 100                 "Analysis_W009", JustWarning, description);
                                                   >> 101     return 0;
144   }                                               102   }
                                                   >> 103   
                                                   >> 104   return it->second;
                                                   >> 105 }  
145                                                   106 
146   return result;                               << 
147 }                                              << 
148                                                   107 
149 //____________________________________________    108 //_____________________________________________________________________________
150 G4bool G4RootNtupleManager::Merge()            << 109 tools::wroot::ntuple::column<double>* 
151 {                                              << 110 G4RootNtupleManager::GetNtupleDColumn(G4int ntupleId, G4int columnId) const
152   auto result = true;                          << 111 {
153                                                << 112   G4RootNtupleDescription* ntupleDecription
154   for ( const auto& manager : fMainNtupleManag << 113     = GetNtupleInFunction(ntupleId, "GetNtupleIColumn");
155     result &= manager->Merge();                << 114   if ( ! ntupleDecription ) return 0;
                                                   >> 115 
                                                   >> 116   std::map<G4int, tools::wroot::ntuple::column<double>* >& ntupleDColumnMap
                                                   >> 117     = ntupleDecription->fNtupleDColumnMap;
                                                   >> 118   std::map<G4int, tools::wroot::ntuple::column<double>* >::const_iterator it
                                                   >> 119     = ntupleDColumnMap.find(columnId);
                                                   >> 120     
                                                   >> 121   if ( it == ntupleDColumnMap.end() ) {
                                                   >> 122     G4ExceptionDescription description;
                                                   >> 123     description << "      "  << "ntupleId " << ntupleId
                                                   >> 124                 << " columnId " << columnId << " does not exist.";
                                                   >> 125     G4Exception("G4RootNtupleManager::GetNtupleDColumn()",
                                                   >> 126                 "Analysis_W009", JustWarning, description);
                                                   >> 127     return 0;
156   }                                               128   }
157                                                << 129   
158   return result;                               << 130   return it->second;
159 }                                              << 131 }  
160                                                << 132  
161 //____________________________________________ << 133 //_____________________________________________________________________________
162 void  G4RootNtupleManager::SetFileManager(     << 134 G4RootNtupleDescription* G4RootNtupleManager::GetNtupleInFunction(G4int id, 
163   const std::shared_ptr<G4RootFileManager>& fi << 135                                       G4String functionName, G4bool warn,
164 {                                              << 136                                       G4bool /*onlyIfActive*/) const
165   fFileManager = fileManager;                  << 137 {                                      
166                                                << 138   G4int index = id - fFirstId;
167   for ( const auto& manager : fMainNtupleManag << 139   if ( index < 0 || index >= G4int(fNtupleVector.size()) ) {
168     manager->SetFileManager(fileManager);      << 140     if ( warn) {
                                                   >> 141       G4String inFunction = "G4RootNtupleManager::";
                                                   >> 142       inFunction += functionName;
                                                   >> 143       G4ExceptionDescription description;
                                                   >> 144       description << "      " << "ntuple " << id << " does not exist.";
                                                   >> 145       G4Exception(inFunction, "Analysis_W007", JustWarning, description);
                                                   >> 146     }
                                                   >> 147     return 0;         
169   }                                               148   }
                                                   >> 149   
                                                   >> 150   return fNtupleVector[index];
170 }                                                 151 }
                                                   >> 152   
                                                   >> 153 // 
                                                   >> 154 // protected methods
                                                   >> 155 //
171                                                   156 
172 //____________________________________________    157 //_____________________________________________________________________________
173 void G4RootNtupleManager::SetNtupleRowWise(G4b << 158 void G4RootNtupleManager::CreateNtuplesFromBooking()
174 {                                                 159 {
175 // Set rowWise mode and propagate it to main n << 160 // Create ntuple from ntuple_booking.
176                                                << 
177   fRowWise = rowWise;                          << 
178   fRowMode = rowMode;                          << 
179                                                   161 
180   for (auto& mainNtupleManager : fMainNtupleMa << 162   if ( ! fNtupleVector.size() ) return;     
181     mainNtupleManager->SetRowWise(rowWise);    << 163   
                                                   >> 164   std::vector<G4RootNtupleDescription*>::iterator itn;  
                                                   >> 165   for (itn = fNtupleVector.begin(); itn != fNtupleVector.end(); itn++ ) {
                                                   >> 166 
                                                   >> 167     tools::ntuple_booking* ntupleBooking = (*itn)->fNtupleBooking;
                                                   >> 168     if ( ! ntupleBooking ) continue;
                                                   >> 169 
                                                   >> 170 #ifdef G4VERBOSE
                                                   >> 171     if ( fState.GetVerboseL4() ) 
                                                   >> 172       fState.GetVerboseL4()
                                                   >> 173         ->Message("create from booking", "ntuple", ntupleBooking->m_name);
                                                   >> 174 #endif
                                                   >> 175 
                                                   >> 176     (*itn)->fNtuple
                                                   >> 177       = new tools::wroot::ntuple(*fNtupleDirectory, *ntupleBooking);
                                                   >> 178   
                                                   >> 179     if ( ntupleBooking->m_columns.size() ) {
                                                   >> 180       // store ntuple columns in local maps
                                                   >> 181       const std::vector<tools::ntuple_booking::col_t>& columns 
                                                   >> 182         = ntupleBooking->m_columns;
                                                   >> 183       std::vector<tools::ntuple_booking::col_t>::const_iterator it;
                                                   >> 184       G4int index = 0;
                                                   >> 185       for ( it = columns.begin(); it!=columns.end(); ++it) {
                                                   >> 186         if ( (*it).second == tools::_cid(int(0) ) ) {
                                                   >> 187           (*itn)->fNtupleIColumnMap[index++] 
                                                   >> 188             = (*itn)->fNtuple->find_column<int>((*it).first);
                                                   >> 189         }
                                                   >> 190         else if ( (*it).second == tools::_cid(float(0) ) ) {
                                                   >> 191           (*itn)->fNtupleFColumnMap[index++] 
                                                   >> 192             = (*itn)->fNtuple->find_column<float>((*it).first);
                                                   >> 193         } 
                                                   >> 194         else if ( (*it).second== tools::_cid(double(0))) {
                                                   >> 195           (*itn)->fNtupleDColumnMap[index++] 
                                                   >> 196             = (*itn)->fNtuple->find_column<double>((*it).first);
                                                   >> 197         }
                                                   >> 198         else {
                                                   >> 199           G4ExceptionDescription description;
                                                   >> 200           description << "      " 
                                                   >> 201                       << "Unsupported column type " << (*it).first;
                                                   >> 202           G4Exception("G4RootNtupleManager::CreateNtupleFromBooking()",
                                                   >> 203                       "Analysis_W004", JustWarning, description);
                                                   >> 204         }
                                                   >> 205       }
                                                   >> 206     }
                                                   >> 207 #ifdef G4VERBOSE
                                                   >> 208     if ( fState.GetVerboseL3() ) 
                                                   >> 209       fState.GetVerboseL3()
                                                   >> 210         ->Message("create from booking", "ntuple", ntupleBooking->m_name);
                                                   >> 211 #endif
182   }                                               212   }
183 }                                              << 213 }   
184                                                   214 
185 //____________________________________________    215 //_____________________________________________________________________________
186 void G4RootNtupleManager::SetNewCycle(G4bool v << 216 G4bool G4RootNtupleManager::IsEmpty() const
187 {                                                 217 {
188   G4TNtupleManager<tools::wroot::ntuple, G4Roo << 218   return ! fNtupleVector.size();
189                                                << 219 }  
190   for ( const auto& manager : fMainNtupleManag << 220  
191     manager->SetNewCycle(value);               << 
192   }                                            << 
193 }                                              << 
194                                                << 
195 //____________________________________________    221 //_____________________________________________________________________________
196 std::shared_ptr<G4RootMainNtupleManager>       << 222 G4bool G4RootNtupleManager::Reset()
197 G4RootNtupleManager::GetMainNtupleManager(G4in << 
198 {                                                 223 {
199   if ( index < 0 || index >= G4int(fMainNtuple << 224 // Reset ntuples
200     Warn("main ntuple manager " + to_string(in << 
201       fkClass, "GetMainNtupleManager");        << 
202     return nullptr;                            << 
203   }                                            << 
204                                                << 
205   return fMainNtupleManagers[index];           << 
206 }                                              << 
207                                                   225 
208 //____________________________________________ << 226   std::vector<G4RootNtupleDescription*>::iterator it;  
209 unsigned int G4RootNtupleManager::GetBasketSiz << 227   for (it = fNtupleVector.begin(); it != fNtupleVector.end(); it++ ) {
210 {                                              << 228     // ntuple is deleted automatically when file is closed
211   if ( ! fFileManager ) {                      << 229     // delete (*it)->fNtuple;
212     Warn("File manager must be defined first." << 230     (*it)->fNtuple=0; 
213     return 0;                                  << 231   }  
                                                   >> 232   
                                                   >> 233   return true;
                                                   >> 234 }  
                                                   >> 235  
                                                   >> 236 //_____________________________________________________________________________
                                                   >> 237 tools::wroot::ntuple* G4RootNtupleManager::GetNtuple() const
                                                   >> 238 {
                                                   >> 239   return GetNtuple(fFirstId);
                                                   >> 240 }  
                                                   >> 241 
                                                   >> 242 //_____________________________________________________________________________
                                                   >> 243 tools::wroot::ntuple* G4RootNtupleManager::GetNtuple(G4int ntupleId) const
                                                   >> 244 {
                                                   >> 245   G4RootNtupleDescription* ntupleDescription
                                                   >> 246     = GetNtupleInFunction(ntupleId, "GetNtuple");
                                                   >> 247     
                                                   >> 248   return ntupleDescription->fNtuple;  
                                                   >> 249 }  
                                                   >> 250 
                                                   >> 251 //_____________________________________________________________________________
                                                   >> 252 G4int G4RootNtupleManager::CreateNtuple(const G4String& name, 
                                                   >> 253                                         const G4String& title)
                                                   >> 254 {
                                                   >> 255 #ifdef G4VERBOSE
                                                   >> 256   if ( fState.GetVerboseL4() ) 
                                                   >> 257     fState.GetVerboseL4()->Message("create", "ntuple", name);
                                                   >> 258 #endif
                                                   >> 259 
                                                   >> 260   // Create ntuple description
                                                   >> 261   G4int index = fNtupleVector.size();
                                                   >> 262   G4RootNtupleDescription* ntupleDescription
                                                   >> 263     = new G4RootNtupleDescription();
                                                   >> 264   fNtupleVector.push_back(ntupleDescription);  
                                                   >> 265 
                                                   >> 266   // Create ntuple booking
                                                   >> 267   ntupleDescription->fNtupleBooking = new tools::ntuple_booking();
                                                   >> 268   ntupleDescription->fNtupleBooking->m_name = name;
                                                   >> 269   ntupleDescription->fNtupleBooking->m_title = title;
                                                   >> 270            // ntuple booking object is deleted in destructor
                                                   >> 271 
                                                   >> 272   // Create ntuple if the file is open
                                                   >> 273   if ( fNtupleDirectory ) {
                                                   >> 274     ntupleDescription->fNtuple 
                                                   >> 275       = new tools::wroot::ntuple(*fNtupleDirectory, name, title);
                                                   >> 276            // ntuple object is deleted automatically when closing a file
214   }                                               277   }
215                                                   278 
216   return fFileManager->GetBasketSize();        << 279   fLockFirstId = true;
217 }                                              << 
218                                                   280 
219 //____________________________________________ << 281 #ifdef G4VERBOSE
220 unsigned int G4RootNtupleManager::GetBasketEnt << 282   if ( fState.GetVerboseL2() ) {
221 {                                              << 283     G4ExceptionDescription description;
222   if ( ! fFileManager ) {                      << 284     description << name << " ntupleId " << index + fFirstId;
223     Warn("File manager must be defined first." << 285     fState.GetVerboseL2()->Message("create", "ntuple", description);
224     return 0;                                  << 286   } 
225   }                                            << 287 #endif
                                                   >> 288 
                                                   >> 289   return index + fFirstId;
                                                   >> 290 }                                         
                                                   >> 291 
                                                   >> 292 //_____________________________________________________________________________
                                                   >> 293 G4int G4RootNtupleManager::CreateNtupleIColumn(const G4String& name)
                                                   >> 294 {
                                                   >> 295   G4int ntupleId = fNtupleVector.size() + fFirstId - 1;
                                                   >> 296   return CreateNtupleIColumn(ntupleId, name);
                                                   >> 297 }  
                                                   >> 298 
                                                   >> 299 //_____________________________________________________________________________
                                                   >> 300 G4int G4RootNtupleManager::CreateNtupleFColumn(const G4String& name)
                                                   >> 301 {
                                                   >> 302   G4int ntupleId = fNtupleVector.size() + fFirstId - 1;
                                                   >> 303   return CreateNtupleFColumn(ntupleId, name);
                                                   >> 304 }  
                                                   >> 305 
                                                   >> 306 //_____________________________________________________________________________
                                                   >> 307 G4int G4RootNtupleManager::CreateNtupleDColumn(const G4String& name)
                                                   >> 308 {
                                                   >> 309   G4int ntupleId = fNtupleVector.size() + fFirstId - 1;
                                                   >> 310   return CreateNtupleDColumn(ntupleId, name);
                                                   >> 311 }  
                                                   >> 312 
                                                   >> 313 //_____________________________________________________________________________
                                                   >> 314 void G4RootNtupleManager::FinishNtuple()
                                                   >> 315 { 
                                                   >> 316   // nothing to be done here
                                                   >> 317 }
                                                   >> 318    
                                                   >> 319 //_____________________________________________________________________________
                                                   >> 320 G4int G4RootNtupleManager::CreateNtupleIColumn(G4int ntupleId, 
                                                   >> 321                                                  const G4String& name)
                                                   >> 322 {
                                                   >> 323 #ifdef G4VERBOSE
                                                   >> 324   if ( fState.GetVerboseL4() ) {
                                                   >> 325     G4ExceptionDescription description;
                                                   >> 326     description << name << " ntupleId " << ntupleId; 
                                                   >> 327     fState.GetVerboseL4()->Message("create", "ntuple I column", description);
                                                   >> 328   }  
                                                   >> 329 #endif
                                                   >> 330   
                                                   >> 331   G4RootNtupleDescription* ntupleDescription
                                                   >> 332     = GetNtupleInFunction(ntupleId, "CreateNtupleIColumn");
                                                   >> 333   if ( ! ntupleDescription )  return -1;   
                                                   >> 334     
                                                   >> 335   tools::ntuple_booking* ntupleBooking
                                                   >> 336     = ntupleDescription->fNtupleBooking;
                                                   >> 337   if ( ! ntupleBooking ) {
                                                   >> 338     G4ExceptionDescription description;
                                                   >> 339     description << "      " 
                                                   >> 340                 << "Ntuple " << ntupleId << " has to be created first. ";
                                                   >> 341     G4Exception("G4RootNtupleManager::CreateNtupleIColumn()",
                                                   >> 342                 "Analysis_W005", JustWarning, description);
                                                   >> 343     return -1;       
                                                   >> 344   }
                                                   >> 345 
                                                   >> 346   // Save column info in booking
                                                   >> 347   G4int index = ntupleBooking->m_columns.size();
                                                   >> 348   ntupleBooking->add_column<int>(name);  
                                                   >> 349  
                                                   >> 350   // Create column if ntuple already exists
                                                   >> 351   if ( ntupleDescription->fNtuple ) {
                                                   >> 352     tools::wroot::ntuple::column<int>* column 
                                                   >> 353       = ntupleDescription->fNtuple->create_column<int>(name);  
                                                   >> 354     ntupleDescription->fNtupleIColumnMap[index] = column;
                                                   >> 355   }  
                                                   >> 356 
                                                   >> 357   fLockFirstNtupleColumnId = true;
                                                   >> 358 
                                                   >> 359 #ifdef G4VERBOSE
                                                   >> 360   if ( fState.GetVerboseL2() ) {
                                                   >> 361     G4ExceptionDescription description;
                                                   >> 362     description << name << " ntupleId " << ntupleId; 
                                                   >> 363     fState.GetVerboseL2()->Message("create", "ntuple I column", description);
                                                   >> 364   }  
                                                   >> 365 #endif
                                                   >> 366 
                                                   >> 367   return index + fFirstNtupleColumnId;       
                                                   >> 368 }                                         
                                                   >> 369 
                                                   >> 370 //_____________________________________________________________________________
                                                   >> 371 G4int G4RootNtupleManager::CreateNtupleFColumn(G4int ntupleId, const G4String& name)
                                                   >> 372 {
                                                   >> 373 #ifdef G4VERBOSE
                                                   >> 374   if ( fState.GetVerboseL4() ) {
                                                   >> 375     G4ExceptionDescription description;
                                                   >> 376     description << name << " ntupleId " << ntupleId; 
                                                   >> 377     fState.GetVerboseL4()->Message("create", "ntuple F column", description);
                                                   >> 378   } 
                                                   >> 379 #endif
                                                   >> 380 
                                                   >> 381   G4RootNtupleDescription* ntupleDescription
                                                   >> 382     = GetNtupleInFunction(ntupleId, "CreateNtupleFColumn");
                                                   >> 383   if ( ! ntupleDescription )  return -1;   
                                                   >> 384 
                                                   >> 385   tools::ntuple_booking* ntupleBooking
                                                   >> 386     = ntupleDescription->fNtupleBooking;  
                                                   >> 387 
                                                   >> 388   if ( ! ntupleBooking ) {
                                                   >> 389     G4ExceptionDescription description;
                                                   >> 390     description << "      " 
                                                   >> 391                 << "Ntuple " << ntupleId << " has to be created first. ";
                                                   >> 392     G4Exception("G4RootNtupleManager::CreateNtupleFColumn()",
                                                   >> 393                 "Analysis_W005", JustWarning, description);
                                                   >> 394     return -1;       
                                                   >> 395   }
                                                   >> 396 
                                                   >> 397   // Save column info in booking
                                                   >> 398   G4int index = ntupleBooking->m_columns.size();
                                                   >> 399   ntupleBooking->add_column<float>(name);  
                                                   >> 400  
                                                   >> 401   // Create column if ntuple already exists
                                                   >> 402   if ( ntupleDescription->fNtuple ) {
                                                   >> 403     tools::wroot::ntuple::column<float>* column 
                                                   >> 404       = ntupleDescription->fNtuple->create_column<float>(name);  
                                                   >> 405     ntupleDescription->fNtupleFColumnMap[index] = column;
                                                   >> 406   }  
                                                   >> 407 
                                                   >> 408   fLockFirstNtupleColumnId = true;
                                                   >> 409 
                                                   >> 410 #ifdef G4VERBOSE
                                                   >> 411   if ( fState.GetVerboseL2() ) {
                                                   >> 412     G4ExceptionDescription description;
                                                   >> 413     description << name << " ntupleId " << ntupleId; 
                                                   >> 414     fState.GetVerboseL2()->Message("create", "ntuple F column", description);
                                                   >> 415   }  
                                                   >> 416 #endif
                                                   >> 417 
                                                   >> 418   return index + fFirstNtupleColumnId;       
                                                   >> 419 }                                         
                                                   >> 420 
                                                   >> 421 
                                                   >> 422 //_____________________________________________________________________________
                                                   >> 423 G4int G4RootNtupleManager::CreateNtupleDColumn(G4int ntupleId, const G4String& name)   
                                                   >> 424 {
                                                   >> 425 #ifdef G4VERBOSE
                                                   >> 426   if ( fState.GetVerboseL4() ) {
                                                   >> 427     G4ExceptionDescription description;
                                                   >> 428     description << name << " ntupleId " << ntupleId; 
                                                   >> 429     fState.GetVerboseL4()->Message("create", "ntuple D column", description);
                                                   >> 430   }  
                                                   >> 431 #endif
                                                   >> 432 
                                                   >> 433   G4RootNtupleDescription* ntupleDescription
                                                   >> 434     = GetNtupleInFunction(ntupleId, "CreateNtupleDColumn");
                                                   >> 435   if ( ! ntupleDescription )  return -1;   
                                                   >> 436 
                                                   >> 437   tools::ntuple_booking* ntupleBooking
                                                   >> 438     = ntupleDescription->fNtupleBooking;  
                                                   >> 439 
                                                   >> 440   if ( ! ntupleBooking ) {
                                                   >> 441     G4ExceptionDescription description;
                                                   >> 442     description << "      " 
                                                   >> 443                 << "Ntuple " << ntupleId << " has to be created first. ";
                                                   >> 444     G4Exception("G4RootNtupleManager::CreateNtupleDColumn()",
                                                   >> 445                 "Analysis_W005", JustWarning, description);
                                                   >> 446     return -1;       
                                                   >> 447   }
                                                   >> 448 
                                                   >> 449   // Save column info in booking
                                                   >> 450   G4int index = ntupleBooking->m_columns.size();
                                                   >> 451   ntupleBooking->add_column<double>(name);  
                                                   >> 452  
                                                   >> 453   // Create column if ntuple already exists
                                                   >> 454   if ( ntupleDescription->fNtuple ) {
                                                   >> 455     tools::wroot::ntuple::column<double>* column 
                                                   >> 456       = ntupleDescription->fNtuple->create_column<double>(name);  
                                                   >> 457     ntupleDescription->fNtupleDColumnMap[index] = column;
                                                   >> 458   }  
                                                   >> 459   
                                                   >> 460   fLockFirstNtupleColumnId = true;
                                                   >> 461 
                                                   >> 462 #ifdef G4VERBOSE
                                                   >> 463   if ( fState.GetVerboseL2() ) {
                                                   >> 464     G4ExceptionDescription description;
                                                   >> 465     description << name << " ntupleId " << ntupleId; 
                                                   >> 466     fState.GetVerboseL2()->Message("create", "ntuple D column", description);
                                                   >> 467   }  
                                                   >> 468 #endif
                                                   >> 469 
                                                   >> 470   return index + fFirstNtupleColumnId;       
                                                   >> 471 }                                         
                                                   >> 472 
                                                   >> 473 //_____________________________________________________________________________
                                                   >> 474 void G4RootNtupleManager::FinishNtuple(G4int /*ntupleId*/)
                                                   >> 475 { 
                                                   >> 476   // nothing to be done here
                                                   >> 477 }
                                                   >> 478    
                                                   >> 479 //_____________________________________________________________________________
                                                   >> 480 G4bool G4RootNtupleManager::FillNtupleIColumn(G4int columnId, G4int value)
                                                   >> 481 {
                                                   >> 482   return FillNtupleIColumn(fFirstId, columnId, value);
                                                   >> 483 }                                         
                                                   >> 484 
                                                   >> 485 //_____________________________________________________________________________
                                                   >> 486 G4bool G4RootNtupleManager::FillNtupleFColumn(G4int columnId, G4float value)
                                                   >> 487 {
                                                   >> 488   return FillNtupleFColumn(fFirstId, columnId, value);
                                                   >> 489 }                                         
                                                   >> 490 
                                                   >> 491 //_____________________________________________________________________________
                                                   >> 492 G4bool G4RootNtupleManager::FillNtupleDColumn(G4int columnId, G4double value)
                                                   >> 493 {
                                                   >> 494   return FillNtupleDColumn(fFirstId, columnId, value);
                                                   >> 495 }                                         
                                                   >> 496 
                                                   >> 497 //_____________________________________________________________________________
                                                   >> 498 G4bool G4RootNtupleManager::AddNtupleRow()
                                                   >> 499 { 
                                                   >> 500   return AddNtupleRow(fFirstId);
                                                   >> 501 }  
                                                   >> 502 
                                                   >> 503 //_____________________________________________________________________________
                                                   >> 504 G4bool G4RootNtupleManager::FillNtupleIColumn(G4int ntupleId, G4int columnId, 
                                                   >> 505                                                 G4int value)
                                                   >> 506 {
                                                   >> 507   tools::wroot::ntuple::column<int>* column 
                                                   >> 508     = GetNtupleIColumn(ntupleId, columnId);
                                                   >> 509   if ( ! column ) {
                                                   >> 510     G4ExceptionDescription description;
                                                   >> 511     description << "      " << "ntupleId " <<  ntupleId
                                                   >> 512                 << " columnId " << columnId << " does not exist.";
                                                   >> 513     G4Exception("G4RootNtupleManager::FillNtupleIColumn()",
                                                   >> 514                 "Analysis_W009", JustWarning, description);
                                                   >> 515     return false;
                                                   >> 516   }  
                                                   >> 517   
                                                   >> 518   column->fill(value);
                                                   >> 519 #ifdef G4VERBOSE
                                                   >> 520   if ( fState.GetVerboseL4() ) {
                                                   >> 521     G4ExceptionDescription description;
                                                   >> 522     description << " ntupleId " << ntupleId  
                                                   >> 523                 << " columnId " << columnId << " value " << value;
                                                   >> 524     fState.GetVerboseL4()->Message("fill", "ntuple I column", description);
                                                   >> 525   }  
                                                   >> 526 #endif
                                                   >> 527   return true;       
                                                   >> 528 }                                         
                                                   >> 529 //_____________________________________________________________________________
                                                   >> 530 G4bool G4RootNtupleManager::FillNtupleFColumn(G4int ntupleId, G4int columnId, 
                                                   >> 531                                                 G4float value)
                                                   >> 532 {
                                                   >> 533   tools::wroot::ntuple::column<float>* column 
                                                   >> 534     = GetNtupleFColumn(ntupleId, columnId);
                                                   >> 535   if ( ! column ) {
                                                   >> 536     G4ExceptionDescription description;
                                                   >> 537     description << "      " << "ntupleId " <<  ntupleId
                                                   >> 538                 << " columnId " << columnId << " does not exist.";
                                                   >> 539     G4Exception("G4RootNtupleManager::FillNtupleFColumn()",
                                                   >> 540                 "Analysis_W009", JustWarning, description);
                                                   >> 541     return false;
                                                   >> 542   }  
                                                   >> 543   
                                                   >> 544   column->fill(value);
                                                   >> 545 #ifdef G4VERBOSE
                                                   >> 546   if ( fState.GetVerboseL4() ) {
                                                   >> 547     G4ExceptionDescription description;
                                                   >> 548     description << " ntupleId " << ntupleId  
                                                   >> 549                 << " columnId " << columnId << " value " << value;
                                                   >> 550     fState.GetVerboseL4()->Message("fill", "ntuple F column", description);
                                                   >> 551   }  
                                                   >> 552 #endif
                                                   >> 553   return true;       
                                                   >> 554 }                                         
                                                   >> 555 //_____________________________________________________________________________
                                                   >> 556 G4bool G4RootNtupleManager::FillNtupleDColumn(G4int ntupleId, G4int columnId, 
                                                   >> 557                                                 G4double value)
                                                   >> 558 {
                                                   >> 559   tools::wroot::ntuple::column<double>* column 
                                                   >> 560     = GetNtupleDColumn(ntupleId, columnId);
                                                   >> 561   if ( ! column ) {
                                                   >> 562     G4ExceptionDescription description;
                                                   >> 563     description << "      " << "ntupleId " <<  ntupleId
                                                   >> 564                 << " columnId " << columnId << " does not exist.";
                                                   >> 565     G4Exception("G4RootNtupleManager::FillNtupleDColumn()",
                                                   >> 566                 "Analysis_W009", JustWarning, description);
                                                   >> 567     return false;
                                                   >> 568   }  
                                                   >> 569   
                                                   >> 570   column->fill(value);
                                                   >> 571 #ifdef G4VERBOSE
                                                   >> 572   if ( fState.GetVerboseL4() ) {
                                                   >> 573     G4ExceptionDescription description;
                                                   >> 574     description << " ntupleId " << ntupleId  
                                                   >> 575                 << " columnId " << columnId << " value " << value;
                                                   >> 576     fState.GetVerboseL4()->Message("fill", "ntuple D column", description);
                                                   >> 577   }  
                                                   >> 578 #endif
                                                   >> 579   return true;       
                                                   >> 580 }                                         
                                                   >> 581 
                                                   >> 582 //_____________________________________________________________________________
                                                   >> 583 G4bool G4RootNtupleManager::AddNtupleRow(G4int ntupleId)
                                                   >> 584 { 
                                                   >> 585 #ifdef G4VERBOSE
                                                   >> 586   if ( fState.GetVerboseL4() ) {
                                                   >> 587     G4ExceptionDescription description;
                                                   >> 588     description << " ntupleId " << ntupleId;  
                                                   >> 589     fState.GetVerboseL4()->Message("add", "ntuple row", description);
                                                   >> 590   }  
                                                   >> 591 #endif
                                                   >> 592 
                                                   >> 593   G4RootNtupleDescription* ntupleDescription
                                                   >> 594     = GetNtupleInFunction(ntupleId, "AddNtupleRow");
                                                   >> 595   if ( ! ntupleDescription ) return false;
                                                   >> 596 
                                                   >> 597   if ( ! ntupleDescription->fNtuple ) {
                                                   >> 598     G4ExceptionDescription description;
                                                   >> 599     description << "      " << " ntupleId " << ntupleId 
                                                   >> 600                 << " does not exist. ";
                                                   >> 601     G4Exception("G4RootNtupleManager::AddNtupleRow()",
                                                   >> 602                 "Analysis_W008", JustWarning, description);
                                                   >> 603     return false;
                                                   >> 604   }  
                                                   >> 605   
                                                   >> 606   G4bool result = ntupleDescription->fNtuple->add_row();
                                                   >> 607   if ( ! result ) {
                                                   >> 608     G4ExceptionDescription description;
                                                   >> 609     description << "      " << " ntupleId " << ntupleId 
                                                   >> 610                 << "adding row has failed.";
                                                   >> 611     G4Exception("G4RootNtupleManager::AddNtupleRow()",
                                                   >> 612                 "Analysis_W004", JustWarning, description);
                                                   >> 613   }         
                                                   >> 614 #ifdef G4VERBOSE
                                                   >> 615   if ( fState.GetVerboseL4() ) {
                                                   >> 616     G4ExceptionDescription description;
                                                   >> 617     description << " ntupleId " << ntupleId;  
                                                   >> 618     fState.GetVerboseL4()->Message("add", "ntuple row", description, result);
                                                   >> 619   }  
                                                   >> 620 #endif
226                                                   621 
227   return fFileManager->GetBasketEntries();     << 622   return result;
228 }                                                 623 }
229                                                   624