Geant4  10.02.p01
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  // Do not create ntuple if it is inactivated
107  if ( fState.GetIsActivation() && ( ! (*itn)->fActivation ) ) continue;
108 
109 #ifdef G4VERBOSE
110  if ( fState.GetVerboseL4() )
111  fState.GetVerboseL4()
112  ->Message("create from booking", "ntuple", ntupleBooking->name());
113 #endif
114 
115  // Create an "ntuple" directory both in memory and in the file
116  fFileManager->CreateNtupleDirectory();
117  G4int hbookIndex = fNtupleHbookIdOffset + index + fFirstId;
118  ++index;
119 
120  // We should be under //PAWC/LUN1/ntuple
121  (*itn)->fNtuple
122  = new tools::hbook::wntuple(hbookIndex, G4cout, *ntupleBooking);
123  fNtupleVector.push_back((*itn)->fNtuple);
124 
125  if ( ntupleBooking->columns().size() ) {
126  // store ntuple columns in local maps
127  const std::vector<tools::column_booking>& columns
128  = ntupleBooking->columns();
129  std::vector<tools::column_booking>::const_iterator it;
130  G4int counter = 0;
131  for ( it = columns.begin(); it!=columns.end(); ++it) {
132  if ( it->cls_id() == tools::_cid(int(0) ) ) {
133  (*itn)->fNtupleIColumnMap[counter++]
134  = (*itn)->fNtuple->find_column<int>(it->name());
135  }
136  else if( it->cls_id() == tools::_cid(float(0) ) ) {
137  (*itn)->fNtupleFColumnMap[counter++]
138  = (*itn)->fNtuple->find_column<float>(it->name());
139  }
140  else if(it->cls_id()== tools::_cid(double(0))) {
141  (*itn)->fNtupleDColumnMap[counter++]
142  = (*itn)->fNtuple->find_column<double>(it->name());
143  }
144  else {
145  G4ExceptionDescription description;
146  description << " "
147  << "Unsupported column type " << it->name();
148  G4Exception("G4HbookAnalysisManager::CreateNtupleFromBooking()",
149  "Analysis_W002", JustWarning, description);
150  }
151  }
152  }
153  FinishNtuple();
154 #ifdef G4VERBOSE
155  if ( fState.GetVerboseL3() )
156  fState.GetVerboseL3()
157  ->Message("create from booking", "ntuple", ntupleBooking->name());
158 #endif
159  }
160 }
161 
162 //_____________________________________________________________________________
163 tools::hbook::wntuple::column<int>*
164 ExG4HbookNtupleManager::GetNtupleIColumn(G4int ntupleId, G4int columnId) const
165 {
166  ExG4HbookNtupleDescription* ntupleDecription
167  = GetNtupleInFunction(ntupleId, "GetNtupleIColumn");
168  if ( ! ntupleDecription ) return 0;
169 
170  std::map<G4int, tools::hbook::wntuple::column<int>* >& ntupleIColumnMap
171  = ntupleDecription->fNtupleIColumnMap;
172  std::map<G4int, tools::hbook::wntuple::column<int>* >::const_iterator it
173  = ntupleIColumnMap.find(columnId);
174  if ( it == ntupleIColumnMap.end() ) {
175  G4ExceptionDescription description;
176  description << " " << "ntupleId " << ntupleId
177  << "column " << columnId << " does not exist.";
178  G4Exception("G4HbookAnalysisManager::GetNtupleIColumn()",
179  "Analysis_W011", JustWarning, description);
180  return 0;
181  }
182 
183  return it->second;
184 }
185 
186 //_____________________________________________________________________________
187 tools::hbook::wntuple::column<float>*
188 ExG4HbookNtupleManager::GetNtupleFColumn(G4int ntupleId, G4int columnId) const
189 {
190  ExG4HbookNtupleDescription* ntupleDecription
191  = GetNtupleInFunction(ntupleId, "GetNtupleFColumn");
192  if ( ! ntupleDecription ) return 0;
193 
194  std::map<G4int, tools::hbook::wntuple::column<float>* >& ntupleFColumnMap
195  = ntupleDecription->fNtupleFColumnMap;
196  std::map<G4int, tools::hbook::wntuple::column<float>* >::const_iterator it
197  = ntupleFColumnMap.find(columnId);
198  if ( it == ntupleFColumnMap.end() ) {
199  G4ExceptionDescription description;
200  description << " " << "ntupleId " << ntupleId
201  << "column " << columnId << " does not exist.";
202  G4Exception("G4HbookAnalysisManager::GetNtupleFColumn()",
203  "Analysis_W011", JustWarning, description);
204  return 0;
205  }
206 
207  return it->second;
208 }
209 
210 //_____________________________________________________________________________
211 tools::hbook::wntuple::column<double>*
212 ExG4HbookNtupleManager::GetNtupleDColumn(G4int ntupleId, G4int columnId) const
213 {
214  ExG4HbookNtupleDescription* ntupleDecription
215  = GetNtupleInFunction(ntupleId, "GetNtupleDColumn");
216  if ( ! ntupleDecription ) return 0;
217 
218  std::map<G4int, tools::hbook::wntuple::column<double>* >& ntupleDColumnMap
219  = ntupleDecription->fNtupleDColumnMap;
220  std::map<G4int, tools::hbook::wntuple::column<double>* >::const_iterator it
221  = ntupleDColumnMap.find(columnId);
222  if ( it == ntupleDColumnMap.end() ) {
223  G4ExceptionDescription description;
224  description << " " << "ntupleId " << ntupleId
225  << "column " << columnId << " does not exist.";
226  G4Exception("G4HbookAnalysisManager::GetNtupleDColumn()",
227  "Analysis_W011", JustWarning, description);
228  return 0;
229  }
230 
231  return it->second;
232 }
233 
234 //_____________________________________________________________________________
235 void ExG4HbookNtupleManager::Reset()
236 {
237 // Reset ntuple
238 
239  std::vector<ExG4HbookNtupleDescription*>::iterator it3;
240  for (it3 = fNtupleDescriptionVector.begin(); it3 != fNtupleDescriptionVector.end(); it3++ ) {
241  delete (*it3)->fNtuple;
242  (*it3)->fNtuple = 0;
243  }
244  fNtupleVector.clear();
245 }
246 
247 //
248 // protected methods
249 //
250 
251 //_____________________________________________________________________________
252 ExG4HbookNtupleDescription* ExG4HbookNtupleManager::GetNtupleInFunction(
253  G4int id,
254  G4String functionName, G4bool warn,
255  G4bool /*onlyIfActive*/) const
256 {
257  G4int index = id - fFirstId;
258  if ( index < 0 || index >= G4int(fNtupleDescriptionVector.size()) ) {
259  if ( warn) {
260  G4String inFunction = "G4HbookAnalysisManager::";
261  inFunction += functionName;
262  G4ExceptionDescription description;
263  description << " " << "ntuple " << id << " does not exist.";
264  G4Exception(inFunction, "Analysis_W011", JustWarning, description);
265  }
266  return 0;
267  }
268 
269  return fNtupleDescriptionVector[index];
270 }
271 
272 //
273 // public methods
274 //
275 
276 //_____________________________________________________________________________
277 G4int ExG4HbookNtupleManager::CreateNtuple(const G4String& name,
278  const G4String& title)
279 {
280  // Create an "ntuple" directory both in memory and in the file
281  if ( fFileManager->IsFile() )
282  fFileManager->CreateNtupleDirectory();
283 
284 #ifdef G4VERBOSE
285  if ( fState.GetVerboseL4() )
286  fState.GetVerboseL4()->Message("create", "ntuple", name);
287 #endif
288 
289  // Create ntuple description
290  G4int index = fNtupleDescriptionVector.size();
291  ExG4HbookNtupleDescription* ntupleDescription
292  = new ExG4HbookNtupleDescription();
293  fNtupleDescriptionVector.push_back(ntupleDescription);
294 
295  // Create ntuple booking
296  ntupleDescription->fNtupleBooking
297  = new tools::ntuple_booking(name, title);
298  // ntuple booking object is deleted in destructor
299 
300  // Set fNtupleHbookIdOffset if needed
301  SetNtupleHbookIdOffset();
302 
303  // Create ntuple if the file is open
304  // We should be under //PAWC/LUN1/ntuple
305  if ( fFileManager->IsFile() ) {
306  G4int hbookIndex = fNtupleHbookIdOffset + index + fFirstId;
307  ntupleDescription->fNtuple
308  = new tools::hbook::wntuple(hbookIndex, name);
309  // ntuple object is deleted when closing a file
310  fNtupleVector.push_back(ntupleDescription->fNtuple);
311  }
312 
313 #ifdef G4VERBOSE
314  if ( fState.GetVerboseL2() ) {
315  G4ExceptionDescription description;
316  description << name << " ntupleId " << index + fFirstId;
317  fState.GetVerboseL2()->Message("create", "ntuple", description);
318  }
319 #endif
320 
321  return index + fFirstId;
322 }
323 
324 //_____________________________________________________________________________
325 G4int ExG4HbookNtupleManager::CreateNtupleIColumn(const G4String& name,
326  std::vector<int>* vector)
327 {
328  G4int ntupleId = fNtupleDescriptionVector.size() + fFirstId - 1;
329  return CreateNtupleIColumn(ntupleId, name, vector);
330 }
331 
332 //_____________________________________________________________________________
333 G4int ExG4HbookNtupleManager::CreateNtupleFColumn(const G4String& name,
334  std::vector<float>* vector)
335 {
336  G4int ntupleId = fNtupleDescriptionVector.size() + fFirstId - 1;
337  return CreateNtupleFColumn(ntupleId, name, vector);
338 }
339 
340 //_____________________________________________________________________________
341 G4int ExG4HbookNtupleManager::CreateNtupleDColumn(const G4String& name,
342  std::vector<double>* vector)
343 {
344  G4int ntupleId = fNtupleDescriptionVector.size() + fFirstId - 1;
345  return CreateNtupleDColumn(ntupleId, name, vector);
346 }
347 
348 //_____________________________________________________________________________
349 G4int ExG4HbookNtupleManager::CreateNtupleSColumn(const G4String& name)
350 {
351  G4int ntupleId = fNtupleDescriptionVector.size() + fFirstId - 1;
352  return CreateNtupleSColumn(ntupleId, name);
353 }
354 
355 //_____________________________________________________________________________
356 void ExG4HbookNtupleManager::FinishNtuple()
357 {
358  G4int ntupleId = fNtupleDescriptionVector.size() + fFirstId - 1;
359  FinishNtuple(ntupleId);
360 }
361 
362 //_____________________________________________________________________________
363 G4int ExG4HbookNtupleManager::CreateNtupleIColumn(G4int ntupleId,
364  const G4String& name,
365  std::vector<int>* vector)
366 {
367  // Vector columns are not supported in HBOOK
368  if ( vector ) {
369  G4ExceptionDescription description;
370  description << " "
371  << "Vector columns are not supported in HBOOK.";
372  G4Exception("(ExG4HbookNtupleManager::CreateNtupleIColumn)",
373  "Analysis_W002", FatalException, description);
374  return kInvalidId;
375  }
376 
377 #ifdef G4VERBOSE
378  if ( fState.GetVerboseL4() ) {
379  G4ExceptionDescription description;
380  description << name << " ntupleId " << ntupleId;
381  fState.GetVerboseL4()->Message("create", "ntuple I column", description);
382  }
383 #endif
384 
385  ExG4HbookNtupleDescription* ntupleDescription
386  = GetNtupleInFunction(ntupleId, "CreateNtupleIColumn");
387  tools::ntuple_booking* ntupleBooking
388  = ntupleDescription->fNtupleBooking;
389 
390  if ( ! ntupleBooking ) {
391  G4ExceptionDescription description;
392  description << " "
393  << "Ntuple " << ntupleId << " has to be created first. ";
394  G4Exception("G4HbookAnalysisManager::CreateNtupleIColumn()",
395  "Analysis_W002", JustWarning, description);
396  return kInvalidId;
397  }
398 
399  // Save column info in booking
400  G4int index = ntupleBooking->columns().size();
401  ntupleBooking->add_column<int>(name);
402 
403  // Create column if ntuple already exists
404  if ( ntupleDescription->fNtuple ) {
405  tools::hbook::wntuple::column<int>* column
406  = ntupleDescription->fNtuple->create_column<int>(name);
407  ntupleDescription->fNtupleIColumnMap[index] = column;
408  }
409 
410  fLockFirstNtupleColumnId = true;
411 
412 #ifdef G4VERBOSE
413  if ( fState.GetVerboseL2() ) {
414  G4ExceptionDescription description;
415  description << name << " ntupleId " << ntupleId;
416  fState.GetVerboseL2()->Message("create", "ntuple I column", description);
417  }
418 #endif
419 
420  return index + fFirstNtupleColumnId;
421 }
422 
423 //_____________________________________________________________________________
424 G4int ExG4HbookNtupleManager::CreateNtupleFColumn(G4int ntupleId,
425  const G4String& name,
426  std::vector<float>* vector)
427 {
428  // Vector columns are not supported in HBOOK
429  if ( vector ) {
430  G4ExceptionDescription description;
431  description << " "
432  << "Vector columns are not supported in HBOOK.";
433  G4Exception("(ExG4HbookNtupleManager::CreateNtupleFColumn)",
434  "Analysis_W002", FatalException, description);
435  return kInvalidId;
436  }
437 
438 #ifdef G4VERBOSE
439  if ( fState.GetVerboseL4() ) {
440  G4ExceptionDescription description;
441  description << name << " ntupleId " << ntupleId;
442  fState.GetVerboseL4()->Message("create", "ntuple F column", description);
443  }
444 #endif
445 
446  ExG4HbookNtupleDescription* ntupleDescription
447  = GetNtupleInFunction(ntupleId, "CreateNtupleFColumn");
448  tools::ntuple_booking* ntupleBooking
449  = ntupleDescription->fNtupleBooking;
450 
451  if ( ! ntupleBooking ) {
452  G4ExceptionDescription description;
453  description << " "
454  << "Ntuple " << ntupleId << " has to be created first. ";
455  G4Exception("G4HbookAnalysisManager::CreateNtupleFColumn()",
456  "Analysis_W002", JustWarning, description);
457  return kInvalidId;
458  }
459 
460  // Save column info in booking
461  G4int index = ntupleBooking->columns().size();
462  ntupleBooking->add_column<float>(name);
463 
464  // Create column if ntuple already exists
465  if ( ntupleDescription->fNtuple ) {
466  tools::hbook::wntuple::column<float>* column
467  = ntupleDescription->fNtuple->create_column<float>(name);
468  ntupleDescription->fNtupleFColumnMap[index] = column;
469  }
470 
471  fLockFirstNtupleColumnId = true;
472 
473 #ifdef G4VERBOSE
474  if ( fState.GetVerboseL2() ) {
475  G4ExceptionDescription description;
476  description << name << " ntupleId " << ntupleId;
477  fState.GetVerboseL2()->Message("create", "ntuple F column", description);
478  }
479 #endif
480 
481  return index + fFirstNtupleColumnId;
482 }
483 
484 
485 //_____________________________________________________________________________
486 G4int ExG4HbookNtupleManager::CreateNtupleDColumn(G4int ntupleId,
487  const G4String& name,
488  std::vector<double>* vector)
489 {
490  // Vector columns are not supported in HBOOK
491  if ( vector ) {
492  G4ExceptionDescription description;
493  description << " "
494  << "Vector columns are not supported in HBOOK.";
495  G4Exception("(ExG4HbookNtupleManager::CreateNtupleDColumn)",
496  "Analysis_W002", FatalException, description);
497  return kInvalidId;
498  }
499 
500 #ifdef G4VERBOSE
501  if ( fState.GetVerboseL4() ) {
502  G4ExceptionDescription description;
503  description << name << " ntupleId " << ntupleId;
504  fState.GetVerboseL4()->Message("create", "ntuple D column", description);
505  }
506 #endif
507 
508  ExG4HbookNtupleDescription* ntupleDescription
509  = GetNtupleInFunction(ntupleId, "CreateNtupleDColumn");
510  tools::ntuple_booking* ntupleBooking
511  = ntupleDescription->fNtupleBooking;
512 
513  if ( ! ntupleBooking ) {
514  G4ExceptionDescription description;
515  description << " "
516  << "Ntuple " << ntupleId << " has to be created first. ";
517  G4Exception("G4HbookAnalysisManager::CreateNtupleDColumn()",
518  "Analysis_W002", JustWarning, description);
519  return kInvalidId;
520  }
521 
522  // Save column info in booking
523  G4int index = ntupleBooking->columns().size();
524  ntupleBooking->add_column<double>(name);
525 
526  // Create column if ntuple already exists
527  if ( ntupleDescription->fNtuple ) {
528  tools::hbook::wntuple::column<double>* column
529  = ntupleDescription->fNtuple->create_column<double>(name);
530  ntupleDescription->fNtupleDColumnMap[index] = column;
531  }
532 
533  fLockFirstNtupleColumnId = true;
534 
535 #ifdef G4VERBOSE
536  if ( fState.GetVerboseL2() ) {
537  G4ExceptionDescription description;
538  description << name << " ntupleId " << ntupleId;
539  fState.GetVerboseL2()->Message("create", "ntuple D column", description);
540  }
541 #endif
542 
543  return index + fFirstNtupleColumnId;
544 }
545 
546 //_____________________________________________________________________________
547 G4int ExG4HbookNtupleManager::CreateNtupleSColumn(G4int /*ntupleId*/,
548  const G4String& /*name*/)
549 {
550  G4ExceptionDescription description;
551  description << " "
552  << "Columns of string type are not supported in HBOOK.";
553  G4Exception("(ExG4HbookNtupleManager::CreateNtupleDColumn)",
554  "Analysis_W002", FatalException, description);
555  return kInvalidId;
556 }
557 
558 //_____________________________________________________________________________
559 void ExG4HbookNtupleManager::FinishNtuple(G4int ntupleId)
560 {
561  ExG4HbookNtupleDescription* ntupleDescription
562  = GetNtupleInFunction(ntupleId, "CreateNtupleDColumn");
563  tools::hbook::wntuple* ntuple = ntupleDescription->fNtuple;
564 
565  if ( ! ntuple ) return;
566 
567 #ifdef G4VERBOSE
568  if ( fState.GetVerboseL4() )
569  fState.GetVerboseL4()
570  ->Message("finish", "ntuple", ntupleDescription->fNtupleBooking->name());
571 #endif
572 
573  // Return to //PAWC/LUN1 :
574  tools::hbook::CHCDIR("//PAWC/LUN1"," ");
575 
576  //fNtuple->add_row_beg();
577 #ifdef G4VERBOSE
578  if ( fState.GetVerboseL2() )
579  fState.GetVerboseL2()
580  ->Message("finish", "ntuple", ntupleDescription->fNtupleBooking->name());
581 #endif
582 }
583 
584 //_____________________________________________________________________________
585 G4bool ExG4HbookNtupleManager::FillNtupleIColumn(G4int columnId, G4int value)
586 {
587  return FillNtupleIColumn(fFirstId, columnId, value);
588 }
589 
590 //_____________________________________________________________________________
591 G4bool ExG4HbookNtupleManager::FillNtupleFColumn(G4int columnId, G4float value)
592 {
593  return FillNtupleFColumn(fFirstId, columnId, value);
594 }
595 
596 //_____________________________________________________________________________
597 G4bool ExG4HbookNtupleManager::FillNtupleDColumn(G4int columnId, G4double value)
598 {
599  return FillNtupleDColumn(fFirstId, columnId, value);
600 }
601 
602 //_____________________________________________________________________________
603 G4bool ExG4HbookNtupleManager::FillNtupleSColumn(G4int columnId,
604  const G4String& value)
605 {
606  return FillNtupleSColumn(fFirstId, columnId, value);
607 }
608 
609 //_____________________________________________________________________________
610 G4bool ExG4HbookNtupleManager::AddNtupleRow()
611 {
612  return AddNtupleRow(fFirstId);
613 }
614 
615 //_____________________________________________________________________________
616 G4bool ExG4HbookNtupleManager::FillNtupleIColumn(
617  G4int ntupleId, G4int columnId,
618  G4int value)
619 {
620  if ( fState.GetIsActivation() && ( ! GetActivation(ntupleId) ) ) {
621  //G4cout << "Skipping FillNtupleIColumn for " << ntupleId << G4endl;
622  return false;
623  }
624 
625  tools::hbook::wntuple::column<int>* column
626  = GetNtupleIColumn(ntupleId, columnId);
627  if ( ! column ) {
628  G4ExceptionDescription description;
629  description << " " << "ntupleId " << ntupleId
630  << "column " << columnId << " does not exist.";
631  G4Exception("G4HbookAnalysisManager::FillNtupleIColumn()",
632  "Analysis_W011", JustWarning, description);
633  return false;
634  }
635 
636  column->fill(value);
637  #ifdef G4VERBOSE
638  if ( fState.GetVerboseL4() ) {
639  G4ExceptionDescription description;
640  description << " ntupleId " << ntupleId
641  << " columnId " << columnId << " value " << value;
642  fState.GetVerboseL4()->Message("fill", "ntuple I column", description);
643  }
644 #endif
645  return true;
646 }
647 //_____________________________________________________________________________
648 G4bool ExG4HbookNtupleManager::FillNtupleFColumn(
649  G4int ntupleId, G4int columnId,
650  G4float value)
651 {
652  if ( fState.GetIsActivation() && ( ! GetActivation(ntupleId) ) ) {
653  //G4cout << "Skipping FillNtupleIColumn for " << ntupleId << G4endl;
654  return false;
655  }
656 
657  tools::hbook::wntuple::column<float>* column
658  = GetNtupleFColumn(ntupleId, columnId);
659  if ( ! column ) {
660  G4ExceptionDescription description;
661  description << " " << "ntupleId " << ntupleId
662  << "column " << columnId << " does not exist.";
663  G4Exception("G4HbookAnalysisManager::FillNtupleFColumn()",
664  "Analysis_W011", JustWarning, description);
665  return false;
666  }
667 
668  column->fill(value);
669 #ifdef G4VERBOSE
670  if ( fState.GetVerboseL4() ) {
671  G4ExceptionDescription description;
672  description << " ntupleId " << ntupleId
673  << " columnId " << columnId << " value " << value;
674  fState.GetVerboseL4()->Message("fill", "ntuple F column", description);
675  }
676 #endif
677  return true;
678 }
679 
680 //_____________________________________________________________________________
681 G4bool ExG4HbookNtupleManager::FillNtupleDColumn(
682  G4int ntupleId, G4int columnId,
683  G4double value)
684 {
685  if ( fState.GetIsActivation() && ( ! GetActivation(ntupleId) ) ) {
686  //G4cout << "Skipping FillNtupleIColumn for " << ntupleId << G4endl;
687  return false;
688  }
689 
690  tools::hbook::wntuple::column<double>* column
691  = GetNtupleDColumn(ntupleId, columnId);
692  if ( ! column ) {
693  G4ExceptionDescription description;
694  description << " " << "ntupleId " << ntupleId
695  << "column " << columnId << " does not exist.";
696  G4Exception("G4HbookAnalysisManager::FillNtupleDColumn()",
697  "Analysis_W011", JustWarning, description);
698  return false;
699  }
700 
701  column->fill(value);
702 #ifdef G4VERBOSE
703  if ( fState.GetVerboseL4() ) {
704  G4ExceptionDescription description;
705  description << " ntupleId " << ntupleId
706  << " columnId " << columnId << " value " << value;
707  fState.GetVerboseL4()->Message("fill", "ntuple D column", description);
708  }
709 #endif
710  return true;
711 }
712 
713 //_____________________________________________________________________________
714 G4bool ExG4HbookNtupleManager::FillNtupleSColumn(
715  G4int ntupleId, G4int /*columnId*/,
716  const G4String& /*value*/)
717 {
718  if ( fState.GetIsActivation() && ( ! GetActivation(ntupleId) ) ) {
719  //G4cout << "Skipping FillNtupleIColumn for " << ntupleId << G4endl;
720  return false;
721  }
722 
723  G4ExceptionDescription description;
724  description << " "
725  << "Columns of string type are not supported in HBOOK.";
726  G4Exception("(ExG4HbookNtupleManager::FillNtupleSColumn)",
727  "Analysis_W011", JustWarning, description);
728  return kInvalidId;
729 }
730 
731 //_____________________________________________________________________________
732 G4bool ExG4HbookNtupleManager::AddNtupleRow(G4int ntupleId)
733 {
734  if ( fState.GetIsActivation() && ( ! GetActivation(ntupleId) ) ) {
735  //G4cout << "Skipping FillNtupleIColumn for " << ntupleId << G4endl;
736  return false;
737  }
738 
739 #ifdef G4VERBOSE
740  if ( fState.GetVerboseL4() ) {
741  G4ExceptionDescription description;
742  description << " ntupleId " << ntupleId;
743  fState.GetVerboseL4()->Message("add", "ntuple row", description);
744  }
745 #endif
746 
747  ExG4HbookNtupleDescription* ntupleDescription
748  = GetNtupleInFunction(ntupleId, "AddNtupleRow");
749 
750  if ( ! ntupleDescription || ! ntupleDescription->fNtuple ) {
751  G4ExceptionDescription description;
752  description << " " << " ntupleId " << ntupleId
753  << " does not exist. ";
754  G4Exception("G4HbookAnalysisManager::AddNtupleRow()",
755  "Analysis_W011", JustWarning, description);
756  return false;
757  }
758 
759  ntupleDescription->fNtuple->add_row();
760 #ifdef G4VERBOSE
761  if ( fState.GetVerboseL4() ) {
762  G4ExceptionDescription description;
763  description << " ntupleId " << ntupleId;
764  fState.GetVerboseL4()->Message("add", "ntuple row", description, true);
765  }
766 #endif
767  return true;
768 }
769 
770 //_____________________________________________________________________________
771 tools::hbook::wntuple* ExG4HbookNtupleManager::GetNtuple() const
772 {
773  return GetNtuple(fFirstId);
774 }
775 
776 //_____________________________________________________________________________
777 tools::hbook::wntuple* ExG4HbookNtupleManager::GetNtuple(G4int ntupleId) const
778 {
779  ExG4HbookNtupleDescription* ntupleDescription
780  = GetNtupleInFunction(ntupleId, "GetNtuple");
781 
782  return ntupleDescription->fNtuple;
783 }
784 
785 //_____________________________________________________________________________
786 G4bool ExG4HbookNtupleManager::SetNtupleHbookIdOffset(G4int offset)
787 {
788  if ( fNtupleDescriptionVector.size() ) {
789  G4ExceptionDescription description;
790  description
791  << "Cannot set NtupleHbookIdOffset as some ntuples already exist.";
792  G4Exception("G4HbookAnalysisManager::SetNtupleHbookIdOffset()",
793  "Analysis_W013", JustWarning, description);
794  return false;
795  }
796 
797  if ( fFirstId + offset < 1 ) {
798  G4ExceptionDescription description;
799  description << "The first ntuple HBOOK id must be >= 1.";
800  G4Exception("G4HbookAnalysisManager::SetNtupleHbookIdOffset()",
801  "Analysis_W013", JustWarning, description);
802  return false;
803  }
804 
805  fNtupleHbookIdOffset = offset;
806  return true;
807 }
808 
809 #endif
810 
811 //_____________________________________________________________________________
812 void ExG4HbookNtupleManager::SetActivation(G4bool activation)
813 {
814  std::vector<ExG4HbookNtupleDescription*>::iterator it;
815  for (it = fNtupleDescriptionVector.begin(); it != fNtupleDescriptionVector.end(); it++ ) {
816  (*it)->fActivation = activation;
817  }
818 }
819 
820 //_____________________________________________________________________________
821 void ExG4HbookNtupleManager::SetActivation(G4int ntupleId, G4bool activation)
822 {
823  ExG4HbookNtupleDescription* ntupleDescription
824  = GetNtupleInFunction(ntupleId, "SetActivation");
825  if ( ! ntupleDescription ) return;
826 
827  ntupleDescription->fActivation = activation;
828 }
829 
830 //_____________________________________________________________________________
831 G4bool ExG4HbookNtupleManager::GetActivation(G4int ntupleId) const
832 {
833  ExG4HbookNtupleDescription* ntupleDescription
834  = GetNtupleInFunction(ntupleId, "GetActivation");
835  if ( ! ntupleDescription ) return false;
836 
837  return ntupleDescription->fActivation;
838 }
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.