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] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

  1 //
  2 // ********************************************************************
  3 // * License and Disclaimer                                           *
  4 // *                                                                  *
  5 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
  6 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
  7 // * conditions of the Geant4 Software License,  included in the file *
  8 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
  9 // * include a list of copyright holders.                             *
 10 // *                                                                  *
 11 // * Neither the authors of this software system, nor their employing *
 12 // * institutes,nor the agencies providing financial support for this *
 13 // * work  make  any representation or  warranty, express or implied, *
 14 // * regarding  this  software system or assume any liability for its *
 15 // * use.  Please see the license in the file  LICENSE  and URL above *
 16 // * for the full disclaimer and the limitation of liability.         *
 17 // *                                                                  *
 18 // * This  code  implementation is the result of  the  scientific and *
 19 // * technical work of the GEANT4 collaboration.                      *
 20 // * By using,  copying,  modifying or  distributing the software (or *
 21 // * any work based  on the software)  you  agree  to acknowledge its *
 22 // * use  in  resulting  scientific  publications,  and indicate your *
 23 // * acceptance of all terms of the Geant4 Software license.          *
 24 // ********************************************************************
 25 //
 26 
 27 // Author: Ivana Hrivnacova, 20/07/2017 (ivana@ipno.in2p3.fr)
 28 
 29 #include "G4AnalysisManagerState.hh"
 30 #include "G4AnalysisUtilities.hh"
 31 
 32 using std::to_string;
 33 
 34 //_____________________________________________________________________________
 35 template <typename NT>
 36 G4TRNtupleManager<NT>::G4TRNtupleManager(const G4AnalysisManagerState& state)
 37  : G4BaseRNtupleManager(state)
 38 {}
 39 
 40 //_____________________________________________________________________________
 41 template <typename NT>
 42 G4TRNtupleManager<NT>::~G4TRNtupleManager()
 43 {
 44   for ( auto ntupleDescription : fNtupleDescriptionVector ) {
 45     delete ntupleDescription;
 46   }
 47 }
 48 
 49 //
 50 // private methods
 51 //
 52 
 53 //_____________________________________________________________________________
 54 template <typename NT>
 55 G4TRNtupleDescription<NT>*
 56 G4TRNtupleManager<NT>::GetNtupleDescriptionInFunction(
 57   G4int id, std::string_view functionName, G4bool warn) const
 58 {
 59   G4int index = id - fFirstId;
 60   if ( index < 0 || index >= G4int(fNtupleDescriptionVector.size()) ) {
 61     if ( warn) {
 62       G4Analysis::Warn("ntuple " + to_string(id) + " does not exist.",
 63         fkClass, functionName);
 64     }
 65     return nullptr;
 66   }
 67 
 68   return fNtupleDescriptionVector[index];
 69 }
 70 
 71 //_____________________________________________________________________________
 72 template <typename NT>
 73 template <typename T>
 74 G4bool
 75 G4TRNtupleManager<NT>::SetNtupleTColumn(
 76   G4int ntupleId, const G4String& columnName, T& value)
 77 {
 78   Message(G4Analysis::kVL4, "set", "ntuple T column",
 79     " ntupleId " + to_string(ntupleId) + " " + columnName);
 80 
 81   auto ntupleDescription = GetNtupleDescriptionInFunction(ntupleId, "SetNtupleTColumn");
 82   if ( ! ntupleDescription )  return false;
 83 
 84   auto ntupleBinding = ntupleDescription->fNtupleBinding;
 85   ntupleBinding->add_column(columnName, value);
 86 
 87   Message(G4Analysis::kVL2, "set", "ntuple T column",
 88     " ntupleId " + to_string(ntupleId) + " " + columnName);
 89 
 90   return true;
 91 }
 92 
 93 //_____________________________________________________________________________
 94 template <typename NT>
 95 template <typename T>
 96 G4bool
 97 G4TRNtupleManager<NT>::SetNtupleTColumn(
 98   G4int ntupleId, const G4String& columnName, std::vector<T>& vector)
 99 {
100   Message(G4Analysis::kVL4, "set", "ntuple T column",
101     " ntupleId " + to_string(ntupleId) + " " + columnName);
102 
103   auto ntupleDescription = GetNtupleDescriptionInFunction(ntupleId, "SetNtupleTColumn");
104   if ( ! ntupleDescription )  return false;
105 
106   auto ntupleBinding = ntupleDescription->fNtupleBinding;
107   ntupleBinding->add_column(columnName, vector);
108 
109   Message(G4Analysis::kVL2, "set", "ntuple T column",
110     " ntupleId " + to_string(ntupleId) + " " + columnName);
111 
112 
113   return true;
114 }
115 
116 //
117 // protected methods
118 //
119 
120 //_____________________________________________________________________________
121 template <typename NT>
122 G4bool G4TRNtupleManager<NT>::IsEmpty() const
123 {
124   return ! fNtupleDescriptionVector.size();
125 }
126 
127 //_____________________________________________________________________________
128 template <typename NT>
129 G4bool G4TRNtupleManager<NT>::Reset()
130 {
131 // Reset ntuples
132 
133   for ( auto ntupleDescription : fNtupleDescriptionVector ) {
134     delete ntupleDescription->fNtuple;
135     ntupleDescription->fNtuple=nullptr;
136   }
137   return true;
138 }
139 
140 //_____________________________________________________________________________
141 template <typename NT>
142 NT*
143 G4TRNtupleManager<NT>::GetNtuple() const
144 {
145   return GetNtuple(fFirstId);
146 }
147 
148 //_____________________________________________________________________________
149 template <typename NT>
150 NT*
151 G4TRNtupleManager<NT>::GetNtuple(
152   G4int ntupleId) const
153 {
154   auto rntupleDescription = GetNtupleDescriptionInFunction(ntupleId, "GetNtuple");
155 
156   if ( ! rntupleDescription ) return nullptr;
157 
158   return rntupleDescription->fNtuple;
159 }
160 
161 //_____________________________________________________________________________
162 template <typename NT>
163 G4int G4TRNtupleManager<NT>::SetNtuple(
164   G4TRNtupleDescription<NT>* rntupleDescription)
165 {
166   auto id = G4int(fNtupleDescriptionVector.size() + fFirstId);
167 
168   fNtupleDescriptionVector.push_back(rntupleDescription);
169 
170   return id;
171 }
172 
173 //_____________________________________________________________________________
174 template <typename NT>
175 G4bool
176 G4TRNtupleManager<NT>::SetNtupleIColumn(
177   G4int ntupleId, const G4String& columnName, G4int& value)
178 {
179   return SetNtupleTColumn<int>(ntupleId, columnName, value);
180 }
181 
182 //_____________________________________________________________________________
183 template <typename NT>
184 G4bool
185 G4TRNtupleManager<NT>::SetNtupleFColumn(
186   G4int ntupleId, const G4String& columnName, G4float& value)
187 {
188   return SetNtupleTColumn<float>(ntupleId, columnName, value);
189 }
190 
191 //_____________________________________________________________________________
192 template <typename NT>
193 G4bool
194 G4TRNtupleManager<NT>::SetNtupleDColumn(
195   G4int ntupleId, const G4String& columnName, G4double& value)
196 {
197   return SetNtupleTColumn<double>(ntupleId, columnName, value);
198 }
199 
200 //_____________________________________________________________________________
201 template <typename NT>
202 G4bool
203 G4TRNtupleManager<NT>::SetNtupleIColumn(
204   G4int ntupleId, const G4String& columnName, std::vector<G4int>& vector)
205 {
206   return SetNtupleTColumn<int>(ntupleId, columnName, vector);
207 }
208 
209 //_____________________________________________________________________________
210 template <typename NT>
211 G4bool
212 G4TRNtupleManager<NT>::SetNtupleFColumn(
213   G4int ntupleId, const G4String& columnName, std::vector<G4float>& vector)
214 {
215   return SetNtupleTColumn<float>(ntupleId, columnName, vector);
216 }
217 
218 //_____________________________________________________________________________
219 template <typename NT>
220 G4bool
221 G4TRNtupleManager<NT>::SetNtupleDColumn(
222   G4int ntupleId, const G4String& columnName, std::vector<G4double>& vector)
223 {
224   return SetNtupleTColumn<double>(ntupleId, columnName, vector);
225 }
226 
227 //_____________________________________________________________________________
228 template <typename NT>
229 G4bool
230 G4TRNtupleManager<NT>::SetNtupleSColumn(
231   G4int ntupleId, const G4String& columnName, G4String& value)
232 {
233   return SetNtupleTColumn<std::string>(ntupleId, columnName, value);
234 }
235 
236 //_____________________________________________________________________________
237 template <typename NT>
238 G4bool
239 G4TRNtupleManager<NT>::SetNtupleSColumn(
240   G4int ntupleId, const G4String& columnName, std::vector<std::string>& vector)
241 {
242   return SetNtupleTColumn<std::string>(ntupleId, columnName, vector);
243 }
244 
245 //_____________________________________________________________________________
246 template <typename NT>
247 G4bool G4TRNtupleManager<NT>::GetNtupleRow(G4int ntupleId)
248 {
249   Message(G4Analysis::kVL4, "get", "ntuple row",
250     "ntupleId " + to_string(ntupleId));
251 
252   auto ntupleDescription
253     = GetNtupleDescriptionInFunction(ntupleId, "GetNtupleRow");
254   if ( ! ntupleDescription )  return false;
255 
256   auto next = GetTNtupleRow(ntupleDescription);
257 
258   Message(G4Analysis::kVL2, "get", "ntuple row",
259     "ntupleId " + to_string(ntupleId));
260 
261   return next;
262 }
263 
264 
265 //_____________________________________________________________________________
266 template <typename NT>
267 G4int
268 G4TRNtupleManager<NT>::GetNofNtuples() const
269 {
270   return G4int(fNtupleDescriptionVector.size());
271 }
272 
273 
274