From d95683a1462ca9abef354a803fa2fc0018c5273b Mon Sep 17 00:00:00 2001 From: Eyck Jentzsch Date: Thu, 23 Feb 2023 13:31:02 +0100 Subject: [PATCH] fixes FTR reading and makes it more robust --- .../database/ftr/AbstractTxStream.java | 3 +- .../scviewer/database/ftr/FtrDbLoader.java | 56 +++++++++++++++---- .../src/jacob/CborDecoder.java | 7 ++- 3 files changed, 49 insertions(+), 17 deletions(-) diff --git a/plugins/com.minres.scviewer.database.ftr/src/com/minres/scviewer/database/ftr/AbstractTxStream.java b/plugins/com.minres.scviewer.database.ftr/src/com/minres/scviewer/database/ftr/AbstractTxStream.java index ac98dfc..2dce2f3 100644 --- a/plugins/com.minres.scviewer.database.ftr/src/com/minres/scviewer/database/ftr/AbstractTxStream.java +++ b/plugins/com.minres.scviewer.database.ftr/src/com/minres/scviewer/database/ftr/AbstractTxStream.java @@ -182,8 +182,7 @@ abstract class AbstractTxStream extends HierNode implements IWaveform { } } rowCount=rowEndTime.size()>0?rowEndTime.size():1; - //getChildNodes().parallelStream().forEach(c -> ((TxGenerator)c).calculateConcurrency()); - getChildNodes().stream().forEach(c -> ((TxGenerator)c).calculateConcurrency()); + getChildNodes().parallelStream().forEach(c -> ((TxGenerator)c).calculateConcurrency()); } } diff --git a/plugins/com.minres.scviewer.database.ftr/src/com/minres/scviewer/database/ftr/FtrDbLoader.java b/plugins/com.minres.scviewer.database.ftr/src/com/minres/scviewer/database/ftr/FtrDbLoader.java index 5aa4b21..d5f8990 100644 --- a/plugins/com.minres.scviewer.database.ftr/src/com/minres/scviewer/database/ftr/FtrDbLoader.java +++ b/plugins/com.minres.scviewer.database.ftr/src/com/minres/scviewer/database/ftr/FtrDbLoader.java @@ -131,7 +131,7 @@ public class FtrDbLoader implements IWaveformDbLoader { * @param txId the tx id * @return the transaction */ - public ITx getTransaction(long txId) { + public synchronized ITx getTransaction(long txId) { if (txCache.containsKey(txId)) return txCache.get(txId); if(transactions.containsKey(txId)) { @@ -185,8 +185,10 @@ public class FtrDbLoader implements IWaveformDbLoader { this.file=file; try(FileInputStream fis = new FileInputStream(file)) { new CborDbParser(this, fis); + } catch (IOException e) { + LOG.warn("Problem parsing file "+file.getName()+": " , e); } catch (Exception e) { - LOG.error("Error parsing file "+file.getName(), e); + LOG.error("Error parsing file "+file.getName()+ ": ", e); transactions.clear(); throw new InputFormatException(e.toString()); } @@ -242,17 +244,15 @@ public class FtrDbLoader implements IWaveformDbLoader { long name_id = cborDecoder.readInt(); long type_id = cborDecoder.readInt(); String attrName = strDict.get((int)name_id); - if(!attributeTypes.containsKey(attrName)) { - attributeTypes.put(attrName, new TxAttributeType(attrName, DataType.values()[(int)type_id], AssociationType.values()[(int)tag-7])); - } - TxAttributeType attrType = attributeTypes.get(attrName); + TxAttributeType attrType = getOrAddAttributeType(tag, type_id, attrName); switch((int)type_id) { case 0: // BOOLEAN - ITxAttribute b = new TxAttribute(attrType, cborDecoder.readInt()>0?"True":"False"); + ITxAttribute b = new TxAttribute(attrType, cborDecoder.readBoolean()?"True":"False"); ret.add(b); break; case 2: // INTEGER case 3: // UNSIGNED + case 10: // POINTER ITxAttribute a = new TxAttribute(attrType, String.valueOf(cborDecoder.readInt())); ret.add(a); break; @@ -269,6 +269,8 @@ public class FtrDbLoader implements IWaveformDbLoader { ITxAttribute s = new TxAttribute(attrType, strDict.get((int)cborDecoder.readInt())); ret.add(s); break; + default: + LOG.warn("Unsupported data type: "+type_id); } } } @@ -279,6 +281,14 @@ public class FtrDbLoader implements IWaveformDbLoader { return ret; } + private synchronized TxAttributeType getOrAddAttributeType(long tag, long type_id, String attrName) { + if(!attributeTypes.containsKey(attrName)) { + attributeTypes.put(attrName, new TxAttributeType(attrName, DataType.values()[(int)type_id], AssociationType.values()[(int)tag-7])); + } + TxAttributeType attrType = attributeTypes.get(attrName); + return attrType; + } + /** * Dispose. */ @@ -318,6 +328,7 @@ public class FtrDbLoader implements IWaveformDbLoader { long array_len = readArrayLength(); assert(array_len==-1); CborType next = peekType(); + int chunk_idx=0; while(next != null && !break_type.isEqualType(next)) { long tag = readTag(); switch((int)tag) { @@ -389,9 +400,12 @@ public class FtrDbLoader implements IWaveformDbLoader { } } next = peekType(); + chunk_idx++; } } catch(IOException e) { - LOG.error("Error parsing file input stream", e); + long pos = 0; + try {pos=inputStream.getChannel().position(); } catch (Exception ee) {} + LOG.error("Error parsing file input stream at position" + pos, e); } } @@ -437,7 +451,8 @@ public class FtrDbLoader implements IWaveformDbLoader { long gen_id = cborDecoder.readInt(); long name_id = cborDecoder.readInt(); long stream_id = cborDecoder.readInt(); - add(gen_id, new TxGenerator(loader, gen_id, loader.strDict.get((int)name_id), loader.txStreams.get(stream_id))); + if(loader.txStreams.containsKey(stream_id)) + add(gen_id, new TxGenerator(loader, gen_id, loader.strDict.get((int)name_id), loader.txStreams.get(stream_id))); } else { throw new IOException("Illegal tage ncountered: "+id); } @@ -451,14 +466,17 @@ public class FtrDbLoader implements IWaveformDbLoader { while(next != null && !break_type.isEqualType(next)) { long blockOffset = cborDecoder.getPos(); long tx_size = cborDecoder.readArrayLength(); + long txId = 0; + long genId = 0; + long attr_idx=0; for(long i = 0; i