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
FieldsModifier and TypeFieldDescriptionprotected BinaryStoreSettingsstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic intMaximum 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 Stringstatic final StringFields inherited from class PamController.PamControlledUnit
isMixed, isViewer - 
Constructor Summary
ConstructorsModifierConstructorDescriptionBinaryStore(String unitName) protectedBinaryStore(String unitType, String unitName)  - 
Method Summary
Modifier and TypeMethodDescriptionbooleancreateFileMenu(JFrame parentFrame) booleancreateMapPoint(File aFile, BinaryHeaderAndFooter bhf, ArrayList<PamDataBlock> streams) Create a data map point and add it to the map.voidcreateOfflineDataMap(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.booleandeleteDataFrom(long timeMillis) Delete all data from a given time, in all data streams.static BinaryStoreFind 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 StringGet the unit type for the binary store.static intGet 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 intCurrent maximum understandable format.Quick convenient way of getting the module status.Store noise in pgdf or pgnf files.intGet the number of different settings within the settings source.intGet the offline state of this module.getSettings(int settingsIndex) Get a specific PamSettingsGroupGet a name for the settings sourcelonggetStoreStatus(boolean getDetail) Get the store status, i.e.static ArrayList<PamDataBlock> getStreamingDataBlocks(boolean binaryStore) Get a list of data blocks with binary storage.static booleanisDataBlockBinaryOut(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 prefixvoidlistDataFiles(ArrayList<File> fileList, File folder, PamFileFilter filter) List all data files - get's called recursivelyList all the index files in the binary storage folderbooleanloadData(PamDataBlock dataBlock, BinaryOfflineDataMapPoint mapPoint, long dataStart, long dataEnd, BinaryDataSink dataSink) Load the data from a single file.booleanloadData(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 namevoidnotifyModelChanged(int changeType) General notification when the PAMGAURD model changes.protected voidvoidpamClose()Called when PAMGUARD is finally closing down so that a module may free any remaining resources (e.g.voidCalled for all controlled units after Pam acquisition has stoppedvoidcalled 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.booleanremoveMapPoint(File aFile, ArrayList<PamDataBlock> streams) protected voidreOpenStores(int endReason, long newFileTime) Called from the process to close and reopen each datastream in a new file.booleanrestoreSettings(PamControlledUnitSettings pamControlledUnitSettings) booleanrewriteIndexFile(PamDataBlock dataBlock, OfflineDataMapPoint offlineDataMapPoint) rewrite the index file.booleanrewriteIndexFile(PamDataBlock dataBlock, OfflineDataMapPoint offlineDataMapPoint, File indexFile) booleansaveData(PamDataBlock pamDataBlock) Saves data in a PamDataBlock.booleansaveEndSettings(long timeNow) Save settings when processing ends.booleansaveStartSettings(long timeNow) Save the settings in some way or another.voidsetBinaryStoreSettings(BinaryStoreSettings binaryStoreSettings) swapFileType(File dataFile, String newType) Swap a file type from whatever is on the end of datafile to newTypeprotected voidunpackAnnotationData(int fileVersion, PamDataUnit createdUnit, BinaryObjectData binaryObjectData, BinaryDataSink dataSink) Unpack annotation data.Methods 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, getUnitTaskManager, getUnitTaskManager, getUnitType, getVerboseLevel, gotoTab, isInMainConfiguration, isNetRx, isViewer, playViewerSound, removePamProcess, removeUnit, rename, saveViewerData, setFrameNumber, setModuleStatusManager, setPamConfiguration, setPamController, setPamModuleInfo, setPamView, setSidePanel, setTabPanel, setToolbarComponent, setUnitTaskManager, setupControlledUnit, stopViewerSound, tellModule, terminalPrint, terminalPrintln, toStringMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface PamController.PamSettings
getUnitTypeMethods 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. - 
binaryStoreSettings
 - 
defUnitType
- See Also:
 
 - 
defUnitName
- See Also:
 
 - 
GlobalFolderArg
- See Also:
 
 
 - 
 - 
Constructor Details
- 
BinaryStore
- Parameters:
 unitType-unitName-
 - 
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:PamControlledUnitGeneral notification when the PAMGAURD model changes.- Overrides:
 notifyModelChangedin classPamControlledUnit- Parameters:
 changeType- type of change
 - 
pamToStart
public void pamToStart()Description copied from class:PamControlledUnitcalled 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:
 pamToStartin classPamControlledUnit
 - 
pamHasStopped
public void pamHasStopped()Description copied from class:PamControlledUnitCalled for all controlled units after Pam acquisition has stopped- Overrides:
 pamHasStoppedin classPamControlledUnit
 - 
reOpenStores
protected void reOpenStores(int endReason, long newFileTime) Called from the process to close and reopen each datastream in a new file. Probably gets called about once an hour on the hour. - 
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:
 getSettingsReferencein interfacePamSettings- Returns:
 - The serialisable object that will be stored
 
 - 
getSettingsVersion
public long getSettingsVersion()- Specified by:
 getSettingsVersionin 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:
 restoreSettingsin interfacePamSettings- Parameters:
 pamControlledUnitSettings-- 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:
 createFileMenuin classPamControlledUnit- Parameters:
 parentFrame- parent frame for the menu- Returns:
 - the file menu item
 
 - 
openBinaryFolder
protected void openBinaryFolder() - 
saveStartSettings
public boolean saveStartSettings(long timeNow) Description copied from interface:PamSettingsSourceSave the settings in some way or another.- Specified by:
 saveStartSettingsin interfacePamSettingsSource- Parameters:
 timeNow- current time.- Returns:
 - true if settings saved successfully
 
 - 
saveEndSettings
public boolean saveEndSettings(long timeNow) Description copied from interface:PamSettingsSourceSave settings when processing ends. This may just be an update of the settings saves with saveStartSettings, e.g. an end time.- Specified by:
 saveEndSettingsin interfacePamSettingsSource- Parameters:
 timeNow-- Returns:
 - true if saved correctly.
 
 - 
getNumSettings
public int getNumSettings()Description copied from interface:PamSettingsSourceGet the number of different settings within the settings source.- Specified by:
 getNumSettingsin interfacePamSettingsSource- Returns:
 - the number of PamSettingsGroups.
 
 - 
getSettings
Description copied from interface:PamSettingsSourceGet a specific PamSettingsGroup- Specified by:
 getSettingsin interfacePamSettingsSource- Parameters:
 settingsIndex- index of group- Returns:
 - a settings group
 
 - 
getSettingsSourceName
Description copied from interface:PamSettingsSourceGet a name for the settings source- Specified by:
 getSettingsSourceNamein interfacePamSettingsSource- Returns:
 - a name
 
 - 
getBinaryStoreSettings
- Returns:
 - the binaryStoreSettings
 
 - 
setBinaryStoreSettings
- Parameters:
 binaryStoreSettings- the binaryStoreSettings to set
 - 
createOfflineDataMap
Description copied from interface:OfflineDataStoreCreate 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:
 createOfflineDataMapin 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:
 rewriteIndexFilein interfaceOfflineDataStore- Parameters:
 dataBlock-offlineDataMapPoint-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:OfflineDataStoreGet the data source name- Specified by:
 getDataSourceNamein interfaceOfflineDataStore- Returns:
 - data source name
 
 - 
loadData
public boolean loadData(PamDataBlock dataBlock, OfflineDataLoadInfo offlineDataLoadInfo, ViewLoadObserver loadObserver) Description copied from interface:OfflineDataStoreLoad data for a given datablock between two time limits.- Specified by:
 loadDatain interfaceOfflineDataStore- Parameters:
 dataBlock- datablock owner of the dataloadObserver-- 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.
 
 - 
unpackAnnotationData
protected void unpackAnnotationData(int fileVersion, PamDataUnit createdUnit, BinaryObjectData binaryObjectData, BinaryDataSink dataSink) Unpack annotation data.- Parameters:
 createdUnit-binaryObjectData-dataSink-
 - 
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:
 saveDatain interfaceOfflineDataStore- Parameters:
 pamDataBlock- data block holding the data.- Returns:
 - true if saved Ok.
 
 - 
pamClose
public void pamClose()Description copied from class:PamControlledUnitCalled when PAMGUARD is finally closing down so that a module may free any remaining resources (e.g. files or COMM ports).- Overrides:
 pamClosein 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:
 getDatagramManagerin 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:
 getGUIin classPamControlledUnit- Parameters:
 flag- . The GUI type flag defined in PAMGuiManager.- Returns:
 - the GUI for the PamControlledUnit unit.
 
 - 
getModuleStatus
Description copied from class:PamControlledUnitQuick convenient way of getting the module status.- Overrides:
 getModuleStatusin classPamControlledUnit- Returns:
 - Module Status or null if no status manager present.
 
 - 
getBackupInformation
- Overrides:
 getBackupInformationin classPamControlledUnit
 - 
getNoiseStore
Store noise in pgdf or pgnf files.- Returns:
 - where noise data are to be stored.
 
 - 
getStoreStatus
Description copied from interface:DataOutputStoreGet the store status, i.e. does it exist, does it contain data, if so over what date range, etc.- Specified by:
 getStoreStatusin interfaceDataOutputStore- Parameters:
 getDetail-- Returns:
 
 - 
deleteDataFrom
public boolean deleteDataFrom(long timeMillis) Description copied from interface:DataOutputStoreDelete all data from a given time, in all data streams.- Specified by:
 deleteDataFromin 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:PamControlledUnitGet 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:
 getOfflineStatein classPamControlledUnit- Returns:
 
 - 
getDataLocation
Description copied from interface:OfflineDataStoreGet 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:
 getDataLocationin interfaceOfflineDataStore- Returns:
 - store locations
 
 - 
getInegrityChecker
Description copied from interface:DataOutputStoreGet a data integrity checker. This can be called at startup to see if there is a problem.- Specified by:
 getInegrityCheckerin interfaceDataOutputStore- Returns:
 
 - 
getBinaryStoreProcess
- Returns:
 - the binaryStoreProcess
 
 
 -