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

Public Member Functions

 WriterPopen (LOG_CHN *log_chn, const char *pipe_command, const char *file_ext)
 
 ~WriterPopen ()
 
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

FILEfFp
 
std::string fPipeCommand
 
std::string fCommand
 
std::string fFileExt
 
time_t fLastCheckTime
 

Additional Inherited Members

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

Detailed Description

Definition at line 765 of file mlogger.cxx.

Constructor & Destructor Documentation

◆ WriterPopen()

WriterPopen::WriterPopen ( LOG_CHN log_chn,
const char pipe_command,
const char file_ext 
)
inline

Definition at line 768 of file mlogger.cxx.

769 {
770 if (fTrace)
771 printf("WriterPopen: path [%s]\n", log_chn->path.c_str());
772 fFp = NULL;
773 fPipeCommand = pipe_command;
775 fLastCheckTime = time(NULL);
776 }
time_t fLastCheckTime
Definition mlogger.cxx:903
FILE * fFp
Definition mlogger.cxx:899
std::string fFileExt
Definition mlogger.cxx:902
std::string fPipeCommand
Definition mlogger.cxx:900
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:

◆ ~WriterPopen()

WriterPopen::~WriterPopen ( )
inline

Definition at line 778 of file mlogger.cxx.

779 {
780 if (fTrace)
781 printf("WriterPopen: destructor\n");
782 if (fFp)
783 pclose(fFp);
784 fFp = NULL;
785 }
Here is the call graph for this function:

Member Function Documentation

◆ wr_close()

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

Implements WriterInterface.

Definition at line 857 of file mlogger.cxx.

858 {
859 int err;
860
861 if (fTrace)
862 printf("WriterPopen: close path [%s]\n", log_chn->path.c_str());
863
864 assert(fFp != NULL);
865
866 log_chn->handle = 0;
867
868#ifdef OS_WINNT
869 // sorry no popen?!?
870 return SS_FILE_ERROR;
871#else
872 err = pclose(fFp);
873 fFp = NULL;
874
875 if (err != 0) {
876 cm_msg(MERROR, "WriterPopen::wr_close", "Cannot write to pipe \'%s\', pclose() returned %d, errno %d (%s)", fCommand.c_str(), err, errno, strerror(errno));
877 return SS_FILE_ERROR;
878 }
879
880 chmod(log_chn->path.c_str(), 0444);
881
882 fBytesOut = ss_file_size(log_chn->path.c_str());
883
884 return SUCCESS;
885#endif
886 }
std::string fCommand
Definition mlogger.cxx:901
#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:
Here is the caller graph for this function:

◆ wr_get_chain()

std::string WriterPopen::wr_get_chain ( )
inlinevirtual

Implements WriterInterface.

Definition at line 893 of file mlogger.cxx.

894 {
895 return fPipeCommand;
896 }

◆ wr_get_file_ext()

std::string WriterPopen::wr_get_file_ext ( )
inlinevirtual

Reimplemented from WriterInterface.

Definition at line 888 of file mlogger.cxx.

889 {
890 return fFileExt;
891 }

◆ wr_open()

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

Implements WriterInterface.

Definition at line 787 of file mlogger.cxx.

788 {
789 fBytesIn = 0;
790 fBytesOut = 0;
791
792 if (fTrace)
793 printf("WriterPopen: open path [%s] pipe [%s] ext [%s]\n", log_chn->path.c_str(), fPipeCommand.c_str(), fFileExt.c_str());
794
795 assert(fFp == NULL);
796
797 if (check_file_exists(log_chn->path.c_str()))
798 return SS_FILE_EXISTS;
799
800#ifdef OS_WINNT
801 // sorry no popen?!?
802 return SS_FILE_ERROR;
803#else
804 fCommand = fPipeCommand + log_chn->path;
805
806 fFp = popen(fCommand.c_str(), "w");
807 if (fFp == NULL) {
808 cm_msg(MERROR, "WriterPopen::wr_open", "Cannot write to pipe \'%s\', popen() errno %d (%s)", fCommand.c_str(), errno, strerror(errno));
809 return SS_FILE_ERROR;
810 }
811
812 log_chn->handle = 9999;
813
814 return SUCCESS;
815#endif
816 }
#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 WriterPopen::wr_write ( LOG_CHN log_chn,
const void data,
const int  size 
)
inlinevirtual

Implements WriterInterface.

Definition at line 818 of file mlogger.cxx.

819 {
820 if (fTrace)
821 printf("WriterPopen: write path [%s], size %d\n", log_chn->path.c_str(), size);
822
823 if (size == 0)
824 return SUCCESS;
825
826 if (fFp == NULL) {
827 return SS_FILE_ERROR;
828 }
829
830 fBytesIn += size;
831
832 int wr = fwrite(data, 1, size, fFp);
833
834 //if (wr > 0)
835 //fBytesOut += wr;
836
837 if (wr != size) {
838 cm_msg(MERROR, "WriterPopen::wr_write", "Cannot write to pipe \'%s\', fwrite(%d) returned %d, errno %d (%s)", fCommand.c_str(), size, wr, errno, strerror(errno));
839
840 if (errno == EPIPE) {
841 cm_msg(MERROR, "WriterPopen::wr_write", "Cannot write to pipe \'%s\': broken pipe, closing the pipe", fCommand.c_str());
842 wr_close(log_chn, 0);
843 }
844
845 return SS_FILE_ERROR;
846 }
847
848 time_t now = time(NULL);
849 if (now - fLastCheckTime > 2) {
851 fBytesOut = ss_file_size(log_chn->path.c_str());
852 }
853
854 return SUCCESS;
855 }
int wr_close(LOG_CHN *log_chn, int run_number)
Definition mlogger.cxx:857
void * data
Definition mana.cxx:268
Here is the call graph for this function:

Member Data Documentation

◆ fCommand

std::string WriterPopen::fCommand
private

Definition at line 901 of file mlogger.cxx.

◆ fFileExt

std::string WriterPopen::fFileExt
private

Definition at line 902 of file mlogger.cxx.

◆ fFp

FILE* WriterPopen::fFp
private

Definition at line 899 of file mlogger.cxx.

◆ fLastCheckTime

time_t WriterPopen::fLastCheckTime
private

Definition at line 903 of file mlogger.cxx.

◆ fPipeCommand

std::string WriterPopen::fPipeCommand
private

Definition at line 900 of file mlogger.cxx.


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