Skip to content

Commit

Permalink
make C++ and Java version consistent
Browse files Browse the repository at this point in the history
  • Loading branch information
carltimmer committed Aug 29, 2024
1 parent 3885ea7 commit caeb4c8
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 8 deletions.
23 changes: 19 additions & 4 deletions java/org/jlab/coda/jevio/test/ReadWriteV4Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.BitSet;

public class ReadWriteV4Test {

Expand Down Expand Up @@ -33,7 +34,7 @@ public class ReadWriteV4Test {
" <bank name=\"Rangy\" tag=\"75 - 78\" >\n" +
" <leaf name=\"BigTag\" tag=\"76\" />\n" +
" </bank >\n" +
"</xmlDict>\n";
"</xmlDict>";

// static ByteBuffer buffer;

Expand Down Expand Up @@ -116,7 +117,9 @@ static EvioBank generateEvioBank(ByteOrder order, int tag, int num) {

try {
builder.appendDoubleData(bank1, dData);
System.out.println(" generate Evio Bank, bank1 len = " + bank1.getTotalBytes());
builder.addChild(ev, bank1);
System.out.println(" generate Evio Bank, ev len = " + ev.getTotalBytes());
}
catch (EvioException e) {/* never happen */}

Expand Down Expand Up @@ -305,7 +308,7 @@ static void writeFile(String filename) {

// Create a "first event"
int[] firstEventData = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
EventBuilder builder = new EventBuilder(1, DataType.INT32, 2);
EventBuilder builder = new EventBuilder(1, DataType.UINT32, 2);
EvioEvent firstEv = builder.getEvent();
try {
firstEv.appendIntData(firstEventData);
Expand Down Expand Up @@ -336,6 +339,9 @@ static void writeFile(String filename) {
// BitSet bitInfo, boolean overWriteOK, boolean append,
// EvioBank firstEvent)

// int streamId = 0, int splitNumber = 0,
// int splitIncrement= 1, int streamCount = 1)


// Create an event with lots of stuff in it
ByteBuffer evioDataBuf = generateEvioBuffer(order, 3, 4);
Expand All @@ -349,13 +355,17 @@ static void writeFile(String filename) {

// write as buffer
writer.writeEvent(evioDataBuf, false);
System.out.println(" Wrote evio buffer, len = " + evioDataBuf.limit());
// write as node
writer.writeEvent(node, false);
System.out.println(" Wrote evio node, total bytes = " + node.getTotalBytes());
// write as EvioBank
writer.writeEvent(bank);
System.out.println(" Wrote evio bank, total bytes = " + bank.getTotalBytes());
System.out.println(" Wrote evio bank, header len in bytes = " + (4*(bank.getHeader().getLength() + 1)));

writer.close();
System.out.println("Finished writing file "+ writer.getCurrentFilename() + ", now read it in");
System.out.println("Finished writing file " + writer.getCurrentFilename() + ", now read it in");
}
catch (EvioException | IOException e) {
e.printStackTrace();
Expand Down Expand Up @@ -627,7 +637,12 @@ public boolean accept(StructureType type, IEvioStructure struct) {
public static void main(String args[]) {

try {
String filename = "./evioTest.evio";

//System.out.println("Dictionary len = " + xmlDict.length());
//System.out.println("Dictionary = \n" + xmlDict);

//String filename_c = "./evioTest.c.evio";
String filename = "./evioTest.java.evio";
writeFile(filename);
readFile(filename);

Expand Down
16 changes: 12 additions & 4 deletions src/test/ReadWriteV4Test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ namespace evio {
"</xmlDict>";

dictionary = ss.str();
//std::cout << "Const: dictionary = " << dictionary << std::endl;
//std::cout << "Dictionary len = " << dictionary.size() << std::endl;
//std::cout << "Dictionary = \n" << dictionary << std::endl;
}


Expand Down Expand Up @@ -175,7 +176,9 @@ namespace evio {
dData[i] = i + 1.;
}
builder.appendDoubleData(bank1, dData, 1000);
cout << " generate Evio Bank, bank1 len = " << bank1->getTotalBytes() << endl;
builder.addChild(ev, bank1);
cout << " generate Evio Bank, ev len = " << ev->getTotalBytes() << endl;

return static_cast<std::shared_ptr<EvioBank>>(ev);
}
Expand Down Expand Up @@ -352,7 +355,7 @@ namespace evio {

void writeFile(string finalFilename) {

ByteOrder outputOrder = ByteOrder::ENDIAN_BIG;
ByteOrder outputOrder = ByteOrder::ENDIAN_LITTLE;

// Create a "first event"
uint32_t firstEventData[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
Expand Down Expand Up @@ -400,10 +403,14 @@ namespace evio {

// write as buffer
writer.writeEvent(evioDataBuf, false);
cout << " Wrote evio buffer, len = " << evioDataBuf->limit() << endl;
// write as node
writer.writeEvent(node, false);
cout << " Wrote evio node, total bytes = " << node->getTotalBytes() << endl;
// write as EvioBank
writer.writeEvent(bank);
cout << " Wrote evio bank, total bytes = " << bank->getTotalBytes() << endl;
cout << " Wrote evio bank, header len in bytes = " << 4*(bank->getHeader()->getLength() + 1) << endl;

writer.close();
cout << "Finished writing file " << finalFilename << " now read it" << endl;
Expand Down Expand Up @@ -434,7 +441,7 @@ namespace evio {

cout << "Print out regular events:" << endl;

for (int i=0; i < reader.getEventCount(); i++) {
for (int i=0; i < evCount; i++) {
auto ev = reader.getEvent(i+1);
cout << "\nEvent" << (i+1) << ":\n" << ev->toString() << endl;
}
Expand Down Expand Up @@ -685,7 +692,8 @@ namespace evio {
int main(int argc, char **argv) {


string filename = "./evioTest.evio";
string filename = "./evioTest.c.evio";
//string filename_j = "./evioTest.java.evio";

evio::ReadWriteTest tester;

Expand Down

0 comments on commit caeb4c8

Please sign in to comment.