From 280bf4e8f59a456bd9eba258d61bfa522725e148 Mon Sep 17 00:00:00 2001 From: carltimmer <carl.timmer.1@gmail.com> Date: Tue, 3 Dec 2024 10:30:33 -0500 Subject: [PATCH] get everything working for FileWriteTest, create java version --- .../jlab/coda/jevio/test/FileWriteTest.java | 125 ++++++++++++++++++ java/org/jlab/coda/jevio/test/README.md | 3 +- src/test/FileWriteTest.cpp | 29 ++-- src/test/README.md | 2 +- 4 files changed, 149 insertions(+), 10 deletions(-) create mode 100644 java/org/jlab/coda/jevio/test/FileWriteTest.java diff --git a/java/org/jlab/coda/jevio/test/FileWriteTest.java b/java/org/jlab/coda/jevio/test/FileWriteTest.java new file mode 100644 index 00000000..84b745a6 --- /dev/null +++ b/java/org/jlab/coda/jevio/test/FileWriteTest.java @@ -0,0 +1,125 @@ +package org.jlab.coda.jevio.test; + +import org.jlab.coda.hipo.CompressionType; +import org.jlab.coda.jevio.*; + +import java.io.IOException; +import java.nio.ByteBuffer; +import java.nio.ByteOrder; + +/** + * Test program. Mirrors the FileWriteTest.cpp file. + * + * @author timmer + * Date: Dec 2, 2024 + */ +public class FileWriteTest { + + + + void eventWriterTest() throws EvioException, IOException { + + //--------------------------------------------- + // Use CompactEventBuilder to create an event + //--------------------------------------------- + + // Create room for entire big event + int bufSize = 1300000; + CompactEventBuilder ceb = new CompactEventBuilder(bufSize, ByteOrder.nativeOrder(), true); + ceb.openBank(1, 1, DataType.INT32); + int[] dd = new int[250000]; + ceb.addIntData(dd, 0, 250000); + ceb.closeAll(); + ByteBuffer bigEvt = ceb.getBuffer(); + + // Little event + bufSize = 1000; + CompactEventBuilder eb = new CompactEventBuilder(bufSize, ByteOrder.nativeOrder(), true); + eb.openBank(1, 1, DataType.INT32); + eb.addIntData(dd, 0, 3); + eb.closeAll(); + ByteBuffer littleEvt = eb.getBuffer(); + + System.out.println("Buf pos = " + bigEvt.position() + ", lim = " + bigEvt.limit() + ", cap = " + bigEvt.capacity()); + + // Write into a file + int targetRecordBytes = 900000; // 900KB + int bufferBytes = 1000000; // 1MB + + String fname = "./codaFileTestCC.ev"; + + int evioVersion = 6; + + if (evioVersion == 4) { + EventWriterV4 writer = new EventWriterV4(fname, null, null, 1, 0, targetRecordBytes, + 100000, bufferBytes, ByteOrder.nativeOrder(), null, null, true, + false, null, 0, 0, 1, 1); + + System.out.println("Write little event 1, buf pos = " + littleEvt.position() + ", lim = " + littleEvt.limit()); + writer.writeEvent(littleEvt, false); + //writer.writeEventToFile(nullptr, littleEvt, false); + // Delay between writes + //std::this_thread::sleep_for(std::chrono::seconds(2)); + System.out.println("Write BIG event 1"); + writer.writeEvent(bigEvt, false); + //std::this_thread::sleep_for(std::chrono::seconds(2)); + System.out.println("Write little event 2, buf pos = " + littleEvt.position() + ", lim = " + littleEvt.limit()); + writer.writeEvent(littleEvt, true); + //std::this_thread::sleep_for(std::chrono::seconds(2)); + System.out.println("Write BIG event 2"); + writer.writeEvent(bigEvt, true); + System.out.println("WRITER CLOSE"); + writer.close(); + + + EvioReader reader = new EvioReader(fname); + EvioEvent ev; + while ( (ev = reader.parseNextEvent()) != null) { + + } + } + else { + EventWriter writer = new EventWriter(fname, null, null, 1, 0, targetRecordBytes, + 100000, ByteOrder.nativeOrder(), null, true, false, + null, 0, 0, 1, 1, CompressionType.RECORD_UNCOMPRESSED, + 0, 0, bufferBytes); + + System.out.println("Write little event 1, buf pos = " + littleEvt.position() + ", lim = " + littleEvt.limit()); + writer.writeEvent(littleEvt); + //writer.writeEventToFile(littleEvt, false, false); + // Delay between writes + //std::this_thread::sleep_for(std::chrono::seconds(2)); + System.out.println("Write BIG event 1"); + writer.writeEvent(bigEvt); + //writer.writeEventToFile(bigEvt, false, false); + //std::this_thread::sleep_for(std::chrono::seconds(2)); + System.out.println("Write little event 2, buf pos = " + littleEvt.position() + ", lim = " + littleEvt.limit()); + writer.writeEvent(littleEvt); + //writer.writeEventToFile(littleEvt, false, true); + //std::this_thread::sleep_for(std::chrono::seconds(2)); + System.out.println("Write BIG event 2"); + writer.writeEvent(bigEvt); + //writer.writeEventToFile(bigEvt, false, true); + System.out.println("WRITER CLOSE"); + writer.close(); + } + } + + + + /** + * Run as a stand-alone application. + */ + public static void main(String[] args) { + FileWriteTest receiver = new FileWriteTest(); + try { + receiver.eventWriterTest(); + } + catch (Exception e) { + e.printStackTrace(); + } + } + + + +} diff --git a/java/org/jlab/coda/jevio/test/README.md b/java/org/jlab/coda/jevio/test/README.md index 5828c9cc..69bb31b9 100644 --- a/java/org/jlab/coda/jevio/test/README.md +++ b/java/org/jlab/coda/jevio/test/README.md @@ -25,11 +25,12 @@ | [CompressionTest2.java](CompressionTest2.java) | Compress data with LZ4, uncompress, compare result to original data. | | [DictionaryTest.java](DictionaryTest.java) | Write out dictionary with file and read back in. | | [DictTest.java](DictTest.java) | Define different dictionaries. Methods to play with EvioXMLDictionary and EvioDictionaryEntry methods. Methods use dictionary with EvioEvent, EvioBank, and EvioSegment. | -| [DictTest2.java](DictTest.java) | Mirrors Dict_FirstEv_Test.cpp. Write evio data to file with EventWriter using the CompactEventBuilder and EventBuilder classes while inserting created dictionary and **first event**. Read files using EvioReader and print out. | +| [DictTest2.java](DictTest.java) | Mirrors Dict_FirstEv_Test.cpp. Write evio data to file with EventWriter using the CompactEventBuilder and EventBuilder classes while inserting created dictionary and **first event**. Read files using EvioReader and print out. | | [ExtractHallDdata.java](ExtractHallDdata.java) | Used only for HallD data compression test for ESNET. Take HallD data file, pull out data (not headers) and store in files to test for compressibility. | | [FileTest.java](FileTest.java) | Methods to test how the AsynchronousFileChannel affect its ByteBuffer arg when reading and writing, find free space on disk, writing event too large for record space, read/write/append data in files, use listeners and filters, write file with extra words in headers. | | [FileTestVer6.java](FileTestVer6.java) | Create event in buffer of CODA Prestart, Go, End, HallD triggered physics in structure (not data). Many methods to write and read evio v6 data files. | | [FileWritingSpeedTest.java](FileWritingSpeedTest.java) | Test speed of writing evio file to disk. | +| [FileWriteTest.java](FileWriteTest.java) | This class mirrors FileWriteTest.cpp. Compare writing same events as ByteBuffers to file with EventWriterV4 (evio 4) and EventWriter (evio 6). | | [FirstEventTest.java](FirstEventTest.java) | Write file or buf with dictionary and first event. Or write first event after EventWriter created. | | [ReadAggOutput.java](ReadAggOutput.java) | Read and parse CODA data file produced in streaming mode with Aggregator. | | [ReaderTest.java](ReaderTest.java) | Use a few files produced by SwapTest. Methods to read XML string and convert to EvioEvent, read evio file and create xml rep out of event and convert back to EvioEvent, get EvioNode with CompactEventReader and convert to XML, read with EvioReader and convert EvioEvent to XML. | diff --git a/src/test/FileWriteTest.cpp b/src/test/FileWriteTest.cpp index b8877c91..850edb0d 100644 --- a/src/test/FileWriteTest.cpp +++ b/src/test/FileWriteTest.cpp @@ -62,20 +62,29 @@ namespace evio { 100000, ByteOrder::ENDIAN_LOCAL, "", true, false, nullptr, 0, 0, 1, 1, bufferBytes); - std::cout << "Write little event 1" << std::endl; + std::cout << "Write little event 1, buf pos = " << littleEvt->position() << ", lim = " << littleEvt->limit() << std::endl; writer.writeEvent(littleEvt, false); + //writer.writeEventToFile(nullptr, littleEvt, false); // Delay between writes //std::this_thread::sleep_for(std::chrono::seconds(2)); std::cout << "Write BIG event 1" << std::endl; writer.writeEvent(bigEvt, false); //std::this_thread::sleep_for(std::chrono::seconds(2)); - std::cout << "Write little event 2" << std::endl; + std::cout << "Write little event 2, buf pos = " << littleEvt->position() << ", lim = " << littleEvt->limit() << std::endl; writer.writeEvent(littleEvt, true); //std::this_thread::sleep_for(std::chrono::seconds(2)); std::cout << "Write BIG event 2" << std::endl; writer.writeEvent(bigEvt, true); std::cout << "WRTER CLOSE" << std::endl; writer.close(); + + + EvioReader reader(fname); + std::shared_ptr<EvioEvent> ev; + while ( (ev = reader.parseNextEvent()) != nullptr) { + + } + } else { EventWriter writer(fname, "", "", 1, 0, targetRecordBytes, @@ -83,18 +92,22 @@ namespace evio { nullptr, 1, 0, 1, 1, Compressor::CompressionType::UNCOMPRESSED, 0, 0, bufferBytes); - std::cout << "Write little event 1" << std::endl; - writer.writeEventToFile(littleEvt, false, false); + std::cout << "Write little event 1, buf pos = " << littleEvt->position() << ", lim = " << littleEvt->limit() << std::endl; + writer.writeEvent(littleEvt); + //writer.writeEventToFile(littleEvt, false, false); // Delay between writes //std::this_thread::sleep_for(std::chrono::seconds(2)); std::cout << "Write BIG event 1" << std::endl; - writer.writeEventToFile(bigEvt, false, false); + writer.writeEvent(bigEvt); + //writer.writeEventToFile(bigEvt, false, false); //std::this_thread::sleep_for(std::chrono::seconds(2)); - std::cout << "Write little event 2" << std::endl; - writer.writeEventToFile(littleEvt, false, true); + std::cout << "Write little event 2, buf pos = " << littleEvt->position() << ", lim = " << littleEvt->limit() << std::endl; + writer.writeEvent(littleEvt); + //writer.writeEventToFile(littleEvt, false, true); //std::this_thread::sleep_for(std::chrono::seconds(2)); std::cout << "Write BIG event 2" << std::endl; - writer.writeEventToFile(bigEvt, false, true); + writer.writeEvent(bigEvt); + //writer.writeEventToFile(bigEvt, false, true); std::cout << "WRTER CLOSE" << std::endl; writer.close(); } diff --git a/src/test/README.md b/src/test/README.md index 4dcd7ed9..71025e68 100644 --- a/src/test/README.md +++ b/src/test/README.md @@ -12,7 +12,7 @@ | yes | [EvioCompStructHandlerTest.cpp](EvioCompStructHandlerTest.cpp) | This class mirrors CompactStructureHandlerTest.java. Create evio event buffer, put into EvioCompactStructureHandler, remove node, and examine resulting buffer. | | yes | [fileTest.cpp](fileTest.cpp) | Very short test to see if #include \<filesystem\> is available on this system. | | yes | [FileWriteTest.cpp](FileWriteTest.cpp) | Compare writing same events as ByteBuffers to file with EventWriterV4 (evio 4) and EventWriter (evio 6). | -| no | [hallDEventFiles.cpp](hallDEventFiles.cpp) | So Esnet can test data compressibility, take a hall D data file and write out each event into a separate file (no record structure). | +| yes | [hallDEventFiles.cpp](hallDEventFiles.cpp) | So Esnet can test data compressibility, take a hall D data file and write out each event into a separate file (no record structure). | | no | [Hipo_Test.cpp](Hipo_Test.cpp) | Create events with CompactEventBuilder, write into hipo file with Writer and read back with Reader, printout. | | no | [IndexArrayLenTest.cpp](IndexArrayLenTest.cpp) | Write evio 6 data (zero-length index array) with fwrite, read back with Reader and print. Used to test the reading of uncompressed evio buffer and file to see if changes made to handle a zero-length index array actually worked. | | | no | [ReadTest.cpp](ReadTest.cpp) | Read hipo/evio file with Reader, print out # events and each event. |