-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConfigTopDir_Tester_e.cpp
More file actions
113 lines (89 loc) · 2.68 KB
/
ConfigTopDir_Tester_e.cpp
File metadata and controls
113 lines (89 loc) · 2.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
//
// Created by alons on 14/08/2024.
//
#include <iomanip>
#include <string>
#include "TString.h"
using namespace std;
#if independent_tester
#include "ConfigBeamE.cpp"
string GetCurrentDirectory()
{
char pwd[PATH_MAX];
getcwd(pwd, sizeof(pwd));
string WorkingDirectory = pwd;
return WorkingDirectory;
}
bool findSubstring(string string1, string string2)
{
if (string1.find(string2) != string::npos)
{
return true;
}
else
{
return false;
}
}
void ReplaceSubStr(string &str, const string &subStr, const string &replacement)
{
bool PrintOut = false;
if (PrintOut)
{
cout << "\nstr0 = " << str << "\n";
}
string TempSource = str;
size_t pos = TempSource.find(subStr);
// Iterate till index position of substring is valid:
while (pos != std::string::npos)
{
// Replace the first occurrence of substring in string from position pos onwards:
TempSource.replace(pos, subStr.length(), replacement);
// Get the index position of next occurrence of substring in string:
pos = TempSource.find(subStr, pos + replacement.length());
}
str = TempSource;
if (PrintOut)
{
cout << "str1 = " << str << "\n";
}
}
TString ConfigTopDir(TString OutPutFolder)
{
string CurrentDir = GetCurrentDirectory();
if (!findSubstring(CurrentDir, "Users/alon/Projects/Uniform-sample-generator"))
{
cout << "Current directory is '" << CurrentDir << endl;
cout << "OutPut folder kept unchanged." << endl;
return OutPutFolder;
}
else
{
cout << "Current directory is '" << CurrentDir << endl;
cout << "OutPut folder changed to '" << CurrentDir << "/OutPut/" << "'" << endl;
return CurrentDir + "/OutPut/";
}
}
#endif
TString ConfigTopDir_Tester_e(const double Ebeam, TString OutPutFolder)
{
string CurrentDir = GetCurrentDirectory();
TString FuncOut;
if (!findSubstring(CurrentDir, "Users/alon/Projects/Uniform-sample-generator"))
{
cout << "Current directory is '" << CurrentDir << endl;
cout << "OutPut folder kept unchanged." << endl;
string OutPutFolder0 = OutPutFolder.Data();
string OutPutFolder1 = OutPutFolder0.substr(0, OutPutFolder0.find_last_of('/'));
FuncOut = OutPutFolder1 + "_Tester_e/";
return FuncOut;
}
else
{
string OutTopDir = "/Users/alon/Downloads/" + ConfigBeamE(Ebeam);
cout << "Current directory is '" << CurrentDir << endl;
cout << "OutPut folder changed to '" << CurrentDir << "/OutPut/" << "'" << endl;
FuncOut = OutTopDir + "/OutPut_Tester_e/";
return FuncOut;
}
}