Geant4  10.01.p02
ExG4HbookNtupleManager.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$
27 //
30 
31 // Author: Ivana Hrivnacova, 15/06/2011 (ivana@ipno.in2p3.fr)
32 
33 #ifdef G4_USE_HBOOK
34 
36 #include "ExG4HbookFileManager.hh"
38 #include "G4AnalysisUtilities.hh"
39 #include "G4UnitsTable.hh"
40 
41 #include <iostream>
42 
43 using namespace G4Analysis;
44 
45 //_____________________________________________________________________________
46 ExG4HbookNtupleManager::ExG4HbookNtupleManager(const G4AnalysisManagerState& state)
47  : G4VNtupleManager(state),
48  fNtupleHbookIdOffset(-1),
49  fNtupleDescriptionVector(),
50  fNtupleVector()
51 {
52 }
53 
54 //_____________________________________________________________________________
55 ExG4HbookNtupleManager::~ExG4HbookNtupleManager()
56 {
57  // Reset();
58 
59  std::vector<ExG4HbookNtupleDescription*>::iterator it;
60  for (it = fNtupleDescriptionVector.begin(); it != fNtupleDescriptionVector.end(); it++ ) {
61  delete *it;
62  }
63 }
64 
65 //
66 // private methods
67 //
68 
69 //_____________________________________________________________________________
70 void ExG4HbookNtupleManager::SetNtupleHbookIdOffset()
71 {
72 // Set fH1HbookIdOffset if needed
73 
74  if ( fNtupleHbookIdOffset == -1 ) {
75  if ( fFirstId > 0 )
76  fNtupleHbookIdOffset = 0;
77  else
78  fNtupleHbookIdOffset = 1;
79 
80  if ( fNtupleHbookIdOffset > 0 ) {
81  G4ExceptionDescription description;
82  description << "Ntuple will be defined in HBOOK with ID = G4_firstNtupleId + 1";
83  G4Exception("ExG4HbookNtupleManager::SetNtupleHbookIdOffset()",
84  "Analysis_W013", JustWarning, description);
85  }
86  }
87 }
88 
89 //_____________________________________________________________________________
90 void ExG4HbookNtupleManager::CreateNtuplesFromBooking()
91 {
92 // Create ntuple from ntuple_booking.
93 
94  if ( ! fNtupleDescriptionVector.size() ) return;
95 
96  // Set fNtupleHbookIdOffset if needed
97  SetNtupleHbookIdOffset();
98 
99  G4int index = 0;
100  std::vector<ExG4HbookNtupleDescription*>::iterator itn;
101  for (itn = fNtupleDescriptionVector.begin(); itn != fNtupleDescriptionVector.end(); itn++ ) {
102 
103  tools::ntuple_booking* ntupleBooking = (*itn)->fNtupleBooking;
104  if ( ! ntupleBooking ) continue;
105 
106 #ifdef G4VERBOSE
107  if ( fState.GetVerboseL4() )
108  fState.GetVerboseL4()
109  ->Message("create from booking", "ntuple", ntupleBooking->name());
110 #endif
111 
112  // Create an "ntuple" directory both in memory and in the file
113  fFileManager->CreateNtupleDirectory();
114  G4int hbookIndex = fNtupleHbookIdOffset + index + fFirstId;
115  ++index;
116 
117  // We should be under //PAWC/LUN1/ntuple
118  (*itn)->fNtuple
119  = new tools::hbook::wntuple(hbookIndex, G4cout, *ntupleBooking);
120  fNtupleVector.push_back((*itn)->fNtuple);
121 
122  if ( ntupleBooking->columns().size() ) {
123  // store ntuple columns in local maps
124  const std::vector<tools::column_booking>& columns
125  = ntupleBooking->columns();
126  std::vector<tools::column_booking>::const_iterator it;
127  G4int counter = 0;
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());
132  }
133  else if( it->cls_id() == tools::_cid(float(0) ) ) {
134  (*itn)->fNtupleFColumnMap[counter++]
135  = (*itn)->fNtuple->find_column<float>(it->name());
136  }
137  else if(it->cls_id()== tools::_cid(double(0))) {
138  (*itn)->fNtupleDColumnMap[counter++]
139  = (*itn)->fNtuple->find_column<double>(it->name());
140  }
141  else {
142  G4ExceptionDescription description;
143  description << " "
144  << "Unsupported column type " << it->name();
145  G4Exception("G4HbookAnalysisManager::CreateNtupleFromBooking()",
146  "Analysis_W002", JustWarning, description);
147  }
148  }
149  }
150  FinishNtuple();
151 #ifdef G4VERBOSE
152  if ( fState.GetVerboseL3() )
153  fState.GetVerboseL3()
154  ->Message("create from booking", "ntuple", ntupleBooking->name());
155 #endif
156  }
157 }
158 
159 //_____________________________________________________________________________
160 tools::hbook::wntuple::column<int>*
161 ExG4HbookNtupleManager::GetNtupleIColumn(G4int ntupleId, G4int columnId) const
162 {
163  ExG4HbookNtupleDescription* ntupleDecription
164  = GetNtupleInFunction(ntupleId, "GetNtupleIColumn");
165  if ( ! ntupleDecription ) return 0;
166 
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() ) {
172  G4ExceptionDescription description;
173  description << " " << "ntupleId " << ntupleId
174  << "column " << columnId << " does not exist.";
175  G4Exception("G4HbookAnalysisManager::GetNtupleIColumn()",
176  "Analysis_W011", JustWarning, description);
177  return 0;
178  }
179 
180  return it->second;
181 }
182 
183 //_____________________________________________________________________________
184 tools::hbook::wntuple::column<float>*
185 ExG4HbookNtupleManager::GetNtupleFColumn(G4int ntupleId, G4int columnId) const
186 {
187  ExG4HbookNtupleDescription* ntupleDecription
188  = GetNtupleInFunction(ntupleId, "GetNtupleFColumn");
189  if ( ! ntupleDecription ) return 0;
190 
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() ) {
196  G4ExceptionDescription description;
197  description << " " << "ntupleId " << ntupleId
198  << "column " << columnId << " does not exist.";
199  G4Exception("G4HbookAnalysisManager::GetNtupleFColumn()",
200  "Analysis_W011", JustWarning, description);
201  return 0;
202  }
203 
204  return it->second;
205 }
206 
207 //_____________________________________________________________________________
208 tools::hbook::wntuple::column<double>*
209 ExG4HbookNtupleManager::GetNtupleDColumn(G4int ntupleId, G4int columnId) const
210 {
211  ExG4HbookNtupleDescription* ntupleDecription
212  = GetNtupleInFunction(ntupleId, "GetNtupleDColumn");
213  if ( ! ntupleDecription ) return 0;
214 
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() ) {
220  G4ExceptionDescription description;
221  description << " " << "ntupleId " << ntupleId
222  << "column " << columnId << " does not exist.";
223  G4Exception("G4HbookAnalysisManager::GetNtupleDColumn()",
224  "Analysis_W011", JustWarning, description);
225  return 0;
226  }
227 
228  return it->second;
229 }
230 
231 //_____________________________________________________________________________
232 void ExG4HbookNtupleManager::Reset()
233 {
234 // Reset ntuple
235 
236  std::vector<ExG4HbookNtupleDescription*>::iterator it3;
237  for (it3 = fNtupleDescriptionVector.begin(); it3 != fNtupleDescriptionVector.end(); it3++ ) {
238  delete (*it3)->fNtuple;
239  (*it3)->fNtuple = 0;
240  }
241  fNtupleVector.clear();
242 }
243 
244 //
245 // protected methods
246 //
247 
248 //_____________________________________________________________________________
249 ExG4HbookNtupleDescription* ExG4HbookNtupleManager::GetNtupleInFunction(
250  G4int id,
251  G4String functionName, G4bool warn,
252  G4bool /*onlyIfActive*/) const
253 {
254  G4int index = id - fFirstId;
255  if ( index < 0 || index >= G4int(fNtupleDescriptionVector.size()) ) {
256  if ( warn) {
257  G4String inFunction = "G4HbookAnalysisManager::";
258  inFunction += functionName;
259  G4ExceptionDescription description;
260  description << " " << "ntuple " << id << " does not exist.";
261  G4Exception(inFunction, "Analysis_W011", JustWarning, description);
262  }
263  return 0;
264  }
265 
266  return fNtupleDescriptionVector[index];
267 }
268 
269 //
270 // public methods
271 //
272 
273 //_____________________________________________________________________________
274 G4int ExG4HbookNtupleManager::CreateNtuple(const G4String& name,
275  const G4String& title)
276 {
277  // Create an "ntuple" directory both in memory and in the file
278  if ( fFileManager->IsFile() )
279  fFileManager->CreateNtupleDirectory();
280 
281 #ifdef G4VERBOSE
282  if ( fState.GetVerboseL4() )
283  fState.GetVerboseL4()->Message("create", "ntuple", name);
284 #endif
285 
286  // Create ntuple description
287  G4int index = fNtupleDescriptionVector.size();
288  ExG4HbookNtupleDescription* ntupleDescription
289  = new ExG4HbookNtupleDescription();
290  fNtupleDescriptionVector.push_back(ntupleDescription);
291 
292  // Create ntuple booking
293  ntupleDescription->fNtupleBooking
294  = new tools::ntuple_booking(name, title);
295  // ntuple booking object is deleted in destructor
296 
297  // Set fNtupleHbookIdOffset if needed
298  SetNtupleHbookIdOffset();
299 
300  // Create ntuple if the file is open
301  // We should be under //PAWC/LUN1/ntuple
302  if ( fFileManager->IsFile() ) {
303  G4int hbookIndex = fNtupleHbookIdOffset + index + fFirstId;
304  ntupleDescription->fNtuple
305  = new tools::hbook::wntuple(hbookIndex, name);
306  // ntuple object is deleted when closing a file
307  fNtupleVector.push_back(ntupleDescription->fNtuple);
308  }
309 
310 #ifdef G4VERBOSE
311  if ( fState.GetVerboseL2() ) {
312  G4ExceptionDescription description;
313  description << name << " ntupleId " << index + fFirstId;
314  fState.GetVerboseL2()->Message("create", "ntuple", description);
315  }
316 #endif
317 
318  return index + fFirstId;
319 }
320 
321 //_____________________________________________________________________________
322 G4int ExG4HbookNtupleManager::CreateNtupleIColumn(const G4String& name,
323  std::vector<int>* vector)
324 {
325  G4int ntupleId = fNtupleDescriptionVector.size() + fFirstId - 1;
326  return CreateNtupleIColumn(ntupleId, name, vector);
327 }
328 
329 //_____________________________________________________________________________
330 G4int ExG4HbookNtupleManager::CreateNtupleFColumn(const G4String& name,
331  std::vector<float>* vector)
332 {
333  G4int ntupleId = fNtupleDescriptionVector.size() + fFirstId - 1;
334  return CreateNtupleFColumn(ntupleId, name, vector);
335 }
336 
337 //_____________________________________________________________________________
338 G4int ExG4HbookNtupleManager::CreateNtupleDColumn(const G4String& name,
339  std::vector<double>* vector)
340 {
341  G4int ntupleId = fNtupleDescriptionVector.size() + fFirstId - 1;
342  return CreateNtupleDColumn(ntupleId, name, vector);
343 }
344 
345 //_____________________________________________________________________________
346 G4int ExG4HbookNtupleManager::CreateNtupleSColumn(const G4String& name)
347 {
348  G4int ntupleId = fNtupleDescriptionVector.size() + fFirstId - 1;
349  return CreateNtupleSColumn(ntupleId, name);
350 }
351 
352 //_____________________________________________________________________________
353 void ExG4HbookNtupleManager::FinishNtuple()
354 {
355  G4int ntupleId = fNtupleDescriptionVector.size() + fFirstId - 1;
356  FinishNtuple(ntupleId);
357 }
358 
359 //_____________________________________________________________________________
360 G4int ExG4HbookNtupleManager::CreateNtupleIColumn(G4int ntupleId,
361  const G4String& name,
362  std::vector<int>* vector)
363 {
364  // Vector columns are not supported in HBOOK
365  if ( vector ) {
366  G4ExceptionDescription description;
367  description << " "
368  << "Vector columns are not supported in HBOOK.";
369  G4Exception("(ExG4HbookNtupleManager::CreateNtupleIColumn)",
370  "Analysis_W002", FatalException, description);
371  return kInvalidId;
372  }
373 
374 #ifdef G4VERBOSE
375  if ( fState.GetVerboseL4() ) {
376  G4ExceptionDescription description;
377  description << name << " ntupleId " << ntupleId;
378  fState.GetVerboseL4()->Message("create", "ntuple I column", description);
379  }
380 #endif
381 
382  ExG4HbookNtupleDescription* ntupleDescription
383  = GetNtupleInFunction(ntupleId, "CreateNtupleIColumn");
384  tools::ntuple_booking* ntupleBooking
385  = ntupleDescription->fNtupleBooking;
386 
387  if ( ! ntupleBooking ) {
388  G4ExceptionDescription description;
389  description << " "
390  << "Ntuple " << ntupleId << " has to be created first. ";
391  G4Exception("G4HbookAnalysisManager::CreateNtupleIColumn()",
392  "Analysis_W002", JustWarning, description);
393  return kInvalidId;
394  }
395 
396  // Save column info in booking
397  G4int index = ntupleBooking->columns().size();
398  ntupleBooking->add_column<int>(name);
399 
400  // Create column if ntuple already exists
401  if ( ntupleDescription->fNtuple ) {
402  tools::hbook::wntuple::column<int>* column
403  = ntupleDescription->fNtuple->create_column<int>(name);
404  ntupleDescription->fNtupleIColumnMap[index] = column;
405  }
406 
407  fLockFirstNtupleColumnId = true;
408 
409 #ifdef G4VERBOSE
410  if ( fState.GetVerboseL2() ) {
411  G4ExceptionDescription description;
412  description << name << " ntupleId " << ntupleId;
413  fState.GetVerboseL2()->Message("create", "ntuple I column", description);
414  }
415 #endif
416 
417  return index + fFirstNtupleColumnId;
418 }
419 
420 //_____________________________________________________________________________
421 G4int ExG4HbookNtupleManager::CreateNtupleFColumn(G4int ntupleId,
422  const G4String& name,
423  std::vector<float>* vector)
424 {
425  // Vector columns are not supported in HBOOK
426  if ( vector ) {
427  G4ExceptionDescription description;
428  description << " "
429  << "Vector columns are not supported in HBOOK.";
430  G4Exception("(ExG4HbookNtupleManager::CreateNtupleFColumn)",
431  "Analysis_W002", FatalException, description);
432  return kInvalidId;
433  }
434 
435 #ifdef G4VERBOSE
436  if ( fState.GetVerboseL4() ) {
437  G4ExceptionDescription description;
438  description << name << " ntupleId " << ntupleId;
439  fState.GetVerboseL4()->Message("create", "ntuple F column", description);
440  }
441 #endif
442 
443  ExG4HbookNtupleDescription* ntupleDescription
444  = GetNtupleInFunction(ntupleId, "CreateNtupleFColumn");
445  tools::ntuple_booking* ntupleBooking
446  = ntupleDescription->fNtupleBooking;
447 
448  if ( ! ntupleBooking ) {
449  G4ExceptionDescription description;
450  description << " "
451  << "Ntuple " << ntupleId << " has to be created first. ";
452  G4Exception("G4HbookAnalysisManager::CreateNtupleFColumn()",
453  "Analysis_W002", JustWarning, description);
454  return kInvalidId;
455  }
456 
457  // Save column info in booking
458  G4int index = ntupleBooking->columns().size();
459  ntupleBooking->add_column<float>(name);
460 
461  // Create column if ntuple already exists
462  if ( ntupleDescription->fNtuple ) {
463  tools::hbook::wntuple::column<float>* column
464  = ntupleDescription->fNtuple->create_column<float>(name);
465  ntupleDescription->fNtupleFColumnMap[index] = column;
466  }
467 
468  fLockFirstNtupleColumnId = true;
469 
470 #ifdef G4VERBOSE
471  if ( fState.GetVerboseL2() ) {
472  G4ExceptionDescription description;
473  description << name << " ntupleId " << ntupleId;
474  fState.GetVerboseL2()->Message("create", "ntuple F column", description);
475  }
476 #endif
477 
478  return index + fFirstNtupleColumnId;
479 }
480 
481 
482 //_____________________________________________________________________________
483 G4int ExG4HbookNtupleManager::CreateNtupleDColumn(G4int ntupleId,
484  const G4String& name,
485  std::vector<double>* vector)
486 {
487  // Vector columns are not supported in HBOOK
488  if ( vector ) {
489  G4ExceptionDescription description;
490  description << " "
491  << "Vector columns are not supported in HBOOK.";
492  G4Exception("(ExG4HbookNtupleManager::CreateNtupleDColumn)",
493  "Analysis_W002", FatalException, description);
494  return kInvalidId;
495  }
496 
497 #ifdef G4VERBOSE
498  if ( fState.GetVerboseL4() ) {
499  G4ExceptionDescription description;
500  description << name << " ntupleId " << ntupleId;
501  fState.GetVerboseL4()->Message("create", "ntuple D column", description);
502  }
503 #endif
504 
505  ExG4HbookNtupleDescription* ntupleDescription
506  = GetNtupleInFunction(ntupleId, "CreateNtupleDColumn");
507  tools::ntuple_booking* ntupleBooking
508  = ntupleDescription->fNtupleBooking;
509 
510  if ( ! ntupleBooking ) {
511  G4ExceptionDescription description;
512  description << " "
513  << "Ntuple " << ntupleId << " has to be created first. ";
514  G4Exception("G4HbookAnalysisManager::CreateNtupleDColumn()",
515  "Analysis_W002", JustWarning, description);
516  return kInvalidId;
517  }
518 
519  // Save column info in booking
520  G4int index = ntupleBooking->columns().size();
521  ntupleBooking->add_column<double>(name);
522 
523  // Create column if ntuple already exists
524  if ( ntupleDescription->fNtuple ) {
525  tools::hbook::wntuple::column<double>* column
526  = ntupleDescription->fNtuple->create_column<double>(name);
527  ntupleDescription->fNtupleDColumnMap[index] = column;
528  }
529 
530  fLockFirstNtupleColumnId = true;
531 
532 #ifdef G4VERBOSE
533  if ( fState.GetVerboseL2() ) {
534  G4ExceptionDescription description;
535  description << name << " ntupleId " << ntupleId;
536  fState.GetVerboseL2()->Message("create", "ntuple D column", description);
537  }
538 #endif
539 
540  return index + fFirstNtupleColumnId;
541 }
542 
543 //_____________________________________________________________________________
544 G4int ExG4HbookNtupleManager::CreateNtupleSColumn(G4int /*ntupleId*/,
545  const G4String& /*name*/)
546 {
547  G4ExceptionDescription description;
548  description << " "
549  << "Columns of string type are not supported in HBOOK.";
550  G4Exception("(ExG4HbookNtupleManager::CreateNtupleDColumn)",
551  "Analysis_W002", FatalException, description);
552  return kInvalidId;
553 }
554 
555 //_____________________________________________________________________________
556 void ExG4HbookNtupleManager::FinishNtuple(G4int ntupleId)
557 {
558  ExG4HbookNtupleDescription* ntupleDescription
559  = GetNtupleInFunction(ntupleId, "CreateNtupleDColumn");
560  tools::hbook::wntuple* ntuple = ntupleDescription->fNtuple;
561 
562  if ( ! ntuple ) return;
563 
564 #ifdef G4VERBOSE
565  if ( fState.GetVerboseL4() )
566  fState.GetVerboseL4()
567  ->Message("finish", "ntuple", ntupleDescription->fNtupleBooking->name());
568 #endif
569 
570  // Return to //PAWC/LUN1 :
571  tools::hbook::CHCDIR("//PAWC/LUN1"," ");
572 
573  //fNtuple->add_row_beg();
574 #ifdef G4VERBOSE
575  if ( fState.GetVerboseL2() )
576  fState.GetVerboseL2()
577  ->Message("finish", "ntuple", ntupleDescription->fNtupleBooking->name());
578 #endif
579 }
580 
581 //_____________________________________________________________________________
582 G4bool ExG4HbookNtupleManager::FillNtupleIColumn(G4int columnId, G4int value)
583 {
584  return FillNtupleIColumn(fFirstId, columnId, value);
585 }
586 
587 //_____________________________________________________________________________
588 G4bool ExG4HbookNtupleManager::FillNtupleFColumn(G4int columnId, G4float value)
589 {
590  return FillNtupleFColumn(fFirstId, columnId, value);
591 }
592 
593 //_____________________________________________________________________________
594 G4bool ExG4HbookNtupleManager::FillNtupleDColumn(G4int columnId, G4double value)
595 {
596  return FillNtupleDColumn(fFirstId, columnId, value);
597 }
598 
599 //_____________________________________________________________________________
600 G4bool ExG4HbookNtupleManager::FillNtupleSColumn(G4int columnId,
601  const G4String& value)
602 {
603  return FillNtupleSColumn(fFirstId, columnId, value);
604 }
605 
606 //_____________________________________________________________________________
607 G4bool ExG4HbookNtupleManager::AddNtupleRow()
608 {
609  return AddNtupleRow(fFirstId);
610 }
611 
612 //_____________________________________________________________________________
613 G4bool ExG4HbookNtupleManager::FillNtupleIColumn(
614  G4int ntupleId, G4int columnId,
615  G4int value)
616 {
617  tools::hbook::wntuple::column<int>* column
618  = GetNtupleIColumn(ntupleId, columnId);
619  if ( ! column ) {
620  G4ExceptionDescription description;
621  description << " " << "ntupleId " << ntupleId
622  << "column " << columnId << " does not exist.";
623  G4Exception("G4HbookAnalysisManager::FillNtupleIColumn()",
624  "Analysis_W011", JustWarning, description);
625  return false;
626  }
627 
628  column->fill(value);
629  #ifdef G4VERBOSE
630  if ( fState.GetVerboseL4() ) {
631  G4ExceptionDescription description;
632  description << " ntupleId " << ntupleId
633  << " columnId " << columnId << " value " << value;
634  fState.GetVerboseL4()->Message("fill", "ntuple I column", description);
635  }
636 #endif
637  return true;
638 }
639 //_____________________________________________________________________________
640 G4bool ExG4HbookNtupleManager::FillNtupleFColumn(
641  G4int ntupleId, G4int columnId,
642  G4float value)
643 {
644  tools::hbook::wntuple::column<float>* column
645  = GetNtupleFColumn(ntupleId, columnId);
646  if ( ! column ) {
647  G4ExceptionDescription description;
648  description << " " << "ntupleId " << ntupleId
649  << "column " << columnId << " does not exist.";
650  G4Exception("G4HbookAnalysisManager::FillNtupleFColumn()",
651  "Analysis_W011", JustWarning, description);
652  return false;
653  }
654 
655  column->fill(value);
656 #ifdef G4VERBOSE
657  if ( fState.GetVerboseL4() ) {
658  G4ExceptionDescription description;
659  description << " ntupleId " << ntupleId
660  << " columnId " << columnId << " value " << value;
661  fState.GetVerboseL4()->Message("fill", "ntuple F column", description);
662  }
663 #endif
664  return true;
665 }
666 //_____________________________________________________________________________
667 G4bool ExG4HbookNtupleManager::FillNtupleDColumn(
668  G4int ntupleId, G4int columnId,
669  G4double value)
670 {
671  tools::hbook::wntuple::column<double>* column
672  = GetNtupleDColumn(ntupleId, columnId);
673  if ( ! column ) {
674  G4ExceptionDescription description;
675  description << " " << "ntupleId " << ntupleId
676  << "column " << columnId << " does not exist.";
677  G4Exception("G4HbookAnalysisManager::FillNtupleDColumn()",
678  "Analysis_W011", JustWarning, description);
679  return false;
680  }
681 
682  column->fill(value);
683 #ifdef G4VERBOSE
684  if ( fState.GetVerboseL4() ) {
685  G4ExceptionDescription description;
686  description << " ntupleId " << ntupleId
687  << " columnId " << columnId << " value " << value;
688  fState.GetVerboseL4()->Message("fill", "ntuple D column", description);
689  }
690 #endif
691  return true;
692 }
693 
694 //_____________________________________________________________________________
695 G4bool ExG4HbookNtupleManager::FillNtupleSColumn(
696  G4int /*ntupleId*/, G4int /*columnId*/,
697  const G4String& /*value*/)
698 {
699  G4ExceptionDescription description;
700  description << " "
701  << "Columns of string type are not supported in HBOOK.";
702  G4Exception("(ExG4HbookNtupleManager::FillNtupleSColumn)",
703  "Analysis_W011", JustWarning, description);
704  return kInvalidId;
705 }
706 
707 //_____________________________________________________________________________
708 G4bool ExG4HbookNtupleManager::AddNtupleRow(G4int ntupleId)
709 {
710 #ifdef G4VERBOSE
711  if ( fState.GetVerboseL4() ) {
712  G4ExceptionDescription description;
713  description << " ntupleId " << ntupleId;
714  fState.GetVerboseL4()->Message("add", "ntuple row", description);
715  }
716 #endif
717 
718  ExG4HbookNtupleDescription* ntupleDescription
719  = GetNtupleInFunction(ntupleId, "AddNtupleRow");
720 
721  if ( ! ntupleDescription || ! ntupleDescription->fNtuple ) {
722  G4ExceptionDescription description;
723  description << " " << " ntupleId " << ntupleId
724  << " does not exist. ";
725  G4Exception("G4HbookAnalysisManager::AddNtupleRow()",
726  "Analysis_W011", JustWarning, description);
727  return false;
728  }
729 
730  ntupleDescription->fNtuple->add_row();
731 #ifdef G4VERBOSE
732  if ( fState.GetVerboseL4() ) {
733  G4ExceptionDescription description;
734  description << " ntupleId " << ntupleId;
735  fState.GetVerboseL4()->Message("add", "ntuple row", description, true);
736  }
737 #endif
738  return true;
739 }
740 
741 //_____________________________________________________________________________
742 tools::hbook::wntuple* ExG4HbookNtupleManager::GetNtuple() const
743 {
744  return GetNtuple(fFirstId);
745 }
746 
747 //_____________________________________________________________________________
748 tools::hbook::wntuple* ExG4HbookNtupleManager::GetNtuple(G4int ntupleId) const
749 {
750  ExG4HbookNtupleDescription* ntupleDescription
751  = GetNtupleInFunction(ntupleId, "GetNtuple");
752 
753  return ntupleDescription->fNtuple;
754 }
755 
756 //_____________________________________________________________________________
757 G4bool ExG4HbookNtupleManager::SetNtupleHbookIdOffset(G4int offset)
758 {
759  if ( fNtupleDescriptionVector.size() ) {
760  G4ExceptionDescription description;
761  description
762  << "Cannot set NtupleHbookIdOffset as some ntuples already exist.";
763  G4Exception("G4HbookAnalysisManager::SetNtupleHbookIdOffset()",
764  "Analysis_W013", JustWarning, description);
765  return false;
766  }
767 
768  if ( fFirstId + offset < 1 ) {
769  G4ExceptionDescription description;
770  description << "The first ntuple HBOOK id must be >= 1.";
771  G4Exception("G4HbookAnalysisManager::SetNtupleHbookIdOffset()",
772  "Analysis_W013", JustWarning, description);
773  return false;
774  }
775 
776  fNtupleHbookIdOffset = offset;
777  return true;
778 }
779 
780 #endif
std::ostringstream G4ExceptionDescription
Definition: globals.hh:76
G4String name
Definition: TRTMaterials.hh:40
float G4float
Definition: G4Types.hh:77
int G4int
Definition: G4Types.hh:78
G4GLOB_DLL std::ostream G4cout
bool G4bool
Definition: G4Types.hh:79
Definition of the ExG4HbookNtupleManager class.
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
double G4double
Definition: G4Types.hh:76
const G4int kInvalidId
Definition of the ExG4HbookFileManager class.