// TODO: fix. Returning Object[] is not the right design
  public Object[] getWaveServerRaw(
      final String s,
      final String c,
      final String n,
      final String l,
      final double t1,
      final double t2) {
    String lc = "";
    if (l != null && !l.equals("--")) {
      lc = "$" + l;
    }
    final String code = s + "$" + c + "$" + n + lc;
    if (!winston.checkConnect() || !winston.useDatabase(code)) {
      return null;
    }
    List<byte[]> bufs = null;
    try {
      bufs = data.getTraceBufBytes(code, t1, t2, 0);
    } catch (final UtilException e) {
    }
    if (bufs == null || bufs.size() == 0) {
      return null;
    }

    try {
      final int sid = channels.getChannelID(code);
      final TraceBuf tb0 = new TraceBuf(bufs.get(0));
      final TraceBuf tbN = new TraceBuf(bufs.get(bufs.size() - 1));
      int total = 0;
      for (final byte[] buf : bufs) {
        total += buf.length;
      }

      String lr = "";
      if (l != null) {
        lr = " " + l;
      }
      final String hdr =
          sid
              + " "
              + s
              + " "
              + c
              + " "
              + n
              + lr
              + " F "
              + tb0.dataType()
              + " "
              + tb0.getStartTime()
              + " "
              + tbN.getEndTime()
              + " "
              + total;
      return new Object[] {hdr, new Integer(total), bufs};
    } catch (final Exception e) {
      LOGGER.error("Could not get raw wave.", e.getLocalizedMessage());
    }
    return null;
  }
Exemple #2
0
  public void mergeHelicorders(final String code, final String date) {
    try {
      LOGGER.info("Begin merging helicorders.");
      final Set<Integer> sourceTimes = new HashSet<Integer>();
      int total = 0;
      LOGGER.info("Getting source times.");
      source.useDatabase(code);
      ResultSet srs =
          source.getStatement().executeQuery("SELECT j2ksec FROM `" + code + "$$H" + date + "`");
      while (srs.next()) {
        total++;
        sourceTimes.add((int) Math.round(srs.getDouble(1)));
      }

      LOGGER.info("Getting destination times.");
      dest.useDatabase(code);
      final ResultSet drs =
          dest.getStatement().executeQuery("SELECT j2ksec FROM `" + code + "$$H" + date + "`");
      total = 0;
      while (drs.next()) {
        total++;
        sourceTimes.remove(new Integer((int) Math.round(drs.getDouble(1))));
      }

      total = 0;
      double read = 0;
      double write = 0;
      LOGGER.info("Begin merging.");
      final PreparedStatement insert =
          dest.getConnection()
              .prepareStatement(
                  "INSERT IGNORE INTO `" + code + "$$H" + date + "` VALUES (?,?,?,?,?)");
      final CodeTimer readTimer = new CodeTimer();
      for (final Iterator<Integer> it = sourceTimes.iterator(); it.hasNext(); ) {
        final int d = it.next().intValue();
        srs =
            source
                .getStatement()
                .executeQuery(
                    "SELECT j2ksec, smin, smax, rcnt, rsam FROM `"
                        + code
                        + "$$H"
                        + date
                        + "` WHERE j2ksec="
                        + d);
        if (srs.next()) {
          insert.setDouble(1, srs.getDouble(1));
          insert.setInt(2, srs.getInt(2));
          insert.setInt(3, srs.getInt(3));
          insert.setInt(4, srs.getInt(4));
          insert.setDouble(5, srs.getDouble(5));
          final CodeTimer writeTimer = new CodeTimer();
          insert.execute();
          writeTimer.stopAndReport();
          write += writeTimer.getRunTimeMillis();
          total++;
        }
      }
      readTimer.stop();
      read = readTimer.getRunTimeMillis() - write;
      LOGGER.info("Done merging, " + read + "ms reading, " + write + "ms writing.");
      LOGGER.info("Merged " + total + " helicorder rows.");
    } catch (final Exception e) {
      LOGGER.error("Could not merge waves. {}", e);
    }
  }
Exemple #3
0
  public void mergeWaves(final String code, final String date) {
    try {
      LOGGER.info("Begin merging waves.");
      final Set<Double> sourceTimes = new HashSet<Double>();
      int total = 0;
      LOGGER.info("Getting source times.");
      source.useDatabase(code);
      ResultSet srs =
          source.getStatement().executeQuery("SELECT st FROM `" + code + "$$" + date + "`");
      while (srs.next()) {
        total++;
        sourceTimes.add(DataUtils.register(srs.getDouble(1), EPSILON));
      }

      LOGGER.info("Getting destination times.");
      dest.useDatabase(code);
      final ResultSet drs =
          dest.getStatement().executeQuery("SELECT st FROM `" + code + "$$" + date + "`");
      total = 0;
      while (drs.next()) {
        total++;
        sourceTimes.remove(new Double(DataUtils.register(drs.getDouble(1), EPSILON)));
      }

      total = 0;
      LOGGER.info("Begin merging.");
      double read = 0;
      double write = 0;
      final PreparedStatement insert =
          dest.getConnection()
              .prepareStatement(
                  "INSERT IGNORE INTO `" + code + "$$" + date + "` VALUES (?,?,?,?,?)");
      final CodeTimer readTimer = new CodeTimer();
      for (final Iterator<Double> it = sourceTimes.iterator(); it.hasNext(); ) {
        final double d = it.next().doubleValue();
        srs =
            source
                .getStatement()
                .executeQuery(
                    "SELECT st, et, sr, datatype, tracebuf FROM `"
                        + code
                        + "$$"
                        + date
                        + "` WHERE st>="
                        + (d - EPSILON)
                        + " AND st<="
                        + (d + EPSILON));
        if (srs.next()) {
          insert.setDouble(1, srs.getDouble(1));
          insert.setDouble(2, srs.getDouble(2));
          insert.setDouble(3, srs.getDouble(3));
          insert.setString(4, srs.getString(4));
          insert.setBlob(5, srs.getBlob(5));
          final CodeTimer writeTimer = new CodeTimer();
          insert.execute();
          writeTimer.stopAndReport();
          write += writeTimer.getRunTimeMillis();
          total++;
        }
      }
      readTimer.stop();
      read = readTimer.getRunTimeMillis() - write;
      LOGGER.info("Done merging, " + read + "ms reading, " + write + "ms writing.");
      LOGGER.info("Merged " + total + " wave rows.");
    } catch (final Exception e) {
      LOGGER.error("Could not merge waves. {}", e);
    }
  }