Skip to content

Commit

Permalink
get everything working for FileWriteTest, create java version
Browse files Browse the repository at this point in the history
  • Loading branch information
carltimmer committed Dec 3, 2024
1 parent 4c209d1 commit 280bf4e
Show file tree
Hide file tree
Showing 4 changed files with 149 additions and 10 deletions.
125 changes: 125 additions & 0 deletions java/org/jlab/coda/jevio/test/FileWriteTest.java
Original file line number Diff line number Diff line change
@@ -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();
}
}



}
3 changes: 2 additions & 1 deletion java/org/jlab/coda/jevio/test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. |
Expand Down
29 changes: 21 additions & 8 deletions src/test/FileWriteTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,39 +62,52 @@ 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,
100000, ByteOrder::ENDIAN_LOCAL, "", true, false,
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();
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. |
Expand Down

0 comments on commit 280bf4e

Please sign in to comment.