@@ -284,6 +284,33 @@ bool NWBFile::startNewRecording(int recordingNumber, const Array<ContinuousGroup
284284 eventDataSets.add (tsStruct.release ());
285285
286286 }
287+ basePath = rootPath + " /events/sync_messages" ;
288+ ancestry.clearQuick ();
289+ ancestry.add (" Timeseries" );
290+ ancestry.add (" AnnotationSeries" );
291+ String desc = " Stores recording start timestamps for each processor in text format" ;
292+ if (!createTimeSeriesBase (basePath, " Autogenerated messages" , desc, desc, ancestry)) return false ;
293+ tsStruct = new TimeSeries ();
294+ tsStruct->basePath = basePath;
295+ dSet = createDataSet (BaseDataType::STR (100 ), 0 , 1 , basePath + " /data" );
296+ if (dSet == nullptr )
297+ {
298+ std::cerr << " Error creating dataset for sync messages" << std::endl;
299+ return false ;
300+ }
301+ else
302+ {
303+ createDataAttributes (basePath, NAN, NAN, " n/a" );
304+ }
305+ tsStruct->baseDataSet = dSet;
306+ dSet = createTimestampDataSet (basePath, 1 );
307+ if (dSet == nullptr ) return false ;
308+ tsStruct->timestampDataSet = dSet;
309+
310+ dSet = createDataSet (BaseDataType::U8, 0 , 1 , basePath + " /control" );
311+ if (dSet == nullptr ) return false ;
312+ tsStruct->controlDataSet = dSet;
313+ syncMsgDataSet = tsStruct;
287314
288315 return true ;
289316 }
@@ -309,10 +336,13 @@ bool NWBFile::startNewRecording(int recordingNumber, const Array<ContinuousGroup
309336 tsStruct = eventDataSets[i];
310337 CHECK_ERROR (setAttribute (BaseDataType::U64, &(tsStruct->numSamples ), tsStruct->basePath , " num_samples" ));
311338 }
339+
340+ CHECK_ERROR (setAttribute (BaseDataType::U64, &(syncMsgDataSet->numSamples ), syncMsgDataSet->basePath , " num_samples" ));
312341
313342 continuousDataSets.clear ();
314343 spikeDataSets.clear ();
315344 eventDataSets.clear ();
345+ syncMsgDataSet = nullptr ;
316346 }
317347
318348 void NWBFile::writeData (int datasetID, int channel, int nSamples, const float * data, float bitVolts)
@@ -425,6 +455,15 @@ bool NWBFile::startNewRecording(int recordingNumber, const Array<ContinuousGroup
425455 eventDataSets[eventID]->numSamples += 1 ;
426456 }
427457
458+ void NWBFile::writeTimestampSyncText (uint16 sourceID, int64 timestamp, float sourceSampleRate, String text)
459+ {
460+ CHECK_ERROR (syncMsgDataSet->baseDataSet ->writeDataBlock (1 , BaseDataType::STR (text.length ()), text.toUTF8 ()));
461+ double timeSec = timestamp / sourceSampleRate;
462+ CHECK_ERROR (syncMsgDataSet->timestampDataSet ->writeDataBlock (1 , BaseDataType::F64, &timeSec));
463+ CHECK_ERROR (syncMsgDataSet->controlDataSet ->writeDataBlock (1 , BaseDataType::U8, &sourceID));
464+ syncMsgDataSet->numSamples += 1 ;
465+ }
466+
428467
429468 String NWBFile::getFileName ()
430469 {
0 commit comments