From 6d06eec7674588ac6070683bdd6a550589659603 Mon Sep 17 00:00:00 2001 From: carltimmer Date: Fri, 10 Jan 2025 11:05:58 -0500 Subject: [PATCH] sync the java and C++ versions of HipoTest, change method signature --- java/org/jlab/coda/jevio/test/HipoTest.java | 48 ++++++++++----------- src/test/Hipo_Test.cpp | 26 +++++------ 2 files changed, 37 insertions(+), 37 deletions(-) diff --git a/java/org/jlab/coda/jevio/test/HipoTest.java b/java/org/jlab/coda/jevio/test/HipoTest.java index c02d9472..26a3a370 100644 --- a/java/org/jlab/coda/jevio/test/HipoTest.java +++ b/java/org/jlab/coda/jevio/test/HipoTest.java @@ -237,7 +237,7 @@ public static ByteBuffer deepCopy(ByteBuffer original) { } - void writeAndReadBuffer() { + void writeAndReadBuffer(int tag, int num) { System.out.println(); System.out.println(); @@ -270,7 +270,7 @@ void writeAndReadBuffer() { Writer writer = new Writer(buffer, userHdr); // Create an evio bank of ints - ByteBuffer evioDataBuf = createEventBuilderBuffer(0, 0, order, 200000); + ByteBuffer evioDataBuf = createEventBuilderBuffer(tag, num, order, 200000); // Create node from this buffer EvioNode node = EvioNode.extractEventNode(evioDataBuf, null, 0, 0, 0); @@ -286,7 +286,25 @@ void writeAndReadBuffer() { System.out.println("Finished buffer ->\n" + buffer.toString()); System.out.println("COPY1 ->\n" + copy.toString()); System.out.println("COPY2 ->\n" + copy2.toString()); - System.out.println("Past close, now read it"); + + // Compare original with copy + boolean unchanged = true; + int index = 0; + for (int i = 0; i < buffer.capacity(); i++) { + if (buffer.array()[i] != copy.array()[i]) { + unchanged = false; + index = i; + System.out.println("Orig buffer CHANGED at byte #" + index); + System.out.println(", 0x" + Integer.toHexString(copy.array()[i] & 0xf) + " changed to 0x" + + Integer.toHexString(buffer.array()[i] & 0xf) ); + Utilities.printBytes(buffer, 0, 200, "Buffer Bytes"); + break; + } + } + if (unchanged) { + System.out.println("ORIGINAL buffer Unchanged!"); + } + Utilities.printBytes(buffer, 0, buffer.limit(), "Buffer Bytes"); @@ -300,31 +318,13 @@ void writeAndReadBuffer() { } boolean unchanged; - int index; + int index = 0; byte[] data = null; try { Reader reader = new Reader(buffer); - // Compare original with copy - unchanged = true; - index = 0; - for (int i = 0; i < buffer.capacity(); i++) { - if (buffer.array()[i] != copy.array()[i]) { - unchanged = false; - index = i; - System.out.println("Orig buffer CHANGED at byte #" + index); - System.out.println(", 0x" + Integer.toHexString(copy.array()[i] & 0xf) + " changed to 0x" + - Integer.toHexString(buffer.array()[i] & 0xf) ); - Utilities.printBytes(buffer, 0, 200, "Buffer Bytes"); - break; - } - } - if (unchanged) { - System.out.println("ORIGINAL buffer Unchanged!"); - } - int evCount = reader.getEventCount(); System.out.println(" Got " + evCount + " events"); @@ -529,7 +529,7 @@ public boolean accept(StructureType type, IEvioStructure struct) { System.exit(1); } } - + public static void main(String args[]) { try { @@ -540,7 +540,7 @@ public static void main(String args[]) { tester.testTreeEventCreation(1,1); // BUFFERS - tester.writeAndReadBuffer(); + tester.writeAndReadBuffer(1, 1); } catch (Exception e) { e.printStackTrace(); diff --git a/src/test/Hipo_Test.cpp b/src/test/Hipo_Test.cpp index c1b16878..92fe8589 100644 --- a/src/test/Hipo_Test.cpp +++ b/src/test/Hipo_Test.cpp @@ -230,7 +230,7 @@ namespace evio { } - void writeAndReadBuffer() { + void writeAndReadBuffer(uint16_t tag, uint8_t num) { std::cout << std::endl << std::endl; std::cout << "--------------------------------------------\n"; @@ -258,7 +258,7 @@ namespace evio { Writer writer(buffer, userHdr, 10); // Create an evio bank of ints - auto evioDataBuf = createEventBuilderBuffer(0, 0, order); + auto evioDataBuf = createEventBuilderBuffer(tag, num, order); // Create node from this buffer std::shared_ptr node = EvioNode::extractEventNode(evioDataBuf, 0, 0, 0); @@ -268,21 +268,13 @@ namespace evio { // Get ready-to-read buffer buffer = writer.getBuffer(); + // 2 ways to copy auto copy = std::make_shared(*buffer); - auto copy2 = std::make_shared(*buffer); + auto copy2 = ByteBuffer::copyBuffer(buffer); std::cout << "Finished buffer ->\n" << buffer->toString() << std::endl; std::cout << "COPY1 ->\n" << copy->toString() << std::endl; std::cout << "COPY2 ->\n" << copy2->toString() << std::endl; - std::cout << "Past close, now read it" << std::endl; - - Util::printBytes(buffer, 0, buffer->limit(), "Buffer Bytes"); - - std::cout << "--------------------------------------------\n"; - std::cout << "------------------ Reader ------------------\n"; - std::cout << "--------------------------------------------\n"; - - Reader reader(buffer); // Compare original with copy bool unchanged = true; @@ -302,6 +294,14 @@ namespace evio { std::cout << "ORIGINAL buffer Unchanged!\n"; } + Util::printBytes(buffer, 0, buffer->limit(), "Buffer Bytes"); + + std::cout << "--------------------------------------------\n"; + std::cout << "------------------ Reader ------------------\n"; + std::cout << "--------------------------------------------\n"; + + Reader reader(buffer); + uint32_t evCount = reader.getEventCount(); std::cout << " Got " << evCount << " events" << std::endl; @@ -532,7 +532,7 @@ int main(int argc, char **argv) { tester.testTreeEventCreation(1,1); // BUFFERS - tester.writeAndReadBuffer(); + tester.writeAndReadBuffer(1,1); return 0; }