23#ifndef RestCore_TRestTools
24#define RestCore_TRestTools
36#define UNUSED(x) (void)x
39#define EXTERN_DEF __declspec(dllimport)
40#define EXTERN_IMP __declspec(dllexport)
42#define EXTERN_DEF extern
50const std::string PARAMETER_NOT_FOUND_STR =
"NO_SUCH_PARA";
51const double PARAMETER_NOT_FOUND_DBL = -99999999;
53EXTERN_DEF std::string REST_COMMIT;
54EXTERN_DEF std::string REST_PATH;
55EXTERN_DEF std::string REST_USER;
56EXTERN_DEF std::string REST_USER_PATH;
57EXTERN_DEF std::string REST_TMP_PATH;
58EXTERN_DEF std::map<std::string, std::string> REST_ARGS;
63 static std::vector<std::string>
GetOptions(std::string optionsStr);
67 static int ReadASCIITable(std::string fName, std::vector<std::vector<Double_t>>& data,
68 Int_t skipLines = 0, std::string separator =
"\t");
69 static int ReadASCIITable(std::string fName, std::vector<std::vector<Float_t>>& data, Int_t skipLines = 0,
70 std::string separator =
"\t");
71 static int ReadASCIITable(std::string fName, std::vector<std::vector<std::string>>& data,
72 Int_t skipLines = 0, std::string separator =
"\t");
74 static int ReadCSVFile(std::string fName, std::vector<std::vector<Double_t>>& data, Int_t skipLines = 0);
75 static int ReadCSVFile(std::string fName, std::vector<std::vector<Float_t>>& data, Int_t skipLines = 0);
81 static int ReadBinaryTable(std::string fName, std::vector<std::vector<T>>& data, Int_t columns = -1);
88 bool removeDuplicates =
true);
90 const std::vector<std::string>& wantedStrings);
100 template <
typename T>
103 template <
typename T>
106 template <
typename T>
107 static std::vector<T>
GetColumnFromTable(
const std::vector<std::vector<T>>& data,
unsigned int column);
109 template <
typename T>
110 static int PrintTable(std::vector<std::vector<T>> data, Int_t start = 0, Int_t end = 0);
112 template <
typename T>
113 static int ExportASCIITable(std::string fname, std::vector<std::vector<T>>& data);
115 template <
typename T>
116 static int ExportBinaryTable(std::string fname, std::vector<std::vector<T>>& data);
119 static bool fileExists(
const std::string& filename);
120 static bool isRootFile(
const std::string& filename);
121 static bool isRunFile(
const std::string& filename);
122 static bool isDataSet(
const std::string& filename);
123 static bool isURL(
const std::string& filename);
128 static std::vector<std::string>
GetSubdirectories(
const std::string& path,
int recursion = -1);
129 static std::pair<std::string, std::string>
SeparatePathAndName(
const std::string& fullname);
130 static std::string
GetPureFileName(
const std::string& fullPathFileName);
131 static std::string
SearchFileInPath(std::vector<std::string> path, std::string filename);
135 static std::istream&
GetLine(std::istream& is, std::string& t);
137 static std::string
Execute(std::string cmd);
139 static std::string
DownloadRemoteFile(
const std::string& remoteFile,
bool pidPrefix =
false);
141 static int UploadToServer(std::string localFile, std::string remoteFile, std::string methodUrl =
"");
143 static std::string
POSTRequest(
const std::string& url,
const std::map<std::string, std::string>& keys);
144 static void ChangeDirectory(
const std::string& toDirectory);
149namespace REST_InitTools {
159inline bool CanOverwrite(T* name,
int level) {
167inline void SetInitLevel(T* name,
int level) {
168 GlobalVarInit<T>::level = level;
175#define MakeGlobal(classname, objName, level) \
176 struct __##classname##_Init { \
177 __##classname##_Init() { \
178 REST_ARGS[#objName] = #classname; \
179 if ((objName) != nullptr) { \
180 if (REST_InitTools::CanOverwrite(objName, level)) { \
182 (objName) = new classname(); \
183 REST_InitTools::SetInitLevel(objName, level); \
186 (objName) = new classname(); \
187 REST_InitTools::SetInitLevel(objName, level); \
191 const __##classname##_Init classname##_Init;
195enum Quantities { ENERGY, LENGTH, TIME };
198 ValueWithQuantity(
double value, Quantities quantity) : fValue(value), fQuantity(quantity){};
199 double GetValue()
const {
return fValue; }
200 std::string ToString()
const;
202 inline operator std::string()
const {
return ToString(); }
206 const Quantities fQuantity;
209inline std::string ToEnergyString(
double value) {
return (std::string)
ValueWithQuantity(value, ENERGY); }
210inline std::string ToTimeString(
double value) {
return (std::string)
ValueWithQuantity(value, TIME); }
211inline std::string ToLengthString(
double value) {
return (std::string)
ValueWithQuantity(value, LENGTH); }
213std::string ToTimeStringLong(
double value);
215inline std::string VectorToString(
const TVector3& v) {
216 return TString::Format(
"(%0.3f, %0.3f, %0.3f)", v.X(), v.Y(), v.Z()).Data();
219inline std::string VectorToString(
const TVector2& v) {
220 return TString::Format(
"(%0.3f, %0.3f)", v.X(), v.Y()).Data();