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