Geant4  10.01.p02
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  // Do not create ntuples on master thread
194  fState.GetIsMaster() ) {
195  G4cout << "Do not create ntuples on master thread" << G4endl;
196  return;
197  }
198 
199  G4int ntupleId = fFirstId;
200  std::vector<G4XmlNtupleDescription*>::iterator itn;
201  for (itn = fNtupleDescriptionVector.begin(); itn != fNtupleDescriptionVector.end(); itn++ ) {
202 
203  tools::ntuple_booking* ntupleBooking = (*itn)->fNtupleBooking;
204  if ( ! ntupleBooking ) continue;
205 
206 // Create ntuple from ntuple_booking.
207 #ifdef G4VERBOSE
208  if ( fState.GetVerboseL4() )
210  ->Message("create from booking", "ntuple", ntupleBooking->name());
211 #endif
212 
213  // create a file for this ntuple
214  if ( ! fFileManager->CreateNtupleFile((*itn)) ) continue;
215 
216  // create ntuple
217  (*itn)->fNtuple
218  = new tools::waxml::ntuple(*((*itn)->fFile), G4cerr, *ntupleBooking);
219  fNtupleVector.push_back((*itn)->fNtuple);
220 
221  if ( ntupleBooking->columns().size() ) {
222  // store ntuple columns in local maps
223  const std::vector<tools::column_booking>& columns
224  = ntupleBooking->columns();
225  std::vector<tools::column_booking>::const_iterator it;
226  G4int index = 0;
227  for ( it = columns.begin(); it!=columns.end(); ++it) {
228  if ( it->cls_id() == tools::_cid(int(0) ) ) {
229  (*itn)->fNtupleIColumnMap[index++]
230  = (*itn)->fNtuple->find_column<int>(it->name());
231  }
232  else if( it->cls_id() == tools::_cid(float(0) ) ) {
233  (*itn)->fNtupleFColumnMap[index++]
234  = (*itn)->fNtuple->find_column<float>(it->name());
235  }
236  else if(it->cls_id()== tools::_cid(double(0))) {
237  (*itn)->fNtupleDColumnMap[index++]
238  = (*itn)->fNtuple->find_column<double>(it->name());
239  }
240  else if(it->cls_id()== tools::_cid(std::string(""))) {
241  (*itn)->fNtupleSColumnMap[index++]
242  = (*itn)->fNtuple->find_column<std::string>(it->name());
243  }
244  else {
245  G4ExceptionDescription description;
246  description << " "
247  << "Unsupported column type " << it->name();
248  G4Exception("G4XmlNtupleManager::CreateNtuplesFromBooking()",
249  "Analysis_W002", JustWarning, description);
250  }
251  }
252  }
253  FinishNtuple(ntupleId++);
254 #ifdef G4VERBOSE
255  if ( fState.GetVerboseL3() )
257  ->Message("create from booking", "ntuple", ntupleBooking->name());
258 #endif
259  }
260 }
261 
262 //_____________________________________________________________________________
264 {
265  return ! fNtupleDescriptionVector.size();
266 }
267 
268 //_____________________________________________________________________________
270 {
271 // Reset ntuples
272 
273  std::vector<G4XmlNtupleDescription*>::iterator it;
274  for (it = fNtupleDescriptionVector.begin(); it != fNtupleDescriptionVector.end(); it++ ) {
275  delete (*it)->fNtuple;
276  (*it)->fNtuple = 0;
277  }
278  fNtupleVector.clear();
279 
280  return true;
281 }
282 
283 //_____________________________________________________________________________
284 tools::waxml::ntuple* G4XmlNtupleManager::GetNtuple() const
285 {
286  return GetNtuple(fFirstId);
287 }
288 
289 //_____________________________________________________________________________
290 tools::waxml::ntuple* G4XmlNtupleManager::GetNtuple(G4int ntupleId) const
291 {
292  G4XmlNtupleDescription* ntupleDescription
293  = GetNtupleInFunction(ntupleId, "GetNtuple");
294 
295  if ( ! ntupleDescription ) return 0;
296 
297  return ntupleDescription->fNtuple;
298 }
299 
300 //_____________________________________________________________________________
302  const G4String& title)
303 {
304 #ifdef G4VERBOSE
305  if ( fState.GetVerboseL4() )
306  fState.GetVerboseL4()->Message("create", "ntuple", name);
307 #endif
308 
309  // Create ntuple description
310  G4int index = fNtupleDescriptionVector.size();
311  G4XmlNtupleDescription* ntupleDescription
312  = new G4XmlNtupleDescription();
313  fNtupleDescriptionVector.push_back(ntupleDescription);
314 
315  // Create ntuple booking
316  ntupleDescription->fNtupleBooking
317  = new tools::ntuple_booking(name, title);
318 
319  // Create ntuple if the file is open (what means here that
320  // a filename was already set)
321  if ( fFileManager->GetFileName().size() ) {
322  if ( fFileManager->CreateNtupleFile(ntupleDescription) ) {
323  ntupleDescription->fNtuple
324  = new tools::waxml::ntuple(*(ntupleDescription->fFile));
325  // ntuple object is deleted when closing a file
326  fNtupleVector.push_back(ntupleDescription->fNtuple);
327  }
328  }
329 
330  fLockFirstId = true;
331 
332 #ifdef G4VERBOSE
333  if ( fState.GetVerboseL2() ) {
334  G4ExceptionDescription description;
335  description << name << " ntupleId " << index + fFirstId;
336  fState.GetVerboseL2()->Message("create", "ntuple", description);
337  }
338 #endif
339 
340  return index + fFirstId;
341 }
342 
343 //_____________________________________________________________________________
345  std::vector<int>* vector)
346 {
347  G4int ntupleId = fNtupleDescriptionVector.size() + fFirstId - 1;
348  return CreateNtupleIColumn(ntupleId, name, vector);
349 }
350 
351 //_____________________________________________________________________________
353  std::vector<float>* vector)
354 {
355  G4int ntupleId = fNtupleDescriptionVector.size() + fFirstId - 1;
356  return CreateNtupleFColumn(ntupleId, name, vector);
357 }
358 
359 //_____________________________________________________________________________
361  std::vector<double>* vector)
362 {
363  G4int ntupleId = fNtupleDescriptionVector.size() + fFirstId - 1;
364  return CreateNtupleDColumn(ntupleId, name, vector);
365 }
366 
367 //_____________________________________________________________________________
369 {
370  G4int ntupleId = fNtupleDescriptionVector.size() + fFirstId - 1;
371  return CreateNtupleSColumn(ntupleId, name);
372 }
373 
374 //_____________________________________________________________________________
376 {
377  G4int ntupleId = fNtupleDescriptionVector.size() + fFirstId - 1;
378  FinishNtuple(ntupleId);
379 }
380 
381 //_____________________________________________________________________________
383  const G4String& name,
384  std::vector<int>* vector)
385 {
386 #ifdef G4VERBOSE
387  if ( fState.GetVerboseL4() ) {
388  G4ExceptionDescription description;
389  description << name << " ntupleId " << ntupleId;
390  fState.GetVerboseL4()->Message("create", "ntuple I column", description);
391  }
392  #endif
393 
394  G4XmlNtupleDescription* ntupleDescription
395  = GetNtupleInFunction(ntupleId, "CreateNtupleIColumn");
396  if ( ! ntupleDescription ) return kInvalidId;
397 
398  tools::ntuple_booking* ntupleBooking
399  = ntupleDescription->fNtupleBooking;
400 
401  if ( ! ntupleBooking ) {
402  G4ExceptionDescription description;
403  description << " "
404  << "Ntuple " << ntupleId << " has to be created first. ";
405  G4Exception("G4XmlNtupleManager::CreateNtupleIColumn()",
406  "Analysis_W002", JustWarning, description);
407  return kInvalidId;
408  }
409 
410  // Save column info in booking
411  G4int index = ntupleBooking->columns().size();
412  if ( ! vector )
413  ntupleBooking->add_column<int>(name);
414  else
415  ntupleBooking->add_column<int>(name, *vector);
416 
417  // Create column if ntuple already exists
418  if ( ntupleDescription->fNtuple ) {
419  if ( ! vector ) {
420  tools::waxml::ntuple::column<int>* column
421  = ntupleDescription->fNtuple->create_column<int>(name);
422  ntupleDescription->fNtupleIColumnMap[index] = column;
423  }
424  else {
425  ntupleDescription->fNtuple->create_column<int>(name, *vector);
426  }
427  }
428 
430 
431 #ifdef G4VERBOSE
432  if ( fState.GetVerboseL2() ) {
433  G4ExceptionDescription description;
434  description << name << " ntupleId " << ntupleId;
435  fState.GetVerboseL2()->Message("create", "ntuple I column", description);
436  }
437 #endif
438 
439  return index + fFirstNtupleColumnId;
440 }
441 
442 //_____________________________________________________________________________
444  const G4String& name,
445  std::vector<float>* vector)
446 {
447 #ifdef G4VERBOSE
448  if ( fState.GetVerboseL4() ) {
449  G4ExceptionDescription description;
450  description << name << " ntupleId " << ntupleId;
451  fState.GetVerboseL4()->Message("create", "ntuple F column", description);
452  }
453 #endif
454 
455  G4XmlNtupleDescription* ntupleDescription
456  = GetNtupleInFunction(ntupleId, "CreateNtupleFColumn");
457  if ( ! ntupleDescription ) return kInvalidId;
458 
459  tools::ntuple_booking* ntupleBooking
460  = ntupleDescription->fNtupleBooking;
461 
462  if ( ! ntupleBooking ) {
463  G4ExceptionDescription description;
464  description << " "
465  << "Ntuple " << ntupleId << " has to be created first. ";
466  G4Exception("G4XmlNtupleManager::CreateNtupleFColumn()",
467  "Analysis_W002", JustWarning, description);
468  return kInvalidId;
469  }
470 
471  // Save column info in booking
472  G4int index = ntupleBooking->columns().size();
473  if ( ! vector )
474  ntupleBooking->add_column<float>(name);
475  else
476  ntupleBooking->add_column<float>(name, *vector);
477 
478  // Create column if ntuple already exists
479  if ( ntupleDescription->fNtuple ) {
480  if ( ! vector ) {
481  tools::waxml::ntuple::column<float>* column
482  = ntupleDescription->fNtuple->create_column<float>(name);
483  ntupleDescription->fNtupleFColumnMap[index] = column;
484  }
485  else {
486  ntupleDescription->fNtuple->create_column<float>(name, *vector);
487  }
488  }
489 
491 
492 #ifdef G4VERBOSE
493  if ( fState.GetVerboseL2() ) {
494  G4ExceptionDescription description;
495  description << name << " ntupleId " << ntupleId;
496  fState.GetVerboseL2()->Message("create", "ntuple F column", description);
497  }
498 #endif
499 
500  return index + fFirstNtupleColumnId;
501 }
502 
503 //_____________________________________________________________________________
505  const G4String& name,
506  std::vector<double>* vector)
507 {
508 #ifdef G4VERBOSE
509  if ( fState.GetVerboseL4() ) {
510  G4ExceptionDescription description;
511  description << name << " ntupleId " << ntupleId;
512  fState.GetVerboseL4()->Message("create", "ntuple D column", description);
513  }
514 #endif
515 
516  G4XmlNtupleDescription* ntupleDescription
517  = GetNtupleInFunction(ntupleId, "CreateNtupleDColumn");
518  if ( ! ntupleDescription ) return kInvalidId;
519 
520  tools::ntuple_booking* ntupleBooking
521  = ntupleDescription->fNtupleBooking;
522 
523  if ( ! ntupleBooking ) {
524  G4ExceptionDescription description;
525  description << " "
526  << "Ntuple " << ntupleId << " has to be created first. ";
527  G4Exception("G4XmlNtupleManager::CreateNtupleDColumn()",
528  "Analysis_W002", JustWarning, description);
529  return kInvalidId;
530  }
531 
532  // Save column info in booking
533  G4int index = ntupleBooking->columns().size();
534  if ( ! vector )
535  ntupleBooking->add_column<double>(name);
536  else
537  ntupleBooking->add_column<double>(name, *vector);
538 
539  // Create column if ntuple already exists
540  if ( ntupleDescription->fNtuple ) {
541  if ( ! vector ) {
542  tools::waxml::ntuple::column<double>* column
543  = ntupleDescription->fNtuple->create_column<double>(name);
544  ntupleDescription->fNtupleDColumnMap[index] = column;
545  }
546  else {
547  ntupleDescription->fNtuple->create_column<double>(name, *vector);
548  }
549  }
550 
552 
553 #ifdef G4VERBOSE
554  if ( fState.GetVerboseL2() ) {
555  G4ExceptionDescription description;
556  description << name << " ntupleId " << ntupleId;
557  fState.GetVerboseL2()->Message("create", "ntuple D column", description);
558  }
559  #endif
560 
561  return index + fFirstNtupleColumnId;
562 }
563 
564 //_____________________________________________________________________________
566  const G4String& name)
567 {
568 #ifdef G4VERBOSE
569  if ( fState.GetVerboseL4() ) {
570  G4ExceptionDescription description;
571  description << name << " ntupleId " << ntupleId;
572  fState.GetVerboseL4()->Message("create", "ntuple S column", description);
573  }
574 #endif
575 
576  G4XmlNtupleDescription* ntupleDescription
577  = GetNtupleInFunction(ntupleId, "CreateNtupleSColumn");
578  if ( ! ntupleDescription ) return kInvalidId;
579 
580  tools::ntuple_booking* ntupleBooking
581  = ntupleDescription->fNtupleBooking;
582 
583  if ( ! ntupleBooking ) {
584  G4ExceptionDescription description;
585  description << " "
586  << "Ntuple " << ntupleId << " has to be created first. ";
587  G4Exception("G4XmlNtupleManager::CreateNtupleSColumn()",
588  "Analysis_W002", JustWarning, description);
589  return kInvalidId;
590  }
591 
592  // Save column info in booking
593  G4int index = ntupleBooking->columns().size();
594  ntupleBooking->add_column<std::string>(name);
595 
596  // Create column if ntuple already exists
597  if ( ntupleDescription->fNtuple ) {
598  tools::waxml::ntuple::column<std::string>* column
599  = ntupleDescription->fNtuple->create_column<std::string>(name);
600  ntupleDescription->fNtupleSColumnMap[index] = column;
601  }
602 
604 
605 #ifdef G4VERBOSE
606  if ( fState.GetVerboseL2() ) {
607  G4ExceptionDescription description;
608  description << name << " ntupleId " << ntupleId;
609  fState.GetVerboseL2()->Message("create", "ntuple S column", description);
610  }
611  #endif
612 
613  return index + fFirstNtupleColumnId;
614 }
615 
616 //_____________________________________________________________________________
618 {
619  G4XmlNtupleDescription* ntupleDescription
620  = GetNtupleInFunction(ntupleId, "FinishNtuple");
621  tools::ntuple_booking* ntupleBooking = 0;
622  if ( ntupleDescription ) {
623  ntupleBooking = ntupleDescription->fNtupleBooking;
624  }
625 
626  if ( ( ! ntupleDescription ) || ( ! ntupleBooking ) ) {
627  G4ExceptionDescription description;
628  description << " "
629  << "Ntuple " << ntupleId << " has to be created first. ";
630  G4Exception("G4XmlNtupleManager::CreateNtupleDColumn()",
631  "Analysis_W002", JustWarning, description);
632  return;
633  }
634 
635 #ifdef G4VERBOSE
636  if ( fState.GetVerboseL4() ) {
637  G4ExceptionDescription description;
638  description << ntupleBooking->name() << " ntupleId " << ntupleId;
639  fState.GetVerboseL4()->Message("finish", "ntuple", description);
640  }
641 #endif
642 
643  // Finish ntuple if ntuple already exists
644  if ( ntupleDescription->fNtuple ) {
645  G4String path = "/";
647  ntupleDescription->fNtuple
648  ->write_header(path, ntupleBooking->name(), ntupleBooking->title());
650  }
651 
652 #ifdef G4VERBOSE
653  if ( fState.GetVerboseL2() ) {
654  G4ExceptionDescription description;
655  description << ntupleBooking->name() << " ntupleId " << ntupleId;
656  fState.GetVerboseL2()->Message("finish", "ntuple", description);
657  }
658 #endif
659 }
660 
661 //_____________________________________________________________________________
663 {
664  return FillNtupleIColumn(fFirstId, columnId, value);
665 }
666 
667 //_____________________________________________________________________________
669 {
670  return FillNtupleFColumn(fFirstId, columnId, value);
671 }
672 
673 //_____________________________________________________________________________
675 {
676  return FillNtupleDColumn(fFirstId, columnId, value);
677 }
678 
679 //_____________________________________________________________________________
681 {
682  return FillNtupleSColumn(fFirstId, columnId, value);
683 }
684 
685 //_____________________________________________________________________________
687  G4int value)
688 {
689  tools::waxml::ntuple::column<int>* column
690  = GetNtupleIColumn(ntupleId, columnId);
691  if ( ! column ) {
692  G4ExceptionDescription description;
693  description << " " << " columnId " << columnId << " does not exist.";
694  G4Exception("G4XmlNtupleManager::FillNtupleIColumn()",
695  "Analysis_W011", JustWarning, description);
696  return false;
697  }
698 
699  column->fill(value);
700 #ifdef G4VERBOSE
701  if ( fState.GetVerboseL4() ) {
702  G4ExceptionDescription description;
703  description << " ntupleId " << ntupleId
704  << " columnId " << columnId << " value " << value;
705  fState.GetVerboseL4()->Message("fill", "ntuple I column", description);
706  }
707 #endif
708  return true;
709 }
710 //_____________________________________________________________________________
712  G4float value)
713 {
714  tools::waxml::ntuple::column<float>* column
715  = GetNtupleFColumn(ntupleId, columnId);
716  if ( ! column ) {
717  G4ExceptionDescription description;
718  description << " " << " columnId " << columnId << " does not exist.";
719  G4Exception("G4XmlNtupleManager::FillNtupleFColumn()",
720  "Analysis_W011", JustWarning, description);
721  return false;
722  }
723 
724  column->fill(value);
725 #ifdef G4VERBOSE
726  if ( fState.GetVerboseL4() ) {
727  G4ExceptionDescription description;
728  description << " ntupleId " << ntupleId
729  << " columnId " << columnId << " value " << value;
730  fState.GetVerboseL4()->Message("fill", "ntuple F column", description);
731  }
732 #endif
733  return true;
734 }
735 
736 //_____________________________________________________________________________
738  G4double value)
739 {
740  tools::waxml::ntuple::column<double>* column
741  = GetNtupleDColumn(ntupleId, columnId);
742  if ( ! column ) {
743  G4ExceptionDescription description;
744  description << " " << " columnId " << columnId << " does not exist.";
745  G4Exception("G4XmlNtupleManager::FillNtupleDColumn()",
746  "Analysis_W011", JustWarning, description);
747  return false;
748  }
749 
750  column->fill(value);
751 #ifdef G4VERBOSE
752  if ( fState.GetVerboseL4() ) {
753  G4ExceptionDescription description;
754  description << " ntupleId " << ntupleId
755  << " columnId " << columnId << " value " << value;
756  fState.GetVerboseL4()->Message("fill", "ntuple D column", description);
757  }
758 #endif
759  return true;
760 }
761 
762 //_____________________________________________________________________________
764  const G4String& value)
765 {
766  tools::waxml::ntuple::column<std::string>* column
767  = GetNtupleSColumn(ntupleId, columnId);
768  if ( ! column ) {
769  G4ExceptionDescription description;
770  description << " " << " columnId " << columnId << " does not exist.";
771  G4Exception("G4XmlNtupleManager::FillNtupleSColumn()",
772  "Analysis_W011", JustWarning, description);
773  return false;
774  }
775 
776  column->fill(value);
777 #ifdef G4VERBOSE
778  if ( fState.GetVerboseL4() ) {
779  G4ExceptionDescription description;
780  description << " ntupleId " << ntupleId
781  << " columnId " << columnId << " value " << value;
782  fState.GetVerboseL4()->Message("fill", "ntuple S column", description);
783  }
784 #endif
785  return true;
786 }
787 
788 //_____________________________________________________________________________
790 {
791  return AddNtupleRow(fFirstId);
792 }
793 
794 //_____________________________________________________________________________
796 {
797 #ifdef G4VERBOSE
798  if ( fState.GetVerboseL4() ) {
799  G4ExceptionDescription description;
800  description << " ntupleId " << ntupleId;
801  fState.GetVerboseL4()->Message("add", "ntuple row", description);
802  }
803 #endif
804 
805  G4XmlNtupleDescription* ntupleDescription
806  = GetNtupleInFunction(ntupleId, "AddNtupleRow");
807  if ( ! ntupleDescription ) return false;
808 
809  if ( ! ntupleDescription->fNtuple ) {
810  G4ExceptionDescription description;
811  description << " " << "ntuple does not exist. ";
812  G4Exception("G4XmlNtupleManager::AddNtupleRow()",
813  "Analysis_W022", JustWarning, description);
814  return false;
815  }
816 
817  ntupleDescription->fNtuple->add_row();
818 #ifdef G4VERBOSE
819  if ( fState.GetVerboseL4() ) {
820  G4ExceptionDescription description;
821  description << " ntupleId " << ntupleId;
822  fState.GetVerboseL4()->Message("add", "ntuple row", description);
823  }
824 #endif
825 
826  return true;
827 }
828 
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
G4GLOB_DLL std::ostream G4cout
const G4AnalysisVerbose * GetVerboseL4() const
bool G4bool
Definition: G4Types.hh:79
G4bool IsEmpty() const
virtual G4bool FillNtupleFColumn(G4int columnId, G4float value)
virtual void FinishNtuple()
G4bool IsMultithreadedApplication()
Definition: G4Threading.cc:134
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
#define G4endl
Definition: G4ios.hh:61
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