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 @@ -158,6 +158,24 @@ protected final int searchIndex(long timestamp) {
final int n = index<0 ? -index-2 : index;
return n;
}

/**
* Get the state index of a TI timestamp, based on the closest timestamp
* within the measured sequence.
* This returns invalid (-1) if the timestamp is not contained within
* the range of measured states.
* @param timestamp TI timestamp (i.e. RUN::config.timestamp)
* @return index
*/
protected final int findClosestIndex(long timestamp) {
int index = this.searchIndex(timestamp);
if(index<0 || index==this.size()-1)
return -1;
if(timestamp<(this.getTimestamp(index)+this.getTimestamp(index+1))/2)
return index;
else
return index+1;
}

/**
* Get the state index of a TI timestamp, based only on the first measured
Expand Down Expand Up @@ -224,9 +242,21 @@ public HelicityBit search(long timestamp) {
* @return the helicity state, null if timestamp is outside of measured range
*/
public HelicityBit search(long timestamp,int offset) {
final int index = this.searchIndex(timestamp)+offset;
final int index = this.searchIndex(timestamp);
if (index < 0) return HelicityBit.UDF;
else return this.get(index+offset);
}

/**
* Find the state corresponding to a given timestamp in the measured sequence.
* @param timestamp TI timestamp (i.e. RUN::config.timestamp)
* @param offset number of states offset
* @return the helicity state, null if timestamp is outside of measured range
*/
public HelicityBit findClosest(long timestamp,int offset) {
final int index = this.findClosestIndex(timestamp);
if (index < 0) return HelicityBit.UDF;
else return this.getState(index).getHelicity();
else return this.get(index+offset);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,27 @@ public HelicityBit search(long timestamp) {
* @return the helicity bit
*/
public HelicityBit search(long timestamp,int offset) {
return this.get(super.searchIndex(timestamp)+offset);
int index = super.searchIndex(timestamp);
if(index>0)
return this.get(index+offset);
else
return HelicityBit.UDF;
}

/**
* Get the delay-corrected state of a TI timestamp by finding the closest
* timestamp in the measured sequence
*
* @param timestamp TI-timestamp (i.e. RUN::config.timestamp)
* @param offset number of states offset
* @return the helicity bit
*/
public HelicityBit findClosest(long timestamp,int offset) {
int index = super.findClosestIndex(timestamp);
if(index>0)
return this.get(index+offset);
else
return HelicityBit.UDF;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,28 @@ public HelicityBit search(Event event,int offset) {
return this.search(rcfgBank.getInt("run",0),rcfgBank.getLong("timestamp",0),offset);
}

/**
* @param runno run number
* @param timestamp TI timestamp
* @param offset number of states offset
* @return helicity for given run number and timestamp plus offset
*/
public HelicityBit findClosest(int runno, long timestamp,int offset) {
if (seqMap.containsKey(runno)) return seqMap.get(runno).findClosest(timestamp,offset);
return HelicityBit.UDF;
}

/**
* @param event HIPO event
* @param offset number of states offset
* @return helicity for given event plus offset
*/
public HelicityBit findClosest(Event event,int offset) {
event.read(this.rcfgBank);
if (rcfgBank.getRows()<1) return HelicityBit.UDF;
return this.findClosest(rcfgBank.getInt("run",0),rcfgBank.getLong("timestamp",0),offset);
}

public HelicityBit predictGenerated(int runno, long timestamp) {
if (seqMap.containsKey(runno)) return seqMap.get(runno).predictGenerated(timestamp);
return HelicityBit.UDF;
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,6 +155,31 @@ 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 nslot = 0;
for (StruckScaler ss : this) {
switch(slot) {
case StruckScaler.SLOT_GATED:
if(ss.gatedClock>=0 && ss.clock<0)
nslot++;
break;
case StruckScaler.SLOT_UNGATED:
if(ss.gatedClock<0 && ss.clock>=0)
nslot++;
break;
default:
break;
}
}
return nslot;
}


/**
* When there's one interval in a RAW::scaler bank, that interval is
* represented by (6) contiguous bank rows. But when there's multiple
Expand All @@ -156,9 +189,14 @@ private void copyGate(int source, int destination) {
private void disentangle() {
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).interval != this.get(ii+2).interval ||
this.get(ii).helicity != this.get(ii+2).helicity ||
this.get(ii).quartet != this.get(ii+2).quartet ) {
d.clear(); //give up on matching in case an anomaly is detected
return;
}
if (this.get(ii).clock<0 && this.get(ii+2).clock>0) {
if (this.get(ii).gatedClock>0 && this.get(ii+2).gatedClock<0) {
if (this.get(ii).gatedClock>=0 && this.get(ii+2).gatedClock<0) {
d.put(this.get(ii+2), this.get(ii));
}
}
Expand Down Expand Up @@ -194,7 +232,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 @@ -53,11 +53,11 @@ public static void assignScalerHelicity(Event event, Bank bank, HelicitySequence
final int offset = bank.getRows() - row - 1 + readoutStateOffset;

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

Expand All @@ -84,11 +84,11 @@ public static void assignScalerHelicity(Long timestamp, Bank bank, HelicitySeque
final int offset = bank.getRows() - row - 1 + readoutStateOffset;

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

Expand Down
Loading