60 monitorId_ = monitorId;
64 grpMonLastUpdated_ = 0;
66 persistentData_ =
false;
68 needToWriteFileHeader_ =
true;
69 groupFileSignature_ = 206661989;
70 groupFileVersion_ = 0.2f;
76 void GroupMonitorCore::init() {
90 if (groupFileId_ != NULL) {
114 timeVector_.push_back(time);
115 dataVector_.push_back(data);
127 std::vector<int> peakTimeVector;
129 int size = dataVector_.size() - 1;
130 for (
int i = 1; i < size; i++) {
131 if (dataVector_[i-1] < dataVector_[i] && dataVector_[i] > dataVector_[i+1])
132 peakTimeVector.push_back(timeVector_[i]);
135 return peakTimeVector;
139 std::vector<int> sortedPeakTimeVector;
141 int size = dataVector_.size() - 1;
142 for (
int i = 1; i < size; i++) {
143 if (dataVector_[i-1] < dataVector_[i] && dataVector_[i] > dataVector_[i+1])
144 sortedPeakTimeVector.push_back(timeVector_[i]);
147 std::sort(sortedPeakTimeVector.begin(), sortedPeakTimeVector.end());
148 std::reverse(sortedPeakTimeVector.begin(), sortedPeakTimeVector.end());
150 return sortedPeakTimeVector;
154 std::vector<float> peakValueVector;
156 int size = dataVector_.size() - 1;
157 for (
int i = 1; i < size; i++) {
158 if (dataVector_[i-1] < dataVector_[i] && dataVector_[i] > dataVector_[i+1])
159 peakValueVector.push_back(dataVector_[i]);
162 return peakValueVector;
166 std::vector<float> sortedPeakValueVector;
168 int size = dataVector_.size() - 1;
169 for (
int i = 1; i < size; i++) {
170 if (dataVector_[i-1] < dataVector_[i] && dataVector_[i] > dataVector_[i+1])
171 sortedPeakValueVector.push_back(dataVector_[i]);
174 std::sort(sortedPeakValueVector.begin(), sortedPeakValueVector.end());
175 std::reverse(sortedPeakValueVector.begin(), sortedPeakValueVector.end());
177 return sortedPeakValueVector;
181 if (!persistentData_) {
193 if (persistentData_) {
196 startTime_ = (startTime_<0) ? currentTime : startTime_;
197 startTimeLast_ = currentTime;
198 accumTime_ = (totalTime_>0) ? totalTime_ : 0;
201 startTime_ = currentTime;
202 startTimeLast_ = currentTime;
209 assert(startTime_>-1 && startTimeLast_>-1 && accumTime_>-1);
219 totalTime_ = stopTime_-startTimeLast_ + accumTime_;
220 assert(totalTime_>=0);
227 if (groupFileId_ != NULL)
228 KERNEL_ERROR(
"GroupMonitorCore: setGroupFileId() has already been called.");
230 groupFileId_ = groupFileId;
232 if (groupFileId_ == NULL)
233 needToWriteFileHeader_ =
false;
236 needToWriteFileHeader_ =
true;
237 writeGroupFileHeader();
243 void GroupMonitorCore::writeGroupFileHeader() {
244 if (!needToWriteFileHeader_)
248 if (!fwrite(&groupFileSignature_,
sizeof(
int), 1, groupFileId_))
249 KERNEL_ERROR(
"GroupMonitorCore: writeSpikeFileHeader has fwrite error");
252 if (!fwrite(&groupFileVersion_,
sizeof(
float), 1, groupFileId_))
253 KERNEL_ERROR(
"GroupMonitorCore: writeGroupFileHeader has fwrite error");
257 int tmpInt = grid.
numX;
258 if (!fwrite(&tmpInt,
sizeof(
int), 1, groupFileId_))
259 KERNEL_ERROR(
"GroupMonitorCore: writeGroupFileHeader has fwrite error");
262 if (!fwrite(&tmpInt,
sizeof(
int),1,groupFileId_))
263 KERNEL_ERROR(
"GroupMonitorCore: writeGroupFileHeader has fwrite error");
266 if (!fwrite(&tmpInt,
sizeof(
int),1,groupFileId_))
267 KERNEL_ERROR(
"GroupMonitorCore: writeGroupFileHeader has fwrite error");
270 needToWriteFileHeader_ =
false;