-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConfigTopDir.cpp
More file actions
140 lines (112 loc) · 3.42 KB
/
ConfigTopDir.cpp
File metadata and controls
140 lines (112 loc) · 3.42 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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
//
// Created by alons on 14/08/2024.
//
#ifndef CONFIGTOPDIR_CPP
#define CONFIGTOPDIR_CPP
#include <iomanip>
#include <string>
#include "TString.h"
#include "ConfigBeamE.cpp"
using namespace std;
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 << "\033[33m" << "Current directory is \033[0m" << CurrentDir << endl;
cout << "\033[33m" << "OutPut folder kept unchanged.\033[0m" << endl;
return OutPutFolder;
}
else
{
cout << "\033[33m" << "Current directory is \033[0m" << CurrentDir << endl;
cout << "\033[33m" << "OutPut folder changed to \033[0m'" << CurrentDir << "/OutPut/" << "'" << endl;
return CurrentDir + "/OutPut/";
}
}
TString ConfigTopDir(const bool gen_1e_events, const bool gen_ep_events, const bool gen_en_events, const double Ebeam, TString OutPutFolder)
{
string CurrentDir = GetCurrentDirectory();
TString FuncOut;
if (!findSubstring(CurrentDir, "Users/alon/Projects/Uniform-sample-generator"))
{
cout << "\033[33m" << "Current directory is \033[0m" << CurrentDir << endl;
cout << "\033[33m" << "OutPut folder kept unchanged.\033[0m" << endl;
string OutPutFolder0 = OutPutFolder.Data();
string OutPutFolder1 = OutPutFolder0.substr(0, OutPutFolder0.find_last_of('/'));
if (gen_1e_events)
{
FuncOut = OutPutFolder1 + "_1e/";
}
else if (gen_ep_events)
{
FuncOut = OutPutFolder1 + "_ep/";
}
else if (gen_en_events)
{
FuncOut = OutPutFolder1 + "_en/";
}
return FuncOut;
}
else
{
string OutTopDir = "/Users/alon/Downloads/" + ConfigBeamE(Ebeam);
cout << "\033[33m" << "Current directory is \033[0m" << CurrentDir << endl;
cout << "\033[33m" << "OutPut folder changed to \033[0m'" << CurrentDir << "/OutPut/" << "'" << endl;
if (gen_1e_events)
{
FuncOut = OutTopDir + "/OutPut_1e/";
}
else if (gen_ep_events)
{
FuncOut = OutTopDir + "/OutPut_ep/";
}
else if (gen_en_events)
{
FuncOut = OutTopDir + "/OutPut_en/";
}
return FuncOut;
}
}
#endif //CONFIGTOPDIR_CPP