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
45const std::string PARAMETER_NOT_FOUND_STR =
"NO_SUCH_PARA";
46const double PARAMETER_NOT_FOUND_DBL = -99999999;
48EXTERN_DEF std::string REST_COMMIT;
49EXTERN_DEF std::string REST_PATH;
50EXTERN_DEF std::string REST_USER;
51EXTERN_DEF std::string REST_USER_PATH;
52EXTERN_DEF std::string REST_TMP_PATH;
53EXTERN_DEF std::map<std::string, std::string> REST_ARGS;
58 static std::vector<std::string>
GetOptions(std::string optionsStr);
62 static int ReadASCIITable(std::string fName, std::vector<std::vector<Double_t>>& data,
63 Int_t skipLines = 0, std::string separator =
"\t");
64 static int ReadASCIITable(std::string fName, std::vector<std::vector<Float_t>>& data, Int_t skipLines = 0,
65 std::string separator =
"\t");
66 static int ReadASCIITable(std::string fName, std::vector<std::vector<std::string>>& data,
67 Int_t skipLines = 0, std::string separator =
"\t");
69 static int ReadCSVFile(std::string fName, std::vector<std::vector<Double_t>>& data, Int_t skipLines = 0);
70 static int ReadCSVFile(std::string fName, std::vector<std::vector<Float_t>>& data, Int_t skipLines = 0);
76 static int ReadBinaryTable(std::string fName, std::vector<std::vector<T>>& data, Int_t columns = -1);
98 static std::vector<T>
GetColumnFromTable(
const std::vector<std::vector<T>>& data,
unsigned int column);
100 template <
typename T>
101 static int PrintTable(std::vector<std::vector<T>> data, Int_t start = 0, Int_t end = 0);
103 template <
typename T>
104 static int ExportASCIITable(std::string fname, std::vector<std::vector<T>>& data);
106 template <
typename T>
107 static int ExportBinaryTable(std::string fname, std::vector<std::vector<T>>& data);
110 static bool fileExists(
const std::string& filename);
111 static bool isRootFile(
const std::string& filename);
112 static bool isRunFile(
const std::string& filename);
113 static bool isDataSet(
const std::string& filename);
114 static bool isURL(
const std::string& filename);
119 static std::vector<std::string>
GetSubdirectories(
const std::string& path,
int recursion = -1);
120 static std::pair<std::string, std::string>
SeparatePathAndName(
const std::string& fullname);
121 static std::string
GetPureFileName(
const std::string& fullPathFileName);
122 static std::string
SearchFileInPath(std::vector<std::string> path, std::string filename);
126 static std::istream&
GetLine(std::istream& is, std::string& t);
128 static std::string
Execute(std::string cmd);
130 static std::string
DownloadRemoteFile(
const std::string& remoteFile,
bool pidPrefix =
false);
132 static int UploadToServer(std::string localFile, std::string remoteFile, std::string methodUrl =
"");
134 static std::string
POSTRequest(
const std::string& url,
const std::map<std::string, std::string>& keys);
135 static void ChangeDirectory(
const std::string& toDirectory);
140namespace REST_InitTools {
150inline bool CanOverwrite(T* name,
int level) {
158inline void SetInitLevel(T* name,
int level) {
159 GlobalVarInit<T>::level = level;
166#define MakeGlobal(classname, objName, level) \
167 struct __##classname##_Init { \
168 __##classname##_Init() { \
169 REST_ARGS[#objName] = #classname; \
170 if ((objName) != nullptr) { \
171 if (REST_InitTools::CanOverwrite(objName, level)) { \
173 (objName) = new classname(); \
174 REST_InitTools::SetInitLevel(objName, level); \
177 (objName) = new classname(); \
178 REST_InitTools::SetInitLevel(objName, level); \
182 const __##classname##_Init classname##_Init;
186enum Quantities { ENERGY, LENGTH, TIME };
189 ValueWithQuantity(
double value, Quantities quantity) : fValue(value), fQuantity(quantity){};
190 double GetValue()
const {
return fValue; }
191 std::string ToString()
const;
193 inline operator std::string()
const {
return ToString(); }
197 const Quantities fQuantity;
200inline std::string ToEnergyString(
double value) {
return (std::string)
ValueWithQuantity(value, ENERGY); }
201inline std::string ToTimeString(
double value) {
return (std::string)
ValueWithQuantity(value, TIME); }
202inline std::string ToLengthString(
double value) {
return (std::string)
ValueWithQuantity(value, LENGTH); }
204std::string ToTimeStringLong(
double value);
206inline std::string VectorToString(
const TVector3& v) {
207 return TString::Format(
"(%0.3f, %0.3f, %0.3f)", v.X(), v.Y(), v.Z()).Data();
210inline std::string VectorToString(
const TVector2& v) {
211 return TString::Format(
"(%0.3f, %0.3f)", v.X(), v.Y()).Data();