@@ -96,11 +96,8 @@ void RecordThread::setFirstBlockFlag (bool state)
9696 this ->notify ();
9797}
9898
99- void RecordThread::run ()
99+ void RecordThread::openFiles ()
100100{
101- spikesReceived = 0 ;
102- spikesWritten = 0 ;
103-
104101 // Initialize per-channel sample numbers
105102 sampleNumbers.clear ();
106103 for (int chan = 0 ; chan < m_numChannels; ++chan)
@@ -114,17 +111,23 @@ void RecordThread::run()
114111 m_perStreamTimestampIdxs.resize (numStreams);
115112 m_perStreamSampleNumbers.resize (numStreams, 0 );
116113
117- bool closeEarly = true ;
118-
119- // 1-Open Files
120- m_cleanExit = false ;
121- closeEarly = false ;
122- Array<int64> initSampleNumbers;
123-
124114 m_engine->openFiles (m_rootFolder, m_experimentNumber, m_recordingNumber);
125115
126116 if (recordNode != nullptr )
127117 recordNode->notifyRecordThreadFilesOpened ();
118+ }
119+
120+ void RecordThread::run ()
121+ {
122+ // 1-Initialize counters
123+ spikesReceived = 0 ;
124+ spikesWritten = 0 ;
125+
126+ bool closeEarly = false ;
127+ int numStreams = recordNode->getNumDataStreams ();
128+
129+ m_cleanExit = false ;
130+ Array<int64> initSampleNumbers;
128131
129132 // 2-Wait until the first block has arrived, so we can align the timestamps
130133 bool isWaiting = false ;
@@ -137,7 +140,7 @@ void RecordThread::run()
137140 wait (1 );
138141 }
139142
140- // Get initial sample numbers from each stream's queue
143+ // 3 - Get initial sample numbers from each stream's queue
141144 int globalChan = 0 ;
142145 for (int streamIdx = 0 ; streamIdx < numStreams; streamIdx++)
143146 {
@@ -165,12 +168,12 @@ void RecordThread::run()
165168 }
166169 m_engine->updateLatestSampleNumbers (initSampleNumbers);
167170
168- // 3- Normal loop
171+ // 4 - Normal loop
169172 while (! threadShouldExit ())
170173 writeData (m_minWriteSamples, m_maxWriteSamples, BLOCK_MAX_WRITE_EVENTS, BLOCK_MAX_WRITE_SPIKES);
171174
172175 // LOGD(__FUNCTION__, " Exiting record thread");
173- // 4- Before closing the thread, try to write the remaining samples
176+ // 5 - Before closing the thread, try to write the remaining samples
174177
175178 LOGD (" Closing all files" );
176179
0 commit comments