Skip to content

Commit 0ce3eff

Browse files
committed
Adapt KWIK format to new hdf5 data types
1 parent 42e357b commit 0ce3eff

3 files changed

Lines changed: 42 additions & 41 deletions

File tree

Source/Plugins/KWIKFormat/RecordEngine/HDF5Recording.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,8 +281,8 @@ void HDF5Recording::writeSpike(int electrodeIndex, const SpikeEvent* spike)
281281
void HDF5Recording::startAcquisition()
282282
{
283283
eventFile = new KWEFile();
284-
eventFile->addEventType("TTL",HDF5FileBase::U8,"event_channels");
285-
eventFile->addEventType("Messages",HDF5FileBase::STR,"Text");
284+
eventFile->addEventType("TTL",HDF5FileBase::BaseDataType::U8,"event_channels");
285+
eventFile->addEventType("Messages", HDF5FileBase::BaseDataType::DSTR, "Text");
286286
spikesFile = new KWXFile();
287287
}
288288

Source/Plugins/KWIKFormat/RecordEngine/KWIKFormat.cpp

Lines changed: 38 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -69,31 +69,31 @@ void KWDFile::startNewRecording(int recordingNumber, int nChannels, KWIKRecordin
6969
String recordPath = String("/recordings/")+String(recordingNumber);
7070
CHECK_ERROR(createGroup(recordPath));
7171
CHECK_ERROR(setAttributeStr(info->name,recordPath,String("name")));
72-
CHECK_ERROR(setAttribute(U64,&(info->start_time),recordPath,String("start_time")));
73-
CHECK_ERROR(setAttribute(U32,&(info->start_sample),recordPath,String("start_sample")));
74-
CHECK_ERROR(setAttribute(F32,&(info->sample_rate),recordPath,String("sample_rate")));
75-
CHECK_ERROR(setAttribute(U32,&(info->bit_depth),recordPath,String("bit_depth")));
72+
CHECK_ERROR(setAttribute(BaseDataType::U64, &(info->start_time), recordPath, String("start_time")));
73+
CHECK_ERROR(setAttribute(BaseDataType::U32, &(info->start_sample), recordPath, String("start_sample")));
74+
CHECK_ERROR(setAttribute(BaseDataType::F32, &(info->sample_rate), recordPath, String("sample_rate")));
75+
CHECK_ERROR(setAttribute(BaseDataType::U32, &(info->bit_depth), recordPath, String("bit_depth")));
7676
CHECK_ERROR(createGroup(recordPath+"/application_data"));
7777
// CHECK_ERROR(setAttributeArray(F32,info->bitVolts.getRawDataPointer(),info->bitVolts.size(),recordPath+"/application_data",String("channel_bit_volts")));
78-
bitVoltsSet = createDataSet(F32, info->bitVolts.size(), 0, recordPath + "/application_data/channel_bit_volts");
78+
bitVoltsSet = createDataSet(BaseDataType::F32, info->bitVolts.size(), 0, recordPath + "/application_data/channel_bit_volts");
7979
if (bitVoltsSet.get())
80-
bitVoltsSet->writeDataBlock(info->bitVolts.size(), F32, info->bitVolts.getRawDataPointer());
80+
bitVoltsSet->writeDataBlock(info->bitVolts.size(), BaseDataType::F32, info->bitVolts.getRawDataPointer());
8181
else
8282
std::cerr << "Error creating bitvolts data set" << std::endl;
8383

84-
CHECK_ERROR(setAttribute(U8,&mSample,recordPath+"/application_data",String("is_multiSampleRate_data")));
84+
CHECK_ERROR(setAttribute(BaseDataType::U8, &mSample, recordPath + "/application_data", String("is_multiSampleRate_data")));
8585
//CHECK_ERROR(setAttributeArray(F32,info->channelSampleRates.getRawDataPointer(),info->channelSampleRates.size(),recordPath+"/application_data",String("channel_sample_rates")));
86-
sampleRateSet = createDataSet(F32, info->channelSampleRates.size(), 0, recordPath + "/application_data/channel_sample_rates");
86+
sampleRateSet = createDataSet(BaseDataType::F32, info->channelSampleRates.size(), 0, recordPath + "/application_data/channel_sample_rates");
8787
if (sampleRateSet.get())
88-
sampleRateSet->writeDataBlock(info->channelSampleRates.size(), F32, info->channelSampleRates.getRawDataPointer());
88+
sampleRateSet->writeDataBlock(info->channelSampleRates.size(), BaseDataType::F32, info->channelSampleRates.getRawDataPointer());
8989
else
9090
std::cerr << "Error creating sample rates data set" << std::endl;
9191

92-
recdata = createDataSet(I16,0,nChannels,CHUNK_XSIZE,recordPath+"/data");
92+
recdata = createDataSet(BaseDataType::I16, 0, nChannels, CHUNK_XSIZE, recordPath + "/data");
9393
if (!recdata.get())
9494
std::cerr << "Error creating data set" << std::endl;
9595

96-
tsData = createDataSet(I64, 0, nChannels, TIMESTAMP_CHUNK_SIZE, recordPath + "/application_data/timestamps");
96+
tsData = createDataSet(BaseDataType::I64, 0, nChannels, TIMESTAMP_CHUNK_SIZE, recordPath + "/application_data/timestamps");
9797
if (!tsData.get())
9898
std::cerr << "Error creating timestamps data set" << std::endl;
9999

@@ -106,7 +106,7 @@ void KWDFile::stopRecording()
106106
String path = String("/recordings/")+String(recordingNumber)+String("/data");
107107
recdata->getRowXPositions(samples);
108108

109-
CHECK_ERROR(setAttributeArray(U32,samples.getRawDataPointer(),samples.size(),path,"valid_samples"));
109+
CHECK_ERROR(setAttributeArray(BaseDataType::U32, samples.getRawDataPointer(), samples.size(), path, "valid_samples"));
110110
//ScopedPointer does the deletion and destructors the closings
111111
recdata = nullptr;
112112
tsData = nullptr;
@@ -116,13 +116,13 @@ int KWDFile::createFileStructure()
116116
{
117117
const uint16 ver = 2;
118118
if (createGroup("/recordings")) return -1;
119-
if (setAttribute(U16,(void*)&ver,"/","kwik_version")) return -1;
119+
if (setAttribute(BaseDataType::U16, (void*)&ver, "/", "kwik_version")) return -1;
120120
return 0;
121121
}
122122

123123
void KWDFile::writeBlockData(int16* data, int nSamples)
124124
{
125-
CHECK_ERROR(recdata->writeDataBlock(nSamples,I16,data));
125+
CHECK_ERROR(recdata->writeDataBlock(nSamples, BaseDataType::I16, data));
126126
}
127127

128128
void KWDFile::writeRowData(int16* data, int nSamples)
@@ -131,15 +131,15 @@ void KWDFile::writeRowData(int16* data, int nSamples)
131131
{
132132
curChan=0;
133133
}
134-
CHECK_ERROR(recdata->writeDataRow(curChan,nSamples,I16,data));
134+
CHECK_ERROR(recdata->writeDataRow(curChan, nSamples, BaseDataType::I16, data));
135135
curChan++;
136136
}
137137

138138
void KWDFile::writeRowData(int16* data, int nSamples, int channel)
139139
{
140140
if (channel >= 0 && channel < nChannels)
141141
{
142-
CHECK_ERROR(recdata->writeDataRow(channel, nSamples, I16, data));
142+
CHECK_ERROR(recdata->writeDataRow(channel, nSamples, BaseDataType::I16, data));
143143
curChan = channel;
144144
}
145145
}
@@ -148,7 +148,7 @@ void KWDFile::writeTimestamps(int64* ts, int nTs, int channel)
148148
{
149149
if (channel >= 0 && channel < nChannels)
150150
{
151-
CHECK_ERROR(tsData->writeDataRow(channel, nTs, I64, ts));
151+
CHECK_ERROR(tsData->writeDataRow(channel, nTs, BaseDataType::I64, ts));
152152
}
153153
}
154154

@@ -190,20 +190,21 @@ int KWEFile::createFileStructure()
190190
if (createGroup(path)) return -1;
191191
path += "/events";
192192
if (createGroup(path)) return -1;
193-
dSet = createDataSet(U64,0,EVENT_CHUNK_SIZE,path + "/time_samples");
193+
dSet = createDataSet(BaseDataType::U64, 0, EVENT_CHUNK_SIZE, path + "/time_samples");
194194
if (!dSet) return -1;
195-
dSet = createDataSet(U16,0,EVENT_CHUNK_SIZE,path + "/recording");
195+
dSet = createDataSet(BaseDataType::U16, 0, EVENT_CHUNK_SIZE, path + "/recording");
196196
if (!dSet) return -1;
197197
path += "/user_data";
198198
if (createGroup(path)) return -1;
199-
dSet = createDataSet(U8,0,EVENT_CHUNK_SIZE,path + "/eventID");
199+
dSet = createDataSet(BaseDataType::U8, 0, EVENT_CHUNK_SIZE, path + "/eventID");
200200
if (!dSet) return -1;
201-
dSet = createDataSet(U8,0,EVENT_CHUNK_SIZE,path + "/nodeID");
201+
dSet = createDataSet(BaseDataType::U8, 0, EVENT_CHUNK_SIZE, path + "/nodeID");
202202
if (!dSet) return -1;
203203
dSet = createDataSet(eventTypes[i],0,EVENT_CHUNK_SIZE,path + "/" + eventDataNames[i]);
204204
if (!dSet) return -1;
205205
}
206-
if (setAttribute(U16,(void*)&ver,"/","kwik_version")) return -1;
206+
if (setAttribute(BaseDataType::U16, (void*)&ver, "/", "kwik_version")) return -1;
207+
207208
return 0;
208209
}
209210

@@ -214,10 +215,10 @@ void KWEFile::startNewRecording(int recordingNumber, KWIKRecordingInfo* info)
214215
String recordPath = String("/recordings/")+String(recordingNumber);
215216
CHECK_ERROR(createGroup(recordPath));
216217
CHECK_ERROR(setAttributeStr(info->name,recordPath,String("name")));
217-
CHECK_ERROR(setAttribute(U64,&(info->start_time),recordPath,String("start_time")));
218+
CHECK_ERROR(setAttribute(BaseDataType::U64, &(info->start_time), recordPath, String("start_time")));
218219
// CHECK_ERROR(setAttribute(U32,&(info->start_sample),recordPath,String("start_sample")));
219-
CHECK_ERROR(setAttribute(F32,&(info->sample_rate),recordPath,String("sample_rate")));
220-
CHECK_ERROR(setAttribute(U32,&(info->bit_depth),recordPath,String("bit_depth")));
220+
CHECK_ERROR(setAttribute(BaseDataType::F32, &(info->sample_rate), recordPath, String("sample_rate")));
221+
CHECK_ERROR(setAttribute(BaseDataType::U32, &(info->bit_depth), recordPath, String("bit_depth")));
221222
// CHECK_ERROR(createGroup(recordPath + "/raw"));
222223
// CHECK_ERROR(createGroup(recordPath + "/raw/hdf5_paths"));
223224

@@ -264,10 +265,10 @@ void KWEFile::writeEvent(int type, uint8 id, uint8 processor, void* data, int64
264265
std::cerr << "HDF5::writeEvent Invalid event type " << type << std::endl;
265266
return;
266267
}
267-
CHECK_ERROR(timeStamps[type]->writeDataBlock(1,U64,&timestamp));
268-
CHECK_ERROR(recordings[type]->writeDataBlock(1,I32,&recordingNumber));
269-
CHECK_ERROR(eventID[type]->writeDataBlock(1,U8,&id));
270-
CHECK_ERROR(nodeID[type]->writeDataBlock(1,U8,&processor));
268+
CHECK_ERROR(timeStamps[type]->writeDataBlock(1, BaseDataType::U64, &timestamp));
269+
CHECK_ERROR(recordings[type]->writeDataBlock(1, BaseDataType::I32, &recordingNumber));
270+
CHECK_ERROR(eventID[type]->writeDataBlock(1, BaseDataType::U8, &id));
271+
CHECK_ERROR(nodeID[type]->writeDataBlock(1, BaseDataType::U8, &processor));
271272
CHECK_ERROR(eventData[type]->writeDataBlock(1,eventTypes[type],data));
272273
}
273274

@@ -283,7 +284,7 @@ void KWEFile::writeEvent(int type, uint8 id, uint8 processor, void* data, int64
283284
kwdIndex++;
284285
}*/
285286

286-
void KWEFile::addEventType(String name, DataTypes type, String dataName)
287+
void KWEFile::addEventType(String name, BaseDataType type, String dataName)
287288
{
288289
eventNames.add(name);
289290
eventTypes.add(type);
@@ -325,7 +326,7 @@ int KWXFile::createFileStructure()
325326
{
326327
const uint16 ver = 2;
327328
if (createGroup("/channel_groups")) return -1;
328-
if (setAttribute(U16,(void*)&ver,"/","kwik_version")) return -1;
329+
if (setAttribute(BaseDataType::U16, (void*)&ver, "/", "kwik_version")) return -1;
329330
for (int i=0; i < channelArray.size(); i++)
330331
{
331332
int res = createChannelGroup(i);
@@ -346,11 +347,11 @@ int KWXFile::createChannelGroup(int index)
346347
int nChannels = channelArray[index];
347348
String path("/channel_groups/"+String(index));
348349
CHECK_ERROR(createGroup(path));
349-
dSet = createDataSet(I16,0,0,nChannels,SPIKE_CHUNK_XSIZE,SPIKE_CHUNK_YSIZE,path+"/waveforms_filtered");
350+
dSet = createDataSet(BaseDataType::I16, 0, 0, nChannels, SPIKE_CHUNK_XSIZE, SPIKE_CHUNK_YSIZE, path + "/waveforms_filtered");
350351
if (!dSet) return -1;
351-
dSet = createDataSet(U64,0,SPIKE_CHUNK_XSIZE,path+"/time_samples");
352+
dSet = createDataSet(BaseDataType::U64, 0, SPIKE_CHUNK_XSIZE, path + "/time_samples");
352353
if (!dSet) return -1;
353-
dSet = createDataSet(U16,0,SPIKE_CHUNK_XSIZE,path+"/recordings");
354+
dSet = createDataSet(BaseDataType::U16, 0, SPIKE_CHUNK_XSIZE, path + "/recordings");
354355
if (!dSet) return -1;
355356
return 0;
356357
}
@@ -412,7 +413,7 @@ void KWXFile::writeSpike(int groupIndex, int nSamples, const float* data, Array<
412413
}
413414
}
414415

415-
CHECK_ERROR(spikeArray[groupIndex]->writeDataBlock(1,nSamples,I16,transformVector));
416-
CHECK_ERROR(recordingArray[groupIndex]->writeDataBlock(1,I32,&recordingNumber));
417-
CHECK_ERROR(timeStamps[groupIndex]->writeDataBlock(1,U64,&timestamp));
416+
CHECK_ERROR(spikeArray[groupIndex]->writeDataBlock(1, nSamples, BaseDataType::I16, transformVector));
417+
CHECK_ERROR(recordingArray[groupIndex]->writeDataBlock(1, BaseDataType::I32, &recordingNumber));
418+
CHECK_ERROR(timeStamps[groupIndex]->writeDataBlock(1, BaseDataType::U64, &timestamp));
418419
}

Source/Plugins/KWIKFormat/RecordEngine/KWIKFormat.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ class KWEFile : public HDF5FileBase
8080
void stopRecording();
8181
void writeEvent(int type, uint8 id, uint8 processor, void* data, int64 timestamp);
8282
// void addKwdFile(String filename);
83-
void addEventType(String name, DataTypes type, String dataName);
83+
void addEventType(String name, BaseDataType type, String dataName);
8484
String getFileName();
8585

8686
protected:
@@ -95,7 +95,7 @@ class KWEFile : public HDF5FileBase
9595
OwnedArray<HDF5RecordingData> nodeID;
9696
OwnedArray<HDF5RecordingData> eventData;
9797
Array<String> eventNames;
98-
Array<DataTypes> eventTypes;
98+
Array<BaseDataType> eventTypes;
9999
Array<String> eventDataNames;
100100
int kwdIndex;
101101

0 commit comments

Comments
 (0)