BmnRoot 26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Loading...
Searching...
No Matches
write_checksum_db.C
Go to the documentation of this file.
1// function to calculate hash values for files whose paths stored in the Database
2// returns the success code: 0 - without errors, error_code - otherwise
3int write_checksum_db(int period_number, bool isSkipExisted = true)
4{
5 UniqueRunNumber* run_numbers;
6 int run_count = UniRunPeriod::GetRunNumbers(run_numbers, period_number), iter_count = 0;
7 if (run_count <= 0) {
8 cout << "ERROR: runs do not exist in the Database for period " << period_number << endl;
9 return -1;
10 }
11
12 bool isError = false;
13 for (int i = 0; i < run_count; i++) {
14 // get run time
15 UniRun* pRun = UniRun::GetRun(run_numbers[i].period_number, run_numbers[i].run_number);
16 if (pRun == nullptr) {
17 cout << "The function encountered with errors: no experimental run was found ("
18 << run_numbers[i].period_number << ":" << run_numbers[i].run_number << "). This run will be skipped!"
19 << endl;
20 isError = true;
21 continue;
22 }
23 if ((isSkipExisted) && (pRun->GetFileHash() != nullptr))
24 continue;
25
26 TString strFilePath = pRun->GetFilePath();
27 gSystem->ExpandPathName(strFilePath);
28
29 if (gSystem->AccessPathName(strFilePath.Data())) {
30 isError = true;
31 cout << "ERROR: raw file does not exist: " << strFilePath << endl;
32 } else {
33 TString strFileHash = UniRawFile::CalculateFileHash(raw_root_file);
34 if (strFileHash == "") {
35 isError = true;
36 cout << "ERROR: a problem occured while opening file: " << strFilePath << endl;
37 continue;
38 }
39 cout << "File: " << strFilePath << ". File checksum = " << strFileHash << endl;
40 int res_code = pRun->SetFileHash(&strFileHash);
41 if (res_code != 0)
42 isError = true;
43 else
44 iter_count++;
45 }
46 }
47
48 if (isError)
49 cout << endl << "There are some errors occured!" << endl;
50 cout << "Checksums were written for " << iter_count << " of " << run_count << " files" << endl;
51
52 return 0;
53}
54
55int write_sim_checksum_db(bool isSkipExisted = true)
56{
58
59 bool isError = false;
60 int file_count = simulation_files->GetEntriesFast(), iter_count = 0;
61 for (int i = 0; i < file_count; i++) {
62 UniSimulationFile* pFile = (UniSimulationFile*)simulation_files->At(i);
63 if ((isSkipExisted) && (pFile->GetFileHash() != nullptr))
64 continue;
65
66 TString strFilePath = pFile->GetFilePath();
67 gSystem->ExpandPathName(strFilePath);
68
69 if (gSystem->AccessPathName(strFilePath.Data())) {
70 isError = true;
71 cout << "ERROR: simulation file does not exist: " << strFilePath << endl;
72 } else {
73 TString strFileHash = UniRawFile::CalculateFileHash(raw_root_file);
74 if (strFileHash == "") {
75 isError = true;
76 cout << "ERROR: a problem occured while opening file: " << strFilePath << endl;
77 continue;
78 }
79 cout << "File: " << strFilePath << ". File checksum = " << strFileHash << endl;
80 int res_code = pRun->SetFileHash(&strFileHash);
81 if (res_code != 0)
82 isError = true;
83 else
84 iter_count++;
85 }
86 }
87
88 // clean memory after work - deleting the array of simulation files
89 simulation_files->Delete();
90 delete simulation_files;
91
92 if (isError)
93 cout << endl << "There are some errors occured!" << endl;
94 cout << "Checksums were written for " << iter_count << " of " << file_count << " files" << endl;
95
96 return 0;
97}
int i
Definition P4_F32vec4.h:22
R__EXTERN TSystem * gSystem
Int_t GetEntriesFast() const
void Delete(Option_t *option="") override
TObject * At(Int_t idx) const override
const char * Data() const
static TString CalculateFileHash(TString file_path)
calculate and return (in hex string format) cheсksum for a given file use Adler32 algorithm if zlib l...
static int GetRunNumbers(UniqueRunNumber *&run_numbers, int period_number)
get numbers of runs existing in the Database for a selected period
UniRun.h Class for the table: run_.
Definition UniRun.h:21
static UniRun * GetRun(int period_number, int run_number)
get run from the database
Definition UniRun.cxx:161
UniSimulationFile.h Class for the table: simulation_file.
TString GetFilePath()
get file path of the current simulation file
static TObjArray * GetSimulationFiles()
get array of all UniSimulationFile-s from the database
TString * GetFileHash()
get file hash of the current simulation file
int write_checksum_db(int period_number, bool isSkipExisted=true)
int write_sim_checksum_db(bool isSkipExisted=true)