-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConfigHelper.C
More file actions
116 lines (106 loc) · 3.65 KB
/
ConfigHelper.C
File metadata and controls
116 lines (106 loc) · 3.65 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
//Helper functions for Config parsing.
#ifndef INCLUDED_CONFIG_HELPER
#define INCLUDED_CONFIG_HELPER
#include "ConfigParser.C"
TString PLOT_OUTPUT_LOCATION="/home/users/bhashemi/public_html/WWWCrossSection/";
TString HIST_OUTPUT_LOCATION="/nfs-7/userdata/bobak/WWWCrossSection_Hists/";
TString parseConfDir(TString conf_path){
/* Replace *configs/.../FNAME.conf with .../ */
conf_path = TString(conf_path(conf_path.Index("configs/")+8, conf_path.Last('/')-conf_path.Index("configs/")-7));
return conf_path;
}
TString getOutputDir(ConfigParser *conf, TString type){
/*Determines the proper output locations of files by parsing the option conf_path to get the directory structure above the level 'configs/'*/
//cout<<__LINE__<<endl;
if (type == "hist"){
//cout<<__LINE__<<endl;
if (conf->get("histo_output_dir") != ""){
//cout<<__LINE__<<endl;
return TString(conf->get("histo_output_dir"));
}
else{
TString output_dir = parseConfDir(conf->get("conf_path"));
//cout<<__LINE__<<endl;
return output_dir.Prepend(HIST_OUTPUT_LOCATION);
}
//cout<<__LINE__<<endl;
}
else if (type == "plot" )
{
if (conf->get("save_dir") != ""){
return TString(conf->get("save_dir"));
}
else{
TString conf_path = conf->get("conf_path");
TString output_dir = parseConfDir(conf_path);
output_dir.Prepend(PLOT_OUTPUT_LOCATION);
conf_path = TString(conf_path(conf_path.Last('/')+1, conf_path.Last('.')-conf_path.Last('/')-1)); //get name of config file
output_dir+=conf_path+"/";
//also add filename for conf script
return output_dir;
}
}
else{
TString error = type.Prepend("In ConfigHelper::getOutputDir -- Did not recieve valid type, either hist or plot... got: ");
throw std::invalid_argument(error.Data());
return TString("");
}
}
TString getDefaultHistDir(ConfigParser *conf){
/*Returns the default hist output location + the conf_path defined by the location of the config file*/
return HIST_OUTPUT_LOCATION+parseConfDir(conf->get("conf_path"));
}
TString parseLatex(TString opt){
/* Replaces \ with # to be in line with ROOT's latex syntax */
opt.ReplaceAll("\\","#");
return opt;
}
vector<double> parseVector(TString opt){
/* Parses options in the config files which are formatted to be vectors [double,double,double,...]*/
vector<double> ret;
TString token;
Ssiz_t from=0;
//cout<<"got vector in string form: "<<opt<<endl;
while(opt.Tokenize(token, from, "[,]")){
token.ReplaceAll("[", "");
token.ReplaceAll("]", "");
token.ReplaceAll(",", "");
token.ReplaceAll(" ", "");
//cout<<"token: "<<token<<endl;
ret.push_back(stod(token.Data()));
}
return ret;
}
vector<int> iparseVector(TString opt){
/* Parses options in the config files which are formatted to be vectors [int,int,int,...]*/
vector<int> ret;
TString token;
Ssiz_t from=0;
//cout<<"got vector in string form: "<<opt<<endl;
while(opt.Tokenize(token, from, "[,]")){
token.ReplaceAll("[", "");
token.ReplaceAll("]", "");
token.ReplaceAll(",", "");
token.ReplaceAll(" ", "");
//cout<<"token: "<<token<<endl;
ret.push_back(stoi(token.Data()));
}
return ret;
}
vector<TString> sParseVector(TString opt){
/* Parses options in the config files which are formatted to be vectors [string,string,string,...]*/
vector<TString> ret;
TString token;
Ssiz_t from=0;
//cout<<"got vector in string form: "<<opt<<endl;
while(opt.Tokenize(token, from, "[,]")){
token.ReplaceAll("[", "");
token.ReplaceAll("]", "");
token.ReplaceAll(",", "");
token.ReplaceAll(" ", "");
//cout<<"token: "<<token<<endl;
ret.push_back(TString(token.Data()));
}
return ret;
}
#endif