BmnRoot 26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Loading...
Searching...
No Matches
check_event_count.C
Go to the documentation of this file.
1R__ADD_INCLUDE_PATH($VMCWORKDIR)
2#include "function_set.h"
3
4// function for walking and checking ROOT files in a given directory (and all subdirectories),
5// whether their event count is corresponding the number in BM@N Database
6// returns the success code: 0 - without errors, error_code - otherwise
7int check_event_count(TString dir_name, int period_number, double tolerance_percent = 0)
8{
9 gSystem->ExpandPathName(dir_name);
10 TSystemDirectory dir(dir_name.Data(), dir_name.Data());
11 TList* file_list = dir.GetListOfFiles();
12 if (file_list == nullptr) {
13 cout << "WARNING: There are no files in the directory: " << dir_name << endl;
14 return 0;
15 }
16
17 int find_count = 0, total_count = 0;
18 TSystemFile* cur_file;
19 TIter iterFile(file_list);
20 while ((cur_file = (TSystemFile*)iterFile.Next())) {
21 TString file_name = cur_file->GetName();
22 if ((file_name == ".") || (file_name == ".."))
23 continue;
24
25 TString file_dir = cur_file->GetTitle();
26 if (cur_file->IsDirectory()) {
27 check_event_count(file_dir, period_number, tolerance_percent);
28 } // if directory
29 else
30 {
31 TString file_path = file_dir + "/" + file_name;
32 if (file_name.EndsWith(".root")) {
33 total_count++;
34
35 // parse run number from the current file name
36 string strRunNumber = find_last_number(file_name.Data());
37 if (strRunNumber == "") {
38 cout << "WARNING: No run number was found in the file name: " << file_path << endl;
39 continue;
40 }
41 int run_number = stoi(strRunNumber);
42
43 // get number of entries (events) in the file
44 int file_event_count = MpdGetNumEvents::GetNumROOTEvents(file_path.Data(), "", 0);
45
46 // get run from the Database
47 UniRun* pRun = UniRun::GetRun(period_number, run_number);
48 if (pRun != nullptr) {
49 int* p_db_event_count = pRun->GetEventCount();
50 if (p_db_event_count == nullptr) {
51 cout << "WARNING: The event count for run number " << period_number << ":" << run_number
52 << " is not stored in the database" << endl;
53 delete pRun;
54 continue;
55 }
56 int db_event_count = *p_db_event_count;
57
58 if (TMath::Abs(db_event_count - file_event_count) > tolerance_percent / 100.0 * db_event_count) {
59 cout << "ATTENTION: The event count in the file (" << file_path << ") = " << file_event_count
60 << ", but in BM@N database = " << db_event_count << endl;
61 find_count++;
62 }
63 delete pRun;
64 } else
65 cout << "WARNING: The run number " << period_number << ":" << run_number
66 << " was not found in the database for the file: " << file_path << endl;
67 } // if (file_name.EndsWith(".data"))
68 } // if not a directory
69 } // while file list
70
71 if (find_count > 0)
72 cout << endl
73 << find_count << " files (from " << total_count
74 << ") have event count being different from the value in the Database (dir: " << dir_name << ")" << endl;
75 else
76 cout << endl
77 << "There are no deviations in event count for " << total_count << " processed files (dir: " << dir_name
78 << ")" << endl;
79
80 return 0;
81}
#define R__ADD_INCLUDE_PATH(PATH)
R__EXTERN TSystem * gSystem
static Int_t GetNumROOTEvents(const char *filename, const char *treename="", int iVerbose=2)
TObject * Next()
const char * GetName() const override
const char * GetTitle() const override
const char * Data() const
virtual TList * GetListOfFiles() const
virtual Bool_t IsDirectory(const char *dir=nullptr) const
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
int * GetEventCount()
get event count of the current run
Definition UniRun.h:129
int check_event_count(TString dir_name, int period_number, double tolerance_percent=0)
string find_last_number(string const &str, bool isOnlyPositive=true)
Double_t Abs(Double_t d)