Skip to content

Commit 90bf8b3

Browse files
authored
Merge pull request #406 from mpaolone/development
Various ALERT updates
2 parents 9fb1b2e + c251ca3 commit 90bf8b3

File tree

38 files changed

+1639
-208
lines changed

38 files changed

+1639
-208
lines changed

common-tools/clas-detector/src/main/java/org/jlab/detector/base/DetectorDescriptor.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,14 @@ public void setOrder(int order){
6464
}
6565
}
6666

67+
public int[] getCSC() {
68+
return new int[]{hw_CRATE,hw_SLOT,hw_CHANNEL};
69+
}
70+
71+
public int[] getSLCO() {
72+
return new int[]{dt_SECTOR,dt_LAYER,dt_COMPONENT,dt_ORDER};
73+
}
74+
6775
public DetectorType getType(){ return this.detectorType;}
6876

6977
public final void setType(DetectorType type){

common-tools/clas-detector/src/main/java/org/jlab/detector/decode/CLASDecoder4.java

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import org.jlab.detector.helicity.HelicityBit;
1515
import org.jlab.detector.helicity.HelicitySequence;
1616
import org.jlab.detector.helicity.HelicityState;
17+
import org.jlab.detector.pulse.ModeAHDC;
1718

1819
import org.jlab.logging.DefaultLogger;
1920

@@ -46,7 +47,8 @@ public class CLASDecoder4 {
4647
private HipoDataEvent hipoEvent = null;
4748
private boolean isRunNumberFixed = false;
4849
private int decoderDebugMode = 0;
49-
private SchemaFactory schemaFactory = new SchemaFactory();
50+
private SchemaFactory schemaFactory = new SchemaFactory();
51+
private ModeAHDC ahdcExtractor = new ModeAHDC();
5052

5153
public CLASDecoder4(boolean development){
5254
codaDecoder = new CodaEventDecoder();
@@ -245,6 +247,26 @@ public List<DetectorDataDgtz> getEntriesSCALER(DetectorType type,
245247
return scaler;
246248
}
247249

250+
public void extractPulses(Event event) {
251+
ahdcExtractor.update(6, null, event, schemaFactory, "AHDC::wf", "AHDC::adc");
252+
}
253+
254+
public Bank getDataBankWF(String name, DetectorType type) {
255+
List<DetectorDataDgtz> a = this.getEntriesADC(type);
256+
Bank b = new Bank(schemaFactory.getSchema(name), a.size());
257+
for (int i=0; i<a.size(); ++i) {
258+
b.putByte("sector", i, (byte) a.get(i).getDescriptor().getSector());
259+
b.putByte("layer", i, (byte) a.get(i).getDescriptor().getLayer());
260+
b.putShort("component", i, (short) a.get(i).getDescriptor().getComponent());
261+
b.putByte("order", i, (byte) a.get(i).getDescriptor().getOrder());
262+
b.putLong("timestamp", i, a.get(i).getADCData(0).getTimeStamp());
263+
DetectorDataDgtz.ADCData xxx = a.get(i).getADCData(0);
264+
for (int j=0; j<xxx.getPulseSize(); ++j)
265+
b.putShort(String.format("s%d",j+1), i, xxx.getPulseValue(j));
266+
}
267+
return b;
268+
}
269+
248270
public Bank getDataBankADC(String name, DetectorType type){
249271

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

421443
Event event = new Event();
422444

445+
String[] wfBankNames = new String[]{"AHDC::wf"};
446+
DetectorType[] wfBankTypes = new DetectorType[]{DetectorType.AHDC};
423447
String[] adcBankNames = new String[]{"FTOF::adc","ECAL::adc","FTCAL::adc",
424448
"FTHODO::adc", "FTTRK::adc",
425449
"HTCC::adc","BST::adc","CTOF::adc",
426450
"CND::adc","LTCC::adc","BMT::adc",
427451
"FMT::adc","HEL::adc","RF::adc",
428-
"BAND::adc","RASTER::adc",
429-
"AHDC::adc"};
452+
"BAND::adc","RASTER::adc"};
430453
DetectorType[] adcBankTypes = new DetectorType[]{DetectorType.FTOF,DetectorType.ECAL,DetectorType.FTCAL,
431454
DetectorType.FTHODO,DetectorType.FTTRK,
432455
DetectorType.HTCC,DetectorType.BST,DetectorType.CTOF,
433456
DetectorType.CND,DetectorType.LTCC,DetectorType.BMT,
434457
DetectorType.FMT,DetectorType.HEL,DetectorType.RF,
435-
DetectorType.BAND, DetectorType.RASTER,
436-
DetectorType.AHDC};
458+
DetectorType.BAND, DetectorType.RASTER};
437459

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

478+
for(int i = 0; i < wfBankTypes.length; i++){
479+
Bank wfBank = getDataBankWF(wfBankNames[i],wfBankTypes[i]);
480+
if(wfBank!=null && wfBank.getRows()>0){
481+
event.write(wfBank);
482+
}
483+
}
484+
456485
for(int i = 0; i < tdcBankTypes.length; i++){
457486
Bank tdcBank = getDataBankTDC(tdcBankNames[i],tdcBankTypes[i]);
458487
if(tdcBank!=null){
@@ -825,7 +854,9 @@ public static void main(String[] args){
825854
decodedEvent.read(rawScaler);
826855
decodedEvent.read(rawRunConf);
827856
decodedEvent.read(helicityAdc);
828-
857+
858+
decoder.extractPulses(decodedEvent);
859+
829860
helicityReadings.add(HelicityState.createFromFadcBank(helicityAdc, rawRunConf,
830861
decoder.detectorDecoder.scalerManager));
831862

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

868899
writer.close();
869900
}
901+
870902
}
Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
2+
package org.jlab.detector.pulse;
3+
4+
import java.util.ArrayList;
5+
import java.util.List;
6+
import org.jlab.io.base.DataBank;
7+
import org.jlab.io.base.DataEvent;
8+
import org.jlab.jnp.hipo4.data.Bank;
9+
import org.jlab.jnp.hipo4.data.Event;
10+
import org.jlab.jnp.hipo4.data.SchemaFactory;
11+
import org.jlab.utils.groups.IndexedTable;
12+
13+
/**
14+
* For now, a place to store standard boilerplate for waveform/pulse HIPO
15+
* manipulations. No bounds checking regarding number of samples.
16+
*
17+
* Here an IndexedTable object from CCDB is used to pass initialization parameters
18+
* to the extractor. If that object is null, the @{link org.jlab.detector.pulse.IExtractor.extract}
19+
* method should know what to do, e.g., hardcoded, channel-independent parameters.
20+
*
21+
* FIXME: Passing the #samples around is obviously bad, and there's probably a
22+
* few non-horrible ways that can be addressed without changing bank format.
23+
*
24+
* @author baltzell
25+
*/
26+
public abstract class HipoExtractor implements IExtractor {
27+
28+
/**
29+
* @param n number of samples in readout
30+
* @param it CCDB table containing extraction initialization parameters
31+
* @param event the event to modify
32+
* @param schema bank schema factory
33+
* @param wfBankName name of the input waveform bank
34+
* @param adcBankName name of the output ADC bank
35+
*/
36+
public void update(int n, IndexedTable it, Event event, SchemaFactory schema, String wfBankName, String adcBankName) {
37+
Bank wf = new Bank(schema.getSchema(wfBankName));
38+
event.read(wf);
39+
if (wf.getRows() > 0) {
40+
Bank adc = new Bank(schema.getSchema(adcBankName));
41+
update(n, it, wf, adc);
42+
event.remove(schema.getSchema(adcBankName));
43+
if (adc.getRows() > 0) event.write(adc);
44+
}
45+
}
46+
47+
/**
48+
* This could be overriden, e.g., for non-standard ADC banks.
49+
* @param n number of samples in readout
50+
* @param it CCDB table containing extraction initialization parameters
51+
* @param event the event to modify
52+
* @param wfBankName name of the input waveform bank
53+
* @param adcBankName name of the output ADC bank
54+
*/
55+
public void update(int n, IndexedTable it, DataEvent event, String wfBankName, String adcBankName) {
56+
DataBank wf = event.getBank(wfBankName);
57+
if (wf.rows() > 0) {
58+
event.removeBank(adcBankName);
59+
List<Pulse> pulses = getPulses(n, it, wf);
60+
if (pulses != null && !pulses.isEmpty()) {
61+
DataBank adc = event.createBank(adcBankName, pulses.size());
62+
for (int i=0; i<pulses.size(); ++i) {
63+
copyIndices(wf, adc, i, i);
64+
adc.setInt("ADC", i, (int)pulses.get(i).integral);
65+
adc.setFloat("time", i, pulses.get(i).time);
66+
}
67+
event.appendBank(adc);
68+
}
69+
}
70+
}
71+
72+
/**
73+
* This could be overriden, e.g., for non-standard ADC banks.
74+
* @param n number of samples in readout
75+
* @param it CCDB table containing extraction initialization parameters
76+
* @param wfBank input waveform bank
77+
* @param adcBank output ADC bank
78+
*/
79+
protected void update(int n, IndexedTable it, Bank wfBank, Bank adcBank) {
80+
if (wfBank.getRows() > 0) {
81+
List<Pulse> pulses = getPulses(n, it, wfBank);
82+
adcBank.reset();
83+
adcBank.setRows(pulses!=null ? pulses.size() : 0);
84+
if (pulses!=null && !pulses.isEmpty()) {
85+
for (int i=0; i<pulses.size(); ++i) {
86+
copyIndices(wfBank, adcBank, pulses.get(i).id, i);
87+
adcBank.putInt("ADC", i, (int)pulses.get(i).integral);
88+
adcBank.putFloat("time", i, pulses.get(i).time);
89+
}
90+
}
91+
}
92+
}
93+
94+
private static void copyIndices(Bank src, Bank dest, int isrc, int idest) {
95+
dest.putByte("sector", idest, src.getByte("sector",isrc));
96+
dest.putByte("layer", idest, src.getByte("layer",isrc));
97+
dest.putShort("component", idest, src.getShort("component",isrc));
98+
dest.putByte("order", idest, src.getByte("order",isrc));
99+
dest.putShort("id", idest, (short)isrc);
100+
}
101+
102+
private static void copyIndices(DataBank src, DataBank dest, int isrc, int idest) {
103+
dest.setByte("sector", idest, src.getByte("sector",isrc));
104+
dest.setByte("layer", idest, src.getByte("layer",isrc));
105+
dest.setShort("component", idest, src.getShort("component",isrc));
106+
dest.setByte("order", idest, src.getByte("order",isrc));
107+
dest.setShort("id", idest, (short)isrc);
108+
}
109+
110+
private static int[] getIndices(Bank bank, int row) {
111+
return new int[] {
112+
bank.getShort("sector", row),
113+
bank.getShort("layer", row),
114+
bank.getShort("component", row),
115+
bank.getShort("order", row)};
116+
}
117+
118+
private static int[] getIndices(DataBank bank, int row) {
119+
return new int[] {
120+
bank.getShort("sector", row),
121+
bank.getShort("layer", row),
122+
bank.getShort("component", row),
123+
bank.getShort("order", row)};
124+
}
125+
126+
private List<Pulse> getPulses(int n, IndexedTable it, DataBank wfBank) {
127+
List<Pulse> pulses = null;
128+
short[] samples = new short[n];
129+
for (int i=0; i<wfBank.rows(); ++i) {
130+
for (int j=0; j<n; ++j)
131+
samples[j] = wfBank.getShort(String.format("s%d",j+1), i);
132+
List<Pulse> p = it==null ? extract(null, i, samples) :
133+
extract(it.getNamedEntry(getIndices(wfBank,i)), i, samples);
134+
if (p!=null && !p.isEmpty()) {
135+
if (pulses == null) pulses = new ArrayList<>();
136+
pulses.addAll(p);
137+
}
138+
}
139+
return pulses;
140+
}
141+
142+
private List<Pulse> getPulses(int n, IndexedTable it, Bank wfBank) {
143+
List<Pulse> pulses = null;
144+
short[] samples = new short[n];
145+
for (int i=0; i<wfBank.getRows(); ++i) {
146+
for (int j=0; j<n; ++j)
147+
samples[j] = wfBank.getShort(String.format("s%d",j+1), i);
148+
// FIXME: Can speed this up (but looks like not for DataBank?):
149+
//samples[j] = wfBank.getShort(String.format(5+j,j+1), i);
150+
List p = it==null ? extract(null, i, samples) :
151+
extract(it.getNamedEntry(getIndices(wfBank,i)), i, samples);
152+
if (p!=null && !p.isEmpty()) {
153+
if (pulses == null) pulses = new ArrayList<>();
154+
pulses.addAll(p);
155+
}
156+
}
157+
return pulses;
158+
}
159+
160+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package org.jlab.detector.pulse;
2+
3+
import java.util.List;
4+
import org.jlab.utils.groups.NamedEntry;
5+
6+
public interface IExtractor <T> {
7+
8+
public List<T> extract(NamedEntry pars, int id, short... samples);
9+
10+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package org.jlab.detector.pulse;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
import org.jlab.utils.groups.NamedEntry;
6+
7+
/**
8+
* Similar to a FADC250 Mode-3 pulse extraction.
9+
*
10+
* @author baltzell
11+
*/
12+
public class Mode3 extends HipoExtractor {
13+
14+
// Fixed extraction parameters:
15+
final double ped = 2000;
16+
final double tet = 2000;
17+
final int nsa = 30;
18+
final int nsb = 5;
19+
20+
/**
21+
* @param pars CCDB row
22+
* @param id link to row in source bank
23+
* @param samples ADC samples
24+
* @return extracted pulses
25+
*/
26+
@Override
27+
public List<Pulse> extract(NamedEntry pars, int id, short... samples) {
28+
29+
List<Pulse> pulses = null;
30+
31+
/*
32+
// Retrive extraction parameters from a CCDB table:
33+
double ped = pars.getValue("ped").doubleValue();
34+
double tet = pars.getValue("tet").doubleValue();
35+
int nsa = pars.getValue("nsa").intValue();
36+
int nsb = pars.getValue("nsb").intValue();
37+
*/
38+
39+
// Perform the extraction:
40+
for (int i=0; i<samples.length-1; ++i) {
41+
// Check for threshold crossing:
42+
if (samples[i] > ped+tet && samples[i+1] > samples[i]) {
43+
int n = 0;
44+
float integral = 0;
45+
// Integrate the pulse:
46+
for (int j=i-nsb; j<=i+nsa; ++j) {
47+
if (j<0) continue;
48+
if (j>=samples.length) break;
49+
integral += samples[j];
50+
n++;
51+
}
52+
integral -= n * ped;
53+
Pulse p = new Pulse(integral, i, 0x0, id);
54+
p.pedestal = (float)(ped);
55+
// Add the new pulse to the list:
56+
if (pulses == null) pulses = new ArrayList<>();
57+
pulses.add(p);
58+
// Add a holdoff time before next possible pulse:
59+
i += nsa;
60+
}
61+
}
62+
return pulses;
63+
}
64+
65+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package org.jlab.detector.pulse;
2+
3+
import java.util.List;
4+
import org.jlab.utils.groups.NamedEntry;
5+
6+
/**
7+
* Similar to a Mode-7 FADC250 pulse extraction.
8+
*
9+
* @author baltzell
10+
*/
11+
public class Mode7 extends Mode3 {
12+
13+
/**
14+
* @param t0 threshold-crossing sample index
15+
* @param ped pedestal (for calculating pulse half-height)
16+
* @param samples
17+
* @return pulse time
18+
*/
19+
private static float calculateTime(int t0, float ped, short... samples) {
20+
for (int j=t0+1; j<samples.length; ++j) {
21+
if (samples[j] < samples[j-1]) {
22+
float slope = (samples[j-1]-ped) / (j-t0);
23+
float offset = samples[j-1] - (j-1)*slope;
24+
return (samples[j-1]/2 - offset) / slope;
25+
}
26+
}
27+
// Fall back to Mode-3 time:
28+
return t0;
29+
}
30+
31+
@Override
32+
public List<Pulse> extract(NamedEntry pars, int id, short... samples) {
33+
List<Pulse> pulses = super.extract(pars, id, samples);
34+
for (Pulse p : pulses)
35+
p.time = calculateTime((int)p.time, p.pedestal, samples);
36+
return pulses;
37+
}
38+
39+
}

0 commit comments

Comments
 (0)