Skip to content
Closed
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 @@ -88,6 +88,14 @@ public final void setSectorLayerComponent(int sector, int layer, int comp){
this.dt_COMPONENT = comp;
}

public final void setSectorLayerComponentOrderType(int sector, int layer, int comp, int order, int type) {
this.dt_SECTOR = sector;
this.dt_LAYER = layer;
this.dt_COMPONENT = comp;
this.dt_ORDER = order;
this.detectorType = DetectorType.getType(type);
}

public static int generateHashCode(int s, int l, int c){
return ((s<<24)&0xFF000000)|
((l<<16)&0x00FF0000)|(c&0x0000FFFF);
Expand All @@ -99,7 +107,6 @@ public int getHashCode(){
(this.dt_COMPONENT&0x00000FFF);
return hash;
}


public void copy(DetectorDescriptor desc){
this.hw_SLOT = desc.hw_SLOT;
Expand All @@ -119,7 +126,6 @@ public boolean compare(DetectorDescriptor desc){
return false;
}


public static String getName(String base, int... ids){
StringBuilder str = new StringBuilder();
str.append(base);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -719,6 +719,8 @@ public void initEvent(DataEvent event){
if(evioEvent.getHandler().getStructure()!=null){
try {

codaDecoder.cacheBranches(evioEvent);

dataList = codaDecoder.getDataEntries( (EvioDataEvent) event);

List<FADCData> fadcPacked = codaDecoder.getADCEntries((EvioDataEvent) event);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,29 @@ public class CodaEventDecoder {
private byte helicityLevel3 = HelicityBit.UDF.value();
private final List<Integer> triggerWords = new ArrayList<>();
JsonObject epicsData = new JsonObject();
List<EvioTreeBranch> branchList = null;

private int tiMaster = -1;

// FIXME: move this to CCDB, e.g., meanwhile cannot reuse ROC id
private static final List<Integer> PCIE_ROCS = Arrays.asList(new Integer[]{78});

public CodaEventDecoder(){
public CodaEventDecoder(){}

/**
* Load map by crate(?).
*
* @param event
*/
void cacheBranches(EvioDataEvent event) {
branchList = getEventBranches(event);
//branchMap = new TreeMap<>();
//for (EvioTreeBranch branch : branchList) {
// if (!branchMap.containsKey(branch.getTag()))
// branchMap.put(branch.getTag(), branch);
//}
}

/**
* returns detector digitized data entries from the event.
* all branches are analyzed and different types of digitized data
Expand All @@ -69,9 +83,8 @@ public List<DetectorDataDgtz> getDataEntries(EvioDataEvent event){
// from the previous event, in the case where there's no HEAD bank:
this.setTriggerBits(0);
List<DetectorDataDgtz> rawEntries = new ArrayList<>();
List<EvioTreeBranch> branches = this.getEventBranches(event);
this.setTimeStamp(event);
for(EvioTreeBranch branch : branches){
for(EvioTreeBranch branch : branchList){
List<DetectorDataDgtz> list = this.getDataEntries(event,branch.getTag());
if(list != null){
rawEntries.addAll(list);
Expand Down Expand Up @@ -186,8 +199,7 @@ public void setTriggerBits(long triggerBits) {

public List<FADCData> getADCEntries(EvioDataEvent event){
List<FADCData> entries = new ArrayList<>();
List<EvioTreeBranch> branches = this.getEventBranches(event);
for(EvioTreeBranch branch : branches){
for(EvioTreeBranch branch : branchList){
List<FADCData> list = this.getADCEntries(event,branch.getTag());
if(list != null){
entries.addAll(list);
Expand All @@ -198,29 +210,20 @@ public List<FADCData> getADCEntries(EvioDataEvent event){

public List<FADCData> getADCEntries(EvioDataEvent event, int crate){
List<FADCData> entries = new ArrayList<>();

List<EvioTreeBranch> branches = this.getEventBranches(event);
EvioTreeBranch cbranch = this.getEventBranch(branches, crate);

EvioTreeBranch cbranch = this.getEventBranch(branchList, crate);
if(cbranch == null ) return null;

for(EvioNode node : cbranch.getNodes()){
if(node.getTag()==57638){
return this.getDataEntries_57638(crate, node, event);
}
}

return entries;
}

public List<FADCData> getADCEntries(EvioDataEvent event, int crate, int tagid){

List<FADCData> adc = new ArrayList<>();
List<EvioTreeBranch> branches = this.getEventBranches(event);

EvioTreeBranch cbranch = this.getEventBranch(branches, crate);
EvioTreeBranch cbranch = this.getEventBranch(branchList, crate);
if(cbranch == null ) return null;

for(EvioNode node : cbranch.getNodes()){
if(node.getTag()==tagid){
// This is regular integrated pulse mode, used for FTOF
Expand All @@ -238,13 +241,9 @@ public List<FADCData> getADCEntries(EvioDataEvent event, int crate, int tagid){
* @return
*/
public List<DetectorDataDgtz> getDataEntries(EvioDataEvent event, int crate){

List<EvioTreeBranch> branches = this.getEventBranches(event);
List<DetectorDataDgtz> bankEntries = new ArrayList<>();

EvioTreeBranch cbranch = this.getEventBranch(branches, crate);
EvioTreeBranch cbranch = this.getEventBranch(branchList, crate);
if(cbranch == null ) return null;

for (EvioNode node : cbranch.getNodes()) {
if (node.getTag() == 57615) {
// This is regular integrated pulse mode, used for FTOF
Expand Down Expand Up @@ -1233,8 +1232,7 @@ public List<DetectorDataDgtz> getDataEntries_57657(Integer crate, EvioNode node

public void getDataEntries_EPICS(EvioDataEvent event){
epicsData = new JsonObject();
List<EvioTreeBranch> branches = this.getEventBranches(event);
for(EvioTreeBranch branch : branches){
for(EvioTreeBranch branch : branchList){
for(EvioNode node : branch.getNodes()){
if(node.getTag()==57620) {
byte[] stringData = ByteDataTransformer.toByteArray(node.getStructureBuffer(true));
Expand All @@ -1260,8 +1258,7 @@ public void getDataEntries_EPICS(EvioDataEvent event){

public HelicityDecoderData getDataEntries_HelicityDecoder(EvioDataEvent event){
HelicityDecoderData data = null;
List<EvioTreeBranch> branches = this.getEventBranches(event);
for(EvioTreeBranch branch : branches){
for(EvioTreeBranch branch : branchList){
for(EvioNode node : branch.getNodes()){
if(node.getTag()==57651) {

Expand Down Expand Up @@ -1341,8 +1338,7 @@ public HelicityDecoderData getDataEntries_HelicityDecoder(EvioDataEvent event){
public List<DetectorDataDgtz> getDataEntries_Scalers(EvioDataEvent event){

List<DetectorDataDgtz> scalerEntries = new ArrayList<>();
List<EvioTreeBranch> branches = this.getEventBranches(event);
for(EvioTreeBranch branch : branches){
for(EvioTreeBranch branch : branchList){
int crate = branch.getTag();
for(EvioNode node : branch.getNodes()){
if(node.getTag()==57637 || node.getTag()==57621){
Expand Down Expand Up @@ -1421,8 +1417,7 @@ else if(node.getTag()==57621 && loop>=5) {
public List<DetectorDataDgtz> getDataEntries_VTP(EvioDataEvent event){

List<DetectorDataDgtz> vtpEntries = new ArrayList<>();
List<EvioTreeBranch> branches = this.getEventBranches(event);
for(EvioTreeBranch branch : branches){
for(EvioTreeBranch branch : branchList){
int crate = branch.getTag();
for(EvioNode node : branch.getNodes()){
if(node.getTag()==57634){
Expand All @@ -1447,11 +1442,10 @@ public List<DetectorDataDgtz> getDataEntries_VTP(EvioDataEvent event){
public List<DetectorDataDgtz> getDataEntries_TDC(EvioDataEvent event){

List<DetectorDataDgtz> tdcEntries = new ArrayList<>();
List<EvioTreeBranch> branches = this.getEventBranches(event);

for(EvioTreeBranch branch : branches){
for(EvioTreeBranch branch : branchList){
int crate = branch.getTag();
EvioTreeBranch cbranch = this.getEventBranch(branches, branch.getTag());
EvioTreeBranch cbranch = this.getEventBranch(branchList, branch.getTag());
for(EvioNode node : cbranch.getNodes()){
if(node.getTag()==57607){
int[] intData = ByteDataTransformer.toIntArray(node.getStructureBuffer(true));
Expand Down Expand Up @@ -1479,10 +1473,9 @@ public List<DetectorDataDgtz> getDataEntries_TDC(EvioDataEvent event){
public List<DetectorDataDgtz> getDataEntries_TI(EvioDataEvent event){

List<DetectorDataDgtz> tiEntries = new ArrayList<>();
List<EvioTreeBranch> branches = this.getEventBranches(event);
for(EvioTreeBranch branch : branches){
for(EvioTreeBranch branch : branchList){
int crate = branch.getTag();
EvioTreeBranch cbranch = this.getEventBranch(branches, branch.getTag());
EvioTreeBranch cbranch = this.getEventBranch(branchList, branch.getTag());
for(EvioNode node : cbranch.getNodes()){
if(node.getTag()==57610){
long[] longData = ByteDataTransformer.toLongArray(node.getStructureBuffer(true));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,15 @@ public class DetectorEventDecoder {
List<DetectorType> keysTrans = null;
List<DetectorType> keysFitter = null;
List<DetectorType> keysFilter = null;
List<DetectorType> keysMicromega= null;

private int runNumber = 10;

private ExtendedFADCFitter extendedFitter = new ExtendedFADCFitter();
private MVTFitter mvtFitter = new MVTFitter();

private TranslationTable translator = new TranslationTable();

public DetectorEventDecoder(boolean development){
if(development==true){
this.initDecoderDev();
Expand All @@ -55,6 +58,11 @@ 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)));
}
this.runNumber = run;
}

Expand Down Expand Up @@ -121,7 +129,9 @@ public final void initDecoder(){

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();
}

Expand All @@ -140,44 +150,21 @@ public void checkTables() {
*/
public void translate(List<DetectorDataDgtz> detectorData){

// Preload CCDB tables:
ArrayList<IndexedTable> tables = new ArrayList<>();
for (String name : tablesTrans) {
tables.add(translationManager.getConstants(runNumber, name));
}
for (DetectorDataDgtz d : detectorData) {

for (DetectorDataDgtz data : detectorData) {
// Get the hardware indexing for this detector data object:
long hash = IndexedTable.DEFAULT_GENERATOR.hashCode(d.getDescriptor().getCrate(),
d.getDescriptor().getSlot(), d.getDescriptor().getChannel());

// Get the hardware indexing for this detector hit:
int crate = data.getDescriptor().getCrate();
int slot = data.getDescriptor().getSlot();
int channel = data.getDescriptor().getChannel();
long hash = IndexedTable.DEFAULT_GENERATOR.hashCode(crate,slot,channel);

// Try to find it in the translation tables:
for (int j=0; j<tablesTrans.size(); ++j) {

IndexedTable t = tables.get(j);

// Found it; now set the detector indexing for this hit:
if (t.hasEntryByHash(hash)) {
if (translator.hasEntryByHash(hash)) {

int sector = t.getIntValueByHash(0, hash);
int layer = t.getIntValueByHash(1, hash);
int component = t.getIntValueByHash(2, hash);
int order = t.getIntValueByHash(3, hash);
// The tanslated detector indexing:
List<Integer> x = translator.getIntegersByHash(hash);

data.getDescriptor().setSectorLayerComponent(sector, layer, component);
data.getDescriptor().setOrder(order);
data.getDescriptor().setType(keysTrans.get(j));

for(int i = 0; i < data.getADCSize(); i++) data.getADCData(i).setOrder(order);
for(int i = 0; i < data.getTDCSize(); i++) data.getTDCData(i).setOrder(order);

// Assume there's only one instance of this crate/slot/channel
// in all translation tables, and we found it, so stop:
break;
}
// Set the translated detector indexing:
d.getDescriptor().setSectorLayerComponentOrderType(x.get(0),x.get(1),x.get(2),x.get(3),x.get(4));
for (int i=0; i<d.getADCSize(); i++) d.getADCData(i).setOrder(x.get(3));
for (int i=0; i<d.getTDCSize(); i++) d.getTDCData(i).setOrder(x.get(3));
}
}
}
Expand All @@ -200,10 +187,7 @@ public void fitPulses(List<DetectorDataDgtz> detectorData){
IndexedTable daq = tables.get(j);
DetectorType type = keysFitter.get(j);
//custom MM fitter
if( ( (type == DetectorType.BMT)&&(data.getDescriptor().getType().getName().equals("BMT")) )
|| ( (type == DetectorType.FMT)&&(data.getDescriptor().getType().getName().equals("FMT")) )
//|| ( (type == DetectorType.AHDC)&&(data.getDescriptor().getType().getName().equals("AHDC")) )
|| ( (type == DetectorType.FTTRK)&&(data.getDescriptor().getType().getName().equals("FTTRK")) ) ){
if (data.getDescriptor().getType() == type && keysMicromega.contains(keysFitter.get(j))) {
short adcOffset = (short) daq.getDoubleValueByHash("adc_offset", hash0);
double fineTimeStampResolution = (byte) daq.getDoubleValueByHash("dream_clock", hash0);
double samplingTime = (byte) daq.getDoubleValueByHash("sampling_time", hash0);
Expand All @@ -222,7 +206,7 @@ public void fitPulses(List<DetectorDataDgtz> detectorData){
int nsb = daq.getIntValueByHash("nsb", hash);
int tet = daq.getIntValueByHash("tet", hash);
int ped = 0;
if(type == DetectorType.RF&&data.getDescriptor().getType().getName().equals("RF")) {
if(data.getDescriptor().getType() == DetectorType.RF && type == DetectorType.RF) {
ped = daq.getIntValueByHash("pedestal", hash);
}
if(data.getADCSize()>0){
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package org.jlab.detector.decode;

import java.util.stream.Collectors;
import org.jlab.utils.groups.IndexedTable;
import org.jlab.detector.base.DetectorType;
import org.jlab.detector.calib.utils.ConstantsManager;
import org.jlab.utils.groups.IndexedTable;

/**
*
Expand All @@ -24,6 +25,7 @@ public void add(DetectorType dt, IndexedTable it) {
int slot = IndexedTable.DEFAULT_GENERATOR.getIndex(hash, 1);
int channel = IndexedTable.DEFAULT_GENERATOR.getIndex(hash, 2);

// first one wins, print error message for loser:
if (hasEntryByHash(hash)) {
System.err.print("TranslationTable: found CCDB overlap for ");
System.err.println(String.format("type %d/%s versus %s and c/s/c=%d/%d/%d",
Expand All @@ -36,17 +38,24 @@ public void add(DetectorType dt, IndexedTable it) {
addEntry(crate, slot, channel);

// add each column's entry to the new row:
for (int column=0; column<it.getEntryMap().values().size(); column++) {
int value = it.getIntValueByHash(column, hash);
setIntValueByHash(value, column, hash);
}
for (int column=0; column<it.getEntryMap().values().size(); column++)
setIntValueByHash(it.getIntValueByHash(column, hash), column, hash);

// add the new detector type, as the last column:
setIntValueByHash(dt.getDetectorId(), it.getEntryMap().values().size(), hash);
}
}
}

public void dump() {
for (Object key : getList().getMap().keySet()) {
int[] idx = IndexedTable.DEFAULT_GENERATOR.getIndices((long)key, 0,1,2);
System.out.print(String.format("%d/%d/%d ", idx[0],idx[1],idx[2]));
System.out.print(getIntegersByHash((long)key).stream().
map(String::valueOf).collect(Collectors.joining("/")));
System.out.print("\n");
}
}

public static final DetectorType[] TYPES = new DetectorType[]{
DetectorType.FTCAL,DetectorType.FTHODO,DetectorType.FTTRK,
Expand All @@ -70,8 +79,9 @@ public static void main(String[] args) {
ConstantsManager conman = new ConstantsManager();
conman.init(STYPES);
TranslationTable tt = new TranslationTable();
for (int i=0; i<STYPES.length; i++)
for (int i=0; i<TYPES.length; i++)
tt.add(TYPES[i],conman.getConstants(18779,STYPES[i]));
tt.show();
tt.dump();
}
}
Loading