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 608 of file mlogger.cxx.

Constructor & Destructor Documentation

◆ WriterGzip()

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

Definition at line 611 of file mlogger.cxx.

612 {
613 if (fTrace)
614 printf("WriterGzip: path [%s]\n", log_chn->path.c_str());
615 fGzfp = 0;
616 if (log_chn->settings.gzip_compression) {
617 fCompress = log_chn->settings.gzip_compression;
618 } else {
620 }
621 fLastCheckTime = time(NULL);
622 }
int fCompress
Definition mlogger.cxx:759
time_t fLastCheckTime
Definition mlogger.cxx:760
gzFile fGzfp
Definition mlogger.cxx:758
static void compress(int init_bits, gdGifBuffer *buffer, gdImagePtr im)
Definition mgd.cxx:1526
TH1X EXPRT * h1_book(const char *name, const char *title, int bins, double min, double max)
Definition rmidas.h:24
Here is the call graph for this function:

◆ ~WriterGzip()

WriterGzip::~WriterGzip ( )
inline

Definition at line 624 of file mlogger.cxx.

625 {
626 if (fTrace)
627 printf("WriterGzip: destructor\n");
628 assert(fGzfp == 0);
629 }
Here is the call graph for this function:

Member Function Documentation

◆ wr_close()

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

Implements WriterInterface.

Definition at line 715 of file mlogger.cxx.

716 {
717 int zerror;
718
719 if (fTrace)
720 printf("WriterGzip: close path [%s]\n", log_chn->path.c_str());
721
722 assert(fGzfp);
723
724 log_chn->handle = 0;
725
727
728 if (zerror != Z_OK) {
729 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));
730 return SS_FILE_ERROR;
731 }
732
734 fGzfp = 0;
735
736 if (zerror != Z_OK) {
737 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));
738 return SS_FILE_ERROR;
739 }
740
741 fBytesOut = ss_file_size(log_chn->path.c_str());
742
743 return SUCCESS;
744 }
#define SS_FILE_ERROR
Definition midas.h:669
#define SUCCESS
Definition mcstd.h:54
#define MERROR
Definition midas.h:559
double ss_file_size(const char *path)
Definition system.cxx:6972
INT cm_msg(INT message_type, const char *filename, INT line, const char *routine, const char *format,...)
Definition midas.cxx:915
Here is the call graph for this function:

◆ wr_get_chain()

std::string WriterGzip::wr_get_chain ( )
inlinevirtual

Implements WriterInterface.

Definition at line 751 of file mlogger.cxx.

752 {
753 return "gzip > " + fFilename;
754 }
std::string fFilename
Definition mlogger.cxx:757

◆ wr_get_file_ext()

std::string WriterGzip::wr_get_file_ext ( )
inlinevirtual

Reimplemented from WriterInterface.

Definition at line 746 of file mlogger.cxx.

747 {
748 return ".gz";
749 }

◆ wr_open()

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

Implements WriterInterface.

Definition at line 631 of file mlogger.cxx.

632 {
633 int zerror;
634
635 fBytesIn = 0;
636 fBytesOut = 0;
637
638 if (fTrace)
639 printf("WriterGzip: open path [%s]\n", log_chn->path.c_str());
640
641 assert(fGzfp == 0);
642
643 if (check_file_exists(log_chn->path.c_str()))
644 return SS_FILE_EXISTS;
645
646 fGzfp = gzopen(log_chn->path.c_str(), "wb");
647 if (fGzfp == 0) {
648 cm_msg(MERROR, "WriterGzip::wr_open", "Cannot write to file \'%s\', gzopen() errno %d (%s)", log_chn->path.c_str(), errno, strerror(errno));
649 return SS_FILE_ERROR;
650 }
651
652 chmod(log_chn->path.c_str(), 0444);
653
654 //printf("WriterGzip::wr_open: compress %d\n", fCompress);
655
656 if (fCompress) {
658 if (zerror != Z_OK) {
659 cm_msg(MERROR, "WriterGzip::wr_open", "gzsetparams() zerror %d", zerror);
660 return SS_FILE_ERROR;
661 }
662 }
663
664#if ZLIB_VERNUM > 0x1235
665 // gzbuffer() added in zlib 1.2.3.5 (8 Jan 2010)
666 zerror = gzbuffer(fGzfp, 128*1024);
667 if (zerror != Z_OK) {
668 cm_msg(MERROR, "WriterGzip::wr_open", "gzbuffer() zerror %d", zerror);
669 return SS_FILE_ERROR;
670 }
671#else
672#warning Very old zlib, no gzbuffer()!
673#endif
674
675 log_chn->handle = 8888;
676
677 fFilename = log_chn->path;
678 return SUCCESS;
679 }
#define SS_FILE_EXISTS
Definition midas.h:686
static bool check_file_exists(const char *filename)
Definition mlogger.cxx:394
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 681 of file mlogger.cxx.

682 {
683 if (fTrace)
684 printf("WriterGzip: write path [%s], size %d\n", log_chn->path.c_str(), size);
685
686 if (size == 0)
687 return SUCCESS;
688
689 assert(fGzfp);
690
691 fBytesIn += size;
692
693 int wr = gzwrite(fGzfp, data, size);
694
695 if (wr != size) {
696 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));
697 return SS_FILE_ERROR;
698 }
699
700#if ZLIB_VERNUM > 0x1235
701 // gzoffset() added in zlib 1.2.3.5 (8 Jan 2010)
703#else
704#warning Very old zlib, no gzoffset()!
705 time_t now = time(NULL);
706 if (now - fLastCheckTime > 2) {
708 fBytesOut = ss_file_size(log_chn->path.c_str());
709 }
710#endif
711
712 return SUCCESS;
713 }
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 759 of file mlogger.cxx.

◆ fFilename

std::string WriterGzip::fFilename
private

Definition at line 757 of file mlogger.cxx.

◆ fGzfp

gzFile WriterGzip::fGzfp
private

Definition at line 758 of file mlogger.cxx.

◆ fLastCheckTime

time_t WriterGzip::fLastCheckTime
private

Definition at line 760 of file mlogger.cxx.


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