// EMF 5/30/03: never clear cache, just don't write if older than // what's there... public void put(ChannelMap cm) { try { if (debug > 3) System.err.println("BRCache.put: cm " + cm); if (debug > 3) for (int i = 0; i < cm.NumberOfChannels(); i++) { System.err.println(i + ": " + cm.GetTimeStart(i) + " " + cm.GetData(i)); } // check must be on per channel basis ChannelMap cmCache = new ChannelMap(); Double[] lastTimeD = sink.getEndTimes(cm); for (int i = 0; i < cm.NumberOfChannels(); i++) { double thisTime = cm.GetTimeStart(i); if (lastTimeD[i] == null || lastTimeD[i].doubleValue() < thisTime) { int idx = cmCache.Add(cm.GetName(i)); cmCache.PutTimeRef(cm, i); cmCache.PutDataRef(idx, cm, i); } } source.Flush(cmCache); /* //if time goes backwards, reset ring buffer double thisTime=Double.MAX_VALUE; for (int i=0;i<cm.NumberOfChannels();i++) { double time=cm.GetTimeStart(i)+cm.GetTimeDuration(i); if (time<thisTime) thisTime=time; } if (thisTime<lastTime) { //reset ring buffer and clear endTimes if (debug>3) System.err.println("BRCache.put: reset ring buffer"); source.SetRingBuffer(1000,"none",0); endTimes.clear(); } if (thisTime<Double.MAX_VALUE) lastTime=thisTime; //put end times into cache for (int i=0;i<cm.NumberOfChannels();i++) { endTimes.put(cm.GetName(i),new Double(cm.GetTimeStart(i)+cm.GetTimeDuration(i))); } //put data into server source.Flush(cm); */ } catch (Exception e) { System.err.println("BRCache.put exception: " + e.getMessage()); e.printStackTrace(); } }
// ********************** PlugInTemplate Overrides *************************// protected void processRequest(ChannelMap fwdData, PlugInChannelMap out) throws SAPIException { if (fwdData.NumberOfChannels() == 0) return; // Override member defaults with dynamic options: int minDecimation = this.minDecimation, maxSamples = this.maxSamples; boolean antiAlias = this.antiAlias; java.util.Properties opts = getRequestOptions(); String temp; if ((temp = opts.getProperty("minDecimation")) != null) minDecimation = Integer.parseInt(temp); if ((temp = opts.getProperty("maxSamples")) != null) maxSamples = Integer.parseInt(temp); if ((temp = opts.getProperty("antiAlias")) != null) antiAlias = "true".equals(temp); // 2007/08/15 WHF maxSamples applies to all channels: // 2007/08/15 WHF Changed their mind. Uncomment to re-enable. /*if (fwdData.NumberOfChannels() == 0) return; maxSamples /= fwdData.NumberOfChannels(); if (maxSamples < 1) maxSamples = 1; */ for (int index = 0; index < fwdData.NumberOfChannels(); ++index) { Object data; // Will add if necessary, otherwise just a lookup: int outIndex = out.Add(fwdData.GetName(index)); // data = GetDataAsArray.get(fwdData, index); data = fwdData.GetDataAsArray(index); if (data == null) { System.err.println("ResamplePlugIn: Unsupported datatype."); continue; } int npts = Array.getLength(data); if (npts <= maxSamples && minDecimation < 2) { // length okay, just copy: out.PutTimeRef(fwdData, index); out.PutDataRef(outIndex, fwdData, index); continue; } // Calculate the decimation factor for this set: int ndeci = (int) Math.ceil(((double) npts) / maxSamples); if (ndeci < minDecimation) ndeci = minDecimation; double[] ddata = null; if (antiAlias) { if (fwdData.GetType(index) == ChannelMap.TYPE_FLOAT64) { ddata = (double[]) data; } else { ddata = new double[npts]; for (int ii = 0; ii < npts; ++ii) ddata[ii] = Array.getDouble(data, ii); } double[] dataOut = new double[ddata.length]; Filter lowPass = new Filter(1.0 / ndeci); lowPass.filter(ddata, dataOut); data = dataOut; } Object result = decimate(data, ndeci); out.PutTime(fwdData.GetTimeStart(index), fwdData.GetTimeDuration(index)); if (antiAlias) { out.PutDataAsFloat64(outIndex, (double[]) result); } else { switch (fwdData.GetType(index)) { case ChannelMap.TYPE_FLOAT32: out.PutDataAsFloat32(outIndex, (float[]) result); break; case ChannelMap.TYPE_FLOAT64: out.PutDataAsFloat64(outIndex, (double[]) result); break; case ChannelMap.TYPE_INT16: out.PutDataAsInt16(outIndex, (short[]) result); break; case ChannelMap.TYPE_INT32: out.PutDataAsInt32(outIndex, (int[]) result); break; case ChannelMap.TYPE_INT64: out.PutDataAsInt64(outIndex, (long[]) result); break; case ChannelMap.TYPE_INT8: out.PutDataAsInt8(outIndex, (byte[]) result); break; } } } }