diff --git a/Source/Plugins/NWBFormat/NWBFormat.cpp b/Source/Plugins/NWBFormat/NWBFormat.cpp index d650c930d286e79c985cfe62b9b91be0793c8765..8b1047fa4354a2f741d5b6b81d4201acba3baa76 100644 --- a/Source/Plugins/NWBFormat/NWBFormat.cpp +++ b/Source/Plugins/NWBFormat/NWBFormat.cpp @@ -36,7 +36,7 @@ #define SPIKE_CHUNK_YSIZE 40 #endif - NWBFile::NWBFile(String fName, String ver) : HDF5FileBase(), filename(fName), GUIVersion(ver), spikeMaxSize(0) + NWBFile::NWBFile(String fName, String ver, String idText) : HDF5FileBase(), filename(fName), identifierText(idText), GUIVersion(ver), spikeMaxSize(0) { //Init stuff readyToOpen=true; //In KWIK this is in initFile, but the new recordEngine methods make it safe for it to be here @@ -76,6 +76,13 @@ int NWBFile::createFileStructure() CHECK_ERROR(setAttributeStr(*xmlText, "/general/data_collection", "configuration")); //TODO: Add default datasets + //Modify this one once we have JUCE4 to allow UTC time + String time = Time::getCurrentTime().formatted("%Y-%m-%dT%H:%M:%S"); + createTextDataSet("", "file_create_date", time); + createTextDataSet("", "identifier", identifierText); + createTextDataSet("", "nwb_version", "NWB-1.0.4_beta"); + createTextDataSet("", "session_description", " "); + createTextDataSet("", "session_start_time", time); return 0; } @@ -298,8 +305,8 @@ int NWBFile::createFileStructure() { return filename; } - - HDF5RecordingData* NWBFile::createRecordingStructures(String basePath, NWBRecordingInfo& info, String helpText, int chunk_size, String ancestry) + + HDF5RecordingData* NWBFile::createRecordingStructures(String basePath, NWBRecordingInfo& info, String helpText, int chunk_size, String ancestry) { StringArray ancestryStrings; ancestryStrings.add("TimeSeries"); @@ -322,4 +329,14 @@ int NWBFile::createFileStructure() return tsSet; } - \ No newline at end of file + + void NWBFile::createTextDataSet(String path, String name, String text) + { + ScopedPointer<HDF5RecordingData> dSet; + + if (text.isEmpty()) text = " "; //to avoid 0-length strings, which cause errors + + dSet = createDataSet(STR, 1, 0, path + "/" + name); + if (!dSet) return; + dSet->writeDataBlock(1, STR, text.toUTF8()); + } \ No newline at end of file diff --git a/Source/Plugins/NWBFormat/NWBFormat.h b/Source/Plugins/NWBFormat/NWBFormat.h index e082babcba0519fb9227b83759967b7807b98dc3..fd3f488ec10bef16247d9124c24c09a819abd053 100644 --- a/Source/Plugins/NWBFormat/NWBFormat.h +++ b/Source/Plugins/NWBFormat/NWBFormat.h @@ -44,7 +44,7 @@ namespace NWBRecording class NWBFile : public HDF5FileBase { public: - NWBFile(String fName, String ver); //with whatever arguments it's necessary + NWBFile(String fName, String ver, String idText); //with whatever arguments it's necessary ~NWBFile(); bool startNewRecording(int recordingNumber, const Array<NWBRecordingInfo>& continuousArray, const Array<NWBRecordingInfo>& electrodeArray); void stopRecording(); @@ -61,6 +61,7 @@ namespace NWBRecording private: HDF5RecordingData* createRecordingStructures(String basePath, NWBRecordingInfo& info, String helpText, int chunk_size, String ancestry); + void createTextDataSet(String path, String name, String text); const String filename; const String GUIVersion; @@ -90,8 +91,8 @@ namespace NWBRecording int spikeMaxSize; const String* xmlText; + const String identifierText; - //whatever is needed JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(NWBFile); }; diff --git a/Source/Plugins/NWBFormat/NWBRecording.cpp b/Source/Plugins/NWBFormat/NWBRecording.cpp index 64497e99aabfcc450b703182739fe074c825b5c8..85618957092d603997f357b5a822e8b1d4e63dca 100644 --- a/Source/Plugins/NWBFormat/NWBRecording.cpp +++ b/Source/Plugins/NWBFormat/NWBRecording.cpp @@ -48,7 +48,7 @@ //Called when acquisition starts, to open the files String basepath = rootFolder.getFullPathName() + rootFolder.separatorString + "experiment_" + String(experimentNumber) + ".nwb"; - recordFile = new NWBFile(basepath, CoreServices::getGUIVersion()); + recordFile = new NWBFile(basepath, CoreServices::getGUIVersion(), identifierText); recordFile->setXmlText(getLatestSettingsXml()); int recProcs = getNumRecordedProcessors(); @@ -217,6 +217,14 @@ RecordEngineManager* NWBRecordEngine::getEngineManager() { //static factory that instantiates the engine manager, which allows to configure recording options among other things. See OriginalRecording to see how to create options for a record engine RecordEngineManager* man = new RecordEngineManager("NWB", "NWB", &(engineFactory<NWBRecordEngine>)); + EngineParameter* param; + param = new EngineParameter(EngineParameter::STR, 0, "Identifier Text", String::empty); + man->addParameter(param); return man; +} + +void NWBRecordEngine::setParameter(EngineParameter& parameter) +{ + strParameter(0, identifierText); } \ No newline at end of file diff --git a/Source/Plugins/NWBFormat/NWBRecording.h b/Source/Plugins/NWBFormat/NWBRecording.h index 2c218d7b0311267c7fc59a505393f214185bc865..2364d8683fd891b5b66787f1fa1692bf79c61497 100644 --- a/Source/Plugins/NWBFormat/NWBRecording.h +++ b/Source/Plugins/NWBFormat/NWBRecording.h @@ -43,6 +43,7 @@ void addSpikeElectrode(int index,const SpikeRecordInfo* elec) override; void writeSpike(int electrodeIndex, const SpikeObject& spike, int64 timestamp) override; void resetChannels() override; + void setParameter(EngineParameter& parameter) override; static RecordEngineManager* getEngineManager(); @@ -61,6 +62,8 @@ HeapBlock<int16> intBuffer; HeapBlock<double> tsBuffer; int bufferSize; + + String identifierText; JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(NWBRecordEngine);