23#ifndef RestCore_TRestTools
24#define RestCore_TRestTools
35#define UNUSED(x) (void)x
38#define EXTERN_DEF __declspec(dllimport)
39#define EXTERN_IMP __declspec(dllexport)
41#define EXTERN_DEF extern
49const std::string PARAMETER_NOT_FOUND_STR =
"NO_SUCH_PARA";
50const double PARAMETER_NOT_FOUND_DBL = -99999999;
52EXTERN_DEF std::string REST_COMMIT;
53EXTERN_DEF std::string REST_PATH;
54EXTERN_DEF std::string REST_USER;
55EXTERN_DEF std::string REST_USER_PATH;
56EXTERN_DEF std::string REST_TMP_PATH;
57EXTERN_DEF std::map<std::string, std::string> REST_ARGS;
62 static std::vector<std::string>
GetOptions(std::string optionsStr);
66 static int ReadASCIITable(std::string fName, std::vector<std::vector<Double_t>>& data,
67 Int_t skipLines = 0, std::string separator =
"\t");
68 static int ReadASCIITable(std::string fName, std::vector<std::vector<Float_t>>& data, Int_t skipLines = 0,
69 std::string separator =
"\t");
70 static int ReadASCIITable(std::string fName, std::vector<std::vector<std::string>>& data,
71 Int_t skipLines = 0, std::string separator =
"\t");
73 static int ReadCSVFile(std::string fName, std::vector<std::vector<Double_t>>& data, Int_t skipLines = 0);
74 static int ReadCSVFile(std::string fName, std::vector<std::vector<Float_t>>& data, Int_t skipLines = 0);
80 static int ReadBinaryTable(std::string fName, std::vector<std::vector<T>>& data, Int_t columns = -1);
87 bool removeDuplicates =
true);
100 template <
typename T>
103 template <
typename T>
104 static std::vector<T>
GetColumnFromTable(
const std::vector<std::vector<T>>& data,
unsigned int column);
106 template <
typename T>
107 static int PrintTable(std::vector<std::vector<T>> data, Int_t start = 0, Int_t end = 0);
109 template <
typename T>
110 static int ExportASCIITable(std::string fname, std::vector<std::vector<T>>& data);
112 template <
typename T>
113 static int ExportBinaryTable(std::string fname, std::vector<std::vector<T>>& data);
116 static bool fileExists(
const std::string& filename);
117 static bool isRootFile(
const std::string& filename);
118 static bool isRunFile(
const std::string& filename);
119 static bool isDataSet(
const std::string& filename);
120 static bool isURL(
const std::string& filename);
125 static std::vector<std::string>
GetSubdirectories(
const std::string& path,
int recursion = -1);
126 static std::pair<std::string, std::string>
SeparatePathAndName(
const std::string& fullname);
127 static std::string
GetPureFileName(
const std::string& fullPathFileName);
128 static std::string
SearchFileInPath(std::vector<std::string> path, std::string filename);
132 static std::istream&
GetLine(std::istream& is, std::string& t);
134 static std::string
Execute(std::string cmd);
136 static std::string
DownloadRemoteFile(
const std::string& remoteFile,
bool pidPrefix =
false);
138 static int UploadToServer(std::string localFile, std::string remoteFile, std::string methodUrl =
"");
140 static std::string
POSTRequest(
const std::string& url,
const std::map<std::string, std::string>& keys);
141 static void ChangeDirectory(
const std::string& toDirectory);
146namespace REST_InitTools {
156inline bool CanOverwrite(T* name,
int level) {
164inline void SetInitLevel(T* name,
int level) {
165 GlobalVarInit<T>::level = level;
172#define MakeGlobal(classname, objName, level) \
173 struct __##classname##_Init { \
174 __##classname##_Init() { \
175 REST_ARGS[#objName] = #classname; \
176 if ((objName) != nullptr) { \
177 if (REST_InitTools::CanOverwrite(objName, level)) { \
179 (objName) = new classname(); \
180 REST_InitTools::SetInitLevel(objName, level); \
183 (objName) = new classname(); \
184 REST_InitTools::SetInitLevel(objName, level); \
188 const __##classname##_Init classname##_Init;
192enum Quantities { ENERGY, LENGTH, TIME };
195 ValueWithQuantity(
double value, Quantities quantity) : fValue(value), fQuantity(quantity){};
196 double GetValue()
const {
return fValue; }
197 std::string ToString()
const;
199 inline operator std::string()
const {
return ToString(); }
203 const Quantities fQuantity;
206inline std::string ToEnergyString(
double value) {
return (std::string)
ValueWithQuantity(value, ENERGY); }
207inline std::string ToTimeString(
double value) {
return (std::string)
ValueWithQuantity(value, TIME); }
208inline std::string ToLengthString(
double value) {
return (std::string)
ValueWithQuantity(value, LENGTH); }
210std::string ToTimeStringLong(
double value);
212inline std::string VectorToString(
const TVector3& v) {
213 return TString::Format(
"(%0.3f, %0.3f, %0.3f)", v.X(), v.Y(), v.Z()).Data();
216inline std::string VectorToString(
const TVector2& v) {
217 return TString::Format(
"(%0.3f, %0.3f)", v.X(), v.Y()).Data();