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.p1)


  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                 << "column " << 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                 << "column " << 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                 << "column " << 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   tools::ntuple_booking* ntupleBooking
                                                   >> 334     = ntupleDescription->fNtupleBooking;  
                                                   >> 335 
                                                   >> 336   if ( ! ntupleBooking ) {
                                                   >> 337     G4ExceptionDescription description;
                                                   >> 338     description << "      " 
                                                   >> 339                 << "Ntuple " << ntupleId << " has to be created first. ";
                                                   >> 340     G4Exception("G4RootNtupleManager::CreateNtupleIColumn()",
                                                   >> 341                 "Analysis_W005", JustWarning, description);
                                                   >> 342     return -1;       
                                                   >> 343   }
                                                   >> 344 
                                                   >> 345   // Save column info in booking
                                                   >> 346   G4int index = ntupleBooking->m_columns.size();
                                                   >> 347   ntupleBooking->add_column<int>(name);  
                                                   >> 348  
                                                   >> 349   // Create column if ntuple already exists
                                                   >> 350   if ( ntupleDescription->fNtuple ) {
                                                   >> 351     tools::wroot::ntuple::column<int>* column 
                                                   >> 352       = ntupleDescription->fNtuple->create_column<int>(name);  
                                                   >> 353     ntupleDescription->fNtupleIColumnMap[index] = column;
                                                   >> 354   }  
                                                   >> 355 
                                                   >> 356   fLockFirstNtupleColumnId = true;
                                                   >> 357 
                                                   >> 358 #ifdef G4VERBOSE
                                                   >> 359   if ( fState.GetVerboseL2() ) {
                                                   >> 360     G4ExceptionDescription description;
                                                   >> 361     description << name << " ntupleId " << ntupleId; 
                                                   >> 362     fState.GetVerboseL2()->Message("create", "ntuple I column", description);
                                                   >> 363   }  
                                                   >> 364 #endif
                                                   >> 365 
                                                   >> 366   return index + fFirstNtupleColumnId;       
                                                   >> 367 }                                         
                                                   >> 368 
                                                   >> 369 //_____________________________________________________________________________
                                                   >> 370 G4int G4RootNtupleManager::CreateNtupleFColumn(G4int ntupleId, const G4String& name)
                                                   >> 371 {
                                                   >> 372 #ifdef G4VERBOSE
                                                   >> 373   if ( fState.GetVerboseL4() ) {
                                                   >> 374     G4ExceptionDescription description;
                                                   >> 375     description << name << " ntupleId " << ntupleId; 
                                                   >> 376     fState.GetVerboseL4()->Message("create", "ntuple F column", description);
                                                   >> 377   } 
                                                   >> 378 #endif
                                                   >> 379 
                                                   >> 380   G4RootNtupleDescription* ntupleDescription
                                                   >> 381     = GetNtupleInFunction(ntupleId, "CreateNtupleFColumn");
                                                   >> 382   tools::ntuple_booking* ntupleBooking
                                                   >> 383     = ntupleDescription->fNtupleBooking;  
                                                   >> 384 
                                                   >> 385   if ( ! ntupleBooking ) {
                                                   >> 386     G4ExceptionDescription description;
                                                   >> 387     description << "      " 
                                                   >> 388                 << "Ntuple " << ntupleId << " has to be created first. ";
                                                   >> 389     G4Exception("G4RootNtupleManager::CreateNtupleFColumn()",
                                                   >> 390                 "Analysis_W005", JustWarning, description);
                                                   >> 391     return -1;       
                                                   >> 392   }
                                                   >> 393 
                                                   >> 394   // Save column info in booking
                                                   >> 395   G4int index = ntupleBooking->m_columns.size();
                                                   >> 396   ntupleBooking->add_column<float>(name);  
                                                   >> 397  
                                                   >> 398   // Create column if ntuple already exists
                                                   >> 399   if ( ntupleDescription->fNtuple ) {
                                                   >> 400     tools::wroot::ntuple::column<float>* column 
                                                   >> 401       = ntupleDescription->fNtuple->create_column<float>(name);  
                                                   >> 402     ntupleDescription->fNtupleFColumnMap[index] = column;
                                                   >> 403   }  
                                                   >> 404 
                                                   >> 405   fLockFirstNtupleColumnId = true;
                                                   >> 406 
                                                   >> 407 #ifdef G4VERBOSE
                                                   >> 408   if ( fState.GetVerboseL2() ) {
                                                   >> 409     G4ExceptionDescription description;
                                                   >> 410     description << name << " ntupleId " << ntupleId; 
                                                   >> 411     fState.GetVerboseL2()->Message("create", "ntuple F column", description);
                                                   >> 412   }  
                                                   >> 413 #endif
                                                   >> 414 
                                                   >> 415   return index + fFirstNtupleColumnId;       
                                                   >> 416 }                                         
                                                   >> 417 
                                                   >> 418 
                                                   >> 419 //_____________________________________________________________________________
                                                   >> 420 G4int G4RootNtupleManager::CreateNtupleDColumn(G4int ntupleId, const G4String& name)   
                                                   >> 421 {
                                                   >> 422 #ifdef G4VERBOSE
                                                   >> 423   if ( fState.GetVerboseL4() ) {
                                                   >> 424     G4ExceptionDescription description;
                                                   >> 425     description << name << " ntupleId " << ntupleId; 
                                                   >> 426     fState.GetVerboseL4()->Message("create", "ntuple D column", description);
                                                   >> 427   }  
                                                   >> 428 #endif
                                                   >> 429 
                                                   >> 430   G4RootNtupleDescription* ntupleDescription
                                                   >> 431     = GetNtupleInFunction(ntupleId, "CreateNtupleDColumn");
                                                   >> 432   tools::ntuple_booking* ntupleBooking
                                                   >> 433     = ntupleDescription->fNtupleBooking;  
                                                   >> 434 
                                                   >> 435   if ( ! ntupleBooking ) {
                                                   >> 436     G4ExceptionDescription description;
                                                   >> 437     description << "      " 
                                                   >> 438                 << "Ntuple " << ntupleId << " has to be created first. ";
                                                   >> 439     G4Exception("G4RootNtupleManager::CreateNtupleDColumn()",
                                                   >> 440                 "Analysis_W005", JustWarning, description);
                                                   >> 441     return -1;       
                                                   >> 442   }
                                                   >> 443 
                                                   >> 444   // Save column info in booking
                                                   >> 445   G4int index = ntupleBooking->m_columns.size();
                                                   >> 446   ntupleBooking->add_column<double>(name);  
                                                   >> 447  
                                                   >> 448   // Create column if ntuple already exists
                                                   >> 449   if ( ntupleDescription->fNtuple ) {
                                                   >> 450     tools::wroot::ntuple::column<double>* column 
                                                   >> 451       = ntupleDescription->fNtuple->create_column<double>(name);  
                                                   >> 452     ntupleDescription->fNtupleDColumnMap[index] = column;
                                                   >> 453   }  
                                                   >> 454   
                                                   >> 455   fLockFirstNtupleColumnId = true;
                                                   >> 456 
                                                   >> 457 #ifdef G4VERBOSE
                                                   >> 458   if ( fState.GetVerboseL2() ) {
                                                   >> 459     G4ExceptionDescription description;
                                                   >> 460     description << name << " ntupleId " << ntupleId; 
                                                   >> 461     fState.GetVerboseL2()->Message("create", "ntuple D column", description);
                                                   >> 462   }  
                                                   >> 463 #endif
                                                   >> 464 
                                                   >> 465   return index + fFirstNtupleColumnId;       
                                                   >> 466 }                                         
                                                   >> 467 
                                                   >> 468 //_____________________________________________________________________________
                                                   >> 469 void G4RootNtupleManager::FinishNtuple(G4int /*ntupleId*/)
                                                   >> 470 { 
                                                   >> 471   // nothing to be done here
                                                   >> 472 }
                                                   >> 473    
                                                   >> 474 //_____________________________________________________________________________
                                                   >> 475 G4bool G4RootNtupleManager::FillNtupleIColumn(G4int columnId, G4int value)
                                                   >> 476 {
                                                   >> 477   return FillNtupleIColumn(fFirstId, columnId, value);
                                                   >> 478 }                                         
                                                   >> 479 
                                                   >> 480 //_____________________________________________________________________________
                                                   >> 481 G4bool G4RootNtupleManager::FillNtupleFColumn(G4int columnId, G4float value)
                                                   >> 482 {
                                                   >> 483   return FillNtupleFColumn(fFirstId, columnId, value);
                                                   >> 484 }                                         
                                                   >> 485 
                                                   >> 486 //_____________________________________________________________________________
                                                   >> 487 G4bool G4RootNtupleManager::FillNtupleDColumn(G4int columnId, G4double value)
                                                   >> 488 {
                                                   >> 489   return FillNtupleDColumn(fFirstId, columnId, value);
                                                   >> 490 }                                         
                                                   >> 491 
                                                   >> 492 //_____________________________________________________________________________
                                                   >> 493 G4bool G4RootNtupleManager::AddNtupleRow()
                                                   >> 494 { 
                                                   >> 495   return AddNtupleRow(fFirstId);
                                                   >> 496 }  
                                                   >> 497 
                                                   >> 498 //_____________________________________________________________________________
                                                   >> 499 G4bool G4RootNtupleManager::FillNtupleIColumn(G4int ntupleId, G4int columnId, 
                                                   >> 500                                                 G4int value)
                                                   >> 501 {
                                                   >> 502   tools::wroot::ntuple::column<int>* column 
                                                   >> 503     = GetNtupleIColumn(ntupleId, columnId);
                                                   >> 504   if ( ! column ) {
                                                   >> 505     G4ExceptionDescription description;
                                                   >> 506     description << "      " << "ntupleId " <<  ntupleId
                                                   >> 507                 << "column " << columnId << " does not exist.";
                                                   >> 508     G4Exception("G4RootNtupleManager::FillNtupleIColumn()",
                                                   >> 509                 "Analysis_W009", JustWarning, description);
                                                   >> 510     return false;
                                                   >> 511   }  
                                                   >> 512   
                                                   >> 513   column->fill(value);
                                                   >> 514 #ifdef G4VERBOSE
                                                   >> 515   if ( fState.GetVerboseL4() ) {
                                                   >> 516     G4ExceptionDescription description;
                                                   >> 517     description << " ntupleId " << ntupleId  
                                                   >> 518                 << " columnId " << columnId << " value " << value;
                                                   >> 519     fState.GetVerboseL4()->Message("fill", "ntuple I column", description);
                                                   >> 520   }  
                                                   >> 521 #endif
                                                   >> 522   return true;       
                                                   >> 523 }                                         
                                                   >> 524 //_____________________________________________________________________________
                                                   >> 525 G4bool G4RootNtupleManager::FillNtupleFColumn(G4int ntupleId, G4int columnId, 
                                                   >> 526                                                 G4float value)
                                                   >> 527 {
                                                   >> 528   tools::wroot::ntuple::column<float>* column 
                                                   >> 529     = GetNtupleFColumn(ntupleId, columnId);
                                                   >> 530   if ( ! column ) {
                                                   >> 531     G4ExceptionDescription description;
                                                   >> 532     description << "      " << "ntupleId " <<  ntupleId
                                                   >> 533                 << "column " << columnId << " does not exist.";
                                                   >> 534     G4Exception("G4RootNtupleManager::FillNtupleFColumn()",
                                                   >> 535                 "Analysis_W009", JustWarning, description);
                                                   >> 536     return false;
                                                   >> 537   }  
                                                   >> 538   
                                                   >> 539   column->fill(value);
                                                   >> 540 #ifdef G4VERBOSE
                                                   >> 541   if ( fState.GetVerboseL4() ) {
                                                   >> 542     G4ExceptionDescription description;
                                                   >> 543     description << " ntupleId " << ntupleId  
                                                   >> 544                 << " columnId " << columnId << " value " << value;
                                                   >> 545     fState.GetVerboseL4()->Message("fill", "ntuple F column", description);
                                                   >> 546   }  
                                                   >> 547 #endif
                                                   >> 548   return true;       
                                                   >> 549 }                                         
                                                   >> 550 //_____________________________________________________________________________
                                                   >> 551 G4bool G4RootNtupleManager::FillNtupleDColumn(G4int ntupleId, G4int columnId, 
                                                   >> 552                                                 G4double value)
                                                   >> 553 {
                                                   >> 554   tools::wroot::ntuple::column<double>* column 
                                                   >> 555     = GetNtupleDColumn(ntupleId, columnId);
                                                   >> 556   if ( ! column ) {
                                                   >> 557     G4ExceptionDescription description;
                                                   >> 558     description << "      " << "ntupleId " <<  ntupleId
                                                   >> 559                 << "column " << columnId << " does not exist.";
                                                   >> 560     G4Exception("G4RootNtupleManager::FillNtupleDColumn()",
                                                   >> 561                 "Analysis_W009", JustWarning, description);
                                                   >> 562     return false;
                                                   >> 563   }  
                                                   >> 564   
                                                   >> 565   column->fill(value);
                                                   >> 566 #ifdef G4VERBOSE
                                                   >> 567   if ( fState.GetVerboseL4() ) {
                                                   >> 568     G4ExceptionDescription description;
                                                   >> 569     description << " ntupleId " << ntupleId  
                                                   >> 570                 << " columnId " << columnId << " value " << value;
                                                   >> 571     fState.GetVerboseL4()->Message("fill", "ntuple D column", description);
                                                   >> 572   }  
                                                   >> 573 #endif
                                                   >> 574   return true;       
                                                   >> 575 }                                         
                                                   >> 576 
                                                   >> 577 //_____________________________________________________________________________
                                                   >> 578 G4bool G4RootNtupleManager::AddNtupleRow(G4int ntupleId)
                                                   >> 579 { 
                                                   >> 580 #ifdef G4VERBOSE
                                                   >> 581   if ( fState.GetVerboseL4() ) {
                                                   >> 582     G4ExceptionDescription description;
                                                   >> 583     description << " ntupleId " << ntupleId;  
                                                   >> 584     fState.GetVerboseL4()->Message("add", "ntuple row", description);
                                                   >> 585   }  
                                                   >> 586 #endif
                                                   >> 587 
                                                   >> 588   G4RootNtupleDescription* ntupleDescription
                                                   >> 589     = GetNtupleInFunction(ntupleId, "AddNtupleRow");
                                                   >> 590 
                                                   >> 591   if ( ! ntupleDescription || ! ntupleDescription->fNtuple ) {
                                                   >> 592     G4ExceptionDescription description;
                                                   >> 593     description << "      " << " ntupleId " << ntupleId 
                                                   >> 594                 << " does not exist. ";
                                                   >> 595     G4Exception("G4RootNtupleManager::AddNtupleRow()",
                                                   >> 596                 "Analysis_W008", JustWarning, description);
                                                   >> 597     return false;
                                                   >> 598   }  
                                                   >> 599   
                                                   >> 600   G4bool result = ntupleDescription->fNtuple->add_row();
                                                   >> 601   if ( ! result ) {
                                                   >> 602     G4ExceptionDescription description;
                                                   >> 603     description << "      " << " ntupleId " << ntupleId 
                                                   >> 604                 << "adding row has failed.";
                                                   >> 605     G4Exception("G4RootNtupleManager::AddNtupleRow()",
                                                   >> 606                 "Analysis_W004", JustWarning, description);
                                                   >> 607   }         
                                                   >> 608 #ifdef G4VERBOSE
                                                   >> 609   if ( fState.GetVerboseL4() ) {
                                                   >> 610     G4ExceptionDescription description;
                                                   >> 611     description << " ntupleId " << ntupleId;  
                                                   >> 612     fState.GetVerboseL4()->Message("add", "ntuple row", description, result);
                                                   >> 613   }  
                                                   >> 614 #endif
226                                                   615 
227   return fFileManager->GetBasketEntries();     << 616   return result;
228 }                                                 617 }
229                                                   618