Geant4  10.01.p03
G4XmlNtupleManager.cc
Go to the documentation of this file.
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 // $Id: G4XmlNtupleManager.cc 70604 2013-06-03 11:27:06Z ihrivnac $
27 
28 // Author: Ivana Hrivnacova, 18/06/2013 (ivana@ipno.in2p3.fr)
29 
30 #include "G4XmlNtupleManager.hh"
32 #include "G4XmlFileManager.hh"
34 #include "G4AnalysisUtilities.hh"
35 #include "G4Threading.hh"
36 #include "G4UnitsTable.hh"
37 
38 #include "tools/ntuple_booking"
39 
40 #include <iostream>
41 #include <cstdio>
42 
43 using namespace G4Analysis;
44 
45 //_____________________________________________________________________________
47  : G4VNtupleManager(state),
48  fFileManager(0),
49  fNtupleDescriptionVector(),
50  fNtupleVector()
51 {
52 }
53 
54 //_____________________________________________________________________________
56 {
57  std::vector<G4XmlNtupleDescription*>::iterator it;
58  for (it = fNtupleDescriptionVector.begin(); it != fNtupleDescriptionVector.end(); it++ ) {
59  delete (*it);
60  }
61 }
62 
63 //
64 // private methods
65 //
66 
67 //_____________________________________________________________________________
68 tools::waxml::ntuple::column<int>*
70 {
71  G4XmlNtupleDescription* ntupleDecription
72  = GetNtupleInFunction(ntupleId, "GetNtupleIColumn");
73  if ( ! ntupleDecription ) return 0;
74 
75  std::map<G4int, tools::waxml::ntuple::column<int>* >& ntupleIColumnMap
76  = ntupleDecription->fNtupleIColumnMap;
77  std::map<G4int, tools::waxml::ntuple::column<int>* >::const_iterator it
78  = ntupleIColumnMap.find(columnId);
79  if ( it == ntupleIColumnMap.end() ) {
80  G4ExceptionDescription description;
81  description << " " << "ntupleId " << ntupleId
82  << " columnId " << columnId << " does not exist.";
83  G4Exception("G4XmlNtupleManager::GetNtupleIColumn()",
84  "Analysis_W011", JustWarning, description);
85  return 0;
86  }
87 
88  return it->second;
89 }
90 
91 //_____________________________________________________________________________
92 tools::waxml::ntuple::column<float>*
94 {
95  G4XmlNtupleDescription* ntupleDecription
96  = GetNtupleInFunction(ntupleId, "GetNtupleFColumn");
97  if ( ! ntupleDecription ) return 0;
98 
99  std::map<G4int, tools::waxml::ntuple::column<float>* >& ntupleFColumnMap
100  = ntupleDecription->fNtupleFColumnMap;
101  std::map<G4int, tools::waxml::ntuple::column<float>* >::const_iterator it
102  = ntupleFColumnMap.find(columnId);
103  if ( it == ntupleFColumnMap.end() ) {
104  G4ExceptionDescription description;
105  description << " " << "ntupleId " << ntupleId
106  << " columnId " << columnId << " does not exist.";
107  G4Exception("G4XmlNtupleManager::GetNtupleFColumn()",
108  "Analysis_W011", JustWarning, description);
109  return 0;
110  }
111 
112  return it->second;
113 }
114 
115 //_____________________________________________________________________________
116 tools::waxml::ntuple::column<double>*
118 {
119  G4XmlNtupleDescription* ntupleDecription
120  = GetNtupleInFunction(ntupleId, "GetNtupleDColumn");
121  if ( ! ntupleDecription ) return 0;
122 
123  std::map<G4int, tools::waxml::ntuple::column<double>* >& ntupleDColumnMap
124  = ntupleDecription->fNtupleDColumnMap;
125  std::map<G4int, tools::waxml::ntuple::column<double>* >::const_iterator it
126  = ntupleDColumnMap.find(columnId);
127  if ( it == ntupleDColumnMap.end() ) {
128  G4ExceptionDescription description;
129  description << " " << "ntupleId " << ntupleId
130  << " columnId " << columnId << " does not exist.";
131  G4Exception("G4XmlNtupleManager::GetNtupleFColumn()",
132  "Analysis_W011", JustWarning, description);
133  return 0;
134  }
135 
136  return it->second;
137 }
138 
139 //_____________________________________________________________________________
140 tools::waxml::ntuple::column<std::string>*
142 {
143  G4XmlNtupleDescription* ntupleDecription
144  = GetNtupleInFunction(ntupleId, "GetNtupleSColumn");
145  if ( ! ntupleDecription ) return 0;
146 
147  std::map<G4int, tools::waxml::ntuple::column<std::string>* >& ntupleSColumnMap
148  = ntupleDecription->fNtupleSColumnMap;
149  std::map<G4int, tools::waxml::ntuple::column<std::string>* >::const_iterator it
150  = ntupleSColumnMap.find(columnId);
151  if ( it == ntupleSColumnMap.end() ) {
152  G4ExceptionDescription description;
153  description << " " << "ntupleId " << ntupleId
154  << " columnId " << columnId << " does not exist.";
155  G4Exception("G4XmlNtupleManager::GetNtupleSColumn()",
156  "Analysis_W011", JustWarning, description);
157  return 0;
158  }
159 
160  return it->second;
161 }
162 
163 //_____________________________________________________________________________
165  G4String functionName, G4bool warn,
166  G4bool /*onlyIfActive*/) const
167 {
168  G4int index = id - fFirstId;
169  if ( index < 0 || index >= G4int(fNtupleDescriptionVector.size()) ) {
170  if ( warn) {
171  G4String inFunction = "G4XmlNtupleManager::";
172  inFunction += functionName;
173  G4ExceptionDescription description;
174  description << " " << "ntuple " << id << " does not exist.";
175  G4Exception(inFunction, "Analysis_W011", JustWarning, description);
176  }
177  return 0;
178  }
179 
180  return fNtupleDescriptionVector[index];
181 }
182 
183 //
184 // protected methods
185 //
186 
187 //_____________________________________________________________________________
189 {
190 // Create ntuple from ntuple_booking.
191 
192  G4int ntupleId = fFirstId;
193  std::vector<G4XmlNtupleDescription*>::iterator itn;
194  for (itn = fNtupleDescriptionVector.begin(); itn != fNtupleDescriptionVector.end(); itn++ ) {
195 
196  tools::ntuple_booking* ntupleBooking = (*itn)->fNtupleBooking;
197  if ( ! ntupleBooking ) continue;
198 
199 // Create ntuple from ntuple_booking.
200 #ifdef G4VERBOSE
201  if ( fState.GetVerboseL4() )
203  ->Message("create from booking", "ntuple", ntupleBooking->name());
204 #endif
205 
206  // create a file for this ntuple
207  if ( ! fFileManager->CreateNtupleFile((*itn)) ) continue;
208 
209  // create ntuple
210  (*itn)->fNtuple
211  = new tools::waxml::ntuple(*((*itn)->fFile), G4cerr, *ntupleBooking);
212  fNtupleVector.push_back((*itn)->fNtuple);
213 
214  if ( ntupleBooking->columns().size() ) {
215  // store ntuple columns in local maps
216  const std::vector<tools::column_booking>& columns
217  = ntupleBooking->columns();
218  std::vector<tools::column_booking>::const_iterator it;
219  G4int index = 0;
220  for ( it = columns.begin(); it!=columns.end(); ++it) {
221  if ( it->cls_id() == tools::_cid(int(0) ) ) {
222  (*itn)->fNtupleIColumnMap[index++]
223  = (*itn)->fNtuple->find_column<int>(it->name());
224  }
225  else if( it->cls_id() == tools::_cid(float(0) ) ) {
226  (*itn)->fNtupleFColumnMap[index++]
227  = (*itn)->fNtuple->find_column<float>(it->name());
228  }
229  else if(it->cls_id()== tools::_cid(double(0))) {
230  (*itn)->fNtupleDColumnMap[index++]
231  = (*itn)->fNtuple->find_column<double>(it->name());
232  }
233  else if(it->cls_id()== tools::_cid(std::string(""))) {
234  (*itn)->fNtupleSColumnMap[index++]
235  = (*itn)->fNtuple->find_column<std::string>(it->name());
236  }
237  else {
238  G4ExceptionDescription description;
239  description << " "
240  << "Unsupported column type " << it->name();
241  G4Exception("G4XmlNtupleManager::CreateNtuplesFromBooking()",
242  "Analysis_W002", JustWarning, description);
243  }
244  }
245  }
246  FinishNtuple(ntupleId++);
247 #ifdef G4VERBOSE
248  if ( fState.GetVerboseL3() )
250  ->Message("create from booking", "ntuple", ntupleBooking->name());
251 #endif
252  }
253 }
254 
255 //_____________________________________________________________________________
257 {
258  return ! fNtupleDescriptionVector.size();
259 }
260 
261 //_____________________________________________________________________________
263 {
264 // Reset ntuples
265 
266  std::vector<G4XmlNtupleDescription*>::iterator it;
267  for (it = fNtupleDescriptionVector.begin(); it != fNtupleDescriptionVector.end(); it++ ) {
268  delete (*it)->fNtuple;
269  (*it)->fNtuple = 0;
270  }
271  fNtupleVector.clear();
272 
273  return true;
274 }
275 
276 //_____________________________________________________________________________
277 tools::waxml::ntuple* G4XmlNtupleManager::GetNtuple() const
278 {
279  return GetNtuple(fFirstId);
280 }
281 
282 //_____________________________________________________________________________
283 tools::waxml::ntuple* G4XmlNtupleManager::GetNtuple(G4int ntupleId) const
284 {
285  G4XmlNtupleDescription* ntupleDescription
286  = GetNtupleInFunction(ntupleId, "GetNtuple");
287 
288  if ( ! ntupleDescription ) return 0;
289 
290  return ntupleDescription->fNtuple;
291 }
292 
293 //_____________________________________________________________________________
295  const G4String& title)
296 {
297 #ifdef G4VERBOSE
298  if ( fState.GetVerboseL4() )
299  fState.GetVerboseL4()->Message("create", "ntuple", name);
300 #endif
301 
302  // Create ntuple description
303  G4int index = fNtupleDescriptionVector.size();
304  G4XmlNtupleDescription* ntupleDescription
305  = new G4XmlNtupleDescription();
306  fNtupleDescriptionVector.push_back(ntupleDescription);
307 
308  // Create ntuple booking
309  ntupleDescription->fNtupleBooking
310  = new tools::ntuple_booking(name, title);
311 
312  // Create ntuple if the file is open (what means here that
313  // a filename was already set)
314  if ( fFileManager->GetFileName().size() ) {
315  if ( fFileManager->CreateNtupleFile(ntupleDescription) ) {
316  ntupleDescription->fNtuple
317  = new tools::waxml::ntuple(*(ntupleDescription->fFile));
318  // ntuple object is deleted when closing a file
319  fNtupleVector.push_back(ntupleDescription->fNtuple);
320  }
321  }
322 
323  fLockFirstId = true;
324 
325 #ifdef G4VERBOSE
326  if ( fState.GetVerboseL2() ) {
327  G4ExceptionDescription description;
328  description << name << " ntupleId " << index + fFirstId;
329  fState.GetVerboseL2()->Message("create", "ntuple", description);
330  }
331 #endif
332 
333  return index + fFirstId;
334 }
335 
336 //_____________________________________________________________________________
338  std::vector<int>* vector)
339 {
340  G4int ntupleId = fNtupleDescriptionVector.size() + fFirstId - 1;
341  return CreateNtupleIColumn(ntupleId, name, vector);
342 }
343 
344 //_____________________________________________________________________________
346  std::vector<float>* vector)
347 {
348  G4int ntupleId = fNtupleDescriptionVector.size() + fFirstId - 1;
349  return CreateNtupleFColumn(ntupleId, name, vector);
350 }
351 
352 //_____________________________________________________________________________
354  std::vector<double>* vector)
355 {
356  G4int ntupleId = fNtupleDescriptionVector.size() + fFirstId - 1;
357  return CreateNtupleDColumn(ntupleId, name, vector);
358 }
359 
360 //_____________________________________________________________________________
362 {
363  G4int ntupleId = fNtupleDescriptionVector.size() + fFirstId - 1;
364  return CreateNtupleSColumn(ntupleId, name);
365 }
366 
367 //_____________________________________________________________________________
369 {
370  G4int ntupleId = fNtupleDescriptionVector.size() + fFirstId - 1;
371  FinishNtuple(ntupleId);
372 }
373 
374 //_____________________________________________________________________________
376  const G4String& name,
377  std::vector<int>* vector)
378 {
379 #ifdef G4VERBOSE
380  if ( fState.GetVerboseL4() ) {
381  G4ExceptionDescription description;
382  description << name << " ntupleId " << ntupleId;
383  fState.GetVerboseL4()->Message("create", "ntuple I column", description);
384  }
385  #endif
386 
387  G4XmlNtupleDescription* ntupleDescription
388  = GetNtupleInFunction(ntupleId, "CreateNtupleIColumn");
389  if ( ! ntupleDescription ) return kInvalidId;
390 
391  tools::ntuple_booking* ntupleBooking
392  = ntupleDescription->fNtupleBooking;
393 
394  if ( ! ntupleBooking ) {
395  G4ExceptionDescription description;
396  description << " "
397  << "Ntuple " << ntupleId << " has to be created first. ";
398  G4Exception("G4XmlNtupleManager::CreateNtupleIColumn()",
399  "Analysis_W002", JustWarning, description);
400  return kInvalidId;
401  }
402 
403  // Save column info in booking
404  G4int index = ntupleBooking->columns().size();
405  if ( ! vector )
406  ntupleBooking->add_column<int>(name);
407  else
408  ntupleBooking->add_column<int>(name, *vector);
409 
410  // Create column if ntuple already exists
411  if ( ntupleDescription->fNtuple ) {
412  if ( ! vector ) {
413  tools::waxml::ntuple::column<int>* column
414  = ntupleDescription->fNtuple->create_column<int>(name);
415  ntupleDescription->fNtupleIColumnMap[index] = column;
416  }
417  else {
418  ntupleDescription->fNtuple->create_column<int>(name, *vector);
419  }
420  }
421 
423 
424 #ifdef G4VERBOSE
425  if ( fState.GetVerboseL2() ) {
426  G4ExceptionDescription description;
427  description << name << " ntupleId " << ntupleId;
428  fState.GetVerboseL2()->Message("create", "ntuple I column", description);
429  }
430 #endif
431 
432  return index + fFirstNtupleColumnId;
433 }
434 
435 //_____________________________________________________________________________
437  const G4String& name,
438  std::vector<float>* vector)
439 {
440 #ifdef G4VERBOSE
441  if ( fState.GetVerboseL4() ) {
442  G4ExceptionDescription description;
443  description << name << " ntupleId " << ntupleId;
444  fState.GetVerboseL4()->Message("create", "ntuple F column", description);
445  }
446 #endif
447 
448  G4XmlNtupleDescription* ntupleDescription
449  = GetNtupleInFunction(ntupleId, "CreateNtupleFColumn");
450  if ( ! ntupleDescription ) return kInvalidId;
451 
452  tools::ntuple_booking* ntupleBooking
453  = ntupleDescription->fNtupleBooking;
454 
455  if ( ! ntupleBooking ) {
456  G4ExceptionDescription description;
457  description << " "
458  << "Ntuple " << ntupleId << " has to be created first. ";
459  G4Exception("G4XmlNtupleManager::CreateNtupleFColumn()",
460  "Analysis_W002", JustWarning, description);
461  return kInvalidId;
462  }
463 
464  // Save column info in booking
465  G4int index = ntupleBooking->columns().size();
466  if ( ! vector )
467  ntupleBooking->add_column<float>(name);
468  else
469  ntupleBooking->add_column<float>(name, *vector);
470 
471  // Create column if ntuple already exists
472  if ( ntupleDescription->fNtuple ) {
473  if ( ! vector ) {
474  tools::waxml::ntuple::column<float>* column
475  = ntupleDescription->fNtuple->create_column<float>(name);
476  ntupleDescription->fNtupleFColumnMap[index] = column;
477  }
478  else {
479  ntupleDescription->fNtuple->create_column<float>(name, *vector);
480  }
481  }
482 
484 
485 #ifdef G4VERBOSE
486  if ( fState.GetVerboseL2() ) {
487  G4ExceptionDescription description;
488  description << name << " ntupleId " << ntupleId;
489  fState.GetVerboseL2()->Message("create", "ntuple F column", description);
490  }
491 #endif
492 
493  return index + fFirstNtupleColumnId;
494 }
495 
496 //_____________________________________________________________________________
498  const G4String& name,
499  std::vector<double>* vector)
500 {
501 #ifdef G4VERBOSE
502  if ( fState.GetVerboseL4() ) {
503  G4ExceptionDescription description;
504  description << name << " ntupleId " << ntupleId;
505  fState.GetVerboseL4()->Message("create", "ntuple D column", description);
506  }
507 #endif
508 
509  G4XmlNtupleDescription* ntupleDescription
510  = GetNtupleInFunction(ntupleId, "CreateNtupleDColumn");
511  if ( ! ntupleDescription ) return kInvalidId;
512 
513  tools::ntuple_booking* ntupleBooking
514  = ntupleDescription->fNtupleBooking;
515 
516  if ( ! ntupleBooking ) {
517  G4ExceptionDescription description;
518  description << " "
519  << "Ntuple " << ntupleId << " has to be created first. ";
520  G4Exception("G4XmlNtupleManager::CreateNtupleDColumn()",
521  "Analysis_W002", JustWarning, description);
522  return kInvalidId;
523  }
524 
525  // Save column info in booking
526  G4int index = ntupleBooking->columns().size();
527  if ( ! vector )
528  ntupleBooking->add_column<double>(name);
529  else
530  ntupleBooking->add_column<double>(name, *vector);
531 
532  // Create column if ntuple already exists
533  if ( ntupleDescription->fNtuple ) {
534  if ( ! vector ) {
535  tools::waxml::ntuple::column<double>* column
536  = ntupleDescription->fNtuple->create_column<double>(name);
537  ntupleDescription->fNtupleDColumnMap[index] = column;
538  }
539  else {
540  ntupleDescription->fNtuple->create_column<double>(name, *vector);
541  }
542  }
543 
545 
546 #ifdef G4VERBOSE
547  if ( fState.GetVerboseL2() ) {
548  G4ExceptionDescription description;
549  description << name << " ntupleId " << ntupleId;
550  fState.GetVerboseL2()->Message("create", "ntuple D column", description);
551  }
552  #endif
553 
554  return index + fFirstNtupleColumnId;
555 }
556 
557 //_____________________________________________________________________________
559  const G4String& name)
560 {
561 #ifdef G4VERBOSE
562  if ( fState.GetVerboseL4() ) {
563  G4ExceptionDescription description;
564  description << name << " ntupleId " << ntupleId;
565  fState.GetVerboseL4()->Message("create", "ntuple S column", description);
566  }
567 #endif
568 
569  G4XmlNtupleDescription* ntupleDescription
570  = GetNtupleInFunction(ntupleId, "CreateNtupleSColumn");
571  if ( ! ntupleDescription ) return kInvalidId;
572 
573  tools::ntuple_booking* ntupleBooking
574  = ntupleDescription->fNtupleBooking;
575 
576  if ( ! ntupleBooking ) {
577  G4ExceptionDescription description;
578  description << " "
579  << "Ntuple " << ntupleId << " has to be created first. ";
580  G4Exception("G4XmlNtupleManager::CreateNtupleSColumn()",
581  "Analysis_W002", JustWarning, description);
582  return kInvalidId;
583  }
584 
585  // Save column info in booking
586  G4int index = ntupleBooking->columns().size();
587  ntupleBooking->add_column<std::string>(name);
588 
589  // Create column if ntuple already exists
590  if ( ntupleDescription->fNtuple ) {
591  tools::waxml::ntuple::column<std::string>* column
592  = ntupleDescription->fNtuple->create_column<std::string>(name);
593  ntupleDescription->fNtupleSColumnMap[index] = column;
594  }
595 
597 
598 #ifdef G4VERBOSE
599  if ( fState.GetVerboseL2() ) {
600  G4ExceptionDescription description;
601  description << name << " ntupleId " << ntupleId;
602  fState.GetVerboseL2()->Message("create", "ntuple S column", description);
603  }
604  #endif
605 
606  return index + fFirstNtupleColumnId;
607 }
608 
609 //_____________________________________________________________________________
611 {
612  G4XmlNtupleDescription* ntupleDescription
613  = GetNtupleInFunction(ntupleId, "FinishNtuple");
614  tools::ntuple_booking* ntupleBooking = 0;
615  if ( ntupleDescription ) {
616  ntupleBooking = ntupleDescription->fNtupleBooking;
617  }
618 
619  if ( ( ! ntupleDescription ) || ( ! ntupleBooking ) ) {
620  G4ExceptionDescription description;
621  description << " "
622  << "Ntuple " << ntupleId << " has to be created first. ";
623  G4Exception("G4XmlNtupleManager::CreateNtupleDColumn()",
624  "Analysis_W002", JustWarning, description);
625  return;
626  }
627 
628 #ifdef G4VERBOSE
629  if ( fState.GetVerboseL4() ) {
630  G4ExceptionDescription description;
631  description << ntupleBooking->name() << " ntupleId " << ntupleId;
632  fState.GetVerboseL4()->Message("finish", "ntuple", description);
633  }
634 #endif
635 
636  // Finish ntuple if ntuple already exists
637  if ( ntupleDescription->fNtuple ) {
638  G4String path = "/";
640  ntupleDescription->fNtuple
641  ->write_header(path, ntupleBooking->name(), ntupleBooking->title());
643  }
644 
645 #ifdef G4VERBOSE
646  if ( fState.GetVerboseL2() ) {
647  G4ExceptionDescription description;
648  description << ntupleBooking->name() << " ntupleId " << ntupleId;
649  fState.GetVerboseL2()->Message("finish", "ntuple", description);
650  }
651 #endif
652 }
653 
654 //_____________________________________________________________________________
656 {
657  return FillNtupleIColumn(fFirstId, columnId, value);
658 }
659 
660 //_____________________________________________________________________________
662 {
663  return FillNtupleFColumn(fFirstId, columnId, value);
664 }
665 
666 //_____________________________________________________________________________
668 {
669  return FillNtupleDColumn(fFirstId, columnId, value);
670 }
671 
672 //_____________________________________________________________________________
674 {
675  return FillNtupleSColumn(fFirstId, columnId, value);
676 }
677 
678 //_____________________________________________________________________________
680  G4int value)
681 {
682  tools::waxml::ntuple::column<int>* column
683  = GetNtupleIColumn(ntupleId, columnId);
684  if ( ! column ) {
685  G4ExceptionDescription description;
686  description << " " << " columnId " << columnId << " does not exist.";
687  G4Exception("G4XmlNtupleManager::FillNtupleIColumn()",
688  "Analysis_W011", JustWarning, description);
689  return false;
690  }
691 
692  column->fill(value);
693 #ifdef G4VERBOSE
694  if ( fState.GetVerboseL4() ) {
695  G4ExceptionDescription description;
696  description << " ntupleId " << ntupleId
697  << " columnId " << columnId << " value " << value;
698  fState.GetVerboseL4()->Message("fill", "ntuple I column", description);
699  }
700 #endif
701  return true;
702 }
703 //_____________________________________________________________________________
705  G4float value)
706 {
707  tools::waxml::ntuple::column<float>* column
708  = GetNtupleFColumn(ntupleId, columnId);
709  if ( ! column ) {
710  G4ExceptionDescription description;
711  description << " " << " columnId " << columnId << " does not exist.";
712  G4Exception("G4XmlNtupleManager::FillNtupleFColumn()",
713  "Analysis_W011", JustWarning, description);
714  return false;
715  }
716 
717  column->fill(value);
718 #ifdef G4VERBOSE
719  if ( fState.GetVerboseL4() ) {
720  G4ExceptionDescription description;
721  description << " ntupleId " << ntupleId
722  << " columnId " << columnId << " value " << value;
723  fState.GetVerboseL4()->Message("fill", "ntuple F column", description);
724  }
725 #endif
726  return true;
727 }
728 
729 //_____________________________________________________________________________
731  G4double value)
732 {
733  tools::waxml::ntuple::column<double>* column
734  = GetNtupleDColumn(ntupleId, columnId);
735  if ( ! column ) {
736  G4ExceptionDescription description;
737  description << " " << " columnId " << columnId << " does not exist.";
738  G4Exception("G4XmlNtupleManager::FillNtupleDColumn()",
739  "Analysis_W011", JustWarning, description);
740  return false;
741  }
742 
743  column->fill(value);
744 #ifdef G4VERBOSE
745  if ( fState.GetVerboseL4() ) {
746  G4ExceptionDescription description;
747  description << " ntupleId " << ntupleId
748  << " columnId " << columnId << " value " << value;
749  fState.GetVerboseL4()->Message("fill", "ntuple D column", description);
750  }
751 #endif
752  return true;
753 }
754 
755 //_____________________________________________________________________________
757  const G4String& value)
758 {
759  tools::waxml::ntuple::column<std::string>* column
760  = GetNtupleSColumn(ntupleId, columnId);
761  if ( ! column ) {
762  G4ExceptionDescription description;
763  description << " " << " columnId " << columnId << " does not exist.";
764  G4Exception("G4XmlNtupleManager::FillNtupleSColumn()",
765  "Analysis_W011", JustWarning, description);
766  return false;
767  }
768 
769  column->fill(value);
770 #ifdef G4VERBOSE
771  if ( fState.GetVerboseL4() ) {
772  G4ExceptionDescription description;
773  description << " ntupleId " << ntupleId
774  << " columnId " << columnId << " value " << value;
775  fState.GetVerboseL4()->Message("fill", "ntuple S column", description);
776  }
777 #endif
778  return true;
779 }
780 
781 //_____________________________________________________________________________
783 {
784  return AddNtupleRow(fFirstId);
785 }
786 
787 //_____________________________________________________________________________
789 {
790 #ifdef G4VERBOSE
791  if ( fState.GetVerboseL4() ) {
792  G4ExceptionDescription description;
793  description << " ntupleId " << ntupleId;
794  fState.GetVerboseL4()->Message("add", "ntuple row", description);
795  }
796 #endif
797 
798  G4XmlNtupleDescription* ntupleDescription
799  = GetNtupleInFunction(ntupleId, "AddNtupleRow");
800  if ( ! ntupleDescription ) return false;
801 
802  if ( ! ntupleDescription->fNtuple ) {
803  G4ExceptionDescription description;
804  description << " " << "ntuple does not exist. ";
805  G4Exception("G4XmlNtupleManager::AddNtupleRow()",
806  "Analysis_W022", JustWarning, description);
807  return false;
808  }
809 
810  ntupleDescription->fNtuple->add_row();
811 #ifdef G4VERBOSE
812  if ( fState.GetVerboseL4() ) {
813  G4ExceptionDescription description;
814  description << " ntupleId " << ntupleId;
815  fState.GetVerboseL4()->Message("add", "ntuple row", description);
816  }
817 #endif
818 
819  return true;
820 }
821 
void Message(const G4String &action, const G4String &object, const G4String &objectName, G4bool success=true) const
virtual G4int CreateNtupleFColumn(const G4String &name, std::vector< float > *vector)
virtual G4int CreateNtupleDColumn(const G4String &name, std::vector< double > *vector)
std::map< G4int, tools::waxml::ntuple::column< int > * > fNtupleIColumnMap
std::ostringstream G4ExceptionDescription
Definition: globals.hh:76
std::map< G4int, tools::waxml::ntuple::column< double > * > fNtupleDColumnMap
std::map< G4int, tools::waxml::ntuple::column< float > * > fNtupleFColumnMap
virtual G4bool FillNtupleIColumn(G4int columnId, G4int value)
std::map< G4int, tools::waxml::ntuple::column< std::string > * > fNtupleSColumnMap
tools::waxml::ntuple * fNtuple
G4String name
Definition: TRTMaterials.hh:40
std::vector< tools::waxml::ntuple * > fNtupleVector
float G4float
Definition: G4Types.hh:77
tools::ntuple_booking * fNtupleBooking
virtual G4bool AddNtupleRow()
std::vector< G4XmlNtupleDescription * > fNtupleDescriptionVector
G4bool CreateNtupleFile(G4XmlNtupleDescription *ntupleDescription)
int G4int
Definition: G4Types.hh:78
virtual G4bool FillNtupleSColumn(G4int columnId, const G4String &value)
G4XmlFileManager * fFileManager
const G4AnalysisVerbose * GetVerboseL2() const
void LockNtupleDirectoryName()
G4String GetNtupleDirectoryName() const
const G4AnalysisVerbose * GetVerboseL3() const
const G4AnalysisVerbose * GetVerboseL4() const
bool G4bool
Definition: G4Types.hh:79
G4bool IsEmpty() const
virtual G4bool FillNtupleFColumn(G4int columnId, G4float value)
virtual void FinishNtuple()
virtual G4int CreateNtupleIColumn(const G4String &name, std::vector< int > *vector)
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
tools::waxml::ntuple::column< float > * GetNtupleFColumn(G4int ntupleId, G4int columnId) const
virtual G4bool FillNtupleDColumn(G4int columnId, G4double value)
virtual G4int CreateNtupleSColumn(const G4String &name)
G4String & append(const G4String &)
virtual G4XmlNtupleDescription * GetNtupleInFunction(G4int id, G4String function, G4bool warn=true, G4bool onlyIfActive=true) const
tools::waxml::ntuple::column< std::string > * GetNtupleSColumn(G4int ntupleId, G4int columnId) const
tools::waxml::ntuple * GetNtuple() const
G4bool fLockFirstNtupleColumnId
G4XmlNtupleManager(const G4AnalysisManagerState &state)
double G4double
Definition: G4Types.hh:76
tools::waxml::ntuple::column< int > * GetNtupleIColumn(G4int ntupleId, G4int columnId) const
G4String GetFileName() const
const G4int kInvalidId
virtual G4int CreateNtuple(const G4String &name, const G4String &title)
tools::waxml::ntuple::column< double > * GetNtupleDColumn(G4int ntupleId, G4int columnId) const
const G4AnalysisManagerState & fState
G4GLOB_DLL std::ostream G4cerr