Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package org.jlab.detector.decode;

import java.util.concurrent.ArrayBlockingQueue;

/**
*
* @author baltzell
*/
public class CLASDecoderPool {

ArrayBlockingQueue<CLASDecoder> pool;

int sharedConstantsManagers = 64;

public CLASDecoderPool(int size, String variation, String timestamp) {

pool = new ArrayBlockingQueue<>(size);

CLASDecoder d0 = null;

for (int i=0; i<size; i++) {

CLASDecoder d;

if (i % sharedConstantsManagers == 0) {
d0 = new CLASDecoder();
if (variation != null) d0.setVariation(variation);
if (timestamp != null) d0.setTimestamp(timestamp);
d = d0;
}
else d = new CLASDecoder(d0);

pool.add(d);
}
}

public CLASDecoder take() throws InterruptedException {
return pool.take();
}

public void put(CLASDecoder decoder) throws InterruptedException {
pool.put(decoder);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@
import java.util.HashSet;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import org.jlab.clara.base.ClaraUtil;
import org.jlab.clara.engine.Engine;
import org.jlab.clara.engine.EngineData;
import org.jlab.clara.engine.EngineDataType;
import org.jlab.clara.engine.EngineStatus;
import org.jlab.detector.decode.CLASDecoder;
import org.jlab.detector.decode.CLASDecoderPool;
import org.jlab.io.evio.EvioDataEvent;
import org.jlab.io.hipo.HipoDataEvent;
import org.jlab.jnp.hipo4.data.SchemaFactory;
Expand All @@ -28,8 +27,7 @@ public class DecoderEngine implements Engine {
Clas12Types.EVIO,Clas12Types.HIPO,EngineDataType.JSON,EngineDataType.STRING);

SchemaFactory schema;
BlockingQueue<CLASDecoder> pool;
int constantsShared = 64;
CLASDecoderPool pool;

public DecoderEngine() {
schema = new SchemaFactory();
Expand Down Expand Up @@ -58,21 +56,9 @@ public void destroy() {}
@Override
public EngineData configure(EngineData ed) {
JSONObject json = new JSONObject(ed.getData());
pool = new ArrayBlockingQueue<>(POOL_SIZE);
CLASDecoder d0 = null;
for (int i=0; i<POOL_SIZE; i++) {
CLASDecoder d;
if (i % constantsShared == 0) {
d0 = new CLASDecoder();
if (json.has("variation")) d0.setVariation(json.getString("variation"));
if (json.has("timestamp")) d0.setVariation(json.getString("timestamp"));
d = d0;
}
else {
d = new CLASDecoder(d0);
}
pool.add(d);
}
pool = new CLASDecoderPool(POOL_SIZE,
json.optString("variation","default"),
json.optString("timestamp",null));
return ed;
}

Expand Down
Loading