48 fNtupleHbookIdOffset(-1),
49 fNtupleDescriptionVector(),
55 ExG4HbookNtupleManager::~ExG4HbookNtupleManager()
59 std::vector<ExG4HbookNtupleDescription*>::iterator it;
60 for (it = fNtupleDescriptionVector.begin(); it != fNtupleDescriptionVector.end(); it++ ) {
70 void ExG4HbookNtupleManager::SetNtupleHbookIdOffset()
74 if ( fNtupleHbookIdOffset == -1 ) {
76 fNtupleHbookIdOffset = 0;
78 fNtupleHbookIdOffset = 1;
80 if ( fNtupleHbookIdOffset > 0 ) {
82 description <<
"Ntuple will be defined in HBOOK with ID = G4_firstNtupleId + 1";
83 G4Exception(
"ExG4HbookNtupleManager::SetNtupleHbookIdOffset()",
90 void ExG4HbookNtupleManager::CreateNtuplesFromBooking()
94 if ( ! fNtupleDescriptionVector.size() )
return;
97 SetNtupleHbookIdOffset();
100 std::vector<ExG4HbookNtupleDescription*>::iterator itn;
101 for (itn = fNtupleDescriptionVector.begin(); itn != fNtupleDescriptionVector.end(); itn++ ) {
103 tools::ntuple_booking* ntupleBooking = (*itn)->fNtupleBooking;
104 if ( ! ntupleBooking )
continue;
107 if ( fState.GetVerboseL4() )
108 fState.GetVerboseL4()
109 ->Message(
"create from booking",
"ntuple", ntupleBooking->name());
113 fFileManager->CreateNtupleDirectory();
114 G4int hbookIndex = fNtupleHbookIdOffset + index + fFirstId;
119 =
new tools::hbook::wntuple(hbookIndex,
G4cout, *ntupleBooking);
120 fNtupleVector.push_back((*itn)->fNtuple);
122 if ( ntupleBooking->columns().size() ) {
124 const std::vector<tools::column_booking>& columns
125 = ntupleBooking->columns();
126 std::vector<tools::column_booking>::const_iterator it;
128 for ( it = columns.begin(); it!=columns.end(); ++it) {
129 if ( it->cls_id() == tools::_cid(
int(0) ) ) {
130 (*itn)->fNtupleIColumnMap[counter++]
131 = (*itn)->fNtuple->find_column<
int>(it->name());
133 else if( it->cls_id() == tools::_cid(
float(0) ) ) {
134 (*itn)->fNtupleFColumnMap[counter++]
135 = (*itn)->fNtuple->find_column<
float>(it->name());
137 else if(it->cls_id()== tools::_cid(
double(0))) {
138 (*itn)->fNtupleDColumnMap[counter++]
139 = (*itn)->fNtuple->find_column<
double>(it->name());
144 <<
"Unsupported column type " << it->name();
145 G4Exception(
"G4HbookAnalysisManager::CreateNtupleFromBooking()",
152 if ( fState.GetVerboseL3() )
153 fState.GetVerboseL3()
154 ->Message(
"create from booking",
"ntuple", ntupleBooking->name());
160 tools::hbook::wntuple::column<int>*
161 ExG4HbookNtupleManager::GetNtupleIColumn(
G4int ntupleId,
G4int columnId)
const
163 ExG4HbookNtupleDescription* ntupleDecription
164 = GetNtupleInFunction(ntupleId,
"GetNtupleIColumn");
165 if ( ! ntupleDecription )
return 0;
167 std::map<G4int, tools::hbook::wntuple::column<int>* >& ntupleIColumnMap
168 = ntupleDecription->fNtupleIColumnMap;
169 std::map<G4int, tools::hbook::wntuple::column<int>* >::const_iterator it
170 = ntupleIColumnMap.find(columnId);
171 if ( it == ntupleIColumnMap.end() ) {
173 description <<
" " <<
"ntupleId " << ntupleId
174 <<
"column " << columnId <<
" does not exist.";
175 G4Exception(
"G4HbookAnalysisManager::GetNtupleIColumn()",
184 tools::hbook::wntuple::column<float>*
185 ExG4HbookNtupleManager::GetNtupleFColumn(
G4int ntupleId,
G4int columnId)
const
187 ExG4HbookNtupleDescription* ntupleDecription
188 = GetNtupleInFunction(ntupleId,
"GetNtupleFColumn");
189 if ( ! ntupleDecription )
return 0;
191 std::map<G4int, tools::hbook::wntuple::column<float>* >& ntupleFColumnMap
192 = ntupleDecription->fNtupleFColumnMap;
193 std::map<G4int, tools::hbook::wntuple::column<float>* >::const_iterator it
194 = ntupleFColumnMap.find(columnId);
195 if ( it == ntupleFColumnMap.end() ) {
197 description <<
" " <<
"ntupleId " << ntupleId
198 <<
"column " << columnId <<
" does not exist.";
199 G4Exception(
"G4HbookAnalysisManager::GetNtupleFColumn()",
208 tools::hbook::wntuple::column<double>*
209 ExG4HbookNtupleManager::GetNtupleDColumn(
G4int ntupleId,
G4int columnId)
const
211 ExG4HbookNtupleDescription* ntupleDecription
212 = GetNtupleInFunction(ntupleId,
"GetNtupleDColumn");
213 if ( ! ntupleDecription )
return 0;
215 std::map<G4int, tools::hbook::wntuple::column<double>* >& ntupleDColumnMap
216 = ntupleDecription->fNtupleDColumnMap;
217 std::map<G4int, tools::hbook::wntuple::column<double>* >::const_iterator it
218 = ntupleDColumnMap.find(columnId);
219 if ( it == ntupleDColumnMap.end() ) {
221 description <<
" " <<
"ntupleId " << ntupleId
222 <<
"column " << columnId <<
" does not exist.";
223 G4Exception(
"G4HbookAnalysisManager::GetNtupleDColumn()",
232 void ExG4HbookNtupleManager::Reset()
236 std::vector<ExG4HbookNtupleDescription*>::iterator it3;
237 for (it3 = fNtupleDescriptionVector.begin(); it3 != fNtupleDescriptionVector.end(); it3++ ) {
238 delete (*it3)->fNtuple;
241 fNtupleVector.clear();
249 ExG4HbookNtupleDescription* ExG4HbookNtupleManager::GetNtupleInFunction(
254 G4int index =
id - fFirstId;
255 if ( index < 0 || index >=
G4int(fNtupleDescriptionVector.size()) ) {
257 G4String inFunction =
"G4HbookAnalysisManager::";
258 inFunction += functionName;
260 description <<
" " <<
"ntuple " <<
id <<
" does not exist.";
266 return fNtupleDescriptionVector[index];
278 if ( fFileManager->IsFile() )
279 fFileManager->CreateNtupleDirectory();
282 if ( fState.GetVerboseL4() )
283 fState.GetVerboseL4()->Message(
"create",
"ntuple", name);
287 G4int index = fNtupleDescriptionVector.size();
288 ExG4HbookNtupleDescription* ntupleDescription
289 =
new ExG4HbookNtupleDescription();
290 fNtupleDescriptionVector.push_back(ntupleDescription);
293 ntupleDescription->fNtupleBooking
294 =
new tools::ntuple_booking(name, title);
298 SetNtupleHbookIdOffset();
302 if ( fFileManager->IsFile() ) {
303 G4int hbookIndex = fNtupleHbookIdOffset + index + fFirstId;
304 ntupleDescription->fNtuple
305 =
new tools::hbook::wntuple(hbookIndex, name);
307 fNtupleVector.push_back(ntupleDescription->fNtuple);
311 if ( fState.GetVerboseL2() ) {
313 description << name <<
" ntupleId " << index + fFirstId;
314 fState.GetVerboseL2()->Message(
"create",
"ntuple", description);
318 return index + fFirstId;
322 G4int ExG4HbookNtupleManager::CreateNtupleIColumn(
const G4String& name,
323 std::vector<int>* vector)
325 G4int ntupleId = fNtupleDescriptionVector.size() + fFirstId - 1;
326 return CreateNtupleIColumn(ntupleId, name, vector);
330 G4int ExG4HbookNtupleManager::CreateNtupleFColumn(
const G4String& name,
331 std::vector<float>* vector)
333 G4int ntupleId = fNtupleDescriptionVector.size() + fFirstId - 1;
334 return CreateNtupleFColumn(ntupleId, name, vector);
338 G4int ExG4HbookNtupleManager::CreateNtupleDColumn(
const G4String& name,
339 std::vector<double>* vector)
341 G4int ntupleId = fNtupleDescriptionVector.size() + fFirstId - 1;
342 return CreateNtupleDColumn(ntupleId, name, vector);
346 G4int ExG4HbookNtupleManager::CreateNtupleSColumn(
const G4String& name)
348 G4int ntupleId = fNtupleDescriptionVector.size() + fFirstId - 1;
349 return CreateNtupleSColumn(ntupleId, name);
353 void ExG4HbookNtupleManager::FinishNtuple()
355 G4int ntupleId = fNtupleDescriptionVector.size() + fFirstId - 1;
356 FinishNtuple(ntupleId);
360 G4int ExG4HbookNtupleManager::CreateNtupleIColumn(
G4int ntupleId,
362 std::vector<int>* vector)
368 <<
"Vector columns are not supported in HBOOK.";
369 G4Exception(
"(ExG4HbookNtupleManager::CreateNtupleIColumn)",
375 if ( fState.GetVerboseL4() ) {
377 description << name <<
" ntupleId " << ntupleId;
378 fState.GetVerboseL4()->Message(
"create",
"ntuple I column", description);
382 ExG4HbookNtupleDescription* ntupleDescription
383 = GetNtupleInFunction(ntupleId,
"CreateNtupleIColumn");
384 tools::ntuple_booking* ntupleBooking
385 = ntupleDescription->fNtupleBooking;
387 if ( ! ntupleBooking ) {
390 <<
"Ntuple " << ntupleId <<
" has to be created first. ";
391 G4Exception(
"G4HbookAnalysisManager::CreateNtupleIColumn()",
397 G4int index = ntupleBooking->columns().size();
398 ntupleBooking->add_column<
int>(
name);
401 if ( ntupleDescription->fNtuple ) {
402 tools::hbook::wntuple::column<int>* column
403 = ntupleDescription->fNtuple->create_column<
int>(
name);
404 ntupleDescription->fNtupleIColumnMap[index] = column;
407 fLockFirstNtupleColumnId =
true;
410 if ( fState.GetVerboseL2() ) {
412 description << name <<
" ntupleId " << ntupleId;
413 fState.GetVerboseL2()->Message(
"create",
"ntuple I column", description);
417 return index + fFirstNtupleColumnId;
421 G4int ExG4HbookNtupleManager::CreateNtupleFColumn(
G4int ntupleId,
423 std::vector<float>* vector)
429 <<
"Vector columns are not supported in HBOOK.";
430 G4Exception(
"(ExG4HbookNtupleManager::CreateNtupleFColumn)",
436 if ( fState.GetVerboseL4() ) {
438 description << name <<
" ntupleId " << ntupleId;
439 fState.GetVerboseL4()->Message(
"create",
"ntuple F column", description);
443 ExG4HbookNtupleDescription* ntupleDescription
444 = GetNtupleInFunction(ntupleId,
"CreateNtupleFColumn");
445 tools::ntuple_booking* ntupleBooking
446 = ntupleDescription->fNtupleBooking;
448 if ( ! ntupleBooking ) {
451 <<
"Ntuple " << ntupleId <<
" has to be created first. ";
452 G4Exception(
"G4HbookAnalysisManager::CreateNtupleFColumn()",
458 G4int index = ntupleBooking->columns().size();
459 ntupleBooking->add_column<
float>(
name);
462 if ( ntupleDescription->fNtuple ) {
463 tools::hbook::wntuple::column<float>* column
464 = ntupleDescription->fNtuple->create_column<
float>(
name);
465 ntupleDescription->fNtupleFColumnMap[index] = column;
468 fLockFirstNtupleColumnId =
true;
471 if ( fState.GetVerboseL2() ) {
473 description << name <<
" ntupleId " << ntupleId;
474 fState.GetVerboseL2()->Message(
"create",
"ntuple F column", description);
478 return index + fFirstNtupleColumnId;
483 G4int ExG4HbookNtupleManager::CreateNtupleDColumn(
G4int ntupleId,
485 std::vector<double>* vector)
491 <<
"Vector columns are not supported in HBOOK.";
492 G4Exception(
"(ExG4HbookNtupleManager::CreateNtupleDColumn)",
498 if ( fState.GetVerboseL4() ) {
500 description << name <<
" ntupleId " << ntupleId;
501 fState.GetVerboseL4()->Message(
"create",
"ntuple D column", description);
505 ExG4HbookNtupleDescription* ntupleDescription
506 = GetNtupleInFunction(ntupleId,
"CreateNtupleDColumn");
507 tools::ntuple_booking* ntupleBooking
508 = ntupleDescription->fNtupleBooking;
510 if ( ! ntupleBooking ) {
513 <<
"Ntuple " << ntupleId <<
" has to be created first. ";
514 G4Exception(
"G4HbookAnalysisManager::CreateNtupleDColumn()",
520 G4int index = ntupleBooking->columns().size();
521 ntupleBooking->add_column<
double>(
name);
524 if ( ntupleDescription->fNtuple ) {
525 tools::hbook::wntuple::column<double>* column
526 = ntupleDescription->fNtuple->create_column<
double>(
name);
527 ntupleDescription->fNtupleDColumnMap[index] = column;
530 fLockFirstNtupleColumnId =
true;
533 if ( fState.GetVerboseL2() ) {
535 description << name <<
" ntupleId " << ntupleId;
536 fState.GetVerboseL2()->Message(
"create",
"ntuple D column", description);
540 return index + fFirstNtupleColumnId;
544 G4int ExG4HbookNtupleManager::CreateNtupleSColumn(
G4int ,
549 <<
"Columns of string type are not supported in HBOOK.";
550 G4Exception(
"(ExG4HbookNtupleManager::CreateNtupleDColumn)",
556 void ExG4HbookNtupleManager::FinishNtuple(
G4int ntupleId)
558 ExG4HbookNtupleDescription* ntupleDescription
559 = GetNtupleInFunction(ntupleId,
"CreateNtupleDColumn");
560 tools::hbook::wntuple* ntuple = ntupleDescription->fNtuple;
562 if ( ! ntuple )
return;
565 if ( fState.GetVerboseL4() )
566 fState.GetVerboseL4()
567 ->Message(
"finish",
"ntuple", ntupleDescription->fNtupleBooking->name());
571 tools::hbook::CHCDIR(
"//PAWC/LUN1",
" ");
575 if ( fState.GetVerboseL2() )
576 fState.GetVerboseL2()
577 ->Message(
"finish",
"ntuple", ntupleDescription->fNtupleBooking->name());
582 G4bool ExG4HbookNtupleManager::FillNtupleIColumn(
G4int columnId,
G4int value)
584 return FillNtupleIColumn(fFirstId, columnId, value);
590 return FillNtupleFColumn(fFirstId, columnId, value);
596 return FillNtupleDColumn(fFirstId, columnId, value);
600 G4bool ExG4HbookNtupleManager::FillNtupleSColumn(
G4int columnId,
603 return FillNtupleSColumn(fFirstId, columnId, value);
607 G4bool ExG4HbookNtupleManager::AddNtupleRow()
609 return AddNtupleRow(fFirstId);
613 G4bool ExG4HbookNtupleManager::FillNtupleIColumn(
617 tools::hbook::wntuple::column<int>* column
618 = GetNtupleIColumn(ntupleId, columnId);
621 description <<
" " <<
"ntupleId " << ntupleId
622 <<
"column " << columnId <<
" does not exist.";
623 G4Exception(
"G4HbookAnalysisManager::FillNtupleIColumn()",
630 if ( fState.GetVerboseL4() ) {
632 description <<
" ntupleId " << ntupleId
633 <<
" columnId " << columnId <<
" value " << value;
634 fState.GetVerboseL4()->Message(
"fill",
"ntuple I column", description);
640 G4bool ExG4HbookNtupleManager::FillNtupleFColumn(
644 tools::hbook::wntuple::column<float>* column
645 = GetNtupleFColumn(ntupleId, columnId);
648 description <<
" " <<
"ntupleId " << ntupleId
649 <<
"column " << columnId <<
" does not exist.";
650 G4Exception(
"G4HbookAnalysisManager::FillNtupleFColumn()",
657 if ( fState.GetVerboseL4() ) {
659 description <<
" ntupleId " << ntupleId
660 <<
" columnId " << columnId <<
" value " << value;
661 fState.GetVerboseL4()->Message(
"fill",
"ntuple F column", description);
667 G4bool ExG4HbookNtupleManager::FillNtupleDColumn(
671 tools::hbook::wntuple::column<double>* column
672 = GetNtupleDColumn(ntupleId, columnId);
675 description <<
" " <<
"ntupleId " << ntupleId
676 <<
"column " << columnId <<
" does not exist.";
677 G4Exception(
"G4HbookAnalysisManager::FillNtupleDColumn()",
684 if ( fState.GetVerboseL4() ) {
686 description <<
" ntupleId " << ntupleId
687 <<
" columnId " << columnId <<
" value " << value;
688 fState.GetVerboseL4()->Message(
"fill",
"ntuple D column", description);
695 G4bool ExG4HbookNtupleManager::FillNtupleSColumn(
701 <<
"Columns of string type are not supported in HBOOK.";
702 G4Exception(
"(ExG4HbookNtupleManager::FillNtupleSColumn)",
708 G4bool ExG4HbookNtupleManager::AddNtupleRow(
G4int ntupleId)
711 if ( fState.GetVerboseL4() ) {
713 description <<
" ntupleId " << ntupleId;
714 fState.GetVerboseL4()->Message(
"add",
"ntuple row", description);
718 ExG4HbookNtupleDescription* ntupleDescription
719 = GetNtupleInFunction(ntupleId,
"AddNtupleRow");
721 if ( ! ntupleDescription || ! ntupleDescription->fNtuple ) {
723 description <<
" " <<
" ntupleId " << ntupleId
724 <<
" does not exist. ";
725 G4Exception(
"G4HbookAnalysisManager::AddNtupleRow()",
730 ntupleDescription->fNtuple->add_row();
732 if ( fState.GetVerboseL4() ) {
734 description <<
" ntupleId " << ntupleId;
735 fState.GetVerboseL4()->Message(
"add",
"ntuple row", description,
true);
742 tools::hbook::wntuple* ExG4HbookNtupleManager::GetNtuple()
const
744 return GetNtuple(fFirstId);
748 tools::hbook::wntuple* ExG4HbookNtupleManager::GetNtuple(
G4int ntupleId)
const
750 ExG4HbookNtupleDescription* ntupleDescription
751 = GetNtupleInFunction(ntupleId,
"GetNtuple");
753 return ntupleDescription->fNtuple;
757 G4bool ExG4HbookNtupleManager::SetNtupleHbookIdOffset(
G4int offset)
759 if ( fNtupleDescriptionVector.size() ) {
762 <<
"Cannot set NtupleHbookIdOffset as some ntuples already exist.";
763 G4Exception(
"G4HbookAnalysisManager::SetNtupleHbookIdOffset()",
768 if ( fFirstId + offset < 1 ) {
770 description <<
"The first ntuple HBOOK id must be >= 1.";
771 G4Exception(
"G4HbookAnalysisManager::SetNtupleHbookIdOffset()",
776 fNtupleHbookIdOffset = offset;
std::ostringstream G4ExceptionDescription
G4GLOB_DLL std::ostream G4cout
Definition of the ExG4HbookNtupleManager class.
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition of the ExG4HbookFileManager class.