Skip to content

Commit

Permalink
sync the java and C++ versions of HipoTest, change method signature
Browse files Browse the repository at this point in the history
  • Loading branch information
carltimmer committed Jan 10, 2025
1 parent ff0712c commit 6d06eec
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 37 deletions.
48 changes: 24 additions & 24 deletions java/org/jlab/coda/jevio/test/HipoTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ public static ByteBuffer deepCopy(ByteBuffer original) {
}


void writeAndReadBuffer() {
void writeAndReadBuffer(int tag, int num) {

System.out.println();
System.out.println();
Expand Down Expand Up @@ -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);

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

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

Expand Down Expand Up @@ -529,7 +529,7 @@ public boolean accept(StructureType type, IEvioStructure struct) {
System.exit(1);
}
}


public static void main(String args[]) {
try {
Expand All @@ -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();
Expand Down
26 changes: 13 additions & 13 deletions src/test/Hipo_Test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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<EvioNode> node = EvioNode::extractEventNode(evioDataBuf, 0, 0, 0);

Expand All @@ -268,21 +268,13 @@ namespace evio {
// Get ready-to-read buffer
buffer = writer.getBuffer();

// 2 ways to copy
auto copy = std::make_shared<ByteBuffer>(*buffer);
auto copy2 = std::make_shared<ByteBuffer>(*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;
Expand All @@ -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;

Expand Down Expand Up @@ -532,7 +532,7 @@ int main(int argc, char **argv) {
tester.testTreeEventCreation(1,1);

// BUFFERS
tester.writeAndReadBuffer();
tester.writeAndReadBuffer(1,1);

return 0;
}
Expand Down

0 comments on commit 6d06eec

Please sign in to comment.