Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
fbbc437
add more helpful helper method
baltzell Aug 12, 2026
bef3cad
simplify
baltzell Aug 12, 2026
a2857f8
add occupancy table
baltzell Aug 10, 2026
72fd63a
complete OccupancyTable class
baltzell Aug 11, 2026
a9f5031
cleanup
baltzell Aug 11, 2026
25dbc4b
cleanup
baltzell Aug 11, 2026
9f5d4a2
add bank
baltzell Aug 11, 2026
dd905d0
make it work
baltzell Aug 12, 2026
e016f69
cleanup
baltzell Aug 12, 2026
8d51bad
cleanup
baltzell Aug 12, 2026
310e8d7
more
baltzell Aug 13, 2026
06bb8bf
claraify it
baltzell Aug 13, 2026
07c6aae
untagged periodic instead
baltzell Aug 13, 2026
c3349a4
cleanup
baltzell Aug 13, 2026
251c6ed
go long
baltzell Aug 13, 2026
36bb119
cleanup
baltzell Aug 13, 2026
88099ba
cleanup
baltzell Aug 13, 2026
46ec581
cleanup
baltzell Aug 13, 2026
009daca
cleanup
baltzell Aug 13, 2026
69ae7ec
cleanup
baltzell Aug 13, 2026
7a1e184
doc
baltzell Aug 13, 2026
4c26270
cleanup
baltzell Aug 14, 2026
83c1af1
rename
baltzell Aug 14, 2026
dfa2a6a
cleanup
baltzell Aug 14, 2026
f94e5c5
add more detectors
baltzell Aug 14, 2026
a3c2f29
update
baltzell Aug 14, 2026
b370735
revert unrelated changes
baltzell Aug 14, 2026
e5c59d1
add occupancy banks to dst (all) schema
baltzell Aug 14, 2026
e0473eb
debug
baltzell Aug 14, 2026
567d19a
fix bank name
baltzell Aug 14, 2026
f022e8d
remove printouts
baltzell Aug 14, 2026
99e84e7
debug
baltzell Aug 14, 2026
a7797e2
ignore negative indices (BMT?)
baltzell Aug 14, 2026
4dc4701
cleanup
baltzell Aug 14, 2026
534cda6
fix counter, add DC::tdc
baltzell Aug 16, 2026
9472515
change default occupancy prescale to 100
baltzell Aug 16, 2026
884c553
cleanup
baltzell Aug 16, 2026
23fa50b
cleanup
baltzell Aug 16, 2026
b8e3741
rename occupancy banks
baltzell Aug 17, 2026
c999bdd
this should be final
baltzell Aug 17, 2026
9197667
fix bank name
baltzell Aug 17, 2026
c06f59e
cleanup
baltzell Aug 17, 2026
5ace9ba
use filtered banks
baltzell Aug 17, 2026
5cc41e0
fix bank names
baltzell Aug 17, 2026
33c8df3
add occupancy to uber engine
baltzell Aug 22, 2026
a43594b
change yaml variable name
baltzell Aug 25, 2026
d361dc3
cleanup, make it thread-safe
baltzell Aug 25, 2026
b1be734
fix build
baltzell Aug 26, 2026
b4fe565
read banks
baltzell Aug 26, 2026
27a7939
cleanup
baltzell Aug 26, 2026
40b1c1a
fix
baltzell Aug 26, 2026
cb1cc02
make it thread-safe
baltzell Aug 27, 2026
0f138b6
change denoise group
baltzell Sep 15, 2026
9967ca9
add CND occupancy banks
baltzell Sep 15, 2026
e93a9f4
Merge branch 'development' into occupancy
baltzell Sep 15, 2026
0c55600
Merge branch 'development' into occupancy
baltzell Sep 30, 2026
3006033
fix version
baltzell Sep 30, 2026
bef9cd4
thread safety
baltzell Sep 30, 2026
5998e5d
convert to a list
baltzell Sep 30, 2026
4dcf5ca
rework
baltzell Sep 30, 2026
62720e3
cleanup
baltzell Sep 30, 2026
f9e0f99
remove oops
baltzell Sep 30, 2026
7460b21
fix
baltzell Sep 30, 2026
e312ef7
actually initialize!
baltzell Sep 30, 2026
6b56a44
fix
baltzell Oct 1, 2026
ba19e37
cleanup
baltzell Oct 1, 2026
4a5282b
revert
baltzell Oct 1, 2026
bd009ae
remove synchronized
baltzell Oct 1, 2026
c7f94ec
add order for FTOF/CTOF/CND
baltzell Oct 1, 2026
fd797d9
revert
baltzell Oct 1, 2026
ba28805
cleanup
baltzell Oct 2, 2026
8344b6c
revert
baltzell Oct 2, 2026
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
Expand Up @@ -8,6 +8,7 @@
import org.jlab.detector.helicity.HelicitySequenceDelayed;
import org.jlab.detector.serial.SerialHoncho;
import org.jlab.detector.serial.PostProcessor;
import org.jlab.detector.serial.Occupancer;
import org.jlab.jnp.hipo4.data.Bank;
import org.jlab.jnp.hipo4.data.Event;
import org.jlab.jnp.hipo4.data.SchemaFactory;
Expand All @@ -28,13 +29,15 @@
*/
public class Clas12Writer extends HipoToHipoWriter {

Occupancer occupancer;
SerialHoncho serial;
Bank runConfig;
ConstantsManager conman;
SchemaFactory fullSchema;
boolean postprocess;

private void init(JSONObject opts) {
occupancer = new Occupancer();
fullSchema = new SchemaFactory();
fullSchema.initFromDirectory(FileUtils.getEnvironmentPath("CLAS12DIR","etc/bankdefs/hipo4"));
serial = new SerialHoncho(fullSchema);
Expand Down Expand Up @@ -63,6 +66,7 @@ protected HipoWriterSorted createWriter(Path file, JSONObject opts) throws Event
protected void writeEvent(Object event) throws EventWriterException {
Event t = serial.read((Event)event);
if (!t.isEmpty()) writer.addEvent(t, 1);
occupancer.process(((Event)event));
super.writeEvent(event);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
package org.jlab.detector.serial;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Map;
import org.jlab.detector.banks.RawBank;
import org.jlab.utils.groups.IndexedTable;
import org.jlab.utils.groups.IndexedTable.IndexedEntry;
import org.jlab.detector.banks.RawBank.OrderGroups;
import org.jlab.jnp.hipo4.data.Bank;
import org.jlab.jnp.hipo4.data.Event;
import org.jlab.jnp.hipo4.data.Schema;
import org.jlab.jnp.hipo4.data.SchemaFactory;
import org.jlab.utils.system.ClasUtilsFile;

/**
* Occupancy bookkeeper based on IndexedTable, with I/O helpers for indexed banks.
*
* @author baltzell
*/
public class Occupancer extends ArrayList<Occupancer.OccupanceTable> {

static final String BANKDIR = ClasUtilsFile.getResourceDir("CLAS12DIR","etc/bankdefs/hipo4/singles/occupancy");
static final SchemaFactory FULL_SCHEMA = new SchemaFactory();
static { FULL_SCHEMA.initFromDirectory(ClasUtilsFile.getResourceDir("CLAS12DIR","etc/bankdefs/hipo4")); }

int prescale = 1000;
int nevents = 0;

public Occupancer() {
super();
init();
}

public Occupancer(int prescale) {
super();
this.prescale = prescale;
init();
}

private void init() {
try {
// Initialize OccupanceTable list, by reading occupancy bank filenames
// and stripping ".json" suffix and "OCC::" prefix to get hit bank name:
addAll(Files.list(Paths.get(BANKDIR))
.filter(Files::isRegularFile)
.map(p -> p.getFileName().toString())
.map(s -> s.substring(0, s.length()-5))
.map(s -> s.substring(5, s.length()))
.map(OccupanceTable::new).toList());
} catch (IOException ex) {
System.getLogger(Occupancer.class.getName()).log(System.Logger.Level.ERROR, (String) null, ex);
}
}

public boolean process(Event event) {
forEach(t -> { t.fill(event, false); });
if (++nevents % prescale == 0) {
forEach(t -> {
if (t.getTable().getRowCount() > 0) {
event.write(t.create(nevents, event));
}
t.reset();
});
nevents = 0;
}
return true;
}

public void reset() {
forEach(t -> { t.reset(); nevents = 0; });
}

public static class OccupanceTable {

Schema occSchema;
Schema hitSchema;
IndexedTable table;

/**
* A 3-index table, e.g., sector/layer/component.
* @param hitBank name of the hit bank
*/
public OccupanceTable(String hitBank) {
hitSchema = FULL_SCHEMA.getSchema(hitBank);
occSchema = FULL_SCHEMA.getSchema("OCC::" + hitBank);
table = new IndexedTable(occSchema.hasEntry("order")?4:3, new String[]{"occ/F"});
}

/**
* An N-index table.
* @param hitBank name of the hit bank
* @param indexCount number of inidices in the hit bank
*/
public OccupanceTable(String hitBank, int indexCount) {
hitSchema = FULL_SCHEMA.getSchema(hitBank);
occSchema = FULL_SCHEMA.getSchema("OCC::" + hitBank);
table = new IndexedTable(indexCount, new String[]{"occ/F"});
}

public final IndexedTable getTable() { return table; }

/**
* Zero the occupancy table.
*/
public final void reset() {
table = new IndexedTable(table.getList().getIndexSize(), new String[]{"occ/F"});
}

/**
* Get the occupancy table, normalized by number of events.
* @param events
* @return
*/
public final IndexedTable getOccupancy(long events) {
IndexedTable t = new IndexedTable(table.getList().getIndexSize(), new String[]{"occ/F"});
for (long hash : ((Map<Long,IndexedEntry>)table.getList().getMap()).keySet()) {
t.addEntry(IndexedTable.DEFAULT_GENERATOR.getIndices(hash, table.getList().getIndexSize()));
t.setDoubleValueByHash((table.getDoubleValueByHash(0, hash))/events, 0, hash);
}
return t;
}

/**
* Fill the occupancy table.
* @param weight
* @param index
*/
public final void fill(float weight, int... index) {
for (int i=0; i<index.length; i++) if (index[i] < 0) return;
final long hash = IndexedTable.DEFAULT_GENERATOR.hashCode(index);
if (!table.hasEntryByHash(hash)) {
table.addEntry(index);
table.setDoubleValueByHash(0.0d, 0, hash);
}
table.setDoubleValueByHash(table.getDoubleValueByHash(0, hash) + weight, 0, hash);
}

/**
* Fill occupancy table from a user-defined bank.
* @param event
* @param weighted
*/
public void fill(Event event, boolean weighted) {
RawBank bank = new RawBank(hitSchema, 1000, OrderGroups.DEFAULT);
bank.read(event);
final int rows = bank.rows();
int[] idx = new int[table.getList().getIndexSize()];
for (int i=0; i<rows; i++) {
for (int j=0; j<table.getList().getIndexSize(); j++) {
if (j==2) idx[j] = bank.getShort(j,i);
else idx[j] = bank.getByte(j,i);
}
if (weighted) fill(bank.getFloat(table.getList().getIndexSize(),i),idx);
else fill(1.0f, idx);
}
}

/**
* Get an occupancy bank, normalized by number of events.
* @param events
* @param event
* @return
*/
public Bank create(long events, Event event) {
Bank b = new Bank(occSchema, table.getRowCount());
Map<Long,IndexedEntry> m = table.getList().getMap();
int i = 0;
for (long hash : m.keySet()) {
int[] idx = IndexedTable.DEFAULT_GENERATOR.getIndices(hash, table.getList().getIndexSize());
for (int j=0; j<table.getList().getIndexSize(); j++) {
if (j == 2) b.putShort(j, i, (short)idx[j]);
else b.putByte(j, i, (byte)idx[j]);
}
b.putFloat(table.getList().getIndexSize(), i, ((float)m.get(hash).getValue(0).intValue())/events);
i++;
}
return b;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.util.Arrays;
import org.jlab.coda.jevio.EvioException;
import org.jlab.detector.decode.CLASDecoder4;
import org.jlab.detector.serial.Occupancer;
import org.jlab.io.evio.EvioDataEvent;
import org.jlab.io.evio.EvioSource;
import org.jlab.io.hipo.HipoDataEvent;
Expand All @@ -42,7 +43,8 @@ public class EngineProcessor {
private SchemaFactory banksToKeep = null;
private final List<String> schemaExempt = Arrays.asList("RUN::config","DC::tdc");

private CLASDecoder4 decoder = new CLASDecoder4();
private final CLASDecoder4 decoder = new CLASDecoder4();
private final Occupancer occupancer = new Occupancer();

public EngineProcessor(){}

Expand Down Expand Up @@ -134,7 +136,7 @@ public void initDefault(){
String[] names = new String[]{
"MAGFIELDS",
"DCCR","DCHB","FTOFHB","EC","HTCC","EBHB",
"DCTB","FTOFTB","EBTB","VTX"
"DCTB","FTOFTB","EBTB","OCC"
};

String[] services = new String[]{
Expand All @@ -148,7 +150,7 @@ public void initDefault(){
"org.jlab.service.dc.DCTBEngine",
"org.jlab.service.ftof.FTOFTBEngine",
"org.jlab.service.eb.EBTBEngine",
"org.jlab.rec.service.vtx.VTXEngine"
"org.jlab.calibration.service.OccupanceEngine",
};

for(int i = 0; i < names.length; i++){
Expand All @@ -164,7 +166,7 @@ public void initAll(){
"CVTFP","CTOF","CND","BAND",
"HTCC","LTCC","EBHB",
"DCTB","FMT","FTOFTB","CVT","EBTB",
"RICHEB","RTPC","AHDC","ATOF","ALERT", "MC","VTX"
"RICHEB","RTPC","AHDC","ATOF","ALERT", "MC","VTX","OCC"
};

String[] services = new String[]{
Expand Down Expand Up @@ -197,7 +199,8 @@ public void initAll(){
"org.jlab.service.atof.ATOFEngine",
"org.jlab.service.alert.ALERTEngine",
"org.jlab.service.mc.TruthMatch",
"org.jlab.rec.service.vtx.VTXEngine"
"org.jlab.rec.service.vtx.VTXEngine",
"org.jlab.calibration.service.OccupanceEngine",
};
if(names.length!=services.length)
LOGGER.log(Level.SEVERE, "initAll : the list of services does not match the list of service names... ");
Expand Down Expand Up @@ -316,6 +319,7 @@ public void processFile(String file, String output){
public void processEvent(DataEvent event, HipoDataSync writer) {
processEvent(event);
removeBanks(event);
occupancer.process(((HipoDataEvent)event).getHipoEvent());
writer.writeEvent(event);
}

Expand Down
Loading
Loading