MIDAS
Loading...
Searching...
No Matches
WriterGzip Class Reference
Inheritance diagram for WriterGzip:
Collaboration diagram for WriterGzip:

Public Member Functions

 WriterGzip (LOG_CHN *log_chn, int compress)
 
 ~WriterGzip ()
 
int wr_open (LOG_CHN *log_chn, int run_number)
 
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 ()
 
std::string wr_get_chain ()
 
- Public Member Functions inherited from WriterInterface
 WriterInterface ()
 
virtual ~WriterInterface ()
 

Private Attributes

std::string fFilename
 
gzFile fGzfp
 
int fCompress
 
time_t fLastCheckTime
 

Additional Inherited Members

- Public Attributes inherited from WriterInterface
bool fTrace
 
double fBytesIn
 
double fBytesOut
 

Detailed Description

Definition at line 582 of file mlogger.cxx.

Constructor & Destructor Documentation

◆ WriterGzip()

WriterGzip::WriterGzip ( LOG_CHN log_chn,
int  compress 
)
inline

Definition at line 585 of file mlogger.cxx.

586 {
587 if (fTrace)
588 printf("WriterGzip: path [%s]\n", log_chn->path.c_str());
589 fGzfp = 0;
590 if (log_chn->settings.gzip_compression) {
592 } else {
594 }
595 fLastCheckTime = time(NULL);
596 }
int fCompress
Definition mlogger.cxx:733
time_t fLastCheckTime
Definition mlogger.cxx:734
gzFile fGzfp
Definition mlogger.cxx:732
static void compress(int init_bits, gdGifBuffer *buffer, gdImagePtr im)
Definition mgd.cxx:1526
uint32_t gzip_compression
Definition mlogger.cxx:182
std::string path
Definition mlogger.cxx:250
CHN_SETTINGS settings
Definition mlogger.cxx:260
Here is the call graph for this function:

◆ ~WriterGzip()

WriterGzip::~WriterGzip ( )
inline

Definition at line 598 of file mlogger.cxx.

599 {
600 if (fTrace)
601 printf("WriterGzip: destructor\n");
602 assert(fGzfp == 0);
603 }

Member Function Documentation

◆ wr_close()

int WriterGzip::wr_close ( LOG_CHN log_chn,
int  run_number 
)
inlinevirtual

Implements WriterInterface.

Definition at line 689 of file mlogger.cxx.

690 {
691 int zerror;
692
693 if (fTrace)
694 printf("WriterGzip: close path [%s]\n", log_chn->path.c_str());
695
696 assert(fGzfp);
697
698 log_chn->handle = 0;
699
700 zerror = gzflush(fGzfp, Z_FINISH);
701
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));
704 return SS_FILE_ERROR;
705 }
706
707 zerror = gzclose(fGzfp);
708 fGzfp = 0;
709
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));
712 return SS_FILE_ERROR;
713 }
714
715 fBytesOut = ss_file_size(log_chn->path.c_str());
716
717 return SUCCESS;
718 }
#define SS_FILE_ERROR
Definition midas.h:670
#define SUCCESS
Definition mcstd.h:54
#define MERROR
Definition midas.h:559
double ss_file_size(const char *path)
Definition system.cxx:7050
INT cm_msg(INT message_type, const char *filename, INT line, const char *routine, const char *format,...)
Definition midas.cxx:931
INT handle
Definition mlogger.cxx:249
Here is the call graph for this function:

◆ wr_get_chain()

std::string WriterGzip::wr_get_chain ( )
inlinevirtual

Implements WriterInterface.

Definition at line 725 of file mlogger.cxx.

726 {
727 return "gzip > " + fFilename;
728 }
std::string fFilename
Definition mlogger.cxx:731

◆ wr_get_file_ext()

std::string WriterGzip::wr_get_file_ext ( )
inlinevirtual

Reimplemented from WriterInterface.

Definition at line 720 of file mlogger.cxx.

721 {
722 return ".gz";
723 }

◆ wr_open()

int WriterGzip::wr_open ( LOG_CHN log_chn,
int  run_number 
)
inlinevirtual

Implements WriterInterface.

Definition at line 605 of file mlogger.cxx.

606 {
607 int zerror;
608
609 fBytesIn = 0;
610 fBytesOut = 0;
611
612 if (fTrace)
613 printf("WriterGzip: open path [%s]\n", log_chn->path.c_str());
614
615 assert(fGzfp == 0);
616
617 if (check_file_exists(log_chn->path.c_str()))
618 return SS_FILE_EXISTS;
619
620 fGzfp = gzopen(log_chn->path.c_str(), "wb");
621 if (fGzfp == 0) {
622 cm_msg(MERROR, "WriterGzip::wr_open", "Cannot write to file \'%s\', gzopen() errno %d (%s)", log_chn->path.c_str(), errno, strerror(errno));
623 return SS_FILE_ERROR;
624 }
625
626 chmod(log_chn->path.c_str(), 0444);
627
628 //printf("WriterGzip::wr_open: compress %d\n", fCompress);
629
630 if (fCompress) {
631 zerror = gzsetparams(fGzfp, fCompress, Z_DEFAULT_STRATEGY);
632 if (zerror != Z_OK) {
633 cm_msg(MERROR, "WriterGzip::wr_open", "gzsetparams() zerror %d", zerror);
634 return SS_FILE_ERROR;
635 }
636 }
637
638#if ZLIB_VERNUM > 0x1235
639 // gzbuffer() added in zlib 1.2.3.5 (8 Jan 2010)
640 zerror = gzbuffer(fGzfp, 128*1024);
641 if (zerror != Z_OK) {
642 cm_msg(MERROR, "WriterGzip::wr_open", "gzbuffer() zerror %d", zerror);
643 return SS_FILE_ERROR;
644 }
645#else
646#warning Very old zlib, no gzbuffer()!
647#endif
648
649 log_chn->handle = 8888;
650
651 fFilename = log_chn->path;
652 return SUCCESS;
653 }
#define SS_FILE_EXISTS
Definition midas.h:687
static bool check_file_exists(const char *filename)
Definition mlogger.cxx:368
Here is the call graph for this function:

◆ wr_write()

int WriterGzip::wr_write ( LOG_CHN log_chn,
const void *  data,
const int  size 
)
inlinevirtual

Implements WriterInterface.

Definition at line 655 of file mlogger.cxx.

656 {
657 if (fTrace)
658 printf("WriterGzip: write path [%s], size %d\n", log_chn->path.c_str(), size);
659
660 if (size == 0)
661 return SUCCESS;
662
663 assert(fGzfp);
664
665 fBytesIn += size;
666
667 int wr = gzwrite(fGzfp, data, size);
668
669 if (wr != 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));
671 return SS_FILE_ERROR;
672 }
673
674#if ZLIB_VERNUM > 0x1235
675 // gzoffset() added in zlib 1.2.3.5 (8 Jan 2010)
676 fBytesOut = gzoffset(fGzfp);
677#else
678#warning Very old zlib, no gzoffset()!
679 time_t now = time(NULL);
680 if (now - fLastCheckTime > 2) {
681 fLastCheckTime = now;
682 fBytesOut = ss_file_size(log_chn->path.c_str());
683 }
684#endif
685
686 return SUCCESS;
687 }
void * data
Definition mana.cxx:268
Here is the call graph for this function:

Member Data Documentation

◆ fCompress

int WriterGzip::fCompress
private

Definition at line 733 of file mlogger.cxx.

◆ fFilename

std::string WriterGzip::fFilename
private

Definition at line 731 of file mlogger.cxx.

◆ fGzfp

gzFile WriterGzip::fGzfp
private

Definition at line 732 of file mlogger.cxx.

◆ fLastCheckTime

time_t WriterGzip::fLastCheckTime
private

Definition at line 734 of file mlogger.cxx.


The documentation for this class was generated from the following file: