BmnRoot 26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Loading...
Searching...
No Matches
BmnFunctionSet.h
Go to the documentation of this file.
1#ifndef BMNFUNCTIONSET_H
2#define BMNFUNCTIONSET_H 1
3
4// ROOT
5#include "TDatime.h"
6#include "TString.h"
7#include "TSystem.h"
8#include "TTimeStamp.h"
9
10#include <TFile.h>
11
12// STL
13#include <chrono>
14#include <string>
15#include <vector>
16
17using SysClock = std::chrono::system_clock;
18using SysPoint = std::chrono::time_point<SysClock>;
19
20/** Class with static common functions to simplify experiment code **/
22{
23 public:
24 // check whether path is a directory
25 static bool isDirectory(TString path);
26 // check whether file exists: 1 - exists, 0 - not exists, -1 - exists but cannot access with the mode (default:
27 // kFileExists) fileName: file path; iVerbose: 0 - no output, 1 - print errors; mode: check for 'kFileExists', or
28 // has 'kExecutePermission', 'kWritePermission' or 'kReadPermission'
29 static int CheckFileExist(TString& fileName, int iVerbose = 0, EAccessMode mode = kFileExists);
30 // check whether directory exists: 1 - exists, 0 - not exists, -1 - exists but cannot access with the mode (default:
31 // kFileExists)
32 static int CheckDirectoryExist(TString& fileName, int iVerbose = 0, EAccessMode mode = kFileExists);
33 // create directory tree for the file name if not exists: 1 - exists, 0 - created
34 // error codes: -1 - exists but cannot access with the mode (default: kWritePermission), -2 - cannot be created, -3
35 // - empty file name
36 static int CreateDirectoryTree(TString& fileName, int iVerbose = 0, EAccessMode mode = kWritePermission);
37 // get the list of input ROOT files for the given input file, which can be a ROOT file with data, a ROOT file with
38 // a TChain object or a text file (extension is not '.root') with a list of ROOT files:
39 // inputFileName: path to the input file; fileList: returns the list of ROOT files with expanded paths
40 // return value: number of files in the list, < 0 - error codes
41 static int GetInputFileList(TString inputFileName, std::vector<TString>& fileList);
42
43 // define whether ROOT file contains simulation data: 1 - true, 0 - false (experimental data), <0 - some errors
44 // occured if filename is not set then the function checks the current processing
45 static int isSimulationFile(TString fileName = "");
46 // method_number: 0 - find FairRtdbRun with period number name; 1 - use "FileHeader" (FairFileHeader)
47 static int GetPeriodNumber(TFile* root_file, int method_number = 0);
48
49 // parsing file name to define beam, target and energy of the run
50 // the file name is parsed with the '_' separator, if it does not fit then with the '.' separator
51 // file_name: name of the file to parse
52 // result (beam, target, energy (GeV)) returns via links, energy is < 0 in case of errors
53 // return value: 0 - success, < 0 - error codes
54 static Int_t ParseFileName(const TString& file_name, TString& beam, TString& target, Double_t& energy);
55
56 // parsing the geometry tag, which can contain the path to an XML file with a local customization of the setup
57 // (see database/geo_db/examples/README.md) after the ';' separator, e.g. "run9_26.09.0;$VMCWORKDIR/my_setup.xml"
58 // If no XML file is given after the separator then the whole value is considered as the setup tag
59 // geometry_tag: the geometry tag to parse, the parsed setup tag is returned via the same link
60 // local_settings: returns the path to the XML file as given (not expanded, e.g. with $VMCWORKDIR), "" if no file
61 // return value: 0 - success, < 0 - error codes
62 static Int_t ParseGeometryTag(TString& geometry_tag, TString& local_settings);
63
64 // get magnetic field value (mV) for the given beam and its energy (e.g. parsed by ParseFileName)
65 // beam: beam particle name; energy: beam energy (GeV)
66 // return value: magnetic field value (mV), < 0 - in case of errors
67 static double GetMagneticFieldByEnergy(const TString& beam, double energy);
68
69 // get the correction factor for the magnetic field map scale calculated as 'field voltage / map voltage'
70 // energy: beam energy (GeV)
71 // return value: correction factor to multiply the field map scale by, 1 - for the energies without correction
72 static double GetFieldScaleCorrection(double energy);
73
76 static void PrintTimePoint(SysPoint p);
77 static std::string TimePoint2String(SysPoint p);
78 static SysPoint TDatime2GMT(TDatime& tdatime, Int_t timezoneOffsetHours = 0);
79
80 private:
83
84 static TString JoinKeys(const std::vector<std::pair<TString, TString>>& dict);
85 // parsing file name with the given separator (used by ParseFileName)
86 // separator: symbol to split the file name into tokens
87 // return value: 0 - success, < 0 - error codes
88 static Int_t ParseFileNameBySeparator(const TString& file_name,
89 const TString& separator,
90 TString& beam,
91 TString& target,
92 Double_t& energy);
93
95};
96
97#endif
int Int_t
double Double_t
#define ClassDef(name, id)
EAccessMode
kFileExists
kWritePermission
std::chrono::system_clock SysClock
std::chrono::time_point< SysClock > SysPoint
Class with static common functions to simplify experiment code.
static Int_t ParseGeometryTag(TString &geometry_tag, TString &local_settings)
static bool isDirectory(TString path)
static int GetPeriodNumber(TFile *root_file, int method_number=0)
static int CheckFileExist(TString &fileName, int iVerbose=0, EAccessMode mode=kFileExists)
static int CheckDirectoryExist(TString &fileName, int iVerbose=0, EAccessMode mode=kFileExists)
static int isSimulationFile(TString fileName="")
static double GetFieldScaleCorrection(double energy)
static double GetMagneticFieldByEnergy(const TString &beam, double energy)
static std::string TimePoint2String(SysPoint p)
static SysPoint TimeStamp2TP(TTimeStamp p)
static void PrintTimePoint(SysPoint p)
static TString JoinKeys(const std::vector< std::pair< TString, TString > > &dict)
static Int_t ParseFileName(const TString &file_name, TString &beam, TString &target, Double_t &energy)
static int CreateDirectoryTree(TString &fileName, int iVerbose=0, EAccessMode mode=kWritePermission)
static Int_t ParseFileNameBySeparator(const TString &file_name, const TString &separator, TString &beam, TString &target, Double_t &energy)
static int GetInputFileList(TString inputFileName, std::vector< TString > &fileList)
static TTimeStamp TimePoint2TS(SysPoint p)
static SysPoint TDatime2GMT(TDatime &tdatime, Int_t timezoneOffsetHours=0)
std::chrono::time_point< SysClock > SysPoint