REST-for-Physics
v2.3
Rare Event Searches ToolKit for Physics
|
A generic class with useful static methods.
TRestTools is a class that defines static methods that might be handy when accessing files or system utilities, or other basic methods that do not fit in a specialized class, and are generic enought to be considered a REST tool.
RESTsoft - Software for Rare Event Searches with TPCs
History of developments:
2016-December: First concept. Javier Galan
Definition at line 60 of file TRestTools.h.
#include <TRestTools.h>
Static Public Member Functions | |
static std::vector< int > | CanvasDivisions (int n) |
It returns a vector with 2 components {a,b}, the components satisfy that a x b = n , being the ratio a/b as close to 1 as possible. More... | |
static void | ChangeDirectory (const std::string &toDirectory) |
static bool | CheckFileIsAccessible (const std::string &) |
Checks if the config file can be opened (and thus exists). It returns true in case of success, false otherwise. | |
static int | ConvertVersionCode (std::string in) |
Convert version to a unique string. | |
static std::string | DownloadRemoteFile (const std::string &remoteFile, bool pidPrefix=false) |
download the remote file automatically, returns the downloaded file name. More... | |
static int | DownloadRemoteFile (std::string remoteFile, std::string localFile) |
download the remote file to the given local address. More... | |
static std::string | Execute (std::string cmd) |
Executes a shell command and returns its output in a string. | |
template<typename T > | |
static int | ExportASCIITable (std::string fname, std::vector< std::vector< T >> &data) |
Writes the contents of the vector table given as argument to fname . Allowed types are Int_t, Float_t and Double_t. | |
template<typename T > | |
static int | ExportBinaryTable (std::string fname, std::vector< std::vector< T >> &data) |
Writes the contents of the vector table given as argument to fname as a binary file. Allowed types are Int_t, Float_t and Double_t. | |
static bool | fileExists (const std::string &filename) |
Returns true if the file (or directory) with path filename exists. More... | |
static int | GetBinaryFileColumns (std::string fname) |
It extracts the number of columns from the filename extension given by argument. The file should contain a binary formatted table with a fixed number of rows and columns. More... | |
template<typename T > | |
static std::vector< T > | GetColumnFromTable (const std::vector< std::vector< T >> &data, unsigned int column) |
It returns a vector with the values extracted from the particular column inside the data table given by argument. More... | |
static std::string | GetFileNameExtension (const std::string &fullname) |
Gets the file extension as the substring found after the latest ".". More... | |
static std::string | GetFileNameRoot (const std::string &fullname) |
Gets the filename root as the substring found before the latest ".". More... | |
static std::vector< std::string > | GetFilesMatchingPattern (std::string pattern, bool unlimited=false) |
Returns a list of files whose name match the pattern string. Key word is "*". e.g. abc00*.root. More... | |
template<typename T > | |
static T | GetIntegralFromTable (const std::vector< std::vector< T >> &data) |
It returns the lowest increase, different from zero, between the elements of a particular column from the table given by argument. More... | |
static std::istream & | GetLine (std::istream &is, std::string &t) |
It reads the next line from the incoming istream and puts it in the string argument t . The remaining istream is returned. | |
template<typename T > | |
static T | GetLowestIncreaseFromTable (std::vector< std::vector< T >> data, Int_t column) |
It returns the lowest increase, different from zero, between the elements of a particular column from the table given by argument. More... | |
template<typename T > | |
static T | GetMaxValueFromTable (const std::vector< std::vector< T >> &data, Int_t column=-1) |
It returns the maximum value for a particular column from the table given by argument. If no column is specified in the arguments, then it gets the maximum from the full table. More... | |
template<typename T > | |
static T | GetMinValueFromTable (const std::vector< std::vector< T >> &data, Int_t column=-1) |
It returns the minimum value for a particular column from the table given by argument. If no column is specified in the arguments, then it gets the minimum from the full table. More... | |
static std::vector< std::string > | GetOptions (std::string optionsStr) |
Returns all the options in an option string. More... | |
static std::string | GetPureFileName (const std::string &fullPathFileName) |
Removes all directories in the full path filename description given in the argument. More... | |
static std::vector< std::string > | GetSubdirectories (const std::string &path, int recursion=-1) |
It lists all the subdirectories inside path and adds them to the result vector. More... | |
static bool | isAbsolutePath (const std::string &path) |
Check if the path is absolute path or not. | |
static Bool_t | IsBinaryFile (std::string fname) |
It identifies if the filename extension follows the formatting ".Nxyzf", where the number of columns is xyz , and the last character is the type of data (f/d/i), float, double and integer respectively. | |
static bool | isDataSet (const std::string &filename) |
It checks if the file contains a dataset object. | |
static bool | isPathWritable (const std::string &path) |
Returns true if the path given by argument is writable. | |
static bool | isRootFile (const std::string &filename) |
Returns true if the filename has *.root* extension. | |
static bool | isRunFile (const std::string &filename) |
It checks if the file has been processed using a REST event processing chain. | |
static bool | isURL (const std::string &filename) |
Returns true if filename is an http address. | |
static Int_t | isValidFile (const std::string &path) |
Returns true if the file with path filename exists. | |
static void | LoadRESTLibrary (bool silent=false) |
Calls gSystem to load REST library. More... | |
static std::string | POSTRequest (const std::string &url, const std::map< std::string, std::string > &keys) |
It performs a POST web protocol request using a set of keys and values given by argument, and returns the result as a string. | |
template<typename T > | |
static int | PrintTable (std::vector< std::vector< T >> data, Int_t start=0, Int_t end=0) |
Prints the contents of the vector table given as argument in screen. Allowed types are Int_t, Float_t and Double_t. More... | |
static int | ReadASCIITable (std::string fName, std::vector< std::vector< Double_t >> &data, Int_t skipLines=0, std::string separator="\t") |
Reads an ASCII file containing a table with values. More... | |
static int | ReadASCIITable (std::string fName, std::vector< std::vector< Float_t >> &data, Int_t skipLines=0, std::string separator="\t") |
Reads an ASCII file containing a table with values. More... | |
static int | ReadASCIITable (std::string fName, std::vector< std::vector< std::string >> &data, Int_t skipLines=0, std::string separator="\t") |
Reads an ASCII file containing a table with values. More... | |
template<typename T > | |
static int | ReadBinaryTable (std::string fName, std::vector< std::vector< T >> &data, Int_t columns=-1) |
Reads a binary file containing a fixed-columns table with values. More... | |
static int | ReadCSVFile (std::string fName, std::vector< std::vector< Double_t >> &data, Int_t skipLines=0) |
Reads a CSV file containing a table with comma separated values. More... | |
static int | ReadCSVFile (std::string fName, std::vector< std::vector< Float_t >> &data, Int_t skipLines=0) |
Reads a CSV file containing a table with comma separated values. More... | |
static std::string | RemoveMultipleSlash (std::string) |
Returns the input string but without multiple slashes ("/") More... | |
static std::string | SearchFileInPath (std::vector< std::string > path, std::string filename) |
Search file in the given vector of path strings, return a full name if found, return "" if not. | |
static std::pair< std::string, std::string > | SeparatePathAndName (const std::string &fullname) |
Separate path and filename in a full path+filename string, returns a pair of string. More... | |
static std::string | ToAbsoluteName (const std::string &filename) |
It takes a path and returns its absolute path. | |
template<typename T > | |
static void | TransposeTable (std::vector< std::vector< T >> &data) |
It transposes the std::vector<std::vector> table given in the argument. It will transform rows in columns. | |
static int | UploadToServer (std::string localFile, std::string remoteFile, std::string methodUrl="") |
|
static |
It returns a vector with 2 components {a,b}, the components satisfy that a x b = n
, being the ratio a/b as close to 1 as possible.
This method can be used to help dividing a canvas that will contain a number n
of plots.
If n
is a prime number, then the pair generated will be n x 1
.
Definition at line 1332 of file TRestTools.cxx.
|
static |
download the remote file automatically, returns the downloaded file name.
The file name is given in url format, and is parsed by TUrl. Various methods will be used, including scp, wget. Downloads to REST_USER_PATH + "/download/" + filename by default.
Definition at line 1124 of file TRestTools.cxx.
|
static |
download the remote file to the given local address.
The file name is given in url format, and is parsed by TUrl. Various methods will be used, including scp, wget. returns 0 if succeed.
Definition at line 1165 of file TRestTools.cxx.
|
static |
Returns true if the file (or directory) with path filename exists.
This method will return true even if it is a pure path. We should call isValidFile
to check if we will be able to open it without problems.
Definition at line 728 of file TRestTools.cxx.
|
static |
It extracts the number of columns from the filename extension given by argument. The file should contain a binary formatted table with a fixed number of rows and columns.
The filename extension will be : ".Nxyzf", where the number of columns is xyz
, and the last character is the type of data (f/d/i), float, double and integer respectively.
Definition at line 315 of file TRestTools.cxx.
|
static |
It returns a vector with the values extracted from the particular column
inside the data
table given by argument.
This method is available for tables of type Float_t, Double_t and Int_t.
Definition at line 494 of file TRestTools.cxx.
|
static |
Gets the file extension as the substring found after the latest ".".
Input: "/home/jgalan/abc.txt" Output: "txt"
Definition at line 823 of file TRestTools.cxx.
|
static |
Gets the filename root as the substring found before the latest ".".
Input: "/home/jgalan/abc.txt" Output: "abc"
Definition at line 834 of file TRestTools.cxx.
|
static |
Returns a list of files whose name match the pattern string. Key word is "*". e.g. abc00*.root.
Argument unlimited will fix an issue with the number of files being to high. However, it causes issues when searching/listing the macros. The default value for unlimited is false
.
Definition at line 976 of file TRestTools.cxx.
|
static |
It returns the lowest increase, different from zero, between the elements of a particular column
from the table given by argument.
This method is available for tables of type Float_t, Double_t and Int_t.
Definition at line 472 of file TRestTools.cxx.
|
static |
It returns the lowest increase, different from zero, between the elements of a particular column
from the table given by argument.
This method is available for tables of type Float_t, Double_t and Int_t.
Definition at line 442 of file TRestTools.cxx.
|
static |
It returns the maximum value for a particular column
from the table given by argument. If no column is specified in the arguments, then it gets the maximum from the full table.
This method is available for tables of type Float_t, Double_t and Int_t.
Definition at line 370 of file TRestTools.cxx.
|
static |
It returns the minimum value for a particular column
from the table given by argument. If no column is specified in the arguments, then it gets the minimum from the full table.
This method is available for tables of type Float_t, Double_t and Int_t.
Definition at line 405 of file TRestTools.cxx.
|
static |
Returns all the options in an option string.
This method gives string to the method GetFirstOption(). And then adds the result to the list.
Definition at line 86 of file TRestTools.cxx.
|
static |
Removes all directories in the full path filename description given in the argument.
e.g. Input: "/home/nkx/abc.txt", Returns: "abc.txt" Input: "/home/nkx/", Output: ""
Definition at line 863 of file TRestTools.cxx.
|
static |
It lists all the subdirectories inside path and adds them to the result vector.
If recursion is 0, then list only the subdirectory of this directory If recursion is < 0, then list subdirectories recursively
Otherwise recurse only certain times.
Definition at line 904 of file TRestTools.cxx.
|
static |
Calls gSystem to load REST library.
REST library lies in $REST_PATH/lib and $HOME/.rest/userlib/ After this we can use reflection methods TClass::GetClass() and TRestMetadata::GetDataMemberRef()
Definition at line 95 of file TRestTools.cxx.
|
static |
Prints the contents of the vector table given as argument in screen. Allowed types are Int_t, Float_t and Double_t.
The printed out data can be restricted to the row lines between start
and end
parameters given by argument.
Definition at line 163 of file TRestTools.cxx.
|
static |
Reads an ASCII file containing a table with values.
This method will open the file fName. This file should contain a tabulated ASCII table containing numeric values. The values on the table will be loaded in the matrix provided through the argument data
. The content of data
will be cleared in this method.
If any header in the file is present, it should be skipped using the argument skipLines
or preceding any line inside the header using #
.
Only works with Double_t vector since we use StringToDouble method.
Definition at line 577 of file TRestTools.cxx.
|
static |
Reads an ASCII file containing a table with values.
This method will open the file fName. This file should contain a tabulated ASCII table containing numeric values. The values on the table will be loaded in the matrix provided through the argument data
. The content of data
will be cleared in this method.
If any header in the file is present, it should be skipped using the argument skipLines
or preceding any line inside the header using #
.
This version works with Float_t vector since we use StringToFloat method.
Definition at line 636 of file TRestTools.cxx.
|
static |
Reads an ASCII file containing a table with values.
This method will open the file fName. This file should contain a tabulated ASCII table containing any format values. The values on the table will be loaded in the matrix provided through the argument data
. The content of data
will be cleared in this method.
If any header in the file is present, it should be skipped using the argument skipLines
or preceding any line inside the header using #
.
This table will just split the ASCII elements inside a std::string matrix
Definition at line 528 of file TRestTools.cxx.
|
static |
Reads a binary file containing a fixed-columns table with values.
This method will open the file fName. This file should contain a table with numeric values of the type specified inside the syntax < >.
For example, a float number table with 6-columns would be read as follows:
The values on the table will be loaded in the matrix provided through the argument data
. The content of data
will be cleared in this method.
Definition at line 253 of file TRestTools.cxx.
|
static |
Reads a CSV file containing a table with comma separated values.
This method will open the file fName. This file should contain a comma separated table containing numeric values. The values on the table will be loaded in the matrix provided through the argument data
. The content of data
will be cleared in this method.
If any header in the file is present, it should be skipped using the argument skipLines
or preceding any line inside the header using #
.
Only works with Double_t vector since we use StringToDouble method.
Definition at line 695 of file TRestTools.cxx.
|
static |
Reads a CSV file containing a table with comma separated values.
This method will open the file fName. This file should contain a comma separated table containing numeric values. The values on the table will be loaded in the matrix provided through the argument data
. The content of data
will be cleared in this method.
If any header in the file is present, it should be skipped using the argument skipLines
or preceding any line inside the header using #
.
Only works with Float_t vector since we use StringToFloat method.
Definition at line 712 of file TRestTools.cxx.
|
static |
Returns the input string but without multiple slashes ("/")
str | input path string (e.g. "///home///test/") |
Definition at line 844 of file TRestTools.cxx.
|
static |
Separate path and filename in a full path+filename string, returns a pair of string.
if input file name contains no directory, the returned directory is set to "." if input file name contains no file, the returned filename is set to "" e.g. Input: "/home/nkx/abc.txt" and ":def", Output: { "/home/nkx/", "abc.txt" } Input: "abc.txt" and ":", Output: { ".", "abc.txt" } Input: "/home/nkx/" and ":", Output: { "/home/nkx/", "" }
Definition at line 813 of file TRestTools.cxx.
|
static |
Upload the local file to remote file, method url will overwrite the login information inside remotefile.
Example: UploadToServer("/home/nkx/abc.txt", "https://sultan.unizar.es/gasFiles/gases.rml", "ssh://nkx:M123456@:8322") Then, the local file abc.txt will be uploaded to the server, renamed to gases.rml and overwrite it
Definition at line 1285 of file TRestTools.cxx.