Class GeminiFileCatalog<RecordClass extends SonarImageRecordI>

java.lang.Object
tritechgemini.fileio.GeminiFileCatalog<RecordClass>
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
ARISFileCatalog, ECDFileCatalog, GLFFileCatalog

public abstract class GeminiFileCatalog<RecordClass extends SonarImageRecordI> extends Object implements Serializable
Catalogue of information that's in a single Sonar data file.
Named when we only supported Tritech GLF and ECD formats, but should also be the base class for any other sonar data catalogues.
These objects are serialized into index files for each data file so don't add anything that can't be serialized.
Author:
Doug Gillespie
See Also:
  • Field Details

  • Constructor Details

    • GeminiFileCatalog

      public GeminiFileCatalog(String filePath)
  • Method Details

    • getFileCatalog

      public static GeminiFileCatalog getFileCatalog(String filePath, boolean create) throws CatalogException
      Preferred way of getting a file catalogue, since it will automatically handle ECD, GLF and DAT files.
      Parameters:
      filePath -
      create - build the catalogue for the file immediately.
      Returns:
      file catalogue of null if the file doesn't exist or is an unknown type.
      Throws:
      CatalogException - if file is null or there is a failure cataloguing it.
    • checkDeserialisedCatalog

      protected abstract void checkDeserialisedCatalog(String filePath2)
      Called just after a catalogue object has been deserialised, giving the opportunity to check anything. note that the file path is set elsewhere to allow for the possibility that the absolute path to the file may have changed, so it's probably not necessary to do anything here.
      Parameters:
      filePath2 -
    • readSerializedCatalog

      public static GeminiFileCatalog readSerializedCatalog(String filePath)
      Read a Gemini file catalogue record for the given data file
      Parameters:
      filePath - path of data (ecd or glf) file
      Returns:
      catalog information read from file.
    • writeSerializedCatalog

      public static boolean writeSerializedCatalog(String filePath, GeminiFileCatalog fileCatalog)
      Write a Gemini file Catalogue
      Parameters:
      filePath - path of data file (.ecd or .glf)
      fileCatalog - file catalogue to write
      Returns:
      true if successful write.
    • getCatalogName

      public static String getCatalogName(String dataFileName)
      Get a name for a serialized catalog file. this is just the normal file name with .x on the end.
      Parameters:
      dataFileName - Data file name.
      Returns:
      name of catalog file.
    • buildCatalogue

      public abstract boolean buildCatalogue(ArrayList<RecordClass> imageRecords) throws Exception
      Catalogue the file. i.e. go through the file and get the times and file positions of every record in the file.
      Parameters:
      imageRecords -
      Returns:
      true if catalog created successfully
      Throws:
      Exception
    • createCatalogue

      public boolean createCatalogue()
      Catalogue the file. i.e. go through the file and get the times and file positions of every record in the file.
      Returns:
      true if catalog created successfully
    • analyseCatalog

      protected void analyseCatalog()
      Get the number of sonars, their id's and types, etc.
    • getFilePath

      public String getFilePath()
    • getCatalogException

      public Exception getCatalogException()
    • loadFullRecord

      public abstract boolean loadFullRecord(RecordClass geminiRecord) throws IOException
      fully load a record (if it isn't already). This may involve going back to the file and getting and unpacking the raw data.
      Parameters:
      geminiRecord -
      Returns:
      true if load sucessful.
      Throws:
      IOException
    • streamCatalog

      public abstract CatalogStreamSummary streamCatalog(CatalogStreamObserver streamObserver) throws CatalogException
      Start a full forwards only read of the catalog from start to end, sending all records through to the streamObserver.

      Whatever calls this will almost definitely want to do so in a separate worker thread because the call will block until the read has finished.

      Parameters:
      streamObserver - observer to get catalog data.
      Returns:
      number of records read.
      Throws:
      CatalogException
    • stopCatalogStream

      public abstract void stopCatalogStream()
      Stop streaming the catalog.
    • getFirstRecordTime

      public long getFirstRecordTime()
      Get the time of the first record
      Returns:
      the time of the first record
    • getLastRecordTime

      public long getLastRecordTime()
      Get the time of the last record
      Returns:
      the time of the first record
    • getNumRecords

      public int getNumRecords()
      Returns:
      total number of records in the file
    • findRecordIndex

      public int findRecordIndex(long recordTime)
      Find the index of the closest record to the given time.
      Parameters:
      recordTime -
      Returns:
      index of closest record to given time.
    • getRecord

      public RecordClass getRecord(int recordIndex)
      Get a record. Note that this does NOT automatically fully load the record. Also note, that this is an overall index and you might be better off using the getSonarRecord functions
      Parameters:
      recordIndex -
      Returns:
      Gemini record.
    • getSonarRecord

      public RecordClass getSonarRecord(int sonarID, int sonarRecord)
      Get a record for a specified sonar
      Parameters:
      sonarID -
      sonarRecord -
      Returns:
    • getFullRecord

      public RecordClass getFullRecord(int recordIndex) throws IOException
      Get a record at given index, loading full data if required.
      Parameters:
      recordIndex -
      Returns:
      fully loaded record.
      Throws:
      IOException
    • cDateToMillis

      public static long cDateToMillis(double cDate)
    • getNumSonars

      public int getNumSonars()
      Get the number of sonars in the catalogue.
      Returns:
      number of sonars in the catalogue.
    • getMaxSonarFrames

      public int getMaxSonarFrames()
      Returns:
      The maximum number of frames for any single sonar
    • getSonarInfo

      public CatalogSonarInfo getSonarInfo(int sonarID)
      Get the summary info for a single sonar.
      Parameters:
      sonarID -
      Returns:
      summary info for a single conar.
    • getSonarIDs

      public int[] getSonarIDs()
      Get the ID's of the sonars in this catalogue.
      Returns:
      array of IDs (these are the things written on the sonar, not their indexes)
    • findRecordForIDandTime

      public SonarImageRecordI findRecordForIDandTime(int sonarID, long timeMillis)
      find the closest record to the given time for the sonar ID
      Parameters:
      sonarID - sonar ID
      timeMillis - time in milliseconds
      Returns:
      closest record or null
    • findRelativeRecord

      public SonarImageRecordI findRelativeRecord(SonarImageRecordI baseRecord, int recordOffset)
      Used when scrolling by record number. Allows to take the current time, then move by a small number of records forwards or backwards.
      Parameters:
      sonarID -
      timeMillis -
      recordOffest -
      Returns:
      relative image record in list.
    • getRecordIndex

      public int getRecordIndex(SonarRecordI currentRecord)
    • getRecordByIndex

      public SonarImageRecordI getRecordByIndex(int index)
      Get record for given index.
      Parameters:
      index -
      Returns:
      record index (or -1 if not found)
    • timedLoadFullRecord

      public boolean timedLoadFullRecord(RecordClass aRecord) throws IOException
      Throws:
      IOException
    • findRecordForIndexandTime

      public SonarImageRecordI findRecordForIndexandTime(int sonarIndex, long timeMillis)
      find the closest record to the given time for the sonar Index
      Parameters:
      sonarIndex - sonar Index (1, 2, 3 ...)
      timeMillis - time in milliseconds
      Returns:
      closest record or null
    • freeAllImageData

      public void freeAllImageData()
    • getTimeZone

      public static TimeZone getTimeZone()
      Returns:
      the timeZone
    • setTimeZone

      public static void setTimeZone(TimeZone timeZone)
      Parameters:
      timeZone - the timeZone to set
    • freeImageData

      public void freeImageData(long currentTime, long timeWinMillis)
      Free image data from all records, but with a window around the time of interest which gets kept.
      Parameters:
      currentTime - current time (in Viewer ?)
      timeWinMillis - time window about current time.
    • getImageRecords

      public ArrayList<RecordClass> getImageRecords()
      Returns:
      the imageRecords
    • setImageRecords

      protected void setImageRecords(ArrayList<RecordClass> imageRecords)
      Parameters:
      imageRecords - the imageRecords to set