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

Public Member Functions

 WriterFile (LOG_CHN *log_chn)
 
 ~WriterFile ()
 
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_chain ()
 
- Public Member Functions inherited from WriterInterface
 WriterInterface ()
 
virtual ~WriterInterface ()
 
virtual std::string wr_get_file_ext ()
 

Private Attributes

std::string fFilename
 
int fFileno
 

Additional Inherited Members

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

Detailed Description

Definition at line 475 of file mlogger.cxx.

Constructor & Destructor Documentation

◆ WriterFile()

WriterFile::WriterFile ( LOG_CHN log_chn)
inline

Definition at line 478 of file mlogger.cxx.

479 {
480 if (fTrace)
481 printf("WriterFile: path [%s]\n", log_chn->path.c_str());
482 fFileno = -1;
483 }
std::string path
Definition mlogger.cxx:250

◆ ~WriterFile()

WriterFile::~WriterFile ( )
inline

Definition at line 485 of file mlogger.cxx.

486 {
487 if (fTrace)
488 printf("WriterFile: destructor\n");
489 fFileno = -1;
490 }

Member Function Documentation

◆ wr_close()

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

Implements WriterInterface.

Definition at line 546 of file mlogger.cxx.

547 {
548 int err;
549
550 if (fTrace)
551 printf("WriterFile: close path [%s]\n", log_chn->path.c_str());
552
553 assert(fFileno >= 0);
554
555 log_chn->handle = 0;
556
557 err = close(fFileno);
558 fFileno = -1;
559
560 if (err != 0) {
561 cm_msg(MERROR, "WriterFile::wr_close", "Cannot write to file \'%s\', close() errno %d (%s)", log_chn->path.c_str(), errno, strerror(errno));
562 return SS_FILE_ERROR;
563 }
564
565 return SUCCESS;
566 }
#define SS_FILE_ERROR
Definition midas.h:670
#define SUCCESS
Definition mcstd.h:54
#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:931
INT handle
Definition mlogger.cxx:249
Here is the call graph for this function:

◆ wr_get_chain()

std::string WriterFile::wr_get_chain ( )
inlinevirtual

Implements WriterInterface.

Definition at line 568 of file mlogger.cxx.

569 {
570 return ">" + fFilename;
571 }
std::string fFilename
Definition mlogger.cxx:574

◆ wr_open()

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

Implements WriterInterface.

Definition at line 492 of file mlogger.cxx.

493 {
494 fBytesIn = 0;
495 fBytesOut = 0;
496
497 if (fTrace)
498 printf("WriterFile: open path [%s]\n", log_chn->path.c_str());
499
500 assert(fFileno < 0);
501
502 if (check_file_exists(log_chn->path.c_str()))
503 return SS_FILE_EXISTS;
504
505#ifdef OS_WINNT
506 fFileno = (int) CreateFile(log_chn->path.c_str(), GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_WRITE_THROUGH | FILE_FLAG_SEQUENTIAL_SCAN, 0);
507#else
508 fFileno = open(log_chn->path.c_str(), O_WRONLY | O_CREAT | O_EXCL | O_TRUNC | O_BINARY | O_LARGEFILE, 0444);
509#endif
510 if (fFileno < 0) {
511 cm_msg(MERROR, "WriterFile::wr_open", "Cannot write to file \'%s\', open() errno %d (%s)", log_chn->path.c_str(), errno, strerror(errno));
512 return SS_FILE_ERROR;
513 }
514
515 log_chn->handle = fFileno;
516
517 fFilename = log_chn->path;
518 return SUCCESS;
519 }
#define SS_FILE_EXISTS
Definition midas.h:687
#define O_BINARY
Definition msystem.h:226
#define O_LARGEFILE
Definition midas.h:210
static bool check_file_exists(const char *filename)
Definition mlogger.cxx:368
Here is the call graph for this function:

◆ wr_write()

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

Implements WriterInterface.

Definition at line 521 of file mlogger.cxx.

522 {
523 if (fTrace)
524 printf("WriterFile: write path [%s], size %d\n", log_chn->path.c_str(), size);
525
526 if (size == 0)
527 return SUCCESS;
528
529 assert(fFileno >= 0);
530
531 fBytesIn += size;
532
533 int wr = write(fFileno, data, size);
534
535 if (wr > 0)
536 fBytesOut += wr;
537
538 if (wr != size) {
539 cm_msg(MERROR, "WriterFile::wr_write", "Cannot write to file \'%s\', write(%d) returned %d, errno: %d (%s)", log_chn->path.c_str(), size, wr, errno, strerror(errno));
540 return SS_FILE_ERROR;
541 }
542
543 return SUCCESS;
544 }
void * data
Definition mana.cxx:268
#define write(n, a, f, d)
Here is the call graph for this function:

Member Data Documentation

◆ fFilename

std::string WriterFile::fFilename
private

Definition at line 574 of file mlogger.cxx.

◆ fFileno

int WriterFile::fFileno
private

Definition at line 575 of file mlogger.cxx.


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