Skip to content

Commit

Permalink
test writing whole record
Browse files Browse the repository at this point in the history
  • Loading branch information
carltimmer committed Dec 18, 2024
1 parent 8a43aa2 commit 9a82c82
Show file tree
Hide file tree
Showing 2 changed files with 107 additions and 28 deletions.
66 changes: 51 additions & 15 deletions java/org/jlab/coda/jevio/test/HipoTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,26 +30,33 @@ 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
//

//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);
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand Down
69 changes: 56 additions & 13 deletions src/test/Hipo_Test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,26 +45,37 @@ 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,
// Compressor::UNCOMPRESSED, false);

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);
Expand All @@ -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;

Expand Down Expand Up @@ -106,19 +120,48 @@ namespace evio {
return;
}

std::cout << "event count = " << reader.getEventCount() << std::endl;

uint32_t len;
std::shared_ptr<uint8_t> 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<uint8_t> 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);
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit 9a82c82

Please sign in to comment.