45 fNtupleHbookIdOffset(-1),
51 ExG4HbookNtupleManager::~ExG4HbookNtupleManager()
55 std::vector<ExG4HbookNtupleDescription*>::iterator it;
56 for (it = fNtupleVector.begin(); it != fNtupleVector.end(); it++ ) {
66 void ExG4HbookNtupleManager::SetNtupleHbookIdOffset()
70 if ( fNtupleHbookIdOffset == -1 ) {
72 fNtupleHbookIdOffset = 0;
74 fNtupleHbookIdOffset = 1;
76 if ( fNtupleHbookIdOffset > 0 ) {
78 description <<
"Ntuple will be defined in HBOOK with ID = G4_firstNtupleId + 1";
79 G4Exception(
"ExG4HbookNtupleManager::SetNtupleHbookIdOffset()",
86 void ExG4HbookNtupleManager::CreateNtuplesFromBooking()
90 if ( ! fNtupleVector.size() )
return;
93 SetNtupleHbookIdOffset();
96 std::vector<ExG4HbookNtupleDescription*>::iterator itn;
97 for (itn = fNtupleVector.begin(); itn != fNtupleVector.end(); itn++ ) {
99 tools::ntuple_booking* ntupleBooking = (*itn)->fNtupleBooking;
100 if ( ! ntupleBooking )
continue;
103 if ( fState.GetVerboseL4() )
104 fState.GetVerboseL4()
105 ->Message(
"create from booking",
"ntuple", ntupleBooking->m_name);
109 fFileManager->CreateNtupleDirectory();
110 G4int hbookIndex = fNtupleHbookIdOffset + index + fFirstId;
115 =
new tools::hbook::wntuple(hbookIndex,
G4cout, *ntupleBooking);
116 if ( ntupleBooking->m_columns.size() ) {
118 const std::vector<tools::ntuple_booking::col_t>& columns
119 = ntupleBooking->m_columns;
120 std::vector<tools::ntuple_booking::col_t>::const_iterator it;
122 for ( it = columns.begin(); it!=columns.end(); ++it) {
123 if ( (*it).second == tools::_cid(
int(0) ) ) {
124 (*itn)->fNtupleIColumnMap[counter++]
125 = (*itn)->fNtuple->find_column<
int>((*it).first);
127 else if( (*it).second == tools::_cid(
float(0) ) ) {
128 (*itn)->fNtupleFColumnMap[counter++]
129 = (*itn)->fNtuple->find_column<
float>((*it).first);
131 else if((*it).second== tools::_cid(
double(0))) {
132 (*itn)->fNtupleDColumnMap[counter++]
133 = (*itn)->fNtuple->find_column<
double>((*it).first);
138 <<
"Unsupported column type " << (*it).first;
139 G4Exception(
"G4HbookAnalysisManager::CreateNtupleFromBooking()",
146 if ( fState.GetVerboseL3() )
147 fState.GetVerboseL3()
148 ->Message(
"create from booking",
"ntuple", ntupleBooking->m_name);
154 tools::hbook::wntuple::column<int>*
155 ExG4HbookNtupleManager::GetNtupleIColumn(
G4int ntupleId,
G4int columnId)
const
157 ExG4HbookNtupleDescription* ntupleDecription
158 = GetNtupleInFunction(ntupleId,
"GetNtupleIColumn");
159 if ( ! ntupleDecription )
return 0;
161 std::map<G4int, tools::hbook::wntuple::column<int>* >& ntupleIColumnMap
162 = ntupleDecription->fNtupleIColumnMap;
163 std::map<G4int, tools::hbook::wntuple::column<int>* >::const_iterator it
164 = ntupleIColumnMap.find(columnId);
165 if ( it == ntupleIColumnMap.end() ) {
167 description <<
" " <<
"ntupleId " << ntupleId
168 <<
"column " << columnId <<
" does not exist.";
169 G4Exception(
"G4HbookAnalysisManager::GetNtupleIColumn()",
178 tools::hbook::wntuple::column<float>*
179 ExG4HbookNtupleManager::GetNtupleFColumn(
G4int ntupleId,
G4int columnId)
const
181 ExG4HbookNtupleDescription* ntupleDecription
182 = GetNtupleInFunction(ntupleId,
"GetNtupleFColumn");
183 if ( ! ntupleDecription )
return 0;
185 std::map<G4int, tools::hbook::wntuple::column<float>* >& ntupleFColumnMap
186 = ntupleDecription->fNtupleFColumnMap;
187 std::map<G4int, tools::hbook::wntuple::column<float>* >::const_iterator it
188 = ntupleFColumnMap.find(columnId);
189 if ( it == ntupleFColumnMap.end() ) {
191 description <<
" " <<
"ntupleId " << ntupleId
192 <<
"column " << columnId <<
" does not exist.";
193 G4Exception(
"G4HbookAnalysisManager::GetNtupleFColumn()",
202 tools::hbook::wntuple::column<double>*
203 ExG4HbookNtupleManager::GetNtupleDColumn(
G4int ntupleId,
G4int columnId)
const
205 ExG4HbookNtupleDescription* ntupleDecription
206 = GetNtupleInFunction(ntupleId,
"GetNtupleDColumn");
207 if ( ! ntupleDecription )
return 0;
209 std::map<G4int, tools::hbook::wntuple::column<double>* >& ntupleDColumnMap
210 = ntupleDecription->fNtupleDColumnMap;
211 std::map<G4int, tools::hbook::wntuple::column<double>* >::const_iterator it
212 = ntupleDColumnMap.find(columnId);
213 if ( it == ntupleDColumnMap.end() ) {
215 description <<
" " <<
"ntupleId " << ntupleId
216 <<
"column " << columnId <<
" does not exist.";
217 G4Exception(
"G4HbookAnalysisManager::GetNtupleDColumn()",
226 void ExG4HbookNtupleManager::Reset()
230 std::vector<ExG4HbookNtupleDescription*>::iterator it3;
231 for (it3 = fNtupleVector.begin(); it3 != fNtupleVector.end(); it3++ ) {
232 delete (*it3)->fNtuple;
242 ExG4HbookNtupleDescription* ExG4HbookNtupleManager::GetNtupleInFunction(
247 G4int index =
id - fFirstId;
248 if ( index < 0 || index >=
G4int(fNtupleVector.size()) ) {
250 G4String inFunction =
"G4HbookAnalysisManager::";
251 inFunction += functionName;
253 description <<
" " <<
"ntuple " <<
id <<
" does not exist.";
259 return fNtupleVector[index];
271 if ( fFileManager->IsFile() )
272 fFileManager->CreateNtupleDirectory();
275 if ( fState.GetVerboseL4() )
276 fState.GetVerboseL4()->Message(
"create",
"ntuple", name);
280 G4int index = fNtupleVector.size();
281 ExG4HbookNtupleDescription* ntupleDescription
282 =
new ExG4HbookNtupleDescription();
283 fNtupleVector.push_back(ntupleDescription);
286 ntupleDescription->fNtupleBooking =
new tools::ntuple_booking();
287 ntupleDescription->fNtupleBooking->m_name =
name;
288 ntupleDescription->fNtupleBooking->m_title = title;
292 SetNtupleHbookIdOffset();
296 if ( fFileManager->IsFile() ) {
297 G4int hbookIndex = fNtupleHbookIdOffset + index + fFirstId;
298 ntupleDescription->fNtuple
299 =
new tools::hbook::wntuple(hbookIndex, name);
304 if ( fState.GetVerboseL2() ) {
306 description << name <<
" ntupleId " << index + fFirstId;
307 fState.GetVerboseL2()->Message(
"create",
"ntuple", description);
311 return index + fFirstId;
315 G4int ExG4HbookNtupleManager::CreateNtupleIColumn(
const G4String& name)
317 G4int ntupleId = fNtupleVector.size() + fFirstId - 1;
318 return CreateNtupleIColumn(ntupleId, name);
322 G4int ExG4HbookNtupleManager::CreateNtupleFColumn(
const G4String& name)
324 G4int ntupleId = fNtupleVector.size() + fFirstId - 1;
325 return CreateNtupleFColumn(ntupleId, name);
329 G4int ExG4HbookNtupleManager::CreateNtupleDColumn(
const G4String& name)
331 G4int ntupleId = fNtupleVector.size() + fFirstId - 1;
332 return CreateNtupleDColumn(ntupleId, name);
336 void ExG4HbookNtupleManager::FinishNtuple()
338 G4int ntupleId = fNtupleVector.size() + fFirstId - 1;
339 FinishNtuple(ntupleId);
343 G4int ExG4HbookNtupleManager::CreateNtupleIColumn(
G4int ntupleId,
347 if ( fState.GetVerboseL4() ) {
349 description << name <<
" ntupleId " << ntupleId;
350 fState.GetVerboseL4()->Message(
"create",
"ntuple I column", description);
354 ExG4HbookNtupleDescription* ntupleDescription
355 = GetNtupleInFunction(ntupleId,
"CreateNtupleIColumn");
356 tools::ntuple_booking* ntupleBooking
357 = ntupleDescription->fNtupleBooking;
359 if ( ! ntupleBooking ) {
362 <<
"Ntuple " << ntupleId <<
" has to be created first. ";
363 G4Exception(
"G4HbookAnalysisManager::CreateNtupleIColumn()",
369 G4int index = ntupleBooking->m_columns.size();
370 ntupleBooking->add_column<
int>(
name);
373 if ( ntupleDescription->fNtuple ) {
374 tools::hbook::wntuple::column<int>* column
375 = ntupleDescription->fNtuple->create_column<
int>(
name);
376 ntupleDescription->fNtupleIColumnMap[index] = column;
379 fLockFirstNtupleColumnId =
true;
382 if ( fState.GetVerboseL2() ) {
384 description << name <<
" ntupleId " << ntupleId;
385 fState.GetVerboseL2()->Message(
"create",
"ntuple I column", description);
389 return index + fFirstNtupleColumnId;
393 G4int ExG4HbookNtupleManager::CreateNtupleFColumn(
G4int ntupleId,
397 if ( fState.GetVerboseL4() ) {
399 description << name <<
" ntupleId " << ntupleId;
400 fState.GetVerboseL4()->Message(
"create",
"ntuple F column", description);
404 ExG4HbookNtupleDescription* ntupleDescription
405 = GetNtupleInFunction(ntupleId,
"CreateNtupleFColumn");
406 tools::ntuple_booking* ntupleBooking
407 = ntupleDescription->fNtupleBooking;
409 if ( ! ntupleBooking ) {
412 <<
"Ntuple " << ntupleId <<
" has to be created first. ";
413 G4Exception(
"G4HbookAnalysisManager::CreateNtupleFColumn()",
419 G4int index = ntupleBooking->m_columns.size();
420 ntupleBooking->add_column<
float>(
name);
423 if ( ntupleDescription->fNtuple ) {
424 tools::hbook::wntuple::column<float>* column
425 = ntupleDescription->fNtuple->create_column<
float>(
name);
426 ntupleDescription->fNtupleFColumnMap[index] = column;
429 fLockFirstNtupleColumnId =
true;
432 if ( fState.GetVerboseL2() ) {
434 description << name <<
" ntupleId " << ntupleId;
435 fState.GetVerboseL2()->Message(
"create",
"ntuple F column", description);
439 return index + fFirstNtupleColumnId;
444 G4int ExG4HbookNtupleManager::CreateNtupleDColumn(
G4int ntupleId,
448 if ( fState.GetVerboseL4() ) {
450 description << name <<
" ntupleId " << ntupleId;
451 fState.GetVerboseL4()->Message(
"create",
"ntuple D column", description);
455 ExG4HbookNtupleDescription* ntupleDescription
456 = GetNtupleInFunction(ntupleId,
"CreateNtupleDColumn");
457 tools::ntuple_booking* ntupleBooking
458 = ntupleDescription->fNtupleBooking;
460 if ( ! ntupleBooking ) {
463 <<
"Ntuple " << ntupleId <<
" has to be created first. ";
464 G4Exception(
"G4HbookAnalysisManager::CreateNtupleDColumn()",
470 G4int index = ntupleBooking->m_columns.size();
471 ntupleBooking->add_column<
double>(
name);
474 if ( ntupleDescription->fNtuple ) {
475 tools::hbook::wntuple::column<double>* column
476 = ntupleDescription->fNtuple->create_column<
double>(
name);
477 ntupleDescription->fNtupleDColumnMap[index] = column;
480 fLockFirstNtupleColumnId =
true;
483 if ( fState.GetVerboseL2() ) {
485 description << name <<
" ntupleId " << ntupleId;
486 fState.GetVerboseL2()->Message(
"create",
"ntuple D column", description);
490 return index + fFirstNtupleColumnId;
494 void ExG4HbookNtupleManager::FinishNtuple(
G4int ntupleId)
496 ExG4HbookNtupleDescription* ntupleDescription
497 = GetNtupleInFunction(ntupleId,
"CreateNtupleDColumn");
498 tools::hbook::wntuple* ntuple = ntupleDescription->fNtuple;
500 if ( ! ntuple )
return;
503 if ( fState.GetVerboseL4() )
504 fState.GetVerboseL4()
505 ->Message(
"finish",
"ntuple", ntupleDescription->fNtupleBooking->m_name);
509 tools::hbook::CHCDIR(
"//PAWC/LUN1",
" ");
513 if ( fState.GetVerboseL2() )
514 fState.GetVerboseL2()
515 ->Message(
"finish",
"ntuple", ntupleDescription->fNtupleBooking->m_name);
520 G4bool ExG4HbookNtupleManager::FillNtupleIColumn(
G4int columnId,
G4int value)
522 return FillNtupleIColumn(fFirstId, columnId, value);
528 return FillNtupleFColumn(fFirstId, columnId, value);
534 return FillNtupleDColumn(fFirstId, columnId, value);
538 G4bool ExG4HbookNtupleManager::AddNtupleRow()
540 return AddNtupleRow(fFirstId);
544 G4bool ExG4HbookNtupleManager::FillNtupleIColumn(
548 tools::hbook::wntuple::column<int>* column
549 = GetNtupleIColumn(ntupleId, columnId);
552 description <<
" " <<
"ntupleId " << ntupleId
553 <<
"column " << columnId <<
" does not exist.";
554 G4Exception(
"G4HbookAnalysisManager::FillNtupleIColumn()",
561 if ( fState.GetVerboseL4() ) {
563 description <<
" ntupleId " << ntupleId
564 <<
" columnId " << columnId <<
" value " << value;
565 fState.GetVerboseL4()->Message(
"fill",
"ntuple I column", description);
571 G4bool ExG4HbookNtupleManager::FillNtupleFColumn(
575 tools::hbook::wntuple::column<float>* column
576 = GetNtupleFColumn(ntupleId, columnId);
579 description <<
" " <<
"ntupleId " << ntupleId
580 <<
"column " << columnId <<
" does not exist.";
581 G4Exception(
"G4HbookAnalysisManager::FillNtupleFColumn()",
588 if ( fState.GetVerboseL4() ) {
590 description <<
" ntupleId " << ntupleId
591 <<
" columnId " << columnId <<
" value " << value;
592 fState.GetVerboseL4()->Message(
"fill",
"ntuple F column", description);
598 G4bool ExG4HbookNtupleManager::FillNtupleDColumn(
602 tools::hbook::wntuple::column<double>* column
603 = GetNtupleDColumn(ntupleId, columnId);
606 description <<
" " <<
"ntupleId " << ntupleId
607 <<
"column " << columnId <<
" does not exist.";
608 G4Exception(
"G4HbookAnalysisManager::FillNtupleDColumn()",
615 if ( fState.GetVerboseL4() ) {
617 description <<
" ntupleId " << ntupleId
618 <<
" columnId " << columnId <<
" value " << value;
619 fState.GetVerboseL4()->Message(
"fill",
"ntuple D column", description);
626 G4bool ExG4HbookNtupleManager::AddNtupleRow(
G4int ntupleId)
629 if ( fState.GetVerboseL4() ) {
631 description <<
" ntupleId " << ntupleId;
632 fState.GetVerboseL4()->Message(
"add",
"ntuple row", description);
636 ExG4HbookNtupleDescription* ntupleDescription
637 = GetNtupleInFunction(ntupleId,
"AddNtupleRow");
639 if ( ! ntupleDescription || ! ntupleDescription->fNtuple ) {
641 description <<
" " <<
" ntupleId " << ntupleId
642 <<
" does not exist. ";
643 G4Exception(
"G4HbookAnalysisManager::AddNtupleRow()",
648 ntupleDescription->fNtuple->add_row();
650 if ( fState.GetVerboseL4() ) {
652 description <<
" ntupleId " << ntupleId;
653 fState.GetVerboseL4()->Message(
"add",
"ntuple row", description,
true);
660 tools::hbook::wntuple* ExG4HbookNtupleManager::GetNtuple()
const
662 return GetNtuple(fFirstId);
666 tools::hbook::wntuple* ExG4HbookNtupleManager::GetNtuple(
G4int ntupleId)
const
668 ExG4HbookNtupleDescription* ntupleDescription
669 = GetNtupleInFunction(ntupleId,
"GetNtuple");
671 return ntupleDescription->fNtuple;
675 G4bool ExG4HbookNtupleManager::SetNtupleHbookIdOffset(
G4int offset)
677 if ( fNtupleVector.size() ) {
680 <<
"Cannot set NtupleHbookIdOffset as some ntuples already exist.";
681 G4Exception(
"G4HbookAnalysisManager::SetNtupleHbookIdOffset()",
686 if ( fFirstId + offset < 1 ) {
688 description <<
"The first ntuple HBOOK id must be >= 1.";
689 G4Exception(
"G4HbookAnalysisManager::SetNtupleHbookIdOffset()",
694 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.