BmnRoot
26.10.0-19-g6979a6c6
Software framework of the BM@N experiment
Toggle main menu visibility
Loading...
Searching...
No Matches
del_files_not_in_db.C
Go to the documentation of this file.
1
#include "../../function_set.h"
2
3
// function for recursively deleting all *.data files in a given directory (and all subdirectories)
4
// which are absent in the Unified Condition Database for a given run
5
// returns the success code: 0 - without errors, error_code - otherwise
6
int
del_files_not_in_db
(
TString
dir_name,
int
period_number,
double
limit_size_in_mb = 0,
bool
isOnlyShow =
true
)
7
{
8
gSystem
->ExpandPathName(dir_name);
9
TSystemDirectory
dir(dir_name.
Data
(), dir_name.
Data
());
10
TList
* file_list = dir.
GetListOfFiles
();
11
if
(file_list ==
nullptr
) {
12
cout <<
"WARNING: There are no files in the directory: "
<< dir_name << endl;
13
return
0;
14
}
15
16
int
del_count = 0;
17
TSystemFile
* cur_file;
18
TIter
iterFile(file_list);
19
while
((cur_file = (
TSystemFile
*)iterFile.
Next
())) {
20
TString
file_name = cur_file->
GetName
();
21
if
((file_name ==
"."
) || (file_name ==
".."
))
22
continue
;
23
24
TString
file_dir = cur_file->
GetTitle
();
25
if
(cur_file->
IsDirectory
()) {
26
del_files_not_in_db
(file_dir, period_number, limit_size_in_mb, isOnlyShow);
27
}
// if directory
28
else
29
{
30
TString
file_path = file_dir +
"/"
+ file_name;
31
if
(file_name.EndsWith(
".data"
)) {
32
// parse run number from the current file name
33
string
strRunNumber =
find_last_number
(file_name.Data());
34
if
(strRunNumber ==
""
) {
35
cout <<
"WARNING: No run number was found in the file name: "
<< file_path << endl;
36
continue
;
37
}
38
int
run_number = stoi(strRunNumber);
39
40
// get run from the Database
41
UniRun
* pRun =
UniRun::GetRun
(period_number, run_number);
42
if
(pRun ==
nullptr
) {
43
Long64_t
size = 0;
44
Long_t
id
= 0, flags = 0, modtime = 0;
45
gSystem
->GetPathInfo(file_path.
Data
(), &
id
, &size, &flags, &modtime);
46
47
double
dFileSize = size / 1024.0 / 1024.0;
48
if
((limit_size_in_mb != 0) && (dFileSize > limit_size_in_mb))
49
continue
;
50
51
cout <<
"ATTENTION: Run "
<< period_number <<
":"
<< run_number
52
<<
" has not been found in the Database"
53
<<
" ("
<< file_path <<
", "
<< dFileSize <<
" MB)"
<< endl;
54
if
(!isOnlyShow) {
55
gSystem
->Unlink(file_path);
56
cout <<
"ATTENTION: The file has been deleted: "
<< file_path << endl << endl;
57
}
58
del_count++;
59
}
else
60
delete
pRun;
61
}
// if (file_name.EndsWith(".data"))
62
}
// if not a directory
63
}
// while file list
64
65
if
(del_count > 0) {
66
if
(isOnlyShow)
67
cout << endl
68
<< del_count <<
" files have been found which are absent in the Database (dir: "
<< dir_name <<
")"
69
<< endl;
70
else
71
cout << endl
72
<< del_count <<
" files have been deleted which are absent in the Database (dir: "
<< dir_name <<
")"
73
<< endl;
74
}
75
76
return
0;
77
}
Long_t
long Long_t
Long64_t
long long Long64_t
gSystem
R__EXTERN TSystem * gSystem
TIter
TIter::Next
TObject * Next()
TList
TNamed::GetName
const char * GetName() const override
TNamed::GetTitle
const char * GetTitle() const override
TString
TString::Data
const char * Data() const
TSystemDirectory
TSystemDirectory::GetListOfFiles
virtual TList * GetListOfFiles() const
TSystemFile
TSystemFile::IsDirectory
virtual Bool_t IsDirectory(const char *dir=nullptr) const
UniRun
UniRun.h Class for the table: run_.
Definition
UniRun.h:21
UniRun::GetRun
static UniRun * GetRun(int period_number, int run_number)
get run from the database
Definition
UniRun.cxx:161
del_files_not_in_db
int del_files_not_in_db(TString dir_name, int period_number, double limit_size_in_mb=0, bool isOnlyShow=true)
Definition
del_files_not_in_db.C:6
find_last_number
string find_last_number(string const &str, bool isOnlyPositive=true)
Definition
function_set.h:484
database
uni_db
examples
raw
del_files_not_in_db.C
Generated on
for BmnRoot by
1.17.0