Geant4  10.01.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 //_____________________________________________________________________________
79  const G4String& fcnName, const G4String& binSchemeName)
80 {
81  G4bool result = true;
82 
83  if ( xmax <= xmin ) {
84  G4ExceptionDescription description;
85  description
86  << " Illegal values of (xmin >= xmax)" << G4endl;
87  G4Exception("G4VAnalysisManager::CheckMinMax",
88  "Analysis_W013", JustWarning, description);
89 
90  result = false;
91  }
92 
93  if ( ( fcnName != "none" ) && ( binSchemeName != "linear" ) ) {
94  G4ExceptionDescription description;
95  description
96  << " Combining Function and Binning scheme is not supported."
97  << G4endl;
98  G4Exception("G4VAnalysisManager::CheckMinMax",
99  "Analysis_W013", JustWarning, description);
100 
101  result = false;
102  }
103 
104  if ( ( GetBinScheme(binSchemeName) == kLogBinScheme ||
105  fcnName == "log" || fcnName == "log10" ) && ( xmin == 0 ) ) {
106  G4ExceptionDescription description;
107  description
108  << " Illegal value of (xmin = 0) with logarithmic function or binning"
109  << G4endl;
110  G4Exception("G4VAnalysisManager::CheckMinMax",
111  "Analysis_W013", JustWarning, description);
112 
113  result = false;
114  }
115 
116  return result;
117 }
118 
119 //_____________________________________________________________________________
120 G4bool CheckEdges(const std::vector<G4double>& edges)
121 {
122  if ( edges.size() <= 1 ) {
123  G4ExceptionDescription description;
124  description
125  << " Illegal edges vector (size <= 1)" << G4endl;
126  G4Exception("G4VAnalysisManager::CheckEdges",
127  "Analysis_W013", JustWarning, description);
128  return false;
129  }
130  else
131  return true;
132 
133 }
134 
135 //_____________________________________________________________________________
136 G4bool CheckName(const G4String& name, const G4String& objectType)
137 {
138  if ( ! name.size() ) {
139  G4ExceptionDescription description;
140  description
141  << " Empty " << objectType << " name is not allowed." << G4endl
142  << " " << objectType << " was not created." << G4endl;
143  G4Exception("G4VAnalysisManager::CheckName",
144  "Analysis_W013", JustWarning, description);
145  return false;
146  }
147  else
148  return true;
149 }
150 
151 //_____________________________________________________________________________
153 {
154  G4double value = 1.;
155  if ( unit != "none" ) {
156  value = G4UnitDefinition::GetValueOf(unit);
157  if ( value == 0. ) value = 1.;
158  }
159  return value;
160 }
161 
162 //_____________________________________________________________________________
163 void UpdateTitle(G4String& title,
164  const G4String& unitName,
165  const G4String& fcnName)
166 {
167  if ( fcnName != "none" ) { title += " "; title += fcnName; title += "("; }
168  if ( unitName != "none" ) { title += " ["; title += unitName; title += "]";}
169  if ( fcnName != "none" ) { title += ")"; }
170 }
171 
172 //_____________________________________________________________________________
173 void Tokenize(const G4String& line, std::vector<G4String>& tokens)
174 {
175  // Define start values
176  std::string::size_type begIdx = 0;
177  std::string::size_type endIdx = 0;
178  G4String token;
179 
180  do {
181  if ( GetToken(line, token, begIdx, endIdx) ) {
182  //G4cout << "got token: '" << token << "'" << G4endl;
183  //G4cout << "beg, end: " << begIdx << ", " << endIdx << G4endl;
184  tokens.push_back(token);
185  }
186  begIdx = endIdx + 1;
187  }
188  while ( endIdx < line.length() );
189 }
190 
191 }
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
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 CheckMinMax(G4double xmin, G4double xmax, const G4String &fcnName="none", const G4String &binSchemeName="linear")
G4bool CheckEdges(const std::vector< G4double > &edges)