Class BinaryStore
- All Implemented Interfaces:
DataOutputStore
,OfflineDataStore
,PamSettings
,PamSettingsSource
,SettingsNameProvider
- Direct Known Subclasses:
SecondaryBinaryStore
The binary store has a number of advantages over database storage, particularly when it comes to writing objects with varying record lengths such as clicks and whistle contours.
Further information about binary storage and information on formats can be found here.
- Author:
- Doug Gillespie
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
static final String
static final String
static final String
static final String
static int
Maximum format that can be understood by this build of PAMGuard.
If a file is opened with a higher format, then PAMGuard will refuse to process the file.static final String
static final String
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
createFileMenu
(JFrame parentFrame) boolean
createMapPoint
(File aFile, BinaryHeaderAndFooter bhf, ArrayList<PamDataBlock> streams) Create a data map point and add it to the map.void
createOfflineDataMap
(Window parentFrame) Create a basic map of the data including first and last times and some kind of data/unit time count plus ideally some kind of start and stop time list of where there are gaps in the data.boolean
deleteDataFrom
(long timeMillis) Delete all data from a given time, in all data streams.static BinaryStore
Find the binary storefindIndexFile
(File dataFile, boolean checkExists) Find the index file to match a given data file.findNoiseFile
(File dataFile, boolean checkExists) Find the noise file to match a given data file.static String
Get the unit type for the binary store.static int
Get the data location.Get the data source namegetFileHeaderAndFooter
(File file) Run checks on each file.getFolderName
(long timeStamp, boolean addSeparator) Get the name of the current storage folder and check the folder exists, if necessary, creating it.getGUI
(int flag) Get the GUI for the PAMControlled unit.Get a data integrity checker.static int
Current maximum understandable format.Quick convenient way of getting the module status.Store noise in pgdf or pgnf files.int
Get the number of different settings within the settings source.int
Get the offline state of this module.getSettings
(int settingsIndex) Get a specific PamSettingsGroupGet a name for the settings sourcelong
getStoreStatus
(boolean getDetail) Get the store status, i.e.static ArrayList<PamDataBlock>
getStreamingDataBlocks
(boolean binaryStore) Get a list of data blocks with binary storage.static boolean
isDataBlockBinaryOut
(PamDataBlock pamDataBlock) Convenience function to determine whether a data block is beiung written to binary filesList all the files in the binary storage folderlistAllFilesWithPrefix
(String prefix) List all the pgdf files in the binary storage folder with the passed prefixvoid
listDataFiles
(ArrayList<File> fileList, File folder, PamFileFilter filter) List all data files - get's called recursivelyList all the index files in the binary storage folderboolean
loadData
(PamDataBlock dataBlock, BinaryOfflineDataMapPoint mapPoint, long dataStart, long dataEnd, BinaryDataSink dataSink) Load the data from a single file.boolean
loadData
(PamDataBlock dataBlock, OfflineDataLoadInfo offlineDataLoadInfo, ViewLoadObserver loadObserver) Load data for a given datablock between two time limits.makeIndexFile
(File dataFile) Create an index file (pgdx) name from a data file (pgdf) file namevoid
notifyModelChanged
(int changeType) General notification when the PAMGAURD model changes.void
pamClose()
Called when PAMGUARD is finally closing down so that a module may free any remaining resources (e.g.void
Called for all controlled units after Pam acquisition has stoppedvoid
called just before data acquisition starts.readHeaderAndFooter
(File file) Public version ofreadHeadAndFoot(File)
methodrebuildFileFooter
(File file) Reads the data objects in the passed file, and records the first/last UID, times and sample numbers.boolean
removeMapPoint
(File aFile, ArrayList<PamDataBlock> streams) boolean
restoreSettings
(PamControlledUnitSettings pamControlledUnitSettings) boolean
rewriteIndexFile
(PamDataBlock dataBlock, OfflineDataMapPoint offlineDataMapPoint) rewrite the index file.boolean
rewriteIndexFile
(PamDataBlock dataBlock, OfflineDataMapPoint offlineDataMapPoint, File indexFile) boolean
saveData
(PamDataBlock pamDataBlock) Saves data in a PamDataBlock.boolean
saveEndSettings
(long timeNow) Save settings when processing ends.boolean
saveStartSettings
(long timeNow) Save the settings in some way or another.void
setBinaryStoreSettings
(BinaryStoreSettings binaryStoreSettings) swapFileType
(File dataFile, String newType) Swap a file type from whatever is on the end of datafile to newTypeMethods inherited from class PamController.PamControlledUnit
addOfflineTaskGroup, addOtherRelatedMenuItems, addPamProcess, addPamProcess, addRelatedMenuItems, canClose, canPlayViewerSound, createDetectionMenu, createDisplayMenu, createHelpMenu, flushDataBlockBuffers, getFrameNumber, getGuiFrame, getInstanceIndex, getModuleStatusManager, getModuleSummary, getModuleSummary, getNumOfflineTaskGroups, getNumPamProcesses, getOfflineTaskGroup, getPamConfiguration, getPamController, getPamModuleInfo, getPamProcess, getPamView, getPlugin, getShortUnitType, getSidePanel, getTabClipCopier, getTabPanel, getTabSpecificMenuBar, getToolbarComponent, getUnitName, getUnitType, getVerboseLevel, gotoTab, isInMainConfiguration, isNetRx, isViewer, playViewerSound, removePamProcess, removeUnit, rename, saveViewerData, setFrameNumber, setModuleStatusManager, setPamConfiguration, setPamController, setPamModuleInfo, setPamView, setSidePanel, setTabPanel, setToolbarComponent, setupControlledUnit, stopViewerSound, tellModule, terminalPrint, terminalPrintln, toString
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface PamController.PamSettings
getUnitType
Methods inherited from interface PamController.SettingsNameProvider
getUnitName
-
Field Details
-
fileType
- See Also:
-
indexFileType
- See Also:
-
settingsFileType
- See Also:
-
noiseFileType
- See Also:
-
MAX_UNDERSTANDABLE_FORMAT
public static int MAX_UNDERSTANDABLE_FORMATMaximum format that can be understood by this build of PAMGuard.
If a file is opened with a higher format, then PAMGuard will refuse to process the file. -
defUnitType
- See Also:
-
defUnitName
- See Also:
-
GlobalFolderArg
- See Also:
-
-
Constructor Details
-
BinaryStore
-
-
Method Details
-
getCurrentFileFormat
public static int getCurrentFileFormat() -
getMaxUnderstandableFormat
public static int getMaxUnderstandableFormat()Current maximum understandable format.- Returns:
- maximum understandable file format.
-
notifyModelChanged
public void notifyModelChanged(int changeType) Description copied from class:PamControlledUnit
General notification when the PAMGAURD model changes.- Overrides:
notifyModelChanged
in classPamControlledUnit
- Parameters:
changeType
- type of change
-
pamToStart
public void pamToStart()Description copied from class:PamControlledUnit
called just before data acquisition starts. Note that PamObservers get a call to setSampleRate anyway so this mainly needs to be used for display elements that may need their scales adjusted before startup.- Overrides:
pamToStart
in classPamControlledUnit
-
pamHasStopped
public void pamHasStopped()Description copied from class:PamControlledUnit
Called for all controlled units after Pam acquisition has stopped- Overrides:
pamHasStopped
in classPamControlledUnit
-
getStreamingDataBlocks
Get a list of data blocks with binary storage. If input parameter is true, then stores which have their binary storage disabled will NOT be included in the list.- Parameters:
binaryStore
- true if binary storage - blocks with binaryStore flag set false will not be included.- Returns:
- list of data blocks which have binary storage.
-
getSettingsReference
- Specified by:
getSettingsReference
in interfacePamSettings
- Returns:
- The serialisable object that will be stored
-
getSettingsVersion
public long getSettingsVersion()- Specified by:
getSettingsVersion
in interfacePamSettings
- Returns:
- An integer version number for the settings
-
getFolderName
Get the name of the current storage folder and check the folder exists, if necessary, creating it.- Parameters:
timeStamp
- current time in milliseconds.addSeparator
- if true, add a path separator character to the end of the path.- Returns:
- true if folder exists (or has been created)
-
restoreSettings
- Specified by:
restoreSettings
in interfacePamSettings
- Returns:
- true if successful The object performs final checks (if needed) and then casts the settings data pamcontrolledunitSettings.settings into the correct type and uses as required
-
checkCommandLine
public boolean checkCommandLine() -
createFileMenu
- Overrides:
createFileMenu
in classPamControlledUnit
- Parameters:
parentFrame
- parent frame for the menu- Returns:
- the file menu item
-
saveStartSettings
public boolean saveStartSettings(long timeNow) Description copied from interface:PamSettingsSource
Save the settings in some way or another.- Specified by:
saveStartSettings
in interfacePamSettingsSource
- Parameters:
timeNow
- current time.- Returns:
- true if settings saved successfully
-
saveEndSettings
public boolean saveEndSettings(long timeNow) Description copied from interface:PamSettingsSource
Save settings when processing ends. This may just be an update of the settings saves with saveStartSettings, e.g. an end time.- Specified by:
saveEndSettings
in interfacePamSettingsSource
- Returns:
- true if saved correctly.
-
getNumSettings
public int getNumSettings()Description copied from interface:PamSettingsSource
Get the number of different settings within the settings source.- Specified by:
getNumSettings
in interfacePamSettingsSource
- Returns:
- the number of PamSettingsGroups.
-
getSettings
Description copied from interface:PamSettingsSource
Get a specific PamSettingsGroup- Specified by:
getSettings
in interfacePamSettingsSource
- Parameters:
settingsIndex
- index of group- Returns:
- a settings group
-
getSettingsSourceName
Description copied from interface:PamSettingsSource
Get a name for the settings source- Specified by:
getSettingsSourceName
in interfacePamSettingsSource
- Returns:
- a name
-
getBinaryStoreSettings
- Returns:
- the binaryStoreSettings
-
setBinaryStoreSettings
- Parameters:
binaryStoreSettings
- the binaryStoreSettings to set
-
createOfflineDataMap
Description copied from interface:OfflineDataStore
Create a basic map of the data including first and last times and some kind of data/unit time count plus ideally some kind of start and stop time list of where there are gaps in the data.- Specified by:
createOfflineDataMap
in interfaceOfflineDataStore
-
listAllFiles
List all the files in the binary storage folder- Returns:
- List of files.
-
listAllFilesWithPrefix
List all the pgdf files in the binary storage folder with the passed prefix- Returns:
- List of files.
-
listIndexFiles
List all the index files in the binary storage folder- Returns:
- List of index files
-
removeMapPoint
-
findIndexFile
Find the index file to match a given data file.- Parameters:
dataFile
- data file.checkExists
- check teh file exists and if it doens't return null- Returns:
- index file to go with the data file.
-
findNoiseFile
Find the noise file to match a given data file.- Parameters:
dataFile
- data file.checkExists
- check the file exists and if it doens't return null- Returns:
- index file to go with the data file.
-
makeIndexFile
Create an index file (pgdx) name from a data file (pgdf) file name- Parameters:
dataFile
- data file name- Returns:
- index file name
-
swapFileType
Swap a file type from whatever is on the end of datafile to newType- Parameters:
dataFile
- existing data file, probably .pgdfnewType
- new file type (should not have the . on)- Returns:
- new file with changed type.
-
rewriteIndexFile
rewrite the index file.- Specified by:
rewriteIndexFile
in interfaceOfflineDataStore
- Parameters:
dataBlock
-dmp
-- Returns:
-
rewriteIndexFile
public boolean rewriteIndexFile(PamDataBlock dataBlock, OfflineDataMapPoint offlineDataMapPoint, File indexFile) - Parameters:
dataBlock
-offlineDataMapPoint
-indexFile
-- Returns:
-
listDataFiles
List all data files - get's called recursively- Parameters:
fileList
- current fiel list - get's added tofolder
- folder to searchfilter
- file filter
-
getDataSourceName
Description copied from interface:OfflineDataStore
Get the data source name- Specified by:
getDataSourceName
in interfaceOfflineDataStore
- Returns:
- data source name
-
loadData
public boolean loadData(PamDataBlock dataBlock, OfflineDataLoadInfo offlineDataLoadInfo, ViewLoadObserver loadObserver) Description copied from interface:OfflineDataStore
Load data for a given datablock between two time limits.- Specified by:
loadData
in interfaceOfflineDataStore
- Parameters:
dataBlock
- datablock owner of the data- Returns:
- true if load successful.
-
loadData
public boolean loadData(PamDataBlock dataBlock, BinaryOfflineDataMapPoint mapPoint, long dataStart, long dataEnd, BinaryDataSink dataSink) Load the data from a single file.Generally, PAMGUARD will use the above function which loads between two times, but for some offline analysis tasks, it's convenient to scroll through file at a time in which case this function can be used.
- Parameters:
dataBlock
- PamDataBlock to receive the datadataStart
- data startdataEnd
- data endbinaryOfflineDataMapPoint
- data map point- Returns:
- true if data were loaded. false if out of memory in which case the calling load function will drop out of the loop over files.
-
saveData
Saves data in a PamDataBlock.First scans all data in the pamDataBlock and works out which files actually need updating based on info in their DataUnitFileInformation then rewrites those files.
Note that data from many files may be in memory and it's also possible that files are only partially read in, in which case, it will be necessary to partially take data from the old file and partially from the stuff in memory !
- Specified by:
saveData
in interfaceOfflineDataStore
- Parameters:
pamDataBlock
- data block holding the data.- Returns:
- true if saved Ok.
-
pamClose
public void pamClose()Description copied from class:PamControlledUnit
Called when PAMGUARD is finally closing down so that a module may free any remaining resources (e.g. files or COMM ports).- Overrides:
pamClose
in classPamControlledUnit
-
isDataBlockBinaryOut
Convenience function to determine whether a data block is beiung written to binary files- Returns:
- only true if binary store is present and the data block subscribes to it.
-
findBinaryStoreControl
Find the binary store- Returns:
- binary storage controller, or null if no binary storage module loaded.
-
getBinaryUnitType
Get the unit type for the binary store.- Returns:
- the binary store unit type.
-
getDatagramManager
- Specified by:
getDatagramManager
in interfaceOfflineDataStore
- Returns:
- the datagramManager
-
getGUI
Get the GUI for the PAMControlled unit. This has multiple GUI options which are instantiated depending on the view type.- Overrides:
getGUI
in classPamControlledUnit
- Parameters:
flag
- . The GUI type flag defined in PAMGuiManager.- Returns:
- the GUI for the PamControlledUnit unit.
-
getModuleStatus
Description copied from class:PamControlledUnit
Quick convenient way of getting the module status.- Overrides:
getModuleStatus
in classPamControlledUnit
- Returns:
- Module Status or null if no status manager present.
-
getBackupInformation
- Overrides:
getBackupInformation
in classPamControlledUnit
-
getNoiseStore
Store noise in pgdf or pgnf files.- Returns:
- where noise data are to be stored.
-
getStoreStatus
Description copied from interface:DataOutputStore
Get the store status, i.e. does it exist, does it contain data, if so over what date range, etc.- Specified by:
getStoreStatus
in interfaceDataOutputStore
- Returns:
-
deleteDataFrom
public boolean deleteDataFrom(long timeMillis) Description copied from interface:DataOutputStore
Delete all data from a given time, in all data streams.- Specified by:
deleteDataFrom
in interfaceDataOutputStore
- Parameters:
timeMillis
- time to delete from (anything >= this time)- Returns:
- true if it seems to have worked OK. False if any errors (e.g. database or file system error).
-
getOfflineState
public int getOfflineState()Description copied from class:PamControlledUnit
Get the offline state of this module. This can generally be idle, but can be a higher state when map making at startup and when running an offline task.- Overrides:
getOfflineState
in classPamControlledUnit
- Returns:
-
getDataLocation
Description copied from interface:OfflineDataStore
Get the data location. This may be a specific file, or might be a folder if data are in many files, a URI, etc.- Specified by:
getDataLocation
in interfaceOfflineDataStore
- Returns:
- store locations
-
getInegrityChecker
Description copied from interface:DataOutputStore
Get a data integrity checker. This can be called at startup to see if there is a problem.- Specified by:
getInegrityChecker
in interfaceDataOutputStore
- Returns:
-
getBinaryStoreProcess
- Returns:
- the binaryStoreProcess
-