|
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 106 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. | |
| 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. | |
| static int | DownloadRemoteFile (std::string remoteFile, std::string localFile) |
| download the remote file to the given local address. | |
| 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. | |
| 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. | |
| 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. | |
| static std::string | GetFileNameExtension (const std::string &fullname) |
| Gets the file extension as the substring found after the latest ".". | |
| static std::string | GetFileNameRoot (const std::string &fullname) |
| Gets the filename root as the substring found before the latest ".". | |
| 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. | |
| 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. | |
| 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. | |
| static std::set< std::string > | GetMatchingStrings (const std::vector< std::string > &stack, const std::vector< std::string > &wantedStrings) |
| Returns a set of strings that match the wanted strings from the stack. The wanted strings can contain wildcards "*" and "?". | |
| 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. | |
| 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. | |
| static std::vector< std::string > | GetObservablesInString (const std::string &observablesStr, bool removeDuplicates=true) |
| Returns a vector with the observables names found in the input string. The observables names must contain the character "_" to be identified as such. e.g. Input: "x1_x2 + x3 - x4*y_z". Output: {"x1_x2", "y_z"} Input: "hitsAna_xMean*hitsAna_xMean+hitsAna_yMean*hitsAna_yMean<100" and true,. | |
| static std::vector< std::string > | GetOptions (std::string optionsStr) |
| Returns all the options in an option string. | |
| static std::string | GetPureFileName (const std::string &fullPathFileName) |
| Removes all directories in the full path filename description given in the argument. | |
| 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. | |
| 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 | IsRemoteRootPath (const std::string &filename) |
| Returns true when ROOT resolves filename to a non-local protocol. | |
| 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. | |
| static bool | MergeRootFilesTransactionally (const std::string &outputFile, const std::vector< std::string > &inputFiles, const std::string &existingTarget="", bool removeInputsOnSuccess=true, std::string *error=nullptr) |
| Merge REST worker outputs using a validated candidate and rollback backup. | |
| 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. | |
| 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. | |
| 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. | |
| static int | ReadASCIITable (std::string fName, std::vector< std::vector< std::string > > &data, Int_t skipLines=0, std::string separator="\t") |
| 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. | |
| 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. | |
| 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. | |
| static std::string | RemoveMultipleSlash (std::string) |
| Returns the input string but without multiple slashes ("/"). | |
| 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. | |
| 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 2197 of file TRestTools.cxx.
|
static |
Definition at line 2187 of file TRestTools.cxx.
|
static |
Checks if the config file can be opened (and thus exists). It returns true in case of success, false otherwise.
Definition at line 1821 of file TRestTools.cxx.
|
static |
Convert version to a unique string.
Definition at line 1903 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 1989 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 2030 of file TRestTools.cxx.
|
static |
Executes a shell command and returns its output in a string.
Definition at line 1926 of file TRestTools.cxx.
|
static |
Writes the contents of the vector table given as argument to fname. Allowed types are Int_t, Float_t and Double_t.
Definition at line 818 of file TRestTools.cxx.
|
static |
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.
Definition at line 847 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 1361 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 948 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 1127 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 1639 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 1650 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 1841 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 1105 of file TRestTools.cxx.
|
static |
It reads the next line from the incoming istream and puts it in the string argument t. The remaining istream is returned.
Definition at line 1952 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 1075 of file TRestTools.cxx.
|
static |
Returns a set of strings that match the wanted strings from the stack. The wanted strings can contain wildcards "*" and "?".
| stack | vector of strings to be searched |
| wantedStrings | vector of strings with the wanted strings to be matched. |
Definition at line 1689 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 1003 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 1038 of file TRestTools.cxx.
|
static |
Returns a vector with the observables names found in the input string. The observables names must contain the character "_" to be identified as such. e.g. Input: "x1_x2 + x3 - x4*y_z". Output: {"x1_x2", "y_z"} Input: "hitsAna_xMean*hitsAna_xMean+hitsAna_yMean*hitsAna_yMean<100" and true,.
Input: "hitsAna_xMean*hitsAna_xMean+hitsAna_yMean*hitsAna_yMean<100" and false, Output: {"hitsAna_xMean", "hitsAna_xMean", "hitsAna_yMean", "hitsAna_yMean"}
Definition at line 1663 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 720 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 1728 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 1769 of file TRestTools.cxx.
|
static |
Check if the path is absolute path or not.
Definition at line 1611 of file TRestTools.cxx.
|
static |
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.
Definition at line 936 of file TRestTools.cxx.
|
static |
It checks if the file contains a dataset object.
Definition at line 1387 of file TRestTools.cxx.
|
static |
Returns true if the path given by argument is writable.
Definition at line 1594 of file TRestTools.cxx.
|
static |
Returns true when ROOT resolves filename to a non-local protocol.
Definition at line 1413 of file TRestTools.cxx.
|
static |
Returns true if the filename has .root extension.
Definition at line 1366 of file TRestTools.cxx.
|
static |
It checks if the file has been processed using a REST event processing chain.
Definition at line 1371 of file TRestTools.cxx.
|
static |
Returns true if filename is an http address.
Definition at line 1405 of file TRestTools.cxx.
|
static |
Returns true if the file with path filename exists.
Definition at line 1352 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 729 of file TRestTools.cxx.
|
static |
Merge REST worker outputs using a validated candidate and rollback backup.
Merge into a same-directory temporary ROOT file and replace the local destination only after the merge and StreamerInfo validation succeed.
existingTarget, when non-empty, seeds the temporary output and is opened through the checked UPDATE path; only inputFiles are then merged into it. Remote inputs are supported by ROOT, but outputFile must resolve to a local file URL/path. Local inputFiles are removed only after a successful replacement when removeInputsOnSuccess is true.
TFileMerger retains the existing merge semantics: workers combine with each other and replace matching objects in existingTarget; target-only objects stay. Inventory schemas/rules and content first, copy existingTarget (if supplied) to a sibling candidate, merge there, and validate before and after installation. A failed installed-result check restores the old output or removes a new one. Only after successful validation are backup and, optionally, inputs removed.
The candidate copies the whole existing output, not just worker objects; disk and I/O overhead therefore scale with output size. POSIX backups normally use a hard link, with a full-copy fallback. Structural validation does not compare event values. This is not a writer lock or a power-loss durability guarantee. Returns false with an error on failure, including cleanup failures after a valid output is installed; rollback failures identify the retained backup.
Definition at line 1451 of file TRestTools.cxx.
|
static |
It performs a POST web protocol request using a set of keys and values given by argument, and returns the result as a string.
Definition at line 2088 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 796 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 1210 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 1269 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 886 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 1328 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 1345 of file TRestTools.cxx.
|
static |
Returns the input string but without multiple slashes ("/").
| str | input path string (e.g. "///home///test/") |
Definition at line 1709 of file TRestTools.cxx.
|
static |
Search file in the given vector of path strings, return a full name if found, return "" if not.
Definition at line 1794 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 1629 of file TRestTools.cxx.
|
static |
It takes a path and returns its absolute path.
Definition at line 1733 of file TRestTools.cxx.
|
static |
It transposes the std::vector<std::vector> table given in the argument. It will transform rows in columns.
Definition at line 978 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 2150 of file TRestTools.cxx.