-
Notifications
You must be signed in to change notification settings - Fork 33
add occupancy bookkeeping class and HIPO banks #1378
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
baltzell
wants to merge
47
commits into
development
Choose a base branch
from
occupancy
base: development
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
47 commits
Select commit
Hold shift + click to select a range
5dba77e
add more helpful helper method
baltzell fe75d01
simplify
baltzell ab9242f
add occupancy table
baltzell b39aa6d
complete OccupancyTable class
baltzell fdbcf36
cleanup
baltzell 76a941b
cleanup
baltzell fd4bf54
add bank
baltzell b8c3467
make it work
baltzell 0f94ca3
cleanup
baltzell b8741b9
cleanup
baltzell 65d0bf6
more
baltzell 76f7676
claraify it
baltzell 08c89f3
untagged periodic instead
baltzell f85516a
cleanup
baltzell 74eb33f
go long
baltzell 9d34200
cleanup
baltzell 2139259
cleanup
baltzell 5910eb4
cleanup
baltzell dae23bc
cleanup
baltzell 159895d
cleanup
baltzell 70637be
doc
baltzell ea2149b
cleanup
baltzell bbb7f77
rename
baltzell e52e457
cleanup
baltzell f4e304d
add more detectors
baltzell d97c024
update
baltzell 02f00e7
revert unrelated changes
baltzell f1c6c9e
add occupancy banks to dst (all) schema
baltzell 2917aeb
debug
baltzell a1f8485
fix bank name
baltzell 8a64ea7
remove printouts
baltzell 3590fad
debug
baltzell 35d4abb
ignore negative indices (BMT?)
baltzell c7eedef
cleanup
baltzell 9914cc7
add column-index accessors
baltzell d3e6186
extension class too
baltzell e6651bd
fix counter, add DC::tdc
baltzell 12f09ec
change default occupancy prescale to 100
baltzell 3875153
cleanup
baltzell e214f89
cleanup
baltzell 400beba
rename occupancy banks
baltzell 71bc319
this should be final
baltzell ee92772
fix bank name
baltzell fa5ffe4
cleanup
baltzell 685fa7a
use filtered banks
baltzell 38e0b64
fix bank names
baltzell 8550f42
Merge branch 'development' into occupancy
baltzell File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
236 changes: 236 additions & 0 deletions
236
common-tools/clas-detector/src/main/java/org/jlab/detector/calib/utils/OccupanceTable.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,236 @@ | ||
| package org.jlab.detector.calib.utils; | ||
|
|
||
| import java.util.Map; | ||
| import org.jlab.detector.banks.RawBank; | ||
| import org.jlab.detector.banks.RawBank.OrderGroups; | ||
| import org.jlab.detector.banks.RawDataBank; | ||
| import org.jlab.io.base.DataBank; | ||
| import org.jlab.io.base.DataEvent; | ||
| import org.jlab.jnp.hipo4.data.Bank; | ||
| import org.jlab.jnp.hipo4.data.Event; | ||
| import org.jlab.jnp.hipo4.data.SchemaFactory; | ||
| import org.jlab.utils.groups.IndexedTable; | ||
| import org.jlab.utils.groups.IndexedTable.IndexedEntry; | ||
|
|
||
| /** | ||
| * Occupancy bookkeeper based on IndexedTable, with I/O helpers for indexed banks. | ||
| * | ||
| * @author baltzell | ||
| */ | ||
| public class OccupanceTable { | ||
|
|
||
| IndexedTable table; | ||
| RawBank hitBank; | ||
| RawDataBank hitDataBank; | ||
| Bank occBank; | ||
|
|
||
| /** | ||
| * A 3-index table, e.g., sector/layer/component. | ||
| * @param schema | ||
| * @param hitBank name of the hit bank | ||
| */ | ||
| public OccupanceTable(SchemaFactory schema, String hitBank) { | ||
| this.hitBank = new RawBank(schema.getSchema(hitBank), 1000, OrderGroups.NOMINAL); | ||
| hitDataBank = new RawDataBank(hitBank, 1000, OrderGroups.NOMINAL); | ||
| occBank = schema.getBank("OCC::"+hitBank); | ||
| table = new IndexedTable(3, new String[]{"occ/F"}); | ||
| } | ||
|
|
||
| /** | ||
| * An N-index table. | ||
| * @param schema | ||
| * @param hitBank name of the hit bank | ||
| * @param indexCount number of inidices in the hit bank | ||
| */ | ||
| public OccupanceTable(SchemaFactory schema, String hitBank, int indexCount) { | ||
| this.hitBank = new RawBank(schema.getSchema(hitBank), 1000, OrderGroups.NOMINAL); | ||
| hitDataBank = new RawDataBank(hitBank, 1000, OrderGroups.NOMINAL); | ||
| occBank = schema.getBank("OCC::"+hitBank); | ||
| table = new IndexedTable(indexCount, new String[]{"occ/F"}); | ||
| } | ||
|
|
||
| /** | ||
| * 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 bank | ||
| * @param weighted | ||
| */ | ||
| public void fill(RawBank bank, boolean weighted) { | ||
| int rows = bank.getRows(); | ||
| 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); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Fill occupancy table from a user-defined bank. | ||
| * @param bank | ||
| * @param weighted | ||
| */ | ||
| public void fill(RawDataBank bank, boolean weighted) { | ||
| if (bank != null) { | ||
| 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); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Fill occupancy table from the hit bank, unweighted. | ||
| * @param event | ||
| */ | ||
| public void fill(Event event) { | ||
| hitBank.read(event); | ||
| fill(hitBank, false); | ||
| } | ||
|
|
||
| /** | ||
| * Fill occupancy table from the hit bank, unweighted. | ||
| * @param event | ||
| */ | ||
| public void fill(DataEvent event) { | ||
| hitDataBank.read(event); | ||
| fill(hitDataBank, false); | ||
| } | ||
|
|
||
| /** | ||
| * Get an occupancy bank, normalized by number of events. | ||
| * @param events | ||
| * @param event | ||
| * @return | ||
| */ | ||
| public final DataBank create(long events, DataEvent event) { | ||
| DataBank b = event.createBank(occBank.getSchema().getName(), table.getRowCount()); | ||
| int i = 0; | ||
| Map<Long,IndexedEntry> m = table.getList().getMap(); | ||
| 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.setShort(j, i, (short)idx[j]); | ||
| else b.setByte(j, i, (byte)idx[j]); | ||
| } | ||
| b.setFloat(table.getList().getIndexSize(), i, ((float)m.get(hash).getValue(0).intValue())/events); | ||
| i++; | ||
| } | ||
| return b; | ||
| } | ||
|
|
||
| /** | ||
| * Get an occupancy bank, normalized by number of events. | ||
| * @param events | ||
| * @return | ||
| */ | ||
| public final Bank create(long events) { | ||
| Bank b = new Bank(occBank.getSchema(), table.getRowCount()); | ||
| int row = 0; | ||
| for (long hash : ((Map<Long,IndexedEntry>)table.getList().getMap()).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, row, (short)idx[j]); | ||
| else b.putByte(j, row, (byte)idx[j]); | ||
| } | ||
| b.putFloat(table.getList().getIndexSize(), row, (float)table.getDoubleValueByHash(0, hash)/events); | ||
| row++; | ||
| } | ||
| return b; | ||
| } | ||
|
|
||
| /** | ||
| * Utility for processing a bunch of occupancies. | ||
| */ | ||
| public static final class OccupanceDriver { | ||
| int events=0,prescale; | ||
| OccupanceTable[] tables; | ||
| public OccupanceDriver(SchemaFactory schema, int prescale) { | ||
| this.prescale = prescale; | ||
| tables = new OccupanceTable[] { | ||
| new OccupanceTable(schema,"DC::tot"), | ||
| new OccupanceTable(schema,"DC::tdc"), | ||
| new OccupanceTable(schema,"ECAL::adc"), | ||
| new OccupanceTable(schema,"ECAL::tdc"), | ||
| new OccupanceTable(schema,"FTOF::adc"), | ||
| new OccupanceTable(schema,"FTOF::tdc"), | ||
| new OccupanceTable(schema,"CTOF::adc"), | ||
| new OccupanceTable(schema,"CTOF::tdc"), | ||
| new OccupanceTable(schema,"HTCC::adc"), | ||
| new OccupanceTable(schema,"HTCC::tdc"), | ||
| new OccupanceTable(schema,"LTCC::adc"), | ||
| new OccupanceTable(schema,"LTCC::tdc"), | ||
| new OccupanceTable(schema,"BST::adc"), | ||
| new OccupanceTable(schema,"BMT::adc"), | ||
| new OccupanceTable(schema,"FTCAL::adc"), | ||
| new OccupanceTable(schema,"FTHODO::adc"), | ||
| new OccupanceTable(schema,"FTTRK::adc"), | ||
| new OccupanceTable(schema,"RICH::tdc"), | ||
| new OccupanceTable(schema,"BAND::adc"), | ||
| new OccupanceTable(schema,"BAND::tdc"), | ||
| }; | ||
| } | ||
| public void process(DataEvent event) { | ||
| for (OccupanceTable t : tables) t.fill(event); | ||
| write(event); | ||
| } | ||
| public void reset() { | ||
| for (OccupanceTable t : tables) t.reset(); | ||
| events = 0; | ||
| } | ||
| synchronized void write(DataEvent event) { | ||
| if (++events % prescale == 0) { | ||
| for (OccupanceTable t : tables) { | ||
| if (t.table.getRowCount() > 0) event.appendBank(t.create(events, event)); | ||
| t.reset(); | ||
| } | ||
| events = 0; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any way to avoid the DRY violation here, and read
occupancy.jsonsomehow?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That could surely be done.