diff --git a/common-tools/clas-detector/src/main/java/org/jlab/detector/examples/DaqPulsePlotter.java b/common-tools/clas-detector/src/main/java/org/jlab/detector/examples/DaqPulsePlotter.java index 82bf909454..95ab32cda5 100644 --- a/common-tools/clas-detector/src/main/java/org/jlab/detector/examples/DaqPulsePlotter.java +++ b/common-tools/clas-detector/src/main/java/org/jlab/detector/examples/DaqPulsePlotter.java @@ -1,8 +1,3 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ package org.jlab.detector.examples; import java.awt.BorderLayout; @@ -15,17 +10,13 @@ import java.util.List; import java.util.Map; import java.util.Set; -import javax.swing.JButton; -import javax.swing.JComboBox; import javax.swing.JFrame; -import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JSplitPane; import org.jlab.detector.base.DetectorCollection; import org.jlab.detector.base.DetectorType; import org.jlab.detector.decode.CodaEventDecoder; import org.jlab.detector.decode.DetectorDataDgtz; -import org.jlab.detector.decode.DetectorDecoderView; import org.jlab.detector.decode.DetectorEventDecoder; import org.jlab.detector.view.DetectorListener; import org.jlab.detector.view.DetectorPane2D; @@ -33,8 +24,6 @@ import org.jlab.detector.view.DetectorView2D; import org.jlab.groot.data.H1F; import org.jlab.groot.data.IDataSet; -import org.jlab.groot.graphics.EmbeddedCanvas; -import org.jlab.groot.graphics.EmbeddedCanvasTabbed; import org.jlab.io.base.DataEvent; import org.jlab.io.evio.EvioDataEvent; import org.jlab.io.task.DataSourceProcessorPane; @@ -45,61 +34,30 @@ * @author gavalian */ public class DaqPulsePlotter implements IDataEventListener,DetectorListener,ActionListener { - Map > detectorMap = - new HashMap >(); - JPanel pane = null; - + Map > detectorMap = new HashMap< >(); + JPanel pane = null; CodaEventDecoder decoder = new CodaEventDecoder(); DetectorEventDecoder detectorDecoder = new DetectorEventDecoder(); - DataSourceProcessorPane processorPane = null; - - //EmbeddedCanvasTabbed canvasTab = new EmbeddedCanvasTabbed(true); - //EmbeddedCanvasGroup canvasTab = new EmbeddedCanvasGroup(); - - JComboBox comboDetector = null; - JComboBox comboSector = null; - JComboBox comboLayer = null; - JComboBox comboBunch = null; - + DataSourceProcessorPane processorPane = null; + public String[] detectorNames = new String[]{"EC","FTOF","CTOF", "HTCC","LTCC"}; public String[] detectorSectors = new String[] {"1","2","3","4","5","6"}; public String[] detectorLayers = new String[] {"1","2","3","4","5","6","7","8","9","10"}; public String[] detectorBunch = new String[] {"1","2","3","4","5","6","7","8","9","10"}; - int nDetectorsPerBunch = 12; - - - DetectorPane2D detectorView = null; - DetectorDecoderView detectorDecoderView = null; + DetectorPane2D detectorView = null; public DaqPulsePlotter(){ pane = new JPanel(); pane.setLayout(new BorderLayout()); - //canvasTab.addCanvas("DAQ"); processorPane = new DataSourceProcessorPane(); processorPane.setDelay(2); JPanel buttonPane = new JPanel(); buttonPane.setLayout(new FlowLayout()); - comboDetector = new JComboBox(this.detectorNames); - comboSector = new JComboBox(this.detectorSectors); - comboLayer = new JComboBox(this.detectorLayers); - comboBunch = new JComboBox(this.detectorBunch); - - - //buttonPane.add(comboDetector); - //buttonPane.add(comboSector); - //buttonPane.add(comboLayer); - //buttonPane.add(new JLabel("Page Number")); - //buttonPane.add(comboBunch); - - //JButton drawButton = new JButton("Draw"); - //drawButton.addActionListener(this); - //buttonPane.add(drawButton); - pane.add(buttonPane,BorderLayout.PAGE_START); JSplitPane splitPane = new JSplitPane(); @@ -108,15 +66,12 @@ public DaqPulsePlotter(){ detectorView.getView().addDetectorListener(this); this.updateDetectorView(); splitPane.setLeftComponent(detectorView); - // splitPane.setRightComponent(canvasTab); pane.add(splitPane,BorderLayout.CENTER); - //pane.add(canvasTab,BorderLayout.CENTER); pane.add(processorPane,BorderLayout.PAGE_END); this.processorPane.addEventListener(this); } - - + public void updateDetectorView(){ for(int sector = 1 ; sector < 7; sector++){ @@ -224,24 +179,16 @@ public void drawSectorLayer(DetectorType type, int sector, int layer){ System.out.println(" plotting type = " + type); DetectorCollection collection = this.detectorMap.get(type.getDetectorId()); Set components = collection.getComponents(sector, layer); - //EmbeddedCanvas c = this.canvasTab.getCanvas(); - //c.clear(); - //c.divide(3, 4); int counter = 0; - int counterCanvas = 0; System.out.println("COLLECTION HAS " + collection.getList().size() + " COMPONENTS = " + components.size()); - int bunch = Integer.parseInt(this.comboBunch.getSelectedItem().toString()); - List datasetList = new ArrayList(); + List datasetList = new ArrayList<>(); for(Integer key : components){ - //c.cd(counterCanvas); H1F h = collection.get(sector,layer,key); datasetList.add(h); - //c.draw(h); } counter++; - //this.canvasTab.setData(datasetList); } } diff --git a/common-tools/clas-detector/src/main/java/org/jlab/detector/examples/DataContainers.java b/common-tools/clas-detector/src/main/java/org/jlab/detector/examples/DataContainers.java deleted file mode 100644 index e79d036eb3..0000000000 --- a/common-tools/clas-detector/src/main/java/org/jlab/detector/examples/DataContainers.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ -package org.jlab.detector.examples; - -import org.jlab.groot.data.H2F; -import org.jlab.utils.groups.IndexedList; - -/** - * - * @author gavalian - */ -public class DataContainers { - public static void main(String[] args){ - IndexedList h2TOF = new IndexedList(3); - - for(int sector = 1; sector < 6; sector++){ - for(int paddle = 1; paddle < 23; paddle++){ - h2TOF.add(new H2F(), sector,1,paddle); - } - } - - - boolean flag = h2TOF.hasItem(2,1,13); - H2F h2P = h2TOF.getItem(2,1,13); - } -} diff --git a/common-tools/clas-io/src/main/java/org/jlab/io/base/BasicDataBank.java b/common-tools/clas-io/src/main/java/org/jlab/io/base/BasicDataBank.java index 0c7efe9cab..2e7d961897 100644 --- a/common-tools/clas-io/src/main/java/org/jlab/io/base/BasicDataBank.java +++ b/common-tools/clas-io/src/main/java/org/jlab/io/base/BasicDataBank.java @@ -1,12 +1,6 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ - package org.jlab.io.base; -import java.util.HashMap; +import java.util.Arrays; import java.util.HashSet; import java.util.LinkedHashMap; import java.util.Map; @@ -19,26 +13,22 @@ * @author gavalian */ public class BasicDataBank implements DataBank { + /** * Defining the containers to hold bank data. */ - private Boolean isUniLength = true; - private Map shortContainer = new LinkedHashMap(); - private Map intContainer = new LinkedHashMap(); - private Map floatContainer = new LinkedHashMap(); - private Map doubleContainer = new LinkedHashMap(); - private Map byteContainer = new LinkedHashMap(); - private Map longContainer = new LinkedHashMap(); + private Map shortContainer = new LinkedHashMap<>(); + private Map intContainer = new LinkedHashMap<>(); + private Map floatContainer = new LinkedHashMap<>(); + private Map doubleContainer = new LinkedHashMap<>(); + private Map byteContainer = new LinkedHashMap<>(); + private Map longContainer = new LinkedHashMap<>(); private DataDescriptor bankDescriptor; public BasicDataBank(DataDescriptor desc){ bankDescriptor = desc; } - - public BasicDataBank(){ - //bankDescriptor = desc; - } - + private void printWarningColumnExists(String routine,String column_name){ System.err.println("[BasicDataBank::"+ routine + ": " + this.getDescriptor().getName() + @@ -60,12 +50,14 @@ private void printOutOfBoundsWarning(String routine, String column_name, int ind } + @Override public String[] getColumnList() { return null; //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } + @Override public DataDescriptor getDescriptor() { return bankDescriptor; //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. @@ -76,6 +68,7 @@ public DataDescriptor getDescriptor() { * @return double array */ + @Override public double[] getDouble(String path) { if(doubleContainer.containsKey(path)==true){ return doubleContainer.get(path); @@ -89,6 +82,7 @@ public double[] getDouble(String path) { * @param arr array of doubles to add to the container. */ + @Override public void setDouble(String path, double[] arr) { if(doubleContainer.containsKey(path)==true){ this.printWarningColumnExists("setDouble", path); @@ -104,6 +98,7 @@ public void setDouble(String path, double[] arr) { * @param value new value to set */ + @Override public void setDouble(String path, int row, double value) { if(doubleContainer.containsKey(path)==false){ this.printWarningColumnDoesNotExist("setDouble", path); @@ -123,6 +118,7 @@ public void setDouble(String path, int row, double value) { * @param arr */ + @Override public void appendDouble(String path, double[] arr) { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } @@ -132,6 +128,7 @@ public void appendDouble(String path, double[] arr) { * @return array of floats */ + @Override public float[] getFloat(String path) { if(floatContainer.containsKey(path)==true){ return floatContainer.get(path); @@ -145,6 +142,7 @@ public float[] getFloat(String path) { * @param arr */ + @Override public void setFloat(String path, float[] arr) { if(floatContainer.containsKey(path)==true){ this.printWarningColumnExists("setDouble", path); @@ -160,6 +158,7 @@ public void setFloat(String path, float[] arr) { * @param value */ + @Override public void setFloat(String path, int row, float value) { if(floatContainer.containsKey(path)==false){ this.printWarningColumnDoesNotExist("setDouble", path); @@ -179,11 +178,13 @@ public void setFloat(String path, int row, float value) { * @param arr */ + @Override public void appendFloat(String path, float[] arr) { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } + @Override public int[] getInt(String path) { if(intContainer.containsKey(path)==true){ return intContainer.get(path); @@ -192,6 +193,7 @@ public int[] getInt(String path) { } + @Override public void setInt(String path, int[] arr) { if(intContainer.containsKey(path)==true){ this.printWarningColumnExists("setInt", path); @@ -201,6 +203,7 @@ public void setInt(String path, int[] arr) { } + @Override public void setInt(String path, int row, int value) { if(intContainer.containsKey(path)==false){ this.printWarningColumnDoesNotExist("setInt", path); @@ -220,11 +223,13 @@ public void setInt(String path, int row, int value) { * @param arr */ + @Override public void appendInt(String path, int[] arr) { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } + @Override public short[] getShort(String path) { if(shortContainer.containsKey(path)==true){ return shortContainer.get(path); @@ -233,6 +238,7 @@ public short[] getShort(String path) { } + @Override public void setShort(String path, short[] arr) { if(shortContainer.containsKey(path)==true){ this.printWarningColumnExists("setShort", path); @@ -242,6 +248,7 @@ public void setShort(String path, short[] arr) { } + @Override public void setShort(String path, int row, short value) { if(shortContainer.containsKey(path)==false){ this.printWarningColumnDoesNotExist("setShort", path); @@ -257,11 +264,13 @@ public void setShort(String path, int row, short value) { } + @Override public void appendShort(String path, short[] arr) { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } + @Override public byte[] getByte(String path) { if(byteContainer.containsKey(path)==true){ return byteContainer.get(path); @@ -270,6 +279,7 @@ public byte[] getByte(String path) { } + @Override public void setByte(String path, byte[] arr) { if(byteContainer.containsKey(path)==true){ this.printWarningColumnExists("setByte", path); @@ -279,6 +289,7 @@ public void setByte(String path, byte[] arr) { } + @Override public void setByte(String path, int row, byte value) { if(byteContainer.containsKey(path)==false){ this.printWarningColumnDoesNotExist("setByte", path); @@ -294,11 +305,13 @@ public void setByte(String path, int row, byte value) { } + @Override public void appendByte(String path, byte[] arr) { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } + @Override public long[] getLong(String path) { if(longContainer.containsKey(path)==true){ return longContainer.get(path); @@ -306,6 +319,7 @@ public long[] getLong(String path) { return new long[0]; } + @Override public void setLong(String path, long[] arr) { if(longContainer.containsKey(path)==true){ this.printWarningColumnExists("setLong", path); @@ -314,6 +328,7 @@ public void setLong(String path, long[] arr) { } } + @Override public void setLong(String path, int row, long value) { if(longContainer.containsKey(path)==false){ this.printWarningColumnDoesNotExist("setLong", path); @@ -328,10 +343,12 @@ public void setLong(String path, int row, long value) { } } + @Override public void appendLong(String path, long[] arr) { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } + @Override public int columns() { int ic = 0; ic += shortContainer.size(); @@ -342,8 +359,8 @@ public int columns() { ic += longContainer.size(); return ic; } - + @Override public int rows() { int nrows = 0; for(Map.Entry item : floatContainer.entrySet()){ @@ -363,8 +380,8 @@ public int rows() { } return nrows; } - + @Override public void show() { int size = this.columns(); String bankname = "undefined"; @@ -422,7 +439,7 @@ public void show() { } } - + @Override public void reset() { shortContainer.clear(); byteContainer.clear(); @@ -431,13 +448,13 @@ public void reset() { doubleContainer.clear(); longContainer.clear(); } - + @Override public void allocate(int rows) { System.err.println("[BasicDataBank]---> allocate is not implemented.."); } - + @Override public double getDouble(String path, int index) { if(doubleContainer.containsKey(path)==true){ if(doubleContainer.get(path).length<=index){ @@ -452,8 +469,8 @@ public double getDouble(String path, int index) { } return 0.0; } - + @Override public float getFloat(String path, int index) { if(floatContainer.containsKey(path)==true){ if(floatContainer.get(path).length<=index){ @@ -469,7 +486,7 @@ public float getFloat(String path, int index) { return (float) 0.0; } - + @Override public int getInt(String path, int index) { if(intContainer.containsKey(path)==true){ if(intContainer.get(path).length<=index){ @@ -484,8 +501,8 @@ public int getInt(String path, int index) { } return 0; } - + @Override public long getLong(String path, int index) { if(longContainer.containsKey(path)==true){ if(longContainer.get(path).length<=index){ @@ -501,6 +518,7 @@ public long getLong(String path, int index) { return 0; } + @Override public short getShort(String path, int index) { if(shortContainer.containsKey(path)==true){ if(shortContainer.get(path).length<=index){ @@ -515,8 +533,8 @@ public short getShort(String path, int index) { } return 0; } - + @Override public byte getByte(String path, int index) { if(byteContainer.containsKey(path)==true){ if(byteContainer.get(path).length<=index){ @@ -532,13 +550,12 @@ public byte getByte(String path, int index) { return 0; } + @Override public TableModel getTableModel(String mask) { String[] tokens = mask.split(":"); - Set entryMask = new HashSet(); - for(String item : tokens){ - entryMask.add(item); - } + Set entryMask = new HashSet<>(); + entryMask.addAll(Arrays.asList(tokens)); String[] columns = this.bankDescriptor.getEntryList(); int nrows = this.rows(); diff --git a/common-tools/clas-io/src/main/java/org/jlab/io/base/BasicDataDescriptor.java b/common-tools/clas-io/src/main/java/org/jlab/io/base/BasicDataDescriptor.java deleted file mode 100644 index 07f47d1cef..0000000000 --- a/common-tools/clas-io/src/main/java/org/jlab/io/base/BasicDataDescriptor.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ - -package org.jlab.io.base; - -import java.util.HashMap; - -/** - * - * @author gavalian - */ -public class BasicDataDescriptor implements DataDescriptor { - private HashMap descProperties = new HashMap(); - private String descName = "UNDEF"; - private String jsonObjectString = ""; - - public BasicDataDescriptor(String name) { - descName = name; - } - - public void init(String s) { - // JSonObject model = new Json.createObjectBuilder(); - } - - public String[] getEntryList() { - throw new UnsupportedOperationException("Not supported yet."); // To change body of generated methods, choose Tools | Templates. - } - - public String getName() { - throw new UnsupportedOperationException("Not supported yet."); // To change body of generated methods, choose Tools | Templates. - } - - public String getXML() { - throw new UnsupportedOperationException("Not supported yet."); // To change body of generated methods, choose Tools | Templates. - } - - public int getProperty(String property_name, String entry_name) { - throw new UnsupportedOperationException("Not supported yet."); // To change body of generated methods, choose Tools | Templates. - } - - public int getProperty(String property_name) { - throw new UnsupportedOperationException("Not supported yet."); // To change body of generated methods, choose Tools | Templates. - } - - public void setPropertyString(String name, String value) { - throw new UnsupportedOperationException("Not supported yet."); // To change body of generated methods, choose Tools | Templates. - } - - public String getPropertyString(String property_name) { - throw new UnsupportedOperationException("Not supported yet."); // To change body of generated methods, choose Tools | Templates. - } - - public void show() { - throw new UnsupportedOperationException("Not supported yet."); // To change body of generated methods, choose Tools | Templates. - } - - public boolean hasEntry(String entry) { - throw new UnsupportedOperationException("Not supported yet."); // To change body of generated methods, choose Tools | Templates. - } - - public boolean hasEntries(String... entries) { - throw new UnsupportedOperationException("Not supported yet."); // To change body of generated methods, choose Tools | Templates. - } - -} diff --git a/common-tools/clas-io/src/main/java/org/jlab/io/base/DataDescriptor.java b/common-tools/clas-io/src/main/java/org/jlab/io/base/DataDescriptor.java index 9ac975cc91..1bddf813e9 100644 --- a/common-tools/clas-io/src/main/java/org/jlab/io/base/DataDescriptor.java +++ b/common-tools/clas-io/src/main/java/org/jlab/io/base/DataDescriptor.java @@ -5,15 +5,15 @@ * It consists of a list of Entries by name and integer ID. */ public interface DataDescriptor { - void init(String s); - String[] getEntryList(); - String getName(); - String getXML(); - boolean hasEntry(String entry); - boolean hasEntries(String... entries); - int getProperty(String property_name, String entry_name); - int getProperty(String property_name); - void setPropertyString(String name, String value); - String getPropertyString(String property_name); - void show(); + void init(String s); + String[] getEntryList(); + String getName(); + String getXML(); + boolean hasEntry(String entry); + boolean hasEntries(String... entries); + int getProperty(String property_name, String entry_name); + int getProperty(String property_name); + void setPropertyString(String name, String value); + String getPropertyString(String property_name); + void show(); } diff --git a/common-tools/clas-io/src/main/java/org/jlab/io/base/DataDictionary.java b/common-tools/clas-io/src/main/java/org/jlab/io/base/DataDictionary.java index 2716e82b8a..2fb2206681 100644 --- a/common-tools/clas-io/src/main/java/org/jlab/io/base/DataDictionary.java +++ b/common-tools/clas-io/src/main/java/org/jlab/io/base/DataDictionary.java @@ -1,9 +1,9 @@ package org.jlab.io.base; public interface DataDictionary { - void init(String format); - String getXML(); - String[] getDescriptorList(); - DataDescriptor getDescriptor(String desc_name); - DataBank createBank(String name, int rows); + void init(String format); + String getXML(); + String[] getDescriptorList(); + DataDescriptor getDescriptor(String desc_name); + DataBank createBank(String name, int rows); } diff --git a/common-tools/clas-io/src/main/java/org/jlab/io/base/DataEntryType.java b/common-tools/clas-io/src/main/java/org/jlab/io/base/DataEntryType.java index 79545a4bbc..dac66ea0cb 100644 --- a/common-tools/clas-io/src/main/java/org/jlab/io/base/DataEntryType.java +++ b/common-tools/clas-io/src/main/java/org/jlab/io/base/DataEntryType.java @@ -1,9 +1,3 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ - package org.jlab.io.base; /** @@ -19,9 +13,6 @@ public enum DataEntryType { LONG (4,8,"int64"), FLOAT (5,4,"float32"), DOUBLE (6,8,"float64"); - //CHAR8 (7,1,"CHAR8"), - //INT32 (8,4,"INT32"); - private final int typeId; private final int typeSize; diff --git a/common-tools/clas-io/src/main/java/org/jlab/io/base/DataEventStore.java b/common-tools/clas-io/src/main/java/org/jlab/io/base/DataEventStore.java deleted file mode 100644 index 05e72ddcab..0000000000 --- a/common-tools/clas-io/src/main/java/org/jlab/io/base/DataEventStore.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ -package org.jlab.io.base; - -import java.util.Map; -import java.util.TreeMap; - -/** - * - * @author gavalian - */ -public class DataEventStore { - private TreeMap store = new TreeMap(); - - - - public DataEventStore(){ - - } - - public DataEventStore(DataEvent event){ - this.init(event); - } - - public final void init(DataEvent event){ - String[] banks = event.getBankList(); - store.clear(); - for(String bank : banks){ - DataBank db = event.getBank(bank); - if(db!=null){ - store.put(bank, db); - } else { - System.err.println("[DataEventStore::init] ----> error : reading bank " - + " [" + bank + "] failed...."); - } - } - } - - public DataBank getBank(String name){ - return this.store.get(name); - } - - public boolean hasBank(String name){ - return this.store.containsKey(name); - } - - public void show(){ - for(Map.Entry bank : this.store.entrySet()){ - System.out.println(String.format("| %-24s | %6d | %6d |", bank.getKey(), - bank.getValue().rows(),bank.getValue().rows())); - } - } -} diff --git a/common-tools/clas-io/src/main/java/org/jlab/io/base/DataEventType.java b/common-tools/clas-io/src/main/java/org/jlab/io/base/DataEventType.java index d08de5afdb..f23ae0619e 100644 --- a/common-tools/clas-io/src/main/java/org/jlab/io/base/DataEventType.java +++ b/common-tools/clas-io/src/main/java/org/jlab/io/base/DataEventType.java @@ -1,8 +1,3 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ package org.jlab.io.base; /** diff --git a/common-tools/clas-io/src/main/java/org/jlab/io/base/DataFactory.java b/common-tools/clas-io/src/main/java/org/jlab/io/base/DataFactory.java deleted file mode 100644 index d966d6368a..0000000000 --- a/common-tools/clas-io/src/main/java/org/jlab/io/base/DataFactory.java +++ /dev/null @@ -1,25 +0,0 @@ -package org.jlab.io.base; - -import java.io.File; - -public class DataFactory { - public DataSource createDataSource(File file) { - return null; - - } - - public DataSource createEvioDataSource(File file) { - return null; - - } - /* - public DataSource createEvioDataSource(JioSerial ioserial) { - return null; - - } - - public DataDictionary createEvioDictionary(String dirpath) { - - }*/ - -} diff --git a/common-tools/clas-io/src/main/java/org/jlab/io/base/DataSourceType.java b/common-tools/clas-io/src/main/java/org/jlab/io/base/DataSourceType.java index c823a52761..03e3259a9c 100644 --- a/common-tools/clas-io/src/main/java/org/jlab/io/base/DataSourceType.java +++ b/common-tools/clas-io/src/main/java/org/jlab/io/base/DataSourceType.java @@ -1,8 +1,3 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ package org.jlab.io.base; /** diff --git a/common-tools/clas-io/src/main/java/org/jlab/io/base/DataSync.java b/common-tools/clas-io/src/main/java/org/jlab/io/base/DataSync.java index 98b5044322..8f4c688b0b 100644 --- a/common-tools/clas-io/src/main/java/org/jlab/io/base/DataSync.java +++ b/common-tools/clas-io/src/main/java/org/jlab/io/base/DataSync.java @@ -1,9 +1,3 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ - package org.jlab.io.base; /** diff --git a/common-tools/clas-io/src/main/java/org/jlab/io/evio/EvioDataBank.java b/common-tools/clas-io/src/main/java/org/jlab/io/evio/EvioDataBank.java index b2fd9e1a04..5aab89d33e 100644 --- a/common-tools/clas-io/src/main/java/org/jlab/io/evio/EvioDataBank.java +++ b/common-tools/clas-io/src/main/java/org/jlab/io/evio/EvioDataBank.java @@ -1,11 +1,9 @@ package org.jlab.io.evio; - import org.jlab.io.base.BasicDataBank; import org.jlab.io.base.DataDescriptor; import org.jlab.io.base.DataEntryType; - public class EvioDataBank extends BasicDataBank { public EvioDataBank(DataDescriptor desc){ diff --git a/common-tools/clas-io/src/main/java/org/jlab/io/evio/EvioDataBucket.java b/common-tools/clas-io/src/main/java/org/jlab/io/evio/EvioDataBucket.java deleted file mode 100644 index 220d97a597..0000000000 --- a/common-tools/clas-io/src/main/java/org/jlab/io/evio/EvioDataBucket.java +++ /dev/null @@ -1,166 +0,0 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ - -package org.jlab.io.evio; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.nio.ByteBuffer; -import java.nio.ByteOrder; -import java.util.logging.Level; -import java.util.logging.Logger; -import java.util.zip.GZIPOutputStream; -import org.jlab.coda.jevio.DataType; -import org.jlab.coda.jevio.EventBuilder; -import org.jlab.coda.jevio.EventWriter; -import org.jlab.coda.jevio.EvioEvent; -import org.jlab.coda.jevio.EvioException; -import org.jlab.coda.jevio.EvioReader; - -/** - * - * @author gavalian - */ -public class EvioDataBucket { - - private EventWriter writer = null; - private EvioReader reader = null; - - private ByteBuffer eventBuffer = null; - private int MAX_BUFFER_SIZE = 10*1024*1024; - - public EvioDataBucket(){ - - } - - public EvioDataBucket(byte[] array, ByteOrder order){ - - this.eventBuffer = ByteBuffer.wrap(array); - this.eventBuffer.order(order); - - try { - - reader = new EvioReader(this.eventBuffer); - - System.out.println("number of events = " + reader.getEventCount() - + " buffer length = " + array.length); - int counter = 0; - - EvioEvent event = reader.parseNextEvent(); - if(event==null) System.out.println(" event is null " ); - for(int loop = 0; loop < array.length; loop++){ - System.out.print(String.format(" %6X ", array[loop])); - if(loop%10==0) System.out.println(); - } - while(event!=null){ - event = reader.parseNextEvent(); - counter++; - } - System.out.println("event count = " + counter); - } catch (EvioException ex) { - Logger.getLogger(EvioDataBucket.class.getName()).log(Level.SEVERE, null, ex); - } catch (IOException ex) { - Logger.getLogger(EvioDataBucket.class.getName()).log(Level.SEVERE, null, ex); - } - - } - - public void openWriter(String filename){ - this.eventBuffer = ByteBuffer.allocate(this.MAX_BUFFER_SIZE); - this.eventBuffer.order(ByteOrder.LITTLE_ENDIAN); - try { - writer = new EventWriter(this.eventBuffer, null); - } catch (EvioException ex) { - Logger.getLogger(EvioDataBucket.class.getName()).log(Level.SEVERE, null, ex); - } - } - - public void writeEvent(EvioEvent ev){ - try { - this.writer.writeEvent(ev); - } catch (EvioException ex) { - Logger.getLogger(EvioDataBucket.class.getName()).log(Level.SEVERE, null, ex); - } catch (IOException ex) { - Logger.getLogger(EvioDataBucket.class.getName()).log(Level.SEVERE, null, ex); - } - } - public void writeEvent(ByteBuffer buffer){ - try { - writer.writeEvent(buffer); - System.out.println("WRITING EVENT BUFFER of LENGTH " + buffer.capacity()); - } catch (EvioException ex) { - Logger.getLogger(EvioDataBucket.class.getName()).log(Level.SEVERE, null, ex); - } catch (IOException ex) { - Logger.getLogger(EvioDataBucket.class.getName()).log(Level.SEVERE, null, ex); - } - } - - public boolean hasSpace(EvioDataEvent event){ - return (event.getEventBuffer().capacity()+writer.getBytesWrittenToBuffer()>=this.MAX_BUFFER_SIZE); - } - - - public byte[] getEventArray(){ - long bytesWritten = this.writer.getBytesWrittenToBuffer(); - int alloc = (int) bytesWritten; - byte[] array = new byte[alloc]; - this.eventBuffer.get(array,0,array.length); - return array; - } - - public byte[] getEventArrayGzip(){ - return EvioDataBucket.gzip(this.getEventArray()); - } - - public static byte[] gzip(byte[] ungzipped) { - final ByteArrayOutputStream bytes = new ByteArrayOutputStream(); - try { - final GZIPOutputStream gzipOutputStream = new GZIPOutputStream(bytes); - gzipOutputStream.write(ungzipped); - gzipOutputStream.close(); - } catch (IOException e) { - // LOG.error("Could not gzip " + Arrays.toString(ungzipped)); - System.out.println("[iG5DataCompressor] ERROR: Could not gzip the array...."); - } - return bytes.toByteArray(); - } - - public void writeEvent(EvioDataEvent event){ - this.writeEvent(event.getEventBuffer()); - } - - public void show(){ - System.out.println("ALLOCATED SIZE = " + this.eventBuffer.capacity() - + " LIMIT " + this.eventBuffer.limit() + " BYTES WRITTEN = " + - writer.getBytesWrittenToBuffer()); - } - - - - public static void main(String[] args){ - EvioDataBucket bucket = new EvioDataBucket(); - bucket.openWriter("test.evio"); - bucket.show(); - for(int loop = 0; loop < 2; loop++){ - System.out.println("WRITING event # " + loop); - EventBuilder eb = new EventBuilder(1, DataType.INT32, 1); - EvioEvent ev = eb.getEvent(); - int[] dat = new int[24]; - try { - ev.appendIntData(dat); - bucket.writeEvent(ev); - } catch (EvioException ex) { - Logger.getLogger(EvioDataBucket.class.getName()).log(Level.SEVERE, null, ex); - } - //EvioDataEvent event = EvioFactory.createEvioEvent(); - //bucket.writeEvent(event.getEventBuffer()); - } - - bucket.show(); - - EvioDataBucket rb = new EvioDataBucket(bucket.getEventArray(), ByteOrder.LITTLE_ENDIAN); - } -} diff --git a/common-tools/clas-io/src/main/java/org/jlab/io/evio/EvioDataChain.java b/common-tools/clas-io/src/main/java/org/jlab/io/evio/EvioDataChain.java deleted file mode 100644 index db87c1c812..0000000000 --- a/common-tools/clas-io/src/main/java/org/jlab/io/evio/EvioDataChain.java +++ /dev/null @@ -1,139 +0,0 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ -package org.jlab.io.evio; - -import java.io.File; -import java.io.IOException; -import java.nio.ByteBuffer; -import java.util.ArrayList; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.jlab.coda.jevio.EvioCompactReader; -import org.jlab.coda.jevio.EvioException; -import org.jlab.io.base.DataEvent; -import org.jlab.io.base.DataEventList; -import org.jlab.io.base.DataSource; -import org.jlab.utils.FileUtils; - -/** - * - * @author gavalian - */ -public class EvioDataChain { - - private ArrayList fileList = new ArrayList(); - private Integer currentFileNumber = 0; - private Integer currentFileNumberOfEvents = 0; - private Integer currentFilePosition = 0; - private EvioCompactReader reader = null; - private ByteBuffer eventBuffer = null; - private Long printoutTimeLast = (long) 0; - private Boolean printoutEnabled = true; - private Integer readerCount = 0; - private double timeIntervalPrintoutSec = 10.0; - - public EvioDataChain(){ - printoutTimeLast = System.currentTimeMillis(); - } - - public void addDir(String directory){ - this.addDir(directory, "evio"); - } - - public void addDir(String directory, String extension){ - ArrayList list = FileUtils.filesInFolder(new File(directory), extension); - fileList.clear(); - for(String item : list){ - System.out.println("add : " + item); - fileList.add(item); - } - } - - public void addFile(String filename){ - fileList.add(filename); - } - - public void open() { - System.err.println("** OPENNING STREAM WITH FILE # = " + this.fileList.size() - + " **"); - - try { - reader = new EvioCompactReader(fileList.get(0)); - this.currentFileNumberOfEvents = reader.getEventCount(); - this.currentFilePosition = 1; - this.currentFileNumber = 0; - this.readerCount = 0; - } catch (EvioException ex) { - Logger.getLogger(EvioDataChain.class.getName()).log(Level.SEVERE, null, ex); - } catch (IOException ex) { - Logger.getLogger(EvioDataChain.class.getName()).log(Level.SEVERE, null, ex); - } - } - - public boolean hasEvent(){ - if(this.currentFileNumber==this.fileList.size()-1){ - if(this.currentFilePositionthis.timeIntervalPrintoutSec){ - this.printoutTimeLast = System.currentTimeMillis(); - System.out.println(String.format("evio reader : %8.1f events %12d ", - elapsedTime,readerCount)); - } - - if(this.currentFilePosition entryNames = new ArrayList(); - private Map descriptorEntries = new LinkedHashMap(); - private HashMap descriptorProperties = new HashMap(); + private ArrayList entryNames = new ArrayList<>(); + private Map descriptorEntries = new LinkedHashMap<>(); + private HashMap descriptorProperties = new HashMap<>(); public EvioDataDescriptor(String name, String parenttag, String containertag) { this.descriptorName = name; @@ -36,35 +30,23 @@ public EvioDataDescriptor(String format) { this.init(format); } - public void init(String s) { + @Override + public final void init(String s) { descriptorEntries.clear(); String[] tokens = s.split("/"); // System.out.println(" N - tokens = " + tokens.length); String[] header = tokens[0].split(":"); this.descriptorName = header[0] + "::" + header[1]; - String section_name = header[1]; - this.descriptorContainerTag = Integer.parseInt(header[2]); - this.descriptorContainerNum = Integer.parseInt(header[3]); + this.descriptorContainerTag = Integer.valueOf(header[2]); + this.descriptorContainerNum = Integer.valueOf(header[3]); this.descriptorProperties.put("parent_tag", header[2]); this.descriptorProperties.put("container_tag", header[3]); - Integer sectionTag = Integer.parseInt(header[3]); + Integer sectionTag = Integer.valueOf(header[3]); for (int loop = 1; loop < tokens.length; loop++) { String[] entryParams = tokens[loop].split(":"); - this.addEntry(this.descriptorName, entryParams[0], sectionTag, Integer.parseInt(entryParams[1]), entryParams[2]); + this.addEntry(this.descriptorName, entryParams[0], sectionTag, Integer.valueOf(entryParams[1]), entryParams[2]); } - /* - * descriptorName = tokens[0]; - * - * descriptorContainerTag = Integer.parseInt(tokens[1]); descriptorContainerNum = Integer.parseInt(tokens[2]); ArrayList nnn = new - * ArrayList(); for(int loop = 3 ; loop < tokens.length; loop+=4){ nnn.add(tokens[loop]); descriptorEntries.put(tokens[loop], new - * EvioDataDescriptorEntry("generic",tokens[loop], Integer.parseInt(tokens[loop+1]), Integer.parseInt(tokens[loop+2]), tokens[loop+3] )); } - */ - // entryNames = new String[nnn.size()]; - // for(int loop = 0; loop < nnn.size(); loop++){ - // entryNames[loop] = nnn.get(loop); - // } - // entryNames = (String[]) nnn.toArray(); } public void addEntry(String section, String name, Integer tag, Integer num, String type) { @@ -72,6 +54,7 @@ public void addEntry(String section, String name, Integer tag, Integer num, Stri entryNames.add(name); } + @Override public String[] getEntryList() { // return entryNames; String[] entries = new String[descriptorEntries.size()]; @@ -81,10 +64,12 @@ public String[] getEntryList() { return entries; } + @Override public String getName() { return descriptorName; } + @Override public int getProperty(String property_name, String entry_name) { int ret = -1; if (descriptorEntries.containsKey(entry_name) == false) { @@ -107,6 +92,7 @@ public int getProperty(String property_name, String entry_name) { return ret; } + @Override public int getProperty(String property_name) { if (property_name.equals("tag") == true) { return descriptorContainerTag; @@ -117,6 +103,7 @@ public int getProperty(String property_name) { return 0; } + @Override public void show() { System.out.println("\n\n>>> BANK name = " + this.getName() + " tag = " + this.getPropertyString("parent_tag")); String[] entry_names = this.getEntryList(); @@ -132,12 +119,14 @@ public void show() { table.show(); } + @Override public String getXML() { StringBuilder str = new StringBuilder(); return str.toString(); } + @Override public void setPropertyString(String name, String value) { if (descriptorProperties.containsKey(name) == true) { descriptorProperties.remove(name); @@ -145,6 +134,7 @@ public void setPropertyString(String name, String value) { descriptorProperties.put(name, value); } + @Override public String getPropertyString(String property_name) { if (descriptorProperties.containsKey(property_name) == true) { return descriptorProperties.get(property_name); @@ -160,8 +150,6 @@ public String toString() { str.append(this.descriptorProperties.get("parent_tag")); str.append(":"); str.append(this.descriptorProperties.get("container_tag")); - - // for(Map.Entry entry : this.descriptorEntries.entrySet()){ for (String item : this.getEntryList()) { str.append("/"); str.append(this.descriptorEntries.get(item).name); @@ -173,23 +161,26 @@ public String toString() { return str.toString(); } - public static void main(String[] args) { - EvioDataDescriptor desc = new EvioDataDescriptor("DC::true", "120", "0"); - desc.init("DC:true:1200:1201/sector:1:float64/layer:2:int64/wire:3:int64"); - desc.show(); - System.out.println(desc); - EvioDataDescriptor desc2 = new EvioDataDescriptor(desc.toString()); - desc2.show(); - } - + @Override public boolean hasEntry(String entry) { return this.descriptorEntries.containsKey(entry); } + @Override public boolean hasEntries(String... entries) { for (String item : entries) if (this.hasEntry(item) == false) return false; return true; } + + public static void main(String[] args) { + EvioDataDescriptor desc = new EvioDataDescriptor("DC::true", "120", "0"); + desc.init("DC:true:1200:1201/sector:1:float64/layer:2:int64/wire:3:int64"); + desc.show(); + System.out.println(desc); + EvioDataDescriptor desc2 = new EvioDataDescriptor(desc.toString()); + desc2.show(); + } + } diff --git a/common-tools/clas-io/src/main/java/org/jlab/io/evio/EvioDataDescriptorEntry.java b/common-tools/clas-io/src/main/java/org/jlab/io/evio/EvioDataDescriptorEntry.java index dfb024d081..d69a764654 100644 --- a/common-tools/clas-io/src/main/java/org/jlab/io/evio/EvioDataDescriptorEntry.java +++ b/common-tools/clas-io/src/main/java/org/jlab/io/evio/EvioDataDescriptorEntry.java @@ -1,9 +1,3 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ - package org.jlab.io.evio; import org.jlab.io.base.DataEntryType; diff --git a/common-tools/clas-io/src/main/java/org/jlab/io/evio/EvioDataDictionary.java b/common-tools/clas-io/src/main/java/org/jlab/io/evio/EvioDataDictionary.java index de03331989..1129c8a18b 100644 --- a/common-tools/clas-io/src/main/java/org/jlab/io/evio/EvioDataDictionary.java +++ b/common-tools/clas-io/src/main/java/org/jlab/io/evio/EvioDataDictionary.java @@ -20,8 +20,8 @@ */ public class EvioDataDictionary implements DataDictionary { - Logger LOGGER = Logger.getLogger(EvioDataDictionary.class.getName()); - private HashMap descriptors = new HashMap(); + static final Logger LOGGER = Logger.getLogger(EvioDataDictionary.class.getName()); + private HashMap descriptors = new HashMap<>(); public EvioDataDictionary() { @@ -35,26 +35,28 @@ public EvioDataDictionary(String directory) { this.initWithDir(directory); } + @Override public void init(String format) { } + @Override public String getXML() { return "some xml"; } + @Override public String[] getDescriptorList() { String[] names = new String[descriptors.keySet().size()]; - // ArrayList array = new ArrayList(); int icounter = 0; for (String key : descriptors.keySet()) { names[icounter] = key; icounter++; } return names; - // throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } + @Override public DataDescriptor getDescriptor(String desc_name) { if (descriptors.containsKey(desc_name) == true) { return descriptors.get(desc_name); @@ -81,10 +83,10 @@ public final void initWithEnv(String envname) { } public final void initWithDir(String dirname) { - ArrayList ignorePrefixes = new ArrayList(); + ArrayList ignorePrefixes = new ArrayList<>(); ignorePrefixes.add("."); ignorePrefixes.add("_"); - LOGGER.log(Level.INFO,"[EvioDataDictionary]---> loading bankdefs from directory : " + dirname); + LOGGER.log(Level.INFO, "[EvioDataDictionary]---> loading bankdefs from directory : {0}", dirname); File dict_dir = new File(dirname); if (dict_dir.exists() == false) { @@ -93,33 +95,24 @@ public final void initWithDir(String dirname) { } ArrayList xmlFileList = FileUtils.filesInFolder(dict_dir, "xml", ignorePrefixes); - LOGGER.log(Level.INFO,"[EvioDataDictionary]------> number of XML files located : " + xmlFileList.size()); + LOGGER.log(Level.INFO, "[EvioDataDictionary]------> number of XML files located : {0}", xmlFileList.size()); Integer counter = 0; for (String file : xmlFileList) { ArrayList descList = DictionaryLoader.getDescriptorsFromFile(file); - // ArrayList descList = DictionaryLoader.descriptorParseXMLtoString(file); for (EvioDataDescriptor desc : descList) { descriptors.put(desc.getName(), desc); - // System.out.println(" rev = " + counter + " desc = " + desc.getName()); - // ArrayList descList = - // EvioDataDescriptor desc = new EvioDataDescriptor(); - // desc.init(format); - // descriptors.put(desc.getName(), desc); counter++; } } - LOGGER.log(Level.INFO,"[EvioDataDictionary]--> total number of descriptors found : " + counter.toString()); + LOGGER.log(Level.INFO, "[EvioDataDictionary]--> total number of descriptors found : {0}", counter.toString()); } public void show() { TablePrintout table = new TablePrintout("Bank:Columns:Tag:Number", "42:8:8:8"); for (Map.Entry entry : descriptors.entrySet()) { - // System.out.println(" step 1 "); String name = entry.getKey(); String[] info = new String[4]; - // System.out.println(" step 2 "); info[0] = name; - // System.out.println(" step 3 "); Integer nentries = descriptors.get(name).getEntryList().length; info[1] = nentries.toString(); Integer tag = descriptors.get(name).getProperty("tag"); @@ -155,16 +148,17 @@ public String getNameByTagNum(int tag, int num) { } } if (desc.getValue().getProperty("tag", entryname) == tag && desc.getValue().getProperty("num", entryname) == num) { - return new String(desc.getKey() + "." + entryname); + return desc.getKey() + "." + entryname; } } } return name; } + @Override public DataBank createBank(String name, int rows) { if (descriptors.containsKey(name) == false) { - LOGGER.log(Level.SEVERE,"[EvioDataDictionary]:: ERROR ---> no descriptor with name = " + name + " is found"); + LOGGER.log(Level.SEVERE, "[EvioDataDictionary]:: ERROR ---> no descriptor with name = {0} is found", name); } EvioDataDescriptor desc = descriptors.get(name); EvioDataBank bank = new EvioDataBank(desc); diff --git a/common-tools/clas-io/src/main/java/org/jlab/io/evio/EvioDataEvent.java b/common-tools/clas-io/src/main/java/org/jlab/io/evio/EvioDataEvent.java index e1a5264b2b..7228a3a9e9 100644 --- a/common-tools/clas-io/src/main/java/org/jlab/io/evio/EvioDataEvent.java +++ b/common-tools/clas-io/src/main/java/org/jlab/io/evio/EvioDataEvent.java @@ -3,6 +3,7 @@ import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.List; @@ -28,873 +29,724 @@ public class EvioDataEvent implements DataEvent { - private HashMap eventProperties = new HashMap(); - private ByteBuffer evioBuffer; - private EvioCompactStructureHandler structure = null; - private EvioDataEventHandler eventHandler = null; - private EvioDataDictionary dictionary = null; - private List eventNodes = null; - private DataEventType eventType = DataEventType.EVENT_ACCUMULATE; - - public EvioDataEvent(byte[] buffer, ByteOrder b_order) { - - evioBuffer = ByteBuffer.wrap(buffer); - evioBuffer.order(b_order); - eventHandler = new EvioDataEventHandler(evioBuffer); - /* - * try { structure = new EvioCompactStructureHandler(evioBuffer,DataType.BANK); eventNodes = structure.getChildNodes(); } catch (EvioException ex) { - * Logger.getLogger(EvioDataEvent.class.getName()).log(Level.SEVERE, null, ex); } - */ - - } - - public EvioDataEvent(ByteBuffer buff) { - evioBuffer = buff; - eventHandler = new EvioDataEventHandler(evioBuffer); - /* - * try { structure = new EvioCompactStructureHandler(evioBuffer,DataType.BANK); eventNodes = structure.getChildNodes(); } catch (EvioException ex) { - * Logger.getLogger(EvioDataEvent.class.getName()).log(Level.SEVERE, null, ex); } - */ - } - - public EvioDataEvent(ByteBuffer buff, EvioDataDictionary dict) { - evioBuffer = buff; - dictionary = dict; - eventHandler = new EvioDataEventHandler(evioBuffer); - /* - * try { structure = new EvioCompactStructureHandler(evioBuffer,DataType.BANK); eventNodes = structure.getChildNodes(); } catch (EvioException ex) { - * Logger.getLogger(EvioDataEvent.class.getName()).log(Level.SEVERE, null, ex); } - */ - } - - public ByteOrder getByteOrder() { - return this.eventHandler.getStructure().getByteBuffer().order(); - } - - public EvioDataEvent(byte[] buffer, ByteOrder b_order, EvioDataDictionary dict) { - evioBuffer = ByteBuffer.wrap(buffer); - evioBuffer.order(b_order); - this.eventHandler = new EvioDataEventHandler(buffer, b_order); - /* - * try { structure = new EvioCompactStructureHandler(evioBuffer,DataType.BANK); eventNodes = structure.getChildNodes(); } catch (EvioException ex) { - * Logger.getLogger(EvioDataEvent.class.getName()).log(Level.SEVERE, null, ex); } - */ - dictionary = dict; - this.setProperty("banks", "*"); - this.setProperty("variables", "*"); - } - - public String[] getBankList() { - try { - // TODO Auto-generated method stub - List nodes = this.eventHandler.getStructure().getNodes(); - ArrayList list = new ArrayList(); - String[] descList = dictionary.getDescriptorList(); - for (EvioNode item : nodes) { - // System.out.println(" TAG-NUM = " + item.getTag() + " " + item.getNum() - // + " " + item.getDataTypeObj()); - if (item.getDataTypeObj() == DataType.ALSOBANK && item.getNum() == 0) { - for (String di : descList) { - if (Integer.parseInt(dictionary.getDescriptor(di).getPropertyString("container_tag")) == item.getTag()) { - list.add(di); - } - // list.add("[" + item.getTag() + ":" + item.getNum() + "]"); - } - // ((EvioDataBank ) bank).addDoubleBuffer(tag, item.); - } - } - String[] banks = new String[list.size()]; - for (int loop = 0; loop < list.size(); loop++) - banks[loop] = list.get(loop); - return banks; - } catch (EvioException ex) { - Logger.getLogger(EvioDataEvent.class.getName()).log(Level.SEVERE, null, ex); - } - return null; - } - - public EvioCompactStructureHandler getStructureHandler() { - // this.eventHandler.getStructure(); - return this.eventHandler.getStructure(); - } - - public EvioDataEventHandler getHandler() { - return this.eventHandler; - } - - public void initEvent(ByteBuffer buffer) { - evioBuffer = buffer; - } - - public String[] getColumnList(String bank_name) { - // TODO Auto-generated method stub - return null; - } - - public DataDictionary getDictionary() { - return this.dictionary; - } - - private int[] getTagNum(String path) { - String[] split_path = path.split("[.]+"); - String bank = split_path[0]; - String col = split_path[1]; - - DataDescriptor desc = this.dictionary.getDescriptor(bank); - int tag = desc.getProperty("tag", col); - int num = desc.getProperty("num", col); - int[] ret = { tag, num }; - return ret; - } - - public float[] getFloat(String path) { - if (path.contains("/") == true) { - String[] tokens = path.split("/"); - return this.getFloat(Integer.parseInt(tokens[0]), Integer.parseInt(tokens[1])); - } else { - int[] tagnum = this.getTagNum(path); - return this.getFloat(tagnum[0], tagnum[1]); - } - // int[] tagnum = this.getTagNum(path); - // return this.getFloat(tagnum[0],tagnum[1]); - } - - public float[] getFloat(int tag, int num) { - EvioNode node = this.getNodeFromTree(tag, num, DataType.FLOAT32); - if (node != null) { - try { - ByteBuffer buffer = this.eventHandler.getStructure().getData(node); - float[] nodedata = ByteDataTransformer.toFloatArray(buffer); - return nodedata; - } catch (EvioException ex) { - Logger.getLogger(EvioDataEvent.class.getName()).log(Level.SEVERE, null, ex); - } - } - return null; - } - - public void setFloat(String path, float[] arr) { - // TODO Auto-generated method stub - - } - - public void appendFloat(String path, float[] arr) { - // TODO Auto-generated method stub - - } - - public int[] getInt(String path) { - if (path.contains("/") == true) { - String[] tokens = path.split("/"); - return this.getInt(Integer.parseInt(tokens[0]), Integer.parseInt(tokens[1])); - } else { - int[] tagnum = this.getTagNum(path); - return this.getInt(tagnum[0], tagnum[1]); - } - } - - public String[] getString(int tag, int num) { - EvioNode node = this.getNodeFromTree(tag, num, DataType.CHARSTAR8); - if (node != null) { - try { - ByteBuffer buffer = this.eventHandler.getStructure().getData(node); - String[] nodedata = ByteDataTransformer.toStringArray(buffer); - return nodedata; - } catch (EvioException ex) { - Logger.getLogger(EvioDataEvent.class.getName()).log(Level.SEVERE, null, ex); - } - } - return null; - } - - public int[] getInt(int tag, int num) { - EvioNode node = this.getNodeFromTree(tag, num, DataType.INT32); - if (node != null) { - try { - ByteBuffer buffer = this.eventHandler.getStructure().getData(node); - int[] nodedata = ByteDataTransformer.toIntArray(buffer); - return nodedata; - } catch (EvioException ex) { - Logger.getLogger(EvioDataEvent.class.getName()).log(Level.SEVERE, null, ex); - } - } - return null; - } + private HashMap eventProperties = new HashMap<>(); + private ByteBuffer evioBuffer; + private EvioDataEventHandler eventHandler = null; + private EvioDataDictionary dictionary = null; + private DataEventType eventType = DataEventType.EVENT_ACCUMULATE; + + public EvioDataEvent(byte[] buffer, ByteOrder b_order) { + evioBuffer = ByteBuffer.wrap(buffer); + evioBuffer.order(b_order); + eventHandler = new EvioDataEventHandler(evioBuffer); + } + + public EvioDataEvent(ByteBuffer buff) { + evioBuffer = buff; + eventHandler = new EvioDataEventHandler(evioBuffer); + } + + public EvioDataEvent(ByteBuffer buff, EvioDataDictionary dict) { + evioBuffer = buff; + dictionary = dict; + eventHandler = new EvioDataEventHandler(evioBuffer); + } + + public ByteOrder getByteOrder() { + return this.eventHandler.getStructure().getByteBuffer().order(); + } + + public EvioDataEvent(byte[] buffer, ByteOrder b_order, EvioDataDictionary dict) { + evioBuffer = ByteBuffer.wrap(buffer); + evioBuffer.order(b_order); + this.eventHandler = new EvioDataEventHandler(buffer, b_order); + dictionary = dict; + this.setProperty("banks", "*"); + this.setProperty("variables", "*"); + } + + @Override + public String[] getBankList() { + try { + List nodes = this.eventHandler.getStructure().getNodes(); + ArrayList list = new ArrayList<>(); + String[] descList = dictionary.getDescriptorList(); + for (EvioNode item : nodes) { + if (item.getDataTypeObj() == DataType.ALSOBANK && item.getNum() == 0) { + for (String di : descList) { + if (Integer.parseInt(dictionary.getDescriptor(di).getPropertyString("container_tag")) == item.getTag()) { + list.add(di); + } + } + } + } + String[] banks = new String[list.size()]; + for (int loop = 0; loop < list.size(); loop++) + banks[loop] = list.get(loop); + return banks; + } catch (EvioException ex) { + Logger.getLogger(EvioDataEvent.class.getName()).log(Level.SEVERE, null, ex); + } + return null; + } + + public EvioCompactStructureHandler getStructureHandler() { + return this.eventHandler.getStructure(); + } + + public EvioDataEventHandler getHandler() { + return this.eventHandler; + } + + public void initEvent(ByteBuffer buffer) { + evioBuffer = buffer; + } + + @Override + public String[] getColumnList(String bank_name) { + return null; + } + + @Override + public DataDictionary getDictionary() { + return this.dictionary; + } + + private int[] getTagNum(String path) { + String[] split_path = path.split("[.]+"); + String bank = split_path[0]; + String col = split_path[1]; + + DataDescriptor desc = this.dictionary.getDescriptor(bank); + int tag = desc.getProperty("tag", col); + int num = desc.getProperty("num", col); + int[] ret = { tag, num }; + return ret; + } + + @Override + public float[] getFloat(String path) { + if (path.contains("/") == true) { + String[] tokens = path.split("/"); + return this.getFloat(Integer.parseInt(tokens[0]), Integer.parseInt(tokens[1])); + } else { + int[] tagnum = this.getTagNum(path); + return this.getFloat(tagnum[0], tagnum[1]); + } + } + + public float[] getFloat(int tag, int num) { + EvioNode node = this.getNodeFromTree(tag, num, DataType.FLOAT32); + if (node != null) { + try { + ByteBuffer buffer = this.eventHandler.getStructure().getData(node); + float[] nodedata = ByteDataTransformer.toFloatArray(buffer); + return nodedata; + } catch (EvioException ex) { + Logger.getLogger(EvioDataEvent.class.getName()).log(Level.SEVERE, null, ex); + } + } + return null; + } + + @Override + public void setFloat(String path, float[] arr) { + } + + @Override + public void appendFloat(String path, float[] arr) { + } + + @Override + public int[] getInt(String path) { + if (path.contains("/") == true) { + String[] tokens = path.split("/"); + return this.getInt(Integer.parseInt(tokens[0]), Integer.parseInt(tokens[1])); + } else { + int[] tagnum = this.getTagNum(path); + return this.getInt(tagnum[0], tagnum[1]); + } + } + + public String[] getString(int tag, int num) { + EvioNode node = this.getNodeFromTree(tag, num, DataType.CHARSTAR8); + if (node != null) { + try { + ByteBuffer buffer = this.eventHandler.getStructure().getData(node); + String[] nodedata = ByteDataTransformer.toStringArray(buffer); + return nodedata; + } catch (EvioException ex) { + Logger.getLogger(EvioDataEvent.class.getName()).log(Level.SEVERE, null, ex); + } + } + return null; + } + + public int[] getInt(int tag, int num) { + EvioNode node = this.getNodeFromTree(tag, num, DataType.INT32); + if (node != null) { + try { + ByteBuffer buffer = this.eventHandler.getStructure().getData(node); + int[] nodedata = ByteDataTransformer.toIntArray(buffer); + return nodedata; + } catch (EvioException ex) { + Logger.getLogger(EvioDataEvent.class.getName()).log(Level.SEVERE, null, ex); + } + } + return null; + } public long[] getLong(int tag, int num) { - EvioNode node = this.getNodeFromTree(tag, num, DataType.LONG64); - if (node != null) { - try { - ByteBuffer buffer = this.eventHandler.getStructure().getData(node); - long[] nodedata = ByteDataTransformer.toLongArray(buffer); - return nodedata; - } catch (EvioException ex) { - Logger.getLogger(EvioDataEvent.class.getName()).log(Level.SEVERE, null, ex); - } - } - return null; - } + EvioNode node = this.getNodeFromTree(tag, num, DataType.LONG64); + if (node != null) { + try { + ByteBuffer buffer = this.eventHandler.getStructure().getData(node); + long[] nodedata = ByteDataTransformer.toLongArray(buffer); + return nodedata; + } catch (EvioException ex) { + Logger.getLogger(EvioDataEvent.class.getName()).log(Level.SEVERE, null, ex); + } + } + return null; + } - public void setInt(String path, int[] arr) { - // TODO Auto-generated method stub - - } - - public void appendInt(String path, int[] arr) { - // TODO Auto-generated method stub - - } - - public short[] getShort(String path) { - int[] tagnum = this.getTagNum(path); - return this.getShort(tagnum[0], tagnum[1]); - } - - public short[] getShort(int tag, int num) { - return null; - } - - public void setShort(String path, short[] arr) { - // TODO Auto-generated method stub - - } - - public void appendShort(String path, short[] arr) { - // TODO Auto-generated method stub - - } - - public byte[] getComposite(int tag, int num) { - EvioNode node = this.getNodeFromTree(tag, num, DataType.COMPOSITE); - if (node != null) { - try { - ByteBuffer buffer = this.eventHandler.getStructure().getData(node); - byte[] nodedata = ByteDataTransformer.toByteArray(buffer); - return nodedata; - } catch (EvioException ex) { - Logger.getLogger(EvioDataEvent.class.getName()).log(Level.SEVERE, null, ex); - } - } - return null; - } - - public boolean hasBank(int tag, int num) { - EvioNode node = this.getNodeFromTree(tag, num, DataType.COMPOSITE); - if (node == null) - return false; - return true; - } - - public boolean hasBank(String bank_name) { - - if (this.dictionary.getDescriptor(bank_name) == null) { - System.err.println("[EvioDataEvent::hasBank] ( ERROR ) ---> " + " there is no descriptor with name " + bank_name); - return false; - } - if (this.eventHandler == null) { - System.out.println("SEVERE ERROR Event handler is NULL"); - return false; - } - - EvioDataDescriptor desc = (EvioDataDescriptor) this.dictionary.getDescriptor(bank_name); - if (desc == null) { - return false; - } - int parenttag = Integer.parseInt(desc.getPropertyString("parent_tag")); - int nodetag = Integer.parseInt(desc.getPropertyString("container_tag")); - // System.out.println("Looking for bank " + bank_name + " TAGS = " + - // parenttag + " / " + nodetag); - - EvioNode parentNode = this.eventHandler.getRootNode(parenttag, 0, DataType.ALSOBANK); - // System.out.println("Looking for bank " + bank_name + " TAGS = " + - // parenttag + " / " + nodetag + " " + parentNode); - // System.out.println("looking for parent tag = " + parenttag); - if (bank_name.compareTo("GenPart::header") == 0 && parentNode != null) - return true; - if (bank_name.compareTo("GenPart::true") == 0 && parentNode != null) - return true; - if (bank_name.compareTo("Lund::header") == 0 && parentNode != null) - return true; - if (bank_name.compareTo("Lund::true") == 0 && parentNode != null) - return true; - if (parentNode == null) - return false; - // System.out.println("ROOT NODE IS FOUND"); - EvioNode leafNode = this.eventHandler.getChildNode(parentNode, nodetag, 0, DataType.ALSOBANK); - if (leafNode == null) - return false; - // System.out.println("CHILD NODE IS FOUND"); - // EvioNode banknode = this.getNodeFromTree(nodetag, 0, DataType.ALSOBANK); - // if(banknode==null) return false; - return true; - } - - public DataBank getBank(String bank_name) { - EvioDataDescriptor desc = (EvioDataDescriptor) this.dictionary.getDescriptor(bank_name); - if (desc == null) - return null; - - int parenttag = Integer.parseInt(desc.getPropertyString("parent_tag")); - int nodetag = Integer.parseInt(desc.getPropertyString("container_tag")); - - EvioNode parentNode = this.eventHandler.getRootNode(parenttag, 0, DataType.ALSOBANK); - if (parentNode == null) - return null; - - EvioNode leafNode = this.eventHandler.getChildNode(parentNode, nodetag, 0, DataType.ALSOBANK); - if (leafNode == null && bank_name.compareTo("GenPart::header") != 0 && bank_name.compareTo("GenPart::true") != 0 + @Override + public void setInt(String path, int[] arr) { + } + + @Override + public void appendInt(String path, int[] arr) { + } + + @Override + public short[] getShort(String path) { + int[] tagnum = this.getTagNum(path); + return this.getShort(tagnum[0], tagnum[1]); + } + + public short[] getShort(int tag, int num) { + return null; + } + + @Override + public void setShort(String path, short[] arr) { + } + + @Override + public void appendShort(String path, short[] arr) { + } + + public byte[] getComposite(int tag, int num) { + EvioNode node = this.getNodeFromTree(tag, num, DataType.COMPOSITE); + if (node != null) { + try { + ByteBuffer buffer = this.eventHandler.getStructure().getData(node); + byte[] nodedata = ByteDataTransformer.toByteArray(buffer); + return nodedata; + } catch (EvioException ex) { + Logger.getLogger(EvioDataEvent.class.getName()).log(Level.SEVERE, null, ex); + } + } + return null; + } + + public boolean hasBank(int tag, int num) { + EvioNode node = this.getNodeFromTree(tag, num, DataType.COMPOSITE); + return node != null; + } + + @Override + public boolean hasBank(String bank_name) { + + if (this.dictionary.getDescriptor(bank_name) == null) { + System.err.println("[EvioDataEvent::hasBank] ( ERROR ) ---> " + " there is no descriptor with name " + bank_name); + return false; + } + if (this.eventHandler == null) { + System.out.println("SEVERE ERROR Event handler is NULL"); + return false; + } + + EvioDataDescriptor desc = (EvioDataDescriptor) this.dictionary.getDescriptor(bank_name); + if (desc == null) { + return false; + } + int parenttag = Integer.parseInt(desc.getPropertyString("parent_tag")); + int nodetag = Integer.parseInt(desc.getPropertyString("container_tag")); + + EvioNode parentNode = this.eventHandler.getRootNode(parenttag, 0, DataType.ALSOBANK); + if (bank_name.compareTo("GenPart::header") == 0 && parentNode != null) + return true; + if (bank_name.compareTo("GenPart::true") == 0 && parentNode != null) + return true; + if (bank_name.compareTo("Lund::header") == 0 && parentNode != null) + return true; + if (bank_name.compareTo("Lund::true") == 0 && parentNode != null) + return true; + if (parentNode == null) + return false; + EvioNode leafNode = this.eventHandler.getChildNode(parentNode, nodetag, 0, DataType.ALSOBANK); + return leafNode != null; + } + + @Override + public DataBank getBank(String bank_name) { + EvioDataDescriptor desc = (EvioDataDescriptor) this.dictionary.getDescriptor(bank_name); + if (desc == null) + return null; + + int parenttag = Integer.parseInt(desc.getPropertyString("parent_tag")); + int nodetag = Integer.parseInt(desc.getPropertyString("container_tag")); + + EvioNode parentNode = this.eventHandler.getRootNode(parenttag, 0, DataType.ALSOBANK); + if (parentNode == null) + return null; + + EvioNode leafNode = this.eventHandler.getChildNode(parentNode, nodetag, 0, DataType.ALSOBANK); + if (leafNode == null && bank_name.compareTo("GenPart::header") != 0 && bank_name.compareTo("GenPart::true") != 0 && bank_name.compareTo("Lund::header") != 0 && bank_name.compareTo("Lund::true") != 0) - return null; + return null; - TreeMap dataTree = null; - if (bank_name.compareTo("GenPart::header") == 0) { - dataTree = this.eventHandler.getNodeData(parentNode); + TreeMap dataTree = null; + if (bank_name.compareTo("GenPart::header") == 0) { + dataTree = this.eventHandler.getNodeData(parentNode); } else if (bank_name.compareTo("GenPart::true") == 0) { - dataTree = this.eventHandler.getNodeData(parentNode); - } else if (bank_name.compareTo("Lund::header") == 0) { - dataTree = this.eventHandler.getNodeData(parentNode); - } else if (bank_name.compareTo("Lund::true") == 0) { - dataTree = this.eventHandler.getNodeData(parentNode); - } else { - dataTree = this.eventHandler.getNodeData(leafNode); - } - - EvioDataBank bank = new EvioDataBank(desc); - String[] entries = desc.getEntryList(); - -// if(bank_name.compareTo("Lund::particles") == 0 || bank_name.compareTo("GenPart::true") == 0) { -// System.out.println("beginning " + bank.rows()+" "+bank.columns()); -// bank.show(); -// } - for (String item : entries) { - // if(item.getValue()<20){ - int type = desc.getProperty("type", item); - int num = desc.getProperty("num", item); -// if(bank_name.compareTo("Lund::particles") == 0 || bank_name.compareTo("GenPart::true") == 0) { -// System.out.println("entry = " + item); -// System.out.println(type + " " + num); -// } - - if (DataEntryType.getType(type) == DataEntryType.INTEGER) { - bank.setInt(item, (int[]) dataTree.get(num)); - } - - if (DataEntryType.getType(type) == DataEntryType.DOUBLE) { - bank.setDouble(item, (double[]) dataTree.get(num)); - } - - if (DataEntryType.getType(type) == DataEntryType.FLOAT) { - bank.setFloat(item, (float[]) dataTree.get(num)); - // System.out.println("ADDING FLOAT VALUE : " + bank_name + " " + item); - } - if (DataEntryType.getType(type) == DataEntryType.SHORT) { - bank.setShort(item, (short[]) dataTree.get(num)); - } - - if (DataEntryType.getType(type) == DataEntryType.BYTE) { - bank.setByte(item, (byte[]) dataTree.get(num)); - // System.out.println("ADDING BYTE VALUE : " + bank_name + " " + item); - } - // } else { - - // } - // System.out.println(item.getKey() + " " + item.getValue() - // + " " + desc.types.get(item.getKey())); -// if(bank_name.compareTo("Lund::particles") == 0 || bank_name.compareTo("GenPart::true") == 0) { -// System.out.println(bank.rows()+" "+bank.columns()); -// bank.show(); -// } - } -// if(bank_name.compareTo("Lund::particles") == 0 || bank_name.compareTo("GenPart::true") == 0) { -// System.out.println("end " + bank.rows()+" "+bank.columns()); -// bank.show(); -// } - return bank; - } - - public void getBank(String bank_name, DataBank bank) { - throw new UnsupportedOperationException("Not supported yet."); // To change body of generated methods, choose Tools | Templates. - } - - public void show() { - - // System.out.println("-----> event show"); - // dictionary.show(); - String[] bankList = this.getBankList(); - /* - * ArrayList bList = new ArrayList(); bList.addAll(Arrays.asList(bankList)); - */ - TablePrintout table = new TablePrintout("bank:nrows:ncols", "48:12:12"); - - if (bankList != null) { - ArrayList bankNames = new ArrayList(); - for (String bank : bankList) { - bankNames.add(bank); - } - - Collections.sort(bankNames); - - for (String bank : bankNames) { - String[] tokens = new String[3]; - tokens[0] = bank; - DataBank dbank = null; - try { - dbank = this.getBank(bank); - } catch (Exception e) { - System.out.println(" ERROR : getbank failed for bank name " + bank); - e.printStackTrace(); - } - if (dbank == null) { - System.err.println("[EvioDataEvent::show] ERROR : bank " + bank + " does not exist"); - continue; - } - Integer ncols = dbank.columns(); - Integer nrows = dbank.rows(); - tokens[1] = nrows.toString(); - tokens[2] = ncols.toString(); - table.addData(tokens); - // System.out.println("BANK [] ---> " + bank); - } - } - table.show(); - } - - public EvioNode getNodeFromTree(int parent_tag, int tag, int num, DataType type) { - /* - * try { List nodes = structure.getChildNodes(); } catch (EvioException ex) { Logger.getLogger(EvioDataEvent.class.getName()).log(Level.SEVERE, - * null, ex); } - */ - return null; - } - - /* - * public EvioNode getChildNode(EvioNode node, int tag, int num, DataType type){ - * - * } - */ - - public EvioNode getNodeFromTree(int tag, int num, DataType type) { - - try { - List nodes = this.eventHandler.getStructure().getNodes(); - - if (nodes == null) { - System.out.println("EVENT NODES = NULL"); - return null; - } - - for (EvioNode item : nodes) { - if (item.getDataTypeObj() == type) { - // System.out.println("parsin node " + item.getTag() + " looking for " + tag ); - } - if (type == DataType.INT32) { - if (item.getTag() == tag && item.getNum() == num - && (item.getDataTypeObj() == DataType.INT32 || item.getDataTypeObj() == DataType.UINT32)) - return item; - } + dataTree = this.eventHandler.getNodeData(parentNode); + } else if (bank_name.compareTo("Lund::header") == 0) { + dataTree = this.eventHandler.getNodeData(parentNode); + } else if (bank_name.compareTo("Lund::true") == 0) { + dataTree = this.eventHandler.getNodeData(parentNode); + } else { + dataTree = this.eventHandler.getNodeData(leafNode); + } + + EvioDataBank bank = new EvioDataBank(desc); + String[] entries = desc.getEntryList(); + + for (String item : entries) { + int type = desc.getProperty("type", item); + int num = desc.getProperty("num", item); + + if (DataEntryType.getType(type) == DataEntryType.INTEGER) { + bank.setInt(item, (int[]) dataTree.get(num)); + } + + if (DataEntryType.getType(type) == DataEntryType.DOUBLE) { + bank.setDouble(item, (double[]) dataTree.get(num)); + } + + if (DataEntryType.getType(type) == DataEntryType.FLOAT) { + bank.setFloat(item, (float[]) dataTree.get(num)); + } + if (DataEntryType.getType(type) == DataEntryType.SHORT) { + bank.setShort(item, (short[]) dataTree.get(num)); + } + + if (DataEntryType.getType(type) == DataEntryType.BYTE) { + bank.setByte(item, (byte[]) dataTree.get(num)); + } + } + return bank; + } + + @Override + public void getBank(String bank_name, DataBank bank) { + throw new UnsupportedOperationException("Not supported yet."); // To change body of generated methods, choose Tools | Templates. + } + + @Override + public void show() { + + String[] bankList = this.getBankList(); + TablePrintout table = new TablePrintout("bank:nrows:ncols", "48:12:12"); + + if (bankList != null) { + ArrayList bankNames = new ArrayList<>(); + bankNames.addAll(Arrays.asList(bankList)); + + Collections.sort(bankNames); + + for (String bank : bankNames) { + String[] tokens = new String[3]; + tokens[0] = bank; + DataBank dbank = null; + try { + dbank = this.getBank(bank); + } catch (Exception e) { + System.out.println(" ERROR : getbank failed for bank name " + bank); + e.printStackTrace(); + } + if (dbank == null) { + System.err.println("[EvioDataEvent::show] ERROR : bank " + bank + " does not exist"); + continue; + } + Integer ncols = dbank.columns(); + Integer nrows = dbank.rows(); + tokens[1] = nrows.toString(); + tokens[2] = ncols.toString(); + table.addData(tokens); + } + } + table.show(); + } + + public EvioNode getNodeFromTree(int parent_tag, int tag, int num, DataType type) { + return null; + } + + public EvioNode getNodeFromTree(int tag, int num, DataType type) { + + try { + List nodes = this.eventHandler.getStructure().getNodes(); + + if (nodes == null) { + System.out.println("EVENT NODES = NULL"); + return null; + } + + for (EvioNode item : nodes) { + if (item.getDataTypeObj() == type) { + } + if (type == DataType.INT32) { + if (item.getTag() == tag && item.getNum() == num + && (item.getDataTypeObj() == DataType.INT32 || item.getDataTypeObj() == DataType.UINT32)) + return item; + } - if(type == DataType.LONG64){ - if (item.getTag() == tag && item.getNum() == num - && (item.getDataTypeObj() == DataType.LONG64 || item.getDataTypeObj() == DataType.ULONG64)) - return item; - } - if (item.getTag() == tag && item.getNum() == num && item.getDataTypeObj() == type) - return item; - /* - * if(item.getTag()==tag&&item.getNum()==num&& item.getDataTypeObj()==type) return item; - */ - } - - } catch (EvioException ex) { - Logger.getLogger(EvioDataEvent.class.getName()).log(Level.SEVERE, null, ex); - } - return null; - } - - public double[] getDouble(int tag, int num) { - EvioNode node = this.getNodeFromTree(tag, num, DataType.DOUBLE64); - if (node != null) { - try { - ByteBuffer buffer = this.eventHandler.getStructure().getData(node); - double[] nodedata = ByteDataTransformer.toDoubleArray(buffer); - return nodedata; - } catch (EvioException ex) { - Logger.getLogger(EvioDataEvent.class.getName()).log(Level.SEVERE, null, ex); - } - } - // double[] ret = {0.0}; - return null; - } - - public double[] getDouble(String path) { - if (path.contains("/") == true) { - String[] tokens = path.split("/"); - return this.getDouble(Integer.parseInt(tokens[0]), Integer.parseInt(tokens[1])); - } else { - int[] tagnum = this.getTagNum(path); - return this.getDouble(tagnum[0], tagnum[1]); - } - } - - public void setDouble(String path, double[] arr) { - throw new UnsupportedOperationException("Not supported yet."); // To change body of generated methods, choose Tools | Templates. - } - - public void appendDouble(String path, double[] arr) { - throw new UnsupportedOperationException("Not supported yet."); // To change body of generated methods, choose Tools | Templates. - } - - public void appendGeneratedBank(DataBank bank) { - // System.err.println("---------> 1"); - String parent_tag = bank.getDescriptor().getPropertyString("parent_tag"); - String container_tag = bank.getDescriptor().getPropertyString("container_tag"); - // System.err.println("---------> 2"); - EvioEvent baseBank = new EvioEvent(Integer.parseInt(parent_tag), DataType.ALSOBANK, 0); - // System.err.println("---------> 3"); - EvioBank sectionBank = new EvioBank(Integer.parseInt(container_tag), DataType.ALSOBANK, 0); - // System.err.println("---------> 4"); - - EventBuilder builder = new EventBuilder(baseBank); - - ByteOrder byteOrder = this.eventHandler.getStructure().getByteBuffer().order(); - - baseBank.setByteOrder(byteOrder); - sectionBank.setByteOrder(byteOrder); - // doubleBank.setByteOrder(byteOrder); - // System.err.println("------------ adding bank "); - // System.err.println("------------ adding bank " + bank.getDescriptor().getName()); - try { - String[] entries = bank.getDescriptor().getEntryList(); - for (String entry : entries) { - // System.out.println("----> adding entry " + entry); - int e_tag = bank.getDescriptor().getProperty("tag", entry); - int e_num = bank.getDescriptor().getProperty("num", entry); - int e_typ = bank.getDescriptor().getProperty("type", entry); - if (DataEntryType.getType(e_typ) == DataEntryType.INTEGER) { - EvioBank dataBank = new EvioBank(e_tag, DataType.INT32, e_num); - dataBank.setByteOrder(byteOrder); - dataBank.appendIntData(bank.getInt(entry)); - builder.addChild(baseBank, dataBank); - } - - if (DataEntryType.getType(e_typ) == DataEntryType.DOUBLE) { - EvioBank dataBank = new EvioBank(e_tag, DataType.DOUBLE64, e_num); - dataBank.setByteOrder(byteOrder); - dataBank.appendDoubleData(bank.getDouble(entry)); - builder.addChild(baseBank, dataBank); - } - - if (DataEntryType.getType(e_typ) == DataEntryType.FLOAT) { - EvioBank dataBank = new EvioBank(e_tag, DataType.FLOAT32, e_num); - dataBank.setByteOrder(byteOrder); - dataBank.appendFloatData(bank.getFloat(entry)); - builder.addChild(baseBank, dataBank); - } - - if (DataEntryType.getType(e_typ) == DataEntryType.SHORT) { - EvioBank dataBank = new EvioBank(e_tag, DataType.SHORT16, e_num); - dataBank.setByteOrder(byteOrder); - dataBank.appendShortData(bank.getShort(entry)); - builder.addChild(baseBank, dataBank); - } - - if (DataEntryType.getType(e_typ) == DataEntryType.BYTE) { - EvioBank dataBank = new EvioBank(e_tag, DataType.CHAR8, e_num); - dataBank.setByteOrder(byteOrder); - dataBank.appendByteData(bank.getByte(entry)); - builder.addChild(baseBank, dataBank); - } - } - - // builder.addChild(baseBank, sectionBank); - - int byteSize = baseBank.getTotalBytes(); - ByteBuffer bb = ByteBuffer.allocate(byteSize); - // System.out.println("-------> adding bank " + bank.getDescriptor().getName() - // + " size = " + byteSize); - bb.order(byteOrder); - baseBank.write(bb); - bb.flip(); - // System.out.println("-----> prior size = " + structure.getByteBuffer().limit()); - ByteBuffer newBuffer = this.eventHandler.getStructure().addStructure(bb); - // System.out.println("---> new byte buffer has size " + newBuffer.limit() - // + " changed from " + structure.getByteBuffer().limit()); - // structure. - EvioCompactStructureHandler handler = - new EvioCompactStructureHandler(this.eventHandler.getStructure().getByteBuffer(), DataType.BANK); - this.eventHandler.setStructure(handler); - /* - * for (Map.Entry bank : integerContainer.entrySet()) { EvioBank dataBank = new EvioBank(tag, DataType.INT32, bank.getKey()); - * dataBank.setByteOrder(byteOrder); dataBank.appendIntData(bank.getValue()); builder.addChild(intBank, dataBank); } - * - * for (Entry bank : doubleBanks.entrySet()) { EvioBank dataBank = new EvioBank(tag, DataType.DOUBLE64, bank.getKey()); - * dataBank.setByteOrder(byteOrder); dataBank.appendDoubleData(bank.getValue()); builder.addChild(doubleBank, dataBank); } - */ - } catch (EvioException e) { - e.printStackTrace(); - } - } - - public void appendBank(DataBank bank) { - // System.err.println("---------> 1"); - String parent_tag = bank.getDescriptor().getPropertyString("parent_tag"); - String container_tag = bank.getDescriptor().getPropertyString("container_tag"); - // System.err.println("---------> 2"); - EvioEvent baseBank = new EvioEvent(Integer.parseInt(parent_tag), DataType.ALSOBANK, 0); - // System.err.println("---------> 3"); - EvioBank sectionBank = new EvioBank(Integer.parseInt(container_tag), DataType.ALSOBANK, 0); - // System.err.println("---------> 4"); - - EventBuilder builder = new EventBuilder(baseBank); - - ByteOrder byteOrder = this.eventHandler.getStructure().getByteBuffer().order(); - - baseBank.setByteOrder(byteOrder); - sectionBank.setByteOrder(byteOrder); - // doubleBank.setByteOrder(byteOrder); - // System.err.println("------------ adding bank "); - // System.err.println("------------ adding bank " + bank.getDescriptor().getName()); - try { - String[] entries = bank.getDescriptor().getEntryList(); - for (String entry : entries) { - // System.out.println("----> adding entry " + entry); - int e_tag = bank.getDescriptor().getProperty("tag", entry); - int e_num = bank.getDescriptor().getProperty("num", entry); - int e_typ = bank.getDescriptor().getProperty("type", entry); - if (DataEntryType.getType(e_typ) == DataEntryType.INTEGER) { - EvioBank dataBank = new EvioBank(e_tag, DataType.INT32, e_num); - dataBank.setByteOrder(byteOrder); - dataBank.appendIntData(bank.getInt(entry)); - builder.addChild(sectionBank, dataBank); - } - - if (DataEntryType.getType(e_typ) == DataEntryType.DOUBLE) { - EvioBank dataBank = new EvioBank(e_tag, DataType.DOUBLE64, e_num); - dataBank.setByteOrder(byteOrder); - dataBank.appendDoubleData(bank.getDouble(entry)); - builder.addChild(sectionBank, dataBank); - } - - if (DataEntryType.getType(e_typ) == DataEntryType.FLOAT) { - EvioBank dataBank = new EvioBank(e_tag, DataType.FLOAT32, e_num); - dataBank.setByteOrder(byteOrder); - dataBank.appendFloatData(bank.getFloat(entry)); - builder.addChild(sectionBank, dataBank); - } - - if (DataEntryType.getType(e_typ) == DataEntryType.SHORT) { - EvioBank dataBank = new EvioBank(e_tag, DataType.SHORT16, e_num); - dataBank.setByteOrder(byteOrder); - dataBank.appendShortData(bank.getShort(entry)); - builder.addChild(sectionBank, dataBank); - } - - if (DataEntryType.getType(e_typ) == DataEntryType.BYTE) { - EvioBank dataBank = new EvioBank(e_tag, DataType.CHAR8, e_num); - dataBank.setByteOrder(byteOrder); - dataBank.appendByteData(bank.getByte(entry)); - builder.addChild(sectionBank, dataBank); - } - } - - builder.addChild(baseBank, sectionBank); - - int byteSize = baseBank.getTotalBytes(); - ByteBuffer bb = ByteBuffer.allocate(byteSize); - // System.out.println("-------> adding bank " + bank.getDescriptor().getName() - // + " size = " + byteSize); - bb.order(byteOrder); - baseBank.write(bb); - bb.flip(); - // System.out.println("-----> prior size = " + structure.getByteBuffer().limit()); - ByteBuffer newBuffer = this.eventHandler.getStructure().addStructure(bb); - // System.out.println("---> new byte buffer has size " + newBuffer.limit() - // + " changed from " + structure.getByteBuffer().limit()); - // structure. - EvioCompactStructureHandler handler = - new EvioCompactStructureHandler(this.eventHandler.getStructure().getByteBuffer(), DataType.BANK); - this.eventHandler.setStructure(handler); - /* - * for (Map.Entry bank : integerContainer.entrySet()) { EvioBank dataBank = new EvioBank(tag, DataType.INT32, bank.getKey()); - * dataBank.setByteOrder(byteOrder); dataBank.appendIntData(bank.getValue()); builder.addChild(intBank, dataBank); } - * - * for (Entry bank : doubleBanks.entrySet()) { EvioBank dataBank = new EvioBank(tag, DataType.DOUBLE64, bank.getKey()); - * dataBank.setByteOrder(byteOrder); dataBank.appendDoubleData(bank.getValue()); builder.addChild(doubleBank, dataBank); } - */ - } catch (EvioException e) { - e.printStackTrace(); - } - - } - - public ByteBuffer getEventBuffer() { - return this.eventHandler.getStructure().getByteBuffer(); - } - - public void setProperty(String property, String value) { - if (eventProperties.containsKey(property) == true) { - eventProperties.remove(property); - } - eventProperties.put(property, value); - } - - public String getProperty(String property) { - throw new UnsupportedOperationException("Not supported yet."); // To change body of generated methods, choose Tools | Templates. - } - - public byte[] getByte(int tag, int num) { - EvioNode node = this.getNodeFromTree(tag, num, DataType.CHAR8); - if (node != null) { - try { - ByteBuffer buffer = this.eventHandler.getStructure().getData(node); - byte[] nodedata = ByteDataTransformer.toByteArray(buffer); - return nodedata; - } catch (EvioException ex) { - Logger.getLogger(EvioDataEvent.class.getName()).log(Level.SEVERE, null, ex); - } - } - // byte[] ret = {0}; - return null; - } - - public byte[] getByte(String path) { - if (path.contains("/") == true) { - String[] tokens = path.split("/"); - return this.getByte(Integer.parseInt(tokens[0]), Integer.parseInt(tokens[1])); - } else { - int[] tagnum = this.getTagNum(path); - return this.getByte(tagnum[0], tagnum[1]); - } - // throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } - - public void setByte(String path, byte[] arr) { - throw new UnsupportedOperationException("Not supported yet."); // To change body of generated methods, choose Tools | Templates. - } - - public void appendByte(String path, byte[] arr) { - throw new UnsupportedOperationException("Not supported yet."); // To change body of generated methods, choose Tools | Templates. - } - - public void copyEvent(EvioDataEvent event) { - byte[] eventBytes = event.getEventBuffer().array(); - this.eventHandler = new EvioDataEventHandler(eventBytes, event.getByteOrder()); - } - - public void appendBanks(DataBank... banklist) { - - String common_tag = banklist[0].getDescriptor().getPropertyString("parent_tag"); - Boolean check = true; - for (int loop = 0; loop < banklist.length; loop++) { - String btag = banklist[loop].getDescriptor().getPropertyString("parent_tag"); - if (btag.compareTo(common_tag) != 0) - check = false; - } - - // System.out.println("Bank consistency check = " + check); - - String parent_tag = common_tag; - - try { - - EvioEvent baseBank = new EvioEvent(Integer.parseInt(parent_tag), DataType.ALSOBANK, 0); - ByteOrder byteOrder = this.eventHandler.getStructure().getByteBuffer().order(); - baseBank.setByteOrder(byteOrder); - EventBuilder builder = new EventBuilder(baseBank); - - for (DataBank bank : banklist) { - String container_tag = bank.getDescriptor().getPropertyString("container_tag"); - // System.err.println("---------> 2"); - - // System.err.println("---------> 3"); - EvioBank sectionBank = new EvioBank(Integer.parseInt(container_tag), DataType.ALSOBANK, 0); - // System.err.println("---------> 4"); - - sectionBank.setByteOrder(byteOrder); - // doubleBank.setByteOrder(byteOrder); - // System.err.println("------------ adding bank "); - // System.err.println("------------ adding bank " + bank.getDescriptor().getName()); - - String[] entries = bank.getDescriptor().getEntryList(); - for (String entry : entries) { - // System.out.println("----> adding entry " + entry); - int e_tag = bank.getDescriptor().getProperty("tag", entry); - int e_num = bank.getDescriptor().getProperty("num", entry); - int e_typ = bank.getDescriptor().getProperty("type", entry); - if (DataEntryType.getType(e_typ) == DataEntryType.INTEGER) { - EvioBank dataBank = new EvioBank(e_tag, DataType.INT32, e_num); - dataBank.setByteOrder(byteOrder); - dataBank.appendIntData(bank.getInt(entry)); - builder.addChild(sectionBank, dataBank); - } - - if (DataEntryType.getType(e_typ) == DataEntryType.DOUBLE) { - EvioBank dataBank = new EvioBank(e_tag, DataType.DOUBLE64, e_num); - dataBank.setByteOrder(byteOrder); - dataBank.appendDoubleData(bank.getDouble(entry)); - builder.addChild(sectionBank, dataBank); - } - - if (DataEntryType.getType(e_typ) == DataEntryType.FLOAT) { - EvioBank dataBank = new EvioBank(e_tag, DataType.FLOAT32, e_num); - dataBank.setByteOrder(byteOrder); - dataBank.appendFloatData(bank.getFloat(entry)); - builder.addChild(sectionBank, dataBank); - } - - if (DataEntryType.getType(e_typ) == DataEntryType.SHORT) { - EvioBank dataBank = new EvioBank(e_tag, DataType.SHORT16, e_num); - dataBank.setByteOrder(byteOrder); - dataBank.appendShortData(bank.getShort(entry)); - builder.addChild(sectionBank, dataBank); - } - - if (DataEntryType.getType(e_typ) == DataEntryType.BYTE) { - EvioBank dataBank = new EvioBank(e_tag, DataType.CHAR8, e_num); - dataBank.setByteOrder(byteOrder); - dataBank.appendByteData(bank.getByte(entry)); - builder.addChild(sectionBank, dataBank); - } - } - - builder.addChild(baseBank, sectionBank); - } - - int byteSize = baseBank.getTotalBytes(); - ByteBuffer bb = ByteBuffer.allocate(byteSize); - // System.out.println("-------> adding bank " + bank.getDescriptor().getName() - // + " size = " + byteSize); - bb.order(byteOrder); - baseBank.write(bb); - bb.flip(); - // System.out.println("-----> prior size = " + structure.getByteBuffer().limit()); - ByteBuffer newBuffer = this.eventHandler.getStructure().addStructure(bb); - // System.out.println("---> new byte buffer has size " + newBuffer.limit() - // + " changed from " + structure.getByteBuffer().limit()); - // structure. - EvioCompactStructureHandler handler = - new EvioCompactStructureHandler(this.eventHandler.getStructure().getByteBuffer(), DataType.BANK); - this.eventHandler.setStructure(handler); - /* - * for (Map.Entry bank : integerContainer.entrySet()) { EvioBank dataBank = new EvioBank(tag, DataType.INT32, bank.getKey()); - * dataBank.setByteOrder(byteOrder); dataBank.appendIntData(bank.getValue()); builder.addChild(intBank, dataBank); } - * - * for (Entry bank : doubleBanks.entrySet()) { EvioBank dataBank = new EvioBank(tag, DataType.DOUBLE64, bank.getKey()); - * dataBank.setByteOrder(byteOrder); dataBank.appendDoubleData(bank.getValue()); builder.addChild(doubleBank, dataBank); } - */ - } catch (EvioException e) { - e.printStackTrace(); - } - } - - public void setType(DataEventType type) { - this.eventType = type; - } - - public DataEventType getType() { - return this.eventType; - } + if(type == DataType.LONG64){ + if (item.getTag() == tag && item.getNum() == num + && (item.getDataTypeObj() == DataType.LONG64 || item.getDataTypeObj() == DataType.ULONG64)) + return item; + } + if (item.getTag() == tag && item.getNum() == num && item.getDataTypeObj() == type) + return item; + } + + } catch (EvioException ex) { + Logger.getLogger(EvioDataEvent.class.getName()).log(Level.SEVERE, null, ex); + } + return null; + } + + public double[] getDouble(int tag, int num) { + EvioNode node = this.getNodeFromTree(tag, num, DataType.DOUBLE64); + if (node != null) { + try { + ByteBuffer buffer = this.eventHandler.getStructure().getData(node); + double[] nodedata = ByteDataTransformer.toDoubleArray(buffer); + return nodedata; + } catch (EvioException ex) { + Logger.getLogger(EvioDataEvent.class.getName()).log(Level.SEVERE, null, ex); + } + } + return null; + } + + @Override + public double[] getDouble(String path) { + if (path.contains("/") == true) { + String[] tokens = path.split("/"); + return this.getDouble(Integer.parseInt(tokens[0]), Integer.parseInt(tokens[1])); + } else { + int[] tagnum = this.getTagNum(path); + return this.getDouble(tagnum[0], tagnum[1]); + } + } + + @Override + public void setDouble(String path, double[] arr) { + throw new UnsupportedOperationException("Not supported yet."); // To change body of generated methods, choose Tools | Templates. + } + + @Override + public void appendDouble(String path, double[] arr) { + throw new UnsupportedOperationException("Not supported yet."); // To change body of generated methods, choose Tools | Templates. + } + + public void appendGeneratedBank(DataBank bank) { + String parent_tag = bank.getDescriptor().getPropertyString("parent_tag"); + String container_tag = bank.getDescriptor().getPropertyString("container_tag"); + EvioEvent baseBank = new EvioEvent(Integer.parseInt(parent_tag), DataType.ALSOBANK, 0); + EvioBank sectionBank = new EvioBank(Integer.parseInt(container_tag), DataType.ALSOBANK, 0); + + EventBuilder builder = new EventBuilder(baseBank); + + ByteOrder byteOrder = this.eventHandler.getStructure().getByteBuffer().order(); + + baseBank.setByteOrder(byteOrder); + sectionBank.setByteOrder(byteOrder); + try { + String[] entries = bank.getDescriptor().getEntryList(); + for (String entry : entries) { + int e_tag = bank.getDescriptor().getProperty("tag", entry); + int e_num = bank.getDescriptor().getProperty("num", entry); + int e_typ = bank.getDescriptor().getProperty("type", entry); + if (DataEntryType.getType(e_typ) == DataEntryType.INTEGER) { + EvioBank dataBank = new EvioBank(e_tag, DataType.INT32, e_num); + dataBank.setByteOrder(byteOrder); + dataBank.appendIntData(bank.getInt(entry)); + builder.addChild(baseBank, dataBank); + } + + if (DataEntryType.getType(e_typ) == DataEntryType.DOUBLE) { + EvioBank dataBank = new EvioBank(e_tag, DataType.DOUBLE64, e_num); + dataBank.setByteOrder(byteOrder); + dataBank.appendDoubleData(bank.getDouble(entry)); + builder.addChild(baseBank, dataBank); + } + + if (DataEntryType.getType(e_typ) == DataEntryType.FLOAT) { + EvioBank dataBank = new EvioBank(e_tag, DataType.FLOAT32, e_num); + dataBank.setByteOrder(byteOrder); + dataBank.appendFloatData(bank.getFloat(entry)); + builder.addChild(baseBank, dataBank); + } + + if (DataEntryType.getType(e_typ) == DataEntryType.SHORT) { + EvioBank dataBank = new EvioBank(e_tag, DataType.SHORT16, e_num); + dataBank.setByteOrder(byteOrder); + dataBank.appendShortData(bank.getShort(entry)); + builder.addChild(baseBank, dataBank); + } + + if (DataEntryType.getType(e_typ) == DataEntryType.BYTE) { + EvioBank dataBank = new EvioBank(e_tag, DataType.CHAR8, e_num); + dataBank.setByteOrder(byteOrder); + dataBank.appendByteData(bank.getByte(entry)); + builder.addChild(baseBank, dataBank); + } + } + + int byteSize = baseBank.getTotalBytes(); + ByteBuffer bb = ByteBuffer.allocate(byteSize); + bb.order(byteOrder); + baseBank.write(bb); + bb.flip(); + ByteBuffer newBuffer = this.eventHandler.getStructure().addStructure(bb); + EvioCompactStructureHandler handler = + new EvioCompactStructureHandler(this.eventHandler.getStructure().getByteBuffer(), DataType.BANK); + this.eventHandler.setStructure(handler); + } catch (EvioException e) { + e.printStackTrace(); + } + } + + @Override + public void appendBank(DataBank bank) { + String parent_tag = bank.getDescriptor().getPropertyString("parent_tag"); + String container_tag = bank.getDescriptor().getPropertyString("container_tag"); + EvioEvent baseBank = new EvioEvent(Integer.parseInt(parent_tag), DataType.ALSOBANK, 0); + EvioBank sectionBank = new EvioBank(Integer.parseInt(container_tag), DataType.ALSOBANK, 0); + + EventBuilder builder = new EventBuilder(baseBank); + + ByteOrder byteOrder = this.eventHandler.getStructure().getByteBuffer().order(); + + baseBank.setByteOrder(byteOrder); + sectionBank.setByteOrder(byteOrder); + try { + String[] entries = bank.getDescriptor().getEntryList(); + for (String entry : entries) { + int e_tag = bank.getDescriptor().getProperty("tag", entry); + int e_num = bank.getDescriptor().getProperty("num", entry); + int e_typ = bank.getDescriptor().getProperty("type", entry); + if (DataEntryType.getType(e_typ) == DataEntryType.INTEGER) { + EvioBank dataBank = new EvioBank(e_tag, DataType.INT32, e_num); + dataBank.setByteOrder(byteOrder); + dataBank.appendIntData(bank.getInt(entry)); + builder.addChild(sectionBank, dataBank); + } + + if (DataEntryType.getType(e_typ) == DataEntryType.DOUBLE) { + EvioBank dataBank = new EvioBank(e_tag, DataType.DOUBLE64, e_num); + dataBank.setByteOrder(byteOrder); + dataBank.appendDoubleData(bank.getDouble(entry)); + builder.addChild(sectionBank, dataBank); + } + + if (DataEntryType.getType(e_typ) == DataEntryType.FLOAT) { + EvioBank dataBank = new EvioBank(e_tag, DataType.FLOAT32, e_num); + dataBank.setByteOrder(byteOrder); + dataBank.appendFloatData(bank.getFloat(entry)); + builder.addChild(sectionBank, dataBank); + } + + if (DataEntryType.getType(e_typ) == DataEntryType.SHORT) { + EvioBank dataBank = new EvioBank(e_tag, DataType.SHORT16, e_num); + dataBank.setByteOrder(byteOrder); + dataBank.appendShortData(bank.getShort(entry)); + builder.addChild(sectionBank, dataBank); + } + + if (DataEntryType.getType(e_typ) == DataEntryType.BYTE) { + EvioBank dataBank = new EvioBank(e_tag, DataType.CHAR8, e_num); + dataBank.setByteOrder(byteOrder); + dataBank.appendByteData(bank.getByte(entry)); + builder.addChild(sectionBank, dataBank); + } + } + + builder.addChild(baseBank, sectionBank); + + int byteSize = baseBank.getTotalBytes(); + ByteBuffer bb = ByteBuffer.allocate(byteSize); + bb.order(byteOrder); + baseBank.write(bb); + bb.flip(); + ByteBuffer newBuffer = this.eventHandler.getStructure().addStructure(bb); + EvioCompactStructureHandler handler = + new EvioCompactStructureHandler(this.eventHandler.getStructure().getByteBuffer(), DataType.BANK); + this.eventHandler.setStructure(handler); + } catch (EvioException e) { + e.printStackTrace(); + } + } + + @Override + public ByteBuffer getEventBuffer() { + return this.eventHandler.getStructure().getByteBuffer(); + } + + @Override + public final void setProperty(String property, String value) { + if (eventProperties.containsKey(property) == true) { + eventProperties.remove(property); + } + eventProperties.put(property, value); + } + + @Override + public String getProperty(String property) { + throw new UnsupportedOperationException("Not supported yet."); // To change body of generated methods, choose Tools | Templates. + } + + public byte[] getByte(int tag, int num) { + EvioNode node = this.getNodeFromTree(tag, num, DataType.CHAR8); + if (node != null) { + try { + ByteBuffer buffer = this.eventHandler.getStructure().getData(node); + byte[] nodedata = ByteDataTransformer.toByteArray(buffer); + return nodedata; + } catch (EvioException ex) { + Logger.getLogger(EvioDataEvent.class.getName()).log(Level.SEVERE, null, ex); + } + } + return null; + } + + @Override + public byte[] getByte(String path) { + if (path.contains("/") == true) { + String[] tokens = path.split("/"); + return this.getByte(Integer.parseInt(tokens[0]), Integer.parseInt(tokens[1])); + } else { + int[] tagnum = this.getTagNum(path); + return this.getByte(tagnum[0], tagnum[1]); + } + } + + @Override + public void setByte(String path, byte[] arr) { + throw new UnsupportedOperationException("Not supported yet."); // To change body of generated methods, choose Tools | Templates. + } + + @Override + public void appendByte(String path, byte[] arr) { + throw new UnsupportedOperationException("Not supported yet."); // To change body of generated methods, choose Tools | Templates. + } + + public void copyEvent(EvioDataEvent event) { + byte[] eventBytes = event.getEventBuffer().array(); + this.eventHandler = new EvioDataEventHandler(eventBytes, event.getByteOrder()); + } + + @Override + public void appendBanks(DataBank... banklist) { + + String parent_tag = banklist[0].getDescriptor().getPropertyString("parent_tag"); + + try { + + EvioEvent baseBank = new EvioEvent(Integer.parseInt(parent_tag), DataType.ALSOBANK, 0); + ByteOrder byteOrder = this.eventHandler.getStructure().getByteBuffer().order(); + baseBank.setByteOrder(byteOrder); + EventBuilder builder = new EventBuilder(baseBank); + + for (DataBank bank : banklist) { + String container_tag = bank.getDescriptor().getPropertyString("container_tag"); + EvioBank sectionBank = new EvioBank(Integer.parseInt(container_tag), DataType.ALSOBANK, 0); + sectionBank.setByteOrder(byteOrder); + + String[] entries = bank.getDescriptor().getEntryList(); + for (String entry : entries) { + int e_tag = bank.getDescriptor().getProperty("tag", entry); + int e_num = bank.getDescriptor().getProperty("num", entry); + int e_typ = bank.getDescriptor().getProperty("type", entry); + if (DataEntryType.getType(e_typ) == DataEntryType.INTEGER) { + EvioBank dataBank = new EvioBank(e_tag, DataType.INT32, e_num); + dataBank.setByteOrder(byteOrder); + dataBank.appendIntData(bank.getInt(entry)); + builder.addChild(sectionBank, dataBank); + } + + if (DataEntryType.getType(e_typ) == DataEntryType.DOUBLE) { + EvioBank dataBank = new EvioBank(e_tag, DataType.DOUBLE64, e_num); + dataBank.setByteOrder(byteOrder); + dataBank.appendDoubleData(bank.getDouble(entry)); + builder.addChild(sectionBank, dataBank); + } + + if (DataEntryType.getType(e_typ) == DataEntryType.FLOAT) { + EvioBank dataBank = new EvioBank(e_tag, DataType.FLOAT32, e_num); + dataBank.setByteOrder(byteOrder); + dataBank.appendFloatData(bank.getFloat(entry)); + builder.addChild(sectionBank, dataBank); + } + + if (DataEntryType.getType(e_typ) == DataEntryType.SHORT) { + EvioBank dataBank = new EvioBank(e_tag, DataType.SHORT16, e_num); + dataBank.setByteOrder(byteOrder); + dataBank.appendShortData(bank.getShort(entry)); + builder.addChild(sectionBank, dataBank); + } + + if (DataEntryType.getType(e_typ) == DataEntryType.BYTE) { + EvioBank dataBank = new EvioBank(e_tag, DataType.CHAR8, e_num); + dataBank.setByteOrder(byteOrder); + dataBank.appendByteData(bank.getByte(entry)); + builder.addChild(sectionBank, dataBank); + } + } + + builder.addChild(baseBank, sectionBank); + } + + int byteSize = baseBank.getTotalBytes(); + ByteBuffer bb = ByteBuffer.allocate(byteSize); + bb.order(byteOrder); + baseBank.write(bb); + bb.flip(); + ByteBuffer newBuffer = this.eventHandler.getStructure().addStructure(bb); + EvioCompactStructureHandler handler = + new EvioCompactStructureHandler(this.eventHandler.getStructure().getByteBuffer(), DataType.BANK); + this.eventHandler.setStructure(handler); + } catch (EvioException e) { + e.printStackTrace(); + } + } + + @Override + public void setType(DataEventType type) { + this.eventType = type; + } + + @Override + public DataEventType getType() { + return this.eventType; + } + + @Override public DataBank createBank(String bank_name, int rows) { return this.dictionary.createBank(bank_name, rows); } @@ -912,12 +764,12 @@ public void removeBanks(String... bankNames) { @Override public long[] getLong(String path) { if (path.contains("/") == true) { - String[] tokens = path.split("/"); - return this.getLong(Integer.parseInt(tokens[0]), Integer.parseInt(tokens[1])); - } else { - int[] tagnum = this.getTagNum(path); - return this.getLong(tagnum[0], tagnum[1]); - } + String[] tokens = path.split("/"); + return this.getLong(Integer.parseInt(tokens[0]), Integer.parseInt(tokens[1])); + } else { + int[] tagnum = this.getTagNum(path); + return this.getLong(tagnum[0], tagnum[1]); + } } @Override diff --git a/common-tools/clas-io/src/main/java/org/jlab/io/evio/EvioDataEventHandler.java b/common-tools/clas-io/src/main/java/org/jlab/io/evio/EvioDataEventHandler.java index cae3f5c028..ef8e7c5953 100644 --- a/common-tools/clas-io/src/main/java/org/jlab/io/evio/EvioDataEventHandler.java +++ b/common-tools/clas-io/src/main/java/org/jlab/io/evio/EvioDataEventHandler.java @@ -1,8 +1,3 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ package org.jlab.io.evio; import java.nio.ByteBuffer; @@ -40,13 +35,11 @@ public EvioDataEventHandler(byte[] buffer, ByteOrder b_order){ //} else { try { structure = new EvioCompactStructureHandler(evioBuffer,DataType.BANK); - //eventNodes = structure.getChildNodes(); eventNodes = structure.getNodes(); } catch (EvioException ex) { Logger.getLogger(EvioDataEvent.class.getName()).log(Level.SEVERE, null, ex); } //} - //this.list(); } public EvioDataEventHandler(ByteBuffer buff){ @@ -57,12 +50,10 @@ public EvioDataEventHandler(ByteBuffer buff){ } catch (EvioException ex) { Logger.getLogger(EvioDataEvent.class.getName()).log(Level.SEVERE, null, ex); } - //this.list(); } public EvioNode getRootNode(int tag, int num, DataType type){ for(EvioNode node : eventNodes){ - //System.out.println(" LOOKING for tag = " + tag + " num = " + num + " type = " + type); if(node.getTag()==tag&&node.getNum()==num&&node.getDataTypeObj()==type){ return node; } @@ -166,7 +157,6 @@ public void list(){ try { childnodes = this.structure.getNodes(); for(EvioNode node : childnodes){ - //for(EvioNode node : this.eventNodes){ System.out.println(String.format(" tag = %8d num = %8d type = %s", node.getTag(),node.getNum(),node.getDataTypeObj())); } diff --git a/common-tools/clas-io/src/main/java/org/jlab/io/evio/EvioDataSync.java b/common-tools/clas-io/src/main/java/org/jlab/io/evio/EvioDataSync.java index cd7093b467..c12f2febbd 100644 --- a/common-tools/clas-io/src/main/java/org/jlab/io/evio/EvioDataSync.java +++ b/common-tools/clas-io/src/main/java/org/jlab/io/evio/EvioDataSync.java @@ -1,13 +1,6 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ - package org.jlab.io.evio; import java.io.File; -import java.io.IOException; import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.nio.file.Path; @@ -19,7 +12,6 @@ import org.jlab.coda.jevio.EventBuilder; import org.jlab.coda.jevio.EventWriter; import org.jlab.coda.jevio.EvioBank; -//import org.jlab.coda.jevio.EvioCompactEventWriter; import org.jlab.coda.jevio.EvioEvent; import org.jlab.coda.jevio.EvioException; import org.jlab.io.base.DataEvent; @@ -29,195 +21,140 @@ * * @author gavalian */ -public class EvioDataSync implements DataSync { - - private String evioOutputDirectory = null; - private String evioOutputFile = null; - private Integer evioCurrentFileNumber = 0; - // private Long maximumBytesToWrite = (long) 1*1024*1024*1024; - private Long maximumBytesToWrite = (long) 1932735283; - private Long maximumRecordsToWrite = (long) 2000000; - private Long currentBytesWritten = (long) 0; - private Long currentRecordsWritten = (long) 0; - private Boolean splitFiles = true; - private ByteOrder writerByteOrder = ByteOrder.LITTLE_ENDIAN; - private EventWriter evioWriter = null; - private String[] CLASDetectors = new String[] { "EC", "PCAL", "FTOF1A", "FTOF1B", "FTOF2", "BST", "CND", "HTCC", "FTCAL", "CTOF" }; - - public EvioDataSync() { - - } - - public EvioDataSync(String filename) { - this.open(filename); - } - - public void setSplit(boolean flag) { - this.splitFiles = flag; - } - - public void open(String filename) { - // this.openFileForWriting(filename); - this.initFileNames(filename); - this.openFileForWriting(); - } - - public void initFileNames(String filename) { - Path filepath = Paths.get(filename); - this.evioOutputFile = filepath.getFileName().toString(); - if (filepath.getParent() == null) { - this.evioOutputDirectory = ""; - } else { - this.evioOutputDirectory = filepath.getParent().toString(); - } - /* - * int extensionIndex = this.evioOutputFile.lastIndexOf("."); if(extensionIndex>=0&&extensionIndex " + this.evioOutputDirectory); - System.out.println("[EvioDataSync] ---> " + this.evioOutputFile); - - } - - private void openFileForWriting() { - StringBuilder str = new StringBuilder(); - if (this.evioOutputDirectory.length() > 2) { - str.append(this.evioOutputDirectory); - str.append("/"); - } - str.append(this.evioOutputFile); - // str.append("."); - // str.append(this.evioCurrentFileNumber); - // str.append(".evio"); - String filename = str.toString(); - String dictionary = "\n" + - // EvioDictionaryGenerator.createDAQDictionary(CLASDetectors) - "\n"; - System.out.println(dictionary); - this.currentBytesWritten = (long) 0; - this.currentRecordsWritten = (long) 0; - File file = new File(filename); - try { - evioWriter = - new EventWriter(new File(filename), dictionary, true); - // writerByteOrder, null, true); - // new EventWriter(file, 1000000, 2, - // ByteOrder.BIG_ENDIAN, null, null); - } catch (EvioException ex) { - Logger.getLogger(EvioDataSync.class.getName()).log(Level.SEVERE, null, ex); - } - } - - public void writeEvent(DataEvent event) { - - if (this.currentBytesWritten > this.maximumBytesToWrite || this.currentRecordsWritten > this.maximumRecordsToWrite) { - this.evioWriter.close(); - this.evioCurrentFileNumber++; - this.openFileForWriting(); - System.out.println("open file # " + this.evioCurrentFileNumber); - } - - try { - // System.err.println("[sync] ---> buffer size = " + event.getEventBuffer().limit()); - ByteBuffer original = event.getEventBuffer(); - Long bufferSize = (long) original.capacity(); - this.currentBytesWritten += bufferSize; - this.currentRecordsWritten++; - ByteBuffer clone = ByteBuffer.allocate(original.capacity()); - clone.order(original.order()); - original.rewind(); - clone.put(original); - original.rewind(); - clone.flip(); - evioWriter.writeEvent(clone); - // event.getEventBuffer().flip(); - - } catch (Exception e){ - System.out.println("Something went wrong with writing"); - } - } - - public void openWithDictionary(String filename, String dictionary) { - File file = new File(filename); - try { - evioWriter = - new EventWriter(new File(filename), null, true); - // new EventWriter(file, 1000000, 2, - // ByteOrder.BIG_ENDIAN, null, null); - } catch (EvioException ex) { - Logger.getLogger(EvioDataSync.class.getName()).log(Level.SEVERE, null, ex); - } - } - - public void close() { - - evioWriter.close(); - } - - public static void writeFileWithDictionary(String inputfile, String outputfile) { - EvioSource reader = new EvioSource(); - reader.open(inputfile); - EvioDataSync writer = new EvioDataSync(); - EvioDataDictionary dict = new EvioDataDictionary("CLAS12DIR", "lib/bankdefs/clas12new/"); - String dictString = dict.getXML(); - - } - - public EvioDataEvent createEvent(EvioDataDictionary dict) { - - try { - // EvioEvent baseBank = new EvioEvent(1, DataType.BANK, 0); - EventBuilder builder = new EventBuilder(1, DataType.BANK, 0); - EvioEvent event = builder.getEvent(); - EvioBank baseBank = new EvioBank(10, DataType.ALSOBANK, 0); - - builder.addChild(event, baseBank); - - ByteOrder byteOrder = writerByteOrder; - - int byteSize = event.getTotalBytes(); - // System.out.println("base bank size = " + byteSize); - ByteBuffer bb = ByteBuffer.allocate(byteSize); - bb.order(byteOrder); - event.write(bb); - bb.flip(); - - return new EvioDataEvent(bb, dict); - } catch (EvioException ex) { - Logger.getLogger(EvioDataSync.class.getName()).log(Level.SEVERE, null, ex); - } - return null; - } - - public DataEvent createEvent() { - - try { - // EvioEvent baseBank = new EvioEvent(1, DataType.BANK, 0); - EventBuilder builder = new EventBuilder(1, DataType.BANK, 0); - EvioEvent event = builder.getEvent(); - EvioBank baseBank = new EvioBank(10, DataType.ALSOBANK, 0); - - builder.addChild(event, baseBank); - - ByteOrder byteOrder = writerByteOrder; - - int byteSize = event.getTotalBytes(); - // System.out.println("base bank size = " + byteSize); - ByteBuffer bb = ByteBuffer.allocate(byteSize); - bb.order(byteOrder); - event.write(bb); - bb.flip(); - - // return new EvioDataEvent(bb); - return new EvioDataEvent(bb, EvioFactory.getDictionary()); - } catch (EvioException ex) { - Logger.getLogger(EvioDataSync.class.getName()).log(Level.SEVERE, null, ex); - } - return null; - } - - public static void main(String[] args) { - String inputfile = args[0]; - - } +public final class EvioDataSync implements DataSync { + + private String evioOutputDirectory = null; + private String evioOutputFile = null; + private Integer evioCurrentFileNumber = 0; + private Long maximumBytesToWrite = (long) 1932735283; + private Long maximumRecordsToWrite = (long) 2000000; + private Long currentBytesWritten = (long) 0; + private Long currentRecordsWritten = (long) 0; + private ByteOrder writerByteOrder = ByteOrder.LITTLE_ENDIAN; + private EventWriter evioWriter = null; + + public EvioDataSync() { + } + + public EvioDataSync(String filename) { + this.open(filename); + } + + public void setSplit(boolean flag) { + } + + @Override + public void open(String filename) { + this.initFileNames(filename); + this.openFileForWriting(); + } + + public void initFileNames(String filename) { + Path filepath = Paths.get(filename); + this.evioOutputFile = filepath.getFileName().toString(); + if (filepath.getParent() == null) { + this.evioOutputDirectory = ""; + } else { + this.evioOutputDirectory = filepath.getParent().toString(); + } + System.out.println("[EvioDataSync] ---> " + this.evioOutputDirectory); + System.out.println("[EvioDataSync] ---> " + this.evioOutputFile); + } + + private void openFileForWriting() { + StringBuilder str = new StringBuilder(); + if (this.evioOutputDirectory.length() > 2) { + str.append(this.evioOutputDirectory); + str.append("/"); + } + str.append(this.evioOutputFile); + String filename = str.toString(); + String dictionary = "\n\n"; + System.out.println(dictionary); + this.currentBytesWritten = (long) 0; + this.currentRecordsWritten = (long) 0; + try { + evioWriter = new EventWriter(new File(filename), dictionary, true); + } catch (EvioException ex) { + Logger.getLogger(EvioDataSync.class.getName()).log(Level.SEVERE, null, ex); + } + } + + @Override + public void writeEvent(DataEvent event) { + + if (this.currentBytesWritten > this.maximumBytesToWrite || this.currentRecordsWritten > this.maximumRecordsToWrite) { + this.evioWriter.close(); + this.evioCurrentFileNumber++; + this.openFileForWriting(); + System.out.println("open file # " + this.evioCurrentFileNumber); + } + + try { + ByteBuffer original = event.getEventBuffer(); + Long bufferSize = (long) original.capacity(); + this.currentBytesWritten += bufferSize; + this.currentRecordsWritten++; + ByteBuffer clone = ByteBuffer.allocate(original.capacity()); + clone.order(original.order()); + original.rewind(); + clone.put(original); + original.rewind(); + clone.flip(); + evioWriter.writeEvent(clone); + } catch (Exception e){ + System.out.println("Something went wrong with writing"); + } + } + + public void openWithDictionary(String filename, String dictionary) { + try { + evioWriter = new EventWriter(new File(filename), null, true); + } catch (EvioException ex) { + Logger.getLogger(EvioDataSync.class.getName()).log(Level.SEVERE, null, ex); + } + } + + @Override + public void close() { + evioWriter.close(); + } + + public EvioDataEvent createEvent(EvioDataDictionary dict) { + try { + EventBuilder builder = new EventBuilder(1, DataType.BANK, 0); + EvioEvent event = builder.getEvent(); + EvioBank baseBank = new EvioBank(10, DataType.ALSOBANK, 0); + builder.addChild(event, baseBank); + ByteOrder byteOrder = writerByteOrder; + int byteSize = event.getTotalBytes(); + ByteBuffer bb = ByteBuffer.allocate(byteSize); + bb.order(byteOrder); + event.write(bb); + bb.flip(); + return new EvioDataEvent(bb, dict); + } catch (EvioException ex) { + Logger.getLogger(EvioDataSync.class.getName()).log(Level.SEVERE, null, ex); + } + return null; + } + + public DataEvent createEvent() { + try { + EventBuilder builder = new EventBuilder(1, DataType.BANK, 0); + EvioEvent event = builder.getEvent(); + EvioBank baseBank = new EvioBank(10, DataType.ALSOBANK, 0); + builder.addChild(event, baseBank); + ByteOrder byteOrder = writerByteOrder; + int byteSize = event.getTotalBytes(); + ByteBuffer bb = ByteBuffer.allocate(byteSize); + bb.order(byteOrder); + event.write(bb); + bb.flip(); + return new EvioDataEvent(bb, EvioFactory.getDictionary()); + } catch (EvioException ex) { + Logger.getLogger(EvioDataSync.class.getName()).log(Level.SEVERE, null, ex); + } + return null; + } } diff --git a/common-tools/clas-io/src/main/java/org/jlab/io/evio/EvioDataWritter.java b/common-tools/clas-io/src/main/java/org/jlab/io/evio/EvioDataWritter.java deleted file mode 100644 index af5b52630c..0000000000 --- a/common-tools/clas-io/src/main/java/org/jlab/io/evio/EvioDataWritter.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ -package org.jlab.io.evio; - -import org.jlab.io.base.DataEvent; -import org.jlab.io.base.DataSync; - -/** - * - * @author gavalian - */ -public class EvioDataWritter implements DataSync { - - - - public void open(String file) { - - } - - public void writeEvent(DataEvent event) { - - } - - public void close() { - - } - - public DataEvent createEvent() { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } - -} diff --git a/common-tools/clas-io/src/main/java/org/jlab/io/evio/EvioDescriptor.java b/common-tools/clas-io/src/main/java/org/jlab/io/evio/EvioDescriptor.java index 7fc744172c..0ee26a1d98 100644 --- a/common-tools/clas-io/src/main/java/org/jlab/io/evio/EvioDescriptor.java +++ b/common-tools/clas-io/src/main/java/org/jlab/io/evio/EvioDescriptor.java @@ -8,105 +8,114 @@ public class EvioDescriptor implements DataDescriptor { - String[] entries; - String name; - int tag; - HashMap nums; - HashMap types; - - public EvioDescriptor(String name, int tag, String[] col_names, HashMap nums, HashMap types) { - this.name = name; - this.tag = tag; - this.entries = col_names; - this.nums = nums; - this.types = types; - } - - public String toString() { - String ret = this.name + " tag: " + this.tag + "\n"; - for (String e : this.entries) { - ret += " " + this.nums.get(e) + " " + e + " (" + this.types.get(e) + ")\n"; - } - return ret; - } - - public String[] getEntryList() { - return this.entries; - } - - public String getName() { - return this.name; - } - - public int getProperty(String property_name, String entry_name) { - int ret = -1; - if ("tag".equals(property_name)) { - ret = tag; - } else if (property_name == "num") { - ret = this.nums.get(entry_name); - } else if (property_name == "type") { - ret = this.types.get(entry_name); - } - return ret; - } - - public int getProperty(String property_name) { - int ret = -1; - if (property_name == "tag") { - ret = tag; - } - return ret; - } - - public void init(String s) { - // do nothing for EVIO - } - - public void show() { - System.out.println("-----> DataBankDescriptor NAME = " + this.name); - TablePrintout table = new TablePrintout("Column:Tag:Number:Type", "24:8:8:8"); - Integer banktag = tag; - for (Map.Entry item : nums.entrySet()) { - String[] tdata = new String[4]; - tdata[0] = item.getKey(); - tdata[1] = banktag.toString(); - tdata[2] = item.getValue().toString(); - tdata[3] = types.get(item.getKey()).toString(); - table.addData(tdata); - /* - * System.out.println(String.format("---------> %12s tag=%5d num=%5d type=%5d", item.getKey(),tag,item.getValue(),types.get(item.getKey()))); - */ - } - table.show(); - } - - public int getType(String name) { - if (this.types.containsKey(name) == true) { - return this.types.get(name); - } - return -1; - } - - public String getXML() { - throw new UnsupportedOperationException("Not supported yet."); // To change body of generated methods, choose Tools | Templates. - } - - public void setPropertyString(String name, String value) { - throw new UnsupportedOperationException("Not supported yet."); // To change body of generated methods, choose Tools | Templates. - } - - public String getPropertyString(String property_name) { - throw new UnsupportedOperationException("Not supported yet."); // To change body of generated methods, choose Tools | Templates. - } - - public boolean hasEntry(String entry) { - return this.types.containsKey(entry); - } - - public boolean hasEntries(String... entries) { - for (String item : entries) - if (this.hasEntry(item) == false) - return false; - return true; - } + String[] entries; + String name; + int tag; + HashMap nums; + HashMap types; + + public EvioDescriptor(String name, int tag, String[] col_names, HashMap nums, HashMap types) { + this.name = name; + this.tag = tag; + this.entries = col_names; + this.nums = nums; + this.types = types; + } + + @Override + public String toString() { + String ret = this.name + " tag: " + this.tag + "\n"; + for (String e : this.entries) { + ret += " " + this.nums.get(e) + " " + e + " (" + this.types.get(e) + ")\n"; + } + return ret; + } + + @Override + public String[] getEntryList() { + return this.entries; + } + + @Override + public String getName() { + return this.name; + } + + @Override + public int getProperty(String property_name, String entry_name) { + int ret = -1; + if (null != property_name) switch (property_name) { + case "tag" -> ret = tag; + case "num" -> ret = this.nums.get(entry_name); + case "type" -> ret = this.types.get(entry_name); + default -> { + } + } + return ret; + } + + @Override + public int getProperty(String property_name) { + int ret = -1; + if ("tag".equals(property_name)) { + ret = tag; + } + return ret; + } + + @Override + public void init(String s) { + // do nothing for EVIO + } + + @Override + public void show() { + System.out.println("-----> DataBankDescriptor NAME = " + this.name); + TablePrintout table = new TablePrintout("Column:Tag:Number:Type", "24:8:8:8"); + Integer banktag = tag; + for (Map.Entry item : nums.entrySet()) { + String[] tdata = new String[4]; + tdata[0] = item.getKey(); + tdata[1] = banktag.toString(); + tdata[2] = item.getValue().toString(); + tdata[3] = types.get(item.getKey()).toString(); + table.addData(tdata); + } + table.show(); + } + + public int getType(String name) { + if (this.types.containsKey(name) == true) { + return this.types.get(name); + } + return -1; + } + + @Override + public String getXML() { + throw new UnsupportedOperationException("Not supported yet."); // To change body of generated methods, choose Tools | Templates. + } + + @Override + public void setPropertyString(String name, String value) { + throw new UnsupportedOperationException("Not supported yet."); // To change body of generated methods, choose Tools | Templates. + } + + @Override + public String getPropertyString(String property_name) { + throw new UnsupportedOperationException("Not supported yet."); // To change body of generated methods, choose Tools | Templates. + } + + @Override + public boolean hasEntry(String entry) { + return this.types.containsKey(entry); + } + + @Override + public boolean hasEntries(String... entries) { + for (String item : entries) + if (this.hasEntry(item) == false) + return false; + return true; + } } diff --git a/common-tools/clas-io/src/main/java/org/jlab/io/evio/EvioDictionary.java b/common-tools/clas-io/src/main/java/org/jlab/io/evio/EvioDictionary.java index 5b536e27f5..01fb60b57b 100644 --- a/common-tools/clas-io/src/main/java/org/jlab/io/evio/EvioDictionary.java +++ b/common-tools/clas-io/src/main/java/org/jlab/io/evio/EvioDictionary.java @@ -45,10 +45,7 @@ public EvioDictionary() { try { File dict_dir = new File(dict_path); this.setDictionary(dict_dir); - /* - * } catch (NoSuchAlgorithmException | ParserConfigurationException | SAXException | IOException | TransformerException e) { // TODO Auto-generated catch - * block e.printStackTrace(); } - */ } catch (ParserConfigurationException ex) { + } catch (ParserConfigurationException ex) { Logger.getLogger(EvioDictionary.class.getName()).log(Level.SEVERE, null, ex); } catch (SAXException ex) { Logger.getLogger(EvioDictionary.class.getName()).log(Level.SEVERE, null, ex); @@ -68,10 +65,7 @@ public EvioDictionary() { public EvioDictionary(File dict_dir) { try { this.setDictionary(dict_dir); - /* - * } catch (NoSuchAlgorithmException | ParserConfigurationException | SAXException | IOException | TransformerException e) { // TODO Auto-generated catch - * block e.printStackTrace(); } - */ } catch (ParserConfigurationException ex) { + } catch (ParserConfigurationException ex) { Logger.getLogger(EvioDictionary.class.getName()).log(Level.SEVERE, null, ex); } catch (SAXException ex) { Logger.getLogger(EvioDictionary.class.getName()).log(Level.SEVERE, null, ex); @@ -84,30 +78,31 @@ public EvioDictionary(File dict_dir) { } } + @Override public void init(String xml_dict) { /* * try { this.setDictionary(xml_dict); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } catch (ParserConfigurationException e) { * e.printStackTrace(); } catch (SAXException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } - * */ } + @Override public String getXML() { return dict; } + @Override public String[] getDescriptorList() { String[] names = new String[descriptors.keySet().size()]; - // ArrayList array = new ArrayList(); int icounter = 0; for (String key : descriptors.keySet()) { names[icounter] = key; icounter++; } return names; - // return (String[]) descriptors.keySet().toArray(); } + @Override public DataDescriptor getDescriptor(String bank_name) { return this.descriptors.get(bank_name); } @@ -133,22 +128,12 @@ private Document getDocument() throws ParserConfigurationException, SAXException return doc; } - private void rebuildHashMaps_2p0() throws ParserConfigurationException, SAXException, IOException { - Document doc = this.getDocument(); - if (doc == null) { - return; - } - this.descriptors = new HashMap(); - NodeList evio_dict_nodelist = doc.getElementsByTagName("evio_dictionary"); - - } - private void rebuildHashMaps() throws ParserConfigurationException, SAXException, IOException { Document doc = this.getDocument(); if (doc == null) { return; } - this.descriptors = new HashMap(); + this.descriptors = new HashMap<>(); NodeList evio_dict_nodelist = doc.getElementsByTagName("evio_dictionary"); for (int i = 0; i < evio_dict_nodelist.getLength(); i++) { Element evio_dict = (Element) evio_dict_nodelist.item(i); @@ -160,28 +145,25 @@ private void rebuildHashMaps() throws ParserConfigurationException, SAXException if (name != null) { int tag = Integer.parseInt(bank_elem.getAttribute("tag")); - ArrayList col_names = new ArrayList(); - HashMap nums = new HashMap(); - HashMap types = new HashMap(); + ArrayList col_names = new ArrayList<>(); + HashMap nums = new HashMap<>(); + HashMap types = new HashMap<>(); NodeList col_node_list = bank_elem.getElementsByTagName("column"); for (int k = 0; k < col_node_list.getLength(); k++) { Element col_elem = (Element) col_node_list.item(k); String col_name = col_elem.getAttribute("name"); - Integer num = Integer.parseInt(col_elem.getAttribute("num")); + Integer num = Integer.valueOf(col_elem.getAttribute("num")); String type_str = col_elem.getAttribute("type"); Integer type; - if (type_str.equals("int32")) { - type = 1; - } else if (type_str.equals("float32")) { - type = 2; - } else if (type_str.equals("float64")) { - type = 3; - } else { - type = 0; - } + type = switch (type_str) { + case "int32" -> 1; + case "float32" -> 2; + case "float64" -> 3; + default -> 0; + }; col_names.add(col_name); nums.put(col_name, num); @@ -200,7 +182,7 @@ private void rebuildHashMaps() throws ParserConfigurationException, SAXException } public void setDictionary(File dict_dir) throws ParserConfigurationException, SAXException, IOException, NoSuchAlgorithmException, TransformerException { - ArrayList ignorePrefixes = new ArrayList(); + ArrayList ignorePrefixes = new ArrayList<>(); ignorePrefixes.add("."); ignorePrefixes.add("_"); @@ -222,7 +204,7 @@ public void setDictionary(File dict_dir) throws ParserConfigurationException, SA // } } } else { - xmlFileList = new ArrayList(); + xmlFileList = new ArrayList<>(); xmlFileList.add(dict_dir.getAbsolutePath()); } @@ -309,6 +291,7 @@ public static void main(String[] args) { System.out.println("DC.x_avg (" + tag + ", " + num + ", " + typ + ")"); } + @Override public DataBank createBank(String name, int rows) { throw new UnsupportedOperationException("Not supported yet."); // To change body of generated methods, choose Tools | Templates. } diff --git a/common-tools/clas-io/src/main/java/org/jlab/io/evio/EvioETSource.java b/common-tools/clas-io/src/main/java/org/jlab/io/evio/EvioETSource.java index 8a7efabb6b..85bead48d7 100644 --- a/common-tools/clas-io/src/main/java/org/jlab/io/evio/EvioETSource.java +++ b/common-tools/clas-io/src/main/java/org/jlab/io/evio/EvioETSource.java @@ -1,8 +1,3 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ package org.jlab.io.evio; import java.io.File; @@ -20,7 +15,6 @@ import org.jlab.coda.et.EtSystem; import org.jlab.coda.et.EtSystemOpenConfig; import org.jlab.coda.et.enums.Mode; -import org.jlab.coda.et.enums.Modify; import org.jlab.coda.et.exception.EtBusyException; import org.jlab.coda.et.exception.EtClosedException; import org.jlab.coda.et.exception.EtDeadException; @@ -38,7 +32,6 @@ import org.jlab.io.base.DataSourceType; import org.jlab.utils.options.OptionParser; - /** * * @author gavalian @@ -46,7 +39,6 @@ public class EvioETSource implements DataSource { - private Boolean connectionOK = false; private String etRingHost = "localhost"; private Integer etRingPort = 11111; @@ -58,7 +50,7 @@ public class EvioETSource implements DataSource { private Integer MAX_NEVENTS = 20; private int currentEventPosition = 0; - List readerEvents = new ArrayList(); + List readerEvents = new ArrayList<>(); public EvioETSource(){ this.etRingPort = EtConstants.serverPort; @@ -127,30 +119,20 @@ public void open(String filename) { if(this.remoteConnection==true){ config.setConnectRemotely(true); } - //config.setConnectRemotely(true); - //System.out.println("-------------->>>>> CONNECTING REMOTELY"); - - //System.out.println("-------------->>>>> CONNECTING LOCALY"); sys = new EtSystem(config); sys.setDebug(EtConstants.debugInfo); sys.open(); EtStationConfig statConfig = new EtStationConfig(); - //statConfig.setBlockMode(EtConstants.stationBlocking); statConfig.setBlockMode(EtConstants.stationNonBlocking); statConfig.setUserMode(EtConstants.stationUserMulti); statConfig.setRestoreMode(EtConstants.stationRestoreOut); - //EtStation station = sys.createStation(statConfig, "GRAND_CENTRAL"); EtStation station = sys.createStation(statConfig, this.etStation); myAttachment = sys.attach(station); - //this.loadEvents(); - //sys.detach(myAttachment); - //System.out.println("[ET-RING] ----> opened a stream with events # = " + this.readerEvents.size()); - } catch (EtException ex) { this.connectionOK = false; ex.printStackTrace(); @@ -198,30 +180,13 @@ public void loadEvents(){ ByteBuffer evioBuffer = ByteBuffer.allocate(events[nevent].getLength()); evioBuffer.put(data, 0, length); evioBuffer.order(buffer.order()); - //EvioReader reader; - //System.out.println("------> parsing event # " + nevent + - // " width length = " + length); try { - //reader = new EvioReader(buffer); EvioCompactReader reader = new EvioCompactReader(buffer); - //EvioEvent event = reader.parseNextEvent(); - /*List nodes = event.getChildrenList(); - System.out.println("----> rawbytes size = " + event.getRawBytes().length); - for(BaseStructure base : nodes){ - System.out.println("----> event # " + nevent + " " + base); - }*/ ByteBuffer localBuffer = reader.getEventBuffer(1); - /* - EvioDataEvent dataEvent = new EvioDataEvent( - event.getRawBytes(),reader.getByteOrder(), - EvioFactory.getDictionary()); - */ - //System.out.println("---> compact event buffer size = " + localBuffer.capacity()); EvioDataEvent dataEvent = new EvioDataEvent(localBuffer,EvioFactory.getDictionary()); this.readerEvents.add(dataEvent); } catch (EvioException ex) { System.out.println("*** ERROR *** : problem reading event # " + nevent ); - //Logger.getLogger(EvioETSource.class.getName()).log(Level.SEVERE, null, ex); } } } @@ -281,6 +246,7 @@ public void putEvents(){ } + @Override public DataEvent getNextEvent() { if(this.currentEventPosition1){ - ethost = args[0]; - file = args[1]; - } else { - System.out.println("\n\n\nUsage : et-connect host etfile\n"); - System.exit(0); - } - - if(args.length>2){ - String flag = args[2]; - if(flag.compareTo("true")==0){ - isRemote = true; - } - } - - EvioETSource reader = new EvioETSource(ethost); - reader.setRemote(isRemote); - reader.open(file); - //for(int loop = 0 ; loop < 10 ; loop++){ - int counter = 0; - EvioEventDecoder decoder = new EvioEventDecoder(); - while(reader.hasEvent()){ - counter++; - System.out.println("Reading next event # " + counter); - EvioDataEvent event = (EvioDataEvent) reader.getNextEvent(); - if(event!=null) { - System.out.println("------> received an event"); - event.getHandler().list(); - List rawdata = decoder.getDataEntries(event); - for(DetectorRawData data : rawdata){ - System.out.println(data); - } - } - }*/ - //} } @Override diff --git a/common-tools/clas-io/src/main/java/org/jlab/io/evio/EvioETSync.java b/common-tools/clas-io/src/main/java/org/jlab/io/evio/EvioETSync.java index 491cf10b95..e591a00b1f 100644 --- a/common-tools/clas-io/src/main/java/org/jlab/io/evio/EvioETSync.java +++ b/common-tools/clas-io/src/main/java/org/jlab/io/evio/EvioETSync.java @@ -1,8 +1,3 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ package org.jlab.io.evio; import java.io.IOException; @@ -12,7 +7,6 @@ import org.jlab.coda.et.EtAttachment; import org.jlab.coda.et.EtConstants; import org.jlab.coda.et.EtEvent; -import org.jlab.coda.et.EtEventImpl; import org.jlab.coda.et.EtStation; import org.jlab.coda.et.EtStationConfig; import org.jlab.coda.et.EtSystem; @@ -23,7 +17,6 @@ import org.jlab.coda.et.exception.EtDeadException; import org.jlab.coda.et.exception.EtEmptyException; import org.jlab.coda.et.exception.EtException; -import org.jlab.coda.et.exception.EtExistsException; import org.jlab.coda.et.exception.EtTimeoutException; import org.jlab.coda.et.exception.EtTooManyException; import org.jlab.coda.et.exception.EtWakeUpException; @@ -36,20 +29,18 @@ */ public class EvioETSync implements DataSync { - private Boolean connectionOK = false; private String etRingHost = ""; private Integer etRingPort = 11111; private EtSystem sys = null; private EtAttachment myAttachment = null; - public EvioETSync(String ip){ this.etRingHost = ip; } + @Override public void open(String filename) { try { - this.connectionOK = true; String etFile = filename; EtSystemOpenConfig config = new EtSystemOpenConfig( etFile,this.etRingHost,this.etRingPort); @@ -62,94 +53,63 @@ public void open(String filename) { statConfig.setRestoreMode(EtConstants.stationRestoreOut); EtStation gsStation = sys.stationNameToObject("GRAND_CENTRAL"); - - //EtStation station = sys.createStation(statConfig, "my_station"); - //EtStation etst = new EtStation(); - //EtStation station = sys.attach(); myAttachment = sys.attach(gsStation); } catch (EtException ex) { - this.connectionOK = false; ex.printStackTrace(); } catch (IOException ex) { - this.connectionOK = false; Logger.getLogger(EvioETSource.class.getName()).log(Level.SEVERE, null, ex); } catch (EtTooManyException ex) { - this.connectionOK = false; Logger.getLogger(EvioETSource.class.getName()).log(Level.SEVERE, null, ex); } catch (EtDeadException ex) { Logger.getLogger(EvioETSource.class.getName()).log(Level.SEVERE, null, ex); } catch (EtClosedException ex) { Logger.getLogger(EvioETSource.class.getName()).log(Level.SEVERE, null, ex); } - } + @Override public void writeEvent(DataEvent event) { - EvioDataEvent evioEvent = (EvioDataEvent) event; - - //byte[] buffer = evioEvent.getHandler().getStructure().getByteBuffer().array(); - //EtEventImpl etEvent = new EtEventImpl(buffer.length); - //etEvent.setData(buffer); - //etEvent.setOwner(1); - //EtEvent[] evs = new EtEvent[]{etEvent}; byte[] buffer = new byte[200]; int eventLength = buffer.length; - System.out.println("WRITING DATA WITH LENGTH " + buffer.length); - try { - - EtEvent[] etevents = sys.newEvents(myAttachment, Mode.SLEEP, false, - 0,1,buffer.length, 1); - - ByteBuffer byteBuffer = etevents[0].getDataBuffer(); - byteBuffer.put(buffer); - byteBuffer.flip(); - - etevents[0].setLength(eventLength); - - //System.out.println("# of events = " + etevents.length + " BUFFER SIZE = " + byteBuffer.capacity() - //+ " LENGTH = " + etevents[0].getLength()); - - - sys.putEvents(myAttachment, etevents); + try { + EtEvent[] etevents = sys.newEvents(myAttachment, Mode.SLEEP, false, + 0,1,buffer.length, 1); + ByteBuffer byteBuffer = etevents[0].getDataBuffer(); + byteBuffer.put(buffer); + byteBuffer.flip(); + etevents[0].setLength(eventLength); + sys.putEvents(myAttachment, etevents); - } catch (IOException ex) { - Logger.getLogger(EvioETSync.class.getName()).log(Level.SEVERE, null, ex); - } catch (EtException ex) { - Logger.getLogger(EvioETSync.class.getName()).log(Level.SEVERE, null, ex); - } catch (EtDeadException ex) { - Logger.getLogger(EvioETSync.class.getName()).log(Level.SEVERE, null, ex); - } catch (EtClosedException ex) { - Logger.getLogger(EvioETSync.class.getName()).log(Level.SEVERE, null, ex); - } catch (EtEmptyException ex) { - Logger.getLogger(EvioETSync.class.getName()).log(Level.SEVERE, null, ex); - } catch (EtBusyException ex) { - Logger.getLogger(EvioETSync.class.getName()).log(Level.SEVERE, null, ex); - } catch (EtTimeoutException ex) { - Logger.getLogger(EvioETSync.class.getName()).log(Level.SEVERE, null, ex); - } catch (EtWakeUpException ex) { - Logger.getLogger(EvioETSync.class.getName()).log(Level.SEVERE, null, ex); - } + } catch (IOException ex) { + Logger.getLogger(EvioETSync.class.getName()).log(Level.SEVERE, null, ex); + } catch (EtException ex) { + Logger.getLogger(EvioETSync.class.getName()).log(Level.SEVERE, null, ex); + } catch (EtDeadException ex) { + Logger.getLogger(EvioETSync.class.getName()).log(Level.SEVERE, null, ex); + } catch (EtClosedException ex) { + Logger.getLogger(EvioETSync.class.getName()).log(Level.SEVERE, null, ex); + } catch (EtEmptyException ex) { + Logger.getLogger(EvioETSync.class.getName()).log(Level.SEVERE, null, ex); + } catch (EtBusyException ex) { + Logger.getLogger(EvioETSync.class.getName()).log(Level.SEVERE, null, ex); + } catch (EtTimeoutException ex) { + Logger.getLogger(EvioETSync.class.getName()).log(Level.SEVERE, null, ex); + } catch (EtWakeUpException ex) { + Logger.getLogger(EvioETSync.class.getName()).log(Level.SEVERE, null, ex); + } } + @Override public void close() { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } - public static void main(String[] args){ String ethost = "129.57.76.215"; String file = "/tmp/myEtRing"; String evioFile = "/Users/gavalian/Work/Software/Release-8.0/COATJAVA/etaPXSection_0_recon.evio"; - /* - if(args.length>1){ - ethost = args[0]; - file = args[1]; - } else { - System.out.println("\n\n\nUsage : et-connect host etfile\n"); - System.exit(0); - }*/ EvioETSync writer = new EvioETSync(ethost); writer.open(file); diff --git a/common-tools/clas-io/src/main/java/org/jlab/io/evio/EvioEventList.java b/common-tools/clas-io/src/main/java/org/jlab/io/evio/EvioEventList.java deleted file mode 100644 index b96378a8b6..0000000000 --- a/common-tools/clas-io/src/main/java/org/jlab/io/evio/EvioEventList.java +++ /dev/null @@ -1,18 +0,0 @@ -package org.jlab.io.evio; - -import org.jlab.io.base.DataEvent; -import org.jlab.io.base.DataEventList; - -public class EvioEventList implements DataEventList { - - public int getSize() { - // TODO Auto-generated method stub - return 0; - } - - public DataEvent getEvent(int i) { - // TODO Auto-generated method stub - return null; - } - -} diff --git a/common-tools/clas-io/src/main/java/org/jlab/io/evio/EvioFactory.java b/common-tools/clas-io/src/main/java/org/jlab/io/evio/EvioFactory.java index ea20698997..e4d0d94264 100644 --- a/common-tools/clas-io/src/main/java/org/jlab/io/evio/EvioFactory.java +++ b/common-tools/clas-io/src/main/java/org/jlab/io/evio/EvioFactory.java @@ -1,20 +1,9 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ - package org.jlab.io.evio; -import java.io.File; -import java.io.IOException; import java.nio.ByteBuffer; import java.nio.ByteOrder; -import java.security.NoSuchAlgorithmException; import java.util.logging.Level; import java.util.logging.Logger; -import javax.xml.parsers.ParserConfigurationException; -import javax.xml.transform.TransformerException; import org.jlab.coda.jevio.DataType; import org.jlab.coda.jevio.EventBuilder; import org.jlab.coda.jevio.EvioBank; @@ -23,7 +12,6 @@ import org.jlab.io.base.DataDescriptor; import org.jlab.io.base.DataEntryType; import org.jlab.utils.CLASResources; -import org.xml.sax.SAXException; /** * @@ -36,7 +24,6 @@ public class EvioFactory { public static EvioDataDictionary readDefaultDictionary(){ EvioDataDictionary dict = new EvioDataDictionary(); - //return dict; String clasDictionaryPath = CLASResources.getResourcePath("etc/bankdefs/clas12"); if(clasDictionaryPath!=null){ dict.initWithDir(clasDictionaryPath); @@ -113,7 +100,6 @@ public static EvioDataBank createEvioBank(String name,int rows){ public static EvioDataEvent createEvioEvent(){ try { - //EvioEvent baseBank = new EvioEvent(1, DataType.BANK, 0); EventBuilder builder = new EventBuilder(1,DataType.BANK,0); EvioEvent event = builder.getEvent(); EvioBank baseBank = new EvioBank(10, DataType.ALSOBANK, 0); @@ -123,7 +109,6 @@ public static EvioDataEvent createEvioEvent(){ ByteOrder byteOrder = ByteOrder.LITTLE_ENDIAN; int byteSize = event.getTotalBytes(); - //System.out.println("base bank size = " + byteSize); ByteBuffer bb = ByteBuffer.allocate(byteSize); bb.order(byteOrder); event.write(bb); @@ -137,7 +122,6 @@ public static EvioDataEvent createEvioEvent(){ } public static EvioDataBank createEvioBank(String name,DataDescriptor desc,int rows){ - //EvioDataDescriptor desc = (EvioDataDescriptor) EvioFactory.getDictionary().getDescriptor(name); EvioDataBank bank = new EvioDataBank(desc); String[] entries = desc.getEntryList(); for(String entry : entries){ diff --git a/common-tools/clas-io/src/main/java/org/jlab/io/evio/EvioRingSource.java b/common-tools/clas-io/src/main/java/org/jlab/io/evio/EvioRingSource.java index 4f3822f3da..6b565ad098 100644 --- a/common-tools/clas-io/src/main/java/org/jlab/io/evio/EvioRingSource.java +++ b/common-tools/clas-io/src/main/java/org/jlab/io/evio/EvioRingSource.java @@ -1,8 +1,3 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ package org.jlab.io.evio; import java.io.File; @@ -34,11 +29,10 @@ */ public class EvioRingSource implements DataSource { - private List eventStore = new ArrayList(); + private List eventStore = new ArrayList<>(); private int eventStoreMaxCapacity = 500; private xMsg xmsgServer = null; - private boolean createConnection(String host){ boolean result = true; @@ -52,13 +46,11 @@ private boolean createConnection(String host){ } } catch (xMsgException ex) { - //Logger.getLogger(HipoRingSource.class.getName()).log(Level.SEVERE, null, ex); System.out.println(" >>> connection to server " + host + " : failed"); this.xmsgServer.destroy(); this.xmsgServer = null; result = false; } - //System.out.println("-----> connection estabilished..."); return result; } @@ -140,11 +132,7 @@ public DataEvent getNextEvent() { return null; } EvioDataEvent event = this.eventStore.get(0); - //System.out.println(" >>> success getting event : size = " + eventStore.size()); - //event.show(); this.eventStore.remove(0); - //System.out.println(" >>> FILO cleanup : size = " + eventStore.size()); - //System.out.println("\n\n"); return event; } @@ -171,31 +159,24 @@ public int getCurrentIndex() { @Override public DataSourceType getType() { return DataSourceType.STREAM; - // throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } @Override public void waitForEvents() { - // For the Ring source, waiting for the events } - private class MyCallBack implements xMsgCallBack { @Override public void callback(xMsgMessage mm) { - byte[] data = mm.getData(); String type = mm.getMimeType(); - System.out.println("\n\n >>>>>> received data : mime " + type); System.out.println(" >>>>>> received data : size " + data.length); if(eventStore.size()>>>>> adding event to the store : size = %d \n", eventStore.size()); } else { - //System.out.printf(" >>>>>> event store is full : size = %d \n", eventStore.size()); } } } @@ -212,7 +193,6 @@ public static void main(String[] args){ while(true){ if(reader.hasEvent()==true){ - //System.out.println("has event"); DataEvent event = reader.getNextEvent(); try { event.show(); @@ -220,7 +200,6 @@ public static void main(String[] args){ System.out.println("something went wrong"); } } else { - //System.out.println("no event"); try { Thread.sleep(20); } catch (InterruptedException ex) { diff --git a/common-tools/clas-io/src/main/java/org/jlab/io/evio/EvioSource.java b/common-tools/clas-io/src/main/java/org/jlab/io/evio/EvioSource.java index 9fe9038e09..abadc99fc9 100644 --- a/common-tools/clas-io/src/main/java/org/jlab/io/evio/EvioSource.java +++ b/common-tools/clas-io/src/main/java/org/jlab/io/evio/EvioSource.java @@ -14,14 +14,13 @@ import org.jlab.io.base.DataSource; import org.jlab.io.base.DataSourceType; -public class EvioSource implements DataSource { +public final class EvioSource implements DataSource { - Logger LOGGER = Logger.getLogger(EvioSource.class.getName()); - private ByteOrder storeByteOrder = ByteOrder.BIG_ENDIAN; - private EvioCompactReader evioReader = null; - private EvioDataEvent evioEvent = null; - private int currentEvent; - private int currentFileEntries; + static final Logger LOGGER = Logger.getLogger(EvioSource.class.getName()); + private ByteOrder storeByteOrder = ByteOrder.BIG_ENDIAN; + private EvioCompactReader evioReader = null; + private int currentEvent; + private int currentFileEntries; @Override public void close() { @@ -37,143 +36,138 @@ public ByteBuffer getEventBuffer(int eventNumber, boolean asdf) throws EvioExcep return evioReader.getEventBuffer(eventNumber, asdf); } - public EvioSource() {} - - public EvioSource(String filename) { - this.open(filename); - } - - public void open(File file) { - this.open(file.getAbsolutePath()); - } - - public void open(String filename) { - try { - evioReader = new EvioCompactReader(new File(filename)); - currentEvent = 1; - currentFileEntries = evioReader.getEventCount(); - storeByteOrder = evioReader.getFileByteOrder(); - LOGGER.log(Level.INFO,"****** opened FILE [] ** NEVENTS = " + currentFileEntries + " *******"); - // TODO Auto-generated method stub - } catch (EvioException ex) { - Logger.getLogger(EvioSource.class.getName()).log(Level.SEVERE, null, ex); - } catch (IOException ex) { - Logger.getLogger(EvioSource.class.getName()).log(Level.SEVERE, null, ex); - } - } - - public void open(ByteBuffer buff) { - try { - evioReader = new EvioCompactReader(buff); - currentEvent = 1; - currentFileEntries = evioReader.getEventCount()+1; - storeByteOrder = evioReader.getFileByteOrder(); - // LOGGER.log(Level.INFO,"****** opened BUFFER [] ** NEVENTS = " + currentFileEntries + " *******"); - } catch (EvioException ex) { - Logger.getLogger(EvioSource.class.getName()).log(Level.SEVERE, null, ex); - } - } - - public int getSize() { - // TODO Auto-generated method stub - return currentFileEntries; - } - - public DataEventList getEventList(int start, int stop) { - // TODO Auto-generated method stub - return null; - } - - public DataEventList getEventList(int nrecords) { - // TODO Auto-generated method stub - return null; - } - - public void reset() { - currentEvent = 1; - } - - public int getCurrentIndex() { - // TODO Auto-generated method stub - return currentEvent; - } - - public DataEvent getPreviousEvent() { - if (currentEvent > currentFileEntries || currentEvent == 2) - return null; - try { - currentEvent--; - currentEvent--; - ByteBuffer evioBuffer = evioReader.getEventBuffer(currentEvent, true); - EvioDataEvent event = new EvioDataEvent(evioBuffer.array(), storeByteOrder); - currentEvent++; - return event; - } catch (EvioException ex) { - Logger.getLogger(EvioSource.class.getName()).log(Level.SEVERE, null, ex); - } - return null; - } - - public DataEvent gotoEvent(int index) { - if (index <= 1 || index > currentFileEntries) - return null; - try { - ByteBuffer evioBuffer = evioReader.getEventBuffer(index, true); - EvioDataEvent event = new EvioDataEvent(evioBuffer.array(), storeByteOrder); - currentEvent = index + 1; - return event; - } catch (EvioException ex) { - Logger.getLogger(EvioSource.class.getName()).log(Level.SEVERE, null, ex); - } - return null; - } - - public EvioDataEventHandler getNextEventHandler() { - if (currentEvent > currentFileEntries) - return null; - try { - ByteBuffer evioBuffer = evioReader.getEventBuffer(currentEvent, true); - EvioDataEventHandler event = new EvioDataEventHandler(evioBuffer.array(), storeByteOrder); - currentEvent++; - return event; - } catch (EvioException ex) { - Logger.getLogger(EvioSource.class.getName()).log(Level.SEVERE, null, ex); - } - return null; - } - - public DataEvent getNextEvent() { - if (currentEvent > currentFileEntries) - return null; - try { - ByteBuffer evioBuffer = evioReader.getEventBuffer(currentEvent, true); - EvioDataEvent event = new EvioDataEvent(evioBuffer.array(), storeByteOrder); - currentEvent++; - return event; - } catch (EvioException ex) { - Logger.getLogger(EvioSource.class.getName()).log(Level.SEVERE, null, ex); - } - return null; - } - /* - * public Histogram1D scanTree(String path, int maxevents){ currentEvent = 1; int maxestimate = 5000; if(maxestimate>=maxevents){ maxestimate = maxevents-2; } - * - * DataRangeEstimator datae = new DataRangeEstimator(path,100,maxestimate); - * - * for(int loop = 0; loop < maxevents; loop++){ DataEvent event = this.getNextEvent(); double[] darray = event.getDouble(path); if(darray!=null){ for(int ndata = - * 0; ndata < darray.length; ndata++){ datae.fill(darray[ndata]); //System.out.println("--> " + darray[ndata]); } } } //= new Histogram1D(); - * System.out.println("----> bins = " + datae.getHistogram().getAxis().getNbins()); return datae.getHistogram(); } - */ - - public boolean hasEvent() { - if (currentEvent > currentFileEntries) - return false; - return true; - } - - public static void main(String[] args) { - - } + public EvioSource() {} + + public EvioSource(String filename) { + this.open(filename); + } + + @Override + public void open(File file) { + this.open(file.getAbsolutePath()); + } + + @Override + public void open(String filename) { + try { + evioReader = new EvioCompactReader(new File(filename)); + currentEvent = 1; + currentFileEntries = evioReader.getEventCount(); + storeByteOrder = evioReader.getFileByteOrder(); + LOGGER.log(Level.INFO, "****** opened FILE [] ** NEVENTS = {0} *******", currentFileEntries); + } catch (EvioException ex) { + Logger.getLogger(EvioSource.class.getName()).log(Level.SEVERE, null, ex); + } catch (IOException ex) { + Logger.getLogger(EvioSource.class.getName()).log(Level.SEVERE, null, ex); + } + } + + @Override + public void open(ByteBuffer buff) { + try { + evioReader = new EvioCompactReader(buff); + currentEvent = 1; + currentFileEntries = evioReader.getEventCount()+1; + storeByteOrder = evioReader.getFileByteOrder(); + } catch (EvioException ex) { + Logger.getLogger(EvioSource.class.getName()).log(Level.SEVERE, null, ex); + } + } + + @Override + public int getSize() { + return currentFileEntries; + } + + @Override + public DataEventList getEventList(int start, int stop) { + return null; + } + + @Override + public DataEventList getEventList(int nrecords) { + return null; + } + + @Override + public void reset() { + currentEvent = 1; + } + + @Override + public int getCurrentIndex() { + return currentEvent; + } + + @Override + public DataEvent getPreviousEvent() { + if (currentEvent > currentFileEntries || currentEvent == 2) + return null; + try { + currentEvent--; + currentEvent--; + ByteBuffer evioBuffer = evioReader.getEventBuffer(currentEvent, true); + EvioDataEvent event = new EvioDataEvent(evioBuffer.array(), storeByteOrder); + currentEvent++; + return event; + } catch (EvioException ex) { + Logger.getLogger(EvioSource.class.getName()).log(Level.SEVERE, null, ex); + } + return null; + } + + @Override + public DataEvent gotoEvent(int index) { + if (index <= 1 || index > currentFileEntries) + return null; + try { + ByteBuffer evioBuffer = evioReader.getEventBuffer(index, true); + EvioDataEvent event = new EvioDataEvent(evioBuffer.array(), storeByteOrder); + currentEvent = index + 1; + return event; + } catch (EvioException ex) { + Logger.getLogger(EvioSource.class.getName()).log(Level.SEVERE, null, ex); + } + return null; + } + + public EvioDataEventHandler getNextEventHandler() { + if (currentEvent > currentFileEntries) + return null; + try { + ByteBuffer evioBuffer = evioReader.getEventBuffer(currentEvent, true); + EvioDataEventHandler event = new EvioDataEventHandler(evioBuffer.array(), storeByteOrder); + currentEvent++; + return event; + } catch (EvioException ex) { + Logger.getLogger(EvioSource.class.getName()).log(Level.SEVERE, null, ex); + } + return null; + } + + @Override + public DataEvent getNextEvent() { + if (currentEvent > currentFileEntries) + return null; + try { + ByteBuffer evioBuffer = evioReader.getEventBuffer(currentEvent, true); + EvioDataEvent event = new EvioDataEvent(evioBuffer.array(), storeByteOrder); + currentEvent++; + return event; + } catch (EvioException ex) { + Logger.getLogger(EvioSource.class.getName()).log(Level.SEVERE, null, ex); + } + return null; + } + + @Override + public boolean hasEvent() { + return currentEvent <= currentFileEntries; + } + + public static void main(String[] args) { + + } @Override public DataSourceType getType() { @@ -182,7 +176,5 @@ public DataSourceType getType() { @Override public void waitForEvents() { - // This method does nothing for source associated with - // a file. } } diff --git a/common-tools/clas-io/src/main/java/org/jlab/io/evio/EvioTreeBranch.java b/common-tools/clas-io/src/main/java/org/jlab/io/evio/EvioTreeBranch.java index 24963bbd24..ea70120378 100644 --- a/common-tools/clas-io/src/main/java/org/jlab/io/evio/EvioTreeBranch.java +++ b/common-tools/clas-io/src/main/java/org/jlab/io/evio/EvioTreeBranch.java @@ -1,9 +1,3 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ - package org.jlab.io.evio; import java.util.ArrayList; @@ -20,7 +14,6 @@ public class EvioTreeBranch { private final ArrayList leafNodes = new ArrayList(); - public EvioTreeBranch(int tag, int num){ branchTag = tag; branchNumber = num; diff --git a/common-tools/clas-io/src/main/java/org/jlab/io/hipo/HipoDataBank.java b/common-tools/clas-io/src/main/java/org/jlab/io/hipo/HipoDataBank.java index 94caa903b0..b1bd77e0fc 100644 --- a/common-tools/clas-io/src/main/java/org/jlab/io/hipo/HipoDataBank.java +++ b/common-tools/clas-io/src/main/java/org/jlab/io/hipo/HipoDataBank.java @@ -30,6 +30,7 @@ public Bank getBank(){ return hipoGroup; } + @Override public String[] getColumnList() { String[] columns = new String[descriptor.getSchema().getElements()]; for(int i = 0; i < columns.length; i++) columns[i] = descriptor.getSchema().getElementName(i); @@ -41,6 +42,7 @@ public DataDescriptor getDescriptor() { return this.descriptor; } + @Override public double[] getDouble(String path) { int nrows = this.hipoGroup.getRows(); double[] result = new double[nrows]; @@ -53,18 +55,22 @@ public double getDouble(String path, int index) { return this.hipoGroup.getDouble(path, index); } + @Override public void setDouble(String path, double[] arr) { throw new UnsupportedOperationException("Not supported yet."); } + @Override public void setDouble(String path, int row, double value) { hipoGroup.putDouble(path,row,value); } + @Override public void appendDouble(String path, double[] arr) { throw new UnsupportedOperationException("Not supported yet."); } + @Override public float[] getFloat(String path) { int nrows = this.hipoGroup.getRows(); float[] result = new float[nrows]; @@ -72,22 +78,27 @@ public float[] getFloat(String path) { return result; } + @Override public float getFloat(String path, int index) { return this.hipoGroup.getFloat(path, index); } + @Override public void setFloat(String path, float[] arr) { throw new UnsupportedOperationException("Not supported yet."); } + @Override public void setFloat(String path, int row, float value) { this.hipoGroup.putFloat(path, row, value); } + @Override public void appendFloat(String path, float[] arr) { throw new UnsupportedOperationException("Not supported yet."); } + @Override public int[] getInt(String path) { int nrows = this.hipoGroup.getRows(); int[] result = new int[nrows]; @@ -95,22 +106,27 @@ public int[] getInt(String path) { return result; } + @Override public int getInt(String path, int index) { return hipoGroup.getInt(path, index); } + @Override public void setInt(String path, int[] arr) { throw new UnsupportedOperationException("Not supported yet."); } + @Override public void setInt(String path, int row, int value) { hipoGroup.putInt(path, row, value); } + @Override public void appendInt(String path, int[] arr) { throw new UnsupportedOperationException("Not supported yet."); } + @Override public short[] getShort(String path) { int nrows = this.hipoGroup.getRows(); short[] result = new short[nrows]; @@ -118,22 +134,27 @@ public short[] getShort(String path) { return result; } + @Override public short getShort(String path, int index) { return hipoGroup.getShort(path, index); } + @Override public void setShort(String path, short[] arr) { throw new UnsupportedOperationException("Not supported yet."); } + @Override public void setShort(String path, int row, short value) { hipoGroup.putShort(path, row, value); } + @Override public void appendShort(String path, short[] arr) { throw new UnsupportedOperationException("Not supported yet."); } + @Override public long[] getLong(String path) { int nrows = this.hipoGroup.getRows(); long[] result = new long[nrows]; @@ -141,22 +162,27 @@ public long[] getLong(String path) { return result; } + @Override public long getLong(String path, int index) { return hipoGroup.getLong(path, index); } + @Override public void setLong(String path, long[] arr) { throw new UnsupportedOperationException("Not supported yet."); } + @Override public void setLong(String path, int row, long value) { hipoGroup.putLong(path, row, value); } + @Override public void appendLong(String path, long[] arr) { throw new UnsupportedOperationException("Not supported yet."); } + @Override public byte[] getByte(String path) { int nrows = this.hipoGroup.getRows(); byte[] result = new byte[nrows]; @@ -164,43 +190,53 @@ public byte[] getByte(String path) { return result; } + @Override public byte getByte(String path, int index) { return hipoGroup.getByte(path, index); } + @Override public void setByte(String path, byte[] arr) { throw new UnsupportedOperationException("Not supported yet."); } + @Override public void setByte(String path, int row, byte value) { hipoGroup.putByte(path, row, value); } + @Override public void appendByte(String path, byte[] arr) { throw new UnsupportedOperationException("Not supported yet."); } + @Override public int columns() { return hipoGroup.getSchema().getElements(); } + @Override public int rows() { return hipoGroup.getRows(); } + @Override public void show() { System.out.println(" SHOWING BANK"); this.hipoGroup.show(); } + @Override public void reset() { } + @Override public void allocate(int rows) { } + @Override public TableModel getTableModel(String mask) { return null; } diff --git a/common-tools/clas-io/src/main/java/org/jlab/io/hipo/HipoDataDescriptor.java b/common-tools/clas-io/src/main/java/org/jlab/io/hipo/HipoDataDescriptor.java index 69190252c4..f8d504f6ab 100644 --- a/common-tools/clas-io/src/main/java/org/jlab/io/hipo/HipoDataDescriptor.java +++ b/common-tools/clas-io/src/main/java/org/jlab/io/hipo/HipoDataDescriptor.java @@ -1,16 +1,8 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ package org.jlab.io.hipo; -import java.util.List; import org.jlab.io.base.DataDescriptor; -import org.jlab.jnp.hipo.data.HipoNodeType; import org.jlab.jnp.hipo4.data.Schema; - /** * * @author gavalian @@ -20,18 +12,16 @@ public class HipoDataDescriptor implements DataDescriptor { private Schema hipoSchema = null; public HipoDataDescriptor(){ - } public HipoDataDescriptor(Schema schema){ - //this.init(schema); hipoSchema = schema; } public final void init(Schema schema){ - // hipoSchema.copy(schema); } + @Override public void init(String s) { hipoSchema = Schema.fromJsonString(s); } @@ -40,7 +30,6 @@ public void init(String s) { public String[] getEntryList() { int elements = hipoSchema.getElements(); String[] entries = new String[elements]; - int counter = 0; for(int i = 0; i < elements; i++){ entries[i] = hipoSchema.getElementName(i); } @@ -55,7 +44,6 @@ public String getXML() { @Override public boolean hasEntry(String entry) { return hipoSchema.hasEntry(entry); - //return (this.hipoSchema.getEntry(entry)!=null); } @Override diff --git a/common-tools/clas-io/src/main/java/org/jlab/io/hipo/HipoDataDictionary.java b/common-tools/clas-io/src/main/java/org/jlab/io/hipo/HipoDataDictionary.java index 5bc60878fd..4915068682 100644 --- a/common-tools/clas-io/src/main/java/org/jlab/io/hipo/HipoDataDictionary.java +++ b/common-tools/clas-io/src/main/java/org/jlab/io/hipo/HipoDataDictionary.java @@ -1,8 +1,3 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ package org.jlab.io.hipo; import java.util.HashMap; @@ -17,9 +12,6 @@ import org.jlab.jnp.hipo4.data.Schema; import org.jlab.jnp.hipo4.data.SchemaFactory; - - - /** * * @author gavalian @@ -37,11 +29,9 @@ public HipoDataDictionary(){ } factory.initFromDirectory(envCLAS + "/" + "etc/bankdefs/hipo4"); List entries = factory.getSchemaList(); - //System.out.println(" schema size = " + entries.size()); for(Schema sch : entries){ HipoDataDescriptor desc = new HipoDataDescriptor(sch); descriptors.put(desc.getName(), desc); - //System.out.println("name = " + sch.getName() + " desc = " + desc.getName()); } System.out.println(" >>>>> loading default dictionary : entries = " + descriptors.size()); } @@ -55,8 +45,6 @@ public void init(String format) { public String getXML() { return ""; } - - @Override public String[] getDescriptorList() { @@ -80,8 +68,6 @@ public DataBank createBank(String name, int rows) { Schema schema = descriptors.get(name).getSchema(); Bank bank = new Bank(schema,rows); HipoDataBank dataBank = new HipoDataBank(bank); - //Map map = descriptors.get(name).getSchema().createNodeMap(rows); - //HipoDataBank bank = new HipoDataBank(map,descriptors.get(name).getSchema()); return dataBank; } diff --git a/common-tools/clas-io/src/main/java/org/jlab/io/hipo/HipoDataEvent.java b/common-tools/clas-io/src/main/java/org/jlab/io/hipo/HipoDataEvent.java index 5da4ed5265..3019d3222a 100644 --- a/common-tools/clas-io/src/main/java/org/jlab/io/hipo/HipoDataEvent.java +++ b/common-tools/clas-io/src/main/java/org/jlab/io/hipo/HipoDataEvent.java @@ -1,16 +1,9 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ package org.jlab.io.hipo; import java.nio.ByteBuffer; -import java.nio.ByteOrder; import java.util.ArrayList; import java.util.Collections; import java.util.List; -import java.util.Map; import org.jlab.io.base.DataBank; import org.jlab.io.base.DataDictionary; import org.jlab.io.base.DataEvent; @@ -49,8 +42,7 @@ public HipoDataEvent(Event event,SchemaFactory factory){ public Event getHipoEvent(){return this.hipoEvent;} public void initDictionary(SchemaFactory factory){ - //this.hipoEvent.getSchemaFactory().copy(factory); - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + throw new UnsupportedOperationException("Not supported yet."); } @Override @@ -64,7 +56,6 @@ public String[] getBankList() { existingBanks.add(schema.getName()); } } - String[] list = new String[existingBanks.size()]; for(int i = 0; i < list.length; i++) list[i] = existingBanks.get(i); return list; @@ -73,7 +64,6 @@ public String[] getBankList() { public String[] getColumnList(String bank_name) { Schema schema = schemaFactory.getSchema(bank_name); int ncolumns = schemaFactory.getSchema(bank_name).getElements(); - //List columnsList = schemaFactory.getSchema(bank_name).getElements(); String[] columns = new String[ncolumns]; for(int i = 0; i < columns.length; i++) columns[i] = schema.getElementName(i); return columns; @@ -89,13 +79,11 @@ public void addSchemaList(List schemaList){ @Override public DataDictionary getDictionary() { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + throw new UnsupportedOperationException("Not supported yet."); } @Override public ByteBuffer getEventBuffer() { - //ByteBuffer buffer = ByteBuffer.wrap(this.hipoEvent.getEventBuffer() - //buffer.order(ByteOrder.LITTLE_ENDIAN); return hipoEvent.getEventBuffer(); } @@ -123,145 +111,86 @@ public boolean hasBank(String name) { @Override public DataBank getBank(String bank_name) { - Schema schema = schemaFactory.getSchema(bank_name); - if(schema!=null){ Bank bank = new Bank(schema); hipoEvent.read(bank); HipoDataBank dataBank = new HipoDataBank(bank); return dataBank; } - //HipoDataBank bank = new HipoDataBank(); return null; } public void getBank(String bank_name, DataBank bank) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + throw new UnsupportedOperationException("Not supported yet."); } public void setProperty(String property, String value) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + throw new UnsupportedOperationException("Not supported yet."); } public String getProperty(String property) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + throw new UnsupportedOperationException("Not supported yet."); } public double[] getDouble(String path) { - /*HipoNode node = this.getHipoNodeByPath(path); - if(node==null){ - System.out.println("\n>>>>> error : getting node failed : " + path); - return new double[0]; - } - return node.getDouble();*/ - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + throw new UnsupportedOperationException("Not supported yet."); } public void setDouble(String path, double[] arr) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + throw new UnsupportedOperationException("Not supported yet."); } public void appendDouble(String path, double[] arr) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + throw new UnsupportedOperationException("Not supported yet."); } public float[] getFloat(String path) { - /* HipoNode node = this.getHipoNodeByPath(path); - if(node==null){ - System.out.println("\n>>>>> error : getting node failed : " + path); - return new float[0]; - } - return node.getFloat();*/ - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + throw new UnsupportedOperationException("Not supported yet."); } public void setFloat(String path, float[] arr) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + throw new UnsupportedOperationException("Not supported yet."); } public void appendFloat(String path, float[] arr) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + throw new UnsupportedOperationException("Not supported yet."); } public int[] getInt(String path) { - /*HipoNode node = this.getHipoNodeByPath(path); - if(node==null){ - System.out.println("\n>>>>> error : getting node failed : " + path); - return new int[0]; - } - return node.getInt();*/ - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + throw new UnsupportedOperationException("Not supported yet."); } public void setInt(String path, int[] arr) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + throw new UnsupportedOperationException("Not supported yet."); } public void appendInt(String path, int[] arr) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + throw new UnsupportedOperationException("Not supported yet."); } public short[] getShort(String path) { - /*HipoNode node = this.getHipoNodeByPath(path); - if(node==null){ - System.out.println("\n>>>>> error : getting node failed : " + path); - return new short[0]; - } - return node.getShort();*/ - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + throw new UnsupportedOperationException("Not supported yet."); } public void setShort(String path, short[] arr) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + throw new UnsupportedOperationException("Not supported yet."); } public void appendShort(String path, short[] arr) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + throw new UnsupportedOperationException("Not supported yet."); } - /* public HipoNode getHipoNodeByPath(String path){ - String[] bank_and_item = path.split("[.]+"); - if(bank_and_item.length<2){ - System.out.println("\n>>>>> error : syntax error in path name : " + path); - return null; - } - Schema schema = this.hipoEvent.getSchemaFactory().getSchema(bank_and_item[0]); - if(schema==null){ - System.out.println("\n>>>>> error : can not find schema with name : " - + bank_and_item[0]); - return null; - } - - SchemaEntry entry = schema.getEntry(bank_and_item[1]); - if(entry==null){ - System.out.println("\n>>>>> error : schema " + bank_and_item[0] + - " dose not have an entry with name :" - + bank_and_item[1]); - return null; - } - - HipoNode node = hipoEvent.getNode(schema.getGroup(), entry.getId()); - return node; - }*/ - public byte[] getByte(String path) { - - /*HipoNode node = this.getHipoNodeByPath(path); - if(node==null){ - System.out.println("\n>>>>> error : getting node failed : " + path); - return new byte[0]; - } - return node.getByte();*/ - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + throw new UnsupportedOperationException("Not supported yet."); } public void setByte(String path, byte[] arr) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + throw new UnsupportedOperationException("Not supported yet."); } public void appendByte(String path, byte[] arr) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + throw new UnsupportedOperationException("Not supported yet."); } public void setType(DataEventType type) { @@ -273,7 +202,6 @@ public DataEventType getType() { } public void show(){ - //this.hipoEvent.show(); this.hipoEvent.scan(); } @@ -284,8 +212,6 @@ public void showBankByOrder(int order){ @Override public DataBank createBank(String bank_name, int rows) { - //System.out.println(" CREATING BANK = " + bank_name); - Schema schema = schemaFactory.getSchema(bank_name); if(schema ==null) { System.out.println(" SCHEMA FOR ["+bank_name + "] = NULL"); @@ -296,24 +222,8 @@ public DataBank createBank(String bank_name, int rows) { System.out.println("\t ----> " + sc); } } - //System.out.println("SCHEMA = " + schema.getName()); - - Bank bank = new Bank(schema,rows); - - HipoDataBank dataBank = new HipoDataBank(bank); - return dataBank; - /* - if(this.hipoEvent.getSchemaFactory().hasSchema(bank_name)==false){ - System.out.println(">>>>> error : descriptor not found : " + bank_name); - System.out.println(">>>>> error : number of descriptors : " + - hipoEvent.getSchemaFactory().getSchemaList().size()); - System.out.println(); - this.hipoEvent.getSchemaFactory().show(); - return null; - } - HipoGroup group = this.hipoEvent.getSchemaFactory().getSchema(bank_name).createGroup(rows); - HipoDataBank bank = new HipoDataBank(group); - return bank;*/ + Bank bank = new Bank(schema,rows); + return new HipoDataBank(bank); } @Override @@ -329,7 +239,6 @@ public void removeBanks(String... bankNames) { for(String bank : bankNames){ removeBank(bank); } - //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } @Override @@ -343,16 +252,16 @@ public long[] getLong(String path) { long[] data = new long[size]; for(int i =0; i < data.length; i++) data[i] = node.getLong(i); return data;*/ - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + throw new UnsupportedOperationException("Not supported yet."); } @Override public void setLong(String path, long[] arr) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + throw new UnsupportedOperationException("Not supported yet."); } @Override public void appendLong(String path, long[] arr) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + throw new UnsupportedOperationException("Not supported yet."); } } diff --git a/common-tools/clas-io/src/main/java/org/jlab/io/hipo/HipoDataSync.java b/common-tools/clas-io/src/main/java/org/jlab/io/hipo/HipoDataSync.java index 412920ee69..c401daaaa0 100644 --- a/common-tools/clas-io/src/main/java/org/jlab/io/hipo/HipoDataSync.java +++ b/common-tools/clas-io/src/main/java/org/jlab/io/hipo/HipoDataSync.java @@ -3,26 +3,21 @@ import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; - import org.jlab.io.base.DataEvent; import org.jlab.io.base.DataSync; - - import org.jlab.io.base.DataBank; import org.jlab.jnp.hipo4.data.Event; import org.jlab.jnp.hipo4.data.Schema; import org.jlab.jnp.hipo4.data.SchemaFactory; -import org.jlab.jnp.hipo4.io.HipoWriter; import org.jlab.jnp.hipo4.io.HipoWriterSorted; - /** * * @author gavalian */ public class HipoDataSync implements DataSync { - public static Logger LOGGER = Logger.getLogger(HipoDataSync.class.getName()); + public static final Logger LOGGER = Logger.getLogger(HipoDataSync.class.getName()); HipoWriterSorted writer = null; @@ -31,9 +26,7 @@ public HipoDataSync(){ this.writer.setCompressionType(2); String env = System.getenv("CLAS12DIR"); writer.getSchemaFactory().initFromDirectory(env + "/etc/bankdefs/hipo4"); - LOGGER.log(Level.INFO,"[HipoDataSync] ---> dictionary size = " + writer.getSchemaFactory().getSchemaList().size()); - //this.writer.getSchemaFactory().initFromDirectory("CLAS12DIR", "etc/bankdefs/hipo"); - //this.writer.getSchemaFactory().show(); + LOGGER.log(Level.INFO, "[HipoDataSync] ---> dictionary size = {0}", writer.getSchemaFactory().getSchemaList().size()); } public HipoDataSync(SchemaFactory factory){ @@ -47,13 +40,6 @@ public HipoDataSync(SchemaFactory factory){ @Override public void open(String file) { - /* - EvioDataDictionary dict = EvioFactory.getDictionary(); - String[] descList = dict.getDescriptorList(); - for(String desc : descList){ - String descString = dict.getDescriptor(desc).toString(); - this.writer.addHeader(descString); - }*/ this.writer.open(file); } @@ -67,7 +53,6 @@ public void addSchemaList(List schemaList){ @Override public void writeEvent(DataEvent event) { - //EvioDataEvent evioEvent = (EvioDataEvent) event; if(event instanceof HipoDataEvent) { HipoDataEvent hipoEvent = (HipoDataEvent) event; @@ -76,6 +61,7 @@ public void writeEvent(DataEvent event) { } public HipoWriterSorted getWriter(){ return writer;} + @Override public void close() { this.writer.close(); } @@ -116,79 +102,10 @@ public static void main(String[] args){ bank.setInt("TDCL", k, (int) (Math.random()*3000) ); bank.setInt("TDCR", k, (int) (Math.random()*3000) ); } - //bank.show(); event.appendBanks(bank,bankDC); writer.writeEvent(event); } writer.close(); - /* - if(args.length<3){ - HipoDataSync.printUsage(); - System.exit(0); - } - - if(args[0].startsWith("-")==false){ - System.out.println("\n\n--> please provide compression type"); - HipoDataSync.printUsage(); - System.exit(0); - } - - int compressionType = -1; - - if(args[0].compareTo("-u")==0){ - compressionType = 0; - } - - if(args[0].compareTo("-gzip")==0){ - compressionType = 1; - } - - if(args[0].compareTo("-lz4")==0){ - compressionType = 2; - } - - if(compressionType<0){ - HipoDataSync.printUsage(); - System.out.println("[error] ---> compression type string is invalid."); - System.exit(0); - } - - String outputFile = args[1]; - List inputFiles = new ArrayList(); - - for(int i = 2; i < args.length; i++){ - inputFiles.add(args[i]); - } - - File outFile = new File(outputFile); - - if(outFile.exists()==true){ - System.out.println("\n[error] ---> can not overwrite existing file.\n\n"); - System.exit(0); - } - - HipoDataSync writer = new HipoDataSync(); - writer.setCompressionType(compressionType); - writer.open(outputFile); - for(String inFile : inputFiles){ - EvioSource reader = new EvioSource(); - reader.open(inFile); - while(reader.hasEvent()){ - EvioDataEvent event = (EvioDataEvent) reader.getNextEvent(); - - EvioDataBank bankFTOF = EvioHipoEvent.getBankFTOF(event); - EvioDataEvent cevent = EvioFactory.createEvioEvent(); - cevent.appendBank(bankFTOF); - if(event.hasBank("TimeBasedTrkg::TBTracks")==true){ - EvioDataBank bankTRK = (EvioDataBank) event.getBank("TimeBasedTrkg::TBTracks"); - cevent.appendBanks(bankTRK); - } - - writer.writeEvent(cevent); - //writer.writeEvent(event); - } - } - writer.close();*/ } } diff --git a/common-tools/clas-io/src/main/java/org/jlab/io/hipo/HipoRingSource.java b/common-tools/clas-io/src/main/java/org/jlab/io/hipo/HipoRingSource.java index a10b972047..2f5fa64d2a 100644 --- a/common-tools/clas-io/src/main/java/org/jlab/io/hipo/HipoRingSource.java +++ b/common-tools/clas-io/src/main/java/org/jlab/io/hipo/HipoRingSource.java @@ -1,8 +1,3 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ package org.jlab.io.hipo; import java.io.File; @@ -35,44 +30,12 @@ */ public class HipoRingSource implements DataSource { - private List eventStore = new ArrayList(); + private List eventStore = new ArrayList<>(); private int eventStoreMaxCapacity = 500; private SchemaFactory dictionary = new SchemaFactory(); private xMsg xmsgServer = null; - - public HipoRingSource(String host){ - /* - super("DataSource", - new xMsgProxyAddress(host, xMsgConstants.DEFAULT_PORT), - new xMsgRegAddress(host, xMsgConstants.REGISTRAR_PORT), - 2); - final String domain = "clas12-domain"; - final String subject = "clas12-data"; - final String type = "data"; - final String description = "clas12 data distribution ring"; - - xMsgTopic topic = xMsgTopic.build(domain, subject, type); - - try { - // Register this subscriber - register(xMsgRegInfo.subscriber(topic, description)); - } catch (xMsgException ex) { - Logger.getLogger(HipoRingSource.class.getName()).log(Level.SEVERE, null, ex); - } - - try { - // Subscribe to default proxy - subscribe(topic, new MyCallBack()); - } catch (xMsgException ex) { - Logger.getLogger(HipoRingSource.class.getName()).log(Level.SEVERE, null, ex); - } - System.out.printf("Subscribed to = %s%n", topic); - - this.dictionary.initFromDirectory("CLAS12DIR", "etc/bankdefs/hipo"); - */ - String envCLAS = System.getenv("CLAS12DIR"); dictionary.initFromDirectory(envCLAS + "/etc/bankdefs/hipo4"); } @@ -121,7 +84,7 @@ public static HipoRingSource createSource(){ @Override public boolean hasEvent() { - return (eventStore.size()>0); + return !eventStore.isEmpty(); } @Override @@ -141,13 +104,11 @@ private boolean createConnection(String host){ } } catch (xMsgException ex) { - //Logger.getLogger(HipoRingSource.class.getName()).log(Level.SEVERE, null, ex); System.out.println(" >>> connection to server " + host + " : failed"); this.xmsgServer.destroy(); this.xmsgServer = null; result = false; } - //System.out.println("-----> connection estabilished..."); return result; } @@ -187,12 +148,11 @@ public void open(String filename) { } System.out.println(" >>> subscription to topic : success\n\n"); - //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } @Override public void open(ByteBuffer buff) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + throw new UnsupportedOperationException("Not supported yet."); } @Override @@ -202,26 +162,21 @@ public int getSize() { @Override public DataEventList getEventList(int start, int stop) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + throw new UnsupportedOperationException("Not supported yet."); } @Override public DataEventList getEventList(int nrecords) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + throw new UnsupportedOperationException("Not supported yet."); } @Override public DataEvent getNextEvent() { - //System.out.println(" >>> get next event : size = " + eventStore.size()); if(eventStore.isEmpty()){ return null; } HipoDataEvent event = this.eventStore.get(0); - //System.out.println(" >>> success getting event : size = " + eventStore.size()); - //event.show(); this.eventStore.remove(0); - //System.out.println(" >>> FILO cleanup : size = " + eventStore.size()); - //System.out.println("\n\n"); return event; } @@ -245,7 +200,7 @@ public int getCurrentIndex() { return 0; } - + @Override public void close() { /*try { this.getConnection().close(); @@ -257,7 +212,6 @@ public void close() { @Override public DataSourceType getType() { return DataSourceType.STREAM; - //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } @Override @@ -269,15 +223,10 @@ private class MyCallBack implements xMsgCallBack { @Override public void callback(xMsgMessage mm) { byte[] data = mm.getData(); - String type = mm.getMimeType(); - //System.out.println("\n\n >>>>>> received data : mime " + type); - //System.out.println(" >>>>>> received data : size " + data.length); if(eventStore.size()>>>>> adding event to the store : size = %d \n", eventStore.size()); } else { - //System.out.printf(" >>>>>> event store is full : size = %d \n", eventStore.size()); } } } @@ -294,7 +243,6 @@ public static void main(String[] args){ while(true){ if(reader.hasEvent()==true){ - //System.out.println("has event"); DataEvent event = reader.getNextEvent(); try { event.show(); @@ -302,7 +250,6 @@ public static void main(String[] args){ System.out.println("something went wrong"); } } else { - //System.out.println("no event"); try { Thread.sleep(20); } catch (InterruptedException ex) { @@ -310,32 +257,5 @@ public static void main(String[] args){ } } } - //reader.open("localhost"); - /* - OptionParser parser = new OptionParser(); - parser.addRequired("-s"); - - - HipoRingSource reader = HipoRingSource.createSource(); - - while(reader.hasEvent()==true){ - - HipoDataEvent event = (HipoDataEvent) reader.getNextEvent(); - //event.show(); - - try { - Thread.sleep(8000); - } catch (InterruptedException ex) { - Logger.getLogger(HipoRingSource.class.getName()).log(Level.SEVERE, null, ex); - } - - } - System.out.println("DONE"); - */ - /* - String host = args[0]; - try (HipoRingSource subscriber = new HipoRingSource(host)) { - xMsgUtil.keepAlive(); - } */ } } diff --git a/common-tools/clas-io/src/main/java/org/jlab/io/hipo3/Hipo3DataBank.java b/common-tools/clas-io/src/main/java/org/jlab/io/hipo3/Hipo3DataBank.java deleted file mode 100644 index 7ad0492691..0000000000 --- a/common-tools/clas-io/src/main/java/org/jlab/io/hipo3/Hipo3DataBank.java +++ /dev/null @@ -1,205 +0,0 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ -package org.jlab.io.hipo3; - -import java.util.List; -import java.util.Map; -import javax.swing.table.TableModel; - -import org.jlab.io.base.DataBank; -import org.jlab.io.base.DataDescriptor; -import org.jlab.jnp.hipo.data.HipoGroup; -import org.jlab.jnp.hipo.data.HipoNode; -import org.jlab.jnp.hipo.schema.Schema; - -/** - * - * @author gavalian - */ -public class Hipo3DataBank implements DataBank { - - private Hipo3DataDescriptor descriptor = null; - private HipoGroup hipoGroup = null; - - public Hipo3DataBank(Hipo3DataDescriptor desc, int size){ - Map nodes = desc.getSchema().createNodeMap(size); - this.descriptor = desc; - hipoGroup = new HipoGroup(nodes,this.descriptor.getSchema()); - } - - public Hipo3DataBank(Map nodes, Schema desc){ - descriptor = new Hipo3DataDescriptor(); - descriptor.init(desc); - hipoGroup = new HipoGroup(nodes,this.descriptor.getSchema()); - } - - public Hipo3DataBank(HipoGroup group){ - this.hipoGroup = group; - descriptor = new Hipo3DataDescriptor(); - descriptor.init(this.hipoGroup.getSchema()); - } - - public HipoGroup getGroup(){ - return this.hipoGroup; - } - - public String[] getColumnList() { - List columnsList = this.hipoGroup.getSchema().schemaEntryList(); - String[] columns = new String[columnsList.size()]; - for(int i = 0; i < columns.length; i++) columns[i] = columnsList.get(i); - return columns; - } - - public DataDescriptor getDescriptor() { - return this.descriptor; - } - - public double[] getDouble(String path) { - return this.hipoGroup.getNode(path).getDouble(); - } - - public double getDouble(String path, int index) { - return this.hipoGroup.getNode(path).getDouble(index); - } - - public void setDouble(String path, double[] arr) { - //this.getNode(path).setDouble(index, value); - } - - public void setDouble(String path, int row, double value) { - this.hipoGroup.getNode(path).setDouble(row, value); - } - - public void appendDouble(String path, double[] arr) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } - - public float[] getFloat(String path) { - return this.hipoGroup.getNode(path).getFloat(); - } - - public float getFloat(String path, int index) { - return this.hipoGroup.getNode(path).getFloat(index); - } - - public void setFloat(String path, float[] arr) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } - - public void setFloat(String path, int row, float value) { - this.hipoGroup.getNode(path).setFloat(row, value); - } - - public void appendFloat(String path, float[] arr) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } - - public int[] getInt(String path) { - return this.getGroup().getNode(path).getInt(); - } - - public int getInt(String path, int index) { - return this.hipoGroup.getNode(path).getInt(index); - } - - public void setInt(String path, int[] arr) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } - - public void setInt(String path, int row, int value) { - this.hipoGroup.getNode(path).setInt(row, value); - } - - public void appendInt(String path, int[] arr) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } - - public short[] getShort(String path) { - return this.hipoGroup.getNode(path).getShort(); - } - - public short getShort(String path, int index) { - return this.hipoGroup.getNode(path).getShort(index); - } - - public void setShort(String path, short[] arr) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } - - public void setShort(String path, int row, short value) { - this.hipoGroup.getNode(path).setShort(row, value); - } - - public void appendShort(String path, short[] arr) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } - - public long[] getLong(String path) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } - - public long getLong(String path, int index) { - return this.hipoGroup.getNode(path).getLong(index); - } - - public void setLong(String path, long[] arr) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } - - public void setLong(String path, int row, long value) { - this.hipoGroup.getNode(path).setLong(row, value); - } - - public void appendLong(String path, long[] arr) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } - - public byte[] getByte(String path) { - return this.hipoGroup.getNode(path).getByte(); - } - - public byte getByte(String path, int index) { - return this.hipoGroup.getNode(path).getByte(index); - } - - public void setByte(String path, byte[] arr) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } - - public void setByte(String path, int row, byte value) { - this.hipoGroup.getNode(path).setByte(row, value); - } - - public void appendByte(String path, byte[] arr) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } - - public int columns() { - return this.hipoGroup.getSchema().getEntries(); - } - - public int rows() { - return this.hipoGroup.getMaxSize(); - } - - public void show() { - System.out.println(" SHOWING BANK"); - this.hipoGroup.show(); - } - - public void reset() { - - } - - public void allocate(int rows) { - - } - - public TableModel getTableModel(String mask) { - return null; - } - -} diff --git a/common-tools/clas-io/src/main/java/org/jlab/io/hipo3/Hipo3DataDescriptor.java b/common-tools/clas-io/src/main/java/org/jlab/io/hipo3/Hipo3DataDescriptor.java deleted file mode 100644 index bf640195dc..0000000000 --- a/common-tools/clas-io/src/main/java/org/jlab/io/hipo3/Hipo3DataDescriptor.java +++ /dev/null @@ -1,100 +0,0 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ -package org.jlab.io.hipo3; - -import java.util.List; -import org.jlab.io.base.DataDescriptor; -import org.jlab.jnp.hipo.data.HipoNodeType; -import org.jlab.jnp.hipo.schema.Schema; -import org.jlab.jnp.hipo.schema.Schema.SchemaEntry; - -/** - * - * @author gavalian - */ -public class Hipo3DataDescriptor implements DataDescriptor { - - private final Schema hipoSchema = new Schema(); - - public Hipo3DataDescriptor(){ - - } - - public Hipo3DataDescriptor(Schema schema){ - this.init(schema); - } - - public final void init(Schema schema){ - hipoSchema.copy(schema); - } - - public void init(String s) { - this.hipoSchema.setFromText(s); - } - - @Override - public String[] getEntryList() { - List entryList = hipoSchema.schemaEntryList(); - String[] entries = new String[entryList.size()]; - int counter = 0; - for(int i = 0; i < entryList.size(); i++){ - entries[i] = entryList.get(i); - } - return entries; - } - - public String getXML() { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } - - public boolean hasEntry(String entry) { - return (this.hipoSchema.getEntry(entry)!=null); - } - - public boolean hasEntries(String... entries) { - for(String entry : entries){ - if(hasEntry(entry)==false) return false; - } - return true; - } - - public int getProperty(String property_name, String entry_name) { - if(property_name.compareTo("type")==0){ - SchemaEntry entry = this.hipoSchema.getEntry(entry_name); - if(entry!=null){ - if(entry.getType()==HipoNodeType.BYTE) return 1; - if(entry.getType()==HipoNodeType.SHORT) return 2; - if(entry.getType()==HipoNodeType.INT) return 3; - if(entry.getType()==HipoNodeType.FLOAT) return 5; - if(entry.getType()==HipoNodeType.DOUBLE) return 6; - return 0; - } - } - return 0; - } - - public int getProperty(String property_name) { - return 1; - } - - public void setPropertyString(String name, String value) { - - } - - public String getPropertyString(String property_name) { - return "undefined"; - } - - public void show() { - System.out.println(this.hipoSchema.toString()); - } - - public String getName() { - return this.hipoSchema.getName(); - } - - public Schema getSchema(){ return this.hipoSchema;} -} diff --git a/common-tools/clas-io/src/main/java/org/jlab/io/hipo3/Hipo3DataDictionary.java b/common-tools/clas-io/src/main/java/org/jlab/io/hipo3/Hipo3DataDictionary.java deleted file mode 100644 index eda645009e..0000000000 --- a/common-tools/clas-io/src/main/java/org/jlab/io/hipo3/Hipo3DataDictionary.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ -package org.jlab.io.hipo3; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import org.jlab.io.base.DataBank; -import org.jlab.io.base.DataDescriptor; -import org.jlab.io.base.DataDictionary; -import org.jlab.jnp.hipo.data.HipoNode; -import org.jlab.jnp.hipo.schema.Schema; -import org.jlab.jnp.hipo.schema.SchemaFactory; - - -/** - * - * @author gavalian - */ -public class Hipo3DataDictionary implements DataDictionary { - - private final Map descriptors = new HashMap(); - - public Hipo3DataDictionary(){ - - SchemaFactory factory = new SchemaFactory(); - factory.initFromDirectory("CLAS12DIR", "etc/bankdefs/hipo"); - List entries = factory.getSchemaList(); - //System.out.println(" schema size = " + entries.size()); - for(Schema sch : entries){ - Hipo3DataDescriptor desc = new Hipo3DataDescriptor(sch); - descriptors.put(desc.getName(), desc); - //System.out.println("name = " + sch.getName() + " desc = " + desc.getName()); - } - System.out.println(" >>>>> loading default dictionary : entries = " + descriptors.size()); - } - - @Override - public void init(String format) { - System.out.println("---- INITIALIZATION NOT IMPLEMENTED ----"); - } - - @Override - public String getXML() { - return ""; - } - - - - @Override - public String[] getDescriptorList() { - Set list = this.descriptors.keySet(); - int counter = 0; - String[] tokens = new String[list.size()]; - for(String item : list){ - tokens[counter] = item; - counter++; - } - return tokens; - } - - @Override - public DataDescriptor getDescriptor(String desc_name) { - return descriptors.get(desc_name); - } - - @Override - public DataBank createBank(String name, int rows) { - Map map = descriptors.get(name).getSchema().createNodeMap(rows); - Hipo3DataBank bank = new Hipo3DataBank(map,descriptors.get(name).getSchema()); - return bank; - } - - public static void main(String[] args){ - System.setProperty("CLAS12DIR", "/Users/gavalian/Work/Software/Release-9.0/COATJAVA/coatjava"); - Hipo3DataDictionary dict = new Hipo3DataDictionary(); - - String[] list = dict.getDescriptorList(); - for(String item : list){ - System.out.println("---> " + item); - Hipo3DataDescriptor desc = (Hipo3DataDescriptor) dict.getDescriptor(item); - String[] entries = desc.getEntryList(); - for(int i = 0; i < entries.length; i++){ - System.out.println("\t\t---> " + entries[i]); - } - } - } -} diff --git a/common-tools/clas-io/src/main/java/org/jlab/io/hipo3/Hipo3DataEvent.java b/common-tools/clas-io/src/main/java/org/jlab/io/hipo3/Hipo3DataEvent.java deleted file mode 100644 index b1a05fd261..0000000000 --- a/common-tools/clas-io/src/main/java/org/jlab/io/hipo3/Hipo3DataEvent.java +++ /dev/null @@ -1,300 +0,0 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ -package org.jlab.io.hipo3; - -import java.nio.ByteBuffer; -import java.nio.ByteOrder; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import org.jlab.io.base.DataBank; -import org.jlab.io.base.DataDictionary; -import org.jlab.io.base.DataEvent; -import org.jlab.io.base.DataEventType; -import org.jlab.jnp.hipo.data.HipoEvent; -import org.jlab.jnp.hipo.data.HipoGroup; -import org.jlab.jnp.hipo.data.HipoNode; -import org.jlab.jnp.hipo.schema.Schema; -import org.jlab.jnp.hipo.schema.Schema.SchemaEntry; -import org.jlab.jnp.hipo.schema.SchemaFactory; - -/** - * - * @author gavalian - */ -public class Hipo3DataEvent implements DataEvent { - - private HipoEvent hipoEvent = null; - private DataEventType eventType = DataEventType.EVENT_ACCUMULATE; - - public Hipo3DataEvent(byte[] array, SchemaFactory factory){ - hipoEvent = new HipoEvent(array,factory); - } - - public Hipo3DataEvent(HipoEvent event){ - this.hipoEvent = event; - } - - public HipoEvent getHipoEvent(){return this.hipoEvent;} - - public void initDictionary(SchemaFactory factory){ - this.hipoEvent.getSchemaFactory().copy(factory); - } - - @Override - public String[] getBankList() { - List schemaList = hipoEvent.getSchemaFactory().getSchemaList(); - List existingBanks = new ArrayList(); - for(Schema schema : schemaList){ - int group = schema.getGroup(); - if(hipoEvent.hasGroup(group)==true){ - existingBanks.add(schema.getName()); - } - } - - String[] list = new String[existingBanks.size()]; - for(int i = 0; i < list.length; i++) list[i] = existingBanks.get(i); - return list; - } - - public String[] getColumnList(String bank_name) { - List columnsList = this.hipoEvent.getSchemaFactory().getSchema(bank_name).schemaEntryList(); - String[] columns = new String[columnsList.size()]; - for(int i = 0; i < columns.length; i++) columns[i] = columnsList.get(i); - return columns; - } - - public DataDictionary getDictionary() { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } - - public ByteBuffer getEventBuffer() { - ByteBuffer buffer = ByteBuffer.wrap(this.hipoEvent.getDataBuffer()); - buffer.order(ByteOrder.LITTLE_ENDIAN); - return buffer; - } - - public void appendBank(DataBank bank) { - if(bank==null) return; - if(bank instanceof Hipo3DataBank){ - HipoGroup group = ((Hipo3DataBank) bank).getGroup(); - hipoEvent.writeGroup(group); - } - } - - public void appendBanks(DataBank... bank) { - for(DataBank item : bank){ - this.appendBank(item); - } - } - - @Override - public boolean hasBank(String name) { - return (this.hipoEvent.hasGroup(name)); - } - - @Override - public DataBank getBank(String bank_name) { - if(this.hipoEvent.getSchemaFactory().hasSchema(bank_name)==true){ - //Schema schema = this.hipoEvent.getSchemaFactory().getSchema(bank_name); - //Map map = this.hipoEvent.getGroup(schema.getGroup()); - HipoGroup group = hipoEvent.getGroup(bank_name); - Hipo3DataBank bank = new Hipo3DataBank(group.getNodesMap(),group.getSchema()); - return bank; - } - //HipoDataBank bank = new HipoDataBank(); - return null; - } - - public void getBank(String bank_name, DataBank bank) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } - - public void setProperty(String property, String value) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } - - public String getProperty(String property) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } - - public double[] getDouble(String path) { - HipoNode node = this.getHipoNodeByPath(path); - if(node==null){ - System.out.println("\n>>>>> error : getting node failed : " + path); - return new double[0]; - } - return node.getDouble(); - //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } - - public void setDouble(String path, double[] arr) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } - - public void appendDouble(String path, double[] arr) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } - - public float[] getFloat(String path) { - HipoNode node = this.getHipoNodeByPath(path); - if(node==null){ - System.out.println("\n>>>>> error : getting node failed : " + path); - return new float[0]; - } - return node.getFloat(); - //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } - - public void setFloat(String path, float[] arr) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } - - public void appendFloat(String path, float[] arr) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } - - public int[] getInt(String path) { - HipoNode node = this.getHipoNodeByPath(path); - if(node==null){ - System.out.println("\n>>>>> error : getting node failed : " + path); - return new int[0]; - } - return node.getInt(); - } - - public void setInt(String path, int[] arr) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } - - public void appendInt(String path, int[] arr) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } - - public short[] getShort(String path) { - HipoNode node = this.getHipoNodeByPath(path); - if(node==null){ - System.out.println("\n>>>>> error : getting node failed : " + path); - return new short[0]; - } - return node.getShort(); - } - - public void setShort(String path, short[] arr) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } - - public void appendShort(String path, short[] arr) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } - - public HipoNode getHipoNodeByPath(String path){ - String[] bank_and_item = path.split("[.]+"); - if(bank_and_item.length<2){ - System.out.println("\n>>>>> error : syntax error in path name : " + path); - return null; - } - Schema schema = this.hipoEvent.getSchemaFactory().getSchema(bank_and_item[0]); - if(schema==null){ - System.out.println("\n>>>>> error : can not find schema with name : " - + bank_and_item[0]); - return null; - } - - SchemaEntry entry = schema.getEntry(bank_and_item[1]); - if(entry==null){ - System.out.println("\n>>>>> error : schema " + bank_and_item[0] + - " dose not have an entry with name :" - + bank_and_item[1]); - return null; - } - - HipoNode node = hipoEvent.getNode(schema.getGroup(), entry.getId()); - return node; - } - - public byte[] getByte(String path) { - HipoNode node = this.getHipoNodeByPath(path); - if(node==null){ - System.out.println("\n>>>>> error : getting node failed : " + path); - return new byte[0]; - } - return node.getByte(); - } - - public void setByte(String path, byte[] arr) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } - - public void appendByte(String path, byte[] arr) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } - - public void setType(DataEventType type) { - this.eventType = type; - } - - public DataEventType getType() { - return this.eventType; - } - - public void show(){ - this.hipoEvent.show(); - } - - public void showBankByOrder(int order){ - this.hipoEvent.showGroupByOrder(order); - } - - @Override - public DataBank createBank(String bank_name, int rows) { - if(this.hipoEvent.getSchemaFactory().hasSchema(bank_name)==false){ - System.out.println(">>>>> error : descriptor not found : " + bank_name); - System.out.println(">>>>> error : number of descriptors : " + - hipoEvent.getSchemaFactory().getSchemaList().size()); - System.out.println(); - this.hipoEvent.getSchemaFactory().show(); - return null; - } - HipoGroup group = this.hipoEvent.getSchemaFactory().getSchema(bank_name).createGroup(rows); - Hipo3DataBank bank = new Hipo3DataBank(group); - return bank; - } - - @Override - public void removeBank(String bankName) { - this.hipoEvent.removeGroup(bankName); - } - - @Override - public void removeBanks(String... bankNames) { - - //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } - - @Override - public long[] getLong(String path) { - HipoNode node = this.getHipoNodeByPath(path); - if(node==null){ - System.out.println("\n>>>>> error : getting node failed : " + path); - return new long[0]; - } - int size = node.getDataSize(); - long[] data = new long[size]; - for(int i =0; i < data.length; i++) data[i] = node.getLong(i); - return data; - } - - @Override - public void setLong(String path, long[] arr) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } - - @Override - public void appendLong(String path, long[] arr) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } -} diff --git a/common-tools/clas-io/src/main/java/org/jlab/io/hipo3/Hipo3DataSource.java b/common-tools/clas-io/src/main/java/org/jlab/io/hipo3/Hipo3DataSource.java deleted file mode 100644 index 732c9aac95..0000000000 --- a/common-tools/clas-io/src/main/java/org/jlab/io/hipo3/Hipo3DataSource.java +++ /dev/null @@ -1,169 +0,0 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ -package org.jlab.io.hipo3; - -import java.io.File; -import java.nio.ByteBuffer; -import org.jlab.io.base.DataEvent; -import org.jlab.io.base.DataEventList; -import org.jlab.io.base.DataEventType; -import org.jlab.io.base.DataSource; -import org.jlab.io.evio.EvioDataDictionary; -import org.jlab.io.base.DataSourceType; -import org.jlab.jnp.hipo.data.HipoEvent; -import org.jlab.jnp.hipo.io.HipoReader; -import org.jlab.jnp.hipo.schema.SchemaFactory; - -/** - * - * @author gavalian - */ -public class Hipo3DataSource implements DataSource { - - HipoReader reader = null; - EvioDataDictionary dictionary = new EvioDataDictionary(); - int numberOfRecords = 0; - int currentEventNumber = 0; - int minEventNumber = 0; - int numberOfEvent = 0; - - public Hipo3DataSource(){ - this.reader = new HipoReader(); - } - - @Override - public boolean hasEvent() { - return reader.hasNext(); - } - - @Override - public void open(File file) { - this.open(file.getAbsolutePath()); - } - /** - * Creates a Writer class with Dictionary from the Reader. - * This method should be used when filtering the input file - * to ensure consistency of dictionaries and banks in the output. - * @return HipoDataSync object for writing an output. - */ - public Hipo3DataSync createWriter(){ - SchemaFactory factory = reader.getSchemaFactory(); - Hipo3DataSync writer = new Hipo3DataSync(factory); - return writer; - } - - @Override - public void open(String filename) { - this.reader.open(filename); - System.out.println("[DataSourceDump] --> opened file with events # " + this.reader.getEventCount()); - //this.reader.getSchemaFactory().show(); - /* - HipoRecord header = this.reader.getHeaderRecord(); - int ncount = header.getEventCount(); - System.out.println("[HipoDataSource] ---> dictionary record opened. # entries = " + ncount); - for(int ev = 0; ev < ncount; ev++){ - byte[] descBytes = header.getEvent(ev); - String descString = new String(descBytes); - //System.out.println("init dictionary : " + descString); - EvioDataDescriptor descriptor = new EvioDataDescriptor(descString); - this.dictionary.addDescriptor(descriptor); - }*/ - //this.dictionary.show(); - /*this.minEventNumber = 0; - this.currentEventNumber = 0; - this.numberOfEvent = this.reader.getEventCount();*/ - } - - public void open(ByteBuffer buff) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } - - public void close() { - - } - - @Override - public int getSize() { - return reader.getEventCount(); - } - - @Override - public DataEventList getEventList(int start, int stop) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } - - @Override - public DataEventList getEventList(int nrecords) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } - - @Override - public DataEvent getNextEvent() { - HipoEvent hipoEvent = reader.readNextEvent(); - /*hipoEvent.getDataBuffer(); - System.out.println(" GET NEXT HIPO EVENT : DICTIONARY SIZE = " + - hipoEvent.getSchemaFactory().getSchemaList().size() + " EVENT LENGTH = " - + hipoEvent.getDataBuffer().length); - hipoEvent.showNodes();*/ - Hipo3DataEvent evioEvent = new Hipo3DataEvent(hipoEvent.getDataBuffer(),hipoEvent.getSchemaFactory()); - if(reader.hasNext()==true){ - evioEvent.setType(DataEventType.EVENT_ACCUMULATE); - } else { - evioEvent.setType(DataEventType.EVENT_STOP); - } - return evioEvent; - } - - @Override - public DataEvent getPreviousEvent() { - HipoEvent hipoEvent = reader.readPreviousEvent(); - hipoEvent.getDataBuffer(); - Hipo3DataEvent evioEvent = new Hipo3DataEvent(hipoEvent.getDataBuffer(),hipoEvent.getSchemaFactory()); - return evioEvent; - - } - - @Override - public DataEvent gotoEvent(int index) { - HipoEvent hipoEvent = reader.readEvent(index); - hipoEvent.getDataBuffer(); - Hipo3DataEvent evioEvent = new Hipo3DataEvent(hipoEvent.getDataBuffer(),hipoEvent.getSchemaFactory()); - return evioEvent; - } - - @Override - public void reset() { - this.currentEventNumber = 0; - } - - @Override - public int getCurrentIndex() { - return this.currentEventNumber; - } - - public static void main(String[] args){ - Hipo3DataSource reader = new Hipo3DataSource(); - reader.open("test_hipoio.hipo"); - int counter = 0; - while(reader.hasEvent()==true){ - DataEvent event = reader.getNextEvent(); - System.out.println("EVENT # " + counter); - event.show(); - counter++; - } - } - - @Override - public DataSourceType getType() { - return DataSourceType.FILE; - //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } - - @Override - public void waitForEvents() { - - } -} diff --git a/common-tools/clas-io/src/main/java/org/jlab/io/hipo3/Hipo3DataSync.java b/common-tools/clas-io/src/main/java/org/jlab/io/hipo3/Hipo3DataSync.java deleted file mode 100644 index afa2d9b5cb..0000000000 --- a/common-tools/clas-io/src/main/java/org/jlab/io/hipo3/Hipo3DataSync.java +++ /dev/null @@ -1,176 +0,0 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ -package org.jlab.io.hipo3; - -import org.jlab.io.base.DataEvent; -import org.jlab.io.base.DataSync; - - -import org.jlab.io.base.DataBank; -import org.jlab.io.evio.EvioDataBank; -import org.jlab.jnp.hipo.data.HipoEvent; -import org.jlab.jnp.hipo.io.HipoWriter; -import org.jlab.jnp.hipo.schema.SchemaFactory; - -/** - * - * @author gavalian - */ -public class Hipo3DataSync implements DataSync { - - HipoWriter writer = null; - - public Hipo3DataSync(){ - this.writer = new HipoWriter(); - this.writer.setCompressionType(2); - writer.appendSchemaFactoryFromDirectory("CLAS12DIR", "etc/bankdefs/hipo"); - System.out.println("[HipoDataSync] ---> dictionary size = " + writer.getSchemaFactory().getSchemaList().size()); - //this.writer.getSchemaFactory().initFromDirectory("CLAS12DIR", "etc/bankdefs/hipo"); - //this.writer.getSchemaFactory().show(); - } - - public Hipo3DataSync(SchemaFactory factory){ - this.writer = new HipoWriter(); - this.writer.setCompressionType(2); - writer.appendSchemaFactory(factory); - } - - @Override - public void open(String file) { - /* - EvioDataDictionary dict = EvioFactory.getDictionary(); - String[] descList = dict.getDescriptorList(); - for(String desc : descList){ - String descString = dict.getDescriptor(desc).toString(); - this.writer.addHeader(descString); - }*/ - this.writer.open(file); - } - - @Override - public void writeEvent(DataEvent event) { - //EvioDataEvent evioEvent = (EvioDataEvent) event; - if(event instanceof Hipo3DataEvent) { - Hipo3DataEvent hipoEvent = (Hipo3DataEvent) event; - this.writer.writeEvent(hipoEvent.getHipoEvent()); - } - } - - public void close() { - this.writer.close(); - } - - public void setCompressionType(int type){ - this.writer.setCompressionType(type); - } - - public DataEvent createEvent() { - HipoEvent event = this.writer.createEvent(); - return new Hipo3DataEvent(event); - } - - public static void printUsage(){ - System.out.println("\tUsage: convert -[option] output.hipo input.evio [input2.evio] [input3.evio]"); - System.out.println("\n\t Options :"); - System.out.println("\t\t -u : uncompressed"); - System.out.println("\t\t -gzip : gzip compression"); - System.out.println("\t\t -lz4 : lz4 compression"); - System.out.println("\n"); - } - - public static void main(String[] args){ - - Hipo3DataSync writer = new Hipo3DataSync(); - writer.open("test_hipoio.hipo"); - for(int i = 0; i < 20; i++){ - DataEvent event = writer.createEvent(); - DataBank bank = event.createBank("FTOF::dgtz", 12); - DataBank bankDC = event.createBank("DC::dgtz", 7); - for(int k = 0; k < 5; k++){ - bank.setByte("sector", k, (byte) (1+k)); - bank.setByte("layer", k, (byte) (2+k)); - bank.setShort("component", k, (short) (2+k*5)); - bank.setInt("ADCL", k, (int) (Math.random()*3000) ); - bank.setInt("ADCR", k, (int) (Math.random()*3000) ); - bank.setInt("TDCL", k, (int) (Math.random()*3000) ); - bank.setInt("TDCR", k, (int) (Math.random()*3000) ); - } - //bank.show(); - event.appendBanks(bank,bankDC); - writer.writeEvent(event); - } - writer.close(); - /* - if(args.length<3){ - HipoDataSync.printUsage(); - System.exit(0); - } - - if(args[0].startsWith("-")==false){ - System.out.println("\n\n--> please provide compression type"); - HipoDataSync.printUsage(); - System.exit(0); - } - - int compressionType = -1; - - if(args[0].compareTo("-u")==0){ - compressionType = 0; - } - - if(args[0].compareTo("-gzip")==0){ - compressionType = 1; - } - - if(args[0].compareTo("-lz4")==0){ - compressionType = 2; - } - - if(compressionType<0){ - HipoDataSync.printUsage(); - System.out.println("[error] ---> compression type string is invalid."); - System.exit(0); - } - - String outputFile = args[1]; - List inputFiles = new ArrayList(); - - for(int i = 2; i < args.length; i++){ - inputFiles.add(args[i]); - } - - File outFile = new File(outputFile); - - if(outFile.exists()==true){ - System.out.println("\n[error] ---> can not overwrite existing file.\n\n"); - System.exit(0); - } - - HipoDataSync writer = new HipoDataSync(); - writer.setCompressionType(compressionType); - writer.open(outputFile); - for(String inFile : inputFiles){ - EvioSource reader = new EvioSource(); - reader.open(inFile); - while(reader.hasEvent()){ - EvioDataEvent event = (EvioDataEvent) reader.getNextEvent(); - - EvioDataBank bankFTOF = EvioHipoEvent.getBankFTOF(event); - EvioDataEvent cevent = EvioFactory.createEvioEvent(); - cevent.appendBank(bankFTOF); - if(event.hasBank("TimeBasedTrkg::TBTracks")==true){ - EvioDataBank bankTRK = (EvioDataBank) event.getBank("TimeBasedTrkg::TBTracks"); - cevent.appendBanks(bankTRK); - } - - writer.writeEvent(cevent); - //writer.writeEvent(event); - } - } - writer.close();*/ - } - -} diff --git a/common-tools/clas-io/src/main/java/org/jlab/io/hipo3/Hipo3RingSource.java b/common-tools/clas-io/src/main/java/org/jlab/io/hipo3/Hipo3RingSource.java deleted file mode 100644 index bccc050d1e..0000000000 --- a/common-tools/clas-io/src/main/java/org/jlab/io/hipo3/Hipo3RingSource.java +++ /dev/null @@ -1,337 +0,0 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ -package org.jlab.io.hipo3; - -import java.io.File; -import java.nio.ByteBuffer; -import java.util.ArrayList; -import java.util.List; -import java.util.logging.Level; -import java.util.logging.Logger; -import javax.swing.JOptionPane; -import org.jlab.coda.xmsg.core.xMsg; -import org.jlab.coda.xmsg.core.xMsgCallBack; -import org.jlab.coda.xmsg.core.xMsgConstants; -import org.jlab.coda.xmsg.core.xMsgMessage; -import org.jlab.coda.xmsg.core.xMsgTopic; -import org.jlab.coda.xmsg.data.xMsgRegInfo; -import org.jlab.coda.xmsg.excp.xMsgException; -import org.jlab.coda.xmsg.net.xMsgProxyAddress; -import org.jlab.coda.xmsg.net.xMsgRegAddress; -import org.jlab.io.base.DataEvent; -import org.jlab.io.base.DataEventList; -import org.jlab.io.base.DataSource; -import org.jlab.io.base.DataSourceType; -import org.jlab.jnp.hipo.schema.SchemaFactory; -import org.jlab.utils.options.OptionParser; - -/** - * - * @author gavalian - */ -public class Hipo3RingSource implements DataSource { - - private List eventStore = new ArrayList(); - private int eventStoreMaxCapacity = 500; - private SchemaFactory dictionary = new SchemaFactory(); - private xMsg xmsgServer = null; - - - - public Hipo3RingSource(String host){ - /* - super("DataSource", - new xMsgProxyAddress(host, xMsgConstants.DEFAULT_PORT), - new xMsgRegAddress(host, xMsgConstants.REGISTRAR_PORT), - 2); - final String domain = "clas12-domain"; - final String subject = "clas12-data"; - final String type = "data"; - final String description = "clas12 data distribution ring"; - - xMsgTopic topic = xMsgTopic.build(domain, subject, type); - - try { - // Register this subscriber - register(xMsgRegInfo.subscriber(topic, description)); - } catch (xMsgException ex) { - Logger.getLogger(HipoRingSource.class.getName()).log(Level.SEVERE, null, ex); - } - - try { - // Subscribe to default proxy - subscribe(topic, new MyCallBack()); - } catch (xMsgException ex) { - Logger.getLogger(HipoRingSource.class.getName()).log(Level.SEVERE, null, ex); - } - System.out.printf("Subscribed to = %s%n", topic); - - this.dictionary.initFromDirectory("CLAS12DIR", "etc/bankdefs/hipo"); - */ - dictionary.initFromDirectory("CLAS12DIR", "etc/bankdefs/hipo"); - } - - public Hipo3RingSource(){ - dictionary.initFromDirectory("CLAS12DIR", "etc/bankdefs/hipo"); - } - - public static Hipo3RingSource createSourceDaq(){ - String daqHosts = "129.57.167.107:129.57.167.109:129.57.167.226:129.57.167.227:129.57.167.41:129.57.167.60:129.57.68.135"; - Hipo3RingSource reader = new Hipo3RingSource(); - reader.open(daqHosts); - return reader; - } - - public static Hipo3RingSource createSource(){ - String s = (String)JOptionPane.showInputDialog( - null, - "Complete the sentence:\n" - + "\"Green eggs and...\"", - "Customized Dialog", - JOptionPane.PLAIN_MESSAGE, - null, - null, - "0.0.0.0"); - if(s!=null){ - System.out.println("----> connecting to host : " + s); - Hipo3RingSource source = new Hipo3RingSource(); - source.open(s); - System.out.println("\n\n"); - System.out.println(" |----> caching connection ---> "); - for(int i = 0; i < 5; i++){ - try { - Thread.sleep(1000); - System.out.println(" |----> caching connection ---- " + source.getSize()); - } catch (InterruptedException ex) { - Logger.getLogger(Hipo3RingSource.class.getName()).log(Level.SEVERE, null, ex); - } - } - return source; - } - - return null; - } - - @Override - public boolean hasEvent() { - return (eventStore.size()>0); - } - - @Override - public void open(File file) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } - - private boolean createConnection(String host){ - boolean result = true; - this.xmsgServer = new xMsg("DataSource", - new xMsgProxyAddress(host, xMsgConstants.DEFAULT_PORT), - new xMsgRegAddress(host, xMsgConstants.REGISTRAR_PORT), - 2); - try { - if(this.xmsgServer.getConnection()!=null){ - System.out.println(" >>> connection to server " + host + " : success"); - } - - } catch (xMsgException ex) { - //Logger.getLogger(HipoRingSource.class.getName()).log(Level.SEVERE, null, ex); - System.out.println(" >>> connection to server " + host + " : failed"); - this.xmsgServer.destroy(); - this.xmsgServer = null; - result = false; - } - //System.out.println("-----> connection estabilished..."); - return result; - } - - @Override - public void open(String filename) { - - String[] hostList = filename.split(":"); - - for(String host : hostList){ - boolean result = this.createConnection(host); - if(result==true) break; - } - - if(this.xmsgServer==null){ - System.out.println("----> error finding server."); - return; - } - System.out.println(" >>> subscribing to topic : data-hipo"); - - final String subject = "clas12data"; - final String type = "data-hipo"; - final String description = "clas12 data distribution ring"; - final String domain = "clas12domain"; - xMsgTopic topic = xMsgTopic.build(domain, subject, type); - try { - // Register this subscriber - this.xmsgServer.register(xMsgRegInfo.subscriber(topic, description)); - } catch (xMsgException ex) { - Logger.getLogger(Hipo3RingSource.class.getName()).log(Level.SEVERE, null, ex); - } - - try { - // Subscribe to default proxy - this.xmsgServer.subscribe(topic, new MyCallBack()); - } catch (xMsgException ex) { - Logger.getLogger(Hipo3RingSource.class.getName()).log(Level.SEVERE, null, ex); - } - System.out.println(" >>> subscription to topic : success\n\n"); - - //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } - - @Override - public void open(ByteBuffer buff) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } - - @Override - public int getSize() { - return this.eventStore.size(); - } - - @Override - public DataEventList getEventList(int start, int stop) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } - - @Override - public DataEventList getEventList(int nrecords) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } - - @Override - public DataEvent getNextEvent() { - //System.out.println(" >>> get next event : size = " + eventStore.size()); - if(eventStore.isEmpty()){ - return null; - } - Hipo3DataEvent event = this.eventStore.get(0); - //System.out.println(" >>> success getting event : size = " + eventStore.size()); - //event.show(); - this.eventStore.remove(0); - //System.out.println(" >>> FILO cleanup : size = " + eventStore.size()); - //System.out.println("\n\n"); - return event; - } - - @Override - public DataEvent getPreviousEvent() { - return null; - } - - @Override - public DataEvent gotoEvent(int index) { - return null; - } - - @Override - public void reset() { - this.eventStore.clear(); - } - - @Override - public int getCurrentIndex() { - return 0; - } - - - public void close() { - /*try { - this.getConnection().close(); - } catch (xMsgException ex) { - Logger.getLogger(HipoRingSource.class.getName()).log(Level.SEVERE, null, ex); - }*/ - } - - @Override - public DataSourceType getType() { - return DataSourceType.STREAM; - //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } - - @Override - public void waitForEvents() { - - } - private class MyCallBack implements xMsgCallBack { - - @Override - public void callback(xMsgMessage mm) { - byte[] data = mm.getData(); - String type = mm.getMimeType(); - //System.out.println("\n\n >>>>>> received data : mime " + type); - //System.out.println(" >>>>>> received data : size " + data.length); - if(eventStore.size()>>>>> adding event to the store : size = %d \n", eventStore.size()); - } else { - //System.out.printf(" >>>>>> event store is full : size = %d \n", eventStore.size()); - } - } - } - - public static void main(String[] args){ - - OptionParser parser = new OptionParser(); - parser.addOption("-s", "localhost"); - parser.parse(args); - - Hipo3RingSource reader = new Hipo3RingSource(); - reader.open(parser.getOption("-s").stringValue()); - //reader.open("128.82.188.90:129.57.76.220:129.57.76.215:129.57.76.230"); - - while(true){ - if(reader.hasEvent()==true){ - //System.out.println("has event"); - DataEvent event = reader.getNextEvent(); - try { - event.show(); - } catch (Exception e) { - System.out.println("something went wrong"); - } - } else { - //System.out.println("no event"); - try { - Thread.sleep(20); - } catch (InterruptedException ex) { - Logger.getLogger(Hipo3RingSource.class.getName()).log(Level.SEVERE, null, ex); - } - } - } - //reader.open("localhost"); - /* - OptionParser parser = new OptionParser(); - parser.addRequired("-s"); - - - HipoRingSource reader = HipoRingSource.createSource(); - - while(reader.hasEvent()==true){ - - HipoDataEvent event = (HipoDataEvent) reader.getNextEvent(); - //event.show(); - - try { - Thread.sleep(8000); - } catch (InterruptedException ex) { - Logger.getLogger(HipoRingSource.class.getName()).log(Level.SEVERE, null, ex); - } - - } - System.out.println("DONE"); - */ - /* - String host = args[0]; - try (HipoRingSource subscriber = new HipoRingSource(host)) { - xMsgUtil.keepAlive(); - } */ - } -} diff --git a/common-tools/clas-io/src/main/java/org/jlab/io/ring/DataDistributionRing.java b/common-tools/clas-io/src/main/java/org/jlab/io/ring/DataDistributionRing.java index 4939f4b6df..e208048713 100644 --- a/common-tools/clas-io/src/main/java/org/jlab/io/ring/DataDistributionRing.java +++ b/common-tools/clas-io/src/main/java/org/jlab/io/ring/DataDistributionRing.java @@ -1,8 +1,3 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ package org.jlab.io.ring; import java.util.logging.Level; @@ -38,19 +33,10 @@ public DataDistributionRing(){ */ public void initProxy(){ try { - String host = xMsgUtil.localhost(); xMsgProxyAddress address = new xMsgProxyAddress(host,xMsgConstants.DEFAULT_PORT); System.out.println("\n >>>>> starting xmsg proxy : " + host + "/" + xMsgConstants.DEFAULT_PORT); proxy = new xMsgProxy(xMsgContext.newContext(), address); - - /* Runtime.getRuntime().addShutdownHook(new Thread() { - @Override - public void run() { - xMsgContext.destroyContext(); - proxy.shutdown(); - } - });*/ proxy.start(); System.out.println("\n >>>>> starting xmsg proxy : success"); } catch (xMsgException ex) { @@ -69,14 +55,6 @@ public void initRegistrar(){ try { xMsgRegAddress address = new xMsgRegAddress("localhost", xMsgConstants.REGISTRAR_PORT); xMsgRegistrar registrar = new xMsgRegistrar(xMsgContext.newContext(), address); - /* Runtime.getRuntime().addShutdownHook(new Thread() { - @Override - public void run() { - xMsgContext.destroyContext(); - registrar.shutdown(); - } - });*/ - registrar.start(); System.out.println("\n >>>>> starting xmsg registrar : success"); } catch (xMsgException ex) { @@ -88,35 +66,14 @@ public void initRing(){ producer = new DataRingProducer(); producer.setDelay(3000); producer.start(); - /* - Runtime.getRuntime().addShutdownHook(new Thread() { - @Override - public void run() { - - System.out.println("\n\n\n"); - System.out.println(" ********* Graceful exit initiated"); - producer.shutdown(); - xMsgContext.destroyContext(); - System.out.println(" ********* Destroying xMsg context : done"); - registrar.shutdown(); - System.out.println(" ********* Registrar shudown : done"); - proxy.shutdown(); - System.out.println(" ********* Proxy service shudown : done"); - System.out.println(" ********* Exiting Data Distribution\n\n"); - System.exit(0); - } - });*/ } public void shutdown(){ System.out.println("\n\n\n"); System.out.println(" ********* Graceful exit initiated"); producer.shutdown(); - System.out.println(" ********* Destroying xMsg context : done"); - registrar.shutdown(); - System.out.println(" ********* Registrar shudown : done"); proxy.shutdown(); System.out.println(" ********* Proxy service shudown : done"); diff --git a/common-tools/clas-io/src/main/java/org/jlab/io/ring/DataRingProducer.java b/common-tools/clas-io/src/main/java/org/jlab/io/ring/DataRingProducer.java index 8689e7c98d..3641dc4d8e 100644 --- a/common-tools/clas-io/src/main/java/org/jlab/io/ring/DataRingProducer.java +++ b/common-tools/clas-io/src/main/java/org/jlab/io/ring/DataRingProducer.java @@ -1,8 +1,3 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ package org.jlab.io.ring; import java.util.logging.Level; @@ -34,6 +29,7 @@ public class DataRingProducer extends xMsg { public DataRingProducer(){ super("DataRingProducer"); } + /** * sets the sleep timer after each event has been published. * @param delay @@ -45,28 +41,22 @@ public void setDelay(int delay){ public void updateList(){ } + /** * Start publisher service. establishes connection */ public void start(){ try { - connection = getConnection(); - final String domain = "clas12domain"; final String subject = "clas12data"; final String typeHipo = "data-hipo"; final String typeEvio = "data-evio"; - final String description = "clas12 data distribution ring"; - topicHipo = xMsgTopic.build(domain, subject, typeHipo); topicEvio = xMsgTopic.build(domain, subject, typeEvio); - register(xMsgRegInfo.publisher(topicHipo, description)); - //register(xMsgRegInfo.publisher(topicEvio, description)); - } catch (xMsgException ex) { Logger.getLogger(DataRingProducer.class.getName()).log(Level.SEVERE, null, ex); @@ -89,23 +79,17 @@ public void addEvioEvent(EvioDataEvent event){ System.out.println(" >>>>>> published message : size = " + b.length); System.out.println(" >>>>>> delay " + publishDelay + " ms"); } - //this.publishCounter++; } - public void shutdown(){ - this.unsubscribeAll(); this.connection.close(); this.destroy(); } public void addEvent(HipoDataEvent event){ - byte[] b = event.getEventBuffer().array(); - xMsgMessage msg = new xMsgMessage(topicHipo,"data/hipo",b); - try { this.publish(connection, msg); } catch (xMsgException ex) { @@ -119,7 +103,6 @@ public void addEvent(HipoDataEvent event){ this.publishCounter++; } - public static void main(String[] args){ int delay = Integer.parseInt(args[0]); String file = args[1]; diff --git a/common-tools/clas-io/src/main/java/org/jlab/io/stream/EvioInputStream.java b/common-tools/clas-io/src/main/java/org/jlab/io/stream/EvioInputStream.java index 203325efaa..547bf76113 100644 --- a/common-tools/clas-io/src/main/java/org/jlab/io/stream/EvioInputStream.java +++ b/common-tools/clas-io/src/main/java/org/jlab/io/stream/EvioInputStream.java @@ -1,9 +1,3 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ - package org.jlab.io.stream; import java.io.File; @@ -35,19 +29,16 @@ public class EvioInputStream { private ByteOrder storeByteOrder = ByteOrder.BIG_ENDIAN; private EvioCompactReader evioReader = null; - private int currentEvent; private int currentFileEntries; private EvioCompactStructureHandler cStructure = null; public void open(String filename){ try { evioReader = new EvioCompactReader(new File(filename)); - currentEvent = 1; currentFileEntries = evioReader.getEventCount(); storeByteOrder = evioReader.getFileByteOrder(); System.out.println("****** opened FILE [] ** NEVENTS = " + currentFileEntries + " *******"); - // TODO Auto-generated method stub } catch (EvioException ex) { Logger.getLogger(EvioSource.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { @@ -56,14 +47,14 @@ public void open(String filename){ } public Map getKeys(){ - Map keymap = new HashMap(); + Map keymap = new HashMap<>(); return keymap; } public int getEntries() { return this.currentFileEntries; } public TreeMap getObjectFromNode(EvioNode root){ - TreeMap treemap = new TreeMap(); + TreeMap treemap = new TreeMap<>(); List nodes = root.getAllNodes(); for(int loop = 0; loop < nodes.size(); loop++){ @@ -113,9 +104,8 @@ public TreeMap getObjectTree(int event){ } public ArrayList< TreeMap > getObjectTree(){ - ArrayList< TreeMap > objectArray = new ArrayList< TreeMap >(); + ArrayList< TreeMap > objectArray = new ArrayList< >(); for(int loop = 0; loop < currentFileEntries; loop++){ - //System.err.println("--- reading file ---"); try { ByteBuffer evioBuffer = evioReader.getEventBuffer(loop+1, true); EvioCompactStructureHandler structure = new EvioCompactStructureHandler(evioBuffer,DataType.BANK); @@ -127,7 +117,7 @@ public ArrayList< TreeMap > getObjectTree(){ (node.getDataTypeObj()==DataType.ALSOBANK|| node.getDataTypeObj()==DataType.BANK)){ TreeMap objects = this.getObjectFromNode(node); - if(objects.size()>0) objectArray.add(objects); + if(!objects.isEmpty()) objectArray.add(objects); } } } catch (EvioException ex) { @@ -141,7 +131,7 @@ public void close(){ this.evioReader.close(); } public ArrayList getContainerTags(){ - ArrayList tags = new ArrayList(); + ArrayList tags = new ArrayList<>(); for(int loop = 0; loop < currentFileEntries; loop++){ try { ByteBuffer evioBuffer = evioReader.getEventBuffer(loop+1, true); @@ -152,7 +142,6 @@ public ArrayList getContainerTags(){ item.getDataTypeObj()==DataType.BANK|| item.getDataTypeObj()==DataType.ALSOBANK) tags.add(item.getTag()); - //return item; } } catch (EvioException ex) { Logger.getLogger(EvioInputStream.class.getName()).log(Level.SEVERE, null, ex); @@ -185,10 +174,6 @@ public EvioNode getNodeFromTree(int tag, int num, DataType type){ item.getDataTypeObj()==type) return item; } - /* - if(item.getTag()==tag&&item.getNum()==num&& - item.getDataTypeObj()==type) - return item;*/ } } catch (EvioException ex) { System.err.println("**** ERROR ***** : error getting node [" + tag @@ -208,9 +193,9 @@ public byte[] getByte(int tag, int num){ Logger.getLogger(EvioInputStream.class.getName()).log(Level.SEVERE, null, ex); } } - //byte[] ret = {0}; return null; } + public double[] getDouble(int tag, int num){ EvioNode node = this.getNodeFromTree(tag,num,DataType.DOUBLE64); if(node!=null){ @@ -222,7 +207,6 @@ public double[] getDouble(int tag, int num){ Logger.getLogger(EvioInputStream.class.getName()).log(Level.SEVERE, null, ex); } } - //double[] ret = {0.0}; return null; } diff --git a/common-tools/clas-io/src/main/java/org/jlab/io/stream/EvioOutputStream.java b/common-tools/clas-io/src/main/java/org/jlab/io/stream/EvioOutputStream.java index df6b3a4720..c06c1c7395 100644 --- a/common-tools/clas-io/src/main/java/org/jlab/io/stream/EvioOutputStream.java +++ b/common-tools/clas-io/src/main/java/org/jlab/io/stream/EvioOutputStream.java @@ -1,9 +1,3 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ - package org.jlab.io.stream; import java.io.File; diff --git a/common-tools/clas-io/src/main/java/org/jlab/io/stream/EvioStreamObject.java b/common-tools/clas-io/src/main/java/org/jlab/io/stream/EvioStreamObject.java index 6261b203dd..94ea45803f 100644 --- a/common-tools/clas-io/src/main/java/org/jlab/io/stream/EvioStreamObject.java +++ b/common-tools/clas-io/src/main/java/org/jlab/io/stream/EvioStreamObject.java @@ -1,9 +1,3 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ - package org.jlab.io.stream; import java.util.TreeMap; diff --git a/common-tools/clas-io/src/main/java/org/jlab/io/task/DataSourceProcessorPane.java b/common-tools/clas-io/src/main/java/org/jlab/io/task/DataSourceProcessorPane.java index 72e009032a..569d720f47 100644 --- a/common-tools/clas-io/src/main/java/org/jlab/io/task/DataSourceProcessorPane.java +++ b/common-tools/clas-io/src/main/java/org/jlab/io/task/DataSourceProcessorPane.java @@ -20,7 +20,6 @@ import org.jlab.io.base.DataSource; import org.jlab.io.evio.EvioETSource; import org.jlab.io.evio.EvioSource; -import org.jlab.io.hipo3.Hipo3DataSource; import org.jlab.io.hipo.HipoDataSource; import org.jlab.io.hipo.HipoRingSource; import org.jlab.io.ui.ConnectionDialog; @@ -37,7 +36,6 @@ public class DataSourceProcessorPane extends JPanel implements ActionListener { private DataSourceProcessor dataProcessor = new DataSourceProcessor(); private String dataFile = null; - private int dataPaneStyle = DataSourceProcessorPane.TOOLBAR; private JLabel statusLabel = null; private java.util.Timer processTimer = null; private JButton mediaPause = null; @@ -47,7 +45,6 @@ public class DataSourceProcessorPane extends JPanel implements ActionListener { private JButton mediaEject = null; private JButton sourceFile = null; private int eventDelay = 0; - public boolean isHipo3Event = false; private String defaultHost = null; private String defaultIp = null; @@ -302,32 +299,9 @@ public void actionPerformed(ActionEvent e) { mediaPlay.setEnabled(true); this.setDataFile(null); } - - if(e.getActionCommand().compareTo("OpenFileHipo3")==0){ - this.stopProcessorTimer(); - isHipo3Event = true; - JFileChooser fc = new JFileChooser(); - fc.setCurrentDirectory(null); - int returnVal = fc.showOpenDialog(this); - if (returnVal == JFileChooser.APPROVE_OPTION) { - String fileName = fc.getSelectedFile().getAbsolutePath(); - System.out.println("file -> " + fileName); - Hipo3DataSource source = new Hipo3DataSource(); - source.open(fileName); - //This is where a real application would open the file. - this.dataProcessor.setSource(source); - statusLabel.setText(dataProcessor.getStatusString()); - mediaNext.setEnabled(true); - mediaPrev.setEnabled(true); - mediaPlay.setEnabled(true); - this.setDataFile(fileName); - } - } - if(e.getActionCommand().compareTo("OpenFileHipo4")==0){ this.stopProcessorTimer(); - isHipo3Event = false; JFileChooser fc = new JFileChooser(); fc.setCurrentDirectory(null); int returnVal = fc.showOpenDialog(this); @@ -389,6 +363,7 @@ public static void main(String[] args){ pane.addEventListener(new IDataEventListener(){ int ncount = 0; + @Override public void dataEventAction(DataEvent event) { ncount++; if(event.getType() == DataEventType.EVENT_START){ @@ -400,10 +375,12 @@ public void dataEventAction(DataEvent event) { } } + @Override public void timerUpdate() { System.out.println("update is called"); } + @Override public void resetEventListener() { System.out.println("reset is called"); ncount = 0; diff --git a/common-tools/clas-io/src/main/java/org/jlab/io/task/IDataEventListener.java b/common-tools/clas-io/src/main/java/org/jlab/io/task/IDataEventListener.java index 8d9f62159c..c08b083132 100644 --- a/common-tools/clas-io/src/main/java/org/jlab/io/task/IDataEventListener.java +++ b/common-tools/clas-io/src/main/java/org/jlab/io/task/IDataEventListener.java @@ -1,9 +1,3 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ - package org.jlab.io.task; import org.jlab.io.base.DataEvent; diff --git a/common-tools/clas-io/src/main/java/org/jlab/io/ui/BankEntryMasks.java b/common-tools/clas-io/src/main/java/org/jlab/io/ui/BankEntryMasks.java deleted file mode 100644 index 53dcc328e7..0000000000 --- a/common-tools/clas-io/src/main/java/org/jlab/io/ui/BankEntryMasks.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ -package org.jlab.io.ui; - -import java.util.HashMap; -import java.util.Map; - -/** - * - * @author gavalian - */ -public class BankEntryMasks { - - Map bankMasks = new HashMap(); - - public BankEntryMasks(){ - - } - - public String getMask(String bankName){ - return bankMasks.get(bankName); - } - - - public void setMask(String bankName, String mask){ - bankMasks.put(bankName, mask); - } - -} diff --git a/common-tools/clas-io/src/main/java/org/jlab/io/ui/BasicDialog.java b/common-tools/clas-io/src/main/java/org/jlab/io/ui/BasicDialog.java index 2f509f1b0d..83ef1d1e1e 100644 --- a/common-tools/clas-io/src/main/java/org/jlab/io/ui/BasicDialog.java +++ b/common-tools/clas-io/src/main/java/org/jlab/io/ui/BasicDialog.java @@ -1,11 +1,5 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ package org.jlab.io.ui; - import java.awt.BorderLayout; import java.awt.Component; import java.awt.Container; diff --git a/common-tools/clas-io/src/main/java/org/jlab/io/ui/ConnectionDialog.java b/common-tools/clas-io/src/main/java/org/jlab/io/ui/ConnectionDialog.java index d1c3c08677..fed12d0953 100644 --- a/common-tools/clas-io/src/main/java/org/jlab/io/ui/ConnectionDialog.java +++ b/common-tools/clas-io/src/main/java/org/jlab/io/ui/ConnectionDialog.java @@ -1,8 +1,3 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ package org.jlab.io.ui; import java.awt.Component; @@ -35,8 +30,6 @@ public class ConnectionDialog extends BasicDialog { public static final int RING_TYPE_ET = 5; public static final int RING_TYPE_HIPO = 6; - private int connectionType = ConnectionDialog.RING_TYPE_ET; - private JRadioButton _directConnect; private JRadioButton _connectToDAQ; @@ -45,7 +38,7 @@ public class ConnectionDialog extends BasicDialog { private static String defaultHost = "clondaq7"; private static String defaultIP = "129.57.167.20"; - Map connectionHosts = new LinkedHashMap(); + Map connectionHosts = new LinkedHashMap<>(); private static String[] closeoutButtons = {"Connect", "Cancel"}; @@ -55,7 +48,6 @@ public class ConnectionDialog extends BasicDialog { private JComboBox _comboHosts; private JComboBox _comboEtFiles; - private JComboBox _files; private int _reason = DialogUtilities.CANCEL_RESPONSE; @@ -64,7 +56,6 @@ public class ConnectionDialog extends BasicDialog { */ public ConnectionDialog() { super("Connection.....", true, closeoutButtons); - int nhosts = hostNames.length; for(int i = 0; i < hostNames.length; i++){ this.connectionHosts.put(hostNames[i],hostIP[i]); } @@ -72,7 +63,6 @@ public ConnectionDialog() { public ConnectionDialog(int type) { super("Connection.....", true, closeoutButtons); - int nhosts = hostNames.length; for(int i = 0; i < hostNames.length; i++){ this.connectionHosts.put(hostNames[i],hostIP[i]); } @@ -80,7 +70,6 @@ public ConnectionDialog(int type) { public ConnectionDialog(String defaultHost, String defaultIP) { super("Connection.....", true, closeoutButtons); - int nhosts = hostNames.length; for(int i = 0; i < hostNames.length; i++){ this.connectionHosts.put(hostNames[i],hostIP[i]); } @@ -105,13 +94,13 @@ protected Component createCenterComponent() { BoxLayout.Y_AXIS)); _ipField = new JTextField(25); - _ipField.setText(this.defaultIP); + _ipField.setText(ConnectionDialog.defaultIP); JPanel subpanel = new JPanel(); subpanel.setLayout(new FlowLayout(FlowLayout.LEFT, 6, 2)); JLabel labelip = new JLabel(" Address: "); - _comboHosts = new JComboBox(this.hostNames); + _comboHosts = new JComboBox(ConnectionDialog.hostNames); ItemListener itemListener = new ItemListener() { @Override @@ -122,7 +111,7 @@ public void itemStateChanged(ItemEvent e) { } } }; - _comboHosts.setSelectedItem(this.defaultHost); + _comboHosts.setSelectedItem(ConnectionDialog.defaultHost); _comboHosts.addItemListener(itemListener); subpanel.add(labelip); @@ -140,11 +129,8 @@ public void itemStateChanged(ItemEvent e) { _fileName.setText("/et/clasprod"); subpanel2.add(label); subpanel2.add(_fileName); - //List etFiles = FileUtils.filesInFolder(null, reason); try { List etFiles = FileUtils.dirListStartsWith("/et", ""); - //List etFiles = FileUtils.dirListStartsWith("/tmp", "et_sys"); - //List etFiles = FileUtils.dirListStartsWith("/Users/gavalian/Work", "d"); for(String f : etFiles){ System.out.println(" -----> " + f); } @@ -208,8 +194,8 @@ public Integer getPort(){ String port_number = _portNumber.getText(); Integer port = 11111; try { - port = Integer.parseInt(port_number); - } catch (Exception e) { + port = Integer.valueOf(port_number); + } catch (NumberFormatException e) { System.out.println("ERROR : the string provided is not a number : " + port_number); } return port; diff --git a/common-tools/clas-io/src/main/java/org/jlab/io/ui/ConnectionDialogHipo.java b/common-tools/clas-io/src/main/java/org/jlab/io/ui/ConnectionDialogHipo.java index 353cf8dd95..91795ef7ed 100644 --- a/common-tools/clas-io/src/main/java/org/jlab/io/ui/ConnectionDialogHipo.java +++ b/common-tools/clas-io/src/main/java/org/jlab/io/ui/ConnectionDialogHipo.java @@ -7,7 +7,6 @@ import javax.swing.Box; import javax.swing.BoxLayout; import javax.swing.ButtonGroup; -import javax.swing.JComboBox; import javax.swing.JPanel; import javax.swing.JRadioButton; import javax.swing.JTextField; @@ -25,23 +24,18 @@ public class ConnectionDialogHipo extends BasicDialog { public static final int RING_TYPE_ET = 5; public static final int RING_TYPE_HIPO = 6; - private int connectionType = ConnectionDialog.RING_TYPE_ET; - private JRadioButton _directConnect; private JRadioButton _connectToDAQ; private static String[] hostNames = new String[]{"clondaq2","clondaq3","clondaq4","clondaq5","clondaq6","clondaq7"}; private static String[] hostIP = new String[]{"129.57.167.109","129.57.167.226","129.57.167.227","129.57.167.41","129.57.167.60","129.57.167.20"}; - Map connectionHosts = new LinkedHashMap(); + Map connectionHosts = new LinkedHashMap<>(); private static String[] closeoutButtons = {"Connect", "Cancel"}; private JTextField _ipField; private JTextField _fileName; - private JComboBox _comboHosts; - private JComboBox _comboEtFiles; - private JComboBox _files; private int _reason = DialogUtilities.CANCEL_RESPONSE; @@ -50,7 +44,6 @@ public class ConnectionDialogHipo extends BasicDialog { */ public ConnectionDialogHipo() { super("Connection.....", true, closeoutButtons); - int nhosts = hostNames.length; for(int i = 0; i < hostNames.length; i++){ this.connectionHosts.put(hostNames[i],hostIP[i]); } @@ -77,9 +70,7 @@ protected Component createCenterComponent() { panel.add(Box.createVerticalStrut(6)); panel.add(_connectToDAQ); - Border emptyBorder = BorderFactory - .createEtchedBorder();//4, 4, 4, 4); - + Border emptyBorder = BorderFactory.createEtchedBorder(); panel.setBorder(BorderFactory.createTitledBorder(emptyBorder, "Connect to Host")); return panel; } diff --git a/common-tools/clas-io/src/main/java/org/jlab/io/ui/DataBankPanel.java b/common-tools/clas-io/src/main/java/org/jlab/io/ui/DataBankPanel.java deleted file mode 100644 index 2f6671555e..0000000000 --- a/common-tools/clas-io/src/main/java/org/jlab/io/ui/DataBankPanel.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ -package org.jlab.io.ui; - -import java.awt.BorderLayout; -import java.awt.Dimension; -import javax.swing.JFrame; -import javax.swing.JPanel; -import javax.swing.JScrollPane; -import javax.swing.JTable; -import org.jlab.io.base.DataBank; - -/** - * - * @author gavalian - */ -public class DataBankPanel extends JPanel { - - private JScrollPane scrollPane = null; - private JTable table = null; - - public DataBankPanel(){ - super(); - this.setPreferredSize(new Dimension(600,400)); - this.initComponents(); - } - - public DataBankPanel(DataBank bank){ - super(); - this.setPreferredSize(new Dimension(600,400)); - this.initComponents(); - this.setBank(bank); - } - - public DataBankPanel(DataBank bank, BankEntryMasks masks){ - super(); - this.setPreferredSize(new Dimension(600,400)); - this.initComponents(); - this.setBank(bank,masks); - } - - private void initComponents(){ - this.setLayout(new BorderLayout()); - - String[] cnames = {"id","p"}; - String[][] cdata = {{"11","0.45"},{"2212","0.65"}}; - this.table = new JTable(cdata,cnames); - - //scrollPane.add(table); - scrollPane = new JScrollPane(table); - //scrollPane.setAutoscrolls(true); - //this.table.setFillsViewportHeight(true); - this.add(scrollPane,BorderLayout.CENTER); - } - - public void setBank(DataBank bank){ - this.table.setModel(bank.getTableModel("")); - } - - public void setBank(DataBank bank, BankEntryMasks masks){ - if(masks.getMask(bank.getDescriptor().getName())==null){ - this.table.setModel(bank.getTableModel("")); - } else { - this.table.setModel(bank.getTableModel(masks.getMask(bank.getDescriptor().getName()))); - } - } - - public static void main(String[] args){ - JFrame frame = new JFrame(); - DataBankPanel panel = new DataBankPanel(); - frame.add(panel); - frame.pack(); - frame.setVisible(true); - } -} diff --git a/common-tools/clas-io/src/main/java/org/jlab/io/ui/DialogUtilities.java b/common-tools/clas-io/src/main/java/org/jlab/io/ui/DialogUtilities.java index a363a744dc..5b7df28c4f 100644 --- a/common-tools/clas-io/src/main/java/org/jlab/io/ui/DialogUtilities.java +++ b/common-tools/clas-io/src/main/java/org/jlab/io/ui/DialogUtilities.java @@ -118,9 +118,9 @@ public String padString(Component c, String inp, String tstr) { int newgap; if (inp == null) { - str = new String(""); + str = ""; } else { - str = new String(inp); + str = inp; } FontMetrics fm = c.getFontMetrics(c.getFont()); diff --git a/common-tools/clas-io/src/main/java/org/jlab/io/utils/CompositeFormatReader.java b/common-tools/clas-io/src/main/java/org/jlab/io/utils/CompositeFormatReader.java index 2b125a9b21..620119ccd0 100644 --- a/common-tools/clas-io/src/main/java/org/jlab/io/utils/CompositeFormatReader.java +++ b/common-tools/clas-io/src/main/java/org/jlab/io/utils/CompositeFormatReader.java @@ -1,9 +1,3 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ - package org.jlab.io.utils; import java.io.IOException; @@ -31,7 +25,6 @@ public class CompositeFormatReader { public static void main4(String[] args){ EvioSource reader = new EvioSource(); reader.open("/Users/gavalian/Work/DataSpace/LTCC/ltcc0test_000195.evio"); - //while(reader.hasEvent()){ for(int loop = 0; loop < 10; loop++){ EvioDataEvent event = (EvioDataEvent) reader.getNextEvent(); EvioNode rawnode = event.getNodeFromTree(57601, 43, DataType.COMPOSITE); @@ -55,7 +48,6 @@ public static void main4(String[] args){ } } - public static void main2(){ try { @@ -77,17 +69,16 @@ public static void main2(){ Logger.getLogger(CompositeFormatReader.class.getName()).log(Level.SEVERE, null, ex); } } + public static void main(String[] args){ CompositeFormatReader.main4(args); } + public static void main3(String[] args){ try { EvioCompactReader reader = new EvioCompactReader("/Users/gavalian/Work/DataSpace/LTCC/ltcc0test_000195.evio"); for(int loop = 0; loop < 10; loop++){ - //EvioNode node = reader.getEvent(loop); - //List nodes = reader.searchEvent(loop+1, 57601, 7); - //System.err.println("event " + loop + " " + nodes.size()); ByteBuffer buffer = reader.getEventBuffer(loop+1); System.err.println("event " + loop + " " + buffer.limit() + " " + buffer.order()); EvioCompactStructureHandler structure = new EvioCompactStructureHandler(buffer,DataType.BANK); @@ -123,11 +114,6 @@ public static void main3(String[] args){ ); CompositeData cdata = new CompositeData(bdata,ByteOrder.LITTLE_ENDIAN); - List itemTypes = cdata.getTypes(); - //String format = cdata. - //for(DataType type : itemTypes){ - // System.err.println(" Data type = " + type); - //} } } } @@ -142,35 +128,4 @@ public static void main3(String[] args){ Logger.getLogger(CompositeFormatReader.class.getName()).log(Level.SEVERE, null, ex); } } - /* - public static void main(String[] args) { - EvioSource reader = new EvioSource(); - reader.open("/Users/gavalian/Work/DataSpace/LTCC/ltcc0test_000168.evio"); - for(int loop = 0; loop < 10; loop++){ - EvioDataEvent event = (EvioDataEvent) reader.getNextEvent(); - System.err.println("Event " + loop + " Has bank = " + event.hasBank(57601, 7)); - EvioCompactStructureHandler structure = event.getStructureHandler(); - try { - List nodes = structure.getNodes(); - /* - if(event.hasBank(57601, 7)==true){ - - EvioNode node = event.getNodeFromTree(57601, 7, DataType.COMPOSITE); - - if(node!=null){ - System.err.println("FOUND THE NODE"); - //ByteBuffer buffer = node.getStructureBuffer(false); - - try { - CompositeData cdata = new CompositeData(buffer.array(),ByteOrder.LITTLE_ENDIAN); - } catch (EvioException ex) { - Logger.getLogger(CompositeFormatReader.class.getName()).log(Level.SEVERE, null, ex); - } - } - } - } catch (EvioException ex) { - Logger.getLogger(CompositeFormatReader.class.getName()).log(Level.SEVERE, null, ex); - } - } - }*/ } diff --git a/common-tools/clas-io/src/main/java/org/jlab/io/utils/DataSourceDump.java b/common-tools/clas-io/src/main/java/org/jlab/io/utils/DataSourceDump.java deleted file mode 100644 index 2cb1273be4..0000000000 --- a/common-tools/clas-io/src/main/java/org/jlab/io/utils/DataSourceDump.java +++ /dev/null @@ -1,113 +0,0 @@ -package org.jlab.io.utils; - -import java.io.Console; -import org.jlab.io.base.DataBank; -import org.jlab.io.base.DataEvent; -import org.jlab.io.base.DataSource; -import org.jlab.io.evio.EvioSource; -import org.jlab.io.hipo.HipoDataEvent; -import org.jlab.io.hipo.HipoDataSource; -import org.jlab.logging.DefaultLogger; - -/** - * - * @author gavalian - */ -public class DataSourceDump { - - public static String waitForEnter() { - String line = ""; - Console c = System.console(); - if (c != null) { - // printf-like arguments - //c.format(message, args); - c.format("\nChoose (n=next,p=previous, q=quit), Type Bank Name or id : "); - line = c.readLine(); - } - return line; - } - public static void main(String[] args){ - - DefaultLogger.debug(); - - if(args.length==0){ - System.out.println("\n\n\t Usage : eviodump [filename]"); - System.exit(0); - } - - String inputFile = args[0]; - - DataSource reader = null; - - if(inputFile.contains("hipo")==true){ - reader = new HipoDataSource(); - } else { - reader = new EvioSource(); - } - - reader.open(inputFile); - - String command = ""; - DataEvent event = null; - int icounter = 0; - - event = reader.getNextEvent(); - System.out.println(" HAS EVENTS = " + reader.hasEvent()); - while(reader.hasEvent()==true){ - - - if(command.length()<1){ - System.out.println("\n"); - System.out.println("*********************** EVENT # " + icounter - + " ***********************"); - event.show(); - } - - command = DataSourceDump.waitForEnter(); - - if(command.compareTo("n")==0){ - event = reader.getNextEvent(); - icounter++; - command = ""; - continue; - } - - if(command.compareTo("p")==0){ - if(icounter>0){ - event = reader.getPreviousEvent(); - icounter--; - } - command = ""; - continue; - } - - if(command.length()>=1){ - int order = -1; - if(command.matches("-?\\d+(\\.\\d+)?")){ - try { - order = Integer.parseInt(command); - if(event instanceof HipoDataEvent){ - HipoDataEvent he = (HipoDataEvent) event; - he.showBankByOrder(order); - continue; - } - } catch(Exception e) { - System.out.println(" [warning] --> unrecognized input [" + command + "]"); - } - } else { - if(event.hasBank(command)==true){ - DataBank bank = event.getBank(command); - bank.show(); - } else { - System.out.println("[DataDump] warning ---> bank not found : " + command); - } - } - } - if(command.compareTo("q")==0){ - reader.close(); - System.exit(0); - } - } - } - -} diff --git a/common-tools/clas-io/src/main/java/org/jlab/io/utils/DetectorBank.java b/common-tools/clas-io/src/main/java/org/jlab/io/utils/DetectorBank.java deleted file mode 100644 index 74f5fbbec8..0000000000 --- a/common-tools/clas-io/src/main/java/org/jlab/io/utils/DetectorBank.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ -package org.jlab.io.utils; - -/** - * - * @author gavalian - */ -public class DetectorBank { - public float X = 0; - public float Y = 0; - public float Z = 0; - public float dX = 0; - public float dY = 0; - public float dZ = 0; - public float time = (float) 0.0; - public float energy = (float) 0.0; - public float path = (float) 0.0; - public short pindex = (short) 0; - public byte dindex = (byte) 0; - public byte detector = (byte) 1; - public byte sector = (byte) 1; - public byte superlayer = (byte) 1; - public short component = (short) 1; -} diff --git a/common-tools/clas-io/src/main/java/org/jlab/io/utils/DictionaryLoader.java b/common-tools/clas-io/src/main/java/org/jlab/io/utils/DictionaryLoader.java index e9153cea9d..83efa60988 100644 --- a/common-tools/clas-io/src/main/java/org/jlab/io/utils/DictionaryLoader.java +++ b/common-tools/clas-io/src/main/java/org/jlab/io/utils/DictionaryLoader.java @@ -1,9 +1,3 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ - package org.jlab.io.utils; import java.io.IOException; @@ -29,7 +23,7 @@ public class DictionaryLoader { public static ArrayList getDescriptorsFromFile(String xmlfile){ - ArrayList list = new ArrayList(); + ArrayList list = new ArrayList<>(); try { DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); @@ -46,10 +40,7 @@ public static ArrayList getDescriptorsFromFile(String xmlfil for(EvioDataDescriptor item : descList){ list.add(item); } - //String oneBank = DictionaryLoader.parseBankXMLtoString(evio_bank); - //dictionary_list.add(oneBank); } - } return list; } catch (ParserConfigurationException ex) { @@ -59,14 +50,12 @@ public static ArrayList getDescriptorsFromFile(String xmlfil } catch (IOException ex) { Logger.getLogger(DictionaryLoader.class.getName()).log(Level.SEVERE, null, ex); } - return null; } - public static ArrayList descriptorParseXMLtoString(String xmlfile) { - ArrayList dictionary_list = new ArrayList(); + ArrayList dictionary_list = new ArrayList<>(); try { DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder = dbFactory.newDocumentBuilder(); @@ -77,12 +66,10 @@ public static ArrayList descriptorParseXMLtoString(String xmlfile) { Element evio_nodes = (Element) evio_dict_nodelist.item(b); NodeList evio_bank_nodes = evio_nodes.getElementsByTagName("bank"); for (int s = 0; s < evio_bank_nodes.getLength(); s++) { - Element evio_bank = (Element) evio_bank_nodes.item(s); String oneBank = DictionaryLoader.parseBankXMLtoString(evio_bank); dictionary_list.add(oneBank); } - } } catch (ParserConfigurationException ex) { Logger.getLogger(DictionaryLoader.class.getName()).log(Level.SEVERE, null, ex); @@ -91,9 +78,9 @@ public static ArrayList descriptorParseXMLtoString(String xmlfile) { } catch (IOException ex) { Logger.getLogger(DictionaryLoader.class.getName()).log(Level.SEVERE, null, ex); } - return dictionary_list; } + /** * Parse an XML string into a descriptors. * @param xmlstring @@ -115,13 +102,14 @@ public static ArrayList parseXMLString(String xmlstring){ } return null; } + /** * * @param doc * @return */ public static ArrayList parseDocumentXMLtoString(Document doc){ - ArrayList dictionary_list = new ArrayList(); + ArrayList dictionary_list = new ArrayList<>(); NodeList evio_bank_nodes = doc.getElementsByTagName("bank"); for (int s = 0; s < evio_bank_nodes.getLength(); s++) { Element evio_bank = (Element) evio_bank_nodes.item(s); @@ -157,19 +145,14 @@ public static String parseBankXMLtoString(Element bankElement){ str.append(entry_num); str.append(":"); str.append(entry_type); - - //System.err.println("Entry = " + entry_name + " " - // + section_tag + " " + entry_num - // + " " + entry_type); } } System.err.println("--> " + str.toString()); - //dictionary_list.add(str.toString()); return str.toString(); } public static ArrayList parseBankXMLtoDescriptorList(Element bankElement){ - ArrayList list = new ArrayList(); + ArrayList list = new ArrayList<>(); String bank_name = bankElement.getAttribute("name"); String bank_tag = bankElement.getAttribute("tag"); @@ -178,8 +161,7 @@ public static ArrayList parseBankXMLtoDescriptorList(Element for(int e = 0 ; e < evio_section.getLength(); e++){ StringBuilder str = new StringBuilder(); Element evio_entry = (Element) evio_section.item(e); - - Integer section_tag = Integer.parseInt(evio_entry.getAttribute("tag")); + Integer section_tag = Integer.valueOf(evio_entry.getAttribute("tag")); String section_name = evio_entry.getAttribute("name"); str.append(bank_name); str.append("::"); @@ -193,16 +175,10 @@ public static ArrayList parseBankXMLtoDescriptorList(Element String entry_num = evio_col.getAttribute("num"); String entry_type = evio_col.getAttribute("type"); desc.addEntry(section_name, entry_name, section_tag, - Integer.parseInt(entry_num), entry_type); - //System.err.println("Entry = " + str.toString() + " " + entry_name + " " - // + section_tag + " " + entry_num - // + " " + entry_type); + Integer.valueOf(entry_num), entry_type); } list.add(desc); } - //System.err.println("--> " + str.toString()); - //dictionary_list.add(str.toString()); - //return str.toString(); return list; } } diff --git a/common-tools/clas-io/src/main/java/org/jlab/io/utils/Evio2HipoConverter.java b/common-tools/clas-io/src/main/java/org/jlab/io/utils/Evio2HipoConverter.java deleted file mode 100644 index 34d6d220c7..0000000000 --- a/common-tools/clas-io/src/main/java/org/jlab/io/utils/Evio2HipoConverter.java +++ /dev/null @@ -1,267 +0,0 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ -package org.jlab.io.utils; - -import java.io.File; -import java.util.ArrayList; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; -import org.jlab.io.base.DataBank; -import org.jlab.io.base.DataEvent; -import org.jlab.io.evio.EvioDataBank; -import org.jlab.io.evio.EvioDataEvent; -import org.jlab.io.evio.EvioDataSync; -import org.jlab.io.evio.EvioFactory; -import org.jlab.io.evio.EvioSource; -import org.jlab.io.hipo.HipoDataSync; - -/** - * - * @author gavalian - */ -public class Evio2HipoConverter { - - public int COMPRESSION_TYPE = 0; - private Map excludedBanks = new LinkedHashMap(); - - public Evio2HipoConverter(){ - this.exclude("DC::true"); - this.exclude("FTOF1A::true"); - this.exclude("FTOF1B::true"); - this.exclude("FTOF2B::true"); - this.exclude("PCAL::true"); - this.exclude("EC::true"); - this.exclude("HTCC::true"); - this.exclude("BST::true"); - } - - public final void exclude(String name){ - this.excludedBanks.put(name, 1); - } - /** - * returns list of banks from the dictionary that match the name. - * @param name - * @return - */ - public List getBanksWithName(String name){ - String[] system = EvioFactory.getDictionary().getDescriptorList(); - - List bankNames = new ArrayList(); - for(String item : system){ - if(item.startsWith(name)==true){ - bankNames.add(item); - } - } - return bankNames; - } - /** - * Returns bank names that match the name, and exist in the event - * @param event - * @param name - * @return - */ - public List getExistingBanksWithName(DataEvent event, String name){ - List banks = this.getBanksWithName(name); - List banksExist = new ArrayList(); - - for(String item : banks){ - if(event.hasBank(item)==true){ - if(this.excludedBanks.containsKey(item)==false){ - banksExist.add(item); - } - } - } - return banksExist; - } - - public Map getExcluded(){ - return this.excludedBanks; - } - - public DataBank[] getDataBanksWithName(DataEvent event, String name){ - List banksExist = this.getExistingBanksWithName(event, name); - DataBank[] banks = new DataBank[banksExist.size()]; - int icounter = 0; - for(int i = 0; i < banksExist.size(); i++){ - banks[i] = event.getBank(banksExist.get(i)); - } - return banks; - } - - public void convertEvio(String output, List input, List banks){ - EvioDataSync writer = new EvioDataSync(); - writer.open(output); - //writer.setCompressionType(this.COMPRESSION_TYPE); - - for(int icount = 0; icount < input.size(); icount++){ - EvioSource reader = new EvioSource(); - reader.open(input.get(icount)); - System.out.println("[convertor] ---> openning file # " + icount - + " : " + input.get(icount)); - while(reader.hasEvent()==true){ - DataEvent inEevent = reader.getNextEvent(); - DataEvent outEvent = EvioFactory.createEvioEvent(); - for(String entries : banks){ - DataBank[] dataBanks = this.getDataBanksWithName(inEevent, entries); - if(dataBanks.length!=0){ - outEvent.appendBanks(dataBanks); - } - } - writer.writeEvent(outEvent); - } - } - } - - public void convertHipo(String output, List input, List banks){ - if(this.COMPRESSION_TYPE>2){ - this.convertEvio(output, input, banks); - } - HipoDataSync writer = new HipoDataSync(); - writer.open(output); - writer.setCompressionType(this.COMPRESSION_TYPE); - - for(int icount = 0; icount < input.size(); icount++){ - EvioSource reader = new EvioSource(); - reader.open(input.get(icount)); - System.out.println("[convertor] ---> openning file # " + icount - + " : " + input.get(icount)); - int counter = 0; - while(reader.hasEvent()==true){ - DataEvent inEvent = reader.getNextEvent(); - DataEvent outEvent = EvioFactory.createEvioEvent(); - counter++; - if(banks.isEmpty()){ - writer.writeEvent(inEvent); - } else { - - for(String entries : banks){ - DataBank[] dataBanks = this.getDataBanksWithName(inEvent, entries); - if(dataBanks.length!=0){ - outEvent.appendBanks(dataBanks); - } - } - - if(inEvent.hasBank("GenPart::true")==true){ - EvioDataBank bankGen = (EvioDataBank) inEvent.getBank("GenPart::true"); - //System.out.println("writing generated event " + counter); - //bankGen.show(); - ((EvioDataEvent) outEvent).appendGeneratedBank(bankGen); - //outEvent.appendBank(bankGen); - } - writer.writeEvent(outEvent); - } - } - } - writer.close(); - } - - public static void printUsage(){ - System.out.println("\tUsage: convert -[compression] -b [bank1:bank2] output.hipo input.evio [input2.evio] [input3.evio]"); - System.out.println("\n\t Options :"); - System.out.println("\t\t -u : uncompressed"); - System.out.println("\t\t -gzip : gzip compression"); - System.out.println("\t\t -lz4 : lz4 compression"); - System.out.println("\n"); - } - - public static void main(String[] args){ - - - if(args.length>0){ - if(args[0].compareTo("-list")==0){ - EvioFactory.getDictionary().show(); - } - } - /* - if(args.length<5){ - HipoDataSync.printUsage(); - System.exit(0); - }*/ - - if(args[0].startsWith("-")==false){ - System.out.println("\n\n--> please provide compression type"); - HipoDataSync.printUsage(); - System.exit(0); - } - - int compressionType = -1; - - if(args[0].compareTo("-u")==0){ - compressionType = 0; - } - - if(args[0].compareTo("-gzip")==0){ - compressionType = 1; - } - - if(args[0].compareTo("-lz4")==0){ - compressionType = 2; - } - - if(args[0].compareTo("-evio")==0){ - compressionType = 3; - } - - if(compressionType<0){ - HipoDataSync.printUsage(); - System.out.println("[error] ---> compression type string is invalid."); - System.exit(0); - } - - if(args[1].startsWith("-b")==false){ - System.out.println("\n\n--> please provide bank names in the output"); - HipoDataSync.printUsage(); - System.exit(0); - } - - String bankNames = args[2]; - List bankList = new ArrayList(); - - boolean writeTrueBanks = false; - - if(bankNames.compareTo("ALLTRUE")==0){ - System.out.println("[convertor] ---> outputing ALL banks with TRUE"); - writeTrueBanks = true; - } else { - if(bankNames.compareTo("ALL")==0){ - System.out.println("[convertor] ---> outputing ALL banks"); - } else { - String[] tokens = bankNames.split(":"); - for(String token : tokens){ - bankList.add(token); - } - } - } - - String outputFile = args[3]; - - File outFile = new File(outputFile); - - if(outFile.exists()==true){ - System.out.println("\n[error] ---> can not overwrite existing file.\n\n"); - System.exit(0); - } - - List inputFiles = new ArrayList(); - - for(int i = 4; i < args.length; i++){ - inputFiles.add(args[i]); - } - - - Evio2HipoConverter converter = new Evio2HipoConverter(); - converter.COMPRESSION_TYPE = compressionType; - if(writeTrueBanks==true){ - converter.getExcluded().clear(); - } - - converter.convertHipo(outputFile, inputFiles, bankList); - //String bank = args[0]; - //converter.getBanksWithName(bank); - - } -} diff --git a/common-tools/clas-io/src/main/java/org/jlab/io/utils/EvioCure.java b/common-tools/clas-io/src/main/java/org/jlab/io/utils/EvioCure.java index ab89f8af8a..d62a828cb7 100644 --- a/common-tools/clas-io/src/main/java/org/jlab/io/utils/EvioCure.java +++ b/common-tools/clas-io/src/main/java/org/jlab/io/utils/EvioCure.java @@ -15,7 +15,7 @@ */ public class EvioCure { - private static Logger LOGGER = Logger.getLogger(EvioCure.class.getName()); + private static final Logger LOGGER = Logger.getLogger(EvioCure.class.getName()); public static void main(String[] args) { DefaultLogger.debug(); @@ -27,11 +27,9 @@ public static void main(String[] args) { EventWriter evioWriter = null; try { EvioReader reader = new EvioReader(inputFile, false, false); - LOGGER.log(Level.INFO, " READER OPENED " + reader.getEventCount()); - String dictionary = "\n"; - LOGGER.log(Level.INFO, " ENDIANNESS : " + reader.getByteOrder()); + LOGGER.log(Level.INFO, " READER OPENED {0}", reader.getEventCount()); + LOGGER.log(Level.INFO, " ENDIANNESS : {0}", reader.getByteOrder()); evioWriter = new EventWriter(outputFile, false, reader.getByteOrder()); - boolean isActive = true; reader.rewind(); for (int i = 1; i < reader.getEventCount(); i++) { ByteBuffer buffer = reader.getEventBuffer(i); @@ -39,7 +37,7 @@ public static void main(String[] args) { evioWriter.writeEvent(buffer); icounter++; } - LOGGER.log(Level.INFO, " RECOVERED EVENT " + icounter); + LOGGER.log(Level.INFO, " RECOVERED EVENT {0}", icounter); evioWriter.close(); } catch (EvioException ex) { LOGGER.log(Level.WARNING, " RECOVERED EVENT (EVIO exception) " + icounter, ex); diff --git a/common-tools/clas-io/src/main/java/org/jlab/io/utils/EvioDataConvertor.java b/common-tools/clas-io/src/main/java/org/jlab/io/utils/EvioDataConvertor.java deleted file mode 100644 index 8cde59c629..0000000000 --- a/common-tools/clas-io/src/main/java/org/jlab/io/utils/EvioDataConvertor.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ -package org.jlab.io.utils; - -/** - * - * @author gavalian - */ -public class EvioDataConvertor { - public static short getShortFromByte(byte data){ - short short_data = 0; - return (short) ((short_data|data)&0x00FF); - } - - public static int getIntFromShort(short data){ - int int_data = 0; - return (int) ( (int_data|data)&0x0000FFFF); - } - - public static void main(String[] args){ - byte data = -117; - System.err.println(String.format("byte = %d short = %d , B=%X S=%X", - data,EvioDataConvertor.getShortFromByte(data),data, - EvioDataConvertor.getShortFromByte(data))); - - short sdata = -25678; - System.err.println(String.format("short = %d int = %d , S=%X I=%X", - sdata,EvioDataConvertor.getIntFromShort(sdata),sdata, - EvioDataConvertor.getIntFromShort(sdata))); - } -} diff --git a/common-tools/clas-io/src/main/java/org/jlab/io/utils/EvioFileRecover.java b/common-tools/clas-io/src/main/java/org/jlab/io/utils/EvioFileRecover.java index 5db0354d86..01a0ccb55e 100644 --- a/common-tools/clas-io/src/main/java/org/jlab/io/utils/EvioFileRecover.java +++ b/common-tools/clas-io/src/main/java/org/jlab/io/utils/EvioFileRecover.java @@ -1,26 +1,15 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ package org.jlab.io.utils; import java.io.File; import java.io.IOException; -import java.nio.ByteBuffer; -import java.nio.ByteOrder; -import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; import org.jlab.coda.jevio.DataType; import org.jlab.coda.jevio.EventBuilder; import org.jlab.coda.jevio.EventWriter; -//import org.jlab.coda.jevio.EvioCompactEventWriter; import org.jlab.coda.jevio.EvioEvent; import org.jlab.coda.jevio.EvioException; -import org.jlab.coda.jevio.EvioNode; import org.jlab.coda.jevio.EvioReader; -import org.jlab.io.evio.EvioFactory; /** * @@ -36,11 +25,7 @@ public static void test(){ try { EventWriter writer = new EventWriter(outputfile); EventBuilder eventBuilder = new EventBuilder(1, DataType.BANK, 1); - //byte[] byteData1 = new byte[499990]; - EvioEvent ev = eventBuilder.getEvent(); - - //ev.appendByteData(byteData1); writer.writeEvent(ev); writer.close(); } catch (EvioException ex) { @@ -65,9 +50,8 @@ public static void recoverFile(String inputfile, String outputfile) { return; } - EvioReader reader = null; - - EventWriter writer = null; + EvioReader reader; + EventWriter writer; try { @@ -94,10 +78,6 @@ public static void recoverFile(String inputfile, String outputfile) { } public static void main(String[] args){ - /* - String inputfile = "/Users/gavalian/Work/Software/Release-8.0/COATJAVA/coatjava/../svt257er_000015.evio.0"; - String outputfile = "/Users/gavalian/Work/Software/Release-8.0/COATJAVA/coatjava/../svt257er_000015_recovered.evio"; - */ String inputfile = args[0]; String outputfile = args[1]; EvioFileRecover.recoverFile(inputfile, outputfile); diff --git a/common-tools/clas-io/src/main/java/org/jlab/io/utils/EvioFileUtils.java b/common-tools/clas-io/src/main/java/org/jlab/io/utils/EvioFileUtils.java deleted file mode 100644 index 6ef884e27c..0000000000 --- a/common-tools/clas-io/src/main/java/org/jlab/io/utils/EvioFileUtils.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ -package org.jlab.io.utils; - -import java.util.ArrayList; - -/** - * - * @author gavalian - */ -public class EvioFileUtils { - public EvioFileUtils(){ - - } - - public static void mergeFiles(String outputFile, ArrayList inputFiles){ - - } - - public static void splitFile(String inputFile, String outputTemplate, int nevents){ - - } -} diff --git a/common-tools/clas-io/src/main/java/org/jlab/io/utils/HipoFileUtils.java b/common-tools/clas-io/src/main/java/org/jlab/io/utils/HipoFileUtils.java deleted file mode 100644 index 7510ed4585..0000000000 --- a/common-tools/clas-io/src/main/java/org/jlab/io/utils/HipoFileUtils.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ -package org.jlab.io.utils; - -import org.jlab.io.hipo.HipoDataSource; - -/** - * - * @author gavalian - */ -public class HipoFileUtils { - - public static void hipoDump(String filename){ - HipoDataSource reader = new HipoDataSource(); - reader.open(filename); - - } - - public static void main(String[] args){ - String file = args[0]; - HipoFileUtils.hipoDump(file); - } -} diff --git a/common-tools/clas-io/src/main/java/org/jlab/utils/EtProducer.java b/common-tools/clas-io/src/main/java/org/jlab/utils/EtProducer.java index b17e700973..335b0c902a 100644 --- a/common-tools/clas-io/src/main/java/org/jlab/utils/EtProducer.java +++ b/common-tools/clas-io/src/main/java/org/jlab/utils/EtProducer.java @@ -1,8 +1,3 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ package org.jlab.utils; import java.io.IOException; diff --git a/common-tools/clas-io/src/main/java/org/jlab/utils/FileUtils.java b/common-tools/clas-io/src/main/java/org/jlab/utils/FileUtils.java index d1e865fada..fe76b951a0 100644 --- a/common-tools/clas-io/src/main/java/org/jlab/utils/FileUtils.java +++ b/common-tools/clas-io/src/main/java/org/jlab/utils/FileUtils.java @@ -8,7 +8,7 @@ public class FileUtils { public static ArrayList filesInFolder(File folder, String ext) { - ArrayList file_list = new ArrayList(); + ArrayList file_list = new ArrayList<>(); for (File f : folder.listFiles()) { if (f.isDirectory()) @@ -30,7 +30,7 @@ public static ArrayList filesInFolder(File folder, String ext) public static List dirListStartsWith(File folder, String starts) { - List file_list = new ArrayList(); + List file_list = new ArrayList<>(); for (File f : folder.listFiles()) { if (f.isDirectory()) @@ -50,13 +50,13 @@ public static List dirListStartsWith(File folder, String starts) public static List dirListStartsWith(String dir, String starts){ File f = new File(dir); - if(f==null) return new ArrayList(); + if(f==null) return new ArrayList<>(); return FileUtils.dirListStartsWith(f, starts); } public static ArrayList filesInFolder(File folder, String ext, ArrayList ignore_prefixes) { - ArrayList file_list = new ArrayList(); + ArrayList file_list = new ArrayList<>(); for (File f : folder.listFiles()) { if (f.isDirectory()) diff --git a/common-tools/clas-io/src/main/java/org/jlab/utils/TablePrintout.java b/common-tools/clas-io/src/main/java/org/jlab/utils/TablePrintout.java index 62b11d519e..20c1283b80 100644 --- a/common-tools/clas-io/src/main/java/org/jlab/utils/TablePrintout.java +++ b/common-tools/clas-io/src/main/java/org/jlab/utils/TablePrintout.java @@ -1,9 +1,3 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ - package org.jlab.utils; import java.util.ArrayList; @@ -14,9 +8,9 @@ */ public class TablePrintout { - private ArrayList headerDesc = new ArrayList(); - private ArrayList headerLength = new ArrayList(); - private ArrayList tableData = new ArrayList(); + private ArrayList headerDesc = new ArrayList<>(); + private ArrayList headerLength = new ArrayList<>(); + private ArrayList tableData = new ArrayList<>(); private Integer tableIndent = 8; @@ -45,7 +39,7 @@ public final void setHeader(String h, String l){ String[] tl = l.split(":"); for(int loop = 0; loop < th.length; loop++){ headerDesc.add(th[loop]); - headerLength.add(Integer.parseInt(tl[loop])); + headerLength.add(Integer.valueOf(tl[loop])); } } @@ -55,7 +49,7 @@ public static Integer[] positionIndex(String posString) Integer[] ticks = new Integer[tokens.length]; for(int loop = 0; loop < tokens.length; loop++) { - ticks[loop] = Integer.parseInt(tokens[loop]); + ticks[loop] = Integer.valueOf(tokens[loop]); } return ticks; } diff --git a/common-tools/clas-physics/pom.xml b/common-tools/clas-physics/pom.xml index 291d0a1930..d2c8a96a7f 100644 --- a/common-tools/clas-physics/pom.xml +++ b/common-tools/clas-physics/pom.xml @@ -14,10 +14,6 @@ - - org.jlab.jnp - jnp-hipo4 - junit junit diff --git a/common-tools/clas-physics/src/main/java/org/jlab/clas/pdg/PDGDatabase.java b/common-tools/clas-physics/src/main/java/org/jlab/clas/pdg/PDGDatabase.java index cb9d9c2149..e607cc34c0 100644 --- a/common-tools/clas-physics/src/main/java/org/jlab/clas/pdg/PDGDatabase.java +++ b/common-tools/clas-physics/src/main/java/org/jlab/clas/pdg/PDGDatabase.java @@ -10,59 +10,59 @@ */ public class PDGDatabase { - static final HashMap particleDatabase = initDatabase(); - - public PDGDatabase() { - } - - public static boolean isValidId(int pid) { - return particleDatabase.containsKey(pid); - // ArrayList ff = null; - } - - public static boolean isValidPid(int pid) { - return particleDatabase.containsKey(pid); - } - - static public PDGParticle getParticleById(int pid) { - if (particleDatabase.containsKey(pid) == true) { - return particleDatabase.get(pid); - } - System.err.println("PDGDatabase::Error -> there is no particle with pid " + pid); - return null; - } - - public static void addParticle(PDGParticle part) { - if (particleDatabase.containsKey(part.pid()) == true) { - System.out.println("PDGDatabase::Error -> Particle with PID " + part.pid() + " already exists in the database."); - return; - } - - particleDatabase.put(part.pid(), part); - } - - public static void addParticle(String name, int pid, double mass, int charge) { - if (particleDatabase.containsKey(pid) == true) { - System.out.println("PDGDatabase::Error -> Particle with PID " + pid + " already exists in the database."); - return; - } - particleDatabase.put(pid, new PDGParticle(name, pid, mass, charge)); - } - - private static HashMap initDatabase() { - HashMap particleMap = new HashMap(); - particleMap.put(11, new PDGParticle("e-", 11, 3, 0.0005, -1)); - particleMap.put(-11, new PDGParticle("e+", -11, 2, 0.0005, 1)); - particleMap.put(12, new PDGParticle("nue-", 12, 4, 0.320e-6, 0)); - particleMap.put(-12, new PDGParticle("nue+", -12, 4, 0.320e-6, 0)); - particleMap.put(13, new PDGParticle("mu-", 13, 6, 0.1056583715, -1)); - particleMap.put(-13, new PDGParticle("mu+", -13, 5, 0.1056583715, 1)); + static final HashMap particleDatabase = initDatabase(); + + public PDGDatabase() { + } + + public static boolean isValidId(int pid) { + return particleDatabase.containsKey(pid); + // ArrayList ff = null; + } + + public static boolean isValidPid(int pid) { + return particleDatabase.containsKey(pid); + } + + static public PDGParticle getParticleById(int pid) { + if (particleDatabase.containsKey(pid) == true) { + return particleDatabase.get(pid); + } + System.err.println("PDGDatabase::Error -> there is no particle with pid " + pid); + return null; + } + + public static void addParticle(PDGParticle part) { + if (particleDatabase.containsKey(part.pid()) == true) { + System.out.println("PDGDatabase::Error -> Particle with PID " + part.pid() + " already exists in the database."); + return; + } + + particleDatabase.put(part.pid(), part); + } + + public static void addParticle(String name, int pid, double mass, int charge) { + if (particleDatabase.containsKey(pid) == true) { + System.out.println("PDGDatabase::Error -> Particle with PID " + pid + " already exists in the database."); + return; + } + particleDatabase.put(pid, new PDGParticle(name, pid, mass, charge)); + } + + private static HashMap initDatabase() { + HashMap particleMap = new HashMap(); + particleMap.put(11, new PDGParticle("e-", 11, 3, 0.0005, -1)); + particleMap.put(-11, new PDGParticle("e+", -11, 2, 0.0005, 1)); + particleMap.put(12, new PDGParticle("nue-", 12, 4, 0.320e-6, 0)); + particleMap.put(-12, new PDGParticle("nue+", -12, 4, 0.320e-6, 0)); + particleMap.put(13, new PDGParticle("mu-", 13, 6, 0.1056583715, -1)); + particleMap.put(-13, new PDGParticle("mu+", -13, 5, 0.1056583715, 1)); particleMap.put(12, new PDGParticle("nue-", 14, 4, 0.320e-6, 0)); - particleMap.put(-12, new PDGParticle("nue+", -14, 4, 0.320e-6, 0)); - particleMap.put(22, new PDGParticle("gamma", 22, 1, 0.000, 0)); - particleMap.put(45, new PDGParticle("d", 45, 45,1.87705, 1)); // This is not a PDG code. + particleMap.put(-12, new PDGParticle("nue+", -14, 4, 0.320e-6, 0)); + particleMap.put(22, new PDGParticle("gamma", 22, 1, 0.000, 0)); + particleMap.put(45, new PDGParticle("d", 45, 45,1.87705, 1)); // This is not a PDG code. - //Light mesons + //Light mesons particleMap.put(211, new PDGParticle("pi+", 211, 8, 0.13957018, 1)); particleMap.put(-211, new PDGParticle("pi-", -211, 9, 0.13957018, -1)); particleMap.put(111, new PDGParticle("pi0", 111, 7, 0.134977, 0)); @@ -141,8 +141,8 @@ private static HashMap initDatabase() { // Light baryons - particleMap.put(2212, new PDGParticle("p", 2212, 14, 0.938272046, 1)); - particleMap.put(-2212, new PDGParticle("pbar", -2212, 15, 0.938272046, -1)); + particleMap.put(2212, new PDGParticle("p", 2212, 14, 0.938272046, 1)); + particleMap.put(-2212, new PDGParticle("pbar", -2212, 15, 0.938272046, -1)); particleMap.put(2112, new PDGParticle("n", 2112, 13, 0.939565379, 0)); particleMap.put(-2112, new PDGParticle("nbar", -2112, 25, 0.939565379, 0)); particleMap.put(2224, new PDGParticle("Delta++", 2224, 1.232, 2)); @@ -191,35 +191,33 @@ private static HashMap initDatabase() { //527 Li6 1000030060 1 100 Baryon 9 5.60305 0.00000e+00 -100 -1 -100 -1 -1 0 //528 Li7 1000030070 1 100 Baryon 9 6.53537 0.00000e+00 -100 -1 -100 -1 -1 0 - return particleMap; - } - - static public PDGParticle getParticleByName(String name) { - for (Map.Entry entry : particleDatabase.entrySet()) { - Integer key = entry.getKey(); - PDGParticle value = (PDGParticle) entry.getValue(); - if (value.name().compareTo(name) == 0) - return value; - // ... - } - return null; - // particleDatabase - } - - public static void show() { - for (Map.Entry items : particleDatabase.entrySet()) { - System.out.println(items.getValue().toString()); - } - } - - public static double getParticleMass(int pid) { - double mass =0.0; - if (particleDatabase.containsKey(pid) == true) { - mass = particleDatabase.get(pid).mass(); - } - else { - System.out.println("PDGDatabase::Error -> there is no particle with pid " + pid); - } - return mass; - } + return particleMap; + } + + static public PDGParticle getParticleByName(String name) { + for (Map.Entry entry : particleDatabase.entrySet()) { + Integer key = entry.getKey(); + PDGParticle value = (PDGParticle) entry.getValue(); + if (value.name().compareTo(name) == 0) + return value; + } + return null; + } + + public static void show() { + for (Map.Entry items : particleDatabase.entrySet()) { + System.out.println(items.getValue().toString()); + } + } + + public static double getParticleMass(int pid) { + double mass =0.0; + if (particleDatabase.containsKey(pid) == true) { + mass = particleDatabase.get(pid).mass(); + } + else { + System.out.println("PDGDatabase::Error -> there is no particle with pid " + pid); + } + return mass; + } } diff --git a/common-tools/clas-physics/src/main/java/org/jlab/physics/fw/IPhysicsCrossSection.java b/common-tools/clas-physics/src/main/java/org/jlab/physics/fw/IPhysicsCrossSection.java deleted file mode 100644 index 03ddd336d5..0000000000 --- a/common-tools/clas-physics/src/main/java/org/jlab/physics/fw/IPhysicsCrossSection.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ -package org.jlab.physics.fw; - -import java.util.List; -import java.util.Map; - -/** - * - * @author gavalian - */ -public interface IPhysicsCrossSection { - - double crossSection(Map values); - double getObservable(String name, Map values); - List getObservableList(); - List getObservables(Map values); - -} diff --git a/common-tools/clas-physics/src/main/java/org/jlab/physics/fw/IPhysicsObservable.java b/common-tools/clas-physics/src/main/java/org/jlab/physics/fw/IPhysicsObservable.java deleted file mode 100644 index 28893e651b..0000000000 --- a/common-tools/clas-physics/src/main/java/org/jlab/physics/fw/IPhysicsObservable.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ -package org.jlab.physics.fw; - -import java.util.Map; -import org.jlab.physics.base.ParameterSpace; -import org.jlab.physics.base.PhaseSpace; - -/** - * - * @author gavalian - */ -public interface IPhysicsObservable { - /* - Map getVariables(); - double getValue(); - String getName();*/ - double getValue(PhaseSpace space, ParameterSpace params); -} diff --git a/common-tools/clas-physics/src/main/java/org/jlab/physics/io/DataManager.java b/common-tools/clas-physics/src/main/java/org/jlab/physics/io/DataManager.java deleted file mode 100644 index 1a70d5ecc2..0000000000 --- a/common-tools/clas-physics/src/main/java/org/jlab/physics/io/DataManager.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ -package org.jlab.physics.io; - -import org.jlab.jnp.hipo4.data.Bank; -import org.jlab.clas.physics.*; - -/** - * - * @author gavalian - */ -public class DataManager { - public DataManager(){ - - } - - public static PhysicsEvent getPhysicsEvent(double beam, Bank eventBank){ - - PhysicsEvent physEvent = new PhysicsEvent(); - physEvent.setBeamParticle(new Particle(11,0.0,0.0,beam)); - - int nrows = eventBank.getRows(); - - for(int i = 0; i < nrows; i++){ - int pid = eventBank.getInt("pid", i); - Particle p = new Particle(); - if(pid!=0){ - p.initParticle(pid, - eventBank.getFloat("px",i), - eventBank.getFloat("py",i), - eventBank.getFloat("pz",i), - eventBank.getFloat("vx",i), - eventBank.getFloat("vy",i), - eventBank.getFloat("vz",i) - ); - } else { - p.initParticleWithPidMassSquare(pid, 0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0); - } - - physEvent.addParticle(p); - } - return physEvent; - } -} diff --git a/common-tools/clas-reco/pom.xml b/common-tools/clas-reco/pom.xml index 93b1d82d86..5779c0b5e7 100644 --- a/common-tools/clas-reco/pom.xml +++ b/common-tools/clas-reco/pom.xml @@ -31,21 +31,11 @@ jclara - - org.jlab.jnp - jnp-hipo - - org.jlab.jnp jnp-hipo4 - - org.jlab - groot - - org.jlab.coda jtools diff --git a/common-tools/clas-reco/src/main/java/org/jlab/clas/physics/AnalysisTree.java b/common-tools/clas-reco/src/main/java/org/jlab/clas/physics/AnalysisTree.java deleted file mode 100644 index 325a90dd17..0000000000 --- a/common-tools/clas-reco/src/main/java/org/jlab/clas/physics/AnalysisTree.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ -package org.jlab.clas.physics; - -import org.jlab.groot.tree.Tree; -import org.jlab.io.evio.EvioDataEvent; -import org.jlab.io.hipo.HipoDataSource; -import org.jlab.physics.analysis.PhysicsAnalysis; - -/** - * - * @author gavalian - */ -public class AnalysisTree extends Tree { - - private PhysicsAnalysis physAnalysis = new PhysicsAnalysis(); - private HipoDataSource hipoReader = null; - private GenericKinematicFitter fitter = new GenericKinematicFitter(11.0); - - public AnalysisTree(){ - super("CLAS12AnalysisTree"); - } - - public void setSource(String filename){ - hipoReader = new HipoDataSource(); - hipoReader.open(filename); - } - - - @Override - public boolean readNext(){ - if(hipoReader.hasEvent()==false) return false; - - EvioDataEvent event = (EvioDataEvent) hipoReader.getNextEvent(); - PhysicsEvent physEvent = fitter.getPhysicsEvent(event); - - physAnalysis.processEvent(physEvent); - System.out.println(physAnalysis.toString()); - return true; - } - - -} diff --git a/common-tools/clas-reco/src/main/java/org/jlab/clas/physics/DataAnalysis.java b/common-tools/clas-reco/src/main/java/org/jlab/clas/physics/DataAnalysis.java deleted file mode 100644 index 50a8ecfeae..0000000000 --- a/common-tools/clas-reco/src/main/java/org/jlab/clas/physics/DataAnalysis.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ -package org.jlab.clas.physics; - -import org.jlab.clas.detector.DetectorData; -import org.jlab.clas.detector.DetectorEvent; -import org.jlab.groot.data.H1F; -import org.jlab.groot.ui.TCanvas; -import org.jlab.io.base.DataEvent; -import org.jlab.io.hipo.HipoDataSource; -import org.jlab.utils.options.OptionParser; - -/** - * - * @author gavalian - */ -public class DataAnalysis { - public static void main(String[] args){ - OptionParser parser = new OptionParser(); - parser.addRequired("-i", "input file"); - parser.addOption("-b", "100", "number of bins in the histogram"); - parser.addRequired("-part", "particle string"); - parser.addRequired("-var", "variable of the particle"); - parser.addRequired("-min", "minimum value for histogram"); - parser.addRequired("-max", "maximum value for histogram"); - parser.addRequired("-filter", "event filter"); - - parser.parse(args); - - H1F h1 = new H1F("h1",parser.getOption("-b").intValue(),parser.getOption("-min").doubleValue(), - parser.getOption("-max").doubleValue()); - h1.setFillColor(43); - HipoDataSource reader = new HipoDataSource(); - reader.open(parser.getOption("-i").stringValue()); - EventFilter filter = new EventFilter(parser.getOption("-filter").stringValue()); - - while(reader.hasEvent()==true){ - DataEvent event = reader.getNextEvent(); - DetectorEvent detEvent = DetectorData.readDetectorEvent(event); - if(filter.isValid(detEvent.getPhysicsEvent())==true){ - //System.out.println(detEvent.getPhysicsEvent().toLundString()); - Particle part = detEvent.getPhysicsEvent().getParticle(parser.getOption("-part").stringValue()); - double var = part.get(parser.getOption("-var").stringValue()); - //System.out.println(" getting particle " + parser.getOption("-part").stringValue()); - //System.out.println(" " + part.get(parser.getOption("-var").stringValue())); - h1.fill(var); - } - } - - TCanvas c1 = new TCanvas("c1",500,500); - c1.draw(h1); - } -} diff --git a/common-tools/clas-reco/src/main/java/org/jlab/clas/physics/EventTree.java b/common-tools/clas-reco/src/main/java/org/jlab/clas/physics/EventTree.java deleted file mode 100644 index 7e6f93ba1d..0000000000 --- a/common-tools/clas-reco/src/main/java/org/jlab/clas/physics/EventTree.java +++ /dev/null @@ -1,436 +0,0 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ -package org.jlab.clas.physics; - -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.util.ArrayList; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; -import javax.swing.JComboBox; -import javax.swing.JDialog; -import javax.swing.JFrame; -import javax.swing.JMenuItem; -import javax.swing.JOptionPane; -import javax.swing.JTextField; -import javax.swing.tree.DefaultMutableTreeNode; -import javax.swing.tree.TreeModel; -import javax.swing.tree.TreePath; -import org.jlab.groot.base.GStyle; -import org.jlab.groot.data.DataVector; -import org.jlab.groot.data.H1F; -import org.jlab.groot.studio.StudioUI; -import org.jlab.groot.tree.DynamicTree; -import org.jlab.groot.tree.Tree; -import org.jlab.groot.tree.TreeProvider; -import org.jlab.groot.tree.TreeTextFile; -import org.jlab.groot.ui.TCanvas; -import org.jlab.io.base.DataEvent; -import org.jlab.io.evio.EvioDataEvent; -import org.jlab.io.hipo.HipoDataSource; - -/** - * - * @author gavalian - */ -public class EventTree extends Tree implements TreeProvider { - - private Map treeBranches = new LinkedHashMap(); - private Tree treeObject = new Tree("Event"); - private GenericKinematicFitter kinFitter = new GenericKinematicFitter(11); - private HipoDataSource reader = null; - private int currentEvent = 0; - private DynamicTree dynamicTree = new DynamicTree("EventTree"); - - public EventTree(){ - super("EventTree"); - } - - @Override - public void reset(){ - currentEvent = 0; - reader.gotoEvent(0); - } - - @Override - public int getEntries(){ - return this.reader.getSize(); - } - - @Override - public int readEntry(int entry) { - DataEvent event = reader.gotoEvent(entry); - if(event==null){ - System.out.println(" NULL event for entry #" + entry); - } else { - this.processEvent(event); - } - return 1; - } - - @Override - public boolean readNext() { - if(reader.hasEvent()==false) return false; - DataEvent event = reader.getNextEvent(); - System.out.println("reading event"); - this.processEvent(event); - return true; - } - - public void setSource(String filename){ - reader = new HipoDataSource(); - reader.open(filename); - } - - public void addBranch(String name, String filter){ - EventTreeBranch branch = new EventTreeBranch(name); - branch.setFilter(filter); - if(treeBranches.containsKey(name)==false){ - treeBranches.put(name, branch); - } else { - System.out.println("TREE Branch already exists : " + name); - } - } - - public void addBranchWithFilter(String name, String filter, String genFilter){ - EventTreeBranch branch = new EventTreeBranch(name); - branch.setFilter(filter); - branch.setFilterGenerated(genFilter); - if(treeBranches.containsKey(name)==false){ - treeBranches.put(name, branch); - } else { - System.out.println("TREE Branch already exists : " + name); - } - } - - public void addLeaf(String branch, String name, String expression, String... properties){ - treeBranches.get(branch).addLeaf(name, expression, properties); - } - - public void initTree(){ - //treeObject = new Tree("EventTree"); - this.reset(); - for(Map.Entry entry : treeBranches.entrySet()){ - Map leafs = entry.getValue().getLeafs(); - for(Map.Entry item : leafs.entrySet()){ - List properties = item.getValue().getProperties(); - for(int i = 0; i < properties.size();i++){ - String branch = item.getValue().getLeafPropertyName(i); - this.addBranch(branch, "", "GeV"); - System.out.println("adding a branch with name = " + branch); - } - } - } - treeObject.print(); - this.getDynamicTree(); - } - - public void processEvent(DataEvent event){ - - RecEvent recEvent = kinFitter.getRecEvent(event); - recEvent.doPidMatch(); - this.resetBranches(-1000.0); - EventFilter filter = new EventFilter("11:2112:321:Xn:X-:X+"); - for(Map.Entry entry : treeBranches.entrySet()){ - if(entry.getValue().getFilter().isValid(recEvent.getReconstructed())){ - //System.out.println("passed the filter"); - Map leafs = entry.getValue().getLeafs(); - for(Map.Entry item : leafs.entrySet()){ - List properties = item.getValue().getProperties(); - Particle p = recEvent.getReconstructed().getParticle(item.getValue().getExpression()); - for(int i = 0; i < properties.size(); i++){ - String branch = item.getValue().getLeafPropertyName(i); - double value = p.get(properties.get(i)); - this.getBranch(branch).setValue(value); - } - } - } - } - //treeObject.print(); - } - - public Tree tree() { - return this; - } - - public TreeModel getTreeModel() { - return null; - } - - @Override - public DynamicTree getDynamicTree() { - - //DynamicTree tree = new DynamicTree(getName()); - this.dynamicTree.clear(); - //roota.add(new DefaultMutableTreeNode("e-") ); - //tree.addObject(rootb, "e+"); - //tree.addObject(rootbranch); - for(Map.Entry entry : this.treeBranches.entrySet()){ - String name = entry.getKey(); - DefaultMutableTreeNode base = this.dynamicTree.addObject( new DefaultMutableTreeNode(name)); - //tree.addObject(base); - System.out.println("creating base = " + name); - EventTreeBranch branch = entry.getValue(); - for(Map.Entry item : branch.getLeafs().entrySet()){ - DefaultMutableTreeNode particle = this.dynamicTree.addObject(base, item.getValue().getName(),true); - - System.out.println("adding leaf = " + item.getValue().getName()); - item.getValue().getProperties(); - for(String property : item.getValue().getProperties()){ - System.out.println("adding property = " + property); - this.dynamicTree.addObject(particle, property); - } - } - //root.add(base); - } - //tree.addObject(root); - this.dynamicTree.repaint(); - this.dynamicTree.revalidate(); - return dynamicTree; - } - - public List actionTreeNode(TreePath[] path, int limit) { - List result = new ArrayList(); - //System.out.println("Got callback to compute something"); - boolean pathOK = true; - - for(TreePath p : path){ - if(p.getPathCount()!=4) pathOK = false; - } - - if(pathOK==false) return result; - - List variables = new ArrayList(); - - for(int i = 0; i < path.length; i++){ - String branch = path[i].getPathComponent(1).toString() + "_" - + path[i].getPathComponent(2).toString() + "_" - + path[i].getPathComponent(3).toString(); - variables.add(branch); - result.add(new DataVector()); - } - - int counter = 0; - int nevents = reader.getSize(); - for(int i = 0; i < nevents; i++){ - - DataEvent event = reader.gotoEvent(i); - if(event!=null){ - counter++; - this.processEvent(event); - boolean addEvent = true; - - for(int k = 0; k < variables.size(); k++){ - if(this.getBranch(variables.get(k)).getValue().doubleValue()<-500) addEvent = false; - } - if(addEvent==true){ - for(int k = 0; k < variables.size(); k++){ - result.get(k).add(this.getBranch(variables.get(k)).getValue().doubleValue()); - } - } - } - if(limit>0&&counter>limit) break; - } - return result; - } - - public JDialog treeConfigure() { - - String[] options = new String[]{"mass","p","theta","phi","px","py","pz","mass2"}; - JComboBox propertyOne = new JComboBox(options); - JComboBox propertyTwo = new JComboBox(options); - JComboBox propertyThree = new JComboBox(options); - JTextField textName = new JTextField(); - JTextField textFilter = new JTextField(); - JTextField textGenFilter = new JTextField(); - JTextField textParticle = new JTextField(); - JTextField textExpression = new JTextField(); - textName.setText("INCLUSIVE"); - textGenFilter.setText("11:X+:X-:Xn"); - textFilter.setText("11:X+:X-:Xn"); - textParticle.setText("electron"); - textExpression.setText("[11]"); - propertyOne.setSelectedIndex(0); - propertyTwo.setSelectedIndex(1); - propertyThree.setSelectedIndex(2); - - Object[] message = { - "Name : ", textName, - "Generated Filter : ", textGenFilter, - "Event Filter : ", textFilter, - "Particle : ", textParticle, - "Expression : ", textExpression, - "property :", propertyOne, - "property :", propertyTwo, - "property :", propertyThree - }; - int option = JOptionPane.showConfirmDialog(null, message, "Add Particle", JOptionPane.OK_CANCEL_OPTION); - if (option == JOptionPane.OK_OPTION) { - String strOne = (String) propertyOne.getSelectedItem(); - String strTwo = (String) propertyTwo.getSelectedItem(); - String strThree = (String) propertyThree.getSelectedItem(); - String name = textName.getText(); - String filter = textFilter.getText(); - String filterGen = textGenFilter.getText(); - String particle = textParticle.getText(); - String expression = textExpression.getText(); - this.addBranchWithFilter(name, filter, filterGen); - - this.addLeaf(name, particle, expression, new String[]{strOne,strTwo,strThree}); - //this.getCanvas().divide(Integer.parseInt(stringCOLS), Integer.parseInt(stringROWS)); - System.out.println(" ADDING BRANCH ----> "); - this.initTree(); - } - - return new JDialog(); - } - - //public Tree getTree(){return treeObject;} - - /** - * class describing EventTree branch - */ - public static class EventTreeBranch { - - private String branchName = ""; - private final EventFilter branchFilter = new EventFilter(); - private final EventFilter branchFilterGenerated = new EventFilter(); - private final Map branchLeafs = new LinkedHashMap(); - - public EventTreeBranch(String name){ - branchName = name; - } - - public EventTreeBranch(String name,String filter){ - branchName = name; - branchFilter.setFilter(filter); - } - - public EventTreeBranch(){ - - } - - public Map getLeafs(){ - return branchLeafs; - } - - public void addLeaf(String name, String expression, String... properties){ - EventTreeLeaf leaf = new EventTreeLeaf(name,expression); - leaf.addProperties(properties); - leaf.setParent(branchName); - branchLeafs.put(leaf.getName(), leaf); - } - - - - public void setName(String name){ branchName = name;} - public String getName(){return branchName;} - public EventFilter getFilter(){return branchFilter;} - public EventFilter getFilterGenerated(){return branchFilterGenerated;} - public void setFilter(String filter) { branchFilter.setFilter(filter);} - public void setFilterGenerated(String filter) { branchFilterGenerated.setFilter(filter);} - - } - - public static class EventTreeLeaf { - - String leafName = ""; - String leafExpression = ""; - String parentBranch = ""; - - List leafProperties = new ArrayList(); - - public EventTreeLeaf(String name, String exp){ - leafName = name; - leafExpression = exp; - } - - public void addProperties(String... properties){ - for(String property : properties){ - leafProperties.add(property); - } - } - - - public void addProperty(String property){ - leafProperties.add(property); - } - - public List getProperties(){ - return leafProperties; - } - - public String getLeafPropertyName(int index){ - return String.format("%s_%s_%s", parentBranch,leafName,leafProperties.get(index)); - } - - public String getExpression(){return leafExpression;} - - public String getParent(){ return parentBranch;} - public void setParent(String parent) {parentBranch = parent;} - public void setName(String name){ leafName = name;} - public String getName(){return leafName;} - - public List getTreeBranches(String prefix){ - List branches = new ArrayList(); - for(String property : leafProperties){ - branches.add(String.format("%s_%s_%s", prefix,leafName,property)); - } - return branches; - } - } - - public void openFile(){ - - } - - public static void main(String[] args){ - GStyle.getGraphErrorsAttributes().setMarkerStyle(0); - GStyle.getGraphErrorsAttributes().setMarkerColor(3); - GStyle.getGraphErrorsAttributes().setMarkerSize(7); - GStyle.getGraphErrorsAttributes().setLineColor(3); - GStyle.getGraphErrorsAttributes().setLineWidth(2); - GStyle.getFunctionAttributes().setLineWidth(6); - GStyle.getAxisAttributesX().setTitleFontSize(14); - GStyle.getAxisAttributesX().setLabelFontSize(12); - GStyle.getAxisAttributesY().setTitleFontSize(14); - GStyle.getAxisAttributesY().setLabelFontSize(12); - GStyle.getH1FAttributes().setFillColor(43); - GStyle.getH1FAttributes().setOptStat("1110"); - - if(args.length==0){ - StudioUI studio = new StudioUI(); - } else { - - String inputFile = args[0]; - - if(inputFile.endsWith(".hipo")==true){ - System.out.println("----> opening a HIPO DST Studio"); - final EventTree evtTree = new EventTree(); - evtTree.setSource(inputFile); - - JMenuItem itemOpen = new JMenuItem("Open DST Hipo..."); - - itemOpen.addActionListener(new ActionListener(){ - public void actionPerformed(ActionEvent e) { - evtTree.openFile(); - } - - }); - StudioUI studio = new StudioUI(evtTree); - studio.addImportMenuItem(itemOpen); - - } else if(inputFile.endsWith(".txt")==true){ - TreeTextFile textTree = new TreeTextFile("TextTree"); - textTree.readFile(inputFile); - StudioUI studio = new StudioUI(textTree); - } - - } - - } -} diff --git a/common-tools/clas-reco/src/main/java/org/jlab/clas/physics/GenericKinematicFitter.java b/common-tools/clas-reco/src/main/java/org/jlab/clas/physics/GenericKinematicFitter.java deleted file mode 100644 index e72222eddc..0000000000 --- a/common-tools/clas-reco/src/main/java/org/jlab/clas/physics/GenericKinematicFitter.java +++ /dev/null @@ -1,156 +0,0 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ -package org.jlab.clas.physics; - -import java.util.Map; -import org.jlab.clas.pdg.PDGDatabase; - -import org.jlab.io.base.DataEvent; -import org.jlab.io.base.DataBank; -import org.jlab.io.base.DataEvent; -import org.jlab.jnp.hipo.data.HipoEvent; -import org.jlab.jnp.hipo.data.HipoNode; - -/** - * - * @author gavalian - */ -public class GenericKinematicFitter { - - private final EventFilter filter = new EventFilter(); - protected Double beamEnergy = 11.0; - - - public GenericKinematicFitter(double beam){ - this.beamEnergy = beam; - this.filter.setFilter("X+:X-:Xn"); - } - - /** - * Returns PhysicsEvent object with reconstructed particles. - * @param event - DataEvent object - * @return PhysicsEvent : event containing particles. - */ - public PhysicsEvent getPhysicsEvent(DataEvent event){ - //if(event instanceof DataEvent){ - //System.out.println(" CHECK FOR PARTICLE = " + event.hasBank("EVENT::particle")); - if(event.hasBank("REC::Particle")){ - DataBank evntBank = (DataBank) event.getBank("REC::Particle"); - int nrows = evntBank.rows(); - PhysicsEvent physEvent = new PhysicsEvent(); - physEvent.setBeam(this.beamEnergy); - for(int loop = 0; loop < nrows; loop++){ - - int pid = evntBank.getInt("pid", loop); - int status = evntBank.getInt("status", loop); - - if(PDGDatabase.isValidPid(pid)==true){ - Particle part = new Particle( - evntBank.getInt("pid", loop), - evntBank.getFloat("px", loop), - evntBank.getFloat("py", loop), - evntBank.getFloat("pz", loop), - evntBank.getFloat("vx", loop), - evntBank.getFloat("vy", loop), - evntBank.getFloat("vz", loop)); - if(status>0){ - physEvent.addParticle(part); - } - } else { - Particle part = new Particle(); - int charge = evntBank.getInt("charge", loop); - part.setParticleWithMass(evntBank.getFloat("mass", loop), - (byte) charge, - evntBank.getFloat("px", loop), - evntBank.getFloat("py", loop), - evntBank.getFloat("pz", loop), - evntBank.getFloat("vx", loop), - evntBank.getFloat("vy", loop), - evntBank.getFloat("vz", loop) - ); - - if(status>0){ - physEvent.addParticle(part); - } - } - - } - return physEvent; - } - - //} - return new PhysicsEvent(this.beamEnergy); - } - - public PhysicsEvent getGeneratedEvent(DataEvent event){ - PhysicsEvent physEvent = new PhysicsEvent(); - physEvent.setBeam(this.beamEnergy); - if(event.hasBank("MC::Particle")){ - DataBank evntBank = (DataBank) event.getBank("MC::Particle"); - int nrows = evntBank.rows(); - for(int loop = 0; loop < nrows; loop++){ - Particle genParticle = new Particle( - evntBank.getInt("pid", loop), - evntBank.getFloat("px", loop)*0.001, - evntBank.getFloat("py", loop)*0.001, - evntBank.getFloat("pz", loop)*0.001, - evntBank.getFloat("vx", loop), - evntBank.getFloat("vy", loop), - evntBank.getFloat("vz", loop)); - physEvent.addParticle(genParticle); - } - } - return physEvent; - } - - public PhysicsEvent createEvent(DataEvent event){ - PhysicsEvent recEvent = this.getPhysicsEvent(event); - PhysicsEvent genEvent = this.getGeneratedEvent(event); - for(int i = 0; i < genEvent.count();i++){ - recEvent.mc().add(genEvent.getParticle(i)); - } - return recEvent; - } - - public PhysicsEvent createEvent(HipoEvent event){ - PhysicsEvent physEvent = new PhysicsEvent(); - physEvent.setBeam(this.beamEnergy); - if(event.hasGroup(20)==true){ - Map items = event.getGroup(20); - int nentries = items.get(1).getDataSize(); - for(int i = 0; i < nentries; i++){ - int pid = items.get(1).getInt(i); - double px = items.get(2).getFloat(i*3+0); - double py = items.get(2).getFloat(i*3+1); - double pz = items.get(2).getFloat(i*3+2); - Particle particle = new Particle(pid,px,py,pz); - double vx = items.get(3).getShort(i*3+0)*100.0; - double vy = items.get(3).getShort(i*3+1)*100.0; - double vz = items.get(3).getShort(i*3+2)*100.0; - particle.vertex().setXYZ(vx, vy, vz); - physEvent.mc().add(particle); - } - } - return physEvent; - } - - public RecEvent getRecEvent(DataEvent event){ - - PhysicsEvent rev = getPhysicsEvent(event); - PhysicsEvent gev = getGeneratedEvent(event); - RecEvent recEvent = new RecEvent(this.beamEnergy); - - for(int i = 0; i < rev.count();i++){ - recEvent.getReconstructed().addParticle(rev.getParticle(i)); - } - - for(int i = 0; i < gev.count();i++){ - recEvent.getGenerated().addParticle(gev.getParticle(i)); - } - - return recEvent; - } -} diff --git a/common-tools/clas-reco/src/main/java/org/jlab/clas/physics/RecEvent.java b/common-tools/clas-reco/src/main/java/org/jlab/clas/physics/RecEvent.java deleted file mode 100644 index eea62c5e41..0000000000 --- a/common-tools/clas-reco/src/main/java/org/jlab/clas/physics/RecEvent.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ -package org.jlab.clas.physics; - -/** - * - * @author gavalian - */ -public class RecEvent { - - private PhysicsEvent recEvent = new PhysicsEvent(); - private PhysicsEvent genEvent = new PhysicsEvent(); - - private double eucledianDistanceThreshold = 0.35; - - - public RecEvent(double beame){ - recEvent.setBeam(beame); - genEvent.setBeam(beame); - } - - public void setEuclidianThreshold(double ed){ - this.eucledianDistanceThreshold = ed; - } - - public void addParticle(Particle p){ - recEvent.addParticle(p); - } - - public void addGeneratedParticle(Particle p){ - genEvent.addParticle(p); - } - - public PhysicsEvent getGenerated(){ return genEvent;} - public PhysicsEvent getReconstructed(){ return recEvent;} - - public Particle getMatched(int gindex){ - Particle p = this.genEvent.getParticle(gindex); - double maxDistance = 1000; - int maxIndex = -1; - for(int i = 0; i < recEvent.count();i++){ - double distance = recEvent.getParticle(i).euclideanDistance(p); - if(distance files){ - HipoWriter writer = new HipoWriter(); - writer.open(outputName); - int nFiles = files.size(); - writer.setCompressionType(compression); - - String[] keepSchema = keep.split(":"); - SchemaFactory writerFactory = new SchemaFactory(); - ProgressPrintout progress = new ProgressPrintout(); - - - for(int i = 0; i < nFiles; i++){ - HipoReader reader = new HipoReader(); - reader.open(files.get(i)); - if(i==0){ - SchemaFactory factory = reader.getSchemaFactory(); - - System.out.println(" OPENNING FIRST FILE : " + files.get(i)); - System.out.println(" Scanning Schema FACTORY"); - List list = factory.getSchemaList(); - - for(Schema schema : list){ - for(String key : keepSchema){ - if(schema.getName().contains(key)==true||keep.compareTo("ALL")==0){ - try { - writerFactory.addSchema(schema); - } catch (Exception ex) { - Logger.getLogger(HipoFileUtils.class.getName()).log(Level.SEVERE, null, ex); - } - writerFactory.addFilter(schema.getName()); - writer.defineSchema(schema); - System.out.println("\t >>>>> adding schema to writer : " + schema.getName()); - } - } - } - writerFactory.show(); - //writeFactory.getSchemaEvent() - } - int nEvents = reader.getEventCount(); - for(int nev = 0; nev < nEvents; nev++){ - HipoEvent event = reader.readEvent(nev); - boolean flag = false; - for(HipoGroup group : event.getGroups()) { -// System.out.println(group.getSchema().getName()); - if(group.getSchema().getName().contains(filter)==true || filter.compareTo("ANY")==0) flag = true; - } - if(flag){ - HipoEvent outEvent = writerFactory.getFilteredEvent(event); - //outEvent.show(); - writer.writeEvent(outEvent); - progress.updateStatus(); - } - } - } - writer.close(); - } - - public static EvioDataBank getGenPart(PhysicsEvent event){ - EvioDataBank bank = EvioFactory.createBank("GenPart::true", event.count()); - for(int i = 0; i < event.count(); i++){ - bank.setInt("pid", i, event.getParticle(i).pid()); - bank.setDouble("px", i, event.getParticle(i).px()*1000.0); - bank.setDouble("py", i, event.getParticle(i).py()*1000.0); - bank.setDouble("pz", i, event.getParticle(i).pz()*1000.0); - bank.setDouble("vx", i, event.getParticle(i).vertex().x()*10.0); - bank.setDouble("vy", i, event.getParticle(i).vertex().y()*10.0); - bank.setDouble("vz", i, event.getParticle(i).vertex().z()*10.0); - } - return bank; - } - - public static List getGeneratedBank(PhysicsEvent event){ - List nodes = new ArrayList(); - HipoNodeBuilder vector = new HipoNodeBuilder(); - //HipoNodeBuilder vector = new HipoNodeBuilder(); - HipoNodeBuilder vertex = new HipoNodeBuilder(); - HipoNodeBuilder pid = new HipoNodeBuilder(); - - for(int i = 0; i < event.count(); i++){ - - pid.push(event.getParticle(i).pid()); - - vector.push( (float) event.getParticle(i).px()); - vector.push( (float) event.getParticle(i).py()); - vector.push( (float) event.getParticle(i).pz()); - - vertex.push((short) (event.getParticle(i).vertex().x()*100.0)); - vertex.push((short) (event.getParticle(i).vertex().y()*100.0)); - vertex.push((short) (event.getParticle(i).vertex().z()*100.0)); - } - - nodes.add(pid.buildNode(20, 1)); - nodes.add(vector.buildNode(20, 2)); - nodes.add(vertex.buildNode(20, 3)); - //System.out.println(); - return nodes; - } - - public static void writeLundFilesHipo(String output, List lundFiles){ - LundReader reader = new LundReader(); - for(int i = 0; i < lundFiles.size(); i++){ - reader.addFile(lundFiles.get(i)); - System.out.println("LUND READER : adding file ->>> " + lundFiles.get(i)); - } - reader.open(); - - HipoWriter writer = new HipoWriter(); - //writer.addHeader("{Reconstruction-File-LUND}"); - - writer.setCompressionType(2); - writer.open(output); - while(reader.next()==true){ - PhysicsEvent event = reader.getEvent(); - HipoEvent hipoEvent = new HipoEvent(); - List nodes = HipoFileUtils.getGeneratedBank(event); - //System.out.println("nodes size = " + nodes.size()); - hipoEvent.addNodes(nodes); - - writer.writeEvent(hipoEvent); - } - writer.close(); - } - - public static void writeLundFiles(String output, List lundFiles){ - LundReader reader = new LundReader(); - for(int i = 0; i < lundFiles.size(); i++){ - reader.addFile(lundFiles.get(i)); - System.out.println("LUND READER : adding file ->>> " + lundFiles.get(i)); - } - reader.open(); - - HipoDataSync writer = new HipoDataSync(); - writer.setCompressionType(2); - writer.open(output); - int icounter = 0; - while(reader.next()==true){ - PhysicsEvent event = reader.getEvent(); - EvioDataEvent evioEvent = EvioFactory.createEvioEvent(); - EvioDataBank genPart = HipoFileUtils.getGenPart(event); - evioEvent.appendGeneratedBank(genPart); - writer.writeEvent(evioEvent); - icounter++; - } - System.out.println("LUND WRITER : written " + icounter + " events "); - writer.close(); - } - - public static void eventShowHipo(String inputFile,String filter, String particle, String property, int nbins){ - HipoReader reader = new HipoReader(); - reader.open(inputFile); - EventFilter evtFilter = new EventFilter(filter); - DataVector result = new DataVector(); - GenericKinematicFitter fitter = new GenericKinematicFitter(11.0); - int nentries = reader.getEventCount(); - int icounter = 0; - - for(int loop = 0; loop < nentries; loop++){ - //byte[] eventBuffer = reader.readEvent(loop); - HipoEvent event = reader.readEvent(loop); - PhysicsEvent physEvent = new PhysicsEvent();//fitter.createEvent(event); - - if(evtFilter.checkFinalState(physEvent.mc())==true){ - icounter++; - Particle p = physEvent.getParticle(particle); - if(p.p()>0.000001){ - double value = p.get(property); - result.add(value); - } - /*System.out.println(" " + physEvent.mc().toLundString()); - System.out.println(" PARTICLE = \n" + p.toLundString()); - System.out.println(" filling value " + value);*/ - } - } - System.out.println(" EVENT # " + nentries + " FILTER PASSED # " + icounter); - H1F h = H1F.create(property, nbins, result); - TCanvas c1 = new TCanvas("c1",500,500); - c1.draw(h); - } - - public static void eventShow(String inputFile,String filter, String particle, String property, int nbins){ - - GenericKinematicFitter fitter = new GenericKinematicFitter(11.0); - - HipoDataSource reader = new HipoDataSource(); - reader.open(inputFile); - EventFilter evtFilter = new EventFilter(filter); - DataVector result = new DataVector(); - - int icounter = 0; - int nevents = 0; - while(reader.hasEvent()==true){ - EvioDataEvent event = (EvioDataEvent) reader.getNextEvent(); - PhysicsEvent physEvent = new PhysicsEvent();//fitter.createEvent(event); - if(evtFilter.checkFinalState(physEvent.mc())==true){ - icounter++; - Particle p = physEvent.getParticle(particle); - if(p.p()>0.000001){ - double value = p.get(property); - result.add(value); - } - /*System.out.println(" " + physEvent.mc().toLundString()); - System.out.println(" PARTICLE = \n" + p.toLundString()); - System.out.println(" filling value " + value);*/ - } - nevents++; - } - System.out.println(" EVENT # " + nevents + " FILTER PASSED # " + icounter); - H1F h = H1F.create(property, nbins, result); - TCanvas c1 = new TCanvas("c1",500,500); - c1.draw(h); - } - - public static void main(String[] args){ - - OptionParser parser = new OptionParser(); - parser.addRequired("-o"); - parser.addOption("-keep", "ALL", "Selection of banks to keep in the output"); - parser.addOption("-filter", "ANY", "Write only events with the selected bank"); - parser.addOption("-c", "2","Compression algorithm (0-none, 1-gzip, 2-lz4)"); - - parser.parse(args); - - String outputFile = parser.getOption("-o").stringValue(); - List inputFileList = parser.getInputList(); - int compression = parser.getOption("-c").intValue(); - String keepBanks = parser.getOption("-keep").stringValue(); - String filterEvents = parser.getOption("-filter").stringValue(); - - HipoFileUtils.writeHipo(outputFile, compression, keepBanks, filterEvents, inputFileList); - /* - if(parser.getCommand().getCommand().compareTo("-lund")==0){ - String output = parser.getCommand().getAsString("-o"); - List inputList = parser.getCommand().getInputList(); - HipoFileUtils.writeLundFiles(output, inputList); - }*/ - } -} diff --git a/reconstruction/eb/pom.xml b/reconstruction/eb/pom.xml index b69b3fb8ad..659cc3b86c 100644 --- a/reconstruction/eb/pom.xml +++ b/reconstruction/eb/pom.xml @@ -18,10 +18,6 @@ org.jlab.jnp jnp-hipo - - org.jlab - groot - cnuphys magfield diff --git a/reconstruction/eb/src/main/java/org/jlab/monitor/eb/ParticleReconstruction.java b/reconstruction/eb/src/main/java/org/jlab/monitor/eb/ParticleReconstruction.java deleted file mode 100644 index 7a90fed29f..0000000000 --- a/reconstruction/eb/src/main/java/org/jlab/monitor/eb/ParticleReconstruction.java +++ /dev/null @@ -1,86 +0,0 @@ -package org.jlab.monitor.eb; - -import org.jlab.clas.pdg.PDGDatabase; -import org.jlab.clas.pdg.PDGParticle; -import org.jlab.clas.physics.GenericKinematicFitter; -import org.jlab.clas.physics.Particle; -import org.jlab.clas.physics.RecEvent; -import org.jlab.groot.data.H1F; -import org.jlab.groot.data.H2F; -import org.jlab.groot.data.IDataSet; -import org.jlab.groot.data.TDirectory; -import org.jlab.io.base.DataEvent; - -/** - * - * @author gavalian - */ -public class ParticleReconstruction { - - public String directoryName = ""; - public GenericKinematicFitter fitter = new GenericKinematicFitter(11.0); - public int particleId = 0; - - public ParticleReconstruction(TDirectory directory, int pid){ - PDGParticle p = PDGDatabase.getParticleById(pid); - directoryName = "/reconstruction/particles/" + p.name(); - particleId = pid; - this.initHistograms(directory); - } - - public final void initHistograms(TDirectory dir){ - dir.cd(); - dir.mkdir(directoryName); - dir.cd(directoryName); - dir.pwd(); - - H2F h2p = new H2F("PRES",40,0.0,10.0,100,-0.2,0.2); - H2F h2t = new H2F("THRES",40,0.0,10.0,180,-5.0,5.0); - H2F h2phi = new H2F("PHIRES",40,0.0,10.0,180,-5.0,5.0); - - H1F h1p = new H1F("PRES_1D","Momentum Resolution",200,-0.2,0.2); - H1F h1t = new H1F("THRES_1D","Theta Resolution",180,-5.0,5.0); - H1F h1phi = new H1F("PHIRES_1D","Phi Resolution",180,-5.0,5.0); - - h1p.setTitleX("(p-p^g)/p^g"); - h1t.setTitleX("#theta^g-#theta"); - h1phi.setTitleX("#phi^g-#phi"); - dir.addDataSet(h2p,h2t,h2phi); - dir.addDataSet(h1p,h1t,h1phi); - dir.ls(); - dir.cd(); - } - - public void process(DataEvent event, TDirectory directory){ - - RecEvent recEvent = fitter.getRecEvent(event); - int np = recEvent.getGenerated().count(); - for(int i = 0; i < np; i++){ - Particle gp = recEvent.getGenerated().getParticle(i); - if(gp.pid()==particleId){ - Particle rp = recEvent.getMatched(i); - if(rp.vector().p()>0){ - //System.out.println("found event " ); - double res_p = (gp.vector().p()-rp.vector().p())/gp.vector().p(); - double res_t = (gp.vector().theta()-rp.vector().theta())*57.29; - double res_phi = (gp.vector().phi()-rp.vector().phi())*57.29; - - IDataSet dsP = directory.getObject(directoryName+"/PRES"); - if(dsP != null) ( (H2F) dsP).fill(gp.vector().p(), res_p); - IDataSet dsT = directory.getObject(directoryName+"/THRES"); - if(dsT != null) ( (H2F) dsT).fill(gp.vector().p(), res_t); - IDataSet dsF = directory.getObject(directoryName+"/PHIRES"); - if(dsF != null) ( (H2F) dsF).fill(gp.vector().p(), res_phi); - - IDataSet dsP1 = directory.getObject(directoryName+"/PRES_1D"); - if(dsP1 != null) ( (H1F) dsP1).fill(res_p); - IDataSet dsT1 = directory.getObject(directoryName+"/THRES_1D"); - if(dsT1 != null) ( (H1F) dsT1).fill(res_t); - IDataSet dsF1 = directory.getObject(directoryName+"/PHIRES_1D"); - if(dsF1 != null) ( (H1F) dsF1).fill(res_phi); - - } - } - } - } -} diff --git a/reconstruction/eb/src/main/java/org/jlab/monitor/eb/ReactionAnalysis.java b/reconstruction/eb/src/main/java/org/jlab/monitor/eb/ReactionAnalysis.java deleted file mode 100644 index 0fd5be8fc4..0000000000 --- a/reconstruction/eb/src/main/java/org/jlab/monitor/eb/ReactionAnalysis.java +++ /dev/null @@ -1,61 +0,0 @@ -package org.jlab.monitor.eb; - -import org.jlab.clas.physics.EventFilter; -import org.jlab.clas.physics.GenericKinematicFitter; -import org.jlab.clas.physics.Particle; -import org.jlab.clas.physics.RecEvent; -import org.jlab.groot.data.H1F; -import org.jlab.groot.data.H2F; -import org.jlab.groot.data.IDataSet; -import org.jlab.groot.data.TDirectory; -import org.jlab.io.base.DataEvent; - -/** - * - * @author gavalian - */ -public class ReactionAnalysis { - - String directoryName = ""; - EventFilter filter = new EventFilter("11:2212:22:22"); - EventFilter filterEP = new EventFilter("11:2212:Xn:X+:X-"); - public GenericKinematicFitter fitter = new GenericKinematicFitter(11.0); - - public ReactionAnalysis(TDirectory dir){ - directoryName = "/physics/eppi0"; - init(dir); - } - - public void init(TDirectory dir){ - dir.cd(); - dir.mkdir(directoryName); - dir.cd(directoryName); - - H1F h1a = new H1F("hQ2",100,0.0,5.0); - H1F h1b = new H1F("hMxEP",100,0.0,0.5); - H1F h1c = new H1F("hMPi0",100,0.0,0.5); - - dir.addDataSet(h1a,h1b,h1c); - dir.cd(); - - } - - public void process(DataEvent event, TDirectory directory){ - RecEvent recEvent = fitter.getRecEvent(event); - recEvent.doPidMatch(); - - if(filter.isValid(recEvent.getGenerated())==true){ - if(filterEP.isValid(recEvent.getReconstructed())==true){ - Particle epmx = recEvent.getReconstructed().getParticle("[b]+[t]-[11]-[2212]"); - - IDataSet dsP = directory.getObject(directoryName+"/hMxEP"); - if(dsP != null) ( (H1F) dsP).fill(epmx.vector().mass()); - } - if(recEvent.getReconstructed().countByPid(22)==2){ - Particle ggm = recEvent.getReconstructed().getParticle("[22,0]+[22,1]"); - IDataSet dsP = directory.getObject(directoryName+"/hMPi0"); - if(dsP != null) ( (H1F) dsP).fill(ggm.vector().mass()); - } - } - } -} diff --git a/reconstruction/eb/src/main/java/org/jlab/monitor/eb/ReconstructionMonitor.java b/reconstruction/eb/src/main/java/org/jlab/monitor/eb/ReconstructionMonitor.java deleted file mode 100644 index c0a3c882de..0000000000 --- a/reconstruction/eb/src/main/java/org/jlab/monitor/eb/ReconstructionMonitor.java +++ /dev/null @@ -1,54 +0,0 @@ -package org.jlab.monitor.eb; - -import java.util.ArrayList; -import java.util.List; -import org.jlab.groot.data.TDirectory; -import org.jlab.groot.ui.TBrowser; -import org.jlab.io.evio.EvioDataEvent; -import org.jlab.io.hipo.HipoDataSource; - -/** - * - * @author gavalian - */ -public class ReconstructionMonitor { - public static void main(String[] args){ - String inputFile = args[0]; - String outputFile = args[1]; - - TDirectory dir = new TDirectory(); - - List recModules = new ArrayList(); - recModules.add(new ParticleReconstruction(dir,11)); - recModules.add(new ParticleReconstruction(dir,2212)); - recModules.add(new ParticleReconstruction(dir,211)); - recModules.add(new ParticleReconstruction(dir,-211)); - - - ReactionAnalysis analysisPi0 = new ReactionAnalysis(dir); - - List objects = dir.getCompositeObjectList(dir); - System.out.println("OBJECTS"); - for(String o : objects){ - System.out.println(o); - } - - System.out.println("OBJECTS END"); - HipoDataSource reader = new HipoDataSource(); - reader.open(inputFile); - - int events = 0; - while(reader.hasEvent()){ - EvioDataEvent event = (EvioDataEvent) reader.getNextEvent(); - for(ParticleReconstruction m : recModules){ - m.process(event, dir); - } - analysisPi0.process(event, dir); - events++; - } - System.out.println(" processed events # " + events); - dir.writeFile(outputFile); - - //TBrowser t = new TBrowser(dir); - } -} diff --git a/reconstruction/ft/src/main/java/org/jlab/rec/ft/FTEBEngine.java b/reconstruction/ft/src/main/java/org/jlab/rec/ft/FTEBEngine.java index f9acd60a40..32cda98f09 100644 --- a/reconstruction/ft/src/main/java/org/jlab/rec/ft/FTEBEngine.java +++ b/reconstruction/ft/src/main/java/org/jlab/rec/ft/FTEBEngine.java @@ -8,8 +8,6 @@ import org.jlab.clas.detector.DetectorData; import org.jlab.clas.detector.DetectorEvent; -import org.jlab.clas.physics.GenericKinematicFitter; -import org.jlab.clas.physics.PhysicsEvent; import org.jlab.clas.reco.ReconstructionEngine; import org.jlab.detector.base.DetectorLayer; import org.jlab.geom.prim.Line3D; @@ -135,875 +133,4 @@ public void setSolenoid(double Solenoid) { public int getDebugMode() { return this.reco.debugMode; } - - - public static void main(String arg[]){ - - FTCALEngine cal = new FTCALEngine(); - cal.init(); - FTHODOEngine hodo = new FTHODOEngine(); - hodo.init(); - FTTRKEngine trk = new FTTRKEngine(); - trk.init(); - FTEBEngine en = new FTEBEngine(); - en.init(); - int debugMode = en.getDebugMode(); - String input = "/home/filippi/clas12/fttrkDev/clas12-offline-software-6.5.13-fttrkDev/filter_005418_newbanks.hipo"; - HipoDataSource reader = new HipoDataSource(); - reader.open(input); - - // initialize histos - H1F h1 = new H1F("Cluster Energy", 100, 0., 8.); - h1.setOptStat(Integer.parseInt("11111")); - h1.setTitleX("Cluster Energy (GeV)"); - H1F h2 = new H1F("Energy Resolution", 100, -1, 1); - h2.setOptStat(Integer.parseInt("11111")); - h2.setTitleX("Energy Resolution(GeV)"); - H1F h3 = new H1F("Theta Resolution", 100, -1, 1); - h3.setOptStat(Integer.parseInt("11111")); - h3.setTitleX("Theta Resolution(deg)"); - H1F h4 = new H1F("Phi Resolution", 100, -10, 10); - h4.setOptStat(Integer.parseInt("11111")); - h4.setTitleX("Phi Resolution(deg)"); - - H1F h5 = new H1F("Time Resolution", 100, -2, 2); - h5.setOptStat(Integer.parseInt("1111")); - h5.setTitleX("Time Resolution(ns)"); - H2F h6 = new H2F("Cluster Energy", 24, -180., 180., 24, -180., 180.); - h6.setTitleX("x (cm)"); - h6.setTitleY("y (cm)"); - H2F h7 = new H2F("N. Clusters", 24, -18., 18., 24, -18., 18.); - h7.setTitleX("x (mm)"); - h7.setTitleY("y (mm)"); - H2F h8 = new H2F("Cluster Energy", 100, 0., 9., 100, -0.5, 0.5); - h8.setTitleX("E (GeV)"); - h8.setTitleY("Energy Resolution(GeV)"); - H2F h9 = new H2F("Cluster Energy", 100, 2., 5., 100, -0.5, 0.5); - h9.setTitleX("#theta"); - h9.setTitleY("Energy Resolution(GeV)"); - H2F h10 = new H2F("Cluster Energy", 100, -180., 180., 100, -0.5, 0.5); - h10.setTitleX("#phi"); - h10.setTitleY("Energy Resolution(GeV)"); - - // residual plots (of TRK wrt tracking on ECAL - black histograms) - H2F h100 = new H2F("Cross on trk layer1", 100, -18., 18., 100, -18., 18.); - h100.setTitleX("x (mm) trk1"); - h100.setTitleY("y (mm) trk1"); - H2F h101 = new H2F("Cross on trk layer2", 100, -18., 18., 100, -18., 18.); - h101.setTitleX("x (mm) trk2"); - h101.setTitleY("y (mm) trk2"); - H2F h700 = new H2F("Strips on trk layer1", 100, -18., 18., 100, -18., 18.); - h100.setTitleX("x (mm) trk1"); - h100.setTitleY("y (mm) trk1"); - H2F h701 = new H2F("Strips on trk layer2", 100, -18., 18., 100, -18., 18.); - h101.setTitleX("x (mm) trk2"); - h101.setTitleY("y (mm) trk2"); - - double limTC = 4.; // for MC 0.05 is ok - H1F h102 = new H1F("trk1 x residual", 63, -limTC, limTC); - h102.setOptStat(10); - h102.setTitleX("trk1 x residual (mm)"); - h102.setFillColor(1); - H1F h103 = new H1F("trk2 x residual", 63, -limTC, limTC); - h103.setOptStat(10); - h103.setFillColor(51); - h103.setTitleX("trk2 x residual (mm)"); - H1F h104 = new H1F("trk1 y residual", 63, -limTC, limTC); - h104.setOptStat(Integer.parseInt("0")); - h104.setFillColor(1); - h104.setTitleX("trk1 y residual (mm)"); - H1F h105 = new H1F("trk2 y residual;", 63, -limTC, limTC); - h105.setOptStat(10); - h105.setTitleX("trk2 y residual (mm)"); - h105.setFillColor(51); - double limTCTheta = 0.05; - double limTCPhi = 1.; - H1F h106 = new H1F("trk1 theta residual (rad)", 100, -limTCTheta, limTCTheta); - h106.setOptStat(10); - h106.setTitleX("trk1 theta residual (rad)"); - h106.setFillColor(1); - H1F h107 = new H1F("trk2 theta residual (rad)", 100, -limTCTheta, limTCTheta); - h107.setOptStat(Integer.parseInt("0")); - h107.setTitleX("trk2 theta residual (rad)"); - h107.setFillColor(51); - H1F h108 = new H1F("trk1 phi residual (rad)", 100, -limTCPhi, limTCPhi); - h108.setOptStat(0); - h108.setTitleX("trk1 phi residual"); - h108.setFillColor(1); - H1F h109 = new H1F("trk2 phi residual (rad)", 100, -limTCPhi, limTCPhi); - h109.setOptStat(10); - h109.setTitleX("trk2 phi residual (rad)"); - h109.setFillColor(51); - - H1F h202 = new H1F("trk1 x", 25, 8.2, 9.0); - H1F h1202 = new H1F("trk1 x MC", 25, 8.2, 9.0); - h202.setOptStat(0); - h202.setTitleX("trk1 x position (mm)"); - h202.setTitleY("counts/strip width/sqrt(12) (16 um)"); // 25 bins - h202.setLineColor(3); - h202.setFillColor(3); - h1202.setLineColor(9); - h1202.setFillColor(49); - H1F h203 = new H1F("trk2 x", 25, 8.2, 9.0); - H1F h1203 = new H1F("trk2 MC", 25, 8.2, 9.0); - h203.setOptStat(0); - h203.setTitleX("trk2 x position (mm)"); - h203.setTitleY("counts/strip width/sqrt(12) (16 um)"); // 25 bins - h203.setLineColor(3); - h203.setFillColor(3); - h1203.setLineColor(9); - h1203.setFillColor(49); - H1F h204 = new H1F("trk1 y", 25, 2.4, 4.0); - H1F h1204 = new H1F("trk1 y MC", 25, 2.4, 4.0); - h204.setOptStat(0); - h204.setTitleX("trk1 y position (mm)"); - h204.setTitleY("counts/strip width/sqrt(12) (16 um)"); // 25 bins - h204.setLineColor(3); - h204.setFillColor(3); - h1204.setLineColor(9); - h1204.setFillColor(49); - H1F h205 = new H1F("trk2 y", 25, 2.4, 4.0); - H1F h1205 = new H1F("trk2 y MC", 25, 2.4, 4.0); - h205.setOptStat(0); - h205.setTitleX("trk2 y position (mm)"); - h205.setTitleY("counts/strip width/sqrt(12) (16 um)"); // 25 bins - h205.setLineColor(3); - h205.setFillColor(3); - h1205.setLineColor(9); - h1205.setFillColor(49); - - // resolution plots (of TRK wrt MC truth - red histograms) - H2F h1100 = new H2F("Cross on trk layer1 MC truth", 100, -18., 18., 100, -18., 18.); - h1100.setTitleX("x (mm) trk1"); - h1100.setTitleY("y (mm) trk1"); - H2F h1101 = new H2F("Cross on trk layer2 MC truth", 100, -18., 18., 100, -18., 18.); - h1101.setTitleX("x (mm) trk2"); - h1101.setTitleY("y (mm) trk2"); - int binres = 35; - double reslim = 5.*FTTRKConstantsLoader.Pitch; - H1F h1102 = new H1F("trk1 x resolution", binres, -reslim, reslim); - h1102.setOptStat(0); - h1102.setTitleX("trk1 x resolutionl (mm)"); - h1102.setLineColor(2); - h1102.setFillColor(2); - H1F h1103 = new H1F("trk2 x resolution", binres, -reslim, reslim); - h1103.setOptStat(0); - h1103.setTitleX("trk2 x resolution (mm)"); - h1103.setLineColor(2); - h1103.setFillColor(32); - H1F h1104 = new H1F("trk1 y resolution", binres, -reslim, reslim); - h1104.setOptStat(0); - h1104.setTitleX("trk1 y resolution (mm)"); - h1104.setLineColor(2); - h1104.setFillColor(2); - H1F h1105 = new H1F("trk2 y resolution", binres, -reslim, reslim); - h1105.setOptStat(0); - h1105.setTitleX("trk2 y resolution (mm)"); - h1105.setLineColor(2); - h1105.setFillColor(32); - H1F h1106 = new H1F("trk1 theta resolution", 50, -0.001, 0.001); - h1106.setOptStat(0); - h1106.setTitleX("trk1 theta resolution (rad)"); - h1106.setLineColor(2); - h1106.setFillColor(27); - H1F h1107 = new H1F("trk2 theta resolution", 50, -0.001, 0.001); - h1107.setOptStat(0); - h1107.setTitleX("trk2 theta resolution (rad)"); - h1107.setLineColor(2); - h1107.setFillColor(37); - H1F h1108 = new H1F("trk1 phi resolution", 50, -0.02, 0.02); - h1108.setOptStat(0); - h1108.setTitleX("trk1 phi resolution (rad)"); - h1108.setLineColor(2); - h1108.setFillColor(2); - H1F h1109 = new H1F("trk2 phi resolution", 50, -0.02, 0.02); - h1109.setOptStat(0); - h1109.setTitleX("trk2 phi resolution (rad)"); - h1109.setLineColor(2); - h1109.setFillColor(32); - - H1F h1112 = new H1F("trk1 Delta x", 50, -0.05, 0.05); - h1112.setOptStat(0); - h1112.setTitleX("trk1 Delta x"); - h1112.setLineColor(6); - h1112.setFillColor(6); - H1F h1113 = new H1F("trk2 Delta x", 50, -0.05, 0.05); - h1113.setOptStat(0); - h1113.setTitleX("trk2 Delta x"); - h1113.setLineColor(6); - h1113.setFillColor(36); - H1F h1114 = new H1F("trk1 Delta y", 50, -0.1, 0.1); - h1114.setOptStat(0); - h1114.setTitleX("trk1 Delta y"); - h1114.setLineColor(6); - h1114.setFillColor(6); - H1F h1115 = new H1F("trk2 Delta y", 50, -0.1, 0.1); - h1115.setOptStat(0); - h1115.setTitleX("trk2 Delta y"); - h1115.setLineColor(6); - h1115.setFillColor(36); - - // Montecarlo radiography - H2F h2000 = new H2F("Montecarlo radiography at first FTTRK det", 100, -15., 15., 100, -15, 15.); - h2000.setTitleX("x (mm)"); - h2000.setTitleY("y (mm)"); - H2F h2001 = new H2F("Montecarlo radiography at second FTTRK det", 100, -15., 15., 100, -15, 15.); - h2001.setTitleX("x (mm)"); - h2001.setTitleY("y (mm)"); - - JFrame frameCALTRK = new JFrame("radiography FTCAL hits and FTTRK Crosses"); - frameCALTRK.setSize(1500,500); - EmbeddedCanvas canvasCALTRK = new EmbeddedCanvas(); - canvasCALTRK.divide(3,1); - - int nev = 0; - int nevWithCrosses = 0, ncrosses2 = 0, nOfFTParticles = 0; - int TRK1 = DetectorLayer.FTTRK_MODULE1 - 1; - int TRK2 = DetectorLayer.FTTRK_MODULE2 - 1; - while (reader.hasEvent()) { // run over all events -// int nev1 = 0; int nev2 = 10000; for(nev=nev1; nev-1) System.out.println("////////////// event read " + bankEvt + " - sequential number " + nev); - //if(nev > 10239) System.exit(0); if(nev != 10239) continue; // stop at a given evt number - cal.processDataEvent(event); - hodo.processDataEvent(event); - trk.processDataEventAndGetClusters(event); - en.processDataEvent(event); - if(!event.hasBank("FTCAL::hits")) continue; - if (event instanceof EvioDataEvent) { - GenericKinematicFitter fitter = new GenericKinematicFitter(11); - PhysicsEvent gen = fitter.getGeneratedEvent((EvioDataEvent) event); - if (event.hasBank("FTRec::tracks")) { - DataBank bank = event.getBank("FTRec::tracks"); - int nrows = bank.rows(); - for (int i = 0; i < nrows; i++) { - h1.fill(bank.getDouble("Energy", i)); - Vector3D part = new Vector3D(bank.getDouble("Cx", i), bank.getDouble("Cy", i), bank.getDouble("Cz", i)); - h5.fill(bank.getDouble("Time", i)); - if(gen.countGenerated() != 0){ - h2.fill(bank.getDouble("Energy", i) - gen.getParticle("[11]").vector().p()); - h3.fill(Math.toDegrees(part.theta() - gen.getParticle("[11]").theta())); - h4.fill(Math.toDegrees(part.phi() - gen.getParticle("[11]").phi())); - h6.fill(bank.getDouble("Energy", i), bank.getDouble("Energy", i) - gen.getParticle("[11]").vector().p()); - } - } - } - } else { - DetectorEvent detectorEvent = DetectorData.readDetectorEvent(event); - PhysicsEvent gen = detectorEvent.getGeneratedEvent(); - if (event.hasBank("FT::particles")) { - DataBank bank = event.getBank("FT::particles"); - int nrows = bank.rows(); - if(nrows>0) nOfFTParticles++; - for (int i = 0; i < nrows; i++) { - int calId = bank.getShort("calID",i); - if(bank.getByte("charge", i)==-1 && bank.getShort("calID",i)>0) { - // track candidate through calorimeter - h1.fill(bank.getFloat("energy", i)); - Vector3D part = new Vector3D(bank.getFloat("cx", i), bank.getFloat("cy", i), bank.getFloat("cz", i)); - h5.fill(bank.getFloat("time", i) - 124.25); // simulation - h7.fill((bank.getFloat("cx", i) * FTCALConstantsLoader.CRYS_ZPOS)/10., (bank.getFloat("cy", i) * FTCALConstantsLoader.CRYS_ZPOS)/10.); - if(gen.countGenerated() != 0){ - h2.fill(bank.getFloat("energy", i) - gen.getGeneratedParticle(0).vector().p()); - h3.fill(gen.getGeneratedParticle(0).vector().p(),Math.toDegrees(part.theta() - gen.getGeneratedParticle(0).theta())); - h4.fill(gen.getGeneratedParticle(0).vector().p(),Math.toDegrees(part.phi() - gen.getGeneratedParticle(0).phi())); - h6.fill(bank.getFloat("cx", i) * FTCALConstantsLoader.CRYS_ZPOS, bank.getFloat("cy", i) * FTCALConstantsLoader.CRYS_ZPOS, bank.getFloat("energy", i) - gen.getGeneratedParticle(0).vector().p()); - h8.fill(gen.getGeneratedParticle(0).vector().p(), bank.getFloat("energy", i) - gen.getGeneratedParticle(0).vector().p()); - h9.fill(Math.toDegrees(gen.getGeneratedParticle(0).theta()), bank.getFloat("energy", i) - gen.getGeneratedParticle(0).vector().p()); - h10.fill(Math.toDegrees(gen.getGeneratedParticle(0).phi()), bank.getFloat("energy", i) - gen.getGeneratedParticle(0).vector().p()); - } - - // check match with trk bank (entry trkID) -// int trkID = bank.getShort("trkID", i); - int trk0ID = bank.getShort("trk0ID", i); // it should correspond to the number of the cross in the banks - int trk1ID = bank.getShort("trk1ID", i); - if(trk0ID >= 0 || trk1ID >= 0){ // at least one cross is present on one TRK det - // loop on crosses bank - DataBank banktrk = event.getBank("FTTRK::crosses"); - int ncrosses = banktrk.rows(); - // how many matched crosses are associated to a given track? - int matchedCrosses = 0; - for(int nc=0; nc0) System.out.println("++++++++++++++++++++++++++ Sequential number " + nev); - } - - for(int nc = 0; nc < ncrosses; nc++){ - int crossID = banktrk.getInt("id", nc); - if(crossID != trk0ID && crossID != trk1ID) continue; - int det = banktrk.getInt("detector", nc); - if(debugMode>0) System.out.println("trk0ID " + trk0ID + " trk1ID " + trk1ID + - " crossID " + crossID); - - if(det>=0){ - float xt = banktrk.getFloat("x", nc); - float yt = banktrk.getFloat("y", nc); - float zt = banktrk.getFloat("z", nc); - Vector3D hitOnTrk = new Vector3D(xt, yt, zt); - // extract information on the crossed strips - float icl1 = banktrk.getShort("Cluster1ID", nc); - float icl2 = banktrk.getShort("Cluster2ID", nc); - DataBank bankcl = event.getBank("FTTRK::clusters"); - // which is the correct location in the cluster bank for the cluster with the given id? - int icl1ok = -1; - int icl2ok = -1; - for(int k=0; k0){ - segment1.setOrigin(0.,0.); segment1.setEnd(0.,0.); - segment2.setOrigin(0.,0.); segment2.setEnd(0.,0.); - seed1 = bankcl.getInt("seed", (int)icl1ok); - seed2 = bankcl.getInt("seed", (int)icl2ok); - int cent1 = (int)bankcl.getFloat("centroid", icl1ok); - int cent2 = (int)bankcl.getFloat("centroid", icl2ok); - // if the cluster is formed by >= 3 strips take the centroid - int clustsize1 = bankcl.getShort("size", icl1ok); - int clustsize2 = bankcl.getShort("size", icl2ok); - if(clustsize1>=FTConstants.TRK_MIN_CLUSTER_SIZE_CENTROID){ - int sector = FTTRKReconstruction.findSector(seed1); - if(!(sector == 0 || sector == 1 || sector == 18 || sector == 19)) seed1 = cent1; - } - if(clustsize2>=FTConstants.TRK_MIN_CLUSTER_SIZE_CENTROID){ - int sector = FTTRKReconstruction.findSector(seed2); - if(!(sector == 0 || sector == 1 || sector == 18 || sector == 19)) seed2 = cent2; - } - int lay1 = bankcl.getInt("layer", (int)icl1ok); - int lay2 = bankcl.getInt("layer", (int)icl2ok); - if(debugMode>0){ - System.out.println("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ seed1, seed2 " + - seed1 + " " + seed2 + " layer1 layer2 " + lay1 + " " + lay2); - System.out.println("~~~~~~~~~~ hit strip 1: " + seed1 + " layer " + lay1 + " sector " + - FTTRKReconstruction.findSector(seed1)); - System.out.println("~~~~~~~~~~ hit strip 2: " + seed2 + " layer " + lay2 + " sector " + - FTTRKReconstruction.findSector(seed2)); - } - if(seed1!=0 && seed2!=0){ - Line3D seg1 = (Line3D) FTTRKConstantsLoader.getStripSegmentLab(lay1, seed1); - Line3D seg2 = (Line3D) FTTRKConstantsLoader.getStripSegmentLab(lay2, seed2); - segment1.setOrigin(seg1.origin().x(), seg1.origin().y()); - segment2.setOrigin(seg2.origin().x(), seg2.origin().y()); - segment1.setEnd(seg1.end().x(), seg1.end().y()); - segment2.setEnd(seg2.end().x(), seg2.end().y()); - - } - } - - if(det==TRK1 && trk0ID==crossID){ - h100.fill(xt, yt); - if(debugMode>0){ - System.out.println("coordinates of track on fttrk " + bank.getFloat("cx", i)*zt + " " + - bank.getFloat("cy", i)*zt + " " + bank.getFloat("cz", i)*zt); - System.out.println("director cosines hit on calorimeter " + part.x() + " " + part.y() + " " + part.z()); - System.out.println("director cosines hit of fttrk " + xt + " " + yt + " " + zt); - } - h102.fill(bank.getFloat("cx", i) *zt - xt); - h104.fill(bank.getFloat("cy", i) *zt - yt); - h106.fill((part.theta() - hitOnTrk.theta())); - h108.fill((part.phi() - hitOnTrk.phi())); - int sec1 = FTTRKReconstruction.findSector(seed1); - int sec2 = FTTRKReconstruction.findSector(seed2); - if(debugMode>0){ - System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> " + sec1 + "-" + sec2 + - " bad seeds d0, event " + nev); - } - canvasCALTRK.cd(0); - segment1.setLineColor(1); - segment2.setLineColor(2); - canvasCALTRK.draw(segment1); - canvasCALTRK.draw(segment2); - - }else if(det==TRK2 && trk1ID==crossID){ - h101.fill(xt, yt); - h103.fill(bank.getFloat("cx", i) *zt - xt); - h105.fill(bank.getFloat("cy", i) *zt - yt); - h107.fill((part.theta() - hitOnTrk.theta())); - h109.fill((part.phi() - hitOnTrk.phi())); - int sec1 = FTTRKReconstruction.findSector(seed1); - int sec2 = FTTRKReconstruction.findSector(seed2); - if(debugMode>0){ - System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> " + sec1 + "-" + sec2 + - " bad seeds d1, event " + nev); - } - canvasCALTRK.cd(1); - segment1.setLineColor(3); - segment2.setLineColor(4); - canvasCALTRK.draw(segment1); - canvasCALTRK.draw(segment2); - } - - } - } - - if(ncrosses==2){ - float x0 = banktrk.getFloat("x", 0); - float y0 = banktrk.getFloat("y", 0); - float x1 = banktrk.getFloat("x", 1); - float y1 = banktrk.getFloat("y", 1); - - Point3D c0 = new Point3D(x0, y0, banktrk.getFloat("z",0)); - Point3D c1 = new Point3D(x1, y1, banktrk.getFloat("z",1)); - Line3D lineBwCrosses = new Line3D(c1, c0); - if(debugMode>0){ - System.out.println("x coordinates on 2 layers " + x0 + " " + x1); - System.out.println("director cosines straight line bw crosses, cx " + lineBwCrosses.originDir().x() + " cy " + - lineBwCrosses.originDir().y() + " cz " + lineBwCrosses.originDir().z()); - } - } - } - } - } - } - - if(event.hasBank("FTTRK::crosses")){ - nevWithCrosses++; - DataBank banktrk = event.getBank("FTTRK::crosses"); - int nrows = banktrk.rows(); - - // comparison with MC data - // how many particles have been generated? - int ipart = gen.countGenerated(); - for(int ip=0; ip0) System.out.println("------- generated particle n " + ip + " type: " + gen.getGeneratedParticle(ip).pid() + " mass " + mass); - double P = gen.getGeneratedParticle(ip).p(); - double cx = gen.getGeneratedParticle(ip).px()/P; - double cy = gen.getGeneratedParticle(ip).py()/P; - double cz = gen.getGeneratedParticle(ip).pz()/P; - double Pz = P*cz; - double Pperp = P*Math.sqrt(cx*cx+cy*cy); - double x0 = gen.getGeneratedParticle(ip).vx(); - double y0 = gen.getGeneratedParticle(ip).vy(); - double z0 = gen.getGeneratedParticle(ip).vz(); - double q = Math.abs(gen.getGeneratedParticle(ip).charge()); // negative particles bend upwards - for (int i = 0; i < nrows; i++) { - int det = banktrk.getInt("detector", i); - double xt = banktrk.getFloat("x", i); - double yt = banktrk.getFloat("y", i); - double zt = banktrk.getFloat("z", i); - - if(debugMode>0){ - System.out.println("MC: x0 = " + x0 + " y0 " + y0 + " z0 " + z0); - System.out.println("MC cosines: cx = " + cx + " cy " + cy + " cz " + cz); - System.out.println("trk: xt = " + xt + " yt " + yt + " zt " + zt); - } - double t = (zt - z0)/cz; - Vector3D hitOnTrk = new Vector3D(xt, yt, zt); - Vector3D hitMCOnTrk = new Vector3D(x0+cx*t, y0+cy*t, zt); // straight line - - if(debugMode>0) System.out.println("MC on the straight line x = " + hitMCOnTrk.x() + " y = " + hitMCOnTrk.y() + - " z = " + hitMCOnTrk.z()); - // if the magnetic field is on, the coordinates must be swum along a helix - double B = en.getSolenoid(); - if(B!=0.){ - // find the crossing point of the helix and a xy plane at given z, where the magneti field stops - double zStop = 100.0; // PROVISIONAL fixed to 1 meter - double phi0 = Math.atan2(cy,cx); - double R = Pperp/0.3/B/q*1.e2; // R in cm - double dAlpha = (zStop-z0)*(B*q*0.3)/Pz*1.e-2; // deltaZ in meters - int nturns = (int) Math.floor(dAlpha/2./Math.PI); // number of full turns - if(dAlpha>0){ - dAlpha -= nturns*2.*Math.PI; - }else{ - dAlpha += nturns*2.*Math.PI; - } - - double xc = R*Math.sin(phi0); - double yc = R*Math.cos(phi0); - Vector3D hitOnPlane = new Vector3D(); - Vector3D tangentAtZstop = new Vector3D(); - if(R*dAlpha>0){ - hitOnPlane.setX(-xc + R*(Math.sin(phi0 + dAlpha))); - hitOnPlane.setY( yc - R*(Math.cos(phi0 + dAlpha))); - hitOnPlane.setZ(zStop); - double gamma = Math.atan2(hitOnPlane.y(),hitOnPlane.x()); - double vx1 = Pperp/P*Math.sin(gamma); - double vy1 = Pperp/P*Math.cos(gamma); - double vz1 = Math.sqrt(1. - vx1*vx1 + vy1*vy1); - double t1 = (zt - hitOnPlane.z())/vz1; - hitMCOnTrk.setXYZ(hitOnPlane.x()+vx1*t1, hitOnPlane.y()+vy1*t1, zt); - }else{ - if(debugMode>0) System.out.println("check particle/curvature signs"); - } - } - if(debugMode>0) System.out.println("MC after swimming in mag field x = " + hitMCOnTrk.x() + " y = " + hitMCOnTrk.y() + - " z = " + hitMCOnTrk.z()); - - // Montecarlo hit location on first detector middle plane - if(det==TRK1) h2000.fill(hitMCOnTrk.x(), hitMCOnTrk.y()); - if(det==TRK2) h2001.fill(hitMCOnTrk.x(), hitMCOnTrk.y()); - if(det==TRK1){ - h1100.fill(hitOnTrk.x(), hitOnTrk.y()); - h1102.fill(hitMCOnTrk.x() - hitOnTrk.x()); - h1104.fill(hitMCOnTrk.y() - hitOnTrk.y()); - h1106.fill((hitMCOnTrk.theta() - hitOnTrk.theta())); - h1108.fill((hitMCOnTrk.phi() - hitOnTrk.phi())); - h1112.fill((hitMCOnTrk.x() - hitOnTrk.x())/hitMCOnTrk.x()); - h1114.fill((hitMCOnTrk.y() - hitOnTrk.y())/hitMCOnTrk.y()); - h202.fill(hitOnTrk.x()); - h1202.fill(hitMCOnTrk.x()); - h204.fill(hitOnTrk.y()); - h1204.fill(hitMCOnTrk.y()); - }else if(det==TRK2){ - h1101.fill(hitOnTrk.x(), hitOnTrk.y()); - h1103.fill(hitMCOnTrk.x() - hitOnTrk.x()); - h1105.fill(hitMCOnTrk.y() - hitOnTrk.y()); - h1107.fill((hitMCOnTrk.theta() - hitOnTrk.theta())); - h1109.fill((hitMCOnTrk.phi() - hitOnTrk.phi())); - - h1113.fill((hitMCOnTrk.x() - hitOnTrk.x())/hitMCOnTrk.x()); - h1115.fill((hitMCOnTrk.y() - hitOnTrk.y())/hitMCOnTrk.y()); - - h203.fill(hitOnTrk.x()); - h1203.fill(hitMCOnTrk.x()); - h205.fill(hitOnTrk.y()); - h1205.fill(hitMCOnTrk.y()); - } - if(debugMode>0){ - System.out.println("MC hit coordinates " + hitMCOnTrk.x() + " " + hitMCOnTrk.y() + " " + hitMCOnTrk.z()); - System.out.println("MC theta " + hitMCOnTrk.theta() + " hit on trk " + hitOnTrk.theta()); - System.out.println("MC phi " + hitMCOnTrk.phi() + " hit on trk " + hitOnTrk.phi()); - System.out.println("trk hit coordinates " + hitOnTrk.x() + " " + hitOnTrk.y() + " " + hitOnTrk.z()); - } - } - } // end MC comparison - } // end loop on crosses - } - } - - if(debugMode>=-1) // print always - System.out.println("@@@@@@@@@@@@@ total number of events read " + nev + " @@@@@ total number of events with rec cross in FTTRK " - + nevWithCrosses + " @@@@ number of reconstructed FTParticles " + nOfFTParticles); - - double narrowFactor = 7.5; // was 4.5 - JFrame frametrk = new JFrame("FTTRK Reconstruction with respect to FTCAL tracking"); - frametrk.setSize(1600, 800); - EmbeddedCanvas canvastrk = new EmbeddedCanvas(); - canvastrk.divide(5, 2); - canvastrk.cd(0); - canvastrk.draw(h100); - canvastrk.cd(1); - canvastrk.draw(h102); - F1D f02 = new F1D("f02","[amp]*gaus(x,[mean],[sigma])", -limTC/narrowFactor, limTC/narrowFactor); - f02.setParameter(0, 10.0); - f02.setParameter(1, 0.0); - f02.setParameter(2, 1.0); - f02.setLineColor(6); - f02.setLineWidth(3); - DataFitter.fit(f02, h102, "Q"); //No options uses error for sigma - f02.setParameter(0, f02.parameter(0).value()); - f02.setParameter(1, f02.parameter(1).value()); - f02.setParameter(2, f02.parameter(2).value()); - DataFitter.fit(f02, h102, "Q"); //No options uses error for sigma - f02.setOptStat(11111); - canvastrk.draw(f02,"same"); - canvastrk.cd(2); - canvastrk.draw(h104); - F1D f04 = new F1D("f04","[amp]*gaus(x,[mean],[sigma])", -limTC/narrowFactor, limTC/(narrowFactor)); - f04.setParameter(0, h104.getMax()); - f04.setParameter(1, h104.getMean()); - f04.setParameter(2, h104.getRMS()/2.); - f04.setLineColor(6); - f04.setLineWidth(3); - DataFitter.fit(f04, h104, "Q"); //No options uses error for sigma - f04.setParameter(0, f04.parameter(0).value()); - f04.setParameter(1, f04.parameter(1).value()); - f04.setParameter(2, f04.parameter(2).value()); - DataFitter.fit(f04, h104, "Q"); //No options uses error for sigma - f04.setOptStat(11111); - canvastrk.draw(f04,"same"); - canvastrk.cd(3); - canvastrk.draw(h106); - F1D f06 = new F1D("f06","[amp]*gaus(x,[mean],[sigma])", -limTCTheta/narrowFactor, limTCTheta/narrowFactor); - f06.setParameter(0, 10.0); - f06.setParameter(1, h106.getMean()); - f06.setParameter(2, h106.getRMS()); - f06.setLineColor(6); - f06.setLineWidth(3); - DataFitter.fit(f06, h106, "Q"); //No options uses error for sigma - f06.setParameter(0, f06.parameter(0).value()); - f06.setParameter(1, f06.parameter(1).value()); - f06.setParameter(2, f06.parameter(2).value()); - DataFitter.fit(f06, h106, "Q"); //No options uses error for sigma - f06.setOptStat(11111); - canvastrk.draw(f06,"same"); - canvastrk.cd(4); - canvastrk.draw(h108); - F1D f08 = new F1D("f08","[amp]*gaus(x,[mean],[sigma])", -limTCPhi/narrowFactor, limTCPhi/narrowFactor); - f08.setParameter(0, h108.getMax()); - f08.setParameter(1, h108.getMean()); - f08.setParameter(2, h108.getRMS()); - f08.setLineColor(6); - f08.setLineWidth(3); - DataFitter.fit(f08, h108, "Q"); //No options uses error for sigma - f08.setOptStat(11111); - canvastrk.draw(f08,"same"); - - canvastrk.cd(5); - canvastrk.draw(h101); - - canvastrk.cd(6); - canvastrk.draw(h103); - F1D f03 = new F1D("f03","[amp]*gaus(x,[mean],[sigma])", -limTC/narrowFactor, limTC/narrowFactor); - f03.setParameter(0, 10.0); - f03.setParameter(1, 0.0); - f03.setParameter(2, 1.0); - f03.setLineColor(6); - f03.setLineWidth(3); - DataFitter.fit(f03, h103, "Q"); //No options uses error for sigma - f03.setParameter(0, f03.parameter(0).value()); - f03.setParameter(1, f03.parameter(1).value()); - f03.setParameter(2, f03.parameter(2).value()); - DataFitter.fit(f03, h103, "Q"); //No options uses error for sigma - f03.setOptStat(1111); - canvastrk.draw(f03,"same"); - - - canvastrk.cd(7); - canvastrk.draw(h105); - F1D f05 = new F1D("f05","[amp]*gaus(x,[mean],[sigma])", -limTC/narrowFactor, limTC/narrowFactor); - f05.setParameter(0, 10.0); - f05.setParameter(1, 0.0); - f05.setParameter(2, 1.0); - f05.setLineColor(6); - f05.setLineWidth(3); - DataFitter.fit(f05, h105, "Q"); //No options uses error for sigma - f05.setParameter(0, f05.parameter(0).value()); - f05.setParameter(1, f05.parameter(1).value()); - f05.setParameter(2, f05.parameter(2).value()); - DataFitter.fit(f05, h105, "Q"); //No options uses error for sigma - f05.setOptStat(1111); - canvastrk.draw(f05,"same"); - - canvastrk.cd(8); - canvastrk.draw(h107); - F1D f07 = new F1D("f07","[amp]*gaus(x,[mean],[sigma])", -limTCTheta/narrowFactor, limTCTheta/narrowFactor); - f07.setParameter(0, h107.getMax()); - f07.setParameter(1, h107.getMean()); - f07.setParameter(2, h107.getRMS()); - f07.setLineColor(6); - f07.setLineWidth(3); - DataFitter.fit(f07, h107, "Q"); //No options uses error for sigma - f07.setOptStat(1111); - canvastrk.draw(f07,"same"); - - canvastrk.cd(9); - canvastrk.draw(h109); - F1D f09 = new F1D("f09","[amp]*gaus(x,[mean],[sigma])", -limTCPhi/narrowFactor, limTCPhi/narrowFactor); - f09.setParameter(0, h109.getMax()); - f09.setParameter(1, h109.getMean()); - f09.setParameter(2, h109.getRMS()); - f09.setLineColor(6); - f09.setLineWidth(3); - DataFitter.fit(f09, h109, "Q"); //No options uses error for sigma - f09.setParameter(0, f09.parameter(0).value()); - f09.setParameter(1, f09.parameter(1).value()); - f09.setParameter(2, f09.parameter(2).value()); - DataFitter.fit(f09, h109, "Q"); //No options uses error for sigma - f09.setOptStat(1111); - canvastrk.draw(f09,"same"); - frametrk.add(canvastrk); - frametrk.setLocationRelativeTo(null); - frametrk.setVisible(true); - - JFrame frametrkres = new JFrame("FTTRK Resolutions wrt MC generated events"); - frametrkres.setSize(1800, 800); - EmbeddedCanvas canvastrkres = new EmbeddedCanvas(); - canvastrkres.divide(7, 2); - int ii = 0; - canvastrkres.cd(ii); - canvastrkres.draw(h1100); - canvastrkres.cd(++ii); - canvastrkres.draw(h1102); - F1D f1 = new F1D("f1","[amp]*gaus(x,[mean],[sigma])", -0.25, 0.25); - f1.setParameter(0, h1102.getMax()); - f1.setParameter(1, h1102.getMean()); - f1.setParameter(2, h1102.getRMS()); - f1.setLineColor(4); - f1.setLineWidth(3); - DataFitter.fit(f1, h1102, "Q"); //No options uses error for sigma - f1.setParameter(0, f1.parameter(0).value()); - f1.setParameter(1, f1.parameter(1).value()); - f1.setParameter(2, f1.parameter(2).value()); - DataFitter.fit(f1, h1102, "Q"); //No options uses error for sigma - f1.setOptStat(1111); - canvastrkres.draw(f1,"same"); - if(debugMode>0) System.out.println(" mean = " + f1.parameter(1).value() - + " sigma = " + f1.parameter(2).value()); - canvastrkres.cd(++ii); - canvastrkres.draw(h1104); - F1D f2 = new F1D("f2","[amp]*gaus(x,[mean],[sigma])", -0.25, 0.25); - f2.setParameter(0, f1.parameter(0).value()); - f2.setParameter(1, f1.parameter(1).value()); - f2.setParameter(2, f1.parameter(2).value()); - f2.setLineColor(24); - f2.setLineWidth(3); - DataFitter.fit(f2, h1104, "Q"); //No options uses error for sigma - f2.setOptStat(1111); - canvastrkres.draw(f2,"same"); - if(debugMode>0) System.out.println(" mean = " + f2.parameter(1).value() - + " sigma = " + f2.parameter(2).error()); - canvastrkres.cd(++ii); - canvastrkres.draw(h1106); - F1D f6 = new F1D("f6","[amp]*gaus(x,[mean],[sigma])", -0.001, 0.001); - f6.setParameter(0, f1.parameter(0).value()); - f6.setParameter(1, h1106.getMean()); - f6.setParameter(2, h1106.getRMS()); - f6.setLineColor(24); - f6.setLineWidth(3); - DataFitter.fit(f6, h1106, "Q"); //No options uses error for sigma - f6.setOptStat(1111); - canvastrkres.draw(f6,"same"); - - canvastrkres.cd(++ii); - canvastrkres.draw(h1108); - F1D f8 = new F1D("f8","[amp]*gaus(x,[mean],[sigma])", -0.005, 0.005); - f8.setParameter(0, h1108.getMax()); - f8.setParameter(1, h1108.getMean()); - f8.setParameter(2, h1108.getRMS()/2); - f8.setLineColor(24); - f8.setLineWidth(3); - DataFitter.fit(f8, h1108, "Q"); //No options uses error for sigma - f8.setOptStat(1111); - canvastrkres.draw(f8,"same"); - canvastrkres.cd(++ii); - canvastrkres.draw(h1112); - F1D f12 = new F1D("f12","[amp]*gaus(x,[mean],[sigma])", -0.05, 0.05); - f12.setParameter(0, f1.parameter(0).value()); - f12.setParameter(1, h1112.getMean()); - f12.setParameter(2, h1112.getRMS()); - f12.setLineColor(24); - f12.setLineWidth(3); - DataFitter.fit(f12, h1112, "Q"); //No options uses error for sigma - f12.setOptStat(1111); - canvastrkres.draw(f12,"same"); - - canvastrkres.cd(++ii); - canvastrkres.draw(h1114); - F1D f14 = new F1D("f14","[amp]*gaus(x,[mean],[sigma])", -0.1, 0.1); - f14.setParameter(0, f1.parameter(0).value()); - f14.setParameter(1, h1114.getMean()); - f14.setParameter(2, h1114.getRMS()); - f14.setLineColor(24); - f14.setLineWidth(3); - DataFitter.fit(f14, h1114, "Q"); //No options uses error for sigma - f14.setOptStat(1111); - canvastrkres.draw(f14,"same"); - - canvastrkres.cd(++ii); - canvastrkres.draw(h1101); - canvastrkres.cd(++ii); - canvastrkres.draw(h1103); - F1D f3 = new F1D("f3","[amp]*gaus(x,[mean],[sigma])", -0.25, 0.25); - f3.setParameter(0, f1.parameter(0).value()); - f3.setParameter(1, f1.parameter(1).value()); - f3.setParameter(2, f1.parameter(2).value()); - f3.setLineColor(34); - f3.setLineWidth(3); - DataFitter.fit(f3, h1103, "Q"); //No options uses error for sigma - f3.setOptStat(1111); - canvastrkres.draw(f3,"same"); - if(debugMode>0) System.out.println(" mean = " + f3.parameter(1).value() - + " sigma = " + f3.parameter(2).error()); - canvastrkres.cd(++ii); - canvastrkres.draw(h1105); - F1D f4 = new F1D("f4","[amp]*gaus(x,[mean],[sigma])", -0.25, 0.25); - f4.setParameter(0, f1.parameter(0).value()); - f4.setParameter(1, f1.parameter(1).value()); - f4.setParameter(2, f1.parameter(2).value()); - f4.setLineColor(44); - f4.setLineWidth(3); - DataFitter.fit(f4, h1105, "Q"); //No options uses error for sigma - f4.setOptStat(1111); - canvastrkres.draw(f4,"same"); - if(debugMode>0) System.out.println(" mean = " + f4.parameter(1).value() - + " sigma = " + f4.parameter(2).error()); - canvastrkres.cd(++ii); - canvastrkres.draw(h1107); - F1D f17 = new F1D("f17","[amp]*gaus(x,[mean],[sigma])", -0.001, 0.001); - f17.setParameter(0, h1107.getMax()); - f17.setParameter(1, h1107.getMean()); - f17.setParameter(2, h1107.getRMS()); - f17.setLineColor(24); - f17.setLineWidth(3); - DataFitter.fit(f17, h1107, "Q"); //No options uses error for sigma - f17.setOptStat(1111); - canvastrkres.draw(f17,"same"); - canvastrkres.cd(++ii); - canvastrkres.draw(h1109); - F1D f19 = new F1D("f19","[amp]*gaus(x,[mean],[sigma])", -0.002, 0.002); - f19.setParameter(0, h1109.getMax()); - f19.setParameter(1, h1109.getMean()); - f19.setParameter(2, h1109.getRMS()); - f19.setLineColor(24); - f19.setLineWidth(3); - DataFitter.fit(f19, h1109, "Q"); //No options uses error for sigma - f19.setOptStat(1111); - canvastrkres.draw(f19,"same"); - - canvastrkres.cd(++ii); - canvastrkres.draw(h1113); - F1D f13 = new F1D("f13","[amp]*gaus(x,[mean],[sigma])", -0.05, 0.05); - f13.setParameter(0, f1.parameter(0).value()); - f13.setParameter(1, h1113.getMean()); - f13.setParameter(2, h1113.getRMS()); - f13.setLineColor(24); - f13.setLineWidth(3); - DataFitter.fit(f13, h1113, "Q"); //No options uses error for sigma - f13.setOptStat(1111); - canvastrkres.draw(f13,"same"); - - canvastrkres.cd(++ii); - canvastrkres.draw(h1115); - F1D f15 = new F1D("f15","[amp]*gaus(x,[mean],[sigma])", -0.1, 0.1); - f15.setParameter(0, f1.parameter(0).value()); - f15.setParameter(1, h1115.getMean()); - f15.setParameter(2, h1115.getRMS()); - f15.setLineColor(24); - f15.setLineWidth(3); - DataFitter.fit(f15, h1115, "Q"); //No options uses error for sigma - f15.setOptStat(1111); - canvastrkres.draw(f15,"same"); - - frametrkres.add(canvastrkres); - frametrkres.setLocationRelativeTo(null); - frametrkres.setVisible(true); - - canvasCALTRK.cd(0); canvasCALTRK.draw(h100, "same"); canvasCALTRK.draw(h7, "same"); - canvasCALTRK.cd(1); canvasCALTRK.draw(h101, "same"); canvasCALTRK.draw(h7, "same"); - canvasCALTRK.cd(2); canvasCALTRK.draw(h7, "same"); - frameCALTRK.add(canvasCALTRK); - frameCALTRK.setLocationRelativeTo(null); - frameCALTRK.setVisible(true); - - } } diff --git a/reconstruction/ft/src/main/java/org/jlab/rec/ft/cal/FTCALEngine.java b/reconstruction/ft/src/main/java/org/jlab/rec/ft/cal/FTCALEngine.java index cf41a2ef5b..eb9bc1cdfa 100644 --- a/reconstruction/ft/src/main/java/org/jlab/rec/ft/cal/FTCALEngine.java +++ b/reconstruction/ft/src/main/java/org/jlab/rec/ft/cal/FTCALEngine.java @@ -6,8 +6,6 @@ import javax.swing.JFrame; import org.jlab.clas.detector.DetectorData; import org.jlab.clas.detector.DetectorEvent; -import org.jlab.clas.physics.GenericKinematicFitter; -import org.jlab.clas.physics.PhysicsEvent; import org.jlab.clas.reco.ReconstructionEngine; import org.jlab.geom.prim.Vector3D; import org.jlab.groot.data.H1F; @@ -22,57 +20,57 @@ public class FTCALEngine extends ReconstructionEngine { - public FTCALEngine() { - super("FTCAL", "devita", "3.0"); - } - - FTCALReconstruction reco; - - @Override - public boolean init() { - reco = new FTCALReconstruction(); - reco.debugMode=0; - - String[] tables = new String[]{ - "/calibration/ft/ftcal/charge_to_energy", - "/calibration/ft/ftcal/time_offsets", - "/calibration/ft/ftcal/time_walk", - "/calibration/ft/ftcal/status", - "/calibration/ft/ftcal/thresholds", - "/calibration/ft/ftcal/cluster", - "/calibration/ft/ftcal/energycorr" - }; - requireConstants(Arrays.asList(tables)); - this.getConstantsManager().setVariation("default"); + public FTCALEngine() { + super("FTCAL", "devita", "3.0"); + } - this.registerOutputBank("FTCAL::hits","FTCAL::clusters"); - - return true; - } + FTCALReconstruction reco; + + @Override + public boolean init() { + reco = new FTCALReconstruction(); + reco.debugMode=0; + + String[] tables = new String[]{ + "/calibration/ft/ftcal/charge_to_energy", + "/calibration/ft/ftcal/time_offsets", + "/calibration/ft/ftcal/time_walk", + "/calibration/ft/ftcal/status", + "/calibration/ft/ftcal/thresholds", + "/calibration/ft/ftcal/cluster", + "/calibration/ft/ftcal/energycorr" + }; + requireConstants(Arrays.asList(tables)); + this.getConstantsManager().setVariation("default"); + + this.registerOutputBank("FTCAL::hits","FTCAL::clusters"); + + return true; + } - @Override - public boolean processDataEvent(DataEvent event) { - List allHits = new ArrayList(); - List selectedHits = new ArrayList(); - List clusters = new ArrayList(); + @Override + public boolean processDataEvent(DataEvent event) { + List allHits = new ArrayList(); + List selectedHits = new ArrayList(); + List clusters = new ArrayList(); - // update calibration constants based on run number if changed - int run = setRunConditionsParameters(event); - - if(run>=0) { - // get hits fron banks - allHits = reco.initFTCAL(event,this.getConstantsManager(), run); - // select good hits and order them by energy - selectedHits = reco.selectHits(allHits,this.getConstantsManager(), run); - // create clusters - clusters = reco.findClusters(selectedHits, this.getConstantsManager(), run); - // set cluster status - reco.selectClusters(clusters, this.getConstantsManager(), run); - // write output banks - reco.writeBanks(event, selectedHits, clusters, this.getConstantsManager(), run); - } - return true; - } + // update calibration constants based on run number if changed + int run = setRunConditionsParameters(event); + + if(run>=0) { + // get hits fron banks + allHits = reco.initFTCAL(event,this.getConstantsManager(), run); + // select good hits and order them by energy + selectedHits = reco.selectHits(allHits,this.getConstantsManager(), run); + // create clusters + clusters = reco.findClusters(selectedHits, this.getConstantsManager(), run); + // set cluster status + reco.selectClusters(clusters, this.getConstantsManager(), run); + // write output banks + reco.writeBanks(event, selectedHits, clusters, this.getConstantsManager(), run); + } + return true; + } public int setRunConditionsParameters(DataEvent event) { int run = -1; @@ -88,96 +86,7 @@ public int setRunConditionsParameters(DataEvent event) { DataBank bank = event.getBank("RUN::config"); run = bank.getInt("run",0); } - + return run; } - - - public static void main (String arg[]) { - FTCALEngine cal = new FTCALEngine(); - cal.init(); - // String input = "/Users/devita/Work/clas12/simulations/clas12Tags/4.4.0/out.hipo"; -// String input = "/home/filippi/clas/ForwardTracker/DATA/out_realGeo_noMagField.data"; -// String input = "/home/filippi/clas/gemc/electronGun/gemc.hipo"; - String input = "/home/filippi/clas12/fttrkDev/clas12-offline-software-6.5.13-fttrkDev/ft_005038.evio.01231.hipo"; - HipoDataSource reader = new HipoDataSource(); -// String input = "/Users/devita/Work/clas12/simulations/tests/detectors/clas12/ft/out_header.ev"; -// EvioSource reader = new EvioSource(); - reader.open(input); - - // initialize histos - H1F h1 = new H1F("Cluster Energy",100, 0.,5.); - h1.setOptStat(Integer.parseInt("1111")); h1.setTitleX("Cluster Energy (GeV)"); - H1F h2 = new H1F("Energy Resolution",100, -1, 1); - h2.setOptStat(Integer.parseInt("1111")); h2.setTitleX("Energy Resolution(GeV)"); - H1F h3 = new H1F("Theta Resolution",100, -2, 2); - h3.setOptStat(Integer.parseInt("1111")); h3.setTitleX("Theta Resolution(deg)"); - H1F h4 = new H1F("Phi Resolution",100, -10, 10); - h4.setOptStat(Integer.parseInt("1111")); h4.setTitleX("Phi Resolution(deg)"); -// H1F h5 = new H1F("Time Resolution",100, -10, 10); - H1F h5 = new H1F("Time Resolution",100, -100, 300); - h5.setOptStat(Integer.parseInt("1111")); h5.setTitleX("Time Resolution(ns)"); - H2F h6 = new H2F("cluster xy", 100, -15., 15., 100, -15., 15.); - h6.setTitleX("cluster x"); h6.setTitleY("cluster y"); - - while(reader.hasEvent()){ -// for(int nev=0; nev<2; nev++){ - DataEvent event = (DataEvent) reader.getNextEvent(); - cal.processDataEvent(event); - - if(event instanceof EvioDataEvent) { - GenericKinematicFitter fitter = new GenericKinematicFitter(11); - PhysicsEvent gen = fitter.getGeneratedEvent((EvioDataEvent)event); - if(event.hasBank("FTCALRec::clusters")) { - DataBank bank = event.getBank("FTCALRec::clusters"); - int nrows = bank.rows(); - for(int i=0; i-1) System.out.println("////////////// event read " + bankEvt + " - sequential number " + nev); - //if(nev > 10239) System.exit(0); if(nev != 10239) continue; // stop at a given evt number - cal.processDataEvent(event); - hodo.processDataEvent(event); - trk.processDataEventAndGetClusters(event); - en.processDataEvent(event); - if(!event.hasBank("FTCAL::hits")) continue; - if (event instanceof EvioDataEvent) { - GenericKinematicFitter fitter = new GenericKinematicFitter(11); - PhysicsEvent gen = fitter.getGeneratedEvent((EvioDataEvent) event); - if (event.hasBank("FTRec::tracks")) { - DataBank bank = event.getBank("FTRec::tracks"); - int nrows = bank.rows(); - for (int i = 0; i < nrows; i++) { - h1.fill(bank.getDouble("Energy", i)); - Vector3D part = new Vector3D(bank.getDouble("Cx", i), bank.getDouble("Cy", i), bank.getDouble("Cz", i)); - h5.fill(bank.getDouble("Time", i)); - if(gen.countGenerated() != 0){ - h2.fill(bank.getDouble("Energy", i) - gen.getParticle("[11]").vector().p()); - h3.fill(Math.toDegrees(part.theta() - gen.getParticle("[11]").theta())); - h4.fill(Math.toDegrees(part.phi() - gen.getParticle("[11]").phi())); - h6.fill(bank.getDouble("Energy", i), bank.getDouble("Energy", i) - gen.getParticle("[11]").vector().p()); - } - } - } - } else { - DetectorEvent detectorEvent = DetectorData.readDetectorEvent(event); - PhysicsEvent gen = detectorEvent.getGeneratedEvent(); - if (event.hasBank("FT::particles")) { - DataBank bank = event.getBank("FT::particles"); - int nrows = bank.rows(); - if(nrows>0) nOfFTParticles++; - for (int i = 0; i < nrows; i++) { - int calId = bank.getShort("calID",i); - if(bank.getByte("charge", i)==-1 && bank.getShort("calID",i)>0) { - // track candidate through calorimeter - h1.fill(bank.getFloat("energy", i)); - Vector3D part = new Vector3D(bank.getFloat("cx", i), bank.getFloat("cy", i), bank.getFloat("cz", i)); - h5.fill(bank.getFloat("time", i) - 124.25); // simulation - h7.fill((bank.getFloat("cx", i) * FTCALConstantsLoader.CRYS_ZPOS)/10., (bank.getFloat("cy", i) * FTCALConstantsLoader.CRYS_ZPOS)/10.); - if(gen.countGenerated() != 0){ - h2.fill(bank.getFloat("energy", i) - gen.getGeneratedParticle(0).vector().p()); - h3.fill(gen.getGeneratedParticle(0).vector().p(),Math.toDegrees(part.theta() - gen.getGeneratedParticle(0).theta())); - h4.fill(gen.getGeneratedParticle(0).vector().p(),Math.toDegrees(part.phi() - gen.getGeneratedParticle(0).phi())); - h6.fill(bank.getFloat("cx", i) * FTCALConstantsLoader.CRYS_ZPOS, bank.getFloat("cy", i) * FTCALConstantsLoader.CRYS_ZPOS, bank.getFloat("energy", i) - gen.getGeneratedParticle(0).vector().p()); - h8.fill(gen.getGeneratedParticle(0).vector().p(), bank.getFloat("energy", i) - gen.getGeneratedParticle(0).vector().p()); - h9.fill(Math.toDegrees(gen.getGeneratedParticle(0).theta()), bank.getFloat("energy", i) - gen.getGeneratedParticle(0).vector().p()); - h10.fill(Math.toDegrees(gen.getGeneratedParticle(0).phi()), bank.getFloat("energy", i) - gen.getGeneratedParticle(0).vector().p()); - } - - // check match with trk bank (entry trkID) -// int trkID = bank.getShort("trkID", i); - int trk1ID = bank.getShort("trk0ID", i); // it should correspond to the number of the cross in the banks - int trk2ID = bank.getShort("trk1ID", i); - if(trk1ID >= 0 || trk2ID >= 0){ // at least one cross is present on one TRK det - // loop on crosses bank - DataBank banktrk = event.getBank("FTTRK::crosses"); - int ncrosses = banktrk.rows(); - // how many matched crosses are associated to a given track? - int matchedCrosses = 0; - for(int nc=0; nc=1) System.out.println("time from TRK" + timeFromTRK + " to be compared to time from TRK" + - ptOnTRK.mag()/PhysicsConstants.speedOfLight()); - int icl1 = banktrk.getShort("Cluster1ID", nc); - int icl2 = banktrk.getShort("Cluster2ID", nc); - DataBank bankcl = event.getBank("FTTRK::clusters"); - int sizeCl1 = bankcl.getShort("size", icl1); - int sizeCl2 = bankcl.getShort("size", icl2); - float totEnergyCl1 = bankcl.getFloat("energy", icl1); - float totEnergyCl2 = bankcl.getFloat("energy", icl2); - if(crossID==TRK1){ - h503.fill(timeFromTRK); - h501.fill(energyFromTRK); - h505.fill(timeFromTRK, energyFromTRK); - h510.fill(totEnergyCl1, totEnergyCl2); - h512.fill(totEnergyCl1); - h512.fill(totEnergyCl2); - }else if(crossID==TRK2){ - h504.fill(timeFromTRK); - h502.fill(energyFromTRK); - h506.fill(timeFromTRK, energyFromTRK); - h511.fill(totEnergyCl1, totEnergyCl2); - h513.fill(totEnergyCl1); - h513.fill(totEnergyCl2); - } - } - } - -// if(matchedCrosses != 1){ -// if(matchedCrosses != 2){ - if(matchedCrosses < FTConstants.TRK_MIN_CROSS_NUMBER){ // at least TRK_MIN_CROSS_NUMBER per event - continue; - }else{ - ncrosses2++; - if(ncrosses<100 && debugMode>0) System.out.println("++++++++++++++++++++++++++ Sequential number " + nev); - } - - for(int nc = 0; nc < ncrosses; nc++){ - int crossID = banktrk.getInt("id", nc); - if(crossID != trk1ID && crossID != trk2ID) continue; - int det = banktrk.getInt("detector", nc); - if(debugMode>0) System.out.println("trk1ID " + trk1ID + " trk2ID " + trk2ID + - " crossID " + crossID); - - if(det>=0){ - float xt = banktrk.getFloat("x", nc); - float yt = banktrk.getFloat("y", nc); - float zt = banktrk.getFloat("z", nc); - Vector3D hitOnTrk = new Vector3D(xt, yt, zt); - // extract information on the crossed strips - float icl1 = banktrk.getShort("Cluster1ID", nc); - float icl2 = banktrk.getShort("Cluster2ID", nc); - DataBank bankcl = event.getBank("FTTRK::clusters"); - // which is the correct location in the cluster bank for the cluster with the given id? - int icl1ok = -1; - int icl2ok = -1; - for(int k=0; k0){ - segment1.setOrigin(0.,0.); segment1.setEnd(0.,0.); - segment2.setOrigin(0.,0.); segment2.setEnd(0.,0.); - seed1 = bankcl.getInt("seed", (int)icl1ok); - seed2 = bankcl.getInt("seed", (int)icl2ok); - int cent1 = (int)bankcl.getFloat("centroid", icl1ok); - int cent2 = (int)bankcl.getFloat("centroid", icl2ok); - // if the cluster is formed by >= 3 strips take the centroid - int clustsize1 = bankcl.getShort("size", icl1ok); - int clustsize2 = bankcl.getShort("size", icl2ok); - if(clustsize1>=FTConstants.TRK_MIN_CLUSTER_SIZE_CENTROID){ - int sector = FTTRKReconstruction.findSector(seed1); - if(!(sector == 0 || sector == 1 || sector == 18 || sector == 19)) seed1 = cent1; - } - if(clustsize2>=FTConstants.TRK_MIN_CLUSTER_SIZE_CENTROID){ - int sector = FTTRKReconstruction.findSector(seed2); - if(!(sector == 0 || sector == 1 || sector == 18 || sector == 19)) seed2 = cent2; - } - int lay1 = bankcl.getInt("layer", (int)icl1ok); - int lay2 = bankcl.getInt("layer", (int)icl2ok); - if(debugMode>0){ - System.out.println("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ seed1, seed2 " + - seed1 + " " + seed2 + " layer1 layer2 " + lay1 + " " + lay2); - System.out.println("~~~~~~~~~~ hit strip 1: " + seed1 + " layer " + lay1 + " sector " + - FTTRKReconstruction.findSector(seed1)); - System.out.println("~~~~~~~~~~ hit strip 2: " + seed2 + " layer " + lay2 + " sector " + - FTTRKReconstruction.findSector(seed2)); - } - if(seed1!=0 && seed2!=0){ - Line3D seg1 = (Line3D) FTTRKConstantsLoader.getStripSegmentLab(lay1, seed1); - Line3D seg2 = (Line3D) FTTRKConstantsLoader.getStripSegmentLab(lay2, seed2); - segment1.setOrigin(seg1.origin().x(), seg1.origin().y()); - segment2.setOrigin(seg2.origin().x(), seg2.origin().y()); - segment1.setEnd(seg1.end().x(), seg1.end().y()); - segment2.setEnd(seg2.end().x(), seg2.end().y()); - - // extract the mumber of strips forming the cross and store them in an occupancy plot for matched signals - // which strips are forming the id cross? - if(lay1==DetectorLayer.FTTRK_LAYER1){h71.fill(seed1); - }else if(lay1==DetectorLayer.FTTRK_LAYER2){h72.fill(seed1); - }else if(lay1==DetectorLayer.FTTRK_LAYER3){h73.fill(seed1); - }else if(lay1==DetectorLayer.FTTRK_LAYER4){h74.fill(seed1); - } - - if(lay2==DetectorLayer.FTTRK_LAYER1){h71.fill(seed2); - }else if(lay2==DetectorLayer.FTTRK_LAYER2){h72.fill(seed2); - }else if(lay2==DetectorLayer.FTTRK_LAYER3){h73.fill(seed2); - }else if(lay2==DetectorLayer.FTTRK_LAYER4){h74.fill(seed2); - } - - DataBank bankhit = event.getBank("FTTRK::hits"); - if(bankhit.rows()>0){ - for(int k=0; k0){ - System.out.println("coordinates of track on fttrk " + bank.getFloat("cx", i)*zt + " " + - bank.getFloat("cy", i)*zt + " " + bank.getFloat("cz", i)*zt); - System.out.println("director cosines hit on calorimeter " + part.x() + " " + part.y() + " " + part.z()); - System.out.println("director cosines hit of fttrk " + xt + " " + yt + " " + zt); - } - h102.fill(bank.getFloat("cx", i) *zt - xt); - h104.fill(bank.getFloat("cy", i) *zt - yt); - h106.fill((part.theta() - hitOnTrk.theta())); - h108.fill((part.phi() - hitOnTrk.phi())); - int sec1 = FTTRKReconstruction.findSector(seed1); - int sec2 = FTTRKReconstruction.findSector(seed2); - hSecDet0.fill(sec1, sec2); - hSeedDet0.fill(seed1, seed2); - if(debugMode>0){ - System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> " + sec1 + "-" + sec2 + - " bad seeds d0, event " + nev); - } - canvasCALTRK.cd(0); - segment1.setLineColor(1); - segment2.setLineColor(2); - canvasCALTRK.draw(segment1); - canvasCALTRK.draw(segment2); - - }else if(det==TRK2 && trk2ID==crossID){ - h101.fill(xt, yt); - h103.fill(bank.getFloat("cx", i) *zt - xt); - h105.fill(bank.getFloat("cy", i) *zt - yt); - h107.fill((part.theta() - hitOnTrk.theta())); - h109.fill((part.phi() - hitOnTrk.phi())); - int sec1 = FTTRKReconstruction.findSector(seed1); - int sec2 = FTTRKReconstruction.findSector(seed2); - hSecDet1.fill(sec1, sec2); - hSeedDet1.fill(seed1, seed2); - if(debugMode>0){ - System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> " + sec1 + "-" + sec2 + - " bad seeds d1, event " + nev); - } - canvasCALTRK.cd(1); - segment1.setLineColor(3); - segment2.setLineColor(4); - canvasCALTRK.draw(segment1); - canvasCALTRK.draw(segment2); - } - - // extract residuals of TRK1 wrt TRK0 and viceversa - // loop on crosses in det0, find track connecting with origin, evaluate residuals of TRK1 hits wrt to this track - double cx = hitOnTrk.x() - centerOfTarget.x(); - double cy = hitOnTrk.y() - centerOfTarget.y(); - double cz = hitOnTrk.z() - centerOfTarget.z(); - for(int ncj = 0; ncj < ncrosses; ncj++) { - int det1 = banktrk.getInt("detector", ncj); - if(det1 >=0 && nc != ncj && det != det1){ - double x1 = banktrk.getFloat("x", ncj); - double y1 = banktrk.getFloat("y", ncj); - double z1 = banktrk.getFloat("z", ncj); - int secondCrossID = banktrk.getInt("id", ncj); - Vector3D cross = new Vector3D(x1, y1, z1); - // check if within tolerance (previously done in findCross) - double r0 = Math.sqrt(hitOnTrk.x()*hitOnTrk.x() + hitOnTrk.y()*hitOnTrk.y() + hitOnTrk.z()*hitOnTrk.z()); - double r1 = Math.sqrt(cross.x()*cross.x() + cross.y()*cross.y() + cross.z()*cross.z()); - double r02d = Math.sqrt(hitOnTrk.x()*hitOnTrk.x() + hitOnTrk.y()*hitOnTrk.y()); - double r12d = Math.sqrt(cross.x()*cross.x() + cross.y()*cross.y()); - double diffRadii = r02d-r12d; - double diffTheta = Math.acos(hitOnTrk.z()/r0) - Math.acos(cross.z()/r1); - double diffPhi = Math.atan2(hitOnTrk.y(), hitOnTrk.x()) - Math.atan2(cross.y(), cross.x()); - if(Math.abs(diffPhi) < diffPhiTolerance && Math.abs(diffRadii)< diffRadTolerance && - Math.abs(diffTheta) < diffThetaTolerance){ - double t = (cross.z()-centerOfTarget.z())/hitOnTrk.z(); - Vector3D pointOnTrackAtZ = new Vector3D(cx*t + centerOfTarget.x(), cy*t + centerOfTarget.y(), z1); - if(det1 == TRK2 && trk2ID == secondCrossID){ - resTrkXdet0.fill(pointOnTrackAtZ.x() - cross.x()); - resTrkYdet0.fill(pointOnTrackAtZ.y() - cross.y()); - resTrkThetadet0.fill(pointOnTrackAtZ.theta() - cross.theta()); - resTrkPhidet0.fill(pointOnTrackAtZ.phi() - cross.phi()); - resTrkXVsXdet0.fill(cross.x(), pointOnTrackAtZ.x() - cross.x()); - resTrkYVsYdet0.fill(cross.y(), pointOnTrackAtZ.y() - cross.y()); - }else if(det1 == TRK1 && trk1ID == secondCrossID){ - resTrkXdet1.fill(pointOnTrackAtZ.x() - cross.x()); - resTrkYdet1.fill(pointOnTrackAtZ.y() - cross.y()); - resTrkThetadet1.fill(pointOnTrackAtZ.theta() - cross.theta()); - resTrkPhidet1.fill(pointOnTrackAtZ.phi() - cross.phi()); - resTrkXVsXdet1.fill(cross.x(), pointOnTrackAtZ.x() - cross.x()); - resTrkYVsYdet1.fill(cross.y(), pointOnTrackAtZ.y() - cross.y()); - } - } - } - } - } - } - - if(ncrosses==2){ - float x0 = banktrk.getFloat("x", 0); - float y0 = banktrk.getFloat("y", 0); - float x1 = banktrk.getFloat("x", 1); - float y1 = banktrk.getFloat("y", 1); - - Point3D c0 = new Point3D(x0, y0, banktrk.getFloat("z",0)); - Point3D c1 = new Point3D(x1, y1, banktrk.getFloat("z",1)); - Line3D lineBwCrosses = new Line3D(c1, c0); - if(debugMode>0){ - System.out.println("x coordinates on 2 layers " + x0 + " " + x1); - System.out.println("director cosines straight line bw crosses, cx " + lineBwCrosses.originDir().x() + " cy " + - lineBwCrosses.originDir().y() + " cz " + lineBwCrosses.originDir().z()); - } - } - } - } - } - } - - if(event.hasBank("FTTRK::crosses")){ - nevWithCrosses++; - DataBank banktrk = event.getBank("FTTRK::crosses"); - int nrows = banktrk.rows(); - - // comparison with MC data - // how many particles have been generated? - int ipart = gen.countGenerated(); - for(int ip=0; ip0) System.out.println("------- generated particle n " + ip + " type: " + gen.getGeneratedParticle(ip).pid() + " mass " + mass); - double P = gen.getGeneratedParticle(ip).p(); - double cx = gen.getGeneratedParticle(ip).px()/P; - double cy = gen.getGeneratedParticle(ip).py()/P; - double cz = gen.getGeneratedParticle(ip).pz()/P; - double Pz = P*cz; - double Pperp = P*Math.sqrt(cx*cx+cy*cy); - double x0 = gen.getGeneratedParticle(ip).vx(); - double y0 = gen.getGeneratedParticle(ip).vy(); - double z0 = gen.getGeneratedParticle(ip).vz(); - double q = Math.abs(gen.getGeneratedParticle(ip).charge()); // negative particles bend upwards - for (int i = 0; i < nrows; i++) { - int det = banktrk.getInt("detector", i); - double xt = banktrk.getFloat("x", i); - double yt = banktrk.getFloat("y", i); - double zt = banktrk.getFloat("z", i); - - if(debugMode>0){ - System.out.println("MC: x0 = " + x0 + " y0 " + y0 + " z0 " + z0); - System.out.println("MC cosines: cx = " + cx + " cy " + cy + " cz " + cz); - System.out.println("trk: xt = " + xt + " yt " + yt + " zt " + zt); - } - double t = (zt - z0)/cz; - Vector3D hitOnTrk = new Vector3D(xt, yt, zt); - Vector3D hitMCOnTrk = new Vector3D(x0+cx*t, y0+cy*t, zt); // straight line - - if(debugMode>0) System.out.println("MC on the straight line x = " + hitMCOnTrk.x() + " y = " + hitMCOnTrk.y() + - " z = " + hitMCOnTrk.z()); - // if the magnetic field is on, the coordinates must be swum along a helix - double B = en.getSolenoid(); - if(B!=0.){ - // find the crossing point of the helix and a xy plane at given z, where the magneti field stops - double zStop = 100.0; // PROVISIONAL fixed to 1 meter - double phi0 = Math.atan2(cy,cx); - double R = Pperp/0.3/B/q*1.e2; // R in cm - double dAlpha = (zStop-z0)*(B*q*0.3)/Pz*1.e-2; // deltaZ in meters - int nturns = (int) Math.floor(dAlpha/2./Math.PI); // number of full turns - if(dAlpha>0){ - dAlpha -= nturns*2.*Math.PI; - }else{ - dAlpha += nturns*2.*Math.PI; - } - - double xc = R*Math.sin(phi0); - double yc = R*Math.cos(phi0); - Vector3D hitOnPlane = new Vector3D(); - Vector3D tangentAtZstop = new Vector3D(); - if(R*dAlpha>0){ - hitOnPlane.setX(-xc + R*(Math.sin(phi0 + dAlpha))); - hitOnPlane.setY( yc - R*(Math.cos(phi0 + dAlpha))); - hitOnPlane.setZ(zStop); - double gamma = Math.atan2(hitOnPlane.y(),hitOnPlane.x()); - double vx1 = Pperp/P*Math.sin(gamma); - double vy1 = Pperp/P*Math.cos(gamma); - double vz1 = Math.sqrt(1. - vx1*vx1 + vy1*vy1); - double t1 = (zt - hitOnPlane.z())/vz1; - hitMCOnTrk.setXYZ(hitOnPlane.x()+vx1*t1, hitOnPlane.y()+vy1*t1, zt); - }else{ - if(debugMode>0) System.out.println("check particle/curvature signs"); - } - } - if(debugMode>0) System.out.println("MC after swimming in mag field x = " + hitMCOnTrk.x() + " y = " + hitMCOnTrk.y() + - " z = " + hitMCOnTrk.z()); - - if(det==TRK1){ - h2000.fill(hitMCOnTrk.x(), hitMCOnTrk.y()); // Montecarlo hit location on first detector middle plane - h1100.fill(hitOnTrk.x(), hitOnTrk.y()); - h1102.fill(hitMCOnTrk.x() - hitOnTrk.x()); - h1104.fill(hitMCOnTrk.y() - hitOnTrk.y()); - h1106.fill((hitMCOnTrk.theta() - hitOnTrk.theta())); - h1108.fill((hitMCOnTrk.phi() - hitOnTrk.phi())); - h1112.fill((hitMCOnTrk.x() - hitOnTrk.x())/hitMCOnTrk.x()); - h1114.fill((hitMCOnTrk.y() - hitOnTrk.y())/hitMCOnTrk.y()); - h202.fill(hitOnTrk.x()); - h1202.fill(hitMCOnTrk.x()); - h204.fill(hitOnTrk.y()); - h1204.fill(hitMCOnTrk.y()); - }else if(det==TRK2){ - h2001.fill(hitMCOnTrk.x(), hitMCOnTrk.y()); - h1101.fill(hitOnTrk.x(), hitOnTrk.y()); - h1103.fill(hitMCOnTrk.x() - hitOnTrk.x()); - h1105.fill(hitMCOnTrk.y() - hitOnTrk.y()); - h1107.fill((hitMCOnTrk.theta() - hitOnTrk.theta())); - h1109.fill((hitMCOnTrk.phi() - hitOnTrk.phi())); - h1113.fill((hitMCOnTrk.x() - hitOnTrk.x())/hitMCOnTrk.x()); - h1115.fill((hitMCOnTrk.y() - hitOnTrk.y())/hitMCOnTrk.y()); - h203.fill(hitOnTrk.x()); - h1203.fill(hitMCOnTrk.x()); - h205.fill(hitOnTrk.y()); - h1205.fill(hitMCOnTrk.y()); - } - if(debugMode>0){ - System.out.println("MC hit coordinates " + hitMCOnTrk.x() + " " + hitMCOnTrk.y() + " " + hitMCOnTrk.z()); - System.out.println("MC theta " + hitMCOnTrk.theta() + " hit on trk " + hitOnTrk.theta()); - System.out.println("MC phi " + hitMCOnTrk.phi() + " hit on trk " + hitOnTrk.phi()); - System.out.println("trk hit coordinates " + hitOnTrk.x() + " " + hitOnTrk.y() + " " + hitOnTrk.z()); - } - } - } // end MC comparison - } // end loop on crosses - } - } - - if(debugMode>=-1) // print always - System.out.println("@@@@@@@@@@@@@ total number of events read " + nev + " @@@@@ total number of events with rec cross in FTTRK " - + nevWithCrosses + " @@@@ number of reconstructed FTParticles " + nOfFTParticles); - - if(timeEnergyDiagnosticHistograms){ - JFrame frame = new JFrame("FT Reconstruction"); - frame.setSize(1200, 800); - EmbeddedCanvas canvas = new EmbeddedCanvas(); - canvas.divide(3, 3); - canvas.cd(0); - canvas.draw(h1); - canvas.cd(1); - canvas.draw(h2); - canvas.cd(2); - canvas.draw(h3); - canvas.cd(3); - h501.setFillColor(3); // green - h502.setFillColor(5); // yellow - h503.setFillColor(8); // dark green - h504.setFillColor(7); // orange - h600.setFillColor(9); // blue violet - - - canvas.draw(h501); - canvas.draw(h502,"same"); - canvas.cd(4); - canvas.draw(h503,""); - canvas.draw(h504,"same"); - - for (int i = 0; i < h6.getDataBufferSize(); i++) { - float meanE = h6.getDataBufferBin(i); - float nE = h7.getDataBufferBin(i); - if (nE > 0) { - h6.setDataBufferBin(i, meanE / nE); - } - } - canvas.cd(5); - canvas.draw(h507); - canvas.cd(6); - canvas.draw(h600); - canvas.cd(7); - canvas.draw(h601); - canvas.cd(8); - frame.add(canvas); - frame.setLocationRelativeTo(null); - frame.setVisible(true); - } - - double narrowFactor = 7.5; // was 4.5 - JFrame frametrk = new JFrame("FTTRK Reconstruction with respect to FTCAL tracking"); - frametrk.setSize(1600, 800); - EmbeddedCanvas canvastrk = new EmbeddedCanvas(); - canvastrk.divide(5, 2); - canvastrk.cd(0); - canvastrk.draw(h100); - canvastrk.cd(1); - canvastrk.draw(h102); - F1D f02 = new F1D("f02","[amp]*gaus(x,[mean],[sigma])", -limTC/narrowFactor, limTC/narrowFactor); - f02.setParameter(0, 10.0); - f02.setParameter(1, 0.0); - f02.setParameter(2, 1.0); - f02.setLineColor(6); - f02.setLineWidth(3); - DataFitter.fit(f02, h102, "Q"); //No options uses error for sigma - f02.setParameter(0, f02.parameter(0).value()); - f02.setParameter(1, f02.parameter(1).value()); - f02.setParameter(2, f02.parameter(2).value()); - DataFitter.fit(f02, h102, "Q"); //No options uses error for sigma - f02.setOptStat(11111); - canvastrk.draw(f02,"same"); - canvastrk.cd(2); - canvastrk.draw(h104); - F1D f04 = new F1D("f04","[amp]*gaus(x,[mean],[sigma])", -limTC/narrowFactor, limTC/(narrowFactor)); - f04.setParameter(0, h104.getMax()); - f04.setParameter(1, h104.getMean()); - f04.setParameter(2, h104.getRMS()/2.); - f04.setLineColor(6); - f04.setLineWidth(3); - DataFitter.fit(f04, h104, "Q"); //No options uses error for sigma - f04.setParameter(0, f04.parameter(0).value()); - f04.setParameter(1, f04.parameter(1).value()); - f04.setParameter(2, f04.parameter(2).value()); - DataFitter.fit(f04, h104, "Q"); //No options uses error for sigma - f04.setOptStat(11111); - canvastrk.draw(f04,"same"); - canvastrk.cd(3); - canvastrk.draw(h106); - F1D f06 = new F1D("f06","[amp]*gaus(x,[mean],[sigma])", -limTCTheta/narrowFactor, limTCTheta/narrowFactor); - f06.setParameter(0, 10.0); - f06.setParameter(1, h106.getMean()); - f06.setParameter(2, h106.getRMS()); - f06.setLineColor(6); - f06.setLineWidth(3); - DataFitter.fit(f06, h106, "Q"); //No options uses error for sigma - f06.setParameter(0, f06.parameter(0).value()); - f06.setParameter(1, f06.parameter(1).value()); - f06.setParameter(2, f06.parameter(2).value()); - DataFitter.fit(f06, h106, "Q"); //No options uses error for sigma - f06.setOptStat(11111); - canvastrk.draw(f06,"same"); - canvastrk.cd(4); - canvastrk.draw(h108); - F1D f08 = new F1D("f08","[amp]*gaus(x,[mean],[sigma])", -limTCPhi/narrowFactor, limTCPhi/narrowFactor); - f08.setParameter(0, h108.getMax()); - f08.setParameter(1, h108.getMean()); - f08.setParameter(2, h108.getRMS()); - f08.setLineColor(6); - f08.setLineWidth(3); - DataFitter.fit(f08, h108, "Q"); //No options uses error for sigma - f08.setOptStat(11111); - canvastrk.draw(f08,"same"); - - canvastrk.cd(5); - canvastrk.draw(h101); - - canvastrk.cd(6); - canvastrk.draw(h103); - F1D f03 = new F1D("f03","[amp]*gaus(x,[mean],[sigma])", -limTC/narrowFactor, limTC/narrowFactor); - f03.setParameter(0, 10.0); - f03.setParameter(1, 0.0); - f03.setParameter(2, 1.0); - f03.setLineColor(6); - f03.setLineWidth(3); - DataFitter.fit(f03, h103, "Q"); //No options uses error for sigma - f03.setParameter(0, f03.parameter(0).value()); - f03.setParameter(1, f03.parameter(1).value()); - f03.setParameter(2, f03.parameter(2).value()); - DataFitter.fit(f03, h103, "Q"); //No options uses error for sigma - f03.setOptStat(1111); - canvastrk.draw(f03,"same"); - - - canvastrk.cd(7); - canvastrk.draw(h105); - F1D f05 = new F1D("f05","[amp]*gaus(x,[mean],[sigma])", -limTC/narrowFactor, limTC/narrowFactor); - f05.setParameter(0, 10.0); - f05.setParameter(1, 0.0); - f05.setParameter(2, 1.0); - f05.setLineColor(6); - f05.setLineWidth(3); - DataFitter.fit(f05, h105, "Q"); //No options uses error for sigma - f05.setParameter(0, f05.parameter(0).value()); - f05.setParameter(1, f05.parameter(1).value()); - f05.setParameter(2, f05.parameter(2).value()); - DataFitter.fit(f05, h105, "Q"); //No options uses error for sigma - f05.setOptStat(1111); - canvastrk.draw(f05,"same"); - - canvastrk.cd(8); - canvastrk.draw(h107); - F1D f07 = new F1D("f07","[amp]*gaus(x,[mean],[sigma])", -limTCTheta/narrowFactor, limTCTheta/narrowFactor); - f07.setParameter(0, h107.getMax()); - f07.setParameter(1, h107.getMean()); - f07.setParameter(2, h107.getRMS()); - f07.setLineColor(6); - f07.setLineWidth(3); - DataFitter.fit(f07, h107, "Q"); //No options uses error for sigma - f07.setOptStat(1111); - canvastrk.draw(f07,"same"); - - canvastrk.cd(9); - canvastrk.draw(h109); - F1D f09 = new F1D("f09","[amp]*gaus(x,[mean],[sigma])", -limTCPhi/narrowFactor, limTCPhi/narrowFactor); - f09.setParameter(0, h109.getMax()); - f09.setParameter(1, h109.getMean()); - f09.setParameter(2, h109.getRMS()); - f09.setLineColor(6); - f09.setLineWidth(3); - DataFitter.fit(f09, h109, "Q"); //No options uses error for sigma - f09.setParameter(0, f09.parameter(0).value()); - f09.setParameter(1, f09.parameter(1).value()); - f09.setParameter(2, f09.parameter(2).value()); - DataFitter.fit(f09, h109, "Q"); //No options uses error for sigma - f09.setOptStat(1111); - canvastrk.draw(f09,"same"); - frametrk.add(canvastrk); - frametrk.setLocationRelativeTo(null); - frametrk.setVisible(true); - - JFrame frametrkres = new JFrame("FTTRK Resolutions wrt MC generated events"); - frametrkres.setSize(1800, 800); - EmbeddedCanvas canvastrkres = new EmbeddedCanvas(); - canvastrkres.divide(7, 2); - int ii = 0; - canvastrkres.cd(ii); - canvastrkres.draw(h1100); - canvastrkres.cd(++ii); - canvastrkres.draw(h1102); - F1D f1 = new F1D("f1","[amp]*gaus(x,[mean],[sigma])", -0.25, 0.25); - f1.setParameter(0, h1102.getMax()); - f1.setParameter(1, h1102.getMean()); - f1.setParameter(2, h1102.getRMS()); - f1.setLineColor(4); - f1.setLineWidth(3); - DataFitter.fit(f1, h1102, "Q"); //No options uses error for sigma - f1.setParameter(0, f1.parameter(0).value()); - f1.setParameter(1, f1.parameter(1).value()); - f1.setParameter(2, f1.parameter(2).value()); - DataFitter.fit(f1, h1102, "Q"); //No options uses error for sigma - f1.setOptStat(1111); - canvastrkres.draw(f1,"same"); - if(debugMode>0) System.out.println(" mean = " + f1.parameter(1).value() - + " sigma = " + f1.parameter(2).value()); - canvastrkres.cd(++ii); - canvastrkres.draw(h1104); - F1D f2 = new F1D("f2","[amp]*gaus(x,[mean],[sigma])", -0.25, 0.25); - f2.setParameter(0, f1.parameter(0).value()); - f2.setParameter(1, f1.parameter(1).value()); - f2.setParameter(2, f1.parameter(2).value()); - f2.setLineColor(24); - f2.setLineWidth(3); - DataFitter.fit(f2, h1104, "Q"); //No options uses error for sigma - f2.setOptStat(1111); - canvastrkres.draw(f2,"same"); - if(debugMode>0) System.out.println(" mean = " + f2.parameter(1).value() - + " sigma = " + f2.parameter(2).error()); - canvastrkres.cd(++ii); - canvastrkres.draw(h1106); - F1D f6 = new F1D("f6","[amp]*gaus(x,[mean],[sigma])", -0.001, 0.001); - f6.setParameter(0, f1.parameter(0).value()); - f6.setParameter(1, h1106.getMean()); - f6.setParameter(2, h1106.getRMS()); - f6.setLineColor(24); - f6.setLineWidth(3); - DataFitter.fit(f6, h1106, "Q"); //No options uses error for sigma - f6.setOptStat(1111); - canvastrkres.draw(f6,"same"); - - canvastrkres.cd(++ii); - canvastrkres.draw(h1108); - F1D f8 = new F1D("f8","[amp]*gaus(x,[mean],[sigma])", -0.005, 0.005); - f8.setParameter(0, h1108.getMax()); - f8.setParameter(1, h1108.getMean()); - f8.setParameter(2, h1108.getRMS()/2); - f8.setLineColor(24); - f8.setLineWidth(3); - DataFitter.fit(f8, h1108, "Q"); //No options uses error for sigma - f8.setOptStat(1111); - canvastrkres.draw(f8,"same"); - canvastrkres.cd(++ii); - canvastrkres.draw(h1112); - F1D f12 = new F1D("f12","[amp]*gaus(x,[mean],[sigma])", -0.05, 0.05); - f12.setParameter(0, f1.parameter(0).value()); - f12.setParameter(1, h1112.getMean()); - f12.setParameter(2, h1112.getRMS()); - f12.setLineColor(24); - f12.setLineWidth(3); - DataFitter.fit(f12, h1112, "Q"); //No options uses error for sigma - f12.setOptStat(1111); - canvastrkres.draw(f12,"same"); - - canvastrkres.cd(++ii); - canvastrkres.draw(h1114); - F1D f14 = new F1D("f14","[amp]*gaus(x,[mean],[sigma])", -0.1, 0.1); - f14.setParameter(0, f1.parameter(0).value()); - f14.setParameter(1, h1114.getMean()); - f14.setParameter(2, h1114.getRMS()); - f14.setLineColor(24); - f14.setLineWidth(3); - DataFitter.fit(f14, h1114, "Q"); //No options uses error for sigma - f14.setOptStat(1111); - canvastrkres.draw(f14,"same"); - - canvastrkres.cd(++ii); - canvastrkres.draw(h1101); - canvastrkres.cd(++ii); - canvastrkres.draw(h1103); - F1D f3 = new F1D("f3","[amp]*gaus(x,[mean],[sigma])", -0.25, 0.25); - f3.setParameter(0, f1.parameter(0).value()); - f3.setParameter(1, f1.parameter(1).value()); - f3.setParameter(2, f1.parameter(2).value()); - f3.setLineColor(34); - f3.setLineWidth(3); - DataFitter.fit(f3, h1103, "Q"); //No options uses error for sigma - f3.setOptStat(1111); - canvastrkres.draw(f3,"same"); - if(debugMode>0) System.out.println(" mean = " + f3.parameter(1).value() - + " sigma = " + f3.parameter(2).error()); - canvastrkres.cd(++ii); - canvastrkres.draw(h1105); - F1D f4 = new F1D("f4","[amp]*gaus(x,[mean],[sigma])", -0.25, 0.25); - f4.setParameter(0, f1.parameter(0).value()); - f4.setParameter(1, f1.parameter(1).value()); - f4.setParameter(2, f1.parameter(2).value()); - f4.setLineColor(44); - f4.setLineWidth(3); - DataFitter.fit(f4, h1105, "Q"); //No options uses error for sigma - f4.setOptStat(1111); - canvastrkres.draw(f4,"same"); - if(debugMode>0) System.out.println(" mean = " + f4.parameter(1).value() - + " sigma = " + f4.parameter(2).error()); - canvastrkres.cd(++ii); - canvastrkres.draw(h1107); - F1D f17 = new F1D("f17","[amp]*gaus(x,[mean],[sigma])", -0.001, 0.001); - f17.setParameter(0, h1107.getMax()); - f17.setParameter(1, h1107.getMean()); - f17.setParameter(2, h1107.getRMS()); - f17.setLineColor(24); - f17.setLineWidth(3); - DataFitter.fit(f17, h1107, "Q"); //No options uses error for sigma - f17.setOptStat(1111); - canvastrkres.draw(f17,"same"); - canvastrkres.cd(++ii); - canvastrkres.draw(h1109); - F1D f19 = new F1D("f19","[amp]*gaus(x,[mean],[sigma])", -0.002, 0.002); - f19.setParameter(0, h1109.getMax()); - f19.setParameter(1, h1109.getMean()); - f19.setParameter(2, h1109.getRMS()); - f19.setLineColor(24); - f19.setLineWidth(3); - DataFitter.fit(f19, h1109, "Q"); //No options uses error for sigma - f19.setOptStat(1111); - canvastrkres.draw(f19,"same"); - - canvastrkres.cd(++ii); - canvastrkres.draw(h1113); - F1D f13 = new F1D("f13","[amp]*gaus(x,[mean],[sigma])", -0.05, 0.05); - f13.setParameter(0, f1.parameter(0).value()); - f13.setParameter(1, h1113.getMean()); - f13.setParameter(2, h1113.getRMS()); - f13.setLineColor(24); - f13.setLineWidth(3); - DataFitter.fit(f13, h1113, "Q"); //No options uses error for sigma - f13.setOptStat(1111); - canvastrkres.draw(f13,"same"); - - canvastrkres.cd(++ii); - canvastrkres.draw(h1115); - F1D f15 = new F1D("f15","[amp]*gaus(x,[mean],[sigma])", -0.1, 0.1); - f15.setParameter(0, f1.parameter(0).value()); - f15.setParameter(1, h1115.getMean()); - f15.setParameter(2, h1115.getRMS()); - f15.setLineColor(24); - f15.setLineWidth(3); - DataFitter.fit(f15, h1115, "Q"); //No options uses error for sigma - f15.setOptStat(1111); - canvastrkres.draw(f15,"same"); - - frametrkres.add(canvastrkres); - frametrkres.setLocationRelativeTo(null); - frametrkres.setVisible(true); - - JFrame frametrkrel = new JFrame("FTTRK Resolutions layer1 vs layer2"); - frametrkrel.setSize(800, 800); - EmbeddedCanvas canvastrkrel = new EmbeddedCanvas(); - canvastrkrel.divide(2, 2); - canvastrkrel.cd(0); - canvastrkrel.draw(h202); - canvastrkrel.draw(h1202,"same"); - canvastrkrel.cd(1); - canvastrkrel.draw(h203); - canvastrkrel.draw(h1203,"same"); - canvastrkrel.cd(2); - canvastrkrel.draw(h204); - canvastrkrel.draw(h1204,"same"); - canvastrkrel.cd(3); - canvastrkrel.draw(h205); - canvastrkrel.draw(h1205,"same"); - - frametrkrel.add(canvastrkrel); - frametrkrel.setLocationRelativeTo(null); - frametrkrel.setVisible(true); - - JFrame frameSecradio = new JFrame("20 sectors occupancy"); - frameSecradio.setSize(1000,500); - EmbeddedCanvas canvasSecradio = new EmbeddedCanvas(); - canvasSecradio.divide(2,1); - canvasSecradio.cd(0); - canvasSecradio.draw(hSecDet0); - // excluded cells - double excx0h1[] = {0., 1., 2., 3., 4., 5., 10., 11., 12., 13.}; - double excy0h1[] = {10., 11., 12., 13., 14., 15., 16., 17.}; - GraphErrors excludedDet0half1 = new GraphErrors(); - for(int i=0; i