Skip to content
Closed
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 @@ -4,6 +4,7 @@
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import org.jlab.detector.banks.RawBank.OrderType;
Expand All @@ -22,14 +23,11 @@ public class DetectorEventDecoder {
ConstantsManager fitterManager = new ConstantsManager();
ConstantsManager scalerManager = new ConstantsManager();

List<String> tablesTrans = null;
List<String> tablesFitter = null;

List<DetectorType> keysTrans = null;
List<DetectorType> keysFitter = null;
List<DetectorType> keysFilter = null;
List<DetectorType> keysMicromega= null;

HashSet<DetectorType> keysFilter;
HashSet<DetectorType> keysMicromega;
HashMap<DetectorType,String> translations;
HashMap<DetectorType,String> fitters;

private int runNumber = 10;

private ExtendedFADCFitter extendedFitter = new ExtendedFADCFitter();
Expand All @@ -38,11 +36,7 @@ public class DetectorEventDecoder {
private TranslationTable translator = new TranslationTable();

public DetectorEventDecoder(boolean development){
if(development==true){
this.initDecoderDev();
} else {
this.initDecoder();
}
this.initDecoder();
}

public void setTimestamp(String timestamp) {
Expand All @@ -60,8 +54,9 @@ public void setVariation(String variation) {
public void setRunNumber(int run){
if (run != this.runNumber) {
translator = new TranslationTable();
for (int i=0; i<keysTrans.size(); i++)
translator.add(keysTrans.get(i), translationManager.getConstants(run, tablesTrans.get(i)));
for (DetectorType t : translations.keySet()) {
translator.add(t, translationManager.getConstants(run, translations.get(t)));
}
}
this.runNumber = run;
}
Expand All @@ -84,62 +79,73 @@ public DetectorEventDecoder(){
this.initDecoder();
}

public final void initDecoderDev(){
keysTrans = Arrays.asList(new DetectorType[]{ DetectorType.HTCC,DetectorType.BST,DetectorType.RTPC} );
tablesTrans = Arrays.asList(new String[]{ "/daq/tt/clasdev/htcc","/daq/tt/clasdev/svt","/daq/tt/clasdev/rtpc" });
keysFitter = Arrays.asList(new DetectorType[]{DetectorType.HTCC});
tablesFitter = Arrays.asList(new String[]{"/daq/fadc/clasdev/htcc"});
translationManager.init(tablesTrans);
fitterManager.init(tablesFitter);
scalerManager.init(Arrays.asList(new String[]{"/runcontrol/fcup","/runcontrol/slm","/runcontrol/hwp",
"/runcontrol/helicity","/daq/config/scalers/dsc1"}));
}

public final void initDecoder(){

// Detector translation table
keysTrans = Arrays.asList(new DetectorType[]{DetectorType.FTCAL,DetectorType.FTHODO,DetectorType.FTTRK,DetectorType.LTCC,DetectorType.ECAL,DetectorType.FTOF,
DetectorType.HTCC,DetectorType.DC,DetectorType.CTOF,DetectorType.CND,DetectorType.BST,DetectorType.RF,DetectorType.BMT,DetectorType.FMT,
DetectorType.RICH,DetectorType.HEL,DetectorType.BAND,DetectorType.RTPC,
DetectorType.RASTER,DetectorType.ATOF,DetectorType.AHDC
});
tablesTrans = Arrays.asList(new String[]{
"/daq/tt/ftcal","/daq/tt/fthodo","/daq/tt/fttrk","/daq/tt/ltcc",
"/daq/tt/ec","/daq/tt/ftof","/daq/tt/htcc","/daq/tt/dc","/daq/tt/ctof","/daq/tt/cnd","/daq/tt/svt",
"/daq/tt/rf","/daq/tt/bmt","/daq/tt/fmt","/daq/tt/rich2","/daq/tt/hel","/daq/tt/band","/daq/tt/rtpc",
"/daq/tt/raster","/daq/tt/atof","/daq/tt/ahdc"
});
translationManager.init(tablesTrans);
keysFilter = new HashSet<>();
keysMicromega= new HashSet<>();
translations = new HashMap<>();
fitters = new HashMap<>();

translations.put(DetectorType.FTCAL, "/daq/tt/ftcal");
translations.put(DetectorType.FTHODO, "/daq/tt/fthodo");
translations.put(DetectorType.FTTRK, "/daq/tt/fttrk");
translations.put(DetectorType.LTCC, "/daq/tt/ltcc");
translations.put(DetectorType.ECAL, "/daq/tt/ec");
translations.put(DetectorType.FTOF, "/daq/tt/ftof");
translations.put(DetectorType.HTCC, "/daq/tt/htcc");
translations.put(DetectorType.DC, "/daq/tt/dc");
translations.put(DetectorType.CTOF, "/daq/tt/ctof");
translations.put(DetectorType.CND, "/daq/tt/cnd");
translations.put(DetectorType.BST, "/daq/tt/svt");
translations.put(DetectorType.RF, "/daq/tt/rf");
translations.put(DetectorType.BMT, "/daq/tt/bmt");
translations.put(DetectorType.FMT, "/daq/tt/fmt");
translations.put(DetectorType.RICH, "/daq/tt/rich2");
translations.put(DetectorType.HEL, "/daq/tt/hel");
translations.put(DetectorType.BAND, "/daq/tt/band");
translations.put(DetectorType.RTPC, "/daq/tt/rtpc");
translations.put(DetectorType.RASTER, "/daq/tt/raster");
translations.put(DetectorType.ATOF, "/daq/tt/atof");
translations.put(DetectorType.AHDC, "/daq/tt/ahdc");

// ADC waveform fitter translation table
keysFitter = Arrays.asList(new DetectorType[]{DetectorType.FTCAL,DetectorType.FTHODO,DetectorType.FTTRK,DetectorType.FTOF,DetectorType.LTCC,
DetectorType.ECAL,DetectorType.HTCC,DetectorType.CTOF,DetectorType.CND,DetectorType.BMT,
DetectorType.FMT,DetectorType.HEL,DetectorType.RF,DetectorType.BAND,DetectorType.RASTER,
DetectorType.AHDC});
tablesFitter = Arrays.asList(new String[]{
"/daq/fadc/ftcal","/daq/fadc/fthodo","/daq/config/fttrk","/daq/fadc/ftof","/daq/fadc/ltcc",
"/daq/fadc/ec", "/daq/fadc/htcc","/daq/fadc/ctof","/daq/fadc/cnd","/daq/config/bmt",
"/daq/config/fmt","/daq/fadc/hel","/daq/fadc/rf","/daq/fadc/band","/daq/fadc/raster",
"/daq/config/ahdc"
});
fitterManager.init(tablesFitter);

// Data filter list
keysFilter = Arrays.asList(new DetectorType[]{DetectorType.DC});
fitters.put(DetectorType.FTCAL, "/daq/fadc/ftcal");
fitters.put(DetectorType.FTHODO, "/daq/fadc/fthodo");
fitters.put(DetectorType.FTTRK, "/daq/fadc/fttrk");
fitters.put(DetectorType.FTOF, "/daq/fadc/ftof");
fitters.put(DetectorType.LTCC, "/daq/fadc/ltcc");
fitters.put(DetectorType.ECAL, "/daq/fadc/ec");
fitters.put(DetectorType.HTCC, "/daq/fadc/htcc");
fitters.put(DetectorType.CTOF, "/daq/fadc/ctof");
fitters.put(DetectorType.CND, "/daq/fadc/cnd");
fitters.put(DetectorType.BMT, "/daq/fadc/bmt");
fitters.put(DetectorType.FMT, "/daq/fadc/fmt");
fitters.put(DetectorType.HEL, "/daq/fadc/hel");
fitters.put(DetectorType.RF, "/daq/fadc/rf");
fitters.put(DetectorType.BAND, "/daq/fadc/band");
fitters.put(DetectorType.RASTER, "/daq/fadc/raster");
fitters.put(DetectorType.AHDC, "/daq/fadc/ahdc");

keysFilter.add(DetectorType.DC);

keysMicromega.add(DetectorType.BMT);
keysMicromega.add(DetectorType.FMT);
keysMicromega.add(DetectorType.FTTRK);

translationManager.init((List)translations.values());

fitterManager.init((List)fitters.values());

scalerManager.init(Arrays.asList(new String[]{"/runcontrol/fcup","/runcontrol/slm","/runcontrol/hwp",
"/runcontrol/helicity","/daq/config/scalers/dsc1"}));

keysMicromega = Arrays.asList(new DetectorType[]{DetectorType.BMT,DetectorType.FMT,DetectorType.FTTRK});

checkTables();
}

public void checkTables() {
for (int i=0; i<tablesTrans.size(); i++) {
IndexedTable t = translationManager.getConstants(runNumber, tablesTrans.get(i));
List<String> tables = (List)translations.values();
for (int i=0; i<tables.size(); i++) {
IndexedTable t = translationManager.getConstants(runNumber, tables.get(i));
for (int j=0; j<i; j++)
t.conflicts(translationManager.getConstants(runNumber, tablesTrans.get(j)));
t.conflicts(translationManager.getConstants(runNumber, tables.get(j)));
}
}

Expand Down Expand Up @@ -169,50 +175,51 @@ public void translate(List<DetectorDataDgtz> detectorData){
}
}

public void fitPulses(List<DetectorDataDgtz> detectorData){
public void fitPulses(List<DetectorDataDgtz> detectorData) {

// preload CCDB tables once:
ArrayList<IndexedTable> tables = new ArrayList<>();
for (String name : tablesFitter) {
tables.add(fitterManager.getConstants(runNumber, name));
HashMap<DetectorType, IndexedTable> tables = new HashMap<>();
for (DetectorType t : translations.keySet()) {
tables.put(t, fitterManager.getConstants(runNumber, translations.get(t)));
}

for(DetectorDataDgtz data : detectorData){
final long hash0 = IndexedTable.DEFAULT_GENERATOR.hashCode(0,0,0);

for (DetectorDataDgtz data : detectorData) {

if (data.getADCSize() == 0) continue;
int crate = data.getDescriptor().getCrate();
int slot = data.getDescriptor().getSlot();
int channel = data.getDescriptor().getChannel();
long hash = IndexedTable.DEFAULT_GENERATOR.hashCode(crate,slot,channel);
long hash0 = IndexedTable.DEFAULT_GENERATOR.hashCode(0,0,0);
boolean ismm = keysMicromega.contains(data.getDescriptor().getType());

for (int j=0; j<keysFitter.size(); ++j) {
IndexedTable daq = tables.get(j);
DetectorType type = keysFitter.get(j);
//custom MM fitter
if (ismm && data.getDescriptor().getType() == type) {
short adcOffset = (short) daq.getDoubleValueByHash("adc_offset", hash0);
double fineTimeStampResolution = (byte) daq.getDoubleValueByHash("dream_clock", hash0);
double samplingTime = (byte) daq.getDoubleValueByHash("sampling_time", hash0);
int sparseSample = daq.getIntValueByHash("sparse", hash0);
ADCData adc = data.getADCData(0);
mvtFitter.fit(adcOffset, fineTimeStampResolution, samplingTime, adc.getPulseArray(), adc.getTimeStamp(), sparseSample);
adc.setHeight((short) (mvtFitter.adcMax));
adc.setTime((int) (mvtFitter.timeMax));
adc.setIntegral((int) (mvtFitter.integral));
adc.setTimeStamp(mvtFitter.timestamp);
// first one wins:
break;
}
else if(daq.hasEntryByHash(hash)==true){
int nsa = daq.getIntValueByHash("nsa", hash);
int nsb = daq.getIntValueByHash("nsb", hash);
int tet = daq.getIntValueByHash("tet", hash);
DetectorType type = data.getDescriptor().getType();

if (!translations.containsKey(type)) continue;

IndexedTable daqTable = tables.get(type);

if (keysMicromega.contains(type)) {
short adcOffset = (short) daqTable.getDoubleValueByHash("adc_offset", hash0);
double fineTimeStampResolution = (byte) daqTable.getDoubleValueByHash("dream_clock", hash0);
double samplingTime = (byte) daqTable.getDoubleValueByHash("sampling_time", hash0);
int sparseSample = daqTable.getIntValueByHash("sparse", hash0);
ADCData adc = data.getADCData(0);
mvtFitter.fit(adcOffset, fineTimeStampResolution, samplingTime, adc.getPulseArray(), adc.getTimeStamp(), sparseSample);
adc.setHeight((short) (mvtFitter.adcMax));
adc.setTime((int) (mvtFitter.timeMax));
adc.setIntegral((int) (mvtFitter.integral));
adc.setTimeStamp(mvtFitter.timestamp);
}
else {
long hash = IndexedTable.DEFAULT_GENERATOR.hashCode(crate,slot,channel);
if (daqTable.hasEntryByHash(hash)==true){
int nsa = daqTable.getIntValueByHash("nsa", hash);
int nsb = daqTable.getIntValueByHash("nsb", hash);
int tet = daqTable.getIntValueByHash("tet", hash);
int ped = 0;
if(data.getDescriptor().getType() == DetectorType.RF && type == DetectorType.RF) {
ped = daq.getIntValueByHash("pedestal", hash);
if (data.getDescriptor().getType() == DetectorType.RF && type == DetectorType.RF) {
ped = daqTable.getIntValueByHash("pedestal", hash);
}
for(int i = 0; i < data.getADCSize(); i++){
for (int i = 0; i < data.getADCSize(); i++) {
ADCData adc = data.getADCData(i);
if(adc.getPulseSize()>0){
try {
Expand All @@ -229,8 +236,6 @@ else if(daq.hasEntryByHash(hash)==true){
}
data.getADCData(i).setADC(nsa, nsb);
}
// first one wins:
break;
}
}
}
Expand Down
Loading