Skip to content

Commit

Permalink
Merge pull request #406 from mpaolone/development
Browse files Browse the repository at this point in the history
Various ALERT updates
  • Loading branch information
baltzell authored Jan 2, 2025
2 parents 9fb1b2e + c251ca3 commit 90bf8b3
Show file tree
Hide file tree
Showing 38 changed files with 1,639 additions and 208 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@ public void setOrder(int order){
}
}

public int[] getCSC() {
return new int[]{hw_CRATE,hw_SLOT,hw_CHANNEL};
}

public int[] getSLCO() {
return new int[]{dt_SECTOR,dt_LAYER,dt_COMPONENT,dt_ORDER};
}

public DetectorType getType(){ return this.detectorType;}

public final void setType(DetectorType type){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.jlab.detector.helicity.HelicityBit;
import org.jlab.detector.helicity.HelicitySequence;
import org.jlab.detector.helicity.HelicityState;
import org.jlab.detector.pulse.ModeAHDC;

import org.jlab.logging.DefaultLogger;

Expand Down Expand Up @@ -46,7 +47,8 @@ public class CLASDecoder4 {
private HipoDataEvent hipoEvent = null;
private boolean isRunNumberFixed = false;
private int decoderDebugMode = 0;
private SchemaFactory schemaFactory = new SchemaFactory();
private SchemaFactory schemaFactory = new SchemaFactory();
private ModeAHDC ahdcExtractor = new ModeAHDC();

public CLASDecoder4(boolean development){
codaDecoder = new CodaEventDecoder();
Expand Down Expand Up @@ -245,6 +247,26 @@ public List<DetectorDataDgtz> getEntriesSCALER(DetectorType type,
return scaler;
}

public void extractPulses(Event event) {
ahdcExtractor.update(6, null, event, schemaFactory, "AHDC::wf", "AHDC::adc");
}

public Bank getDataBankWF(String name, DetectorType type) {
List<DetectorDataDgtz> a = this.getEntriesADC(type);
Bank b = new Bank(schemaFactory.getSchema(name), a.size());
for (int i=0; i<a.size(); ++i) {
b.putByte("sector", i, (byte) a.get(i).getDescriptor().getSector());
b.putByte("layer", i, (byte) a.get(i).getDescriptor().getLayer());
b.putShort("component", i, (short) a.get(i).getDescriptor().getComponent());
b.putByte("order", i, (byte) a.get(i).getDescriptor().getOrder());
b.putLong("timestamp", i, a.get(i).getADCData(0).getTimeStamp());
DetectorDataDgtz.ADCData xxx = a.get(i).getADCData(0);
for (int j=0; j<xxx.getPulseSize(); ++j)
b.putShort(String.format("s%d",j+1), i, xxx.getPulseValue(j));
}
return b;
}

public Bank getDataBankADC(String name, DetectorType type){

List<DetectorDataDgtz> adcDGTZ = this.getEntriesADC(type);
Expand Down Expand Up @@ -420,20 +442,20 @@ public Event getDataEvent(){

Event event = new Event();

String[] wfBankNames = new String[]{"AHDC::wf"};
DetectorType[] wfBankTypes = new DetectorType[]{DetectorType.AHDC};
String[] adcBankNames = new String[]{"FTOF::adc","ECAL::adc","FTCAL::adc",
"FTHODO::adc", "FTTRK::adc",
"HTCC::adc","BST::adc","CTOF::adc",
"CND::adc","LTCC::adc","BMT::adc",
"FMT::adc","HEL::adc","RF::adc",
"BAND::adc","RASTER::adc",
"AHDC::adc"};
"BAND::adc","RASTER::adc"};
DetectorType[] adcBankTypes = new DetectorType[]{DetectorType.FTOF,DetectorType.ECAL,DetectorType.FTCAL,
DetectorType.FTHODO,DetectorType.FTTRK,
DetectorType.HTCC,DetectorType.BST,DetectorType.CTOF,
DetectorType.CND,DetectorType.LTCC,DetectorType.BMT,
DetectorType.FMT,DetectorType.HEL,DetectorType.RF,
DetectorType.BAND, DetectorType.RASTER,
DetectorType.AHDC};
DetectorType.BAND, DetectorType.RASTER};

String[] tdcBankNames = new String[]{"FTOF::tdc","ECAL::tdc","DC::tdc",
"HTCC::tdc","LTCC::tdc","CTOF::tdc",
Expand All @@ -453,6 +475,13 @@ public Event getDataEvent(){
}
}

for(int i = 0; i < wfBankTypes.length; i++){
Bank wfBank = getDataBankWF(wfBankNames[i],wfBankTypes[i]);
if(wfBank!=null && wfBank.getRows()>0){
event.write(wfBank);
}
}

for(int i = 0; i < tdcBankTypes.length; i++){
Bank tdcBank = getDataBankTDC(tdcBankNames[i],tdcBankTypes[i]);
if(tdcBank!=null){
Expand Down Expand Up @@ -825,7 +854,9 @@ public static void main(String[] args){
decodedEvent.read(rawScaler);
decodedEvent.read(rawRunConf);
decodedEvent.read(helicityAdc);


decoder.extractPulses(decodedEvent);

helicityReadings.add(HelicityState.createFromFadcBank(helicityAdc, rawRunConf,
decoder.detectorDecoder.scalerManager));

Expand Down Expand Up @@ -867,4 +898,5 @@ public static void main(String[] args){

writer.close();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@

package org.jlab.detector.pulse;

import java.util.ArrayList;
import java.util.List;
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;

/**
* For now, a place to store standard boilerplate for waveform/pulse HIPO
* manipulations. No bounds checking regarding number of samples.
*
* Here an IndexedTable object from CCDB is used to pass initialization parameters
* to the extractor. If that object is null, the @{link org.jlab.detector.pulse.IExtractor.extract}
* method should know what to do, e.g., hardcoded, channel-independent parameters.
*
* FIXME: Passing the #samples around is obviously bad, and there's probably a
* few non-horrible ways that can be addressed without changing bank format.
*
* @author baltzell
*/
public abstract class HipoExtractor implements IExtractor {

/**
* @param n number of samples in readout
* @param it CCDB table containing extraction initialization parameters
* @param event the event to modify
* @param schema bank schema factory
* @param wfBankName name of the input waveform bank
* @param adcBankName name of the output ADC bank
*/
public void update(int n, IndexedTable it, Event event, SchemaFactory schema, String wfBankName, String adcBankName) {
Bank wf = new Bank(schema.getSchema(wfBankName));
event.read(wf);
if (wf.getRows() > 0) {
Bank adc = new Bank(schema.getSchema(adcBankName));
update(n, it, wf, adc);
event.remove(schema.getSchema(adcBankName));
if (adc.getRows() > 0) event.write(adc);
}
}

/**
* This could be overriden, e.g., for non-standard ADC banks.
* @param n number of samples in readout
* @param it CCDB table containing extraction initialization parameters
* @param event the event to modify
* @param wfBankName name of the input waveform bank
* @param adcBankName name of the output ADC bank
*/
public void update(int n, IndexedTable it, DataEvent event, String wfBankName, String adcBankName) {
DataBank wf = event.getBank(wfBankName);
if (wf.rows() > 0) {
event.removeBank(adcBankName);
List<Pulse> pulses = getPulses(n, it, wf);
if (pulses != null && !pulses.isEmpty()) {
DataBank adc = event.createBank(adcBankName, pulses.size());
for (int i=0; i<pulses.size(); ++i) {
copyIndices(wf, adc, i, i);
adc.setInt("ADC", i, (int)pulses.get(i).integral);
adc.setFloat("time", i, pulses.get(i).time);
}
event.appendBank(adc);
}
}
}

/**
* This could be overriden, e.g., for non-standard ADC banks.
* @param n number of samples in readout
* @param it CCDB table containing extraction initialization parameters
* @param wfBank input waveform bank
* @param adcBank output ADC bank
*/
protected void update(int n, IndexedTable it, Bank wfBank, Bank adcBank) {
if (wfBank.getRows() > 0) {
List<Pulse> pulses = getPulses(n, it, wfBank);
adcBank.reset();
adcBank.setRows(pulses!=null ? pulses.size() : 0);
if (pulses!=null && !pulses.isEmpty()) {
for (int i=0; i<pulses.size(); ++i) {
copyIndices(wfBank, adcBank, pulses.get(i).id, i);
adcBank.putInt("ADC", i, (int)pulses.get(i).integral);
adcBank.putFloat("time", i, pulses.get(i).time);
}
}
}
}

private static void copyIndices(Bank src, Bank dest, int isrc, int idest) {
dest.putByte("sector", idest, src.getByte("sector",isrc));
dest.putByte("layer", idest, src.getByte("layer",isrc));
dest.putShort("component", idest, src.getShort("component",isrc));
dest.putByte("order", idest, src.getByte("order",isrc));
dest.putShort("id", idest, (short)isrc);
}

private static void copyIndices(DataBank src, DataBank dest, int isrc, int idest) {
dest.setByte("sector", idest, src.getByte("sector",isrc));
dest.setByte("layer", idest, src.getByte("layer",isrc));
dest.setShort("component", idest, src.getShort("component",isrc));
dest.setByte("order", idest, src.getByte("order",isrc));
dest.setShort("id", idest, (short)isrc);
}

private static int[] getIndices(Bank bank, int row) {
return new int[] {
bank.getShort("sector", row),
bank.getShort("layer", row),
bank.getShort("component", row),
bank.getShort("order", row)};
}

private static int[] getIndices(DataBank bank, int row) {
return new int[] {
bank.getShort("sector", row),
bank.getShort("layer", row),
bank.getShort("component", row),
bank.getShort("order", row)};
}

private List<Pulse> getPulses(int n, IndexedTable it, DataBank wfBank) {
List<Pulse> pulses = null;
short[] samples = new short[n];
for (int i=0; i<wfBank.rows(); ++i) {
for (int j=0; j<n; ++j)
samples[j] = wfBank.getShort(String.format("s%d",j+1), i);
List<Pulse> p = it==null ? extract(null, i, samples) :
extract(it.getNamedEntry(getIndices(wfBank,i)), i, samples);
if (p!=null && !p.isEmpty()) {
if (pulses == null) pulses = new ArrayList<>();
pulses.addAll(p);
}
}
return pulses;
}

private List<Pulse> getPulses(int n, IndexedTable it, Bank wfBank) {
List<Pulse> pulses = null;
short[] samples = new short[n];
for (int i=0; i<wfBank.getRows(); ++i) {
for (int j=0; j<n; ++j)
samples[j] = wfBank.getShort(String.format("s%d",j+1), i);
// FIXME: Can speed this up (but looks like not for DataBank?):
//samples[j] = wfBank.getShort(String.format(5+j,j+1), i);
List p = it==null ? extract(null, i, samples) :
extract(it.getNamedEntry(getIndices(wfBank,i)), i, samples);
if (p!=null && !p.isEmpty()) {
if (pulses == null) pulses = new ArrayList<>();
pulses.addAll(p);
}
}
return pulses;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.jlab.detector.pulse;

import java.util.List;
import org.jlab.utils.groups.NamedEntry;

public interface IExtractor <T> {

public List<T> extract(NamedEntry pars, int id, short... samples);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package org.jlab.detector.pulse;

import java.util.ArrayList;
import java.util.List;
import org.jlab.utils.groups.NamedEntry;

/**
* Similar to a FADC250 Mode-3 pulse extraction.
*
* @author baltzell
*/
public class Mode3 extends HipoExtractor {

// Fixed extraction parameters:
final double ped = 2000;
final double tet = 2000;
final int nsa = 30;
final int nsb = 5;

/**
* @param pars CCDB row
* @param id link to row in source bank
* @param samples ADC samples
* @return extracted pulses
*/
@Override
public List<Pulse> extract(NamedEntry pars, int id, short... samples) {

List<Pulse> pulses = null;

/*
// Retrive extraction parameters from a CCDB table:
double ped = pars.getValue("ped").doubleValue();
double tet = pars.getValue("tet").doubleValue();
int nsa = pars.getValue("nsa").intValue();
int nsb = pars.getValue("nsb").intValue();
*/

// Perform the extraction:
for (int i=0; i<samples.length-1; ++i) {
// Check for threshold crossing:
if (samples[i] > ped+tet && samples[i+1] > samples[i]) {
int n = 0;
float integral = 0;
// Integrate the pulse:
for (int j=i-nsb; j<=i+nsa; ++j) {
if (j<0) continue;
if (j>=samples.length) break;
integral += samples[j];
n++;
}
integral -= n * ped;
Pulse p = new Pulse(integral, i, 0x0, id);
p.pedestal = (float)(ped);
// Add the new pulse to the list:
if (pulses == null) pulses = new ArrayList<>();
pulses.add(p);
// Add a holdoff time before next possible pulse:
i += nsa;
}
}
return pulses;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package org.jlab.detector.pulse;

import java.util.List;
import org.jlab.utils.groups.NamedEntry;

/**
* Similar to a Mode-7 FADC250 pulse extraction.
*
* @author baltzell
*/
public class Mode7 extends Mode3 {

/**
* @param t0 threshold-crossing sample index
* @param ped pedestal (for calculating pulse half-height)
* @param samples
* @return pulse time
*/
private static float calculateTime(int t0, float ped, short... samples) {
for (int j=t0+1; j<samples.length; ++j) {
if (samples[j] < samples[j-1]) {
float slope = (samples[j-1]-ped) / (j-t0);
float offset = samples[j-1] - (j-1)*slope;
return (samples[j-1]/2 - offset) / slope;
}
}
// Fall back to Mode-3 time:
return t0;
}

@Override
public List<Pulse> extract(NamedEntry pars, int id, short... samples) {
List<Pulse> pulses = super.extract(pars, id, samples);
for (Pulse p : pulses)
p.time = calculateTime((int)p.time, p.pedestal, samples);
return pulses;
}

}
Loading

0 comments on commit 90bf8b3

Please sign in to comment.