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

Public Member Functions

 WriterLZ4 (LOG_CHN *log_chn, WriterInterface *wr)
 
 ~WriterLZ4 ()
 
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

WriterInterfacefWr
 
MLZ4F_compressionContext_t fContext
 
MLZ4F_preferences_t fPrefs
 
char * fBuffer
 
int fBufferSize
 
int fBlockSize
 

Additional Inherited Members

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

Detailed Description

Definition at line 1396 of file mlogger.cxx.

Constructor & Destructor Documentation

◆ WriterLZ4()

WriterLZ4::WriterLZ4 ( LOG_CHN log_chn,
WriterInterface wr 
)
inline

Definition at line 1399 of file mlogger.cxx.

1400 {
1401 if (fTrace)
1402 printf("WriterLZ4: path [%s]\n", log_chn->path.c_str());
1403
1404 assert(wr != NULL);
1405
1406 fBuffer = NULL;
1407 fWr = wr;
1408 fBufferSize = 0;
1409 fBlockSize = 0;
1410 }
int fBlockSize
Definition mlogger.cxx:1587
WriterInterface * fWr
Definition mlogger.cxx:1582
int fBufferSize
Definition mlogger.cxx:1586
char * fBuffer
Definition mlogger.cxx:1585
std::string path
Definition mlogger.cxx:250

◆ ~WriterLZ4()

WriterLZ4::~WriterLZ4 ( )
inline

Definition at line 1412 of file mlogger.cxx.

1413 {
1414 if (fTrace)
1415 printf("WriterLZ4: destructor\n");
1416
1417 FREE(fBuffer);
1418 DELETE(fWr);
1419 }
#define FREE(ptr)
Definition mlogger.cxx:341
#define DELETE(ptr)
Definition mlogger.cxx:342

Member Function Documentation

◆ wr_close()

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

Implements WriterInterface.

Definition at line 1519 of file mlogger.cxx.

1520 {
1521 int xstatus = SUCCESS;
1522 MLZ4F_errorCode_t errorCode;
1523
1524 if (fTrace)
1525 printf("WriterLZ4: close path [%s]\n", log_chn->path.c_str());
1526
1527 log_chn->handle = 0;
1528
1529 /* write End of Stream mark */
1530 size_t headerSize = MLZ4F_compressEnd(fContext, fBuffer, fBufferSize, NULL);
1531
1532 if (MLZ4F_isError(headerSize)) {
1533 errorCode = headerSize;
1534 cm_msg(MERROR, "WriterLZ4::wr_close", "LZ4F_compressEnd() error %d (%s)", (int)errorCode, MLZ4F_getErrorName(errorCode));
1535 return SS_FILE_ERROR;
1536 }
1537
1538 int status = fWr->wr_write(log_chn, fBuffer, headerSize);
1539
1540 fBytesIn += 0;
1542
1543 if (status != SUCCESS) {
1544 if (xstatus == SUCCESS)
1545 xstatus = status;
1546 }
1547
1548 /* close downstream writer */
1549
1550 status = fWr->wr_close(log_chn, run_number);
1551
1552 if (status != SUCCESS) {
1553 if (xstatus == SUCCESS)
1554 xstatus = status;
1555 }
1556
1557 /* free resources */
1558
1559 free(fBuffer);
1560 fBuffer = NULL;
1561 fBufferSize = 0;
1562
1563 errorCode = MLZ4F_freeCompressionContext(fContext);
1564 if (MLZ4F_isError(errorCode)) {
1565 cm_msg(MERROR, "WriterLZ4::wr_close", "LZ4F_freeCompressionContext() error %d (%s)", (int)errorCode, MLZ4F_getErrorName(errorCode));
1566 if (xstatus == SUCCESS)
1567 xstatus = SS_FILE_ERROR;
1568 }
1569
1570 return xstatus;
1571 }
virtual int wr_close(LOG_CHN *log_chn, int run_number)=0
virtual int wr_write(LOG_CHN *log_chn, const void *data, const int size)=0
MLZ4F_compressionContext_t fContext
Definition mlogger.cxx:1583
#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 run_number[2]
Definition mana.cxx:246
DWORD status
Definition odbhist.cxx:39
INT handle
Definition mlogger.cxx:249
Here is the call graph for this function:

◆ wr_get_chain()

std::string WriterLZ4::wr_get_chain ( )
inlinevirtual

Implements WriterInterface.

Definition at line 1577 of file mlogger.cxx.

1577 {
1578 return "lz4 | " + fWr->wr_get_chain();
1579 }
virtual std::string wr_get_chain()=0
Here is the call graph for this function:

◆ wr_get_file_ext()

std::string WriterLZ4::wr_get_file_ext ( )
inlinevirtual

Reimplemented from WriterInterface.

Definition at line 1573 of file mlogger.cxx.

1573 {
1574 return ".lz4" + fWr->wr_get_file_ext();
1575 }
virtual std::string wr_get_file_ext()
Definition mlogger.cxx:388
Here is the call graph for this function:

◆ wr_open()

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

Implements WriterInterface.

Definition at line 1421 of file mlogger.cxx.

1422 {
1423 int status;
1424 MLZ4F_errorCode_t errorCode;
1425
1426 if (fTrace)
1427 printf("WriterLZ4: open path [%s]\n", log_chn->path.c_str());
1428
1429 status = fWr->wr_open(log_chn, run_number);
1430 if (status != SUCCESS) {
1431 return status;
1432 }
1433
1434 errorCode = MLZ4F_createCompressionContext(&fContext, MLZ4F_VERSION);
1435 if (MLZ4F_isError(errorCode)) {
1436 cm_msg(MERROR, "WriterLZ4::wr_open", "LZ4F_createCompressionContext() error %d (%s)", (int)errorCode, MLZ4F_getErrorName(errorCode));
1437 return SS_FILE_ERROR;
1438 }
1439
1440 MLZ4F_blockSizeID_t blockSizeId = MLZ4F_max4MB;
1441 fBlockSize = 4*1024*1024;
1442 fBufferSize = MLZ4F_compressFrameBound(fBlockSize, NULL);
1443 fBufferSize *= 2; // kludge
1444 fBuffer = (char*)malloc(fBufferSize);
1445 if (fBuffer == NULL) {
1446 cm_msg(MERROR, "WriterLZ4::wr_open", "Cannot malloc() %d bytes for an LZ4 compression buffer, block size %d, errno %d (%s)", fBufferSize, fBlockSize, errno, strerror(errno));
1447 return SS_FILE_ERROR;
1448 }
1449
1450 MEMZERO(fPrefs);
1451
1452 fPrefs.compressionLevel = 0; // 0=fast, non-zero=???
1453 fPrefs.autoFlush = 0; // ???
1454 fPrefs.frameInfo.contentChecksumFlag = MLZ4F_contentChecksumEnabled;
1455 fPrefs.frameInfo.blockSizeID = blockSizeId;
1456
1457 size_t headerSize = MLZ4F_compressBegin(fContext, fBuffer, fBufferSize, &fPrefs);
1458
1459 if (MLZ4F_isError(headerSize)) {
1460 errorCode = headerSize;
1461 cm_msg(MERROR, "WriterLZ4::wr_open", "LZ4F_compressBegin() error %d (%s)", (int)errorCode, MLZ4F_getErrorName(errorCode));
1462 return SS_FILE_ERROR;
1463 }
1464
1465 status = fWr->wr_write(log_chn, fBuffer, headerSize);
1466
1467 fBytesIn += 0;
1469
1470 if (status != SUCCESS) {
1471 return SS_FILE_ERROR;
1472 }
1473
1474 log_chn->handle = 9999;
1475
1476 return SUCCESS;
1477 }
virtual int wr_open(LOG_CHN *log_chn, int run_number)=0
MLZ4F_preferences_t fPrefs
Definition mlogger.cxx:1584
#define MEMZERO(obj)
Definition mlogger.cxx:339
Here is the call graph for this function:

◆ wr_write()

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

Implements WriterInterface.

Definition at line 1479 of file mlogger.cxx.

1480 {
1481 const char* ptr = (const char*)data;
1482 int remaining = size;
1483
1484 if (fTrace)
1485 printf("WriterLZ4: write path [%s], size %d\n", log_chn->path.c_str(), size);
1486
1487 while (remaining > 0) {
1488 int wsize = remaining;
1489
1490 if (wsize > fBlockSize)
1491 wsize = fBlockSize;
1492
1493 size_t outSize = MLZ4F_compressUpdate(fContext, fBuffer, fBufferSize, ptr, wsize, NULL);
1494
1495 if (MLZ4F_isError(outSize)) {
1496 int errorCode = outSize;
1497 cm_msg(MERROR, "WriterLZ4::wr_write", "LZ4F_compressUpdate() with %d bytes, block size %d, buffer size %d, write size %d, remaining %d bytes, error %d (%s)", wsize, fBlockSize, fBufferSize, size, remaining, (int)errorCode, MLZ4F_getErrorName(errorCode));
1498 return SS_FILE_ERROR;
1499 }
1500
1501 if (outSize > 0) {
1502 int status = fWr->wr_write(log_chn, fBuffer, outSize);
1503
1504 fBytesIn += wsize;
1506
1507 if (status != SUCCESS) {
1508 return SS_FILE_ERROR;
1509 }
1510 }
1511
1512 ptr += wsize;
1513 remaining -= wsize;
1514 }
1515
1516 return SUCCESS;
1517 }
void * data
Definition mana.cxx:268
Here is the call graph for this function:

Member Data Documentation

◆ fBlockSize

int WriterLZ4::fBlockSize
private

Definition at line 1587 of file mlogger.cxx.

◆ fBuffer

char* WriterLZ4::fBuffer
private

Definition at line 1585 of file mlogger.cxx.

◆ fBufferSize

int WriterLZ4::fBufferSize
private

Definition at line 1586 of file mlogger.cxx.

◆ fContext

MLZ4F_compressionContext_t WriterLZ4::fContext
private

Definition at line 1583 of file mlogger.cxx.

◆ fPrefs

MLZ4F_preferences_t WriterLZ4::fPrefs
private

Definition at line 1584 of file mlogger.cxx.

◆ fWr

WriterInterface* WriterLZ4::fWr
private

Definition at line 1582 of file mlogger.cxx.


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