33#include <mysqld_error.h>
37#include <mysqld_error.h>
40void create_runlog_sql_tree();
49 sprintf(buf,
"%d",
value);
55 const char* sign =
"";
87#define CHN_TREE_STR(_name) const char *_name[] = {\
90"Type = STRING : [8] Disk",\
91"Filename = STRING : [256] run%05d.mid",\
92"Format = STRING : [8] MIDAS",\
93"Compression = INT32 : 0",\
94"ODB dump = BOOL : 1",\
95"ODB dump format = STRING : [32] json",\
96"Options ODB dump format = STRING[3] :",\
100"Log messages = UINT32 : 0",\
101"Buffer = STRING : [32] SYSTEM",\
102"Event ID = INT32 : -1",\
103"Trigger mask = INT32 : -1",\
104"Event limit = DOUBLE : 0",\
105"Byte limit = DOUBLE : 0",\
106"Subrun Byte limit = DOUBLE : 0",\
107"Tape capacity = DOUBLE : 0",\
108"Subdir format = STRING : [32]",\
109"Current filename = STRING : [256]",\
110"Data checksum = STRING : [256] CRC32C",\
111"Options Data checksum = STRING[5] :",\
117"File checksum = STRING : [256] CRC32C",\
118"Options File checksum = STRING[5] :",\
124"Compress = STRING : [256] lz4",\
125"Options Compress = STRING[5] :",\
131"Output = STRING : [256] FILE",\
132"Options Output = STRING[5] :",\
138"Gzip compression = UINT32 : 0",\
139"Bzip2 compression = UINT32 : 0",\
140"Pbzip2 num cpu = UINT32 : 0",\
141"Pbzip2 compression = UINT32 : 0",\
142"Pbzip2 options = STRING : [256]",\
145"Events written = DOUBLE : 0",\
146"Bytes written = DOUBLE : 0",\
147"Bytes written uncompressed = DOUBLE : 0",\
148"Bytes written total = DOUBLE : 0",\
149"Bytes written subrun = DOUBLE : 0",\
150"Files written = DOUBLE : 0",\
151"Disk level = DOUBLE : 0",\
157 char obsolete_type[8];
159 char obsolete_format[8];
162 char odb_dump_format[32];
163 char options_odb_dump_format[3][32];
172 char subdir_format[32];
173 char current_filename[256];
174 char data_checksum[256];
175 char options_data_checksum[5][32];
176 char file_checksum[256];
177 char options_file_checksum[5][32];
179 char options_compress[5][32];
181 char options_output[5][32];
186 char pbzip2_options[256];
191#define CHN_SETTINGS_STR(_name) const char *_name[] = { \
193"Type = STRING : [8] Disk",\
194"Filename = STRING : [256] run%05d.mid",\
195"Format = STRING : [8] MIDAS",\
196"Compression = INT32 : 0",\
197"ODB dump = BOOL : 1",\
198"ODB dump format = STRING : [32] json",\
199"Log messages = UINT32 : 0",\
200"Buffer = STRING : [32] SYSTEM",\
201"Event ID = INT32 : -1",\
202"Trigger mask = INT32 : -1",\
203"Event limit = DOUBLE : 0",\
204"Byte limit = DOUBLE : 0",\
205"Subrun Byte limit = DOUBLE : 0",\
206"Tape capacity = DOUBLE : 0",\
207"Subdir format = STRING : [32]",\
208"Current filename = STRING : [256]",\
209"Data checksum = STRING : [256]",\
210"File checksum = STRING : [256]",\
211"Compress = STRING : [256]",\
212"Output = STRING : [256]",\
213"Gzip compression = UINT32 : 0",\
214"Bzip2 compression = UINT32 : 0",\
215"Pbzip2 num cpu = UINT32 : 0",\
216"Pbzip2 compression = UINT32 : 0",\
217"Pbzip2 options = STRING : [256]",\
231#define CHN_STATISTICS_STR(_name) const char *_name[] = {\
232"Events written = DOUBLE : 0",\
233"Bytes written = DOUBLE : 0",\
234"Bytes written uncompressed = DOUBLE : 0",\
235"Bytes written total = DOUBLE : 0",\
236"Bytes written subrun = DOUBLE : 0",\
237"Files written = DOUBLE : 0",\
238"Disk level = DOUBLE : 0",\
284#define DISK_CHECK_INTERVAL_MILLISEC 10000
339#define MEMZERO(obj) memset(&(obj), 0, sizeof(obj))
341#define FREE(ptr) if (ptr) free(ptr); (ptr)=NULL;
342#define DELETE(ptr) if (ptr) delete (ptr); (ptr)=NULL;
346static std::string
xpathname(
const char* xpath,
int level)
348 std::string path = xpath;
350 size_t p = path.rfind(
".");
352 if (p == std::string::npos)
354 path = path.substr(0, p);
362 int fd = open(filename, O_CREAT|O_EXCL|O_WRONLY, S_IRUSR|S_IRGRP|S_IROTH);
365 return fdopen(fd,
"w");
371 int status = stat(filename, &st);
404 printf(
"WriterInterface: default constructor!\n");
415 printf(
"WriterNull: path [%s]\n", log_chn->
path.c_str());
422 printf(
"WriterNull: destructor\n");
428 printf(
"WriterNull: open path [%s]\n", log_chn->
path.c_str());
440 printf(
"WriterNull: write path [%s], size %d\n", log_chn->
path.c_str(), size);
452 printf(
"WriterNull: close path [%s]\n", log_chn->
path.c_str());
481 printf(
"WriterFile: path [%s]\n", log_chn->
path.c_str());
488 printf(
"WriterFile: destructor\n");
498 printf(
"WriterFile: open path [%s]\n", log_chn->
path.c_str());
506 fFileno = (int) CreateFile(log_chn->
path.c_str(), GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_WRITE_THROUGH | FILE_FLAG_SEQUENTIAL_SCAN, 0);
511 cm_msg(
MERROR,
"WriterFile::wr_open",
"Cannot write to file \'%s\', open() errno %d (%s)", log_chn->
path.c_str(), errno, strerror(errno));
524 printf(
"WriterFile: write path [%s], size %d\n", log_chn->
path.c_str(), size);
539 cm_msg(
MERROR,
"WriterFile::wr_write",
"Cannot write to file \'%s\', write(%d) returned %d, errno: %d (%s)", log_chn->
path.c_str(), size, wr, errno, strerror(errno));
551 printf(
"WriterFile: close path [%s]\n", log_chn->
path.c_str());
561 cm_msg(
MERROR,
"WriterFile::wr_close",
"Cannot write to file \'%s\', close() errno %d (%s)", log_chn->
path.c_str(), errno, strerror(errno));
588 printf(
"WriterGzip: path [%s]\n", log_chn->
path.c_str());
601 printf(
"WriterGzip: destructor\n");
613 printf(
"WriterGzip: open path [%s]\n", log_chn->
path.c_str());
620 fGzfp = gzopen(log_chn->
path.c_str(),
"wb");
622 cm_msg(
MERROR,
"WriterGzip::wr_open",
"Cannot write to file \'%s\', gzopen() errno %d (%s)", log_chn->
path.c_str(), errno, strerror(errno));
626 chmod(log_chn->
path.c_str(), 0444);
632 if (zerror != Z_OK) {
633 cm_msg(
MERROR,
"WriterGzip::wr_open",
"gzsetparams() zerror %d", zerror);
638#if ZLIB_VERNUM > 0x1235
640 zerror = gzbuffer(
fGzfp, 128*1024);
641 if (zerror != Z_OK) {
642 cm_msg(
MERROR,
"WriterGzip::wr_open",
"gzbuffer() zerror %d", zerror);
646#warning Very old zlib, no gzbuffer()!
658 printf(
"WriterGzip: write path [%s], size %d\n", log_chn->
path.c_str(), size);
670 cm_msg(
MERROR,
"WriterGzip::wr_write",
"Cannot write to file \'%s\', gzwrite(%d) returned %d, errno: %d (%s)", log_chn->
path.c_str(), size, wr, errno, strerror(errno));
674#if ZLIB_VERNUM > 0x1235
678#warning Very old zlib, no gzoffset()!
679 time_t now = time(NULL);
694 printf(
"WriterGzip: close path [%s]\n", log_chn->
path.c_str());
700 zerror = gzflush(
fGzfp, Z_FINISH);
702 if (zerror != Z_OK) {
703 cm_msg(
MERROR,
"WriterGzip::wr_close",
"Cannot write to file \'%s\', gzflush(Z_FINISH) zerror %d, errno: %d (%s)", log_chn->
path.c_str(), zerror, errno, strerror(errno));
707 zerror = gzclose(
fGzfp);
710 if (zerror != Z_OK) {
711 cm_msg(
MERROR,
"WriterGzip::wr_close",
"Cannot write to file \'%s\', gzclose() zerror %d, errno: %d (%s)", log_chn->
path.c_str(), zerror, errno, strerror(errno));
745 printf(
"WriterPopen: path [%s]\n", log_chn->
path.c_str());
755 printf(
"WriterPopen: destructor\n");
767 printf(
"WriterPopen: open path [%s] pipe [%s] ext [%s]\n", log_chn->
path.c_str(),
fPipeCommand.c_str(),
fFileExt.c_str());
782 cm_msg(
MERROR,
"WriterPopen::wr_open",
"Cannot write to pipe \'%s\', popen() errno %d (%s)",
fCommand.c_str(), errno, strerror(errno));
795 printf(
"WriterPopen: write path [%s], size %d\n", log_chn->
path.c_str(), size);
806 int wr = fwrite(
data, 1, size,
fFp);
812 cm_msg(
MERROR,
"WriterPopen::wr_write",
"Cannot write to pipe \'%s\', fwrite(%d) returned %d, errno %d (%s)",
fCommand.c_str(), size, wr, errno, strerror(errno));
814 if (errno == EPIPE) {
815 cm_msg(
MERROR,
"WriterPopen::wr_write",
"Cannot write to pipe \'%s\': broken pipe, closing the pipe",
fCommand.c_str());
822 time_t now = time(NULL);
836 printf(
"WriterPopen: close path [%s]\n", log_chn->
path.c_str());
850 cm_msg(
MERROR,
"WriterPopen::wr_close",
"Cannot write to pipe \'%s\', pclose() returned %d, errno %d (%s)",
fCommand.c_str(), err, errno, strerror(errno));
854 chmod(log_chn->
path.c_str(), 0444);
890 printf(
"WriterCRC32Zlib: path [%s], level %d\n", log_chn->
path.c_str(), level);
902 printf(
"WriterCRC32Zlib: destructor\n");
911 printf(
"WriterCRC32Zlib: open path [%s], level %d\n", log_chn->
path.c_str(),
fLevel);
924 fCrc32 = crc32(0, Z_NULL, 0);
932 printf(
"WriterCRC32Zlib: write path [%s], size %d\n", log_chn->
path.c_str(), size);
951 std::string f = x +
".crc32zlib";
954 printf(
"WriterCRC32Zlib: close path [%s], level %d, file [%s]\n", log_chn->
path.c_str(),
fLevel, f.c_str());
958 cm_msg(
MLOG,
"CRC32Zlib",
"File \'%s\' CRC32-zlib checksum: 0x%08lx, %.0f bytes", x.c_str(), (
unsigned long)
fCrc32,
fBytesIn);
962 cm_msg(
MERROR,
"WriterCRC32Zlib::wr_close",
"Cannot write CRC32Zlib to file \'%s\', fopen() errno %d (%s)", f.c_str(), errno, strerror(errno));
1006 printf(
"WriterCRC32C: path [%s], level %d\n", log_chn->
path.c_str(), level);
1018 printf(
"WriterCRC32C: destructor\n");
1027 printf(
"WriterCRC32C: open path [%s], level %d\n", log_chn->
path.c_str(),
fLevel);
1048 printf(
"WriterCRC32C: write path [%s], size %d\n", log_chn->
path.c_str(), size);
1067 std::string f = x +
".crc32c";
1070 printf(
"WriterCRC32C: close path [%s], level %d, file [%s]\n", log_chn->
path.c_str(),
fLevel, f.c_str());
1074 cm_msg(
MLOG,
"CRC32C",
"File \'%s\' CRC32C checksum: 0x%08lx, %.0f bytes", x.c_str(), (
unsigned long)
fCrc32,
fBytesIn);
1078 cm_msg(
MERROR,
"WriterCRC32C::wr_close",
"Cannot write CRC32C to file \'%s\', fopen() errno %d (%s)", f.c_str(), errno, strerror(errno));
1080 fprintf(
fp,
"%08lx %.0f %s\n", (
unsigned long)
fCrc32,
fBytesIn, x.c_str());
1122 printf(
"WriterSHA256: path [%s], level %d\n", log_chn->
path.c_str(), level);
1135 printf(
"WriterSHA256: destructor\n");
1146 printf(
"WriterSHA256: open path [%s], level %d\n", log_chn->
path.c_str(),
fLevel);
1167 printf(
"WriterSHA256: write path [%s], size %d\n", log_chn->
path.c_str(), size);
1186 sprintf(s,
"%02x",
c);
1190 std::string
toString(
const unsigned char sha256sum[32])
1193 for (
int i=0;
i<32;
i++)
1194 s +=
toHex(sha256sum[
i]);
1201 std::string f = x +
".sha256";
1204 printf(
"WriterSHA256: close path [%s], level %d, file [%s]\n", log_chn->
path.c_str(),
fLevel, f.c_str());
1208 unsigned char sha256sum[32];
1218 cm_msg(
MERROR,
"WriterSHA256::wr_close",
"Cannot write SHA-256 checksum to file \'%s\', fopen() errno %d (%s)", f.c_str(), errno, strerror(errno));
1262 printf(
"WriterSHA512: path [%s], level %d\n", log_chn->
path.c_str(), level);
1275 printf(
"WriterSHA512: destructor\n");
1286 printf(
"WriterSHA512: open path [%s], level %d\n", log_chn->
path.c_str(),
fLevel);
1307 printf(
"WriterSHA512: write path [%s], size %d\n", log_chn->
path.c_str(), size);
1326 sprintf(s,
"%02x",
c);
1330 std::string
toString(
const unsigned char sha512sum[64])
1333 for (
int i=0;
i<64;
i++)
1334 s +=
toHex(sha512sum[
i]);
1341 std::string f = x +
".sha512";
1344 printf(
"WriterSHA512: close path [%s], level %d, file [%s]\n", log_chn->
path.c_str(),
fLevel, f.c_str());
1348 unsigned char sha512sum[64];
1358 cm_msg(
MERROR,
"WriterSHA512::wr_close",
"Cannot write SHA-512 checksum to file \'%s\', fopen() errno %d (%s)", f.c_str(), errno, strerror(errno));
1394#include "mlz4frame.h"
1402 printf(
"WriterLZ4: path [%s]\n", log_chn->
path.c_str());
1415 printf(
"WriterLZ4: destructor\n");
1424 MLZ4F_errorCode_t errorCode;
1427 printf(
"WriterLZ4: open path [%s]\n", log_chn->
path.c_str());
1434 errorCode = MLZ4F_createCompressionContext(&
fContext, MLZ4F_VERSION);
1435 if (MLZ4F_isError(errorCode)) {
1436 cm_msg(
MERROR,
"WriterLZ4::wr_open",
"LZ4F_createCompressionContext() error %d (%s)", (
int)errorCode, MLZ4F_getErrorName(errorCode));
1440 MLZ4F_blockSizeID_t blockSizeId = MLZ4F_max4MB;
1446 cm_msg(
MERROR,
"WriterLZ4::wr_open",
"Cannot malloc() %d bytes for an LZ4 compression buffer, block size %d, errno %d (%s)",
fBufferSize,
fBlockSize, errno, strerror(errno));
1452 fPrefs.compressionLevel = 0;
1454 fPrefs.frameInfo.contentChecksumFlag = MLZ4F_contentChecksumEnabled;
1455 fPrefs.frameInfo.blockSizeID = blockSizeId;
1459 if (MLZ4F_isError(headerSize)) {
1460 errorCode = headerSize;
1461 cm_msg(
MERROR,
"WriterLZ4::wr_open",
"LZ4F_compressBegin() error %d (%s)", (
int)errorCode, MLZ4F_getErrorName(errorCode));
1481 const char* ptr = (
const char*)
data;
1482 int remaining = size;
1485 printf(
"WriterLZ4: write path [%s], size %d\n", log_chn->
path.c_str(), size);
1487 while (remaining > 0) {
1488 int wsize = remaining;
1495 if (MLZ4F_isError(outSize)) {
1496 int errorCode = outSize;
1497 cm_msg(
MERROR,
"WriterLZ4::wr_write",
"LZ4F_compressUpdate() with %d bytes, block size %d, buffer size %d, write size %d, remaining %d bytes, error %d (%s)", wsize,
fBlockSize,
fBufferSize, size, remaining, (
int)errorCode, MLZ4F_getErrorName(errorCode));
1522 MLZ4F_errorCode_t errorCode;
1525 printf(
"WriterLZ4: close path [%s]\n", log_chn->
path.c_str());
1532 if (MLZ4F_isError(headerSize)) {
1533 errorCode = headerSize;
1534 cm_msg(
MERROR,
"WriterLZ4::wr_close",
"LZ4F_compressEnd() error %d (%s)", (
int)errorCode, MLZ4F_getErrorName(errorCode));
1563 errorCode = MLZ4F_freeCompressionContext(
fContext);
1564 if (MLZ4F_isError(errorCode)) {
1565 cm_msg(
MERROR,
"WriterLZ4::wr_close",
"LZ4F_freeCompressionContext() error %d (%s)", (
int)errorCode, MLZ4F_getErrorName(errorCode));
1614 size =
sizeof(
BOOL);
1621 str =
"run%05d.json";
1628 size =
sizeof(
BOOL);
1644 cm_msg(
MERROR,
"logger_init",
"Cannot create channel entry in database");
1664 create_runlog_sql_tree();
1676 static int buffer_size = 100000;
1680 if (pevent == NULL) {
1681 cm_msg(
MERROR,
"log_odb_dump",
"Cannot allocate ODB dump buffer");
1705 static int buffer_size = 100000;
1709 if (pevent == NULL) {
1710 cm_msg(
MERROR,
"log_odb_dump",
"Cannot allocate ODB dump buffer");
1736 char* buffer = NULL;
1737 int buffer_size = 0;
1747 if (pevent == NULL) {
1751 memcpy(pevent+1, buffer, buffer_end);
1768 cm_msg(
MERROR,
"log_odb_dump",
"Invalid ODB dump format \"%s\" in ODB settings for channel \"%s\". Valid formats are: \"odb\", \"xml\", \"json\"", log_chn->
settings.
odb_dump_format, log_chn->
name.c_str());
1774void odb_save(
const char *filename,
bool make_file_readonly)
1780 if (path.length() > 0) {
1801 if (make_file_readonly)
1802 chmod(path.c_str(), 0444);
1807 printf(
"saved odb to \"%s\" in %d ms\n", path.c_str(), te-t0);
1813static void xwrite(
const char* filename,
int fd,
const void*
data,
int size)
1817 cm_msg(
MERROR,
"xwrite",
"cannot write to \'%s\', write(%d) returned %d, errno %d (%s)", filename, size, wr, errno, strerror(errno));
1831static const char *
mname[] = {
1846void ctime_to_datetime(
char *date)
1848 char ctime_date[30];
1852 mstrlcpy(ctime_date, date,
sizeof(ctime_date));
1853 memset(&tms, 0,
sizeof(
struct tm));
1855 for (
i = 0;
i < 12;
i++)
1856 if (strncmp(ctime_date + 4,
mname[
i], 3) == 0)
1860 tms.tm_mday = atoi(ctime_date + 8);
1861 tms.tm_hour = atoi(ctime_date + 11);
1862 tms.tm_min = atoi(ctime_date + 14);
1863 tms.tm_sec = atoi(ctime_date + 17);
1864 tms.tm_year = atoi(ctime_date + 20) - 1900;
1867 if (tms.tm_year < 90)
1871 sprintf(date,
"%d-%02d-%02d %02d-%02d-%02d",
1872 tms.tm_year + 1900, tms.tm_mon + 1, tms.tm_mday, tms.tm_hour, tms.tm_min, tms.tm_sec);
1877int mysql_query_debug(MYSQL * db,
const char *query)
1880 std::string filename;
1891 if (!filename.empty()) {
1900 path = dir + filename;
1907 path = dir + filename;
1910 fh = open(path.c_str(), O_WRONLY | O_CREAT | O_APPEND |
O_LARGEFILE, 0644);
1912 printf(
"Cannot open message log file \'%s\', open() returned %d, errno %d (%s)\n", path.c_str(),
1913 fh, errno, strerror(errno));
1915 xwrite(path.c_str(), fh, query, strlen(query));
1916 xwrite(path.c_str(), fh,
";\n", 2);
1922 status = mysql_query(db, query);
1925 cm_msg(
MERROR,
"mysql_query_debug",
"SQL error: %s", mysql_error(db));
1932int sql_get_columns(
HNDLE hKeyRoot, SQL_LIST ** sql_list)
1949 *sql_list = (SQL_LIST *) malloc(
sizeof(SQL_LIST) *
n);
1951 for (
i = 0;
i <
n;
i++) {
1964 char*
data = (
char*)malloc(size);
1969 mstrlcpy(
str, s.c_str(),
sizeof(
str));
1971 assert(strlen(
str) <
sizeof(
str));
1974 strcpy((*sql_list)[
i].
data,
str[0] ==
'y' ||
str[0] ==
'Y' ?
"1" :
"0");
1980 if (strlen(
str) == 24 &&
str[10] ==
' ' &&
str[13] ==
':') {
1981 strcpy(
str,
"DATETIME");
1982 ctime_to_datetime((*sql_list)[
i].
data);
1986 sprintf(
str,
" TEXT");
1991 strcpy(
str,
"TINYINT UNSIGNED ");
1994 strcpy(
str,
"TINYINT ");
1997 strcpy(
str,
"CHAR ");
2000 strcpy(
str,
"SMALLINT UNSIGNED ");
2003 strcpy(
str,
"SMALLINT ");
2006 strcpy(
str,
"INT UNSIGNED ");
2009 strcpy(
str,
"INT ");
2012 strcpy(
str,
"BOOLEAN ");
2015 strcpy(
str,
"FLOAT ");
2018 strcpy(
str,
"DOUBLE ");
2026 strcpy((*sql_list)[
i].column_type,
str);
2034BOOL sql_create_table(MYSQL * db,
char *database,
char *table,
HNDLE hKeyRoot)
2038 std::string query =
msprintf(
"CREATE TABLE `%s`.`%s` (", database, table);
2040 int n_col = sql_get_columns(hKeyRoot, &sql_list);
2043 cm_msg(
MERROR,
"sql_create_database",
"ODB tree \"%s\" contains no variables", path.c_str());
2047 for (
int i = 0;
i < n_col;
i++) {
2048 query +=
msprintf(
"`%s` %s NOT NULL, ", sql_list[
i].column_name, sql_list[
i].column_type);
2051 query +=
msprintf(
"PRIMARY KEY (`%s`))", sql_list[0].column_name);
2054 if (mysql_query_debug(db, query.c_str())) {
2055 cm_msg(
MERROR,
"sql_create_table",
"Failed to create table: Error: %s", mysql_error(db));
2064BOOL sql_modify_table(MYSQL * db,
char *database,
char *table,
HNDLE hKeyRoot)
2068 int n_col = sql_get_columns(hKeyRoot, &sql_list);
2071 cm_msg(
MERROR,
"sql_modify_table",
"ODB tree \"%s\" contains no variables", path.c_str());
2075 for (
int i = 0;
i < n_col;
i++) {
2080 query =
msprintf(
"ALTER TABLE `%s`.`%s` ADD `%s` %s", database, table, sql_list[
i].column_name, sql_list[
i].column_type);
2082 query =
msprintf(
"ALTER TABLE `%s`.`%s` ADD `%s` %s AFTER `%s`",
2084 sql_list[
i].column_name,
2085 sql_list[
i].column_type,
2086 sql_list[
i - 1].column_name);
2089 if (mysql_query_debug(db, query.c_str())) {
2090 if (mysql_errno(db) == ER_DUP_FIELDNAME) {
2093 query =
msprintf(
"ALTER TABLE `%s`.`%s` MODIFY `%s` %s", database, table, sql_list[
i].column_name, sql_list[
i].column_type);
2095 if (mysql_query_debug(db, query.c_str())) {
2097 cm_msg(
MERROR,
"sql_modify_table",
"Failed to modify column: Error: %s", mysql_error(db));
2103 cm_msg(
MERROR,
"sql_modify_table",
"Failed to add column: Error: %s", mysql_error(db));
2109 cm_msg(
MINFO,
"sql_insert",
"SQL table '%s.%s' modified successfully", database, table);
2116BOOL sql_create_database(MYSQL * db,
const char *database)
2118 std::string query =
msprintf(
"CREATE DATABASE `%s`", database);
2119 if (mysql_query_debug(db, query.c_str())) {
2120 cm_msg(
MERROR,
"sql_create_database",
"Failed to create database: Error: %s", mysql_error(db));
2125 query =
msprintf(
"USE `%s`", database);
2126 if (mysql_query_debug(db, query.c_str())) {
2127 cm_msg(
MERROR,
"sql_create_database",
"Failed to select database: Error: %s", mysql_error(db));
2136int sql_insert(MYSQL * db,
char *database,
char *table,
HNDLE hKeyRoot,
BOOL create_flag)
2144 std::string query =
msprintf(
"INSERT INTO `%s`.`%s` (", database, table);
2145 int n_col = sql_get_columns(hKeyRoot, &sql_list);
2149 for (
int i = 0;
i < n_col;
i++) {
2150 query +=
msprintf(
"`%s`", sql_list[
i].column_name);
2151 if (
i < n_col - 1) {
2156 query +=
") VALUES (";
2158 for (
int i = 0;
i < n_col;
i++) {
2161 size_t len = strlen(sql_list[
i].
data);
2163 mysql_escape_string(
str, sql_list[
i].
data, len);
2167 if (
i < n_col - 1) {
2175 if (mysql_query_debug(db, query.c_str())) {
2178 if (mysql_errno(db) == ER_DUP_ENTRY) {
2180 return ER_DUP_ENTRY;
2182 }
else if (mysql_errno(db) == ER_NO_SUCH_TABLE && create_flag) {
2185 sql_create_table(db, database, table, hKeyRoot);
2186 if (mysql_query_debug(db, query.c_str())) {
2187 cm_msg(
MERROR,
"sql_insert",
"Failed to update database: Error: %s", mysql_error(db));
2188 return mysql_errno(db);
2190 cm_msg(
MINFO,
"sql_insert",
"SQL table '%s.%s' created successfully", database, table);
2192 }
else if (mysql_errno(db) == ER_BAD_FIELD_ERROR && create_flag) {
2195 sql_modify_table(db, database, table, hKeyRoot);
2196 if (mysql_query_debug(db, query.c_str())) {
2197 cm_msg(
MERROR,
"sql_insert",
"Failed to update database: Error: %s", mysql_error(db));
2198 return mysql_errno(db);
2202 int status = mysql_errno(db);
2203 cm_msg(
MERROR,
"sql_insert",
"Failed to update database: Errno: %d, Error: %s",
status, mysql_error(db));
2204 return mysql_errno(db);
2213int sql_update(MYSQL * db,
char *database,
char *table,
HNDLE hKeyRoot,
BOOL create_flag,
char *where)
2222 std::string query =
msprintf(
"UPDATE `%s`.`%s` SET ", database, table);
2223 int n_col = sql_get_columns(hKeyRoot, &sql_list);
2227 for (
int i = 0;
i < n_col;
i++) {
2228 size_t len = strlen(sql_list[
i].
data);
2230 mysql_escape_string(
str, sql_list[
i].
data, len);
2231 query +=
msprintf(
"`%s`='%s'", sql_list[
i].column_name,
str);
2232 if (
i < n_col - 1) {
2240 if (mysql_query_debug(db, query.c_str())) {
2241 if (mysql_errno(db) == ER_NO_SUCH_TABLE && create_flag) {
2244 sql_create_table(db, database, table, hKeyRoot);
2245 return sql_insert(db, database, table, hKeyRoot, create_flag);
2247 }
else if (mysql_errno(db) == ER_BAD_FIELD_ERROR && create_flag) {
2250 sql_modify_table(db, database, table, hKeyRoot);
2251 if (mysql_query_debug(db, query.c_str())) {
2252 cm_msg(
MERROR,
"sql_update",
"Failed to update database: Error: %s", mysql_error(db));
2253 return mysql_errno(db);
2257 cm_msg(
MERROR,
"sql_update",
"Failed to update database: Error: %s", mysql_error(db));
2258 return mysql_errno(db);
2267void create_runlog_sql_tree()
2269 char hostname[80], username[80], password[80], table[80], filename[80];
2270 int size, write_flag, create_flag;
2273 size =
sizeof(create_flag);
2277 size =
sizeof(write_flag);
2281 size =
sizeof(hostname);
2282 strcpy(hostname,
"localhost");
2285 size =
sizeof(username);
2286 strcpy(username,
"root");
2289 size =
sizeof(password);
2294 std::string database;
2298 size =
sizeof(table);
2299 strcpy(table,
"Runlog");
2302 size =
sizeof(filename);
2303 strcpy(filename,
"sql.log");
2312 db_create_link(
hDB, 0,
"/Logger/Runlog/SQL/Links BOR/Run number",
"/Runinfo/Run number");
2315 db_create_link(
hDB, 0,
"/Logger/Runlog/SQL/Links BOR/Comment",
"/Experiment/Run parameters/Comment");
2318 db_create_link(
hDB, 0,
"/Logger/Runlog/SQL/Links BOR/Start time",
"/Runinfo/Start time");
2327 db_create_link(
hDB, 0,
"/Logger/Runlog/SQL/Links EOR/Stop time",
"/Runinfo/Stop time");
2331 "/Equipment/Trigger/Statistics/Events sent");
2338void write_runlog_sql(
BOOL bor)
2341 char hostname[80], username[80], password[80], database[80], table[80], query[5000], where[500];
2342 int status, size, write_flag, create_flag;
2348 size =
sizeof(
BOOL);
2370 sql_get_columns(hKeyRoot, &sql_list);
2371 sprintf(where,
"WHERE `%s`='%s'", sql_list[0].column_name, sql_list[0].
data);
2379 cm_msg(
MERROR,
"write_runlog_sql",
"Cannot find \"/Logger/Runlog/SQL/Links BOR");
2385 cm_msg(
MERROR,
"write_runlog_sql",
"Cannot find \"/Logger/Runlog/SQL/Links EOR");
2390 size =
sizeof(create_flag);
2394 size =
sizeof(write_flag);
2398 size =
sizeof(hostname);
2399 strcpy(hostname,
"localhost");
2402 size =
sizeof(username);
2403 strcpy(username,
"root");
2406 size =
sizeof(password);
2411 size =
sizeof(database);
2413 size =
sizeof(database);
2416 size =
sizeof(table);
2417 strcpy(table,
"Runlog");
2427 if (!mysql_real_connect(&db, hostname, username, password, NULL, 0, NULL, 0)) {
2428 cm_msg(
MERROR,
"write_runlog_sql",
"Failed to connect to database: Error: %s", mysql_error(&db));
2434 sprintf(query,
"USE `%s`", database);
2435 if (mysql_query_debug(&db, query)) {
2439 if (!sql_create_database(&db, database)) {
2443 cm_msg(
MINFO,
"write_runlog_sql",
"Database \"%s\" created successfully", database);
2446 cm_msg(
MERROR,
"write_runlog_sql",
"Failed to select database: Error: %s", mysql_error(&db));
2453 status = sql_insert(&db, database, table, hKeyRoot, create_flag);
2454 if (
status == ER_DUP_ENTRY)
2455 sql_update(&db, database, table, hKeyRoot, create_flag, where);
2457 sql_update(&db, database, table, hKeyRoot, create_flag, where);
2468 std::string filename;
2469 int size, write_flag;
2472 size =
sizeof(write_flag);
2476 filename =
"runlog.log";
2479 db_find_key(
hDB, 0,
"/Logger/Runlog/ASCII/Links BOR", &hKeyRoot);
2485 db_create_link(
hDB, 0,
"/Logger/Runlog/ASCII/Links BOR/Run number",
"/Runinfo/Run number");
2488 db_create_link(
hDB, 0,
"/Logger/Runlog/ASCII/Links BOR/Comment",
"/Experiment/Run parameters/Comment");
2491 db_create_link(
hDB, 0,
"/Logger/Runlog/ASCII/Links BOR/Start time",
"/Runinfo/Start time");
2494 db_find_key(
hDB, 0,
"/Logger/Runlog/ASCII/Links EOR", &hKeyRoot);
2500 db_create_link(
hDB, 0,
"/Logger/Runlog/ASCII/Links EOR/Stop time",
"/Runinfo/Stop time");
2504 "/Equipment/Trigger/Statistics/Events sent");
2513 char filename[256], dir[256], path[256];
2514 int status, size, write_flag;
2518 size =
sizeof(
BOOL);
2526 db_find_key(
hDB, 0,
"/Logger/Runlog/ASCII/Links BOR", &hKeyRoot);
2528 cm_msg(
MERROR,
"write_runlog_ascii",
"Cannot find \"/Logger/Runlog/ASCII/Links BOR");
2532 db_find_key(
hDB, 0,
"/Logger/Runlog/ASCII/Links EOR", &hKeyRoot);
2534 cm_msg(
MERROR,
"write_runlog_ascii",
"Cannot find \"/Logger/Runlog/ASCII/Links EOR");
2539 size =
sizeof(write_flag);
2543 size =
sizeof(filename);
2544 strcpy(filename,
"runlog.log");
2555 strcat(path, filename);
2557 strcpy(path, filename);
2563 FILE *f = fopen(path,
"r");
2566 f = fopen(path,
"wt");
2571 db_find_key(
hDB, 0,
"/Logger/Runlog/ASCII/Links BOR", &hKeyRoot);
2572 for (
int i = 0;;
i++) {
2580 db_find_key(
hDB, 0,
"/Logger/Runlog/ASCII/Links EOR", &hKeyRoot);
2581 for (
int i = 0;;
i++) {
2594 f = fopen(path,
"at");
2599 db_find_key(
hDB, 0,
"/Logger/Runlog/ASCII/Links BOR", &hKeyRoot);
2601 db_find_key(
hDB, 0,
"/Logger/Runlog/ASCII/Links EOR", &hKeyRoot);
2603 for (
int i = 0;;
i++) {
2610 char*
data = (
char*)malloc(size);
2616 fprintf(f,
"%s\t",
str.c_str());
2628 int size, write_flag;
2631 size =
sizeof(write_flag);
2635 size =
sizeof(dirname);
2636 strcpy(dirname,
"runlogs");
2645 db_create_link(
hDB, 0,
"/Logger/Runlog/JSON/Links BOR/Run number",
"/Runinfo/Run number");
2648 db_create_link(
hDB, 0,
"/Logger/Runlog/JSON/Links BOR/Comment",
"/Experiment/Run parameters/Comment");
2651 db_create_link(
hDB, 0,
"/Logger/Runlog/JSON/Links BOR/Start time",
"/Runinfo/Start time");
2660 db_create_link(
hDB, 0,
"/Logger/Runlog/JSON/Links EOR/Stop time",
"/Runinfo/Stop time");
2664 "/Equipment/Trigger/Statistics/Events sent");
2673 char filename[256], messagedir[256], datadir[256], dirname[256], path[256];
2674 int status, size, write_flag;
2679 size =
sizeof(
BOOL);
2689 cm_msg(
MERROR,
"write_runlog_json",
"Cannot find \"/Logger/Runlog/JSON/Links BOR");
2695 cm_msg(
MERROR,
"write_runlog_json",
"Cannot find \"/Logger/Runlog/JSON/Links EOR");
2700 size =
sizeof(write_flag);
2704 size =
sizeof(datadir);
2705 strcpy(datadir,
"");
2708 size =
sizeof(messagedir);
2709 strcpy(messagedir,
"");
2712 size =
sizeof(dirname);
2713 strcpy(dirname,
"runlogs");
2716 size =
sizeof(runnumber);
2719 snprintf(filename, 256,
"runlog_%06i.json", runnumber);
2722 mstrlcpy(path, messagedir,
sizeof(path));
2724 mstrlcpy(path, datadir,
sizeof(path));
2727 mstrlcat(path, dirname,
sizeof(path));
2735 status = mkdir(path, 0755);
2738 mstrlcat(path, filename,
sizeof(path));
2744 char fileflag[2] =
"a";
2746 strcpy(fileflag,
"a");
2748 FILE *
file = fopen(path, fileflag);
2750 cm_msg(
MERROR,
"write_runlog_json",
"Cannot open file \"%s\"", path);
2759 int buffer_size = 100000;
2760 char *buffer = (
char *)malloc(buffer_size);
2764 json_write(&buffer, &buffer_size, &buffer_end, 0,
"{\n \"BOR\": ", 0);
2766 json_write(&buffer, &buffer_size, &buffer_end, 0,
" \"EOR\": ", 0);
2776 json_write(&buffer, &buffer_size, &buffer_end, 0,
",\n", 0);
2778 json_write(&buffer, &buffer_size, &buffer_end, 0,
" \n}\n", 0);
2782 size_t wr = fwrite(buffer, 1, buffer_end,
file);
2783 if (wr != (
size_t) buffer_end) {
2784 cm_msg(
MERROR,
"write_runlog_json",
"Cannot write to file \"%s\", fwrite() errno %d (%s)", filename, errno, strerror(errno));
2812 char user[32], pass[32];
2813 char directory[256],
file_name[256], file_mode[256];
2814 char bdestination[256];
2815 mstrlcpy(bdestination, xdestination,
sizeof(bdestination));
2816 char* destination = bdestination;
2819 if (destination[0] ==
'/')
2828 token = strtok(destination,
",");
2832 token = strtok(NULL,
", ");
2836 token = strtok(NULL,
", ");
2838 mstrlcpy(user, token,
sizeof(user));
2840 token = strtok(NULL,
", ");
2842 mstrlcpy(pass, token,
sizeof(pass));
2844 token = strtok(NULL,
", ");
2846 mstrlcpy(directory, token,
sizeof(directory));
2848 token = strtok(NULL,
", ");
2852 token = strtok(NULL,
", ");
2855 mstrlcpy(file_mode, token,
sizeof(file_mode));
2882 return (*con)->err_no;
2895 printf(
"WriterFtp: path [%s]\n", log_chn->
path.c_str());
2903 printf(
"WriterFtp: destructor\n");
2917 printf(
"WriterFtp: open path [%s]\n", log_chn->
path.c_str());
2919 assert(
fFtp == NULL);
2923 cm_msg(
MERROR,
"WriterFtp::wr_open",
"Cannot open FTP connection \'%s\', ftp_open() status %d, errno %d (%s)", log_chn->
path.c_str(),
status, errno, strerror(errno));
2935 printf(
"WriterFtp: write path [%s], size %d\n", log_chn->
path.c_str(), size);
2952 cm_msg(
MERROR,
"WriterFtp::wr_write",
"Cannot write to FTP connection \'%s\', ftp_send(%d) returned %d, errno %d (%s)", log_chn->
path.c_str(), size, wr, errno, strerror(errno));
2962 printf(
"WriterFtp: close path [%s]\n", log_chn->
path.c_str());
2964 assert(
fFtp != NULL);
3004#define EVENT_DEF_CACHE_SIZE 30
3008 if (event_def == NULL)
3011 assert(event_def != NULL);
3016 return &event_def[
i];
3024 cm_msg(
MERROR,
"db_get_event_definition",
"too many event definitions");
3033 return &event_def[
index];
3038 cm_msg(
MERROR,
"db_get_event_definition",
"cannot find /equipment entry in ODB");
3046 cm_msg(
MERROR,
"db_get_event_definition",
"Cannot find event id %d under /equipment",
event_id);
3068 cm_msg(
MERROR,
"db_get_event_definition",
"unknown data format name \"%s\"",
str);
3074 return &event_def[
index];
3083 std::string bzip2_command =
"bzip2 -z";
3086 bzip2_command +=
" -";
3090 return new WriterPopen(log_chn, (bzip2_command +
" > ").c_str(),
".bz2");
3095 std::string pbzip2_command =
"pbzip2 -c -z";
3098 pbzip2_command +=
" -p";
3103 pbzip2_command +=
" -";
3108 pbzip2_command +=
" ";
3112 return new WriterPopen(log_chn, (pbzip2_command +
" > ").c_str(),
".bz2");
3115#define CHECKSUM_NONE 0
3116#define CHECKSUM_ZLIB 1
3117#define CHECKSUM_CRC32C 2
3118#define CHECKSUM_SHA256 3
3119#define CHECKSUM_SHA512 4
3134 cm_msg(
MERROR,
"log_create_writer",
"channel %s unknown checksum code %d", log_chn->
path.c_str(), code);
3139#define COMPRESS_NONE 0
3140#define COMPRESS_ZLIB 1
3141#define COMPRESS_LZ4 2
3142#define COMPRESS_BZIP2 3
3143#define COMPRESS_PBZIP2 4
3152 cm_msg(
MERROR,
"log_create_writer",
"channel %s unknown compression code %d", log_chn->
path.c_str(), code);
3157#define OUTPUT_NONE 0
3158#define OUTPUT_NULL 1
3159#define OUTPUT_FILE 2
3162#define OUTPUT_PIPE 5
3168 int size =
sizeof(
value);
3177 std::string s =
set +
" (one of:" + def +
")";
3180 const char*
value = s.c_str();
3184int check_add(
int v,
int n,
const std::string& val,
const char*
str,
bool bdef, std::string* def, std::string* sel)
3186 (*def) += std::string(
" ") +
str;
3189 if (val.find(
str) == 0) {
3248 assert(log_chn->
writer == NULL);
3256 cm_msg(
MERROR,
"log_create_writer",
"channel %s requested GZIP/ZLIB compression, output module must be FILE", log_chn->
path.c_str());
3266 cm_msg(
MERROR,
"log_create_writer",
"channel %s requested BZIP2 compression, output module must be FILE", log_chn->
path.c_str());
3277 cm_msg(
MERROR,
"log_create_writer",
"channel %s requested PBZIP2 compression, output module must be FILE", log_chn->
path.c_str());
3387 mstrlcpy(
str, log_chn->
path.c_str(),
sizeof(
str));
3393 mstrlcpy(p, p+1,
sizeof(
str));
3394 rename(log_chn->
path.c_str(),
str);
3413 std::string
str = log_chn->
path.c_str();
3414 size_t pos =
str.rfind(
'/');
3415 if (pos != std::string::npos) {
3421 double MiB = 1024*1024;
3424 double limit = 10E6;
3425 double level = 1.0-disk_free/disk_size;
3428 *pdisk_size = disk_size;
3430 *pdisk_free = disk_free;
3435 printf(
"log_disk_level: channel path [%s], disk_size %1.0lf MiB, disk_free %1.0lf MiB, limit %1.0f MiB, disk level %.1f%%\n", log_chn->
path.c_str(), disk_size/
MiB, disk_free/
MiB, limit/
MiB, level*100.0);
3443 static DWORD last_check_time = 0;
3445 if (last_check_time == 0)
3469 size =
sizeof(
BOOL);
3474 cm_msg(
MINFO,
"get_trans_flag",
"ODB \"/Logger/Async transitions\" is obsolete, please delete it");
3477 size =
sizeof(
BOOL);
3482 cm_msg(
MINFO,
"get_trans_flag",
"ODB \"/Logger/Multithread transitions\" is obsolete, please delete it");
3485 size =
sizeof(
BOOL);
3511 size =
sizeof(
BOOL);
3528 cm_msg(
MERROR,
"stop_the_run",
"another transition is in progress, will try again later");
3532 cm_msg(
MERROR,
"stop_the_run",
"cannot stop the run, cm_transition() status %d, error: %s",
status, errstr);
3548 size =
sizeof(
BOOL);
3553 cm_msg(
MINFO,
"start_the_run",
"Run auto restart canceled");
3558 size =
sizeof(
state);
3561 cm_msg(
MERROR,
"start_the_run",
"cannot get Runinfo/State in database, db_get_value() status %d",
status);
3565 static int backoff = 1;
3568 cm_msg(
MINFO,
"start_the_run",
"Runinfo/State %d is not STATE_STOPPED, will try again in %d seconds",
state, backoff);
3572 else if (backoff > 1*60)
3592 cm_msg(
MTALK,
"start_the_run",
"starting new run");
3595 cm_msg(
MERROR,
"start_the_run",
"cannot restart run: cm_transition() status %d, error: %s",
status, errstr);
3637 cm_msg(
MTALK,
"log_write",
"Error writing output file, stopping run");
3638 cm_msg(
MERROR,
"log_write",
"Cannot write \'%s\', error %d, stopping run", log_chn->
path.c_str(),
status);
3650 cm_msg(
MTALK,
"log_write",
"stopping run after having received %1.0lf events",
3659 size =
sizeof(duration);
3704 next_subrun =
FALSE;
3705 size =
sizeof(next_subrun);
3726 next_subrun =
FALSE;
3736 cm_msg(
MTALK,
"log_write",
"stopping run after having received %1.0lf mega bytes",
3749 const double MiB = 1024*1024;
3750 double disk_size = 0;
3751 double disk_free = 0;
3755 double limit = 10E6;
3757 if (disk_size > 100E9) {
3759 }
else if (disk_size > 10E9) {
3763 if (disk_free < limit) {
3765 cm_msg(
MTALK,
"log_write",
"disk nearly full, stopping the run");
3766 cm_msg(
MERROR,
"log_write",
"Disk \'%s\' is almost full: %1.0lf MiBytes free out of %1.0f MiBytes, stopping the run", log_chn->
path.c_str(), disk_free/
MiB, disk_size/
MiB);
3781static std::vector<MidasHistoryInterface*>
mh;
3784static int add_event(
int* indexp, time_t timestamp,
int event_id,
const char* event_name,
HNDLE hKey,
int ntags,
const TAG* tags, time_t min_period,
int hotlink)
3788 int index = *indexp;
3793 printf(
"add_event: event %d, name \"%s\", ntags %d\n",
event_id, event_name, ntags);
3794 for (
i=0;
i<ntags;
i++) {
3795 printf(
"tag %d: name \"%s\", type %d, n_data %d\n",
i, tags[
i].
name, tags[
i].
type, tags[
i].n_data);
3802 if (strcmp(
hist_log[
i].event_name, event_name) == 0) {
3803 cm_msg(
MERROR,
"add_event",
"Duplicate event name \'%s\' with event id %d", event_name,
event_id);
3824 for (
i=0;
i<ntags;
i++) {
3826 cm_msg(
MERROR,
"add_event",
"Invalid tag %d \'%s\' in event %d \'%s\': cannot do history for TID_STRING data, sorry!",
i, tags[
i].
name,
event_id, event_name);
3830 cm_msg(
MERROR,
"add_event",
"Invalid tag %d \'%s\' in event %d \'%s\': cannot do history for TID_INT64 data, sorry!",
i, tags[
i].
name,
event_id, event_name);
3834 cm_msg(
MERROR,
"add_event",
"Invalid tag %d \'%s\' in event %d \'%s\': cannot do history for TID_UINT64 data, sorry!",
i, tags[
i].
name,
event_id, event_name);
3844 for (
i=0;
i<ntags;
i++) {
3845 if (isspace(tags[
i].
name[strlen(tags[
i].
name)-1])) {
3846 cm_msg(
MERROR,
"add_event",
"Invalid tag %d \'%s\' in event %d \'%s\': has trailing spaces",
i, tags[
i].
name,
event_id, event_name);
3851 for (
unsigned i=0;
i<
mh.size();
i++) {
3852 status =
mh[
i]->hs_define_event(event_name, timestamp, ntags, tags);
3854 cm_msg(
MERROR,
"add_event",
"Cannot define event \"%s\", hs_define_event() status %d", event_name,
status);
3862 cm_msg(
MERROR,
"add_event",
"Cannot define event \"%s\", db_get_record_size() status %d", event_name,
status);
3876 cm_msg(
MERROR,
"add_event",
"Cannot allocate data buffer for event \"%s\" size %d", event_name, size);
3885 "Cannot hotlink event %d \"%s\" for history logging, db_open_record() status %d",
3894 printf(
"Created event %d for equipment \"%s\", %d tags, size %d\n",
event_id, event_name, ntags, size);
3905 INT n_var, n_tags, n_names = 0;
3906 HNDLE hKeyRoot, hKeyVar, hLinkKey, hVarKey, hKeyEq, hHistKey,
hKey;
3909 KEY key, varkey, linkkey, histkey;
3912 int global_per_variable_history = 0;
3914 time_t now = time(NULL);
3920 for (
unsigned i=0;
i<
mh.size();
i++)
3942 size =
sizeof(active);
3947 size =
sizeof(
debug);
3951 int per_variable = 1;
3952 size =
sizeof(per_variable);
3963 size =
sizeof(active);
3968 size =
sizeof(
debug);
3979 size =
sizeof(active);
3984 size =
sizeof(
debug);
3995 size =
sizeof(active);
4000 size =
sizeof(
debug);
4011 size =
sizeof(active);
4016 size =
sizeof(
debug);
4027 size =
sizeof(active);
4032 size =
sizeof(
debug);
4042 cm_msg(
MERROR,
"open_history",
"Something is wrong with /Logger/History, db_find_key() status %d",
status);
4048 for (
int ichan = 0; ; ichan++) {
4058 if (strcasecmp(hi->
type,
"MIDAS")==0) {
4065 global_per_variable_history = 1;
4066 }
else if (strcasecmp(hi->
type,
"FILE")==0) {
4073 global_per_variable_history = 1;
4074 }
else if (strcasecmp(hi->
type,
"ODBC")==0) {
4075 global_per_variable_history = 1;
4076 }
else if (strcasecmp(hi->
type,
"SQLITE")==0) {
4077 global_per_variable_history = 1;
4078 }
else if (strcasecmp(hi->
type,
"MYSQL")==0) {
4079 global_per_variable_history = 1;
4080 }
else if (strcasecmp(hi->
type,
"PGSQL")==0) {
4081 global_per_variable_history = 1;
4085 cm_msg(
MINFO,
"open_history",
"Writing history to channel \'%s\' type \'%s\'", hi->
name, hi->
type);
4093 for (
unsigned i=0;
i<
mh.size();
i++) {
4104 cm_msg(
MERROR,
"open_history",
"mlogger ODB setting /History/PerVariableHistory is obsolete, please delete it. Use /Logger/History/MIDAS/PerVariableHistory instead");
4106 global_per_variable_history =
i;
4109 if (global_per_variable_history) {
4110 static int previous = -1;
4111 if (global_per_variable_history != previous) {
4112 if (global_per_variable_history)
4113 cm_msg(
MINFO,
"open_history",
"Per-variable history is enabled");
4117 previous = global_per_variable_history;
4129 "/Equipment/Trigger/Statistics/Events per sec.");
4133 "/Equipment/Trigger/Statistics/kBytes per sec.");
4142 cm_msg(
MINFO,
"open_history",
"Cannot find /Equipment entry in database, history system is inactive");
4147 cm_msg(
MERROR,
"open_history",
"Cannot find /Equipment entry in database, db_find_key() status %d",
status);
4153 for (ieq = 0; ; ieq++) {
4158 int32_t min_period = 0;
4161 size =
sizeof(min_period);
4165 if (min_period > 0) {
4166 BOOL per_variable_history = global_per_variable_history;
4172 if (strchr(eq_name,
':'))
4173 cm_msg(
MERROR,
"open_history",
"Equipment name \'%s\' contains characters \':\', this may break the history system", eq_name);
4177 cm_msg(
MERROR,
"open_history",
"Cannot find /Equipment/%s/Variables entry in database", eq_name);
4181 size =
sizeof(eq_id);
4191 (
"\n==================== Equipment \"%s\", ID %d =======================\n",
4195 for (n_var = 0, n_tags = 0;; n_var++) {
4222 cm_msg(
MINFO,
"open_history",
"Equipment \"%s\" history is enabled, but there are no Variables in ODB", eq_name);
4225 tag = (
TAG *) calloc(
sizeof(
TAG), n_tags);
4237 HNDLE hKeyNames = 0;
4238 BOOL single_names =
false;
4243 sprintf(
str,
"Settings/Names %s", varkey.
name);
4247 printf(
"Using \"/Equipment/%s/Settings/Names %s\" for variable \"%s\"\n", eq_name, varkey.
name, varkey.
name);
4257 single_names = (hKeyNames > 0);
4261 printf(
"Using \"/Equipment/%s/Settings/Names\" for variable \"%s\"\n", eq_name, varkey.
name);
4269 if (hKeyNames && n_names < varkey.
num_values) {
4271 "Array size mismatch: \"/Equipment/%s/Settings/%s\" has %d entries while \"/Equipment/%s/Variables/%s\" has %d entries",
4283 tag[i_tag].
name[0] = 0;
4286 size =
sizeof(xname);
4289 mstrlcpy(tag[i_tag].
name, xname,
sizeof(tag[i_tag].
name));
4291 if (strlen(tag[i_tag].
name) < 1) {
4293 sprintf(buf,
"%d",
j);
4303 "Name for history entry \"%s %s\" too long", tag[i_tag].
name, varkey.
name);
4315 printf(
"Defined tag %d, name \"%s\", type %d, num_values %d\n",
4316 i_tag, tag[i_tag].
name, tag[i_tag].
type, tag[i_tag].n_data);
4340 printf(
"Defined tag %d, name \"%s\", type %d, num_values %d\n", i_tag, tag[i_tag].
name,
4341 tag[i_tag].
type, tag[i_tag].n_data);
4351 printf(
"Defined tag %d, name \"%s\", type %d, num_values %d\n", i_tag, tag[i_tag].
name,
4352 tag[i_tag].
type, tag[i_tag].n_data);
4357 if (per_variable_history && i_tag>0) {
4365 assert(i_tag <= n_tags);
4376 if (!per_variable_history && i_tag>0) {
4377 assert(i_tag <= n_tags);
4391 if (eq_id > max_event_id)
4392 max_event_id = eq_id;
4399 max_event_id = ((int) ((max_event_id + 1) / 10) + 1) * 10;
4403 for (li = 0;; li++) {
4409 strcpy(hist_name, histkey.
name);
4414 cm_msg(
MERROR,
"open_history",
"Only subkeys allows in /History/Links, key \"%s\"",
key.
name);
4419 printf(
"\n==================== History link \"%s\", ID %d =======================\n",
4420 hist_name, max_event_id);
4423 for (
i = n_var = 0;;
i++) {
4435 "History link /History/Links/%s/%s is invalid", hist_name,
key.
name);
4441 cm_msg(
MERROR,
"open_history",
"History event %s has no variables in ODB", hist_name);
4444 tag = (
TAG *) calloc(
sizeof(
TAG), n_var);
4446 assert(tag != NULL);
4448 for (
i = 0, size = 0, n_var = 0;;
i++) {
4469 strcpy(tag[n_var].
name, linkkey.
name);
4474 printf(
"Defined tag \"%s\", type %d, num_values %d\n",
4475 tag[n_var].
name, tag[n_var].
type, tag[n_var].n_data);
4502 tag = (
TAG *) calloc(
sizeof(
TAG), 2);
4504 assert(tag != NULL);
4506 strcpy(tag[0].
name,
"State");
4510 strcpy(tag[1].
name,
"Run number");
4514 const char* event_name =
"Run transitions";
4516 for (
unsigned i=0;
i<
mh.size();
i++) {
4517 status =
mh[
i]->hs_define_event(event_name, now, 2, tag);
4519 cm_msg(
MERROR,
"add_event",
"Cannot define event \"%s\", hs_define_event() status %d", event_name,
status);
4538 double telapsed = tend - tstart;
4539 if (telapsed > 10.0) {
4540 cm_msg(
MERROR,
"open_history",
"open_history() took %.3f seconds", telapsed);
4552 time_t flush_period_sec = 1;
4557 printf(
"flush history buffers!\n");
4559 for (
unsigned h = 0; h <
mh.size(); h++)
4560 mh[h]->hs_flush_buffers();
4576 for (
int i = 0;;
i++) {
4595 for (
unsigned h=0; h<
mh.size(); h++) {
4596 mh[h]->hs_disconnect();
4611 time_t now = time(NULL);
4630 printf(
"Error in history system, aborting.\n");
4642 for (
unsigned h=0; h<
mh.size(); h++) {
4646 printf(
"write_history_event: \'%s\', channel \'%s\' hs_write_event() status %d\n",
hist_log[
i].event_name,
mh[h]->
name,
status);
4652 if (end_millitime - start_millitime > 3000)
4653 cm_msg(
MINFO,
"log_history",
"History write operation took %d ms", end_millitime - start_millitime);
4667 time_t now = time(NULL);
4673 for (
i = 0, total_size = 0;;
i++) {
4688 printf(
"Error in history system, aborting.\n");
4700 for (
unsigned h=0; h<
mh.size(); h++)
4706 if (end_millitime - start_millitime > 3000)
4707 cm_msg(
MINFO,
"log_system_history",
"History write operation took %d ms", end_millitime - start_millitime);
4716 std::string data_dir;
4724 std::string filename = chn_settings->
filename;
4727 bool ispipe =
false;
4729 char* p = strchr(chn_settings->
filename,
'>');
4730 if (chn_settings->
filename[0] ==
'|' && p) {
4741 const char*s = chn_settings->
filename;
4764 if (data_dir.empty()) {
4778 localtime_r(&now, &tms);
4781 strftime(dir,
sizeof(dir), chn_settings->
subdir_format, &tms);
4793 if (
status == -1 && errno != EEXIST)
4794 cm_msg(
MERROR,
"log_generate_file_name",
"Cannot create subdirectory \"%s\", mkdir() errno %d (%s)",
str.c_str(), errno, strerror(errno));
4803 if (strchr(
str.c_str(),
'%')) {
4804 if (strchr(strchr(
str.c_str(),
'%')+1,
'%')) {
4820 log_chn->
path = path;
4824 if (strncmp(path.c_str(), data_dir.c_str(), data_dir.length()) == 0)
4825 tmpstr = path.c_str() + data_dir.length();
4829 mstrlcpy(cstr, tmpstr.c_str(),
sizeof(cstr));
4837 if (strchr(strchr(
str.c_str(),
'%')+1,
'%')) {
4889 }
while (n_bytes > 0);
4907 *p_tape_flag = tape_flag;
4946 time_t now = time(NULL);
4948 for (
unsigned h=0; h<
mh.size(); h++)
4949 mh[h]->
hs_write_event(
"Run transitions", now,
sizeof(eb), (
const char*)eb);
4959 assert(
info != NULL);
4969 printf(
"Channel %s settings updated\n", log_chn->
name.c_str());
4989 HNDLE hKeyRoot, hKeyChannel;
4998 assert(error != NULL);
5005 std::string
str =
"last.json";
5023 size =
sizeof(
BOOL);
5041 strcpy(error,
"Cannot create channel entry in database");
5048 strcpy(error,
"Cannot create channel entry in database");
5078 strcpy(error,
"Cannot find channel settings info");
5086 strcpy(error,
"Cannot find channel statistics info");
5107 strcpy(error,
"Cannot read channel info");
5120 if (!chn_settings->
active || !write_data)
5135 sprintf(error,
"Cannot open file \'%s\' (See messages)", chn->
path.c_str());
5137 sprintf(error,
"File \'%s\' exists already, run start aborted", chn->
path.c_str());
5139 sprintf(error,
"No tape in device \'%s\'", chn->
path.c_str());
5141 sprintf(error,
"Tape error, cannot start run");
5143 sprintf(error,
"Device \'%s\' used by someone else", chn->
path.c_str());
5145 sprintf(error,
"Cannot open FTP channel to \'%s\'", chn->
path.c_str());
5147 sprintf(error,
"No ROOT support compiled into mlogger, please compile with -DHAVE_ROOT flag");
5150 sprintf(error,
"Invalid data format, please use \"MIDAS\", \"ASCII\", \"DUMP\" or \"ROOT\"");
5168 cm_msg(
MERROR,
"tr_start",
"Cannot change access mode for statistics record, error %d",
status);
5170 cm_msg(
MINFO,
"tr_start",
"Recovered access mode for statistics record of channel \"%s\"", chn->
name.c_str());
5175 cm_msg(
MERROR,
"tr_start",
"Cannot open statistics record for channel \"%s\", error %d", chn->
name.c_str(),
status);
5180 cm_msg(
MERROR,
"tr_start",
"db_watch() status %d, cannot open channel settings record, probably other logger is using it",
status);
5186 sprintf(error,
"Cannot open buffer %s", chn_settings->
buffer);
5196 sprintf(error,
"Cannot place event request");
5214 sprintf(error,
"Cannot place event request");
5226 cm_msg(
MTALK,
"tr_start",
"tape mounting finished");
5235 write_runlog_sql(
TRUE);
5246 printf(
"tr_start: run %d started in %d ms: odb dump %d ms, close channels %d ms, configure channels %d ms, configure history %d ms, write runlog %d ms\n",
5269 printf(
"tr_start_abort: run %d\n",
run_number);
5276 cm_msg(
MINFO,
"tr_start_abort",
"Deleting previous file \"%s\"", chn->
path.c_str());
5277 unlink(chn->
path.c_str());
5325 size =
sizeof(flag);
5329 strcpy(
str,
"run%d.json");
5334 strcpy(
str,
"run%d.json");
5337 if (strchr(
str,
'%'))
5340 strcpy(filename,
str);
5349 write_runlog_sql(
FALSE);
5361 cm_msg(
MTALK,
"tr_stop",
"all tape channels closed");
5374 size =
sizeof(delay);
5383 printf(
"tr_stop: run %d stopped in %d ms: close channels %d ms, odb dump %d ms, write run log %d ms, write history %d ms\n",
5432 printf(
"write data event: req %d, evid %d, timestamp %d, size %d\n", request_id, pheader->
event_id, pheader->
time_stamp, pheader->
data_size);
5461 DWORD last_time_kb = 0;
5462 DWORD last_time_stat = 0;
5467 signal(SIGPIPE, SIG_IGN);
5470 setbuf(stdout, NULL);
5471 setbuf(stderr, NULL);
5479 for (
i = 1;
i < argc;
i++) {
5480 if (argv[
i][0] ==
'-' && argv[
i][1] ==
'd')
5482 else if (argv[
i][0] ==
'-' && argv[
i][1] ==
'D')
5484 else if (argv[
i][0] ==
'-' && argv[
i][1] ==
's')
5486 else if (argv[
i][0] ==
'-' && argv[
i][1] ==
'v')
5488 else if (argv[
i][0] ==
'-') {
5489 if (
i + 1 >= argc || argv[
i + 1][0] ==
'-')
5491 if (argv[
i][1] ==
'e')
5495 printf(
"usage: mlogger [-e Experiment] [-d] [-D] [-s] [-v]\n\n");
5502 printf(
"Becoming a daemon...\n");
5513 printf(
"Logger runs already.\n");
5551 printf(
"Error in history system, aborting startup.\n");
5557 std::string data_dir;
5559 if (data_dir.length() <= 0)
5561 printf(
"Data directory is \"%s\" unless specified under /Logger/channels/\n", data_dir.c_str());
5564 std::string message_dir;
5566 if (message_dir.empty()) {
5567 message_dir = data_dir;
5568 printf(
"Message directory is \"%s\" unless specified in /Logger/Message dir\n", message_dir.c_str());
5570 printf(
"Message directory is \"%s\"\n", message_dir.c_str());
5577 printf(
"History directory is \"%s\" unless specified under /Logger/history/\n",
history_dir.c_str());
5579 printf(
"History directory is \"%s\"\n",
history_dir.c_str());
5583 std::string sql_host;
5585 std::string sql_table;
5593 printf(
"SQL database is %s/%s/%s", sql_host.c_str(), sql_db.c_str(), sql_table.c_str());
5598 printf(
"\nMIDAS logger started. Stop with \"!\"\n");
5633 size =
sizeof(duration);
5637 cm_msg(
MTALK,
"main",
"stopping run after %d seconds", duration);
5644 cm_msg(
MTALK,
"main",
"another attempt to stop the run");
5659 if ((
char) ch ==
'!')
5674 printf(
"Stopping image history threads...");
char type[NAME_LENGTH]
history channel name
int wr_write(LOG_CHN *log_chn, const void *data, const int size)
int wr_close(LOG_CHN *log_chn, int run_number)
std::string wr_get_file_ext()
int wr_open(LOG_CHN *log_chn, int run_number)
std::string wr_get_chain()
WriterCRC32C(LOG_CHN *log_chn, int level, WriterInterface *wr)
int wr_close(LOG_CHN *log_chn, int run_number)
std::string wr_get_file_ext()
int wr_write(LOG_CHN *log_chn, const void *data, const int size)
WriterCRC32Zlib(LOG_CHN *log_chn, int level, WriterInterface *wr)
std::string wr_get_chain()
int wr_open(LOG_CHN *log_chn, int run_number)
int wr_close(LOG_CHN *log_chn, int run_number)
WriterFile(LOG_CHN *log_chn)
std::string wr_get_chain()
int wr_write(LOG_CHN *log_chn, const void *data, const int size)
int wr_open(LOG_CHN *log_chn, int run_number)
std::string wr_get_file_ext()
WriterFtp(LOG_CHN *log_chn)
int wr_open(LOG_CHN *log_chn, int run_number)
std::string wr_get_chain()
int wr_write(LOG_CHN *log_chn, const void *data, const int size)
int wr_close(LOG_CHN *log_chn, int run_number)
int wr_write(LOG_CHN *log_chn, const void *data, const int size)
std::string wr_get_chain()
WriterGzip(LOG_CHN *log_chn, int compress)
std::string wr_get_file_ext()
int wr_close(LOG_CHN *log_chn, int run_number)
int wr_open(LOG_CHN *log_chn, int run_number)
virtual ~WriterInterface()
virtual int wr_close(LOG_CHN *log_chn, int run_number)=0
virtual int wr_open(LOG_CHN *log_chn, int run_number)=0
virtual std::string wr_get_chain()=0
virtual std::string wr_get_file_ext()
virtual int wr_write(LOG_CHN *log_chn, const void *data, const int size)=0
std::string wr_get_file_ext()
MLZ4F_compressionContext_t fContext
int wr_write(LOG_CHN *log_chn, const void *data, const int size)
int wr_open(LOG_CHN *log_chn, int run_number)
MLZ4F_preferences_t fPrefs
WriterLZ4(LOG_CHN *log_chn, WriterInterface *wr)
std::string wr_get_chain()
int wr_close(LOG_CHN *log_chn, int run_number)
int wr_open(LOG_CHN *log_chn, int run_number)
std::string wr_get_file_ext()
bool fSimulateCompression
WriterNull(LOG_CHN *log_chn)
std::string wr_get_chain()
int wr_close(LOG_CHN *log_chn, int run_number)
int wr_write(LOG_CHN *log_chn, const void *data, const int size)
std::string wr_get_file_ext()
int wr_open(LOG_CHN *log_chn, int run_number)
int wr_close(LOG_CHN *log_chn, int run_number)
int wr_write(LOG_CHN *log_chn, const void *data, const int size)
WriterPopen(LOG_CHN *log_chn, const char *pipe_command, const char *file_ext)
std::string wr_get_chain()
std::string toHex(unsigned char c)
std::string wr_get_chain()
int wr_close(LOG_CHN *log_chn, int run_number)
int wr_open(LOG_CHN *log_chn, int run_number)
WriterSHA256(LOG_CHN *log_chn, int level, WriterInterface *wr)
std::string toString(const unsigned char sha256sum[32])
mbedtls_sha256_context fCtx
int wr_write(LOG_CHN *log_chn, const void *data, const int size)
std::string wr_get_file_ext()
int wr_write(LOG_CHN *log_chn, const void *data, const int size)
std::string toString(const unsigned char sha512sum[64])
mbedtls_sha512_context fCtx
std::string toHex(unsigned char c)
std::string wr_get_file_ext()
std::string wr_get_chain()
int wr_close(LOG_CHN *log_chn, int run_number)
WriterSHA512(LOG_CHN *log_chn, int level, WriterInterface *wr)
int wr_open(LOG_CHN *log_chn, int run_number)
INT transition(INT run_number, char *error)
uint32_t crc32c(uint32_t crc, const void *buf, size_t len)
int ftp_login(FTP_CON **con, const char *host, unsigned short port, const char *user, const char *password, const char *account)
int ftp_close(FTP_CON *con)
int ftp_command(FTP_CON *con, const char *command, const char *param,...)
#define FTP_RESPONSE_ERROR
void ftp_debug(int(*debug_func)(const char *message), int(*error_func)(const char *message))
int ftp_send(int sock, const char *buffer, int n_bytes_to_write)
int ftp_bye(FTP_CON *con)
#define ftp_chdir(ftp, dir)
#define ftp_open_write(ftp, file)
INT bm_open_buffer(const char *buffer_name, INT buffer_size, INT *buffer_handle)
INT bm_delete_request(INT request_id)
INT bm_request_event(HNDLE buffer_handle, short int event_id, short int trigger_mask, INT sampling_type, HNDLE *request_id, EVENT_HANDLER *func)
INT bm_set_cache_size(INT buffer_handle, size_t read_size, size_t write_size)
INT bm_close_buffer(INT buffer_handle)
INT bm_compose_event(EVENT_HEADER *event_header, short int event_id, short int trigger_mask, DWORD data_size, DWORD serial)
INT cm_register_transition(INT transition, INT(*func)(INT, char *), INT sequence_number)
INT cm_yield(INT millisec)
INT cm_get_experiment_database(HNDLE *hDB, HNDLE *hKeyClient)
INT cm_connect_experiment(const char *host_name, const char *exp_name, const char *client_name, void(*func)(char *))
INT cm_transition(INT transition, INT run_number, char *errstr, INT errstr_size, INT async_flag, INT debug_flag)
INT cm_disconnect_experiment(void)
std::string cm_get_path()
INT cm_get_environment(char *host_name, int host_name_size, char *exp_name, int exp_name_size)
INT cm_set_watchdog_params(BOOL call_watchdog, DWORD timeout)
INT cm_exist(const char *name, BOOL bUnique)
static void xwrite(const char *filename, int fd, const void *data, int size)
#define CM_TRANSITION_IN_PROGRESS
#define DB_NO_MORE_SUBKEYS
#define SS_INVALID_FORMAT
static INT hs_write_event(DWORD event_id, const void *data, DWORD size)
#define MESSAGE_BUFFER_NAME
#define MAX_STRING_LENGTH
#define MESSAGE_BUFFER_SIZE
double ss_disk_size(const char *path)
time_t ss_mktime(struct tm *tms)
INT ss_getchar(BOOL reset)
double ss_disk_free(const char *path)
double ss_file_size(const char *path)
INT ss_daemon_init(BOOL keep_stdout)
INT cm_msg_flush_buffer()
INT cm_msg(INT message_type, const char *filename, INT line, const char *routine, const char *format,...)
BOOL equal_ustring(const char *str1, const char *str2)
INT db_get_data_index(HNDLE hDB, HNDLE hKey, void *data, INT *buf_size, INT idx, DWORD type)
INT db_send_changed_records()
INT db_get_value(HNDLE hDB, HNDLE hKeyRoot, const char *key_name, void *data, INT *buf_size, DWORD type, BOOL create)
INT db_save_json(HNDLE hDB, HNDLE hKey, const char *filename, int flags)
INT db_open_record(HNDLE hDB, HNDLE hKey, void *ptr, INT rec_size, WORD access_mode, void(*dispatcher)(INT, INT, void *), void *info)
std::string strcomb1(const char **list)
INT db_save_xml(HNDLE hDB, HNDLE hKey, const char *filename)
INT db_get_path(HNDLE hDB, HNDLE hKey, char *path, INT buf_size)
INT db_get_record1(HNDLE hDB, HNDLE hKey, void *data, INT *buf_size, INT align, const char *rec_str)
INT db_copy(HNDLE hDB, HNDLE hKey, char *buffer, INT *buffer_size, const char *path)
INT db_get_record_size(HNDLE hDB, HNDLE hKey, INT align, INT *buf_size)
INT db_get_data(HNDLE hDB, HNDLE hKey, void *data, INT *buf_size, DWORD type)
INT db_create_key(HNDLE hDB, HNDLE hKey, const char *key_name, DWORD type)
INT db_check_record(HNDLE hDB, HNDLE hKey, const char *keyname, const char *rec_str, BOOL correct)
INT db_copy_json_save(HNDLE hDB, HNDLE hKey, char **buffer, int *buffer_size, int *buffer_end)
INT db_copy_xml(HNDLE hDB, HNDLE hKey, char *buffer, int *buffer_size, bool header)
INT db_unwatch(HNDLE hDB, HNDLE hKey)
INT db_set_mode(HNDLE hDB, HNDLE hKey, WORD mode, BOOL recurse)
INT db_save(HNDLE hDB, HNDLE hKey, const char *filename, BOOL bRemote)
INT db_get_key(HNDLE hDB, HNDLE hKey, KEY *key)
INT db_get_link(HNDLE hDB, HNDLE hKey, KEY *key)
INT EXPRT db_get_value_string(HNDLE hdb, HNDLE hKeyRoot, const char *key_name, int index, std::string *s, BOOL create, int create_string_length)
INT db_watch(HNDLE hDB, HNDLE hKey, void(*dispatcher)(INT, INT, INT, void *), void *info)
INT db_enum_link(HNDLE hDB, HNDLE hKey, INT idx, HNDLE *subkey_handle)
int EXPRT json_write_anything(HNDLE hDB, HNDLE hKey, char **buffer, int *buffer_size, int *buffer_end, int level, int must_be_subdir, int flags, time_t timestamp)
INT db_sprintf(char *string, const void *data, INT data_size, INT idx, DWORD type)
INT db_set_value(HNDLE hDB, HNDLE hKeyRoot, const char *key_name, const void *data, INT data_size, INT num_values, DWORD type)
INT db_find_key(HNDLE hDB, HNDLE hKey, const char *key_name, HNDLE *subhKey)
BOOL ends_with_ustring(const char *str, const char *suffix)
void json_write(char **buffer, int *buffer_size, int *buffer_end, int level, const char *s, int quoted)
static DATABASE * db_lock_database(HNDLE hDB, int *pstatus, const char *caller, bool check_attached=true)
INT db_open_record1(HNDLE hDB, HNDLE hKey, void *ptr, INT rec_size, WORD access_mode, void(*dispatcher)(INT, INT, void *), void *info, const char *rec_str)
INT db_set_record(HNDLE hDB, HNDLE hKey, void *data, INT buf_size, INT align)
INT db_enum_key(HNDLE hDB, HNDLE hKey, INT idx, HNDLE *subkey_handle)
static void db_unlock_database(DATABASE *pdb, const char *caller)
INT db_close_record(HNDLE hDB, HNDLE hKey)
INT db_create_record(HNDLE hDB, HNDLE hKey, const char *orig_key_name, const char *init_str)
INT db_create_link(HNDLE hDB, HNDLE hKey, const char *link_name, const char *destination)
INT db_protect_database(HNDLE hDB)
const char * rpc_tid_name(INT id)
int hs_save_event_list(const std::vector< std::string > *pevents)
int hs_get_history(HNDLE hDB, HNDLE hKey, int flags, int debug_flag, MidasHistoryInterface **mh)
std::string history_dir()
char exp_name[NAME_LENGTH]
BOOL debug
debug printouts
INT bor(INT run_number, char *error)
char host_name[HOST_NAME_LENGTH]
static void compress(int init_bits, gdGifBuffer *buffer, gdImagePtr im)
static void output(code_int code)
bool ends_with_char(const std::string &s, char c)
INT bm_get_buffer_level(INT buffer_handle, INT *n_bytes)
std::string msprintf(const char *format,...)
#define DIR_SEPARATOR_STR
#define JSFLAG_FOLLOW_LINKS
#define JSFLAG_OMIT_LAST_WRITTEN
#define DEFAULT_BUFFER_SIZE
#define JSFLAG_OMIT_NAMES
#define message(type, str)
#define write(n, a, f, d)
int select_compression_module(HNDLE hDB, HNDLE hSet, const char *name)
void log_history(HNDLE hDB, HNDLE hKey, void *info)
void receive_event(HNDLE hBuf, HNDLE request_id, EVENT_HEADER *pheader, void *pevent)
void create_runlog_json_tree()
INT tr_stop(INT run_number, char *error)
#define DISK_CHECK_INTERVAL_MILLISEC
std::string get_value(HNDLE hDB, HNDLE hDir, const char *name)
INT tr_start_abort(INT run_number, char *error)
static std::vector< MidasHistoryInterface * > mh
EVENT_DEF * db_get_event_definition(short int event_id)
void log_odb_dump_json(LOG_CHN *log_chn, short int event_id, INT run_number)
void maybe_flush_history(time_t now)
void log_odb_dump(LOG_CHN *log_chn, short int event_id, INT run_number)
int log_create_writer(LOG_CHN *log_chn)
void stop_image_history()
#define CHN_TREE_STR(_name)
INT tr_pause(INT run_number, char *error)
static std::vector< std::string > history_events
int log_generate_file_name(LOG_CHN *log_chn)
static FILE * fopen_wx(const char *filename)
static int get_trans_flag()
void log_system_history(HNDLE hDB, HNDLE hKey, void *info)
int select_checksum_module(HNDLE hDB, HNDLE hSet, const char *name)
INT tr_start(INT run_number, char *error)
WriterInterface * NewCompression(LOG_CHN *log_chn, int code, WriterInterface *chained)
INT log_open(LOG_CHN *log_chn, INT run_number)
#define EVENT_DEF_CACHE_SIZE
INT ftp_error(const char *message)
time_t last_history_flush
INT tr_resume(INT run_number, char *error)
WriterInterface * NewChecksum(LOG_CHN *log_chn, int code, int level, WriterInterface *chained)
WriterInterface * NewWriterBzip2(LOG_CHN *log_chn)
int maybe_check_disk_level()
INT log_close(LOG_CHN *log_chn, INT run_number)
void create_runlog_ascii_tree()
void odb_save(const char *filename, bool make_file_readonly)
void log_odb_dump_xml(LOG_CHN *log_chn, short int event_id, INT run_number)
void set_value(HNDLE hDB, HNDLE hDir, const char *name, const std::string &set, const std::string &def)
int check_add(int v, int n, const std::string &val, const char *str, bool bdef, std::string *def, std::string *sel)
static std::string TimeToString(time_t t)
#define CHN_SETTINGS_STR(_name)
INT ftp_open(const char *xdestination, FTP_CON **con)
std::vector< LOG_CHN * > log_channels
int select_output_module(HNDLE hDB, HNDLE hSet, const char *name)
static void watch_settings(HNDLE hDB, HNDLE hKey, HNDLE index, void *info)
static std::string IntToString(int value)
int get_number_image_history_threads()
LOG_CHN * new_LOG_CHN(const char *name)
static int write_history(DWORD transition, DWORD run_number)
static int add_event(int *indexp, time_t timestamp, int event_id, const char *event_name, HNDLE hKey, int ntags, const TAG *tags, time_t min_period, int hotlink)
INT log_write(LOG_CHN *log_chn, EVENT_HEADER *pheader)
static bool check_file_exists(const char *filename)
static struct hist_log_s * hist_log
void log_odb_dump_odb(LOG_CHN *log_chn, short int event_id, INT run_number)
#define CHN_STATISTICS_STR(_name)
void start_image_history()
static std::string xpathname(const char *xpath, int level)
void write_runlog_json(BOOL bor)
void write_runlog_ascii(BOOL bor)
int log_disk_level(LOG_CHN *log_chn, double *pdisk_size, double *pdisk_free)
int close_channels(int run_number, BOOL *p_tape_flag)
WriterInterface * NewWriterPbzip2(LOG_CHN *log_chn)
int stop_the_run(int restart)
void mbedtls_sha256_finish(mbedtls_sha256_context *ctx, unsigned char output[32])
SHA-256 final digest.
void mbedtls_sha256_update(mbedtls_sha256_context *ctx, const unsigned char *input, size_t ilen)
SHA-256 process buffer.
void mbedtls_sha256_free(mbedtls_sha256_context *ctx)
Clear SHA-256 context.
void mbedtls_sha256_init(mbedtls_sha256_context *ctx)
Initialize SHA-256 context.
void mbedtls_sha256_starts(mbedtls_sha256_context *ctx, int is224)
SHA-256 context setup.
void mbedtls_sha512_starts(mbedtls_sha512_context *ctx, int is384)
SHA-512 context setup.
void mbedtls_sha512_update(mbedtls_sha512_context *ctx, const unsigned char *input, size_t ilen)
SHA-512 process buffer.
void mbedtls_sha512_free(mbedtls_sha512_context *ctx)
Clear SHA-512 context.
void mbedtls_sha512_finish(mbedtls_sha512_context *ctx, unsigned char output[64])
SHA-512 final digest.
void mbedtls_sha512_init(mbedtls_sha512_context *ctx)
Initialize SHA-512 context.
uint32_t bzip2_compression
double obsolete_tape_capacity
uint32_t pbzip2_compression
uint32_t gzip_compression
double bytes_written_subrun
double bytes_written_total
double bytes_written_uncompressed
CHN_STATISTICS statistics
SHA-256 context structure.
SHA-512 context structure.