74 if (connDb ==
nullptr)
80 "start_datetime, end_datetime, file_path, event_count, file_size, file_hash) "
81 "values ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)");
85 stmt->
SetInt(0, period_number);
86 stmt->
SetInt(1, run_number);
87 stmt->
SetInt(2, start_event);
88 stmt->
SetInt(3, end_event);
92 stmt->
SetInt(7, event_count);
94 if (file_hash ==
nullptr)
101 cout <<
"ERROR: inserting new raw file to the Database has been failed" << endl;
111 TSQLStatement* stmt_last = db_server->
Statement(
"SELECT currval(pg_get_serial_sequence('raw_file','file_id'))");
120 cout <<
"ERROR: no last ID in DB!" << endl;
124 file_id = stmt_last->
GetInt(0);
128 cout <<
"ERROR: getting last ID has been failed!" << endl;
134 tmp_file_id = file_id;
135 int tmp_period_number;
136 tmp_period_number = period_number;
138 tmp_run_number = run_number;
140 tmp_start_event = start_event;
142 tmp_end_event = end_event;
144 tmp_start_datetime = start_datetime;
146 tmp_end_datetime = end_datetime;
148 tmp_file_path = file_path;
150 tmp_event_count = event_count;
151 int64_t tmp_file_size;
152 tmp_file_size = file_size;
154 if (file_hash ==
nullptr)
155 tmp_file_hash =
nullptr;
157 tmp_file_hash =
new TString(*file_hash);
159 return new UniRawFile(connDb, tmp_file_id, tmp_period_number, tmp_run_number, tmp_start_event, tmp_end_event,
160 tmp_start_datetime, tmp_end_datetime, tmp_file_path, tmp_event_count, tmp_file_size,
168 if (connDb ==
nullptr)
173 TString sql =
TString::Format(
"select file_id, period_number, run_number, start_event, end_event, start_datetime, "
174 "end_datetime, file_path, event_count, file_size, file_hash "
176 "where file_id = %d",
182 cout <<
"ERROR: getting raw file from the database has been failed" << endl;
194 cout <<
"ERROR: raw file was not found in the database" << endl;
202 tmp_file_id = stmt->
GetInt(0);
203 int tmp_period_number;
204 tmp_period_number = stmt->
GetInt(1);
206 tmp_run_number = stmt->
GetInt(2);
208 tmp_start_event = stmt->
GetInt(3);
210 tmp_end_event = stmt->
GetInt(4);
218 tmp_event_count = stmt->
GetInt(8);
219 int64_t tmp_file_size;
223 tmp_file_hash =
nullptr;
229 return new UniRawFile(connDb, tmp_file_id, tmp_period_number, tmp_run_number, tmp_start_event, tmp_end_event,
230 tmp_start_datetime, tmp_end_datetime, tmp_file_path, tmp_event_count, tmp_file_size,
238 if (connDb ==
nullptr)
243 TString sql =
TString::Format(
"select file_id, period_number, run_number, start_event, end_event, start_datetime, "
244 "end_datetime, file_path, event_count, file_size, file_hash "
246 "where lower(file_path) = lower('%s')",
252 cout <<
"ERROR: getting raw file from the database has been failed" << endl;
264 cout <<
"ERROR: raw file was not found in the database" << endl;
272 tmp_file_id = stmt->
GetInt(0);
273 int tmp_period_number;
274 tmp_period_number = stmt->
GetInt(1);
276 tmp_run_number = stmt->
GetInt(2);
278 tmp_start_event = stmt->
GetInt(3);
280 tmp_end_event = stmt->
GetInt(4);
288 tmp_event_count = stmt->
GetInt(8);
289 int64_t tmp_file_size;
293 tmp_file_hash =
nullptr;
299 return new UniRawFile(connDb, tmp_file_id, tmp_period_number, tmp_run_number, tmp_start_event, tmp_end_event,
300 tmp_start_datetime, tmp_end_datetime, tmp_file_path, tmp_event_count, tmp_file_size,
308 if (connDb ==
nullptr)
315 "where file_id = %d",
321 cout <<
"ERROR: getting raw file from the database has been failed" << endl;
348 if (connDb ==
nullptr)
355 "where lower(file_path) = lower('%s')",
361 cout <<
"ERROR: getting raw file from the database has been failed" << endl;
388 if (connDb ==
nullptr)
394 "where file_id = $1");
402 cout <<
"ERROR: deleting raw file from the dataBase has been failed" << endl;
418 if (connDb ==
nullptr)
424 "where lower(file_path) = lower($1)");
432 cout <<
"ERROR: deleting raw file from the DataBase has been failed" << endl;
448 if (connDb ==
nullptr)
453 TString sql =
TString::Format(
"select file_id, period_number, run_number, start_event, end_event, start_datetime, "
454 "end_datetime, file_path, event_count, file_size, file_hash "
460 cout <<
"ERROR: getting all 'raw files' from the dataBase has been failed" << endl;
471 cout <<
"Table 'raw_file':" << endl;
474 cout << (stmt->
GetInt(0));
475 cout <<
", period_number: ";
476 cout << (stmt->
GetInt(1));
477 cout <<
", run_number: ";
478 cout << (stmt->
GetInt(2));
479 cout <<
", start_event: ";
480 cout << (stmt->
GetInt(3));
481 cout <<
", end_event: ";
482 cout << (stmt->
GetInt(4));
483 cout <<
", start_datetime: ";
484 cout << (stmt->
GetDatime(5)).AsSQLString();
485 cout <<
", end_datetime: ";
486 cout << (stmt->
GetDatime(6)).AsSQLString();
487 cout <<
", file_path: ";
489 cout <<
", event_count: ";
490 cout << (stmt->
GetInt(8));
491 cout <<
", file_size: ";
493 cout <<
", file_hash: ";
511 cout <<
"CRITICAL ERROR: Connection object is null" << endl;
518 "set period_number = $1 "
519 "where file_id = $2");
523 stmt->
SetInt(0, period_number);
528 cout <<
"ERROR: updating information about raw file has been failed" << endl;
543 cout <<
"CRITICAL ERROR: Connection object is null" << endl;
550 "set run_number = $1 "
551 "where file_id = $2");
555 stmt->
SetInt(0, run_number);
560 cout <<
"ERROR: updating information about raw file has been failed" << endl;
575 cout <<
"CRITICAL ERROR: Connection object is null" << endl;
582 "set start_event = $1 "
583 "where file_id = $2");
587 stmt->
SetInt(0, start_event);
592 cout <<
"ERROR: updating information about raw file has been failed" << endl;
607 cout <<
"CRITICAL ERROR: Connection object is null" << endl;
614 "set end_event = $1 "
615 "where file_id = $2");
619 stmt->
SetInt(0, end_event);
624 cout <<
"ERROR: updating information about raw file has been failed" << endl;
639 cout <<
"CRITICAL ERROR: Connection object is null" << endl;
646 "set start_datetime = $1 "
647 "where file_id = $2");
656 cout <<
"ERROR: updating information about raw file has been failed" << endl;
671 cout <<
"CRITICAL ERROR: Connection object is null" << endl;
678 "set end_datetime = $1 "
679 "where file_id = $2");
688 cout <<
"ERROR: updating information about raw file has been failed" << endl;
703 cout <<
"CRITICAL ERROR: Connection object is null" << endl;
710 "set file_path = $1 "
711 "where file_id = $2");
720 cout <<
"ERROR: updating information about raw file has been failed" << endl;
735 cout <<
"CRITICAL ERROR: Connection object is null" << endl;
742 "set event_count = $1 "
743 "where file_id = $2");
747 stmt->
SetInt(0, event_count);
752 cout <<
"ERROR: updating information about raw file has been failed" << endl;
767 cout <<
"CRITICAL ERROR: Connection object is null" << endl;
774 "set file_size = $1 "
775 "where file_id = $2");
784 cout <<
"ERROR: updating information about raw file has been failed" << endl;
799 cout <<
"CRITICAL ERROR: Connection object is null" << endl;
806 "set file_hash = $1 "
807 "where file_id = $2");
811 if (file_hash ==
nullptr)
819 cout <<
"ERROR: updating information about raw file has been failed" << endl;
827 if (file_hash ==
nullptr)
839 cout <<
"Table 'raw_file'";
861 if (connDb ==
nullptr)
870 "where period_number = %d AND run_number = %d "
871 "AND %d >= start_event AND %d <= end_event AND %d >= start_event AND %d <= end_event "
872 "AND NOT (((%d - start_event) = 1) AND ((%d - end_event) = -1))",
873 period_number, run_number, start_event, start_event, end_event, end_event, start_event,
878 "where period_number = %d AND run_number = %d "
879 "AND start_event = %d AND end_event = %d",
880 period_number, run_number, start_event, end_event);
885 cout <<
"ERROR: getting raw file from the database has been failed" << endl;
914 if (connDb ==
nullptr)
921 "where period_number = %d AND run_number = %d "
922 "AND %d = start_event "
923 "order by end_event desc limit 1",
924 period_number, run_number, start_event);
929 cout <<
"ERROR: getting raw file from the database has been failed" << endl;
949 <<
"ERROR: while checking existense of raw files in UniConDa one raw file is found with 0 end event value ("
950 << period_number <<
":" << run_number <<
":" << start_event <<
")" << endl
951 <<
"The function returns 1 end event value to exclude uncertancies" << endl;
965 if (connDb ==
nullptr)
972 "where period_number = %d AND run_number = %d",
973 period_number, run_number);
978 cout <<
"ERROR: getting summary event count for run " << period_number <<
":" << run_number
979 <<
" from the database has been failed" << endl;
990 cout <<
"WARNING: there are no raw files for run " << period_number <<
":" << run_number <<
" in the database"
997 int sum_event_count = stmt->
GetInt(0);
1002 return sum_event_count;
1009 if (connDb ==
nullptr)
1014 TString sql =
TString::Format(
"select file_id, period_number, run_number, start_event, end_event, start_datetime, "
1015 "end_datetime, file_path, event_count, file_size, file_hash "
1017 "where period_number = %d AND run_number = %d "
1018 "order by start_event asc",
1019 period_number, run_number);
1024 cout <<
"ERROR: getting raw files for run " << period_number <<
":" << run_number
1025 <<
" from the database has been failed" << endl;
1037 if (connRaw ==
nullptr) {
1038 cout <<
"ERROR: the connection to the UniConDa Database for the selected raw file info failed" << endl;
1045 tmp_file_id = stmt->
GetInt(0);
1046 int tmp_period_number;
1047 tmp_period_number = stmt->
GetInt(1);
1049 tmp_run_number = stmt->
GetInt(2);
1050 int tmp_start_event;
1051 tmp_start_event = stmt->
GetInt(3);
1053 tmp_end_event = stmt->
GetInt(4);
1055 tmp_start_datetime = stmt->
GetDatime(5);
1060 int tmp_event_count;
1061 tmp_event_count = stmt->
GetInt(8);
1062 int64_t tmp_file_size;
1066 tmp_file_hash =
nullptr;
1070 raw_files->
Add((
TObject*)
new UniRawFile(connDb, tmp_file_id, tmp_period_number, tmp_run_number, tmp_start_event,
1071 tmp_end_event, tmp_start_datetime, tmp_end_datetime, tmp_file_path,
1072 tmp_event_count, tmp_file_size, tmp_file_hash));
1088 bool strict_compare)
1091 if (connDb ==
nullptr)
1098 sql =
TString::Format(
"select file_id, period_number, run_number, start_event, end_event, start_datetime, "
1099 "end_datetime, file_path, event_count, file_size, file_hash "
1101 "where period_number = %d AND run_number = %d AND start_event = %d AND end_event = %d "
1102 "order by file_id desc",
1103 period_number, run_number, start_event, end_event);
1105 sql =
TString::Format(
"select file_id, period_number, run_number, start_event, end_event, start_datetime, "
1106 "end_datetime, file_path, event_count, file_size, file_hash "
1108 "where period_number = %d AND run_number = %d "
1109 "AND %d >= start_event AND %d <= end_event AND %d >= start_event AND %d <= end_event "
1110 "AND NOT (((%d - start_event) = 1) AND ((%d - end_event) = -1)) "
1111 "order by file_id desc",
1112 period_number, run_number, start_event, start_event, end_event, end_event, start_event,
1119 cout <<
"ERROR: getting raw files for run " << period_number <<
":" << run_number <<
" and events "
1120 << start_event <<
"-" << end_event <<
" from the database has been failed" << endl;
1132 if (connRaw ==
nullptr) {
1133 cout <<
"ERROR: the connection to the UniConDa Database for the selected raw file info failed" << endl;
1140 tmp_file_id = stmt->
GetInt(0);
1141 int tmp_period_number;
1142 tmp_period_number = stmt->
GetInt(1);
1144 tmp_run_number = stmt->
GetInt(2);
1145 int tmp_start_event;
1146 tmp_start_event = stmt->
GetInt(3);
1148 tmp_end_event = stmt->
GetInt(4);
1150 tmp_start_datetime = stmt->
GetDatime(5);
1155 int tmp_event_count;
1156 tmp_event_count = stmt->
GetInt(8);
1157 int64_t tmp_file_size;
1161 tmp_file_hash =
nullptr;
1165 raw_files->
Add((
TObject*)
new UniRawFile(connDb, tmp_file_id, tmp_period_number, tmp_run_number, tmp_start_event,
1166 tmp_end_event, tmp_start_datetime, tmp_end_datetime, tmp_file_path,
1167 tmp_event_count, tmp_file_size, tmp_file_hash));
1182 if (connDb ==
nullptr)
1189 TString sql =
TString::Format(
"select file_id, period_number, run_number, start_event, end_event, start_datetime, "
1190 "end_datetime, file_path, event_count, file_size, file_hash "
1192 "where position('%s' in file_path) > 0 "
1193 "order by file_id desc",
1199 cout <<
"ERROR: getting raw files for file path part " << path_part <<
" from the database has been failed"
1212 if (connRaw ==
nullptr) {
1213 cout <<
"ERROR: the connection to the UniConDa Database for the selected raw file info failed" << endl;
1220 tmp_file_id = stmt->
GetInt(0);
1221 int tmp_period_number;
1222 tmp_period_number = stmt->
GetInt(1);
1224 tmp_run_number = stmt->
GetInt(2);
1225 int tmp_start_event;
1226 tmp_start_event = stmt->
GetInt(3);
1228 tmp_end_event = stmt->
GetInt(4);
1230 tmp_start_datetime = stmt->
GetDatime(5);
1235 int tmp_event_count;
1236 tmp_event_count = stmt->
GetInt(8);
1237 int64_t tmp_file_size;
1241 tmp_file_hash =
nullptr;
1245 raw_files->
Add((
TObject*)
new UniRawFile(connDb, tmp_file_id, tmp_period_number, tmp_run_number, tmp_start_event,
1246 tmp_end_event, tmp_start_datetime, tmp_end_datetime, tmp_file_path,
1247 tmp_event_count, tmp_file_size, tmp_file_hash));
1262 ifstream raw_file(raw_file_path, ios::binary);
1264 cout <<
"ERROR: raw file could not be opened to calculate Adler32 checksum: " << raw_file_path << endl;
1268 uLong adler = adler32(0L, Z_NULL, 0);
1270 const size_t bufferSize = 65536;
1271 char buffer[bufferSize];
1272 while (raw_file.read(buffer, bufferSize) || raw_file.gcount() > 0)
1273 adler = adler32(adler, (
const Bytef*)buffer, raw_file.gcount());
1278 std::ostringstream hexStream;
1279 hexStream << std::hex << std::setw(8) << std::setfill(
'0') << (adler & 0xFFFFFFFF);
1281 return hexStream.str();
1285 cout <<
"ERROR: raw file could not be opened to calculate MD5 checksum: " << raw_file_path << endl;
1292 delete pMD5
return strMD5;
const char * AsString() const
static TMD5 * FileChecksum(const char *file)
void Add(TObject *obj) override
virtual TSQLStatement * Statement(const char *, Int_t=100)
virtual const char * GetString(Int_t)
virtual Bool_t NextIteration()=0
virtual Bool_t NextResultRow()=0
virtual Bool_t SetString(Int_t, const char *, Int_t=256)
Bool_t SetDatime(Int_t, const TDatime &)
virtual Int_t GetInt(Int_t)
virtual Bool_t IsNull(Int_t)
virtual Long64_t GetLong64(Int_t)
virtual Bool_t Process()=0
virtual Bool_t SetInt(Int_t, Int_t)
virtual Bool_t SetNull(Int_t)
virtual Bool_t StoreResult()=0
virtual Bool_t SetLong64(Int_t, Long64_t)
const char * Data() const
static TString Format(const char *fmt,...)
static UniConnection * Open()
TSQLServer * GetSQLServer()
TString str_file_path
file path
static int PrintAll()
print all raw files
TString * str_file_hash
file hash
int i_start_event
start event
int SetFileSize(int64_t file_size)
set file size of the current raw file
void Print()
print information about current raw file
int SetEndDatetime(TDatime end_datetime)
set end datetime of the current raw file
UniConnection * connectionDB
connection to the database
int SetFileHash(TString *file_hash)
set file hash of the current raw file
static int GetSumEventCount(int period_number, int run_number)
get event count for a given run as a sum for all raw files: if <0 - database operation error
static UniRawFile * GetRawFile(int file_id)
get raw file from the database
static int CheckRawFileExists(int file_id)
check raw file exists in the database: 1- true, 0 - false, <0 - database operation error
int SetRunNumber(int run_number)
set run number of the current raw file
int SetEventCount(int event_count)
set event count of the current raw file
int SetStartDatetime(TDatime start_datetime)
set start datetime of the current raw file
int SetStartEvent(int start_event)
set start event of the current raw file
UniRawFile(UniConnection *db_connect, int file_id, int period_number, int run_number, int start_event, int end_event, TDatime start_datetime, TDatime end_datetime, TString file_path, int event_count, int64_t file_size, TString *file_hash)
static UniRawFile * CreateRawFile(int period_number, int run_number, int start_event, int end_event, TDatime start_datetime, TDatime end_datetime, TString file_path, int event_count, int64_t file_size, TString *file_hash)
add new raw file to the database
int SetEndEvent(int end_event)
set end event of the current raw file
int i_period_number
period number
int SetFilePath(TString file_path)
set file path of the current raw file
int i_event_count
event count
TDatime ts_end_datetime
end datetime
TDatime ts_start_datetime
start datetime
static TObjArray * GetRawFiles(int period_number, int run_number)
get array of raw files (UniRawFile*) corresponding to the period:run number ordered by start_event as...
static int DeleteRawFile(int file_id)
delete raw file from the database
int i_run_number
run number
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...
int64_t i64_file_size
file size
int SetPeriodNumber(int period_number)
set period number of the current raw file