#include <MyConfigure.hh>
Public Member Functions | |
MyConfigure (void) | |
virtual | ~MyConfigure (void) |
std::vector< G4String > | GetWords (G4String formula) |
bool | FindMacro (G4String word, G4String &value) |
void | Replace (G4String &formula, G4String word, G4String value) |
double | CalFormula (G4String formula, int iRep=0) |
G4String | ReplaceMacro (G4String formula) |
Static Public Attributes | |
static std::vector< G4String > | knownValueNames |
static std::vector< G4String > | knownValues |
Definition at line 11 of file MyConfigure.hh.
MyConfigure::MyConfigure | ( | void | ) |
Definition at line 17 of file MyConfigure.cc.
MyConfigure::~MyConfigure | ( | void | ) | [virtual] |
Definition at line 20 of file MyConfigure.cc.
double MyConfigure::CalFormula | ( | G4String | formula, | |
int | iRep = 0 | |||
) |
Definition at line 23 of file MyConfigure.cc.
Referenced by SimpleGeometryParameter::Calculate(), and PrimaryGeneratorAction::ReadCard().
00023 { 00024 // std::cout<<"TO Calculate for: \""<<formula<<"\" "<<iRep<<std::endl; // to be deleted 00025 // formula = ReplaceMacro(formula); 00026 TF1 *f1 = new TF1("f1", formula); 00027 double value = f1->Eval(iRep); 00028 // std::cout<<"\t=>"<<value<<std::endl; 00029 delete f1; 00030 return value; 00031 }
bool MyConfigure::FindMacro | ( | G4String | word, | |
G4String & | value | |||
) |
Definition at line 87 of file MyConfigure.cc.
References knownValueNames, and knownValues.
Referenced by Replace(), and ReplaceMacro().
00087 { 00088 bool found = false; 00089 for (int i = 0; i< knownValues.size(); i++){ 00090 if (knownValueNames[i]==word){ 00091 value = knownValues[i]; 00092 found = true; 00093 break; 00094 } 00095 } 00096 return found; 00097 }
std::vector< G4String > MyConfigure::GetWords | ( | G4String | formula | ) |
Definition at line 48 of file MyConfigure.cc.
Referenced by ReplaceMacro().
00048 { 00049 std::vector<G4String> words; 00050 words.clear(); 00051 const char* cformula = formula.c_str(); 00052 int length = strlen(cformula); 00053 char temp[1240]; 00054 int tempoffset = 0; 00055 for ( int offset = 0; offset < length; offset++ ){ 00056 char c = cformula[offset]; 00057 bool isword = false; 00058 if (c>='a'&&c<='z' 00059 ||c>='A'&&c<='Z' 00060 ||c>='0'&&c<='9' 00061 ||c=='_' 00062 ){ 00063 temp[tempoffset++] = cformula[offset]; 00064 isword = true; 00065 } 00066 if (!isword||offset==length-1){ 00067 if (tempoffset>0){ 00068 temp[tempoffset++] = '\0'; 00069 tempoffset=0; 00070 G4String word = temp; 00071 bool found = false; 00072 for(int iWord = 0; iWord<words.size(); iWord++){ 00073 if (words[iWord]==word){ 00074 found = true; 00075 break; 00076 } 00077 } 00078 if (!found){ 00079 words.push_back(word); 00080 } 00081 } 00082 } 00083 } 00084 return words; 00085 }
void MyConfigure::Replace | ( | G4String & | formula, | |
G4String | word, | |||
G4String | value | |||
) |
Definition at line 99 of file MyConfigure.cc.
References FindMacro().
Referenced by ReplaceMacro().
00099 { 00100 // std::cout<<"-- \""<<formula<<"\""<<std::endl; // to be deleted 00101 G4String newform = ""; 00102 const char* cformula = formula.c_str(); 00103 int length = strlen(cformula); 00104 char temp[1024]; 00105 int tempoffset = 0; 00106 char cnewform[1024]; 00107 int newformoffset = 0; 00108 for ( int offset = 0; offset < length; offset++ ){ 00109 char c = cformula[offset]; 00110 bool isword = false; 00111 if (c>='a'&&c<='z' 00112 ||c>='A'&&c<='Z' 00113 ||c>='0'&&c<='9' 00114 ||c=='_' 00115 ){ 00116 temp[tempoffset++] = cformula[offset]; 00117 isword = true; 00118 } 00119 if (!isword||offset==length-1){ 00120 if (tempoffset>0){ 00121 temp[tempoffset] = '\0'; 00122 tempoffset=0; 00123 if (newformoffset>0){ 00124 cnewform[newformoffset] = '\0'; 00125 newformoffset=0; 00126 G4String newformtemp = cnewform; 00127 newform=newform+newformtemp; 00128 } 00129 G4String word = temp; 00130 // std::cout<<" \""<<word<<"\""<<std::endl; // to be deleted 00131 G4String newword; 00132 bool found = FindMacro(word,newword); 00133 if (found){ 00134 newform=newform+"("+newword+")"; 00135 } 00136 else{ 00137 newform=newform+word; 00138 } 00139 // std::cout<<" to \""<<newword<<"\""<<std::endl; // to be deleted 00140 } 00141 if(!isword){ 00142 cnewform[newformoffset++] = cformula[offset]; 00143 } 00144 if (offset==length-1){ 00145 cnewform[newformoffset] = '\0'; 00146 G4String newformtemp = cnewform; 00147 newform=newform+newformtemp; 00148 } 00149 } 00150 } 00151 // std::cout<<" -->\""<<newform<<"\""<<std::endl; // to be deleted 00152 formula = newform; 00153 }
G4String MyConfigure::ReplaceMacro | ( | G4String | formula | ) |
Definition at line 33 of file MyConfigure.cc.
References FindMacro(), GetWords(), and Replace().
Referenced by SimpleGeometryParameter::GetValue(), and PrimaryGeneratorAction::ReadCard().
00033 { 00034 // std::cout<<"TO replace for: \""<<formula<<"\""<<std::endl; // to be deleted 00035 std::vector<G4String> words = GetWords(formula); 00036 // std::cout<<" "<<words.size()<<" words"<<std::endl; // to be deleted 00037 for (int iWord = 0; iWord < words.size(); iWord++ ){ 00038 // std::cout<<" "<<iWord<<std::endl; // to be deleted 00039 G4String value; 00040 if (FindMacro(words[iWord],value)){ 00041 Replace(formula,words[iWord],value); 00042 } 00043 } 00044 // std::cout<<"\t=>"<<formula<<std::endl; 00045 return formula; 00046 }
std::vector< G4String > MyConfigure::knownValueNames [static] |
Definition at line 24 of file MyConfigure.hh.
Referenced by FindMacro(), SimpleGeometryParameter::GetValue(), and PrimaryGeneratorAction::ReadCard().
std::vector< G4String > MyConfigure::knownValues [static] |
Definition at line 25 of file MyConfigure.hh.
Referenced by FindMacro(), SimpleGeometryParameter::GetValue(), and PrimaryGeneratorAction::ReadCard().