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