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");
67 static int ReadCSVFile(std::string fName, std::vector<std::vector<Double_t>>& data, Int_t skipLines = 0);
68 static int ReadCSVFile(std::string fName, std::vector<std::vector<Float_t>>& data, Int_t skipLines = 0);
74 static int ReadBinaryTable(std::string fName, std::vector<std::vector<T>>& data, Int_t columns = -1);
96 static std::vector<T>
GetColumnFromTable(
const std::vector<std::vector<T>>& data,
unsigned int column);
99 static int PrintTable(std::vector<std::vector<T>> data, Int_t start = 0, Int_t end = 0);
101 template <
typename T>
102 static int ExportASCIITable(std::string fname, std::vector<std::vector<T>>& data);
104 template <
typename T>
105 static int ExportBinaryTable(std::string fname, std::vector<std::vector<T>>& data);
108 static bool fileExists(
const std::string& filename);
109 static bool isRootFile(
const std::string& filename);
110 static bool isRunFile(
const std::string& filename);
111 static bool isDataSet(
const std::string& filename);
112 static bool isURL(
const std::string& filename);
117 static std::vector<std::string>
GetSubdirectories(
const std::string& path,
int recursion = -1);
118 static std::pair<std::string, std::string>
SeparatePathAndName(
const std::string& fullname);
119 static std::string
GetPureFileName(
const std::string& fullPathFileName);
120 static std::string
SearchFileInPath(std::vector<std::string> path, std::string filename);
124 static std::istream&
GetLine(std::istream& is, std::string& t);
126 static std::string
Execute(std::string cmd);
130 static int UploadToServer(std::string localFile, std::string remoteFile, std::string methodUrl =
"");
132 static std::string
POSTRequest(
const std::string& url,
const std::map<std::string, std::string>& keys);
133 static void ChangeDirectory(
const std::string& toDirectory);
136namespace REST_InitTools {
146inline bool CanOverwrite(T* name,
int level) {
154inline void SetInitLevel(T* name,
int level) {
155 GlobalVarInit<T>::level = level;
162#define MakeGlobal(classname, objName, level) \
163 struct __##classname##_Init { \
164 __##classname##_Init() { \
165 REST_ARGS[#objName] = #classname; \
166 if ((objName) != nullptr) { \
167 if (REST_InitTools::CanOverwrite(objName, level)) { \
169 (objName) = new classname(); \
170 REST_InitTools::SetInitLevel(objName, level); \
173 (objName) = new classname(); \
174 REST_InitTools::SetInitLevel(objName, level); \
178 const __##classname##_Init classname##_Init;
182enum Quantities { ENERGY, LENGTH, TIME };
185 ValueWithQuantity(
double value, Quantities quantity) : fValue(value), fQuantity(quantity){};
186 double GetValue()
const {
return fValue; }
187 std::string ToString()
const;
189 inline operator std::string()
const {
return ToString(); }
193 const Quantities fQuantity;
196inline std::string ToEnergyString(
double value) {
return (std::string)
ValueWithQuantity(value, ENERGY); }
197inline std::string ToTimeString(
double value) {
return (std::string)
ValueWithQuantity(value, TIME); }
198inline std::string ToLengthString(
double value) {
return (std::string)
ValueWithQuantity(value, LENGTH); }
200std::string ToTimeStringLong(
double value);
202inline std::string VectorToString(
const TVector3& v) {
203 return TString::Format(
"(%0.3f, %0.3f, %0.3f)", v.X(), v.Y(), v.Z()).Data();
206inline std::string VectorToString(
const TVector2& v) {
207 return TString::Format(
"(%0.3f, %0.3f)", v.X(), v.Y()).Data();