MIDAS
Loading...
Searching...
No Matches
lazylogger.cxx File Reference
#include "midas.h"
#include "msystem.h"
#include "mstrlcpy.h"
#include <libgen.h>
#include <mutex>
#include <iostream>
#include "mdsupport.h"
#include <assert.h>
#include <vector>
#include <string>
#include <algorithm>
Include dependency graph for lazylogger.cxx:

Go to the source code of this file.

Classes

struct  DIRLOG
 
struct  LAZY_SETTING
 
struct  LAZY_STATISTICS
 
struct  LAZY_INFO
 

Macros

#define URL_SIZE   256
 
#define NOTHING_TODO   0
 
#define FORCE_EXIT   1
 
#define EXIT_REQUEST   2
 
#define TRY_LATER   3
 
#define NEW_FILE   1
 
#define REMOVE_FILE   2
 
#define REMOVE_ENTRY   3
 
#define MAX_LAZY_CHANNEL   100
 
#define TRACE
 
#define LOG_TYPE_SCRIPT   (-1)
 
#define DONTOPENZIP   0
 
#define MAX_FILE_PATH   128
 
#define LAZY_SETTINGS_STRING   "\Period = INT : 10\n\Maintain free space (%) = INT : 0\n\Stay behind = INT : 0\n\Alarm Class = STRING : [32]\n\Running condition = STRING : [128] ALWAYS\n\Data dir = STRING : [256] \n\Data format = STRING : [8] MIDAS\n\Filename format = STRING : [128] run%05d.mid\n\Backup type = STRING : [8] Tape\n\Execute after rewind = STRING : [64]\n\Path = STRING : [128] \n\Capacity (Bytes) = FLOAT : 5e9\n\List label= STRING : [128] \n\Execute before writing file = STRING : [64]\n\Execute after writing file = STRING : [64]\n\Modulo.Position = STRING : [8]\n\Copy Delay = INT : 0\n\Tape Data Append = BOOL : y\n\"
 
#define LAZY_STATISTICS_STRING   "\Backup file = STRING : [128] none \n\File size (Bytes) = DOUBLE : 0.0\n\KBytes copied = DOUBLE : 0.0\n\Total Bytes copied = DOUBLE : 0.0\n\Copy progress (%) = DOUBLE : 0\n\Copy Rate (Bytes per s) = DOUBLE : 0\n\Backup status (%) = DOUBLE : 0\n\Number of Files = INT : 0\n\Current Lazy run = INT : 0\n\"
 
#define WATCHDOG_TIMEOUT   60000 /* 60 sec for tape access */
 

Typedefs

typedef std::vector< DIRLOGDIRLOGLIST
 

Functions

bool cmp_dirlog1 (const DIRLOG &a, const DIRLOG &b)
 
bool cmp_dirlog (const DIRLOG &a, const DIRLOG &b)
 
INT moduloCheck (INT lModulo, INT lPosition, INT lrun)
 
BOOL lazy_file_exists (char *dir, char *file)
 
INT lazy_main (INT, LAZY_INFO *, int max_event_size)
 
INT lazy_copy (char *dev, char *file, int max_event_size)
 
INT lazy_load_params (HNDLE hDB, HNDLE hKey)
 
INT build_log_list (const char *fmt, const char *dir, DIRLOGLIST *plog)
 
INT build_done_list_odb (HNDLE, INT **)
 
void lazy_settings_hotlink (HNDLE hDB, HNDLE hKey, void *info)
 
void lazy_maintain_check (HNDLE hKey, LAZY_INFO *pLall)
 
void print_dirlog (const DIRLOGLIST *dirlog)
 
INT lazy_trstop (INT rn, char *error)
 
INT lazy_run_extract (const char *name)
 
INT lazy_file_remove (const char *pufile)
 
INT lazy_log_update (INT action, INT run, const char *label, const char *file, DWORD perf_time)
 
std::string list_filename (const char *lazyname, const char *listname)
 
void load_done_list (const char *lazyname, const DIRLOGLIST *dirlist, DIRLOGLIST *dlist)
 
int save_list (const char *lazyname, const char *listname, const DIRLOGLIST *dlist)
 
void convert_done_list (HNDLE hLch)
 
INT build_done_list (HNDLE hLch, const DIRLOGLIST *pdirlist, DIRLOGLIST *pdone)
 
INT save_done_list (HNDLE hLch, DIRLOGLIST *pdone)
 
int find_next_file (const DIRLOGLIST *plog, const DIRLOGLIST *pdone)
 
INT lazy_select_purge (HNDLE hKey, INT channel, LAZY_INFO *pLall, const char *fmt, const char *dir, DIRLOG *f)
 
void lazy_statistics_update (INT cploop_time)
 
BOOL condition_test (char *string)
 
BOOL lazy_condition_check (void)
 
int lazy_disk_copy_loop (const char *outfile, const char *infile, FILE *fpout, FILE *fpin)
 
INT lazy_disk_copy (const char *outfile, const char *infile)
 
INT lazy_maintain_free_space (LAZY_INFO *pLch, LAZY_INFO *pLall)
 
static void watch_settings (HNDLE hDB, HNDLE hKey, HNDLE index, void *info)
 
int main (int argc, char **argv)
 

Variables

BOOL debug = FALSE
 debug printouts
 
BOOL nodelete = FALSE
 
LAZY_SETTING lazy
 
LAZY_STATISTICS lazyst
 
LAZY_INFO lazyinfo [MAX_LAZY_CHANNEL] = {{0, FALSE, "Tape"}}
 
INT channel = -1
 
INT lazy_semaphore
 
HNDLE hDB
 main ODB handle
 
HNDLE hKey
 
HNDLE pcurrent_hKey
 
double lastsz
 
HNDLE hKeyst
 
INT run_state
 
INT hDev
 
BOOL msg_flag
 
BOOL convert_flag = FALSE
 
BOOL copy_continue = TRUE
 
INT data_fmt
 
INT dev_type
 
char lazylog [MAX_STRING_LENGTH]
 
BOOL full_bck_flag = FALSE
 
BOOL maintain_touched = FALSE
 
INT blockn = 0
 
BOOL stop_transition = FALSE
 
BOOL delay_start = FALSE
 
DWORD lazy_time = 0
 

Macro Definition Documentation

◆ DONTOPENZIP

#define DONTOPENZIP   0

Definition at line 51 of file lazylogger.cxx.

◆ EXIT_REQUEST

#define EXIT_REQUEST   2

Definition at line 42 of file lazylogger.cxx.

◆ FORCE_EXIT

#define FORCE_EXIT   1

Definition at line 41 of file lazylogger.cxx.

◆ LAZY_SETTINGS_STRING

#define LAZY_SETTINGS_STRING   "\Period = INT : 10\n\Maintain free space (%) = INT : 0\n\Stay behind = INT : 0\n\Alarm Class = STRING : [32]\n\Running condition = STRING : [128] ALWAYS\n\Data dir = STRING : [256] \n\Data format = STRING : [8] MIDAS\n\Filename format = STRING : [128] run%05d.mid\n\Backup type = STRING : [8] Tape\n\Execute after rewind = STRING : [64]\n\Path = STRING : [128] \n\Capacity (Bytes) = FLOAT : 5e9\n\List label= STRING : [128] \n\Execute before writing file = STRING : [64]\n\Execute after writing file = STRING : [64]\n\Modulo.Position = STRING : [8]\n\Copy Delay = INT : 0\n\Tape Data Append = BOOL : y\n\"

Definition at line 122 of file lazylogger.cxx.

◆ LAZY_STATISTICS_STRING

#define LAZY_STATISTICS_STRING   "\Backup file = STRING : [128] none \n\File size (Bytes) = DOUBLE : 0.0\n\KBytes copied = DOUBLE : 0.0\n\Total Bytes copied = DOUBLE : 0.0\n\Copy progress (%) = DOUBLE : 0\n\Copy Rate (Bytes per s) = DOUBLE : 0\n\Backup status (%) = DOUBLE : 0\n\Number of Files = INT : 0\n\Current Lazy run = INT : 0\n\"

Definition at line 142 of file lazylogger.cxx.

◆ LOG_TYPE_SCRIPT

#define LOG_TYPE_SCRIPT   (-1)

Definition at line 50 of file lazylogger.cxx.

◆ MAX_FILE_PATH

#define MAX_FILE_PATH   128

Definition at line 119 of file lazylogger.cxx.

◆ MAX_LAZY_CHANNEL

#define MAX_LAZY_CHANNEL   100

Definition at line 48 of file lazylogger.cxx.

◆ NEW_FILE

#define NEW_FILE   1

Definition at line 45 of file lazylogger.cxx.

◆ NOTHING_TODO

#define NOTHING_TODO   0

Definition at line 40 of file lazylogger.cxx.

◆ REMOVE_ENTRY

#define REMOVE_ENTRY   3

Definition at line 47 of file lazylogger.cxx.

◆ REMOVE_FILE

#define REMOVE_FILE   2

Definition at line 46 of file lazylogger.cxx.

◆ TRACE

#define TRACE

Definition at line 49 of file lazylogger.cxx.

◆ TRY_LATER

#define TRY_LATER   3

Definition at line 43 of file lazylogger.cxx.

◆ URL_SIZE

#define URL_SIZE   256

Definition at line 31 of file lazylogger.cxx.

◆ WATCHDOG_TIMEOUT

#define WATCHDOG_TIMEOUT   60000 /* 60 sec for tape access */

Definition at line 217 of file lazylogger.cxx.

Typedef Documentation

◆ DIRLOGLIST

typedef std::vector<DIRLOG> DIRLOGLIST

Definition at line 62 of file lazylogger.cxx.

Function Documentation

◆ build_done_list()

INT build_done_list ( HNDLE  hLch,
const DIRLOGLIST pdirlist,
DIRLOGLIST pdone 
)

Definition at line 719 of file lazylogger.cxx.

730{
731 HNDLE hKey;
732 KEY key;
733 int status = db_get_key(hDB, hLch, &key);
734 assert(status == DB_SUCCESS);
735
736 if (db_find_key(hDB, hLch, "List", &hKey) == DB_SUCCESS) {
737 cm_msg(MERROR, "build_done_list",
738 "lazylogger cannot continue: found old-style done list in ODB \'/Lazy/%s/List\'. Please convert to new done list format using \'lazylogger -C\'",
739 key.name);
741 exit(1);
742 }
743
745
746 return pdone->size();
747}
INT cm_disconnect_experiment(void)
Definition midas.cxx:2846
#define DB_SUCCESS
Definition midas.h:631
#define MERROR
Definition midas.h:559
INT cm_msg(INT message_type, const char *filename, INT line, const char *routine, const char *format,...)
Definition midas.cxx:915
INT db_get_key(HNDLE hDB, HNDLE hKey, KEY *key)
Definition odb.cxx:6019
INT db_find_key(HNDLE hDB, HNDLE hKey, const char *key_name, HNDLE *subhKey)
Definition odb.cxx:4079
void load_done_list(const char *lazyname, const DIRLOGLIST *dirlist, DIRLOGLIST *dlist)
HNDLE hKey
HNDLE hDB
main ODB handle
KEY key
Definition mdump.cxx:34
INT HNDLE
Definition midas.h:132
DWORD status
Definition odbhist.cxx:39
TH1X EXPRT * h1_book(const char *name, const char *title, int bins, double min, double max)
Definition rmidas.h:24
Definition midas.h:1026
char name[NAME_LENGTH]
Definition midas.h:1029
Here is the call graph for this function:
Here is the caller graph for this function:

◆ build_done_list_odb()

INT build_done_list_odb ( HNDLE  hLch,
INT **  pdo 
)

Definition at line 488 of file lazylogger.cxx.

499{
501 KEY key;
502 INT i, j, size, tot_nelement, nelement, temp;
503
504 if (db_find_key(hDB, hLch, "List", &hKey) != DB_SUCCESS) {
505 return 0;
506 }
507
508 tot_nelement = 0;
509 for (i = 0;; i++) {
511 if (!hSubkey)
512 break;
515 *pdo = (INT *) realloc(*pdo, sizeof(INT) * (tot_nelement + nelement));
516 size = nelement * sizeof(INT);
517 db_get_data(hDB, hSubkey, (char *) (*pdo + tot_nelement), &size, TID_INT);
519 }
520
521 if (0) {
522 printf("read pdo: %d\n", tot_nelement);
523 for (i = 0; i < tot_nelement; i++)
524 printf("%d: %d\n", i, (*pdo)[i]);
525 }
526
527 /* expand compressed run numbers */
528 for (i = 0; i < tot_nelement; i++)
529 if ((*pdo)[i] < 0) {
530 int first = (*pdo)[i - 1];
531 int last = -(*pdo)[i];
532 int nruns = last - first + 1;
533 assert(nruns > 1);
534
535 *pdo = (INT *) realloc(*pdo, sizeof(INT) * (tot_nelement + nruns - 2));
536 assert(*pdo != NULL);
537
538 memmove((*pdo) + i + nruns - 1, (*pdo) + i + 1, sizeof(INT) * (tot_nelement - i - 1));
539
540 for (j = 1; j < nruns; j++)
541 (*pdo)[i + j - 1] = first + j;
542
543 tot_nelement += nruns - 2;
544 }
545
546 if (0) {
547 printf("uncompressed pdo: %d\n", tot_nelement);
548 for (i = 0; i < tot_nelement; i++)
549 printf("%d: %d\n", i, (*pdo)[i]);
550 }
551
552 /* sort array of integers */
553 for (j = 0; j < tot_nelement - 1; j++) {
554 for (i = j + 1; i < tot_nelement; i++) {
555 if (*(*pdo + j) > *(*pdo + i)) {
556 memcpy(&temp, (*pdo + i), sizeof(INT));
557 memcpy((*pdo + i), (*pdo + j), sizeof(INT));
558 memcpy((*pdo + j), &temp, sizeof(INT));
559 }
560 }
561 }
562
563 if (0) {
564 printf("sorted pdo: %d\n", tot_nelement);
565 for (i = 0; i < tot_nelement; i++)
566 printf(" %d\n", (*pdo)[i]);
567 }
568
569 return tot_nelement;
570}
#define TID_INT
Definition midas.h:338
INT db_get_data(HNDLE hDB, HNDLE hKey, void *data, INT *buf_size, DWORD type)
Definition odb.cxx:6539
INT db_enum_key(HNDLE hDB, HNDLE hKey, INT idx, HNDLE *subkey_handle)
Definition odb.cxx:5586
INT i
Definition mdump.cxx:32
HNDLE hSubkey
Definition mdump.cxx:35
int INT
Definition midas.h:129
INT j
Definition odbhist.cxx:40
INT num_values
Definition midas.h:1028
Here is the call graph for this function:
Here is the caller graph for this function:

◆ build_log_list()

INT build_log_list ( const char fmt,
const char dir,
DIRLOGLIST plog 
)

Definition at line 392 of file lazylogger.cxx.

404{
405 char str[MAX_FILE_PATH];
406 char dir[MAX_FILE_PATH];
407 char *dot;
408 int lModulo = 0, lPosition = 0;
409
410 mstrlcpy(dir, xdir, sizeof(dir));
411
412 while (fmt) {
413 /* substitue %xx by * */
414 mstrlcpy(str, fmt, sizeof(str));
415
416 fmt = strchr(fmt, ',');
417 if (fmt)
418 fmt++;
419
420 char *s = strchr(str, ',');
421 if (s)
422 *s = 0;
423
424 if (strchr(str, '%')) {
425 *strchr(str, '%') = '*';
426 if (strchr(str, '.'))
427 strcpy((strchr(str, '*') + 1), strchr(str, '.'));
428 }
429
430 char *list = NULL;
431
432 /* create dir listing with given criteria */
433 int nfile = ss_file_find(dir, str, &list);
434
435 /* check */
436 /*
437 for (j=0;j<nfile;j++)
438 printf ("list[%i]:%s\n",j, list+j*MAX_STRING_LENGTH);
439 */
440
441 std::vector<std::string> flist;
442 for (int j = 0; j < nfile; j++)
443 flist.push_back(list + j * MAX_STRING_LENGTH);
444
445 free(list);
446
447 /* Check Modulo option */
448 if (lazy.modulo[0]) {
449 /* Modulo enabled, extract modulo and position */
450 dot = strchr(lazy.modulo, '.');
451 if (dot) {
452 *dot = '\0';
454 lPosition = atoi(dot + 1);
455 *dot = '.';
456 }
457 }
458
459 /* fill structure */
460 for (unsigned j = 0 ; j < flist.size(); j++) {
461 INT lrun;
462 /* extract run number */
463 lrun = lazy_run_extract((char *) flist[j].c_str());
464 /* apply the modulo if enabled */
466 /* if modulo enable skip */
467 if (lrun == 0)
468 continue;
469
470 std::string s = dir;
471 s += flist[j];
472
473 DIRLOG d;
474 d.filename = flist[j];
475 d.runno = lrun;
476 d.size = ss_file_size((char *) s.c_str());
477
478 dlist->push_back(d);
479 }
480 }
481
482 sort(dlist->begin(), dlist->end(), cmp_dirlog);
483
484 return dlist->size();
485}
INT lModulo
Global var for testing passed at BOR.
Definition ebuser.cxx:48
#define MAX_STRING_LENGTH
Definition msystem.h:113
double ss_file_size(const char *path)
Definition system.cxx:6972
INT ss_file_find(const char *path, const char *pattern, char **plist)
Definition system.cxx:6713
INT lazy_run_extract(const char *name)
#define MAX_FILE_PATH
bool cmp_dirlog(const DIRLOG &a, const DIRLOG &b)
INT moduloCheck(INT lModulo, INT lPosition, INT lrun)
LAZY_SETTING lazy
char str[256]
Definition odbhist.cxx:33
std::string filename
double d
Definition system.cxx:1311
static te_expr * list(state *s)
Definition tinyexpr.c:567
Here is the call graph for this function:
Here is the caller graph for this function:

◆ cmp_dirlog()

bool cmp_dirlog ( const DIRLOG a,
const DIRLOG b 
)

Definition at line 112 of file lazylogger.cxx.

112 {
113 bool r = cmp_dirlog1(a, b);
114 //printf("compare %s %s yields %d\n", a.filename.c_str(), b.filename.c_str(), r);
115 return r;
116}
bool cmp_dirlog1(const DIRLOG &a, const DIRLOG &b)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ cmp_dirlog1()

bool cmp_dirlog1 ( const DIRLOG a,
const DIRLOG b 
)

Definition at line 64 of file lazylogger.cxx.

64 {
65 if (a.runno < b.runno)
66 return true;
67
68 if (a.runno > b.runno)
69 return false;
70
71 const char *sa = a.filename.c_str();
72 const char *sb = b.filename.c_str();
73
74 while (1) {
75 if (*sa == 0) // sa is shorter
76 return true;
77
78 if (*sb == 0) // sb is shorter
79 return false;
80
81 //printf("cmp char %c %c\n", *sa, *sb);
82
83 if (*sa < *sb)
84 return true;
85
86 if (*sa > *sb)
87 return false;
88
89 // at this point, *sa == *sb
90
91 if (isdigit(*sa)) {
92 int ia = strtoul(sa, (char **) &sa, 10);
93 int ib = strtoul(sb, (char **) &sb, 10);
94
95 //printf("cmp int %d %d\n", ia, ib);
96
97 if (ia < ib)
98 return true;
99
100 if (ia > ib)
101 return false;
102
103 // at this point, ia == ib
104 continue;
105 }
106
107 sa++;
108 sb++;
109 }
110}
INT runno
Here is the call graph for this function:
Here is the caller graph for this function:

◆ condition_test()

BOOL condition_test ( char string)

Definition at line 1051 of file lazylogger.cxx.

1066{
1067 KEY key;
1068 double value;
1069 double lcond_value;
1070 INT size, index, status;
1071 char left[64], right[64];
1072 char *p = NULL, *pp, *ppl, *pc, *lp;
1073
1074 index = 0;
1075 p = string;
1076 if (p) {
1077 while (isspace(*p))
1078 p++;
1079
1080 pc = strpbrk(p, "<=>");
1081 if (pc) {
1082 strncpy(left, p, pc - p);
1083 lp = left + (pc - p - 1);
1084 while (isspace(*lp))
1085 lp--;
1086 *(lp + 1) = '\0';
1087 strncpy(right, pc + 1, (strlen(p) - strlen(left)));
1088 right[strlen(p) - strlen(left) - 1] = '\0';
1089 }
1090
1091 if ((pp = strpbrk(left, "[(")) != NULL) {
1092 if ((ppl = strpbrk(left, "])")) != NULL) {
1093 *pp = '\0';
1094 *ppl = '\0';
1095 index = atoi(pp + 1);
1096 }
1097 *pp = '\0';
1098 }
1099
1100 /* convert value */
1101 value = (double) (atoi(right));
1102
1103 status = db_find_key(hDB, 0, left, &hKey);
1104 if (status != DB_SUCCESS) {
1105 cm_msg(MINFO, "condition_check", "Key %s not found", left);
1106 return FALSE;
1107 }
1109 if ((status == DB_SUCCESS) && (key.type <= TID_DOUBLE)) {
1110 /* get value of the condition */
1111 size = sizeof(lcond_value);
1113 std::string s = db_sprintf(&lcond_value, key.item_size, 0, key.type);
1114 lcond_value = std::stof(s);
1115 }
1116
1117 /* printf("string:%s\n condition: %s %f %c %f \n"
1118 , string, left, lcond_value, *pc, value);
1119 */
1120 /*
1121 if (pv == NULL)
1122 return TRUE;
1123 */
1124 /* perform condition check */
1125 if (((*pc == '>') && ((double) lcond_value > value)) || ((*pc == '=') && ((double) lcond_value == value)) ||
1126 ((*pc == '<') && ((double) lcond_value < value)))
1127 return TRUE;
1128 else
1129 return FALSE;
1130 }
1131 /* catch wrong argument in the condition as TRUE */
1132 return TRUE;
1133}
#define FALSE
Definition cfortran.h:309
#define TID_DOUBLE
Definition midas.h:343
#define MINFO
Definition midas.h:560
INT db_get_data_index(HNDLE hDB, HNDLE hKey, void *data, INT *buf_size, INT idx, DWORD type)
Definition odb.cxx:6893
INT db_sprintf(char *string, const void *data, INT data_size, INT idx, DWORD type)
Definition odb.cxx:10843
INT index
Definition mana.cxx:271
#define TRUE
Definition midas.h:182
static int left(const struct frozen *f)
double value[100]
Definition odbhist.cxx:42
DWORD type
Definition midas.h:1027
INT item_size
Definition midas.h:1032
Here is the call graph for this function:
Here is the caller graph for this function:

◆ convert_done_list()

void convert_done_list ( HNDLE  hLch)

Definition at line 664 of file lazylogger.cxx.

675{
677
679
680 KEY key;
681 int status = db_get_key(hDB, hLch, &key);
682 assert(status == DB_SUCCESS);
683
684 HNDLE hKey;
685 status = db_find_key(hDB, hLch, "List", &hKey);
686
687 if (status != DB_SUCCESS) {
688 cm_msg(MERROR, "convert_done_list", "Cannot find \'/Lazy/%s/List\' db_find_key() status %d", key.name, status);
690 exit(1);
691 }
692
693 INT *pdo = NULL;
694 int n = build_done_list_odb(hLch, &pdo);
695
697
698 for (int i = 0; i < n; i++)
699 for (unsigned j = 0; j < dlist.size(); j++)
700 if (dlist[j].runno == pdo[i])
701 done.push_back(dlist[j]);
702
703 free(pdo);
704
705 save_list(key.name, "donelist", &done);
706
707 status = db_rename_key(hDB, hKey, "List.converted");
708 assert(status == DB_SUCCESS);
709
710 cm_msg(MINFO, "convert_done_list",
711 "Done list converted from old ODB \'/Lazy/%s/List\' format to new file-based format. ODB \'List\' renamed to \'List.converted\'",
712 key.name);
713
715 exit(1);
716}
int done
INT db_rename_key(HNDLE hDB, HNDLE hKey, const char *name)
Definition odb.cxx:6261
INT build_log_list(const char *fmt, const char *dir, DIRLOGLIST *plog)
std::vector< DIRLOG > DIRLOGLIST
INT build_done_list_odb(HNDLE, INT **)
int save_list(const char *lazyname, const char *listname, const DIRLOGLIST *dlist)
DWORD n[4]
Definition mana.cxx:247
char backfmt[MAX_FILE_PATH]
char dir[256]
Here is the call graph for this function:
Here is the caller graph for this function:

◆ find_next_file()

int find_next_file ( const DIRLOGLIST plog,
const DIRLOGLIST pdone 
)

Definition at line 771 of file lazylogger.cxx.

784{
785 for (unsigned j = 0; j < plog->size(); j++) {
786 bool found = false;
787 for (unsigned i = 0; i < pdone->size(); i++) {
788 if ((*plog)[j].filename == (*pdone)[i].filename)
789 found = true;
790 }
791
792 if (!found)
793 if ((*plog)[j].size > 0)
794 return j;
795 }
796
797 return -1;
798}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ lazy_condition_check()

BOOL lazy_condition_check ( void  )

Definition at line 1136 of file lazylogger.cxx.

1147{
1148 /* Get condition */
1149 if (equal_ustring(lazy.condition, "ALWAYS"))
1150 return TRUE;
1151 else if (equal_ustring(lazy.condition, "NEVER"))
1152 return FALSE;
1153 else if (equal_ustring(lazy.condition, "WHILE_ACQ_NOT_RUNNING")) {
1154 if (run_state == STATE_RUNNING)
1155 return FALSE;
1156 else
1157 return TRUE;
1158 } else
1159 return (condition_test(lazy.condition));
1160}
#define STATE_RUNNING
Definition midas.h:307
BOOL equal_ustring(const char *str1, const char *str2)
Definition odb.cxx:3201
INT run_state
BOOL condition_test(char *string)
char condition[128]
Here is the call graph for this function:
Here is the caller graph for this function:

◆ lazy_copy()

INT lazy_copy ( char dev,
char file,
int  max_event_size 
)

Definition at line 1163 of file lazylogger.cxx.

1176{
1177 void *plazy = NULL;
1178 DWORD szlazy;
1181 DWORD watchdog_timeout;
1182 static INT last_error = 0;
1183 //char *pext;
1185 char filename[256];
1186
1187 if (debug)
1188 printf("lazy_copy %s to %s\n", infile, outfile);
1189
1190 /* init copy variables */
1191 lazyst.cur_size = 0.0f;
1192
1193 /* open any logging file (output) */
1194 mstrlcpy(filename, outfile, sizeof(filename)); // ftp modifies filename
1195 if ((status = md_file_wopen(dev_type, data_fmt, filename, &hDev)) != 1) {
1196 if ((ss_time() - last_error) > 60) {
1197 last_error = ss_time();
1198 cm_msg(MTALK, "Lazy_copy", "cannot open %s, error %d", outfile, status);
1199 }
1200 return (FORCE_EXIT);
1201 }
1202
1203 /* New lazy copy if TAPE & append required force a mv to EOD */
1204 if ((dev_type == LOG_TYPE_TAPE) && lazy.tapeAppend) {
1205 /* Position Tape to end of Data */
1206 cm_msg(MINFO, "Lazy", "Positioning Tape to EOD");
1207
1208 cm_get_watchdog_params(&watchdog_flag, &watchdog_timeout);
1209 cm_set_watchdog_params(watchdog_flag, 300000); /* 5 min for tape rewind */
1211 cm_set_watchdog_params(watchdog_flag, watchdog_timeout);
1212 if (status != SS_SUCCESS) {
1213 cm_msg(MINFO, "Lazy", "Error while Positioning Tape to EOD (%d)", status);
1215 return (FORCE_EXIT);
1216 }
1217 }
1218
1219 /* reset error message */
1220 last_error = 0;
1221
1222 /* open input data file */
1224 return (FORCE_EXIT);
1225
1226 /* run shell command if available */
1227 if (equal_ustring(lazy.type, "Tape")) {
1228 /* get the block number. If -1 it probably means that the tape
1229 is not ready. Wait for a while */
1230 blockn = -1;
1231 while (blockn < 0) {
1233 if (blockn >= 0)
1234 break;
1235 cm_msg(MINFO, "Lazy", "Tape is not ready");
1236 cm_yield(3000);
1237 }
1238 if (lazy.commandBefore[0]) {
1239 char cmd[256];
1240 sprintf(cmd, "%s %s %s %d %s %i", lazy.commandBefore, infile, outfile, blockn, lazy.backlabel, lazyst.nfiles);
1241 cm_msg(MINFO, "Lazy", "Exec pre file write script:%s", cmd);
1242 ss_system(cmd);
1243 }
1244 }
1245
1246 /* force a statistics update on the first loop */
1247 cpy_loop_time = -2000;
1248 if (dev_type == LOG_TYPE_TAPE) {
1249 char str[256];
1250 sprintf(str, "Starting lazy job on %s at block %d", lazyst.backfile, blockn);
1251 if (msg_flag)
1252 cm_msg(MTALK, "Lazy", "%s", str);
1253 cm_msg1(MINFO, "lazy_copy", "lazy", "%s", str);
1254 }
1255
1256 /* infinite loop while copying */
1257 while (1) {
1258 if (copy_continue) {
1261 if (status != SS_SUCCESS) {
1262 /* close source file */
1264 /* close output data file */
1266 /* szlazy is the requested block size. Why is it copied to cm_msg?
1267 cm_msg(MERROR,"lazy_copy","Write error %i",szlazy); */
1268 cm_msg(MERROR, "lazy_copy", "Write error ");
1269 if (status == SS_NO_SPACE)
1270 return status;
1271 return (FORCE_EXIT);
1272 }
1275 if ((ss_millitime() - cpy_loop_time) > 2000) {
1276 /* update statistics */
1278
1279 /* check conditions */
1281
1282 /* update check loop */
1284
1285 /* yield quickly */
1286 status = cm_yield(1);
1288 cm_msg(MINFO, "Lazy", "Abort postponed until end of copy of %s %1.0lf[%%]",
1289 infile, (double) lazyst.progress);
1291 }
1292 }
1293 } /* get physrec */
1294 else
1295 break;
1296 } /* copy_continue */
1297 else { /* !copy_continue */
1298 status = cm_yield(1000);
1299 if (status == RPC_SHUTDOWN || status == SS_ABORT)
1300 return (FORCE_EXIT);
1301 if ((ss_millitime() - no_cpy_last_time) > 5000) {
1304 }
1305 } /* !copy_continue */
1306 } /* while forever */
1307
1308 /* update for last the statistics */
1310
1311 /* close input log device */
1313
1314 /* close output data file */
1315 if (equal_ustring(lazy.type, "Tape")) {
1317 }
1319 if (status != SS_SUCCESS) {
1320 if (status == SS_NO_SPACE)
1321 return status;
1322 return (FORCE_EXIT);
1323 }
1324
1325 /* request exit */
1326 if (exit_request)
1327 return (EXIT_REQUEST);
1328 return 0;
1329}
INT cm_yield(INT millisec)
Definition midas.cxx:5642
INT cm_get_watchdog_params(BOOL *call_watchdog, DWORD *timeout)
Definition midas.cxx:3317
INT cm_set_watchdog_params(BOOL call_watchdog, DWORD timeout)
Definition midas.cxx:3283
#define SS_SUCCESS
Definition midas.h:663
#define SS_ABORT
Definition midas.h:677
#define SS_NO_SPACE
Definition midas.h:687
#define RPC_SHUTDOWN
Definition midas.h:707
unsigned int DWORD
Definition mcstd.h:51
#define MTALK
Definition midas.h:564
#define MD_SUCCESS
Definition mdsupport.h:60
INT md_file_wclose(INT handle, INT type, INT data_fmt, char *destination)
INT md_file_ropen(char *infile, INT data_fmt, INT openzip, INT max_event_size)
INT md_physrec_get(INT data_fmt, void **precord, DWORD *readn)
INT md_file_wopen(INT type, INT data_fmt, char *filename, INT *hDev)
INT md_log_write(INT handle, INT data_fmt, INT type, void *prec, DWORD nbytes)
INT md_file_rclose(INT data_fmt)
#define LOG_TYPE_TAPE
Definition msystem.h:494
DWORD ss_millitime()
Definition system.cxx:3393
INT ss_tape_close(INT channel)
Definition system.cxx:5902
INT ss_tape_get_blockn(INT channel)
Definition system.cxx:6568
INT ss_tape_spool(INT channel)
Definition system.cxx:6400
DWORD ss_time()
Definition system.cxx:3462
INT ss_system(const char *command)
Definition system.cxx:2116
INT cm_msg1(INT message_type, const char *filename, INT line, const char *facility, const char *routine, const char *format,...)
Definition midas.cxx:973
BOOL lazy_condition_check(void)
INT blockn
LAZY_STATISTICS lazyst
#define EXIT_REQUEST
void lazy_statistics_update(INT cploop_time)
BOOL debug
debug printouts
#define FORCE_EXIT
INT data_fmt
BOOL msg_flag
BOOL copy_continue
#define DONTOPENZIP
INT hDev
INT dev_type
INT max_event_size
Definition mfed.cxx:30
DWORD BOOL
Definition midas.h:105
char commandBefore[64]
char backlabel[MAX_FILE_PATH]
char backfile[MAX_FILE_PATH]
Here is the call graph for this function:
Here is the caller graph for this function:

◆ lazy_disk_copy()

INT lazy_disk_copy ( const char outfile,
const char infile 
)

Definition at line 1615 of file lazylogger.cxx.

1628{
1629 int status;
1630 DWORD watchdog_timeout;
1632
1633 if (debug)
1634 printf("lazy_disk_copy %s to %s\n", infile, outfile);
1635
1636 double MiB = 1024 * 1024;
1637 double disk_size = ss_disk_size((char *) outfile);
1638 double disk_free = ss_disk_free((char *) outfile);
1639
1640 if (debug)
1641 printf("output disk size %.1f MiB, free %.1f MiB\n", disk_size / MiB, disk_free / MiB);
1642
1643 /* init copy variables */
1644 lazyst.cur_size = 0.0f;
1645
1646 /* run shell command if available */
1647 if (lazy.commandBefore[0]) {
1648 char cmd[256];
1649 sprintf(cmd, "%s %s %i", lazy.commandBefore, infile, lazyst.nfiles);
1650 cm_msg(MINFO, "Lazy", "Exec pre file write script:%s", cmd);
1651 ss_system(cmd);
1652 }
1653
1654 FILE *fpin = fopen(infile, "rb");
1655 if (!fpin) {
1656 cm_msg(MERROR, "Lazy_disk_copy", "Cannot read from \'%s\', errno %d (%s)", infile, errno, strerror(errno));
1657 return FORCE_EXIT;
1658 }
1659
1660 FILE *fptest = fopen(outfile, "rb");
1661 if (fptest) {
1662 fclose(fptest);
1663 fptest = NULL;
1664 cm_msg(MINFO, "Lazy_disk_copy", "Output file \'%s\' already exists, removing", outfile);
1665 unlink(outfile);
1666 //return FORCE_EXIT;
1667 }
1668
1669 FILE *fpout = fopen(outfile, "wb");
1670 if (!fpout) {
1671 cm_msg(MERROR, "Lazy_disk_copy", "Cannot write to \'%s\', errno %d (%s)", outfile, errno, strerror(errno));
1672 fclose(fpin);
1673 return TRY_LATER;
1674 }
1675
1676 setbuf(fpin, NULL);
1677 setbuf(fpout, NULL);
1678
1679 {
1680 char str[MAX_FILE_PATH];
1681 sprintf(str, "Starting lazy_disk_copy \'%s\' to \'%s\'", infile, outfile);
1682 if (msg_flag)
1683 cm_msg(MTALK, "Lazy", "%s", str);
1684 cm_msg1(MINFO, "lazy_disk_copy", "lazy", "%s", str);
1685 }
1686
1687 double cpy_start_time = ss_millitime();
1688
1689 cm_get_watchdog_params(&watchdog_flag, &watchdog_timeout);
1690 cm_set_watchdog_params(watchdog_flag, 10 * 60 * 1000); /* increase timeout in case of delays writing output file */
1691
1693
1694 cm_set_watchdog_params(watchdog_flag, watchdog_timeout);
1695
1696 /* update for last the statistics */
1698
1699 /* close input log device */
1700 fclose(fpin);
1701 fpin = NULL;
1702
1703 status = fclose(fpout);
1704 if (status != 0) {
1705 cm_msg(MERROR, "Lazy_disk_copy", "Cannot close \'%s\', errno %d (%s)", outfile, errno, strerror(errno));
1706 //if (status == SS_NO_SPACE)
1707 // return status;
1708 return TRY_LATER;
1709 }
1710
1711 if (copy_status) {
1712 return copy_status;
1713 }
1714
1715 chmod(outfile, 0444);
1716
1717 double t = (ss_millitime() - cpy_start_time) / 1000.0;
1718 //double MiB = 1024*1024;
1719 cm_msg(MINFO, "lazy_disk_copy", "Copy finished in %.1f sec, %.1f MiBytes at %.1f MiBytes/sec", t,
1721
1722 return 0;
1723}
double ss_disk_size(const char *path)
Definition system.cxx:7048
double ss_disk_free(const char *path)
Definition system.cxx:6620
const double MiB
int lazy_disk_copy_loop(const char *outfile, const char *infile, FILE *fpout, FILE *fpin)
#define TRY_LATER
Here is the call graph for this function:
Here is the caller graph for this function:

◆ lazy_disk_copy_loop()

int lazy_disk_copy_loop ( const char outfile,
const char infile,
FILE fpout,
FILE fpin 
)

Definition at line 1333 of file lazylogger.cxx.

1333 {
1334 int status;
1335 int no_cpy_last_time = 0;
1336
1337 /* force a statistics update on the first loop */
1338 int cpy_loop_time = -2000;
1339
1340 /* infinite loop while copying */
1341 while (1) {
1342 if (copy_continue) {
1343 const int kBufSize = 1 * 1024 * 1024;
1344 char buf[kBufSize];
1345 int rd = fread(buf, 1, kBufSize, fpin);
1346 if (rd > 0) {
1347 int wr = fwrite(buf, 1, rd, fpout);
1348 if (wr != rd) {
1349 cm_msg(MERROR, "Lazy_disk_copy", "Cannot write to \'%s\', errno %d (%s)", outfile, errno,
1350 strerror(errno));
1351 //if (status == SS_NO_SPACE)
1352 // return status;
1353 return TRY_LATER;
1354 }
1355
1356 lazyst.cur_size += (double) wr;
1358 if ((ss_millitime() - cpy_loop_time) > 2000) {
1359 /* update statistics */
1361
1362 /* check conditions */
1364
1365 /* update check loop */
1367
1368 /* yield quickly */
1369 status = cm_yield(1);
1370 if (status == RPC_SHUTDOWN || status == SS_ABORT) {
1371 cm_msg(MINFO, "Lazy", "Copy aborted by cm_yield() status %d", status);
1372 return FORCE_EXIT;
1373 }
1374 }
1375 } else if (rd == 0) {
1376 // end of input file
1377 break;
1378 } else {
1379 // read error
1380 cm_msg(MERROR, "Lazy_disk_copy", "Cannot read from \'%s\', errno %d (%s)", infile, errno, strerror(errno));
1381 return FORCE_EXIT;
1382 }
1383 } /* copy_continue */
1384 else { /* !copy_continue */
1385 status = cm_yield(1000);
1386 if (status == RPC_SHUTDOWN || status == SS_ABORT) {
1387 return FORCE_EXIT;
1388 }
1389 if ((ss_millitime() - no_cpy_last_time) > 5000) {
1392 }
1393 } /* !copy_continue */
1394 } /* while forever */
1395
1396 return 0;
1397}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ lazy_file_exists()

BOOL lazy_file_exists ( char dir,
char file 
)

Definition at line 1850 of file lazylogger.cxx.

1862{
1863 char *list;
1864 char fullfile[MAX_FILE_PATH] = {'\0'};
1865
1866 if (ss_file_find(dir, file, &list) == 1) {
1867 strcat(fullfile, dir);
1870 if ((lazyst.file_size = (double) (ss_file_size(fullfile))) > 0) {
1871 free(list);
1872 return TRUE;
1873 }
1874 }
1875 free(list);
1876 return FALSE;
1877}
#define DIR_SEPARATOR_STR
Definition midas.h:194
Here is the call graph for this function:
Here is the caller graph for this function:

◆ lazy_file_remove()

INT lazy_file_remove ( const char pufile)

Definition at line 294 of file lazylogger.cxx.

294 {
296
297 if (nodelete) {
298 printf("lazy_file_remove: running in nodelete mode (-n switch), will not remove \'%s\'\n", pufile);
299 return !SS_SUCCESS;
300 }
301
302 /* open device */
303 fHandle = open(pufile, O_RDONLY, 0644);
304 if (fHandle == -1)
305 return SS_INVALID_NAME;
306
307 close(fHandle);
308
309 status = ss_file_remove((char *) pufile);
310 if (status != 0)
311 return SS_FILE_ERROR;
312 return SS_SUCCESS;
313}
#define SS_FILE_ERROR
Definition midas.h:669
#define SS_INVALID_NAME
Definition midas.h:666
INT ss_file_remove(const char *path)
Definition system.cxx:6952
BOOL nodelete
Here is the call graph for this function:
Here is the caller graph for this function:

◆ lazy_load_params()

INT lazy_load_params ( HNDLE  hDB,
HNDLE  hKey 
)

◆ lazy_log_update()

INT lazy_log_update ( INT  action,
INT  run,
const char label,
const char file,
DWORD  perf_time 
)

Definition at line 316 of file lazylogger.cxx.

316 {
317 char str[1024];
318
319 strcpy(str, "no action");
320
321 /* log Lazy logger to midas.log only */
322 if (action == NEW_FILE) {
323 /* keep track of number of file on that channel */
324 lazyst.nfiles++;
325
326 if (equal_ustring(lazy.type, "FTP"))
327 sprintf(str, "%s[%i]: (cp:%.1fs) %s %1.3lfMB file COPIED",
328 label, lazyst.nfiles, (double) perf_time / 1000., lazyst.backfile, lazyst.file_size / 1024.0 / 1024.0);
329 else if (equal_ustring(lazy.type, "SFTP"))
330 sprintf(str, "%s[%i]: (cp:%.1fs) %s %1.3lfMB file COPIED",
331 label, lazyst.nfiles, (double) perf_time / 1000., lazyst.backfile, lazyst.file_size / 1024.0 / 1024.0);
332 else if (equal_ustring(lazy.type, "Script")) {
333 sprintf(str, "%s[%i]: (cp:%.1fs) %s %1.3lfMB file NEW",
334 label, lazyst.nfiles, (double) perf_time / 1000., lazyst.backfile, lazyst.file_size / 1024.0 / 1024.0);
335 } else if (equal_ustring(lazy.type, "Disk")) {
336 if (lazy.path[0] != 0)
337 if (lazy.path[strlen(lazy.path) - 1] != DIR_SEPARATOR)
339 sprintf(str, "%s[%i]: (cp:%.1fs) %s%s %1.3lfMB file NEW",
340 label, lazyst.nfiles, (double) perf_time / 1000.,
341 lazy.path, lazyst.backfile, lazyst.file_size / 1024.0 / 1024.0);
342 } else if (equal_ustring(lazy.type, "Tape")) {
343 /* June 2002, use variable blockn from the real tape position */
344 sprintf(str, "%s[%i]: (cp:%.1fs) %s/%s %1.3lfMB file NEW (position at block %d)",
345 label, lazyst.nfiles, (double) perf_time / 1000.,
346 lazy.path, lazyst.backfile, lazyst.file_size / 1024.0 / 1024.0, blockn);
347 if (lazy.commandAfter[0]) {
348 char cmd[1024];
349 sprintf(cmd, "%s %s %i %s/%s %1.3lf %d", lazy.commandAfter,
351 lazyst.file_size / 1024.0 / 1024.0, blockn);
352 cm_msg(MINFO, "Lazy", "Exec post file write script:%s", cmd);
353 ss_system(cmd);
354 }
355 }
356 } else if (action == REMOVE_FILE)
357 sprintf(str, "%i (rm:%dms) %s file REMOVED", run, perf_time, file);
358
359 else if (action == REMOVE_ENTRY)
360 sprintf(str, "%s run#%i entry REMOVED", label, run);
361
362 /* Now add this info to a special log file */
363 cm_msg1(MINFO, "lazy", "lazy_log_update", "%s", str);
364
365 return 0;
366}
#define REMOVE_FILE
#define REMOVE_ENTRY
#define NEW_FILE
#define DIR_SEPARATOR
Definition midas.h:193
DWORD run
Definition odbhist.cxx:39
char commandAfter[64]
char path[MAX_FILE_PATH]
Here is the call graph for this function:
Here is the caller graph for this function:

◆ lazy_main()

INT lazy_main ( INT  channel,
LAZY_INFO pLall,
int  max_event_size 
)

Definition at line 1975 of file lazylogger.cxx.

1985{
1986 DWORD cp_time;
1987 INT size, status;
1990 DWORD watchdog_timeout;
1991 LAZY_INFO *pLch;
1992 static BOOL eot_reached = FALSE;
1993 BOOL haveTape;
1994
1995 /* current channel */
1996 pLch = &pLall[channel];
1997
1998 if (convert_flag) {
1999 convert_done_list(pLch->hKey);
2000 assert(!"NOT REACHED");
2001 }
2002
2003 /* extract Data format from the struct */
2004 if (equal_ustring(lazy.format, "MIDAS"))
2006 else {
2007 cm_msg(MERROR, "Lazy", "Unknown data format %s (MIDAS)", lazy.format);
2008 return DB_NO_ACCESS;
2009 }
2010
2011 /* extract Device type from the struct */
2012 if (equal_ustring(lazy.type, "DISK"))
2014 else if (equal_ustring(lazy.type, "TAPE"))
2016 else if (equal_ustring(lazy.type, "FTP"))
2018 else if (equal_ustring(lazy.type, "SFTP"))
2020 else if (equal_ustring(lazy.type, "SCRIPT"))
2022 else {
2023 cm_msg(MERROR, "Lazy", "Unknown device type %s (Disk, Tape, SFTP, FTP or SCRIPT)", lazy.type);
2024 return DB_NO_ACCESS;
2025 }
2026
2028 if (lazy.backlabel[0] == 0 || strcmp(lazy.backlabel, lazyinfo[channel].name) != 0) {
2030 size = sizeof(lazy.backlabel);
2031 db_set_value(hDB, pLch->hKey, "Settings/List label", lazy.backlabel, size, 1, TID_STRING);
2032 }
2033 /* make sure that we don't operate on the current DAQ file if so set to oldest */
2034 //if (lazy.staybehind == 0) {
2035 // cm_msg(MERROR, "Lazy", "Stay behind cannot be 0");
2036 // return NOTHING_TODO;
2037 //}
2038
2039 /* Check if Tape is OK */
2040 /* ... */
2041
2042 haveTape = (lazy.backlabel[0] != '\0');
2043
2044 /* check if space on device (not empty tape label) */
2045 if (lazy.backlabel[0] == '\0') {
2047 } else {
2048 if (full_bck_flag) {
2050 size = sizeof(lazyst);
2051 memset(&lazyst, 0, size);
2052 if (db_find_key(hDB, pLch->hKey, "Statistics", &hKeyst) == DB_SUCCESS) {
2053 status = db_set_record(hDB, hKeyst, &lazyst, size, 0);
2054 /* New session of lazy, apply append in case of Tape */
2055 /* DISK for debugging */
2056 if ((dev_type == LOG_TYPE_DISK) && lazy.tapeAppend) {
2057 /* Position Tape to end of Data */
2058 cm_msg(MINFO, "Lazy", "Positioning Tape to EOD");
2059 }
2060 } else
2061 cm_msg(MERROR, "lazy_main", "did not find /Lazy/Lazy_%s/Statistics for zapping", pLch->name);
2062 // INT al_reset_alarm(char *alarm_name)
2063 if (dev_type == LOG_TYPE_TAPE)
2064 al_reset_alarm("Tape");
2065 }
2066 }
2067 /* check if data dir is none empty */
2068 if (lazy.dir[0] == '\0') {
2069 cm_msg(MINFO, "Lazy", "Please setup Data dir for input source path!");
2070 return NOTHING_TODO;
2071 }
2072
2073 if (lazy.dir[0] != 0)
2074 if (lazy.dir[strlen(lazy.dir) - 1] != DIR_SEPARATOR)
2076
2077 /* check if device path is set */
2078 if (lazy.path[0] == '\0') {
2079 cm_msg(MINFO, "Lazy", "Please setup backup device path too!");
2080 return NOTHING_TODO;
2081 }
2082
2085
2086 save_list(pLch->name, "dirlist", &dirlist);
2087
2090
2092
2093 /* compare list : run NOT in donelist AND run in dirlog */
2095
2096 //const DIRLOG* tobe_backup = cmp_log2donelist(&dirlist, &donelist);
2097
2098 //if (debug)
2099 //print_dirlog(&dirlist);
2100
2101 //print_dirlog(&donelist);
2102 //printf("tobe_backup: %p\n", tobe_backup);
2103
2104 if (tobe_backup < 0)
2105 return NOTHING_TODO;
2106
2107 if (debug)
2108 printf("selected for backup: %s, run %d\n", dirlist[tobe_backup].filename.c_str(), dirlist[tobe_backup].runno);
2109
2110 /* Get current run number */
2111 int cur_acq_run;
2112 size = sizeof(cur_acq_run);
2113 status = db_get_value(hDB, 0, "Runinfo/Run number", &cur_acq_run, &size, TID_INT, FALSE);
2114 assert(status == SUCCESS);
2115
2117
2118 int behind_files = dirlist.size() - tobe_backup;
2120
2123
2124 bool nothing_todo = false;
2125
2126 /* "stay behind by so many runs" mode */
2127 if (lazy.staybehind < 0)
2129
2130 /* "stay behind by so many files" mode */
2131 if (lazy.staybehind > 0)
2133
2134 /* "no stay behind" mode */
2135 if (lazy.staybehind == 0) {
2136 if (dirlist[tobe_backup].runno != cur_acq_run)
2137 nothing_todo = false;
2138 else if (behind_files > 1)
2139 nothing_todo = false;
2140 else {
2141 nothing_todo = false;
2142
2143 /* In case it is the current run make sure
2144 1) no transition is in progress
2145 2) the run start has not been aborted
2146 3) the run has been ended
2147 */
2148
2149 int flag;
2150 size = sizeof(flag);
2151 status = db_get_value(hDB, 0, "Runinfo/Transition in progress", &flag, &size, TID_INT, FALSE);
2152 assert(status == SUCCESS);
2153 if (flag) {
2154 if (debug)
2155 printf("transition in progress, cannot backup last file\n");
2156 nothing_todo = true;
2157 }
2158
2159 size = sizeof(flag);
2160 status = db_get_value(hDB, 0, "Runinfo/Start abort", &flag, &size, TID_INT, FALSE);
2161 assert(status == SUCCESS);
2162 if (flag) {
2163 if (debug)
2164 printf("run start aborted, cannot backup last file\n");
2165 nothing_todo = true;
2166 }
2167
2168 int cur_state_run;
2169 status = db_get_value(hDB, 0, "Runinfo/State", &cur_state_run, &size, TID_INT, FALSE);
2170 assert(status == SUCCESS);
2171 if ((cur_state_run != STATE_STOPPED)) {
2172 if (debug)
2173 printf("run still running, cannot backup last file\n");
2174 nothing_todo = true;
2175 }
2176 }
2177 }
2178
2179 if (debug)
2180 printf("behind: %d files, %d runs, staybehind: %d, nothing_todo: files: %d, runs: %d, lazylogger: %d\n",
2182
2183 if (nothing_todo) {
2184 return NOTHING_TODO;
2185 }
2186
2188 if (!haveTape) {
2189 if (debug)
2190 printf("haveTape: %d, nothing to do.\n", haveTape);
2191 return NOTHING_TODO;
2192 }
2193
2194 mstrlcpy(lazyst.backfile, dirlist[tobe_backup].filename.c_str(), sizeof(lazyst.backfile));
2195
2196 std::string xfile = lazy.dir;
2197 xfile += dirlist[tobe_backup].filename;
2198 mstrlcpy(inffile, xfile.c_str(), sizeof(inffile));
2199
2200 /* Check again if the backup file is present in the logger dir */
2202 /* compose the destination file name */
2203 if ((dev_type == LOG_TYPE_DISK) || (dev_type == LOG_TYPE_SFTP)) {
2204 if (lazy.path[0] != 0)
2205 if (lazy.path[strlen(lazy.path) - 1] != DIR_SEPARATOR)
2207 strcpy(outffile, lazy.path);
2209 } else if (dev_type == LOG_TYPE_TAPE)
2210 strcpy(outffile, lazy.path);
2211 else if (dev_type == LOG_TYPE_FTP) {
2212 /* Format for FTP
2213 lazy.path=host,port,user,password,directory,filename[,umask]
2214 expect filename in format such as "bck%08d.mid" */
2215
2216 /*
2217 if (lazy.path[0] != 0)
2218 if (lazy.path[strlen(lazy.path)-1] != DIR_SEPARATOR)
2219 strcat(lazy.path, DIR_SEPARATOR_STR);
2220 */
2221
2222 strcpy(str, lazy.path);
2223 /* substitute "%d" for current run number */
2224 if (strchr(str, '%'))
2226 else
2227 strcpy(outffile, str);
2228
2229 /* substitute "#d" for current run number millenium */
2230 mstrlcpy(str, outffile, sizeof(str));
2231 if (strchr(str, '#')) {
2232 *strchr(str, '#') = '%';
2233 sprintf(outffile, str, lazyst.cur_run / 1000);
2234 }
2235 }
2236
2237 /* check if space on backup device ONLY in the TAPE case */
2239 char pre_label[32];
2240 /* save the last label for shell script */
2241 strcpy(pre_label, lazy.backlabel);
2242
2243 /* Reset EOT reached */
2245
2246 /* not enough space => reset list label */
2247 lazy.backlabel[0] = '\0';
2248 size = sizeof(lazy.backlabel);
2249 db_set_value(hDB, pLch->hKey, "Settings/List label", lazy.backlabel, size, 1, TID_STRING);
2251 cm_msg(MINFO, "Lazy", "Not enough space for next copy on backup device!");
2252
2253 /* rewind device if TAPE type */
2254 if (dev_type == LOG_TYPE_TAPE) {
2256 char str[256];
2257 sprintf(str, "Tape %s is full with %d files", pre_label, lazyst.nfiles);
2258 cm_msg(MINFO, "Lazy", "%s", str);
2259
2260 /* Setup alarm */
2261 lazy.alarm[0] = 0;
2262 size = sizeof(lazy.alarm);
2263 db_get_value(hDB, pLch->hKey, "Settings/Alarm Class", lazy.alarm, &size, TID_STRING, TRUE);
2264
2265 /* trigger alarm if defined */
2266 if (lazy.alarm[0])
2267 al_trigger_alarm("Tape",
2268 "Tape full, Please remove current tape and load new one!",
2269 lazy.alarm, "Tape full", AT_INTERNAL);
2270
2271 /* run shell command if available */
2272 if (lazy.command[0]) {
2273 std::string cmd;
2274 cmd += lazy.command;
2275 cmd += " ";
2276 cmd += lazy.path;
2277 cmd += " ";
2278 cmd += pLch->name;
2279 cmd += " ";
2280 cmd += pre_label;
2281 cm_msg(MINFO, "Lazy", "Exec post-rewind script:%s", cmd.c_str());
2282 ss_system(cmd.c_str());
2283 }
2284
2285 cm_msg(MINFO, "Lazy", "backup device rewinding...");
2286 cm_get_watchdog_params(&watchdog_flag, &watchdog_timeout);
2287 cm_set_watchdog_params(watchdog_flag, 300000); /* 5 min for tape rewind */
2289 if (channel < 0) {
2290 cm_msg(MERROR, "Lazy", "Cannot rewind tape %s - %d - %d", outffile, channel, status);
2291 return NOTHING_TODO;
2292 }
2293 //else
2294 // cm_msg(MINFO,"Lazy", "After call ss_tape_open used to rewind tape %s - %d - %d", outffile, channel, status);
2295 cm_msg(MINFO, "Lazy", "Calling ss_tape_unmount");
2298 cm_set_watchdog_params(watchdog_flag, watchdog_timeout);
2299 return NOTHING_TODO;
2300 } // 1
2301 } // LOG_TYPE_TAPE
2302
2303 // Postpone copy by "copy_delay" if the copy check happens right after the
2304 // stop transition. This permit EOR external scripts to complete there operations
2305 // prior to the lazycopy.
2306 // Delay the copy in case:
2307 // 0) all previous condition for copy is satisfied
2308 // 1) Stopped transition has been detected,
2309
2310 if (stop_transition) {
2311 printf("in loop stop detected\n");
2312 stop_transition = FALSE; // reset transition (trfunction())
2313 delay_start = TRUE; // take notice of transition
2314 lazy_time = ss_time(); // mark time for delay
2315 }
2316 // check if its time after a stop transition
2317 if (delay_start && (ss_time() - lazy_time) < (DWORD) lazy.copy_delay) {
2318 printf("During delay %d... (%d)\n", ss_time() - lazy_time, lazy.copy_delay);
2319 return NOTHING_TODO;
2320 } else {
2322 }
2323
2324 /* Finally do the copy */
2326 status = 0;
2327 if (dev_type == LOG_TYPE_SCRIPT) {
2328#ifdef OS_LINUX
2329 //sprintf(lazy.backlabel, "%06d", 100 * (lazyst.cur_run / 100));
2331#else
2332 assert(!"lazy_script_copy not supported under Windows");
2333#endif
2334 } else if (dev_type == LOG_TYPE_SFTP) {
2335#ifdef HAVE_CURL
2336 // copy CURL SFTP
2338#else
2339 assert(!"SFTP copying requires CURL to be installed! Install CURL, re-run cmake, and re-compile!");
2340#endif
2341 } else if (dev_type == LOG_TYPE_DISK) {
2342 // copy block mode
2344 } else {
2345 // copy event mode (old method)
2347 }
2348
2349 if ((status != 0) && (status != EXIT_REQUEST)) {
2350 if (status == SS_NO_SPACE) {
2351 /* Consider this case as EOT reached */
2352 eot_reached = TRUE;
2353 return status;
2354 } else if (status == FORCE_EXIT)
2355 return status;
2356 cm_msg(MERROR, "Lazy", "copy failed -%s-%s-%i", lazy.path, lazyst.backfile, status);
2357 if (status == TRY_LATER)
2358 return status;
2359 return FORCE_EXIT;
2360 }
2362
2363 // copy done, update listings, logs, ODB
2364 donelist.push_back(dirlist[tobe_backup]);
2365 save_done_list(pLch->hKey, &donelist);
2368 } /* file exists */
2369 else {
2370 // If file not present it may be due to a run abort.
2371 // As the file is based on the "tobe_backup" run number
2372 // which is evaluated every lazy check, if a run is missing
2373 // it will be skiped properly.
2374 // No message is needed in this case.
2375 // cm_msg(MERROR, "Lazy", "lazy_file_exists file %s doesn't exists", lazyst.backfile);
2376 return NOTHING_TODO;
2377 }
2378
2379 if (status == EXIT_REQUEST)
2381
2382 //-PAA code moved at the end of "file exists condition" (above)
2383 // cp_time = ss_millitime() - cp_time;
2384 // donelist.push_back(dirlist[tobe_backup]);
2385 // save_done_list(pLch->hKey, &donelist);
2386 // lazy_log_update(NEW_FILE, lazyst.cur_run, lazy.backlabel, lazyst.backfile, cp_time);
2387
2388 if (msg_flag)
2389 cm_msg(MTALK, "Lazy", " lazy job %s done!", lazyst.backfile);
2390
2391 /* generate/update a <channel>_recover.odb file when everything is Ok
2392 after each file copy */
2393 {
2394 std::string str;
2395 /* leave "list label" as it is, as long as the _recover.odb is loaded before
2396 the lazylogger is started with NO -z things should be fine */
2397 /* save the recover with "List Label" empty */
2398 if (lazy.dir[strlen(lazy.dir) - 1] != DIR_SEPARATOR) {
2399 str += lazy.dir;
2400 str += DIR_SEPARATOR;
2401 str += pLch->name;
2402 str += "_recover.odb";
2403 } else {
2404 str += lazy.dir;
2405 str += pLch->name;
2406 str += "_recover.odb";
2407 }
2408
2409 db_save(hDB, pLch->hKey, str.c_str(), TRUE);
2410 }
2411
2412 if (exit_request)
2413 return (FORCE_EXIT);
2414 return NOTHING_TODO;
2415}
INT al_reset_alarm(const char *alarm_name)
Definition alarm.cxx:525
INT al_trigger_alarm(const char *alarm_name, const char *alarm_message, const char *default_class, const char *cond_str, INT type)
Definition alarm.cxx:283
#define DB_NO_ACCESS
Definition midas.h:648
#define SUCCESS
Definition mcstd.h:54
#define STATE_STOPPED
Definition midas.h:305
#define TID_STRING
Definition midas.h:346
#define FORMAT_MIDAS
Definition midas.h:311
#define LOG_TYPE_DISK
Definition msystem.h:493
#define LOG_TYPE_SFTP
Definition msystem.h:496
#define LOG_TYPE_FTP
Definition msystem.h:495
INT ss_tape_unmount(INT channel)
Definition system.cxx:6512
INT ss_tape_open(char *path, INT oflag, INT *channel)
Definition system.cxx:5811
INT db_send_changed_records()
Definition odb.cxx:13777
INT db_get_value(HNDLE hDB, HNDLE hKeyRoot, const char *key_name, void *data, INT *buf_size, DWORD type, BOOL create)
Definition odb.cxx:5415
INT db_save(HNDLE hDB, HNDLE hKey, const char *filename, BOOL bRemote)
Definition odb.cxx:9245
INT db_set_value(HNDLE hDB, HNDLE hKeyRoot, const char *key_name, const void *data, INT data_size, INT num_values, DWORD type)
Definition odb.cxx:5261
INT db_set_record(HNDLE hDB, HNDLE hKey, void *data, INT buf_size, INT align)
Definition odb.cxx:12291
INT lazy_log_update(INT action, INT run, const char *label, const char *file, DWORD perf_time)
INT lazy_copy(char *dev, char *file, int max_event_size)
int find_next_file(const DIRLOGLIST *plog, const DIRLOGLIST *pdone)
INT lazy_maintain_free_space(LAZY_INFO *pLch, LAZY_INFO *pLall)
void convert_done_list(HNDLE hLch)
LAZY_INFO lazyinfo[MAX_LAZY_CHANNEL]
BOOL full_bck_flag
BOOL delay_start
BOOL convert_flag
INT lazy_disk_copy(const char *outfile, const char *infile)
INT channel
DWORD lazy_time
BOOL lazy_file_exists(char *dir, char *file)
BOOL stop_transition
#define NOTHING_TODO
INT save_done_list(HNDLE hLch, DIRLOGLIST *pdone)
#define LOG_TYPE_SCRIPT
INT build_done_list(HNDLE hLch, const DIRLOGLIST *pdirlist, DIRLOGLIST *pdone)
HNDLE hKeyst
#define AT_INTERNAL
Definition midas.h:1442
char name[32]
char command[64]
char alarm[32]
Here is the call graph for this function:
Here is the caller graph for this function:

◆ lazy_maintain_check()

void lazy_maintain_check ( HNDLE  hKey,
LAZY_INFO pLall 
)

Definition at line 940 of file lazylogger.cxx.

951{
952 INT size;
953 INT i, maintain;
954 char dir[256], ff[128];
955 char cdir[256], cff[128];
956 char cmodulostr[8], modulostr[8];
957
958 /* do test only if maintain has been touched */
959 if (!maintain_touched)
960 return;
962
963 /* check is Maintain free is enabled */
964 size = sizeof(maintain);
965 db_get_value(hDB, hKey, "Settings/Maintain free space (%)", &maintain, &size, TID_INT, TRUE);
966 if (maintain != 0) {
967 /* scan other channels */
968
969 /* get current specification */
970 size = sizeof(cdir);
971 db_get_value(hDB, hKey, "Settings/Data dir", cdir, &size, TID_STRING, TRUE);
972 size = sizeof(cff);
973 db_get_value(hDB, hKey, "Settings/filename format", cff, &size, TID_STRING, TRUE);
974 size = sizeof(modulostr);
975 db_get_value(hDB, hKey, "Settings/Modulo.Position", cmodulostr, &size, TID_STRING, TRUE);
976
977 /* build matching dir and ff */
978 for (i = 0; i < MAX_LAZY_CHANNEL; i++) {
979 if (((pLall + i)->hKey) && (hKey != (pLall + i)->hKey)) { /* valid channel */
980 size = sizeof(dir);
981 db_get_value(hDB, (pLall + i)->hKey, "Settings/Data dir", dir, &size, TID_STRING, TRUE);
982 size = sizeof(ff);
983 db_get_value(hDB, (pLall + i)->hKey, "Settings/filename format", ff, &size, TID_STRING, TRUE);
984 size = sizeof(modulostr);
985 db_get_value(hDB, (pLall + i)->hKey, "Settings/Modulo.Position", modulostr, &size, TID_STRING, TRUE);
986
987 if ((strcmp(dir, cdir) == 0) && (strcmp(ff, cff) == 0) && !cmodulostr[0] && !modulostr[0]) {
988 /* check "maintain free space" */
989 size = sizeof(maintain);
990 db_get_value(hDB, (pLall + i)->hKey, "Settings/Maintain free space (%)",
991 &maintain, &size, TID_INT, TRUE);
992 if (maintain) {
993 /* disable and inform */
994 size = sizeof(maintain);
995 maintain = 0;
996 db_set_value(hDB, (pLall + i)->hKey, "Settings/Maintain free space (%)", &maintain, size, 1, TID_INT);
997 cm_msg(MINFO, "lazy_maintain_check",
998 "Maintain free space on channel %s has been disable", (pLall + i)->name);
999 }
1000 }
1001 }
1002 }
1003 }
1004}
#define MAX_LAZY_CHANNEL
BOOL maintain_touched
#define name(x)
Definition midas_macro.h:24
Here is the call graph for this function:
Here is the caller graph for this function:

◆ lazy_maintain_free_space()

INT lazy_maintain_free_space ( LAZY_INFO pLch,
LAZY_INFO pLall 
)

Definition at line 1881 of file lazylogger.cxx.

1881 {
1882 int status;
1883
1884 /* update "maintain free space" */
1886
1887 /* check SPACE and purge if necessary = % (1:99) */
1888 if (lazy.pupercent > 0) {
1889
1890 // Compute initial disk space
1891 double freepercent = 100. * ss_disk_free(lazy.dir) / ss_disk_size(lazy.dir);
1892
1893 // Check for Disk full first
1894 if (freepercent < 5.0) {
1895 std::string str;
1896 str += "Disk ";
1897 str += lazy.dir;
1898 str += "is almost full, free space: ";
1899 char buf[256];
1900 sprintf(buf, "%.1f%%", freepercent);
1901 str += buf;
1902 al_trigger_alarm("Disk Full", str.c_str(), lazy.alarm, "Disk buffer full", AT_INTERNAL);
1903 } else {
1904 HNDLE hKey;
1905 if (db_find_key(hDB, 0, "/Alarms/Alarms/Disk Full", &hKey) == DB_SUCCESS)
1906 al_reset_alarm("Disk Full");
1907 }
1908
1909 if (debug)
1910 printf("free space on %s: %.1f%%, lazy limit %d%%\n", lazy.dir, freepercent, lazy.pupercent);
1911
1912 /* Lock other clients out of this following code as
1913 it may access the other client info tree */
1914
1916 if (status != SS_SUCCESS) {
1917 /* exit for now and come back later */
1918 return NOTHING_TODO;
1919 }
1920
1921 /* check purging action */
1922 while (freepercent <= (double) lazy.pupercent) {
1923 // flag for single purge
1925 /* search file to purge : run in donelist AND run in dirlog */
1926 /* synchronize donelist to dir log in case user has purged
1927 some file by hand. Basically remove the run in the list if the
1928 file is not anymore in the source dir. */
1929 DIRLOG f;
1930 if (lazy_select_purge(pLch->hKey, channel, pLall, lazy.backfmt, lazy.dir, &f) == SUCCESS) {
1931 /* check if beyond keep file + 1 */
1932 if (1 /*purun < (cur_acq_run - abs(lazy.staybehind) - 1)*/) {
1933 DWORD rm_time;
1934 /* remove file */
1936 std::string path = lazy.dir;
1937 path += f.filename;
1938 if (debug)
1939 printf("file selected for removal %s [%s]\n", f.filename.c_str(), path.c_str());
1940 status = lazy_file_remove(path.c_str());
1942 if (status != SS_SUCCESS) {
1943 cm_msg(MERROR, "Lazy", "lazy_file_remove failed on file %s", path.c_str());
1944 // break out if can't delete files
1945 break;
1946 } else {
1947 status = lazy_log_update(REMOVE_FILE, f.runno, NULL, path.c_str(), rm_time);
1948 donepurge = TRUE;
1949 }
1950 } // purun found
1951
1952 // Re-compute free space
1954
1955 if (debug)
1956 printf("free space on %s: %.1f%%, lazy limit %d%%\n", lazy.dir, freepercent, lazy.pupercent);
1957
1958 } // select_purge
1959
1960 // donepurge = FALSE => nothing else to do
1961 // donepurge = TRUE => one purge done loop back once more
1962 if (!donepurge)
1963 break;
1964 } // while
1965
1966 /* Release the semaphore */
1968
1969 } /* end of if pupercent > 0 */
1970
1971 return SUCCESS;
1972}
INT ss_semaphore_release(HNDLE semaphore_handle)
Definition system.cxx:2781
INT ss_semaphore_wait_for(HNDLE semaphore_handle, DWORD timeout_millisec)
Definition system.cxx:2639
void lazy_maintain_check(HNDLE hKey, LAZY_INFO *pLall)
INT lazy_semaphore
INT lazy_file_remove(const char *pufile)
INT lazy_select_purge(HNDLE hKey, INT channel, LAZY_INFO *pLall, const char *fmt, const char *dir, DIRLOG *f)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ lazy_run_extract()

INT lazy_run_extract ( const char name)

Definition at line 255 of file lazylogger.cxx.

267{
268#if 0
269 char run_str[256];
270 int j;
271
272 mstrlcpy(run_str, name, sizeof(run_str));
273 if (strlen(run_str) < 2)
274 return 0;
275
276 for (j = strlen(run_str) - 1; j >= 0 && !isdigit(run_str[j]); j--)
277 run_str[j] = 0;
278
279 for (j = strlen(run_str) - 1; j >= 0 && isdigit(run_str[j]); j--);
280
281 return atoi(run_str + j + 1);
282#endif
283
284 while (*name && !isdigit(*name))
285 name++;
286
287 if (*name == 0)
288 return 0;
289
290 return atoi(name);
291}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ lazy_select_purge()

INT lazy_select_purge ( HNDLE  hKey,
INT  channel,
LAZY_INFO pLall,
const char fmt,
const char dir,
DIRLOG f 
)

Definition at line 801 of file lazylogger.cxx.

823{
824 int size;
825 char ddir[256], ff[128], strmodulo[8];
826
827 /* Scan donelist from first element (oldest)
828 check if run exists in dirlog
829 if yes return file and run number */
830
831 while (1) {
832 /* try to find the oldest matching run present in the list AND on disk */
833 /* build current done list */
834
837
838 /* build matching dir and file format (ff) */
839 for (int i = 0; i < MAX_LAZY_CHANNEL; i++) {
840 /* Check if key present && key different than currrent
841 and if modulo is off */
842 if (((pLall + i)->hKey)) {
843 /* extract dir and ff */
844 size = sizeof(strmodulo);
845 db_get_value(hDB, (pLall + i)->hKey, "Settings/Modulo.Position", strmodulo, &size, TID_STRING, TRUE);
846 if (strmodulo[0]) {
847 /* Modulo enabled, skip this channel */
848 if (debug)
849 printf("purge: skipping channel \'%s\' which uses modulo \'%s\'\n", lazyinfo[i].name, strmodulo);
850 continue;
851 }
852
853 size = sizeof(ddir);
854 db_get_value(hDB, (pLall + i)->hKey, "Settings/Data dir", ddir, &size, TID_STRING, TRUE);
855 size = sizeof(ff);
856 db_get_value(hDB, (pLall + i)->hKey, "Settings/filename format", ff, &size, TID_STRING, TRUE);
857
858 // monkey about with trailing '/' characters
859
860 int len = strlen(ddir);
861 if (ddir[len - 1] != '/') {
862 ddir[len] = '/';
863 ddir[len + 1] = 0;
864 }
865
866 /* if same dir && same ff => mark lazy channel */
867 if (strcmp(ddir, dir) != 0) {
868 if (debug)
869 printf("purge: skipping channel \'%s\' which uses different data dir \'%s\', we use \'%s\'\n",
870 lazyinfo[i].name, ddir, dir);
871 continue;
872 }
873
874 if (debug)
875 printf("Loading file lists for channel \'%s\', data dir \'%s\', format \'%s\'\n", lazyinfo[i].name, ddir,
876 ff);
877
878 /* load file list and done list for matching channels */
881 }
882 } /* end of loop over channels */
883
884 /* search for files to delete */
885 for (unsigned k = 0; k < dirlists[channel].size(); k++) {
886 bool can_delete = true;
887
888 if (debug)
889 printf("purge: consider file \'%s\'\n", dirlists[channel][k].filename.c_str());
890
891 for (int i = 0; i < MAX_LAZY_CHANNEL; i++)
892 if (((pLall + i)->hKey)) {
893 bool in_dir_list = false;
894 bool in_done_list = false;
895
896 for (unsigned j = 0; j < dirlists[i].size(); j++)
897 if (dirlists[i][j].filename == dirlists[channel][k].filename) {
898 in_dir_list = true;
899 break;
900 }
901
902 if (!in_dir_list) {
903 if (debug)
904 printf("channel \'%s\': file is not in dir list, ok to delete\n", lazyinfo[i].name);
905 continue;
906 }
907
908 for (unsigned j = 0; j < donelists[i].size(); j++)
909 if (donelists[i][j].filename == dirlists[channel][k].filename) {
910 in_done_list = true;
911 break;
912 }
913
914 if (!in_done_list) {
915 if (debug)
916 printf("channel \'%s\': file is in dirlist but not in done list, cannot delete\n",
917 lazyinfo[i].name);
918 can_delete = false;
919 break;
920 }
921
922 if (debug)
923 printf("channel \'%s\': file is in dirlist and in done list, ok to delete\n", lazyinfo[i].name);
924 }
925
926 if (can_delete) {
927 if (debug)
928 printf("purge: file \'%s\' is done by all channels\n", dirlists[channel][k].filename.c_str());
929 *f = dirlists[channel][k];
930 return SUCCESS;
931 }
932 }
933
934 /* nothing to remove */
935 return !SUCCESS;
936 }
937}
INT k
Definition odbhist.cxx:40
Here is the call graph for this function:
Here is the caller graph for this function:

◆ lazy_settings_hotlink()

void lazy_settings_hotlink ( HNDLE  hDB,
HNDLE  hKey,
void info 
)

◆ lazy_statistics_update()

void lazy_statistics_update ( INT  cploop_time)

Definition at line 1007 of file lazylogger.cxx.

1017{
1018
1019 if (debug) {
1020 printf("file.size:%f - ", lazyst.file_size);
1021 printf("file.curr:%f - ", lazyst.cur_size);
1022 printf("lastsz:%f - ", lastsz);
1023 printf("nfiles:%i\n", lazyst.nfiles);
1024 }
1025 /* update rate [kb/s] statistics */
1026 if (cploop_time == 0) // special function: set copy_rate to zero at end of copy
1027 lazyst.copy_rate = 0.0;
1028 if ((ss_millitime() - cploop_time) > 100)
1030 if (lazyst.copy_rate < 0.0)
1031 lazyst.copy_rate = 0.0;
1032
1033 /* update % statistics */
1034 if (lazyst.file_size != 0.0f)
1035 lazyst.progress = (100.0f * (lazyst.cur_size / lazyst.file_size));
1036 else
1037 lazyst.progress = 0.0f;
1038
1039 /* update backup % statistics */
1040 if (lazy.capacity > 0.0f)
1042 else
1043 lazyst.bckfill = 0.0f;
1044
1046 /* udate ODB statistics */
1048}
double lastsz
Here is the call graph for this function:
Here is the caller graph for this function:

◆ lazy_trstop()

INT lazy_trstop ( INT  rn,
char error 
)

Definition at line 248 of file lazylogger.cxx.

248 {
249 printf("lazy has detected a STOP transition\n");
251 return CM_SUCCESS;
252}
#define CM_SUCCESS
Definition midas.h:582
Here is the call graph for this function:
Here is the caller graph for this function:

◆ list_filename()

std::string list_filename ( const char lazyname,
const char listname 
)

Definition at line 572 of file lazylogger.cxx.

572 {
573 std::string s(cm_get_path());
574 s += ".Lazy_";
575 s += lazyname;
576 s += ".";
577 s += listname;
578 return s;
579}
std::string cm_get_path()
Definition midas.cxx:1537
Here is the call graph for this function:
Here is the caller graph for this function:

◆ load_done_list()

void load_done_list ( const char lazyname,
const DIRLOGLIST dirlist,
DIRLOGLIST dlist 
)

Definition at line 581 of file lazylogger.cxx.

581 {
582 FILE *fp = fopen(list_filename(lazyname, "donelist").c_str(), "r");
583 if (!fp)
584 return;
585
586 while (1) {
587 char str[256];
588 char *s = fgets(str, sizeof(str), fp);
589 if (!s)
590 break;
591
592 DIRLOG d;
593
594 char *p = strchr(s, ' ');
595
596 if (p) {
597 *p = 0;
598 p++;
599 }
600
601 d.filename = s;
602 d.runno = strtoul(p, &p, 0);
603 d.size = strtod(p, &p);
604
605 bool found = false;
606 if (dirlist) {
607 for (unsigned i = 0; i < dirlist->size(); i++)
608 if ((*dirlist)[i].filename == d.filename) {
609 found = true;
610 break;
611 }
612 } else
613 found = true;
614
615 if (found)
616 dlist->push_back(d);
617 }
618
619 fclose(fp);
620
621 sort(dlist->begin(), dlist->end(), cmp_dirlog);
622}
std::string list_filename(const char *lazyname, const char *listname)
static FILE * fp
Here is the call graph for this function:
Here is the caller graph for this function:

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 2441 of file lazylogger.cxx.

2441 {
2442 char channel_name[32];
2445 BOOL daemon;
2446 INT i, msg, size, status, mainlast_time;
2447 DWORD last_time_kb = 0;
2448 setbuf(stdout, NULL);
2449 setbuf(stderr, NULL);
2450
2451 /* set default */
2452 host_name[0] = 0;
2453 expt_name[0] = 0;
2454 channel_name[0] = 0;
2456 msg_flag = FALSE;
2457 debug = daemon = FALSE;
2458
2459 /* set default */
2461
2462 /* get parameters */
2463 for (i = 1; i < argc; i++) {
2464 if (argv[i][0] == '-' && argv[i][1] == 'd')
2465 debug = TRUE;
2466 else if (argv[i][0] == '-' && argv[i][1] == 'n')
2467 nodelete = TRUE;
2468 else if (argv[i][0] == '-' && argv[i][1] == 'D')
2469 daemon = TRUE;
2470 else if (strncmp(argv[i], "-C", 2) == 0)
2472 else if (strncmp(argv[i], "-z", 2) == 0)
2473 zap_flag = TRUE;
2474 else if (strncmp(argv[i], "-t", 2) == 0)
2475 msg_flag = TRUE;
2476 else if (argv[i][0] == '-') {
2477 if (i + 1 >= argc || argv[i + 1][0] == '-')
2478 goto usage;
2479 if (strncmp(argv[i], "-e", 2) == 0)
2480 strcpy(expt_name, argv[++i]);
2481 else if (strncmp(argv[i], "-h", 2) == 0)
2482 strcpy(host_name, argv[++i]);
2483 else if (strncmp(argv[i], "-c", 2) == 0)
2484 strcpy(channel_name, argv[++i]);
2485 } else {
2486 usage:
2487 printf("Lazylogger: Multi channel background data copier\n");
2488 printf("\n");
2489 printf("Usage: lazylogger [-d] [-n] [-D] [-h <Hostname>] [-e <Experiment>] [-z] [-t] [-C] -c <channel name>\n");
2490 printf("\n");
2491 printf("Options:\n");
2492 printf(" -c <channel name> - specify lazylogger channel name\n");
2493 printf(" -C - convert old-format done list to new file-based format\n");
2494 printf(" -d - enable debug printout\n");
2495 printf(" -n - do not delete any files (for testing \"Maintain free space\")\n");
2496 printf(" -D - start as a daemon\n");
2497 printf(" -h - connect to experiment on another machine\n");
2498 printf(" -e - connect to non-default experiment\n");
2499 printf(" -z - clear /Lazy/channel/Statistics\n");
2500 printf(" -t - permit lazy logger to TALK (see mlxspeaker)\n");
2501 printf("\n");
2502 printf("Quick man :\n");
2503 printf("The Lazy/Settings tree is composed of the following parameters:\n");
2504 printf("Maintain free space (%%)(0): purge source device to maintain free space on the source directory\n");
2505 printf(" (0) : no purge \n");
2506 printf("Stay behind (0) : If negative number : lazylog runs starting from the OLDEST\n");
2507 printf(" run file sitting in the 'Dir data' to the current acquisition\n");
2508 printf(" run minus the 'Stay behind number'\n");
2509 printf(" If positive number : lazylog starts from the current\n");
2510 printf(" acquisition run minus 'Stay behind number' \n");
2511 printf(" Zero : no stay-behind - files are saved as soon as they are closed\n");
2512 printf("Alarm Class : Specify the Class to be used in case of Tape Full condition\n");
2513 printf("Running condition : active/deactive lazylogger under given condition i.e:\n");
2514 printf(" 'ALWAYS' (default) : Independent of the ACQ state ...\n");
2515 printf(" 'NEVER' : ...\n");
2516 printf(" 'WHILE_ACQ_NOT_RUNNING': ...\n");
2517 printf(" '/alias/max_rate < 200' (max_rate is a link)\n");
2518 printf(" '/equipment/scaler/variables/scal[4] < 23.45'\n");
2519 printf(" '/equipment/trigger/statistics/events per sec. < 400'\n");
2520 printf("Data dir : MIDAS Data Directory (same as \"/Logger/Data Dir\")\n");
2521 printf("Data format : Data format (MIDAS)\n");
2522 printf("Filename format : Run format i.e. \"run%%05d.mid\", or \"*.mid.gz\" or \"*.mid.gz,*.xml\" \n");
2523 printf("List label : Label of destination save_set.\n");
2524 printf(" Prevent lazylogger to run if not given.\n");
2525 printf(" Will be reset if maximum capacity reached.\n");
2526 printf("Execute after rewind : Execute the command <cmd> after rewind complete\n");
2527 printf(" : args passed are: 'device path' 'channel name' 'list label'\n");
2528 printf(" : The actual command will look like: <cmd> /dev/nst0 Tape Data_2000\n");
2529 printf("Backup type : Destination device type (Disk, Tape, Script, SFTP, FTP)\n");
2530 printf("Path : Destination path (file.ext, /dev/nst0, ftp...)\n");
2531 printf(" in case of SFTP type, the 'Path' entry should be:\n");
2532 printf(" sftp://username@host/path\n");
2533 printf(" in case of FTP type, the 'Path' entry should be:\n");
2534 printf(" host, port, user, password, directory, run%%05d.mid\n");
2535 printf("Capacity (Bytes) : Maximum capacity of the destination device.\n");
2536 printf("modulo : Enable multiple lazy on same source. Ex: 3ch : 3.0, 3.1, 3.2\n");
2537 printf("tapeAppend : Enable positioning of the TAPE to EOD before each lazy copy\n");
2538 return 1;
2539 }
2540 }
2541
2542 /* Handle SIGPIPE signals generated from errors on the pipe */
2543#ifdef SIGPIPE
2545#endif
2546 if (daemon) {
2547 printf("Becoming a daemon...\n");
2549 }
2550
2551 /* connect to experiment */
2553 if (status != CM_SUCCESS)
2554 return 1;
2555
2556 /* create a common semaphore for the independent lazylogger */
2558
2559 /* check lazy status for multiple channels */
2561 if (db_find_key(hDB, 0, "/Lazy", &hKey) == DB_SUCCESS) {
2562 HNDLE hSubkey;
2563 KEY key;
2564 INT j = 0;
2565 for (i = 0;; i++) {
2567 if (!hSubkey)
2568 break;
2570 if (key.type == TID_KEY) {
2571 /* compose client name */
2572 std::string strclient;
2573 strclient += "Lazy_";
2574 strclient += key.name;
2575 if (cm_exist(strclient.c_str(), TRUE) == CM_SUCCESS)
2576 lazyinfo[j].active = TRUE;
2577 else
2579 strcpy(lazyinfo[j].name, key.name);
2580
2582 j++;
2583 }
2584 }
2585 } else {
2586 /* create settings tree */
2587 channel = 0;
2588 if (channel_name[0] != 0)
2590 std::string str;
2591 str += "/Lazy/";
2593 str += "/Settings";
2595 }
2596
2597 { /* Selection of client */
2598 INT i, j;
2599 char str[32];
2600
2601 if (lazyinfo[0].hKey) {
2602 if (channel_name[0] == 0) {
2603 /* command prompt */
2604 printf(" Available Lazy channels to connect to:\n");
2605 i = 0;
2606 j = 1;
2607 while (lazyinfo[i].hKey) {
2608 if (!lazyinfo[i].active)
2609 printf("%d) Lazy %s \n", j, lazyinfo[i].name);
2610 else
2611 printf(".) Lazy %s already active\n", lazyinfo[i].name);
2612 j++;
2613 i++;
2614 }
2615 printf("Enter client number or new lazy client name: ");
2616 i = atoi(ss_gets(str, 32));
2617 if ((i == 0) && ((strlen(str) == 0) || (strncmp(str, " ", 1) == 0))) {
2618 cm_msg(MERROR, "Lazy", "Please specify a valid channel name (%s)", str);
2620 return 1;
2621 }
2622 } else {
2623 /* Skip the command prompt for serving the -c option */
2624 /*
2625 scan if channel_name already exists
2626 Yes : check if client is running
2627 Yes : get out (goto error)
2628 No : connect (extract index)
2629 No : new channel (i=0)
2630 */
2631 i = 0;
2632 j = -1;
2633 while (lazyinfo[i].hKey) {
2635 /* correct name => check active */
2636 if (lazyinfo[i].active) {
2637 cm_msg(MERROR, "Lazy", "Lazy channel "
2638 "%s"
2639 " already running!",
2640 lazyinfo[i].name);
2642 return 1;
2643 }
2644 j = i;
2645 }
2646 i++;
2647 }
2648 if (j == -1) {
2649 /* new entry */
2650 i = 0;
2651 mstrlcpy(str, channel_name, sizeof(str));
2652 } else {
2653 /* connect to */
2654 i = j + 1;
2655 }
2656 }
2657
2658 if (i == 0) { /* new entry */
2659 for (j = 0; j < MAX_LAZY_CHANNEL; j++) {
2660 if (lazyinfo[j].hKey == 0) {
2661 /* compose client name */
2662 std::string strclient;
2663 strclient += "Lazy_";
2664 strclient += str;
2665 if (cm_exist(strclient.c_str(), TRUE) == CM_SUCCESS)
2666 lazyinfo[j].active = TRUE;
2667 else
2669 strcpy(lazyinfo[j].name, str);
2670 lazyinfo[j].hKey = 0;
2671 channel = j;
2672 break;
2673 }
2674 }
2675 } else if (!lazyinfo[i - 1].active)
2676 channel = i - 1;
2677 else
2678 channel = -1;
2679 }
2680
2681 if (channel < 0) {
2683 return 1;
2684 }
2685
2686 { /* creation of the lazy channel */
2687 char str[128];
2688
2689 if (lazyinfo[channel].hKey == 0)
2690 printf(" Creating Lazy channel %s\n", lazyinfo[channel].name);
2691
2692 /* create/update settings */
2693 sprintf(str, "/Lazy/%s/Settings", lazyinfo[channel].name);
2695 /* create/update statistics */
2696 sprintf(str, "/Lazy/%s/Statistics", lazyinfo[channel].name);
2698 sprintf(str, "/Lazy/%s", lazyinfo[channel].name);
2700 }
2701 }
2702 /* disconnect from experiment */
2704
2705 { /* reconnect to experiment with proper name */
2706 std::string str;
2707 str += "Lazy_";
2710 }
2711 if (status != CM_SUCCESS) {
2713 return 1;
2714 }
2715
2717
2719
2720 size = sizeof(max_event_size);
2721 status = db_get_value(hDB, 0, "/Experiment/MAX_EVENT_SIZE", &max_event_size, &size, TID_DWORD, TRUE);
2722
2723 /* Remove temporary Lazy entry */
2724 {
2725 HNDLE hPkey;
2726
2727 status = db_find_key(hDB, 0, "Programs/Lazy", &hPkey);
2728 if (status == DB_SUCCESS) {
2730 if (status != DB_SUCCESS) {
2731 cm_msg(MERROR, "Lazy", "Cannot delete /Programs/Lazy");
2732 }
2733 }
2734 }
2735
2736 /* turn on keepalive messages with increased timeout */
2737 if (debug)
2739
2740#ifdef HAVE_FTPLIB
2741 if (debug)
2742 ftp_debug((int (*)(const char *)) puts, (int (*)(const char *)) puts);
2743#endif
2744
2745 printf("Lazy_%s starting... "
2746 "!"
2747 " to exit \n",
2749
2750 if (zap_flag) {
2751 /* reset the statistics */
2752 cm_msg(MINFO, "Lazy", "zapping %s/statistics content", lazyinfo[channel].name);
2753 size = sizeof(lazyst);
2754 memset(&lazyst, 0, size);
2755 if (db_find_key(hDB, lazyinfo[channel].hKey, "Statistics", &hKeyst) == DB_SUCCESS)
2756 status = db_set_record(hDB, hKeyst, &lazyst, size, 0);
2757 else
2758 cm_msg(MERROR, "Lazy", "did not find %s/Statistics for zapping", lazyinfo[channel].name);
2759 }
2760
2761 /* get value once & hot links the run state */
2762 db_find_key(hDB, 0, "/runinfo/state", &hKey);
2763 size = sizeof(run_state);
2764 db_get_data(hDB, hKey, &run_state, &size, TID_INT);
2765 status = db_open_record(hDB, hKey, &run_state, sizeof(run_state), MODE_READ, NULL, NULL); // watch a TID_INT
2766 if (status != DB_SUCCESS) {
2767 cm_msg(MERROR, "Lazy", "cannot open /runinfo/state record");
2768 }
2769 /* hot link for statistics in write mode */
2770 size = sizeof(lazyst);
2771 if (db_find_key(hDB, lazyinfo[channel].hKey, "Statistics", &hKey) == DB_SUCCESS) {
2773 }
2775 if (status == DB_NO_ACCESS) {
2776 /* record is probably still in exclusive access by dead FE, so reset it */
2778 if (status != DB_SUCCESS)
2779 cm_msg(MERROR, "Lazy", "Cannot change access mode for %s/Statistics record, error %d", lazyinfo[channel].name,
2780 status);
2781 else
2782 cm_msg(MINFO, "Lazy", "Recovered access mode for %s/Statistics record", lazyinfo[channel].name);
2784 }
2785 if (status != DB_SUCCESS) {
2786 cm_msg(MERROR, "Lazy", "cannot open %s/Statistics record", lazyinfo[channel].name);
2787 }
2788 /* get /settings once & hot link settings in read mode */
2789 db_find_key(hDB, lazyinfo[channel].hKey, "Settings", &hKey);
2790
2791 size = sizeof(lazy);
2793 if (status != DB_SUCCESS) {
2794 cm_msg(MERROR, "Lazy", "cannot get %s/Settings record, db_get_record() status %d", lazyinfo[channel].name,
2795 status);
2796 }
2797
2799 if (status != DB_SUCCESS) {
2800 cm_msg(MERROR, "Lazy", "cannot open %s/Settings record", lazyinfo[channel].name);
2801 }
2802
2803 /* set global key for that channel */
2805
2806 /* set Data dir from /logger if local is empty & /logger exists */
2807 if ((lazy.dir[0] == '\0') && (db_find_key(hDB, 0, "/Logger/Data dir", &hKey) == DB_SUCCESS)) {
2808 size = sizeof(lazy.dir);
2810 db_set_value(hDB, lazyinfo[channel].hKey, "Settings/Data dir", lazy.dir, size, 1, TID_STRING);
2811 }
2812
2813 // Register for STOP transition
2815 printf("Failed to start local RPC server");
2817
2818 /* let user read message before window might close */
2819 ss_sleep(5000);
2820 return 1;
2821 }
2822
2823 mainlast_time = 0;
2824
2825 /* initialize ss_getchar() */
2826 ss_getchar(0);
2827
2828 DWORD period = lazy.period * 1000;
2829
2830 int ch = 0;
2831
2832 do {
2833 msg = cm_yield(2000);
2834 if (period < 1)
2835 period = 1;
2836 if ((ss_millitime() - mainlast_time) > period) {
2838 if (status == FORCE_EXIT) {
2839 cm_msg(MERROR, "lazy", "Exit requested by program");
2840 break;
2841 }
2843 if (status == TRY_LATER) {
2844 period *= 2;
2845 DWORD max_period = 30 * 60 * 1000;
2846 if (period > max_period)
2847 period = max_period;
2848 cm_msg(MINFO, "lazy", "Will try again after %d seconds", period);
2849 } else {
2850 period = lazy.period * 1000;
2851 }
2852 }
2853
2854 /* check keyboard once every 100 ms */
2855 if (ss_millitime() - last_time_kb > 100) {
2857
2858 ch = 0;
2859 while (ss_kbhit()) {
2860 ch = ss_getchar(0);
2861 if (ch == -1)
2862 ch = getchar();
2863 if ((char) ch == '!')
2864 break;
2865 }
2866 }
2867 } while (msg != RPC_SHUTDOWN && msg != SS_ABORT && ch != '!');
2868
2870 return 1;
2871}
static void usage()
void ftp_debug(int(*debug_func)(const char *message), int(*error_func)(const char *message))
Definition ftplib.cxx:32
INT cm_register_transition(INT transition, INT(*func)(INT, char *), INT sequence_number)
Definition midas.cxx:3593
INT cm_get_experiment_database(HNDLE *hDB, HNDLE *hKeyClient)
Definition midas.cxx:3011
INT cm_connect_experiment1(const char *host_name, const char *default_exp_name, const char *client_name, void(*func)(char *), INT odb_size, DWORD watchdog_timeout)
Definition midas.cxx:2297
INT cm_get_environment(char *host_name, int host_name_size, char *exp_name, int exp_name_size)
Definition midas.cxx:2134
INT cm_exist(const char *name, BOOL bUnique)
Definition midas.cxx:7520
#define TID_KEY
Definition midas.h:349
#define MODE_DELETE
Definition midas.h:372
#define MODE_WRITE
Definition midas.h:371
#define MODE_READ
Definition midas.h:370
#define TR_STOP
Definition midas.h:406
#define TID_DWORD
Definition midas.h:336
BOOL ss_kbhit()
Definition system.cxx:3664
INT ss_semaphore_create(const char *name, HNDLE *semaphore_handle)
Definition system.cxx:2460
INT ss_getchar(BOOL reset)
Definition system.cxx:7503
INT ss_daemon_init(BOOL keep_stdout)
Definition system.cxx:2001
INT ss_sleep(INT millisec)
Definition system.cxx:3628
char * ss_gets(char *string, int size)
Definition system.cxx:7770
INT db_delete_key(HNDLE hDB, HNDLE hKey, BOOL follow_links)
Definition odb.cxx:3856
INT db_open_record(HNDLE hDB, HNDLE hKey, void *ptr, INT rec_size, WORD access_mode, void(*dispatcher)(INT, INT, void *), void *info)
Definition odb.cxx:13291
INT db_get_record1(HNDLE hDB, HNDLE hKey, void *data, INT *buf_size, INT align, const char *rec_str)
Definition odb.cxx:11805
INT db_set_mode(HNDLE hDB, HNDLE hKey, WORD mode, BOOL recurse)
Definition odb.cxx:8027
INT db_watch(HNDLE hDB, HNDLE hKey, void(*dispatcher)(INT, INT, INT, void *), void *info)
Definition odb.cxx:13813
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)
Definition odb.cxx:13441
INT db_create_record(HNDLE hDB, HNDLE hKey, const char *orig_key_name, const char *init_str)
Definition odb.cxx:12800
#define LAZY_SETTINGS_STRING
INT lazy_main(INT, LAZY_INFO *, int max_event_size)
#define LAZY_STATISTICS_STRING
static void watch_settings(HNDLE hDB, HNDLE hKey, HNDLE index, void *info)
#define WATCHDOG_TIMEOUT
HNDLE pcurrent_hKey
INT lazy_trstop(INT rn, char *error)
BOOL daemon
Definition mana.cxx:258
char host_name[HOST_NAME_LENGTH]
Definition mana.cxx:242
char expt_name[NAME_LENGTH]
Definition mevb.cxx:44
#define HOST_NAME_LENGTH
Definition midas.h:273
#define DEFAULT_MAX_EVENT_SIZE
Definition midas.h:254
#define DEFAULT_ODB_SIZE
Definition midas.h:270
Here is the call graph for this function:

◆ moduloCheck()

INT moduloCheck ( INT  lModulo,
INT  lPosition,
INT  lrun 
)

Definition at line 369 of file lazylogger.cxx.

381{
382 if (lModulo) {
383 if ((lrun % lModulo) == lPosition)
384 return lrun;
385 else
386 return 0;
387 } else
388 return lrun;
389}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ print_dirlog()

void print_dirlog ( const DIRLOGLIST dirlog)

Definition at line 238 of file lazylogger.cxx.

238 {
239 for (unsigned i = 0; i < dirlog->size(); i++)
240 printf("%d: %s, run %d, size %12.0f\n",
241 i,
242 (*dirlog)[i].filename.c_str(),
243 (*dirlog)[i].runno,
244 (*dirlog)[i].size);
245};
Here is the call graph for this function:

◆ save_done_list()

INT save_done_list ( HNDLE  hLch,
DIRLOGLIST pdone 
)

Definition at line 750 of file lazylogger.cxx.

761{
762 KEY key;
763 int status = db_get_key(hDB, hLch, &key);
764 assert(status == DB_SUCCESS);
765 sort(pdone->begin(), pdone->end(), cmp_dirlog);
766 save_list(key.name, "donelist", pdone);
767 return SUCCESS;
768}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ save_list()

int save_list ( const char lazyname,
const char listname,
const DIRLOGLIST dlist 
)

Definition at line 624 of file lazylogger.cxx.

624 {
625 std::string fname = list_filename(lazyname, listname);
626 std::string tmpname = fname + ".tmp";
627
628 FILE *fp = fopen(tmpname.c_str(), "w");
629 if (!fp) {
630 cm_msg(MERROR, "save_list", "Cannot write to \'%s\', errno %d (%s)",
631 tmpname.c_str(),
632 errno,
633 strerror(errno));
634 return !SUCCESS;
635 }
636
637 for (unsigned i = 0; i < dlist->size(); i++) {
638 const char *s = (*dlist)[i].filename.c_str();
639 const char *p;
640 while ((p = strchr(s, DIR_SEPARATOR)))
641 s = p + 1;
642 fprintf(fp, "%s %d %12.0f\n",
643 s,
644 (*dlist)[i].runno,
645 (*dlist)[i].size);
646 }
647
648 fclose(fp);
649
650 int status = rename(tmpname.c_str(), fname.c_str());
651 if (status) {
652 cm_msg(MERROR, "save_list", "Cannot rename \'%s\' to \'%s\', errno %d (%s)",
653 tmpname.c_str(),
654 fname.c_str(),
655 errno,
656 strerror(errno));
657 return !SUCCESS;
658 }
659
660 return SUCCESS;
661}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ watch_settings()

static void watch_settings ( HNDLE  hDB,
HNDLE  hKey,
HNDLE  index,
void info 
)
static

Definition at line 2419 of file lazylogger.cxx.

2419 {
2420 int status;
2421 assert(info != NULL);
2422 HNDLE hSet = *(HNDLE *) info;
2423 int size = sizeof(lazy);
2425 if (status != DB_SUCCESS) {
2426 cm_msg(MINFO, "watch_settings", "db_get_record(settings) status %d", status);
2427 return;
2428 }
2429
2430 // printf("Settings updated\n");
2431
2432 if (lazy.pupercent != 0)
2434 else
2436
2437 //printf("pup %d, touched %d\n", lazy.pupercent, maintain_touched);
2438}
void ** info
Definition fesimdaq.cxx:41
HNDLE hSet
Definition msysmon.cxx:531
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ blockn

INT blockn = 0

Definition at line 212 of file lazylogger.cxx.

◆ channel

INT channel = -1

Definition at line 198 of file lazylogger.cxx.

◆ convert_flag

BOOL convert_flag = FALSE

Definition at line 207 of file lazylogger.cxx.

◆ copy_continue

BOOL copy_continue = TRUE

Definition at line 208 of file lazylogger.cxx.

◆ data_fmt

INT data_fmt

Definition at line 209 of file lazylogger.cxx.

◆ debug

BOOL debug = FALSE

debug printouts

Definition at line 53 of file lazylogger.cxx.

◆ delay_start

BOOL delay_start = FALSE

Definition at line 214 of file lazylogger.cxx.

◆ dev_type

INT dev_type

Definition at line 209 of file lazylogger.cxx.

◆ full_bck_flag

BOOL full_bck_flag = FALSE

Definition at line 211 of file lazylogger.cxx.

◆ hDB

HNDLE hDB

main ODB handle

Definition at line 202 of file lazylogger.cxx.

◆ hDev

INT hDev

Definition at line 205 of file lazylogger.cxx.

◆ hKey

HNDLE hKey

Definition at line 202 of file lazylogger.cxx.

◆ hKeyst

HNDLE hKeyst

Definition at line 204 of file lazylogger.cxx.

◆ lastsz

double lastsz

Definition at line 203 of file lazylogger.cxx.

◆ lazy

Definition at line 175 of file lazylogger.cxx.

◆ lazy_semaphore

INT lazy_semaphore

Definition at line 201 of file lazylogger.cxx.

◆ lazy_time

DWORD lazy_time = 0

Definition at line 215 of file lazylogger.cxx.

◆ lazyinfo

LAZY_INFO lazyinfo[MAX_LAZY_CHANNEL] = {{0, FALSE, "Tape"}}

Definition at line 196 of file lazylogger.cxx.

196{{0, FALSE, "Tape"}};

◆ lazylog

Definition at line 210 of file lazylogger.cxx.

◆ lazyst

Definition at line 188 of file lazylogger.cxx.

◆ maintain_touched

BOOL maintain_touched = FALSE

Definition at line 211 of file lazylogger.cxx.

◆ msg_flag

BOOL msg_flag

Definition at line 206 of file lazylogger.cxx.

◆ nodelete

BOOL nodelete = FALSE

Definition at line 54 of file lazylogger.cxx.

◆ pcurrent_hKey

HNDLE pcurrent_hKey

Definition at line 202 of file lazylogger.cxx.

◆ run_state

INT run_state

Definition at line 205 of file lazylogger.cxx.

◆ stop_transition

BOOL stop_transition = FALSE

Definition at line 213 of file lazylogger.cxx.