Пример #1
0
  // 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();
    }
  }
Пример #2
0
  /**
   * Get the metadata channel tree for the given <code>path</code>. This will populate the channel
   * map with channel objects derived from the metadata. This will recursively make requests for
   * child servers and plugins up to the maximum request depth of {@value #MAX_REQUEST_DEPTH}.
   *
   * @param sink sink the sink connection to the RBNB server
   * @param path the path for the desired metadata
   * @param channels the map to populate with channel objects
   * @param depth the depth of the request
   * @return the metadata channel tree for the given path
   * @throws SAPIException if a server error occurs
   * @see #MAX_REQUEST_DEPTH
   */
  private ChannelTree getChannelTree(
      Sink sink, String path, Map<String, Channel> channels, int depth) throws SAPIException {
    depth++;

    ChannelTree ctree = ChannelTree.EMPTY_TREE;

    ChannelMap markerChannelMap = new ChannelMap();

    ChannelMap cmap = new ChannelMap();

    if (path == null) {
      path = "";
      cmap.Add("...");
    } else {
      cmap.Add(path + "/...");
    }

    sink.RequestRegistration(cmap);

    cmap = sink.Fetch(FETCH_TIMEOUT, cmap);

    if (cmap.GetIfFetchTimedOut()) {
      log.error("Failed to get metadata.  Fetch timed out.");
      return ctree;
    }

    ctree = ChannelTree.createFromChannelMap(cmap);

    // store user metadata in channel objects
    String[] channelList = cmap.GetChannelList();
    for (int i = 0; i < channelList.length; i++) {
      int channelIndex = cmap.GetIndex(channelList[i]);
      if (channelIndex != -1) {
        ChannelTree.Node node = ctree.findNode(channelList[i]);
        String userMetadata = cmap.GetUserInfo(channelIndex);
        Channel channel = new RBNBChannel(node, userMetadata);
        channels.put(channelList[i], channel);

        // look for marker channels
        String mimeType = channel.getMetadata("mime");
        if (mimeType != null && mimeType.compareToIgnoreCase(EventMarker.MIME_TYPE) == 0) {
          markerChannelMap.Add(node.getFullName());
        }
      }
    }

    Iterator<?> it = ctree.iterator();
    while (it.hasNext()) {
      ChannelTree.Node node = (ChannelTree.Node) it.next();
      NodeTypeEnum type = node.getType();

      // look for child servers or plugins and get their channels
      if ((type == ChannelTree.SERVER || type == ChannelTree.PLUGIN)
          && !path.startsWith(node.getFullName())
          && depth < MAX_REQUEST_DEPTH) {
        ChannelTree childChannelTree = getChannelTree(sink, node.getFullName(), channels, depth);
        ctree = childChannelTree.merge(ctree);
      }
    }

    if (markerChannelMap.NumberOfChannels() > 0) {
      double markersDuration = System.currentTimeMillis() / 1000d;

      // request from start of marker channels to now
      sink.Request(markerChannelMap, 0, markersDuration, "absolute");

      markerChannelMap = sink.Fetch(FETCH_TIMEOUT, markerChannelMap);
      if (!markerChannelMap.GetIfFetchTimedOut()) {
        // notify marker listeners
        fireMarkersUpdated(markerChannelMap);
      } else {
        log.error("Failed to get event markers. Fetched timed out.");
      }
    }

    return ctree;
  }
Пример #3
0
  // **********************  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;
        }
      }
    }
  }