Geant4 VMC Version 6.6
Loading...
Searching...
No Matches
TG4Globals.cxx
Go to the documentation of this file.
1//------------------------------------------------
2// The Geant4 Virtual Monte Carlo package
3// Copyright (C) 2007 - 2014 Ivana Hrivnacova
4// All rights reserved.
5//
6// For the licensing terms see geant4_vmc/LICENSE.
7// Contact: root-vmc@cern.ch
8//-------------------------------------------------
9
14
15#include "TG4Globals.h"
16
17#include <stdlib.h>
18
19const TString TG4Globals::fgkEndl = "x\n";
20const char TG4Globals::fgkTokenSeparator = '+';
21
22//_____________________________________________________________________________
27
28//
29// public static methods
30//
31
32//_____________________________________________________________________________
34 const TString& className, const TString& methodName, const TString& text)
35{
37
38 TString newText = "x\n" + className + "::" + methodName + ":x\n";
39 newText += text + "\n";
40 newText += "*** TG4Exception: Aborting execution ***";
41 newText.ReplaceAll("x\n", "\n ");
42
43 G4cerr << newText.Data() << G4endl << G4endl;
44 abort();
45}
46
47//_____________________________________________________________________________
49 const TString& className, const TString& methodName, const TString& text)
50{
52
53 TString newText = "++++ TG4Warning: ++++x\n";
54 newText += className + "::" + methodName + ":x\n";
55 newText += text + "\n";
56 newText += "+++++++++++++++++++++++";
57 newText.ReplaceAll("x\n", "\n ");
58
59 G4cerr << newText.Data() << G4endl << G4endl;
60}
61
62//_____________________________________________________________________________
63void TG4Globals::AppendNumberToString(G4String& s, G4int a)
64{
66
67 const char* kpNumber = "0123456789";
68 G4String p = "";
69 G4String q = "";
70 do {
71 G4int b = a / 10;
72 G4int c = a % 10;
73 p = kpNumber[c];
74 q = p.append(q);
75 a = b;
76 } while (a > 0);
77 s.append(q);
78}
79
80//_____________________________________________________________________________
81G4bool TG4Globals::Compare(G4bool activation, TG4G3ControlValue controlValue)
82{
86
87 if (controlValue == kUnsetControlValue) {
88 TG4Globals::Warning("TG4Globals", "Compare", "Control value = kUnset.");
89 return false;
90 }
91
92 if (controlValue == kActivate || controlValue == kActivate2)
93 return activation;
94 else
95 return !activation;
96}
97
98//_____________________________________________________________________________
99void TG4Globals::PrintStars(G4bool emptyLineFirst)
100{
102
103 if (emptyLineFirst) G4cout << G4endl;
104
105 G4cout << "**********************************************" << G4endl;
106
107 if (!emptyLineFirst) G4cout << G4endl;
108}
109
110//_____________________________________________________________________________
112{
114
115 return G4String("vmc@root.cern.ch");
116}
117
118//_____________________________________________________________________________
119G4String TG4Globals::GetToken(Int_t i, const TString& s)
120{
122
123 std::vector<G4String> tokens;
124 std::string ss = s.Data();
125
126 /*
127 std::string::size_type idx0 = 0;
128 std::string::size_type idx1 = ss.find(fgkTokenSeparator,idx0);
129 if ( idx1 == std::string::npos ) idx1 = ss.length();
130 do {
131 tokens.push_back(TString(ss.substr(idx0, idx1-idx0)));
132 idx0 = idx1+1;
133 idx1 = ss.find(fgkTokenSeparator,idx0);
134 if ( idx1 == std::string::npos ) idx1 = ss.length();
135 }
136 while ( idx0 <= ss.length() );
137 */
138 std::string::size_type idx0 = 0;
139 do {
140 std::string::size_type idx1 = ss.find(fgkTokenSeparator, idx0);
141 if (idx1 == std::string::npos) idx1 = ss.length();
142 tokens.push_back(G4String(ss.substr(idx0, idx1 - idx0)));
143 idx0 = idx1 + 1;
144 } while (idx0 <= ss.length());
145
146 if (i < 0 || i >= Int_t(tokens.size()))
147 return "";
148 else
149 return tokens[i];
150}
Definition of the TG4Globals class and basic container types.
static void AppendNumberToString(G4String &string, G4int number)
static G4String GetToken(Int_t i, const TString &s)
static G4String Help()
static const TString fgkEndl
Special endl.
Definition TG4Globals.h:94
static void PrintStars(G4bool emptyLineFirst)
static void Warning(const TString &className, const TString &methodName, const TString &text)
static void Exception(const TString &className, const TString &methodName, const TString &text)
static G4bool Compare(G4bool activation, TG4G3ControlValue controlValue)
static const char fgkTokenSeparator
Separator in GetToken() method.
Definition TG4Globals.h:95
TG4G3ControlValue
Enumeration for G3 processes control values.
@ kActivate
process is activated WITH generation of secondaries
@ kUnsetControlValue
value not set
@ kActivate2
process is activated WITHOUT generation of secondaries