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);
101 template <
typename T>
102 static std::vector<T>
GetColumnFromTable(
const std::vector<std::vector<T>>& data,
unsigned int column);
104 template <
typename T>
105 static int PrintTable(std::vector<std::vector<T>> data, Int_t start = 0, Int_t end = 0);
107 template <
typename T>
108 static int ExportASCIITable(std::string fname, std::vector<std::vector<T>>& data);
110 template <
typename T>
111 static int ExportBinaryTable(std::string fname, std::vector<std::vector<T>>& data);
114 static bool fileExists(
const std::string& filename);
115 static bool isRootFile(
const std::string& filename);
116 static bool isRunFile(
const std::string& filename);
117 static bool isDataSet(
const std::string& filename);
118 static bool isURL(
const std::string& filename);
123 static std::vector<std::string>
GetSubdirectories(
const std::string& path,
int recursion = -1);
124 static std::pair<std::string, std::string>
SeparatePathAndName(
const std::string& fullname);
125 static std::string
GetPureFileName(
const std::string& fullPathFileName);
126 static std::string
SearchFileInPath(std::vector<std::string> path, std::string filename);
130 static std::istream&
GetLine(std::istream& is, std::string& t);
132 static std::string
Execute(std::string cmd);
134 static std::string
DownloadRemoteFile(
const std::string& remoteFile,
bool pidPrefix =
false);
136 static int UploadToServer(std::string localFile, std::string remoteFile, std::string methodUrl =
"");
138 static std::string
POSTRequest(
const std::string& url,
const std::map<std::string, std::string>& keys);
139 static void ChangeDirectory(
const std::string& toDirectory);
144namespace REST_InitTools {
154inline bool CanOverwrite(T* name,
int level) {
162inline void SetInitLevel(T* name,
int level) {
163 GlobalVarInit<T>::level = level;
170#define MakeGlobal(classname, objName, level) \
171 struct __##classname##_Init { \
172 __##classname##_Init() { \
173 REST_ARGS[#objName] = #classname; \
174 if ((objName) != nullptr) { \
175 if (REST_InitTools::CanOverwrite(objName, level)) { \
177 (objName) = new classname(); \
178 REST_InitTools::SetInitLevel(objName, level); \
181 (objName) = new classname(); \
182 REST_InitTools::SetInitLevel(objName, level); \
186 const __##classname##_Init classname##_Init;
190enum Quantities { ENERGY, LENGTH, TIME };
193 ValueWithQuantity(
double value, Quantities quantity) : fValue(value), fQuantity(quantity){};
194 double GetValue()
const {
return fValue; }
195 std::string ToString()
const;
197 inline operator std::string()
const {
return ToString(); }
201 const Quantities fQuantity;
204inline std::string ToEnergyString(
double value) {
return (std::string)
ValueWithQuantity(value, ENERGY); }
205inline std::string ToTimeString(
double value) {
return (std::string)
ValueWithQuantity(value, TIME); }
206inline std::string ToLengthString(
double value) {
return (std::string)
ValueWithQuantity(value, LENGTH); }
208std::string ToTimeStringLong(
double value);
210inline std::string VectorToString(
const TVector3& v) {
211 return TString::Format(
"(%0.3f, %0.3f, %0.3f)", v.X(), v.Y(), v.Z()).Data();
214inline std::string VectorToString(
const TVector2& v) {
215 return TString::Format(
"(%0.3f, %0.3f)", v.X(), v.Y()).Data();