Geant4  10.00.p03
G4AnalysisUtilities.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 
28 // Author: Ivana Hrivnacova, 22/08/2013 (ivana@ipno.in2p3.fr)
29 
30 #include "G4AnalysisUtilities.hh"
31 #include "G4BinScheme.hh"
32 #include "G4UnitsTable.hh"
33 #include "G4String.hh"
34 
35 namespace {
36 
37 //_____________________________________________________________________________
38 G4bool GetToken(const G4String& line, G4String& token,
39  std::string::size_type begIdx, std::string::size_type& endIdx)
40 {
41  while ( line[begIdx] == ' ') ++begIdx;
42  if ( line[begIdx] == '"' ) {
43  endIdx = line.find('"', begIdx+1);
44  if ( endIdx == std::string::npos ) endIdx = line.length();
45  token = line.substr(begIdx+1, (endIdx-1)-begIdx);
46  ++endIdx;
47  }
48  else {
49  endIdx = line.find(' ', begIdx);
50  if ( endIdx == std::string::npos ) endIdx = line.length();
51  token = line.substr(begIdx, endIdx-begIdx);
52  }
53  return ( token.length() > 0 );
54 }
55 
56 }
57 
58 namespace G4Analysis
59 {
60 
61 //_____________________________________________________________________________
63 {
64  if ( nbins <= 0 ) {
65  G4ExceptionDescription description;
66  description
67  << " Illegal value of number of bins: nbins <= 0" << G4endl;
68  G4Exception("G4VAnalysisManager::CheckNbins",
69  "Analysis_W013", JustWarning, description);
70  return false;
71  }
72  else
73  return true;
74 }
75 
76 
77 //_____________________________________________________________________________
78 G4bool CheckMinMax(G4double xmin, G4double xmax, const G4String& binSchemeName)
79 {
80  G4bool result = true;
81 
82  if ( xmax <= xmin ) {
83  G4ExceptionDescription description;
84  description
85  << " Illegal values of (xmin >= xmax)" << G4endl;
86  G4Exception("G4VAnalysisManager::CheckMinMax",
87  "Analysis_W013", JustWarning, description);
88 
89  result = false;
90  }
91 
92  if ( ( GetBinScheme(binSchemeName) == kLogBinScheme ) && ( xmin == 0 ) ) {
93  G4ExceptionDescription description;
94  description
95  << " Illegal value of (xmin = 0) with logarithmic binning" << G4endl;
96  G4Exception("G4VAnalysisManager::CheckMinMax",
97  "Analysis_W013", JustWarning, description);
98 
99  result = false;
100  }
101 
102  return result;
103 }
104 
105 //_____________________________________________________________________________
106 G4bool CheckEdges(const std::vector<G4double>& edges)
107 {
108  if ( edges.size() <= 1 ) {
109  G4ExceptionDescription description;
110  description
111  << " Illegal edges vector (size <= 1)" << G4endl;
112  G4Exception("G4VAnalysisManager::CheckEdges",
113  "Analysis_W013", JustWarning, description);
114  return false;
115  }
116  else
117  return true;
118 
119 }
120 
121 //_____________________________________________________________________________
122 G4bool CheckName(const G4String& name, const G4String& objectType)
123 {
124  if ( ! name.size() ) {
125  G4ExceptionDescription description;
126  description
127  << " Empty " << objectType << " name is not allowed." << G4endl
128  << " " << objectType << " was not created." << G4endl;
129  G4Exception("G4VAnalysisManager::CheckName",
130  "Analysis_W013", JustWarning, description);
131  return false;
132  }
133  else
134  return true;
135 }
136 
137 //_____________________________________________________________________________
139 {
140  G4double value = 1.;
141  if ( unit != "none" ) {
142  value = G4UnitDefinition::GetValueOf(unit);
143  if ( value == 0. ) value = 1.;
144  }
145  return value;
146 }
147 
148 //_____________________________________________________________________________
149 void UpdateTitle(G4String& title,
150  const G4String& unitName,
151  const G4String& fcnName)
152 {
153  if ( fcnName != "none" ) { title += " "; title += fcnName; title += "("; }
154  if ( unitName != "none" ) { title += " ["; title += unitName; title += "]";}
155  if ( fcnName != "none" ) { title += ")"; }
156 }
157 
158 //_____________________________________________________________________________
159 void Tokenize(const G4String& line, std::vector<G4String>& tokens)
160 {
161  // Define start values
162  std::string::size_type begIdx = 0;
163  std::string::size_type endIdx = 0;
164  G4String token;
165 
166  do {
167  if ( GetToken(line, token, begIdx, endIdx) ) {
168  //G4cout << "got token: '" << token << "'" << G4endl;
169  //G4cout << "beg, end: " << begIdx << ", " << endIdx << G4endl;
170  tokens.push_back(token);
171  }
172  begIdx = endIdx + 1;
173  }
174  while ( endIdx != line.length() );
175 }
176 
177 }
std::ostringstream G4ExceptionDescription
Definition: globals.hh:76
G4String name
Definition: TRTMaterials.hh:40
int G4int
Definition: G4Types.hh:78
void UpdateTitle(G4String &title, const G4String &unitName, const G4String &fcnName)
static G4double GetValueOf(const G4String &)
G4bool CheckName(const G4String &name, const G4String &objectType)
bool G4bool
Definition: G4Types.hh:79
G4bool CheckMinMax(G4double xmin, G4double xmax, const G4String &binSchemeName)
G4double GetUnitValue(const G4String &unit)
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
void Tokenize(const G4String &line, std::vector< G4String > &tokens)
G4BinScheme GetBinScheme(const G4String &binSchemeName)
Definition: G4BinScheme.cc:36
#define G4endl
Definition: G4ios.hh:61
G4bool CheckNbins(G4int nbins)
double G4double
Definition: G4Types.hh:76
G4bool CheckEdges(const std::vector< G4double > &edges)