Skip to content
Draft
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
Expand Up @@ -123,7 +123,8 @@ else if (seq != null) {
runScalerBank = ds.createRunBank(writer.getSchemaFactory());
helScalerBank = ds.createHelicityBank(writer.getSchemaFactory());

SerialUtil.assignScalerHelicity(event, helScalerBank, helSeq);
if(helSeq.getSequence(runConfigBank.getInt("run",0))!=null)
SerialUtil.assignScalerHelicity(runConfigBank.getLong("timestamp",0), helScalerBank, helSeq.getSequence(runConfigBank.getInt("run",0)));

// put modified HEL/RUN::scaler back in the event:
event.write(runScalerBank);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ public boolean getHalfWavePlate() {
return this.halfWavePlate;
}

public double getHelicityClock() {
return helicityClock;
}

/**
* Get the the number of states in the sequence.
* @return the number of states
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public class StruckScaler extends DaqScaler {
public HelicityBit getQuartet() { return this.quartet; }

// These slots corrspond to gated/ungated scalers in RAW::scaler.
public static final int NSLOT=2;
public static final int SLOT_GATED=0;
public static final int SLOT_UNGATED=1;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ else if (Input.equals(Input.CLOCK, chan)) {
break;
case StruckScaler.SLOT_UNGATED:
if (Input.equals(Input.FCUP, chan)) {
reading.helicity = HelicityBit.createFromRawBit(bank.getByte("helicity",k));
reading.quartet = HelicityBit.createFromRawBit(bank.getByte("quartet",k));
reading.fcup = bank.getLong("value",k);
}
else if (Input.equals(Input.SLM, chan)) {
Expand All @@ -115,6 +117,12 @@ else if (Input.equals(Input.CLOCK, chan)) {
break;
}
}

// ignore banks with more than the tegular 4 ( (tsettle+tstable) x (gated+ungated) ) readings
// or unbalance between gated/ungated readngs (allow difference by 1)
if(this.size()>(Interval.values().length-1)*StruckScaler.NSLOT ||
Math.abs(this.count(StruckScaler.SLOT_GATED)-count(StruckScaler.SLOT_UNGATED))>1)
this.clear();
}

/**
Expand Down Expand Up @@ -147,19 +155,50 @@ private void copyGate(int source, int destination) {
this.copyGate(this.get(source), this.get(destination));
}

/**
* Counts the number of raw readouts for the selected slot
* @param slot the index of the slot
* @return the number
**/
private int count(int slot) {
int n = 0;
for (StruckScaler ss : this) {
switch(slot) {
case StruckScaler.SLOT_GATED:
if(ss.gatedClock>=0 && ss.clock<0)
n++;
break;
case StruckScaler.SLOT_UNGATED:
if(ss.gatedClock<0 && ss.clock>=0)
n++;
break;
default:
break;
}
}
return n;
}


/**
* When there's one interval in a RAW::scaler bank, that interval is
* represented by (6) contiguous bank rows. But when there's multiple
* intervals, the gated/ungated are interspersed with another interval
* (and the ungated doesn't contain the helicity bit). Here we fix.
*/
private void disentangle() {
int n = Interval.values().length-1;
HashMap<StruckScaler,StruckScaler> d = new HashMap<>();
for (int ii=0; ii<this.size()-2; ii++) {
if (this.get(ii).interval != this.get(ii+2).interval) continue;
if (this.get(ii).clock<0 && this.get(ii+2).clock>0) {
if (this.get(ii).gatedClock>0 && this.get(ii+2).gatedClock<0) {
d.put(this.get(ii+2), this.get(ii));
for (int ii=0; ii<this.size()-n; ii++) {
if (this.get(ii).interval != this.get(ii+n).interval ||
this.get(ii).helicity != this.get(ii+n).helicity ||
this.get(ii).quartet != this.get(ii+n).quartet ) {
d.clear(); //give up on matching in case an anomaly is detected
return;
}
if (this.get(ii).clock<0 && this.get(ii+n).clock>0) {
if (this.get(ii).gatedClock>=0 && this.get(ii+n).gatedClock<0) {
d.put(this.get(ii+n), this.get(ii));
}
}
}
Expand Down Expand Up @@ -194,7 +233,7 @@ private void add() {
* @param interval the type of helicity interval to preserve
*/
private void strip(HelicityInterval interval) {
for (int ii=0; ii<this.size(); ii++) {
for (int ii=this.size()-1; ii>=0; ii--) {
if (this.get(ii).getHelicityInterval(this.helTable) != interval) {
this.remove(ii);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ public class SerialUtil {
* @param bank the HEL::scaler bank
* @param seq previously initialized helicity sequence
*/
@Deprecated
public static void assignScalerHelicity(Event event, Bank bank, HelicitySequenceManager seq) {

// Struck (helicity) scaler readout is always slightly after the helicity
// state change, i.e., as registered in the FADCs, so its true helicity
// is offset by one state from its event:
Expand Down Expand Up @@ -69,10 +70,12 @@ public static void assignScalerHelicity(Event event, Bank bank, HelicitySequence
*/
public static void assignScalerHelicity(Long timestamp, Bank bank, HelicitySequence seq) {

// Struck (helicity) scaler readout is always slightly after the helicity
// state change, i.e., as registered in the FADCs, so its true helicity
// is offset by one state from its event:
final int readoutStateOffset = -1;
// Struck (helicity) scaler readout is always after the helicity
// state change, so its true helicity is offset by one state from its event;
// to avoid ambiguities arising from whether the scaler bznk appears before
// the helicity change is registered in the FADCs, shift by half a state:
final int readoutTimestampOffset = (int) (-0.5 * HelicitySequence.TIMESTAMP_CLOCK
/ seq.getHelicityClock());

// Rows in the HEL::scaler bank correspond to the most recent, consecutive,
// time-ordered, T-stable intervals. The first row is the earliest in
Expand All @@ -81,14 +84,14 @@ public static void assignScalerHelicity(Long timestamp, Bank bank, HelicitySeque

// This is the helicity state offset for this HEL::scaler row, where
// the last row has an offset of -1:
final int offset = bank.getRows() - row - 1 + readoutStateOffset;
final int offset = bank.getRows() - row - 1;

// Assign delay-corrected helicity to this HEL::scaler row:
bank.putByte("helicity",row,seq.search(timestamp,offset).value());
bank.putByte("helicity",row,seq.search(timestamp+readoutTimestampOffset,offset).value());
if (seq.getHalfWavePlate())
bank.putByte("helicityRaw",0,(byte)(-1*seq.search(timestamp,offset).value()));
bank.putByte("helicityRaw",0,(byte)(-1*seq.search(timestamp+readoutTimestampOffset,offset).value()));
else
bank.putByte("helicityRaw",0,seq.search(timestamp,offset).value());
bank.putByte("helicityRaw",0,seq.search(timestamp+readoutTimestampOffset,offset).value());
}
}

Expand Down
Loading