33 #include "tools/waxml/begend"
34 #include "tools/waxml/histos"
43 if ( fgInstance == 0 ) {
63 <<
"G4CsvAnalysisManager already exists."
64 <<
"Cannot create another instance.";
65 G4Exception(
"G4CsvAnalysisManager::G4CsvAnalysisManager()",
76 delete fNtupleBooking;
87 tools::wcsv::ntuple::column<int>*
88 G4CsvAnalysisManager::GetNtupleIColumn(
G4int id)
const
90 std::map<G4int, tools::wcsv::ntuple::column<int>* >::const_iterator it
91 = fNtupleIColumnMap.find(
id);
92 if ( it == fNtupleIColumnMap.end() ) {
94 description <<
" " <<
"column " <<
id <<
" does not exist.";
95 G4Exception(
"G4CsvAnalysisManager::GetNtupleIColumn()",
104 tools::wcsv::ntuple::column<float>*
105 G4CsvAnalysisManager::GetNtupleFColumn(
G4int id)
const
107 std::map<G4int, tools::wcsv::ntuple::column<float>* >::const_iterator it
108 = fNtupleFColumnMap.find(
id);
109 if ( it == fNtupleFColumnMap.end() ) {
111 description <<
" " <<
"column " <<
id <<
" does not exist.";
112 G4Exception(
"G4CsvAnalysisManager::GetNtupleFColumn()",
122 tools::wcsv::ntuple::column<double>*
123 G4CsvAnalysisManager::GetNtupleDColumn(
G4int id)
const
125 std::map<G4int, tools::wcsv::ntuple::column<double>* >::const_iterator it
126 = fNtupleDColumnMap.find(
id);
127 if ( it == fNtupleDColumnMap.end() ) {
129 description <<
" " <<
"column " <<
id <<
" does not exist.";
130 G4Exception(
"G4CsvAnalysisManager::GetNtupleDColumn()",
139 G4bool G4CsvAnalysisManager::Reset()
148 void G4CsvAnalysisManager::ExceptionForHistograms(
151 G4String inFunction =
"G4CsvAnalysisManager::";
152 inFunction += functionName;
155 <<
"Histograms are not supported." ;
184 if ( name.find(
".") == std::string::npos ) {
195 if ( fFile )
delete fFile;
197 fFile =
new std::ofstream(name);
198 if ( fFile->fail() ) {
200 description <<
" " <<
"Cannot open file " << fileName;
207 if ( fNtupleBooking && ( ! fNtuple ) ) {
213 if ( fNtupleBooking->m_columns.size() ) {
215 const std::vector<tools::ntuple_booking::col_t>& columns
216 = fNtupleBooking->m_columns;
217 std::vector<tools::ntuple_booking::col_t>::const_iterator it;
219 for ( it = columns.begin(); it!=columns.end(); ++it) {
220 if ( (*it).second == tools::_cid(
int(0) ) ) {
221 G4cout <<
"adding int " << fNtuple->find_column<
int>((*it).first) <<
G4endl;
222 fNtupleIColumnMap[index++] = fNtuple->find_column<
int>((*it).first);
224 else if( (*it).second == tools::_cid(
float(0) ) ) {
225 fNtupleFColumnMap[index++] = fNtuple->find_column<
float>((*it).first);
227 else if((*it).second== tools::_cid(
double(0))) {
228 fNtupleDColumnMap[index++] = fNtuple->find_column<
double>((*it).first);
233 <<
"Unsupported column type " << (*it).first;
279 description <<
" " <<
"Resetting data failed";
305 ExceptionForHistograms(
"CreateH1");
321 ExceptionForHistograms(
"CreateH2");
332 ExceptionForHistograms(
"SetH1");
347 ExceptionForHistograms(
"SetH2");
354 ExceptionForHistograms(
"ScaleH1");
361 ExceptionForHistograms(
"ScaleH2");
369 if ( fNtupleBooking ) {
372 <<
"Ntuple already exists. "
373 <<
"(Only one ntuple is currently supported.)";
374 G4Exception(
"G4CsvAnalysisManager::CreateNtuple()",
385 fNtupleBooking =
new tools::ntuple_booking();
386 fNtupleBooking->m_name =
name;
387 fNtupleBooking->m_title =
title;
410 if ( ! fNtupleBooking ) {
413 <<
"Ntuple has to be created first. ";
414 G4Exception(
"G4CsvAnalysisManager::CreateNtupleIColumn()",
420 G4int index = fNtupleBooking->m_columns.size();
421 fNtupleBooking->add_column<
int>(
name);
425 tools::wcsv::ntuple::column<int>* column
426 = fNtuple->create_column<
int>(
name);
427 fNtupleIColumnMap[
index] = column;
448 if ( ! fNtupleBooking ) {
451 <<
"Ntuple has to be created first. ";
452 G4Exception(
"G4CsvAnalysisManager::CreateNtupleFColumn()",
458 G4int index = fNtupleBooking->m_columns.size();
459 fNtupleBooking->add_column<
float>(
name);
463 tools::wcsv::ntuple::column<float>* column
464 = fNtuple->create_column<
float>(
name);
465 fNtupleFColumnMap[
index] = column;
486 if ( ! fNtupleBooking ) {
489 <<
"Ntuple has to be created first. ";
490 G4Exception(
"G4CsvAnalysisManager::CreateNtupleDColumn()",
496 G4int index = fNtupleBooking->m_columns.size();
497 fNtupleBooking->add_column<
double>(
name);
501 tools::wcsv::ntuple::column<double>* column
502 = fNtuple->create_column<
double>(
name);
503 fNtupleDColumnMap[
index] = column;
529 <<
"Histograms are not supported." ;
542 <<
"Histograms are not supported." ;
551 tools::wcsv::ntuple::column<int>* column = GetNtupleIColumn(
id);
554 description <<
" " <<
"column " <<
id <<
" does not exist.";
555 G4Exception(
"G4CsvAnalysisManager::FillNtupleIColumn()",
564 description <<
" id " <<
id <<
" value " <<
value;
573 tools::wcsv::ntuple::column<float>* column = GetNtupleFColumn(
id);
576 description <<
" " <<
"column " <<
id <<
" does not exist.";
577 G4Exception(
"G4CsvAnalysisManager::FillNtupleFColumn()",
586 description <<
" id " <<
id <<
" value " <<
value;
596 tools::wcsv::ntuple::column<double>* column = GetNtupleDColumn(
id);
599 description <<
" " <<
"column " <<
id <<
" does not exist.";
600 G4Exception(
"G4CsvAnalysisManager::FillNtupleDColumn()",
609 description <<
" id " <<
id <<
" value " <<
value;
626 description <<
" " <<
"ntuple does not exist. ";
627 G4Exception(
"G4CsvAnalysisManager::AddNtupleRow()",
651 ExceptionForHistograms(
"GetH1Nbins");
658 ExceptionForHistograms(
"GetH1Xmin");
665 ExceptionForHistograms(
"GetH1Xmax");
672 ExceptionForHistograms(
"GetH1Xwidth");
679 ExceptionForHistograms(
"GetH2NXbins");
686 ExceptionForHistograms(
"GetH2Xmin");
693 ExceptionForHistograms(
"GetH2Xmin");
700 ExceptionForHistograms(
"GetH2XWidth");
707 ExceptionForHistograms(
"GetH2NYbins");
714 ExceptionForHistograms(
"GetH2Ymin");
721 ExceptionForHistograms(
"GetH2Ymax");
728 ExceptionForHistograms(
"GetH2YWidth");
736 ExceptionForHistograms(
"SetH1Title");
744 ExceptionForHistograms(
"SetH1XAxisTitle");
752 ExceptionForHistograms(
"SetH1YAxisTitle");
760 ExceptionForHistograms(
"SetH2Title");
768 ExceptionForHistograms(
"SetH2XAxisTitle");
776 ExceptionForHistograms(
"SetH2YAxisTitle");
784 ExceptionForHistograms(
"SetH2ZAxisTitle");
791 ExceptionForHistograms(
"GetH1XAxisTitle");
798 ExceptionForHistograms(
"GetH1Title");
805 ExceptionForHistograms(
"GetH1YAxisTitle");
813 ExceptionForHistograms(
"GetH2Title");
820 ExceptionForHistograms(
"GetH2XAxisTitle");
827 ExceptionForHistograms(
"GetH2YAxisTitle");
834 ExceptionForHistograms(
"GetH2ZAxisTitle");