From 9a82c82261d02a81ab5d3d583c12858aeff7771a Mon Sep 17 00:00:00 2001 From: carltimmer Date: Wed, 18 Dec 2024 12:56:06 -0500 Subject: [PATCH] test writing whole record --- java/org/jlab/coda/jevio/test/HipoTest.java | 66 +++++++++++++++----- src/test/Hipo_Test.cpp | 69 +++++++++++++++++---- 2 files changed, 107 insertions(+), 28 deletions(-) diff --git a/java/org/jlab/coda/jevio/test/HipoTest.java b/java/org/jlab/coda/jevio/test/HipoTest.java index f9e15817..5615b59d 100644 --- a/java/org/jlab/coda/jevio/test/HipoTest.java +++ b/java/org/jlab/coda/jevio/test/HipoTest.java @@ -30,6 +30,17 @@ void testCompactEventCreation(int tag, int num) throws EvioException, IOExceptio Utilities.printBytes(buffer, 0, buffer.limit(), "BUFFER BYTES"); System.out.println("\nBuffer -> \n" + buffer.toString()); + + CompressionType compressionType = CompressionType.RECORD_COMPRESSION_LZ4_BEST; + CompressionType compressionType2 = CompressionType.RECORD_UNCOMPRESSED; + + //------------------------------ + // Create record to test writer.writeRecord(recOut); + // This will not change position of buffer. + //------------------------------ + RecordOutputStream recOut = new RecordOutputStream(order, 0, 0, compressionType2); + recOut.addEvent(buffer, 0); + //------------------------------ // // Write file @@ -37,19 +48,15 @@ void testCompactEventCreation(int tag, int num) throws EvioException, IOExceptio //WriterMT writer = new WriterMT(); -// WriterMT writer = new WriterMT(order, 1000, 1000000, -// CompressionType.RECORD_COMPRESSION_LZ4_BEST, -// 3, 4); +// WriterMT writer = new WriterMT(order, 1000, 1000000, compressionType, 3, 4); WriterMT writer = new WriterMT(HeaderType.EVIO_FILE, order, 1000, 1000000, - dictionary, buffer.array(), buffer.limit(), - CompressionType.RECORD_COMPRESSION_LZ4_BEST, + dictionary, buffer.array(), buffer.limit(), compressionType, 3, false, 4); // // Writer writer = new Writer(HeaderType.EVIO_FILE, ByteOrder.nativeOrder(), -// 0, 0, dictionary, buffer.array(), buffer.limit(), -// CompressionType.RECORD_COMPRESSION_LZ4_BEST, false); +// 0, 0, dictionary, buffer.array(), buffer.limit(), compressionType, false); writer.open(writeFileName1, null, true); writer.addEvent(buffer); @@ -64,6 +71,8 @@ void testCompactEventCreation(int tag, int num) throws EvioException, IOExceptio writer.addEvent(buffer); writer.addEvent(buffer); writer.addEvent(buffer); + System.out.println("add entire record"); + writer.writeRecord(recOut); writer.close(); f = new File (writeFileName1); @@ -98,16 +107,43 @@ void testCompactEventCreation(int tag, int num) throws EvioException, IOExceptio byte[] bytes = reader.getNextEvent(); EvioEvent ev = EvioReader.getEvent(bytes, 0, reader.getByteOrder()); - System.out.println("next evio event ->\n" + ev.treeToString("")); + if (bytes != null) { + System.out.println("next evio event ->\n" + ev.treeToString("")); + } + + bytes = reader.getEvent(0); + if (bytes != null) { + System.out.println("getEvent(0), size = " + bytes.length); + } - byte[] bytes2 = reader.getEvent(0); - System.out.println("get event(0), size = " + bytes2.length); + bytes = reader.getEvent(1); + if (bytes != null) { + System.out.println("getEvent(1), size = " + bytes.length); + } - bytes2 = reader.getEvent(1); - System.out.println("get event(1), size = " + bytes2.length); + bytes = reader.getEvent(2); + if (bytes != null) { + System.out.println("getEvent(2), size = " + bytes.length); + } - bytes2 = reader.getEvent(2); - System.out.println("get event(2), size = " + bytes2.length); + bytes = reader.getEvent(3); + if (bytes != null) { + System.out.println("getEvent(3), size = " + bytes.length); + } + + // This event was added with reader.recordWrite() + bytes = reader.getEvent(4); + if (bytes != null) { + System.out.println("getEvent(4), size = " + bytes.length); + } + + bytes = reader.getEvent(20); + if (bytes != null) { + System.out.println("getEvent(20), size = " + bytes.length); + } + else { + System.out.println("getEvent(20), no such event!"); + } ByteBuffer bb1 = ByteBuffer.allocate(20000); reader.getEvent(bb1, 0); @@ -190,7 +226,7 @@ public static void main(String args[]) { try { HipoTest tester = new HipoTest(); tester.testCompactEventCreation(1,1); - tester.testTreeEventCreation(1,1); + //tester.testTreeEventCreation(1,1); } catch (Exception e) { e.printStackTrace(); diff --git a/src/test/Hipo_Test.cpp b/src/test/Hipo_Test.cpp index daabff27..2321a037 100644 --- a/src/test/Hipo_Test.cpp +++ b/src/test/Hipo_Test.cpp @@ -45,14 +45,25 @@ namespace evio { void testCompactEventCreation(uint16_t tag, uint8_t num) { try { + bool addTrailerIndex = true; + // Create ByteBuffer with EvioEvent in it buffer = createCompactEventBuffer(tag, num); Util::printBytes(buffer, 0, buffer->limit(), "BUFFER BYTES"); std::cout << "\nBuffer -> \n" << buffer->toString() << "\n"; + //------------------------------ + // Create record to test writer.writeRecord(recOut); + // This will not change position of buffer. + //------------------------------ + RecordOutput recOut(order); + recOut.addEvent(buffer, 0); + //------------------------------ + // - // Write file + // Write file. + // Dictionary and first event end up as user header in file header. // // Writer writer(HeaderType::EVIO_FILE, ByteOrder::ENDIAN_LOCAL, // 0, 0, "", nullptr, 0, @@ -60,11 +71,11 @@ namespace evio { WriterMT writer(HeaderType::EVIO_FILE, ByteOrder::ENDIAN_LOCAL, 0, 0, dictionary, buffer->array(), buffer->limit(), - Compressor::UNCOMPRESSED, 1); + Compressor::UNCOMPRESSED, 1, addTrailerIndex); -// WriterMT writer(HeaderType::EVIO_FILE, ByteOrder::ENDIAN_LOCAL, -// 0, 0, dictionary, buffer->array(), buffer->limit(), -// Compressor::LZ4_BEST, 3); + WriterMT writer2(HeaderType::EVIO_FILE, ByteOrder::ENDIAN_LOCAL, + 0, 0, dictionary, buffer->array(), buffer->limit(), + Compressor::LZ4_BEST, 3, addTrailerIndex); writer.open(writeFileName1, nullptr, true); writer.addEvent(buffer); @@ -77,6 +88,9 @@ namespace evio { writer.addEvent(buffer); writer.addEvent(buffer); writer.addEvent(buffer); + std::cout << "add entire record" << std::endl; + writer.writeRecord(recOut); + writer.close(); std::cout << "File size of " << writeFileName1 << " is now " << getFileSize(writeFileName1) << std::endl; @@ -106,19 +120,48 @@ namespace evio { return; } + std::cout << "event count = " << reader.getEventCount() << std::endl; + uint32_t len; std::shared_ptr bytes = reader.getNextEvent(&len); auto ev = EvioReader::getEvent(bytes.get(), len, reader.getByteOrder()); - std::cout << "next evio event ->\n" << ev->treeToString("") << std::endl; + if (bytes != nullptr) { + std::cout << "next evio event ->\n" << ev->treeToString("") << std::endl; + } + + bytes = reader.getEvent(0, &len); + if (bytes != nullptr) { + std::cout << "getEvent(0), size = " << std::to_string(len) << std::endl; + } - std::shared_ptr bytes2 = reader.getEvent(0, &len); - std::cout << "get event(0), size = " << std::to_string(len) << std::endl; + bytes = reader.getEvent(1, &len); + if (bytes != nullptr) { + std::cout << "getEvent(1), size = " << std::to_string(len) << std::endl; + } + + bytes = reader.getEvent(2, &len); + if (bytes != nullptr) { + std::cout << "getEvent(2), size = " << std::to_string(len) << std::endl; + } + + bytes = reader.getEvent(3, &len); + if (bytes != nullptr) { + std::cout << "getEvent(3), size = " << std::to_string(len) << std::endl; + } - reader.getEvent(1, &len); - std::cout << "get event(1), size = " << std::to_string(len) << std::endl; + // This event was added with reader.recordWrite() + bytes = reader.getEvent(4, &len); + if (bytes != nullptr) { + std::cout << "getEvent(4), size = " << std::to_string(len) << std::endl; + } - reader.getEvent(1, &len); - std::cout << "get event(2), size = " << std::to_string(len) << std::endl; + bytes = reader.getEvent(20, &len); + if (bytes != nullptr) { + std::cout << "getEvent(20), size = " << std::to_string(len) << std::endl; + } + else { + std::cout << "getEvent(20), no such event!" << std::endl; + } ByteBuffer bb1(20000); reader.getEvent(bb1, 0); @@ -193,7 +236,7 @@ namespace evio { int main(int argc, char **argv) { auto tester = evio::HipoTester(); tester.testCompactEventCreation(1,1); - tester.testTreeEventCreation(1,1); + //tester.testTreeEventCreation(1,1); return 0; }