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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/xml/src/G4XmlRNtupleManager.cc (Version 11.3.0) and /analysis/xml/src/G4XmlRNtupleManager.cc (Version 10.6.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                                                    26 
 27 // Author: Ivana Hrivnacova, 25/07/2014 (ivana     27 // Author: Ivana Hrivnacova, 25/07/2014 (ivana@ipno.in2p3.fr)
 28                                                    28 
 29 #include "G4XmlRNtupleManager.hh"                  29 #include "G4XmlRNtupleManager.hh"
 30 #include "G4XmlRFileManager.hh"                << 
 31 #include "G4AnalysisManagerState.hh"               30 #include "G4AnalysisManagerState.hh"
 32 #include "G4AnalysisUtilities.hh"              << 
 33                                                    31 
 34 using namespace G4Analysis;                    <<  32 // 
 35 using std::to_string;                          << 
 36                                                << 
 37 //                                             << 
 38 // utility function (to be provided in tools)      33 // utility function (to be provided in tools)
 39 //                                                 34 //
 40                                                    35 
 41 namespace tools {                                  36 namespace tools {
 42 namespace aida {                                   37 namespace aida {
 43 template <class T>                                 38 template <class T>
 44 bool to_vector(base_ntu& a_ntu,std::vector<T>&     39 bool to_vector(base_ntu& a_ntu,std::vector<T>& a_vec) {
 45   a_vec.clear();                                   40   a_vec.clear();
 46   const std::vector<base_col*>& cols = a_ntu.c     41   const std::vector<base_col*>& cols = a_ntu.cols();
 47   if(cols.empty()) return false;                   42   if(cols.empty()) return false;
 48   base_col* _base_col = cols.front();              43   base_col* _base_col = cols.front();
 49   aida_col<T>* _col = safe_cast<base_col, aida     44   aida_col<T>* _col = safe_cast<base_col, aida_col<T> >(*_base_col);
 50   if(!_col) return false;                          45   if(!_col) return false;
 51   a_ntu.start();                                   46   a_ntu.start();
 52   uint64 _rows = a_ntu.rows();                     47   uint64 _rows = a_ntu.rows();
 53   a_vec.resize(_rows);                             48   a_vec.resize(_rows);
 54   T v;                                             49   T v;
 55  {for(uint64 row=0;row<_rows;row++) {              50  {for(uint64 row=0;row<_rows;row++) {
 56     if(!a_ntu.next()) {a_vec.clear();return fa     51     if(!a_ntu.next()) {a_vec.clear();return false;}
 57     if(!_col->get_entry(v)) {a_vec.clear();ret     52     if(!_col->get_entry(v)) {a_vec.clear();return false;}
 58     a_vec[row] = v;                                53     a_vec[row] = v;
 59   }}                                               54   }}
 60   return true;                                     55   return true;
 61 }                                                  56 }
 62 }}                                                 57 }}
 63                                                    58 
 64 //____________________________________________     59 //_____________________________________________________________________________
 65 G4XmlRNtupleManager::G4XmlRNtupleManager(const     60 G4XmlRNtupleManager::G4XmlRNtupleManager(const G4AnalysisManagerState& state)
 66  : G4TRNtupleManager<tools::aida::ntuple>(stat     61  : G4TRNtupleManager<tools::aida::ntuple>(state)
 67 {}                                                 62 {}
 68                                                    63 
 69 //                                             << 
 70 // private methods                             << 
 71 //                                             << 
 72                                                << 
 73 //____________________________________________     64 //_____________________________________________________________________________
 74 G4int G4XmlRNtupleManager::ReadNtupleImpl(cons <<  65 G4XmlRNtupleManager::~G4XmlRNtupleManager()
 75                                           cons <<  66 {}
 76                                           cons << 
 77                                           G4bo << 
 78 {                                              << 
 79   Message(kVL4, "read", "ntuple", ntupleName); << 
 80                                                << 
 81   // Ntuples are saved per object and per thre << 
 82   // but apply the ntuple name and the thread  << 
 83   // only if fileName is not provided explicit << 
 84   auto fullFileName = fileName;                << 
 85   if ( ! isUserFileName ) {                    << 
 86     fullFileName = fFileManager->GetNtupleFile << 
 87   }                                            << 
 88                                                << 
 89   auto handler = fFileManager->GetHandler<tool << 
 90                                  fullFileName, << 
 91   if (handler == nullptr) return kInvalidId;   << 
 92                                                << 
 93   auto rntuple = static_cast<tools::aida::ntup << 
 94   auto id = SetNtuple(new G4TRNtupleDescriptio << 
 95                                                << 
 96   Message(kVL2, "read", "ntuple", ntupleName,  << 
 97                                                    67 
 98   return id;                                   <<  68 // 
 99 }                                              <<  69 // private methods
                                                   >>  70 //
100                                                    71 
101 //____________________________________________     72 //_____________________________________________________________________________
102 G4bool G4XmlRNtupleManager::SetNtupleIColumn(G <<  73 G4bool G4XmlRNtupleManager::SetNtupleIColumn(G4int ntupleId, 
103                                              c <<  74                                              const G4String& columnName, 
104                                              s     75                                              std::vector<G4int>& vector)
105 {                                                  76 {
106 // Override base class default implementation      77 // Override base class default implementation
107                                                    78 
108   Message(kVL4, "set", "ntuple I column",      <<  79 #ifdef G4VERBOSE
109     " ntupleId " + to_string(ntupleId) + " " + <<  80   if ( fState.GetVerboseL4() ) {
                                                   >>  81     G4ExceptionDescription description;
                                                   >>  82     description << " ntupleId " << ntupleId << " " << columnName;  
                                                   >>  83     fState.GetVerboseL4()->Message("set", "ntuple I column", description);
                                                   >>  84   }  
                                                   >>  85 #endif
110                                                    86 
111   auto ntupleDescription = GetNtupleDescriptio     87   auto ntupleDescription = GetNtupleDescriptionInFunction(ntupleId, "SetNtupleIColumn");
112   if (ntupleDescription == nullptr) return fal <<  88   if ( ! ntupleDescription )  return false;   
113                                                <<  89   
114   // not supported                                 90   // not supported
115   //tools::ntuple_binding* ntupleBinding = ntu     91   //tools::ntuple_binding* ntupleBinding = ntupleDescription->fNtupleBinding;
116   //ntupleBinding->add_column(columnName, vect     92   //ntupleBinding->add_column(columnName, vector);
117                                                    93 
118   auto subNtuple = new tools::aida::ntuple(G4c     94   auto subNtuple = new tools::aida::ntuple(G4cout, columnName);
119   ntupleDescription->fIVectorBindingMap[subNtu     95   ntupleDescription->fIVectorBindingMap[subNtuple] = &vector;
120   tools::ntuple_binding* ntupleBinding = ntupl     96   tools::ntuple_binding* ntupleBinding = ntupleDescription->fNtupleBinding;
121   ntupleBinding->add_column_cid(columnName, *s     97   ntupleBinding->add_column_cid(columnName, *subNtuple);
122                                                    98 
123   Message(kVL2, "set", "ntuple I column",      <<  99 #ifdef G4VERBOSE
124     " ntupleId " + to_string(ntupleId) + " " + << 100   if ( fState.GetVerboseL2() ) {
                                                   >> 101     G4ExceptionDescription description;
                                                   >> 102     description << " ntupleId " << ntupleId << " " << columnName;  
                                                   >> 103     fState.GetVerboseL2()->Message("set", "ntuple I colum", description, true);
                                                   >> 104   }  
                                                   >> 105 #endif
125                                                   106 
126   return true;                                    107   return true;
127 }                                                 108 }
128                                                   109 
129 //____________________________________________    110 //_____________________________________________________________________________
130 G4bool G4XmlRNtupleManager::SetNtupleFColumn(G << 111 G4bool G4XmlRNtupleManager::SetNtupleFColumn(G4int ntupleId, 
131                                              c << 112                                              const G4String& columnName, 
132                                              s    113                                              std::vector<G4float>& vector)
133 {                                                 114 {
134 // Override base class default implementation     115 // Override base class default implementation
135                                                   116 
136   Message(kVL4, "set", "ntuple F column",      << 117 #ifdef G4VERBOSE
137     " ntupleId " + to_string(ntupleId) + " " + << 118   if ( fState.GetVerboseL4() ) {
138                                                << 119     G4ExceptionDescription description;
                                                   >> 120     description << " ntupleId " << ntupleId << " " << columnName;  
                                                   >> 121     fState.GetVerboseL4()->Message("set", "ntuple F column of vector", description);
                                                   >> 122   }  
                                                   >> 123 #endif
139                                                   124 
140   auto ntupleDescription = GetNtupleDescriptio    125   auto ntupleDescription = GetNtupleDescriptionInFunction(ntupleId, "SetNtupleFColumn");
141   if (ntupleDescription == nullptr) return fal << 126   if ( ! ntupleDescription )  return false;   
142                                                << 127   
143   // not supported                                128   // not supported
144   //tools::ntuple_binding* ntupleBinding = ntu    129   //tools::ntuple_binding* ntupleBinding = ntupleDescription->fNtupleBinding;
145   //ntupleBinding->add_column(columnName, vect    130   //ntupleBinding->add_column(columnName, vector);
146                                                   131 
147   auto subNtuple = new tools::aida::ntuple(G4c    132   auto subNtuple = new tools::aida::ntuple(G4cout, columnName);
148   ntupleDescription->fFVectorBindingMap[subNtu    133   ntupleDescription->fFVectorBindingMap[subNtuple] = &vector;
149   tools::ntuple_binding* ntupleBinding = ntupl    134   tools::ntuple_binding* ntupleBinding = ntupleDescription->fNtupleBinding;
150   ntupleBinding->add_column_cid(columnName, *s    135   ntupleBinding->add_column_cid(columnName, *subNtuple);
151                                                   136 
152   Message(kVL4, "set", "ntuple F column",      << 137 #ifdef G4VERBOSE
153     " ntupleId " + to_string(ntupleId) + " " + << 138   if ( fState.GetVerboseL2() ) {
                                                   >> 139     G4ExceptionDescription description;
                                                   >> 140     description << " ntupleId " << ntupleId << " " << columnName;  
                                                   >> 141     fState.GetVerboseL2()->Message("set", "ntuple F colum", description, true);
                                                   >> 142   }  
                                                   >> 143 #endif
154                                                   144 
155   return true;                                    145   return true;
156 }                                                 146 }
157                                                   147 
158 //____________________________________________    148 //_____________________________________________________________________________
159 G4bool G4XmlRNtupleManager::SetNtupleDColumn(G << 149 G4bool G4XmlRNtupleManager::SetNtupleDColumn(G4int ntupleId, 
160                                              c << 150                                              const G4String& columnName, 
161                                              s    151                                              std::vector<G4double>& vector)
162 {                                                 152 {
163 // Override base class default implementation     153 // Override base class default implementation
164                                                   154 
165   Message(kVL4, "set", "ntuple D column",      << 155 #ifdef G4VERBOSE
166     " ntupleId " + to_string(ntupleId) + " " + << 156   if ( fState.GetVerboseL4() ) {
                                                   >> 157     G4ExceptionDescription description;
                                                   >> 158     description << " ntupleId " << ntupleId << " " << columnName;  
                                                   >> 159     fState.GetVerboseL4()->Message("set", "ntuple D column of vector", description);
                                                   >> 160   }  
                                                   >> 161 #endif
167                                                   162 
168   auto ntupleDescription = GetNtupleDescriptio    163   auto ntupleDescription = GetNtupleDescriptionInFunction(ntupleId, "SetNtupleDColumn");
169   if (ntupleDescription == nullptr) return fal << 164   if ( ! ntupleDescription )  return false;   
170                                                << 165   
171   // not supported                                166   // not supported
172   //tools::ntuple_binding* ntupleBinding = ntu    167   //tools::ntuple_binding* ntupleBinding = ntupleDescription->fNtupleBinding;
173   //ntupleBinding->add_column(columnName, vect    168   //ntupleBinding->add_column(columnName, vector);
174                                                   169 
175   auto subNtuple = new tools::aida::ntuple(G4c    170   auto subNtuple = new tools::aida::ntuple(G4cout, columnName);
176   ntupleDescription->fDVectorBindingMap[subNtu    171   ntupleDescription->fDVectorBindingMap[subNtuple] = &vector;
177   tools::ntuple_binding* ntupleBinding = ntupl    172   tools::ntuple_binding* ntupleBinding = ntupleDescription->fNtupleBinding;
178   ntupleBinding->add_column_cid(columnName, *s    173   ntupleBinding->add_column_cid(columnName, *subNtuple);
179                                                   174 
180   Message(kVL2, "set", "ntuple D column",      << 175 #ifdef G4VERBOSE
181     " ntupleId " + to_string(ntupleId) + " " + << 176   if ( fState.GetVerboseL2() ) {
182                                                << 177     G4ExceptionDescription description;
183   return true;                                 << 178     description << " ntupleId " << ntupleId << " " << columnName;  
184 }                                              << 179     fState.GetVerboseL2()->Message("set", "ntuple D colum", description, true);
185                                                << 180   }  
186 //____________________________________________ << 181 #endif
187 G4bool G4XmlRNtupleManager::SetNtupleSColumn(G << 
188                                              c << 
189                                              s << 
190 {                                              << 
191 // Override base class default implementation  << 
192                                                << 
193   Message(kVL4, "set", "ntuple S column",      << 
194     " ntupleId " + to_string(ntupleId) + " " + << 
195                                                << 
196   auto ntupleDescription = GetNtupleDescriptio << 
197   if (ntupleDescription == nullptr) return fal << 
198                                                << 
199   // not supported                             << 
200   //tools::ntuple_binding* ntupleBinding = ntu << 
201   //ntupleBinding->add_column(columnName, vect << 
202                                                << 
203   auto subNtuple = new tools::aida::ntuple(G4c << 
204   ntupleDescription->fSVectorBindingMap[subNtu << 
205   tools::ntuple_binding* ntupleBinding = ntupl << 
206   ntupleBinding->add_column_cid(columnName, *s << 
207                                                << 
208   Message(kVL2, "set", "ntuple S column",      << 
209     " ntupleId " + to_string(ntupleId) + " " + << 
210                                                   182 
211   return true;                                    183   return true;
212 }                                                 184 }
213                                                   185 
214 //____________________________________________    186 //_____________________________________________________________________________
215 G4bool G4XmlRNtupleManager::GetTNtupleRow(        187 G4bool G4XmlRNtupleManager::GetTNtupleRow(
216   G4TRNtupleDescription<tools::aida::ntuple>*     188   G4TRNtupleDescription<tools::aida::ntuple>* ntupleDescription)
217 {                                                 189 {
218   auto ntuple = ntupleDescription->fNtuple;       190   auto ntuple = ntupleDescription->fNtuple;
219                                                   191 
220   G4bool isInitialized = ntupleDescription->fI    192   G4bool isInitialized = ntupleDescription->fIsInitialized;
221   if ( ! isInitialized ) {                        193   if ( ! isInitialized ) {
222     tools::ntuple_binding* ntupleBinding = ntu    194     tools::ntuple_binding* ntupleBinding = ntupleDescription->fNtupleBinding;
223     if ( ! ntuple->set_binding(std::cout, *ntu    195     if ( ! ntuple->set_binding(std::cout, *ntupleBinding) ) {
224       Warn("Ntuple initialization failed !!",  << 196       G4ExceptionDescription description;
                                                   >> 197       description 
                                                   >> 198         << "      " 
                                                   >> 199         << "Ntuple initialization failed !!"; 
                                                   >> 200       G4Exception("G4XmlRNtuple::GetNtupleRow()",
                                                   >> 201                   "Analysis_WR021", JustWarning, description);
225       return false;                               202       return false;
226     }                                             203     }
227     ntupleDescription->fIsInitialized = true;     204     ntupleDescription->fIsInitialized = true;
228     ntuple->start();                              205     ntuple->start();
229   }                                               206   }
230                                                   207 
231   G4bool next = ntuple->next();                   208   G4bool next = ntuple->next();
232   if ( next ) {                                   209   if ( next ) {
233     if ( ! ntuple->get_row() ) {                  210     if ( ! ntuple->get_row() ) {
234       Warn("Ntuple get_row() failed !!", fkCla << 211       G4ExceptionDescription description;
                                                   >> 212       description 
                                                   >> 213         << "      " 
                                                   >> 214         << "Ntuple get_row() failed !!"; 
                                                   >> 215       G4Exception("G4XmlRNtuple::GetNtupleRow()",
                                                   >> 216                   "Analysis_WR021", JustWarning, description);
235       return false;                               217       return false;
236     }                                             218     }
237                                                   219 
238     // fill vector from sub ntuples               220     // fill vector from sub ntuples
239     for ( auto [key, value] : ntupleDescriptio << 221 
240       tools::aida::to_vector<int>(*key, *value << 222     {std::map<tools::aida::ntuple*, std::vector<int>* >::iterator it;
241     }                                          << 223     for ( it = ntupleDescription->fIVectorBindingMap.begin(); 
242     for ( auto [key, value] : ntupleDescriptio << 224           it != ntupleDescription->fIVectorBindingMap.end(); it++) {
243       tools::aida::to_vector<float>(*key, *val << 225       tools::aida::to_vector<int>(*(it->first), *(it->second));        
244     }                                          << 226     }}
245     for ( auto [key, value] : ntupleDescriptio << 227     {std::map<tools::aida::ntuple*, std::vector<float>* >::iterator it;
246       tools::aida::to_vector<double>(*key, *va << 228     for ( it = ntupleDescription->fFVectorBindingMap.begin(); 
247     }                                          << 229           it != ntupleDescription->fFVectorBindingMap.end(); it++) {
248     for ( auto [key, value] : ntupleDescriptio << 230       tools::aida::to_vector<float>(*(it->first), *(it->second));        
249       tools::aida::to_vector<std::string>(*key << 231     }}
250     }                                          << 232     {std::map<tools::aida::ntuple*, std::vector<double>* >::iterator it;
251   }                                            << 233     for ( it = ntupleDescription->fDVectorBindingMap.begin(); 
                                                   >> 234           it != ntupleDescription->fDVectorBindingMap.end(); it++) {
                                                   >> 235       tools::aida::to_vector<double>(*(it->first), *(it->second));        
                                                   >> 236     }}
                                                   >> 237   }  
252                                                   238 
253   return next;                                    239   return next;
254 }                                              << 240 }   
255                                                   241